|
| 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.pipe.it.dual.treemodel.auto.basic; |
| 21 | + |
| 22 | +import org.apache.iotdb.common.rpc.thrift.TSStatus; |
| 23 | +import org.apache.iotdb.commons.client.sync.SyncConfigNodeIServiceClient; |
| 24 | +import org.apache.iotdb.commons.pipe.agent.plugin.builtin.BuiltinPipePlugin; |
| 25 | +import org.apache.iotdb.confignode.rpc.thrift.TCreatePipeReq; |
| 26 | +import org.apache.iotdb.db.it.utils.TestUtils; |
| 27 | +import org.apache.iotdb.it.env.MultiEnvFactory; |
| 28 | +import org.apache.iotdb.it.env.cluster.node.DataNodeWrapper; |
| 29 | +import org.apache.iotdb.it.framework.IoTDBTestRunner; |
| 30 | +import org.apache.iotdb.it.utils.IPv6TestUtils; |
| 31 | +import org.apache.iotdb.itbase.category.MultiClusterIT2DualTreeAutoBasic; |
| 32 | +import org.apache.iotdb.pipe.it.dual.treemodel.auto.AbstractPipeDualTreeModelAutoIT; |
| 33 | +import org.apache.iotdb.rpc.TSStatusCode; |
| 34 | + |
| 35 | +import org.junit.AfterClass; |
| 36 | +import org.junit.Assert; |
| 37 | +import org.junit.Before; |
| 38 | +import org.junit.BeforeClass; |
| 39 | +import org.junit.Test; |
| 40 | +import org.junit.experimental.categories.Category; |
| 41 | +import org.junit.runner.RunWith; |
| 42 | + |
| 43 | +import java.util.Arrays; |
| 44 | +import java.util.Collections; |
| 45 | +import java.util.HashMap; |
| 46 | +import java.util.Map; |
| 47 | + |
| 48 | +import static org.apache.iotdb.it.utils.IPv6TestUtils.IPV6_LOOPBACK_ADDRESS; |
| 49 | + |
| 50 | +@RunWith(IoTDBTestRunner.class) |
| 51 | +@Category({MultiClusterIT2DualTreeAutoBasic.class}) |
| 52 | +public class IoTDBPipeIPv6IT extends AbstractPipeDualTreeModelAutoIT { |
| 53 | + |
| 54 | + private static String previousTestNodeAddress; |
| 55 | + |
| 56 | + @BeforeClass |
| 57 | + public static void setUpIPv6() { |
| 58 | + IPv6TestUtils.assumeIPv6LoopbackAvailable(); |
| 59 | + previousTestNodeAddress = IPv6TestUtils.setTestNodeAddressToIPv6Loopback(); |
| 60 | + } |
| 61 | + |
| 62 | + @AfterClass |
| 63 | + public static void tearDownIPv6() { |
| 64 | + IPv6TestUtils.restoreTestNodeAddress(previousTestNodeAddress); |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + @Before |
| 69 | + public void setUp() { |
| 70 | + MultiEnvFactory.createEnv(2); |
| 71 | + senderEnv = MultiEnvFactory.getEnv(0); |
| 72 | + receiverEnv = MultiEnvFactory.getEnv(1); |
| 73 | + setupConfig(); |
| 74 | + senderEnv.initClusterEnvironment(1, 1); |
| 75 | + receiverEnv.initClusterEnvironment(1, 1); |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + protected void setupConfig() { |
| 80 | + super.setupConfig(); |
| 81 | + senderEnv |
| 82 | + .getConfig() |
| 83 | + .getCommonConfig() |
| 84 | + .setDataReplicationFactor(1) |
| 85 | + .setSchemaReplicationFactor(1); |
| 86 | + receiverEnv |
| 87 | + .getConfig() |
| 88 | + .getCommonConfig() |
| 89 | + .setDataReplicationFactor(1) |
| 90 | + .setSchemaReplicationFactor(1); |
| 91 | + } |
| 92 | + |
| 93 | + @Test |
| 94 | + public void testSyncAndAsyncSinksThroughIPv6Loopback() throws Exception { |
| 95 | + assertDataNodesUseIPv6(senderEnv.getDataNodeWrapperList()); |
| 96 | + assertDataNodesUseIPv6(receiverEnv.getDataNodeWrapperList()); |
| 97 | + |
| 98 | + final String receiverNodeUrl = receiverEnv.getDataNodeWrapper(0).getIpAndPortString(); |
| 99 | + Assert.assertTrue(receiverNodeUrl.startsWith("[::1]:")); |
| 100 | + |
| 101 | + try (final SyncConfigNodeIServiceClient client = |
| 102 | + (SyncConfigNodeIServiceClient) senderEnv.getLeaderConfigNodeConnection()) { |
| 103 | + createAndStartPipe( |
| 104 | + client, |
| 105 | + "ipv6_async_pipe", |
| 106 | + "root.ipv6_async.**", |
| 107 | + BuiltinPipePlugin.IOTDB_THRIFT_ASYNC_CONNECTOR.getPipePluginName(), |
| 108 | + receiverNodeUrl); |
| 109 | + createAndStartPipe( |
| 110 | + client, |
| 111 | + "ipv6_sync_pipe", |
| 112 | + "root.ipv6_sync.**", |
| 113 | + BuiltinPipePlugin.IOTDB_THRIFT_SYNC_CONNECTOR.getPipePluginName(), |
| 114 | + receiverNodeUrl); |
| 115 | + } |
| 116 | + |
| 117 | + TestUtils.executeNonQueries( |
| 118 | + senderEnv, |
| 119 | + Arrays.asList( |
| 120 | + "insert into root.ipv6_async.d1(time, s1) values (1, 1)", |
| 121 | + "insert into root.ipv6_sync.d1(time, s1) values (1, 1)", |
| 122 | + "flush"), |
| 123 | + null); |
| 124 | + |
| 125 | + TestUtils.assertDataEventuallyOnEnv( |
| 126 | + receiverEnv, |
| 127 | + "select count(s1) from root.ipv6_async.d1", |
| 128 | + "count(root.ipv6_async.d1.s1),", |
| 129 | + Collections.singleton("1,")); |
| 130 | + TestUtils.assertDataEventuallyOnEnv( |
| 131 | + receiverEnv, |
| 132 | + "select count(s1) from root.ipv6_sync.d1", |
| 133 | + "count(root.ipv6_sync.d1.s1),", |
| 134 | + Collections.singleton("1,")); |
| 135 | + } |
| 136 | + |
| 137 | + private static void createAndStartPipe( |
| 138 | + final SyncConfigNodeIServiceClient client, |
| 139 | + final String pipeName, |
| 140 | + final String sourcePath, |
| 141 | + final String sinkName, |
| 142 | + final String receiverNodeUrl) |
| 143 | + throws Exception { |
| 144 | + final Map<String, String> sourceAttributes = new HashMap<>(); |
| 145 | + sourceAttributes.put("source.path", sourcePath); |
| 146 | + |
| 147 | + final Map<String, String> sinkAttributes = new HashMap<>(); |
| 148 | + sinkAttributes.put("sink", sinkName); |
| 149 | + sinkAttributes.put("sink.batch.enable", "false"); |
| 150 | + sinkAttributes.put("sink.node-urls", receiverNodeUrl); |
| 151 | + |
| 152 | + final TSStatus status = |
| 153 | + client.createPipe( |
| 154 | + new TCreatePipeReq(pipeName, sinkAttributes).setExtractorAttributes(sourceAttributes)); |
| 155 | + Assert.assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode()); |
| 156 | + Assert.assertEquals( |
| 157 | + TSStatusCode.SUCCESS_STATUS.getStatusCode(), client.startPipe(pipeName).getCode()); |
| 158 | + } |
| 159 | + |
| 160 | + private static void assertDataNodesUseIPv6(final Iterable<DataNodeWrapper> dataNodes) { |
| 161 | + for (final DataNodeWrapper dataNode : dataNodes) { |
| 162 | + Assert.assertEquals(IPV6_LOOPBACK_ADDRESS, dataNode.getIp()); |
| 163 | + Assert.assertTrue(dataNode.getIpAndPortString().startsWith("[::1]:")); |
| 164 | + } |
| 165 | + } |
| 166 | +} |
0 commit comments