-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Verify connection && Refactor async connection framework (#12667)
- Loading branch information
1 parent
93211e1
commit 85971c6
Showing
98 changed files
with
3,774 additions
and
1,186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBVerifyConnectionIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.iotdb.db.it; | ||
|
||
import org.apache.iotdb.commons.service.ThriftService; | ||
import org.apache.iotdb.consensus.ConsensusFactory; | ||
import org.apache.iotdb.it.env.EnvFactory; | ||
import org.apache.iotdb.it.framework.IoTDBTestRunner; | ||
import org.apache.iotdb.itbase.category.ClusterIT; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.junit.runner.RunWith; | ||
|
||
import java.sql.Connection; | ||
import java.sql.ResultSet; | ||
import java.sql.Statement; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@RunWith(IoTDBTestRunner.class) | ||
@Category({ClusterIT.class}) | ||
public class IoTDBVerifyConnectionIT { | ||
private static final String testConsensusProtocolClass = ConsensusFactory.RATIS_CONSENSUS; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
EnvFactory.getEnv() | ||
.getConfig() | ||
.getCommonConfig() | ||
.setConfigNodeConsensusProtocolClass(testConsensusProtocolClass) | ||
.setSchemaRegionConsensusProtocolClass(testConsensusProtocolClass) | ||
.setDataRegionConsensusProtocolClass(testConsensusProtocolClass); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
EnvFactory.getEnv().cleanClusterEnvironment(); | ||
} | ||
|
||
@Test | ||
public void verifyConnectionAllUpTest() throws Exception { | ||
EnvFactory.getEnv().initClusterEnvironment(3, 3); | ||
try (Connection connection = EnvFactory.getEnv().getConnection(); | ||
Statement statement = connection.createStatement()) { | ||
ResultSet resultSet = statement.executeQuery("verify connection"); | ||
Assert.assertEquals( | ||
ImmutableMap.of(ThriftService.STATUS_UP, 12), collectConnectionResult(resultSet)); | ||
resultSet = statement.executeQuery("verify connection details"); | ||
Assert.assertEquals( | ||
ImmutableMap.of(ThriftService.STATUS_UP, 54), collectConnectionResult(resultSet)); | ||
} | ||
} | ||
|
||
@Test | ||
public void verifyConnectionWithNodeCorruptTest() throws Exception { | ||
EnvFactory.getEnv().initClusterEnvironment(5, 1); | ||
try (Connection connection = EnvFactory.getEnv().getConnection(); | ||
Statement statement = connection.createStatement()) { | ||
ResultSet resultSet = statement.executeQuery("verify connection details"); | ||
Assert.assertEquals( | ||
ImmutableMap.of(ThriftService.STATUS_UP, 38), collectConnectionResult(resultSet)); | ||
EnvFactory.getEnv().getConfigNodeWrapperList().get(0).stopForcibly(); | ||
resultSet = statement.executeQuery("verify connection"); | ||
Assert.assertEquals( | ||
ImmutableMap.of(ThriftService.STATUS_UP, 2, ThriftService.STATUS_DOWN, 11), | ||
collectConnectionResult(resultSet)); | ||
resultSet = statement.executeQuery("verify connection details"); | ||
Assert.assertEquals( | ||
ImmutableMap.of(ThriftService.STATUS_UP, 27, ThriftService.STATUS_DOWN, 11), | ||
collectConnectionResult(resultSet)); | ||
EnvFactory.getEnv().getConfigNodeWrapperList().get(1).stopForcibly(); | ||
Thread.sleep(10000); | ||
resultSet = statement.executeQuery("verify connection"); | ||
Assert.assertEquals( | ||
ImmutableMap.of(ThriftService.STATUS_UP, 2, ThriftService.STATUS_DOWN, 20), | ||
collectConnectionResult(resultSet)); | ||
resultSet = statement.executeQuery("verify connection details"); | ||
Assert.assertEquals( | ||
ImmutableMap.of(ThriftService.STATUS_UP, 18, ThriftService.STATUS_DOWN, 20), | ||
collectConnectionResult(resultSet)); | ||
} | ||
} | ||
|
||
private static Map<String, Integer> collectConnectionResult(ResultSet resultSet) | ||
throws Exception { | ||
Map<String, Integer> map = new HashMap<>(); | ||
while (resultSet.next()) { | ||
String result = resultSet.getString(3).split(" ")[0]; | ||
map.computeIfPresent(result, (key, value) -> value + 1); | ||
map.putIfAbsent(result, 1); | ||
} | ||
return map; | ||
} | ||
|
||
private static void showResult(ResultSet resultSet) throws Exception { | ||
while (resultSet.next()) { | ||
System.out.printf( | ||
"%s %s %s\n", resultSet.getString(1), resultSet.getString(2), resultSet.getString(3)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,7 @@ keyWords | |
| CONDITION | ||
| CONFIGNODES | ||
| CONFIGURATION | ||
| CONNECTION | ||
| CONNECTOR | ||
| CONTAIN | ||
| CONTAINS | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.