|
| 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.db.it; |
| 21 | + |
| 22 | +import org.apache.iotdb.common.rpc.thrift.TDataNodeLocation; |
| 23 | +import org.apache.iotdb.common.rpc.thrift.TSStatus; |
| 24 | +import org.apache.iotdb.commons.client.sync.SyncConfigNodeIServiceClient; |
| 25 | +import org.apache.iotdb.confignode.rpc.thrift.TShowClusterResp; |
| 26 | +import org.apache.iotdb.consensus.ConsensusFactory; |
| 27 | +import org.apache.iotdb.it.env.EnvFactory; |
| 28 | +import org.apache.iotdb.it.env.cluster.node.ConfigNodeWrapper; |
| 29 | +import org.apache.iotdb.it.env.cluster.node.DataNodeWrapper; |
| 30 | +import org.apache.iotdb.it.framework.IoTDBTestRunner; |
| 31 | +import org.apache.iotdb.it.utils.IPv6TestUtils; |
| 32 | +import org.apache.iotdb.itbase.category.ClusterIT; |
| 33 | +import org.apache.iotdb.rpc.TSStatusCode; |
| 34 | + |
| 35 | +import org.junit.AfterClass; |
| 36 | +import org.junit.BeforeClass; |
| 37 | +import org.junit.Test; |
| 38 | +import org.junit.experimental.categories.Category; |
| 39 | +import org.junit.runner.RunWith; |
| 40 | + |
| 41 | +import java.sql.Connection; |
| 42 | +import java.sql.ResultSet; |
| 43 | +import java.sql.Statement; |
| 44 | + |
| 45 | +import static org.apache.iotdb.it.utils.IPv6TestUtils.IPV6_LOOPBACK_ADDRESS; |
| 46 | +import static org.junit.Assert.assertEquals; |
| 47 | +import static org.junit.Assert.assertFalse; |
| 48 | +import static org.junit.Assert.assertTrue; |
| 49 | + |
| 50 | +@RunWith(IoTDBTestRunner.class) |
| 51 | +@Category({ClusterIT.class}) |
| 52 | +public class IoTDBIPv6ClusterIT { |
| 53 | + |
| 54 | + private static String previousTestNodeAddress; |
| 55 | + |
| 56 | + @BeforeClass |
| 57 | + public static void setUp() { |
| 58 | + IPv6TestUtils.assumeIPv6LoopbackAvailable(); |
| 59 | + previousTestNodeAddress = IPv6TestUtils.setTestNodeAddressToIPv6Loopback(); |
| 60 | + EnvFactory.getEnv() |
| 61 | + .getConfig() |
| 62 | + .getCommonConfig() |
| 63 | + .setSchemaRegionConsensusProtocolClass(ConsensusFactory.RATIS_CONSENSUS) |
| 64 | + .setDataRegionConsensusProtocolClass(ConsensusFactory.IOT_CONSENSUS) |
| 65 | + .setSchemaReplicationFactor(3) |
| 66 | + .setDataReplicationFactor(3); |
| 67 | + EnvFactory.getEnv().initClusterEnvironment(1, 3); |
| 68 | + } |
| 69 | + |
| 70 | + @AfterClass |
| 71 | + public static void tearDown() { |
| 72 | + EnvFactory.getEnv().cleanClusterEnvironment(); |
| 73 | + IPv6TestUtils.restoreTestNodeAddress(previousTestNodeAddress); |
| 74 | + } |
| 75 | + |
| 76 | + @Test |
| 77 | + public void clusterCanCommunicateThroughIPv6Loopback() throws Exception { |
| 78 | + for (ConfigNodeWrapper configNode : EnvFactory.getEnv().getConfigNodeWrapperList()) { |
| 79 | + assertEquals(IPV6_LOOPBACK_ADDRESS, configNode.getIp()); |
| 80 | + assertTrue(configNode.getIpAndPortString().startsWith("[::1]:")); |
| 81 | + } |
| 82 | + for (DataNodeWrapper dataNode : EnvFactory.getEnv().getDataNodeWrapperList()) { |
| 83 | + assertEquals(IPV6_LOOPBACK_ADDRESS, dataNode.getIp()); |
| 84 | + assertTrue(dataNode.getIpAndPortString().startsWith("[::1]:")); |
| 85 | + } |
| 86 | + |
| 87 | + try (SyncConfigNodeIServiceClient client = |
| 88 | + (SyncConfigNodeIServiceClient) EnvFactory.getEnv().getLeaderConfigNodeConnection()) { |
| 89 | + final TShowClusterResp showClusterResp = client.showCluster(); |
| 90 | + final TSStatus status = showClusterResp.getStatus(); |
| 91 | + assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode()); |
| 92 | + assertEquals(1, showClusterResp.getConfigNodeListSize()); |
| 93 | + assertEquals(3, showClusterResp.getDataNodeListSize()); |
| 94 | + showClusterResp |
| 95 | + .getConfigNodeList() |
| 96 | + .forEach( |
| 97 | + configNode -> |
| 98 | + assertEquals(IPV6_LOOPBACK_ADDRESS, configNode.getInternalEndPoint().getIp())); |
| 99 | + showClusterResp.getDataNodeList().forEach(this::assertDataNodeLocationUsesIPv6); |
| 100 | + } |
| 101 | + |
| 102 | + try (Connection connection = EnvFactory.getEnv().getConnection(); |
| 103 | + Statement statement = connection.createStatement()) { |
| 104 | + statement.execute("CREATE DATABASE root.ipv6_cluster"); |
| 105 | + statement.execute("CREATE TIMESERIES root.ipv6_cluster.d1.s1 INT64"); |
| 106 | + statement.execute("INSERT INTO root.ipv6_cluster.d1(time, s1) VALUES (1, 300)"); |
| 107 | + try (ResultSet resultSet = statement.executeQuery("SELECT s1 FROM root.ipv6_cluster.d1")) { |
| 108 | + assertTrue(resultSet.next()); |
| 109 | + assertEquals(1L, resultSet.getLong(1)); |
| 110 | + assertEquals(300L, resultSet.getLong(2)); |
| 111 | + assertFalse(resultSet.next()); |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + private void assertDataNodeLocationUsesIPv6(final TDataNodeLocation dataNodeLocation) { |
| 117 | + assertEquals(IPV6_LOOPBACK_ADDRESS, dataNodeLocation.getClientRpcEndPoint().getIp()); |
| 118 | + assertEquals(IPV6_LOOPBACK_ADDRESS, dataNodeLocation.getInternalEndPoint().getIp()); |
| 119 | + assertEquals(IPV6_LOOPBACK_ADDRESS, dataNodeLocation.getMPPDataExchangeEndPoint().getIp()); |
| 120 | + assertEquals( |
| 121 | + IPV6_LOOPBACK_ADDRESS, dataNodeLocation.getSchemaRegionConsensusEndPoint().getIp()); |
| 122 | + assertEquals(IPV6_LOOPBACK_ADDRESS, dataNodeLocation.getDataRegionConsensusEndPoint().getIp()); |
| 123 | + } |
| 124 | +} |
0 commit comments