|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.iotdb.subscription.it.local.tablemodel; |
| 21 | + |
| 22 | +import org.apache.iotdb.it.env.EnvFactory; |
| 23 | +import org.apache.iotdb.it.framework.IoTDBTestRunner; |
| 24 | +import org.apache.iotdb.itbase.category.LocalStandaloneIT; |
| 25 | +import org.apache.iotdb.session.subscription.ISubscriptionTableSession; |
| 26 | +import org.apache.iotdb.session.subscription.ISubscriptionTreeSession; |
| 27 | +import org.apache.iotdb.session.subscription.SubscriptionTableSessionBuilder; |
| 28 | +import org.apache.iotdb.session.subscription.SubscriptionTreeSessionBuilder; |
| 29 | +import org.apache.iotdb.session.subscription.consumer.ISubscriptionTablePullConsumer; |
| 30 | +import org.apache.iotdb.session.subscription.consumer.ISubscriptionTreePullConsumer; |
| 31 | +import org.apache.iotdb.session.subscription.consumer.table.SubscriptionTablePullConsumerBuilder; |
| 32 | +import org.apache.iotdb.session.subscription.consumer.tree.SubscriptionTreePullConsumerBuilder; |
| 33 | +import org.apache.iotdb.subscription.it.local.AbstractSubscriptionLocalIT; |
| 34 | + |
| 35 | +import org.junit.Assert; |
| 36 | +import org.junit.Before; |
| 37 | +import org.junit.Test; |
| 38 | +import org.junit.experimental.categories.Category; |
| 39 | +import org.junit.runner.RunWith; |
| 40 | + |
| 41 | +import static org.junit.Assert.fail; |
| 42 | + |
| 43 | +@RunWith(IoTDBTestRunner.class) |
| 44 | +@Category({LocalStandaloneIT.class}) |
| 45 | +public class IoTDBSubscriptionIsolationIT extends AbstractSubscriptionLocalIT { |
| 46 | + |
| 47 | + @Override |
| 48 | + @Before |
| 49 | + public void setUp() throws Exception { |
| 50 | + super.setUp(); |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + public void testTopicIsolation() throws Exception { |
| 55 | + final String treeTopicName = "treeTopic"; |
| 56 | + final String tableTopicName = "tableTopic"; |
| 57 | + |
| 58 | + final String host = EnvFactory.getEnv().getIP(); |
| 59 | + final int port = Integer.parseInt(EnvFactory.getEnv().getPort()); |
| 60 | + |
| 61 | + // create tree topic |
| 62 | + try (final ISubscriptionTreeSession session = |
| 63 | + new SubscriptionTreeSessionBuilder().host(host).port(port).build()) { |
| 64 | + session.open(); |
| 65 | + session.createTopic(treeTopicName); |
| 66 | + } |
| 67 | + |
| 68 | + // create table topic |
| 69 | + try (final ISubscriptionTableSession session = |
| 70 | + new SubscriptionTableSessionBuilder().host(host).port(port).build()) { |
| 71 | + session.createTopic(tableTopicName); |
| 72 | + } |
| 73 | + |
| 74 | + // show topic on tree session |
| 75 | + try (final ISubscriptionTreeSession session = |
| 76 | + new SubscriptionTreeSessionBuilder().host(host).port(port).build()) { |
| 77 | + session.open(); |
| 78 | + Assert.assertEquals(1, session.getTopics().size()); |
| 79 | + Assert.assertTrue(session.getTopic(treeTopicName).isPresent()); |
| 80 | + Assert.assertFalse(session.getTopic(tableTopicName).isPresent()); |
| 81 | + } |
| 82 | + |
| 83 | + // show topic on table session |
| 84 | + try (final ISubscriptionTableSession session = |
| 85 | + new SubscriptionTableSessionBuilder().host(host).port(port).build()) { |
| 86 | + Assert.assertEquals(1, session.getTopics().size()); |
| 87 | + Assert.assertTrue(session.getTopic(tableTopicName).isPresent()); |
| 88 | + Assert.assertFalse(session.getTopic(treeTopicName).isPresent()); |
| 89 | + } |
| 90 | + |
| 91 | + // drop table topic on tree session |
| 92 | + try (final ISubscriptionTreeSession session = |
| 93 | + new SubscriptionTreeSessionBuilder().host(host).port(port).build()) { |
| 94 | + session.open(); |
| 95 | + try { |
| 96 | + session.dropTopic(tableTopicName); |
| 97 | + fail(); |
| 98 | + } catch (final Exception ignored) { |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + // drop tree topic on table session |
| 103 | + try (final ISubscriptionTableSession session = |
| 104 | + new SubscriptionTableSessionBuilder().host(host).port(port).build()) { |
| 105 | + try { |
| 106 | + session.dropTopic(treeTopicName); |
| 107 | + fail(); |
| 108 | + } catch (final Exception ignored) { |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + // drop tree topic on tree session |
| 113 | + try (final ISubscriptionTreeSession session = |
| 114 | + new SubscriptionTreeSessionBuilder().host(host).port(port).build()) { |
| 115 | + session.open(); |
| 116 | + session.dropTopic(treeTopicName); |
| 117 | + } |
| 118 | + |
| 119 | + // drop table topic on table session |
| 120 | + try (final ISubscriptionTableSession session = |
| 121 | + new SubscriptionTableSessionBuilder().host(host).port(port).build()) { |
| 122 | + session.dropTopic(tableTopicName); |
| 123 | + } |
| 124 | + } |
| 125 | + |
| 126 | + @Test |
| 127 | + public void testSubscriptionIsolation() throws Exception { |
| 128 | + final String treeTopicName = "treeTopic"; |
| 129 | + final String tableTopicName = "tableTopic"; |
| 130 | + |
| 131 | + final String host = EnvFactory.getEnv().getIP(); |
| 132 | + final int port = Integer.parseInt(EnvFactory.getEnv().getPort()); |
| 133 | + |
| 134 | + // create tree topic |
| 135 | + try (final ISubscriptionTreeSession session = |
| 136 | + new SubscriptionTreeSessionBuilder().host(host).port(port).build()) { |
| 137 | + session.open(); |
| 138 | + session.createTopic(treeTopicName); |
| 139 | + } |
| 140 | + |
| 141 | + // create table topic |
| 142 | + try (final ISubscriptionTableSession session = |
| 143 | + new SubscriptionTableSessionBuilder().host(host).port(port).build()) { |
| 144 | + session.createTopic(tableTopicName); |
| 145 | + } |
| 146 | + |
| 147 | + // subscribe table topic on tree consumer |
| 148 | + try (final ISubscriptionTreePullConsumer consumer = |
| 149 | + new SubscriptionTreePullConsumerBuilder().host(host).port(port).build()) { |
| 150 | + consumer.open(); |
| 151 | + try { |
| 152 | + consumer.subscribe(tableTopicName); |
| 153 | + fail(); |
| 154 | + } catch (final Exception ignored) { |
| 155 | + } |
| 156 | + } |
| 157 | + |
| 158 | + // subscribe tree topic on table consumer |
| 159 | + try (final ISubscriptionTablePullConsumer consumer = |
| 160 | + new SubscriptionTablePullConsumerBuilder().host(host).port(port).build()) { |
| 161 | + consumer.open(); |
| 162 | + try { |
| 163 | + consumer.subscribe(treeTopicName); |
| 164 | + fail(); |
| 165 | + } catch (final Exception ignored) { |
| 166 | + } |
| 167 | + } |
| 168 | + |
| 169 | + // subscribe tree topic on tree consumer |
| 170 | + final ISubscriptionTreePullConsumer treeConsumer = |
| 171 | + new SubscriptionTreePullConsumerBuilder().host(host).port(port).build(); |
| 172 | + treeConsumer.open(); |
| 173 | + treeConsumer.subscribe(treeTopicName); |
| 174 | + |
| 175 | + // subscribe table topic on table consumer |
| 176 | + final ISubscriptionTablePullConsumer tableConsumer = |
| 177 | + new SubscriptionTablePullConsumerBuilder().host(host).port(port).build(); |
| 178 | + tableConsumer.open(); |
| 179 | + tableConsumer.subscribe(tableTopicName); |
| 180 | + |
| 181 | + // show subscription on tree session |
| 182 | + try (final ISubscriptionTreeSession session = |
| 183 | + new SubscriptionTreeSessionBuilder().host(host).port(port).build()) { |
| 184 | + session.open(); |
| 185 | + Assert.assertEquals(1, session.getSubscriptions().size()); |
| 186 | + Assert.assertEquals(1, session.getSubscriptions(treeTopicName).size()); |
| 187 | + Assert.assertEquals(0, session.getSubscriptions(tableTopicName).size()); |
| 188 | + } |
| 189 | + |
| 190 | + // show subscription on table session |
| 191 | + try (final ISubscriptionTableSession session = |
| 192 | + new SubscriptionTableSessionBuilder().host(host).port(port).build()) { |
| 193 | + Assert.assertEquals(1, session.getSubscriptions().size()); |
| 194 | + Assert.assertEquals(1, session.getSubscriptions(tableTopicName).size()); |
| 195 | + Assert.assertEquals(0, session.getSubscriptions(treeTopicName).size()); |
| 196 | + } |
| 197 | + |
| 198 | + // unsubscribe table topic on tree consumer |
| 199 | + try { |
| 200 | + treeConsumer.unsubscribe(tableTopicName); |
| 201 | + fail(); |
| 202 | + } catch (final Exception ignored) { |
| 203 | + |
| 204 | + } |
| 205 | + |
| 206 | + // unsubscribe tree topic on table consumer |
| 207 | + try { |
| 208 | + tableConsumer.unsubscribe(treeTopicName); |
| 209 | + fail(); |
| 210 | + } catch (final Exception ignored) { |
| 211 | + |
| 212 | + } |
| 213 | + |
| 214 | + // close consumers |
| 215 | + treeConsumer.close(); |
| 216 | + tableConsumer.close(); |
| 217 | + } |
| 218 | +} |
0 commit comments