You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/08/07 11:01:03 UTC

[GitHub] [iotdb] MiniSho opened a new pull request, #6906: [IOTDB-3821] add some new test cases for ConfigNodeIT

MiniSho opened a new pull request, #6906:
URL: https://github.com/apache/iotdb/pull/6906

   1. test query and remove DataNodes
   2. test showCluster and showDataNodes
   3. migrate testPermission in ConfigNodeRPCServiceProcessorTest
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] CRZbulabula commented on a diff in pull request #6906: [IOTDB-3821] add some new test cases for ConfigNodeIT

Posted by GitBox <gi...@apache.org>.
CRZbulabula commented on code in PR #6906:
URL: https://github.com/apache/iotdb/pull/6906#discussion_r939767712


##########
integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBConfigNodeIT.java:
##########
@@ -204,6 +228,597 @@ public void removeAndStopConfigNodeTest() {
       assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
     } catch (Exception e) {
       e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
+
+  @Test
+  public void queryAndRemoveDataNodeTest() {
+    TShowDataNodesResp showDataNodesResp = null;
+    TDataNodeRegisterReq dataNodeRegisterReq;
+    TDataNodeRegisterResp dataNodeRegisterResp;
+    TDataNodeConfigurationResp dataNodeConfigurationResp;
+    TDataNodeRemoveReq removeReq;
+    TDataNodeRemoveResp removeResp;
+
+    List<ConfigNodeWrapper> configNodeWrappers = EnvFactory.getEnv().getConfigNodeWrapperList();
+    List<DataNodeWrapper> dataNodeWrappers = EnvFactory.getEnv().getDataNodeWrapperList();
+    TDataNodeLocation dataNodeLocation = new TDataNodeLocation();
+    TDataNodeConfiguration dataNodeConfiguration = new TDataNodeConfiguration();
+    List<TDataNodeLocation> removeDataNodeLocationList = new ArrayList<>();
+    List<TDataNodeInfo> dataNodeInfos;
+
+    try (SyncConfigNodeIServiceClient client =
+        (SyncConfigNodeIServiceClient) EnvFactory.getEnv().getConfigNodeConnection()) {
+      // add DataNode
+      DataNodeWrapper dataNodeWrapper =
+          new DataNodeWrapper(
+              configNodeWrappers.get(0).getIpAndPortString(),
+              "IoTDBConfigNodeIT",
+              "dataNodeTest",
+              EnvUtils.searchAvailablePorts());
+      dataNodeWrapper.createDir();
+      dataNodeWrapper.changeConfig(ConfigFactory.getConfig().getEngineProperties());
+      dataNodeWrapper.start();
+      dataNodeWrappers.add(dataNodeWrapper);
+
+      EnvFactory.getEnv().setDataNodeWrapperList(dataNodeWrappers);
+      for (int i = 0; i < retryNum; i++) {
+        showDataNodesResp = client.showDataNodes();
+        if (showDataNodesResp.getDataNodesInfoListSize() == 4) {
+          break;
+        }
+        Thread.sleep(1000);
+      }
+      assertEquals(4, showDataNodesResp.getDataNodesInfoListSize());
+
+      dataNodeInfos = showDataNodesResp.getDataNodesInfoList();
+      dataNodeConfiguration.setLocation(dataNodeLocation);
+      dataNodeConfiguration.setResource(new TNodeResource(8, 1024 * 1024));
+      dataNodeRegisterReq = new TDataNodeRegisterReq(dataNodeConfiguration);
+      TDataNodeInfo dataNodeInfo = dataNodeInfos.get(3);
+
+      // test success re-register
+      dataNodeLocation.setDataNodeId(dataNodeInfo.getDataNodeId());
+      dataNodeLocation.setClientRpcEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort()));
+      dataNodeLocation.setMPPDataExchangeEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 1));
+      dataNodeLocation.setInternalEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 2));
+      dataNodeLocation.setDataRegionConsensusEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 3));
+      dataNodeLocation.setSchemaRegionConsensusEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 4));
+
+      dataNodeRegisterResp = client.registerDataNode(dataNodeRegisterReq);
+      assertEquals(
+          TSStatusCode.DATANODE_ALREADY_REGISTERED.getStatusCode(),
+          dataNodeRegisterResp.getStatus().getCode());
+
+      // test query all DataNodeInfos
+      dataNodeConfigurationResp = client.getDataNodeConfiguration(-1);
+      Map<Integer, TDataNodeConfiguration> infoMap =
+          dataNodeConfigurationResp.getDataNodeConfigurationMap();
+      assertEquals(
+          TSStatusCode.SUCCESS_STATUS.getStatusCode(),
+          dataNodeConfigurationResp.getStatus().getCode());
+      assertEquals(4, infoMap.size());
+      List<Map.Entry<Integer, TDataNodeConfiguration>> infoList =
+          new ArrayList<>(infoMap.entrySet());
+      infoList.sort(Comparator.comparingInt(Map.Entry::getKey));
+      int count = 0;
+      for (DataNodeWrapper expectedDataNode : dataNodeWrappers) {
+        for (int i = 0; i < 4; i++) {
+          TDataNodeLocation dnLocation = infoList.get(i).getValue().getLocation();
+          if (expectedDataNode.getInternalPort() == dnLocation.getInternalEndPoint().getPort()
+              && expectedDataNode.getMppDataExchangePort()
+                  == dnLocation.getMPPDataExchangeEndPoint().getPort()
+              && expectedDataNode.getSchemaRegionConsensusPort()
+                  == dnLocation.getSchemaRegionConsensusEndPoint().getPort()
+              && expectedDataNode.getDataRegionConsensusPort()
+                  == dnLocation.getDataRegionConsensusEndPoint().getPort()) {
+            count++;
+            break;
+          }
+        }
+      }
+      assertEquals(4, count);
+
+      // test query one DataNodeInfo
+      dataNodeConfigurationResp = client.getDataNodeConfiguration(dataNodeLocation.getDataNodeId());
+      infoMap = dataNodeConfigurationResp.getDataNodeConfigurationMap();
+      TDataNodeLocation dnLocation =
+          dataNodeConfigurationResp
+              .getDataNodeConfigurationMap()
+              .get(dataNodeLocation.getDataNodeId())
+              .getLocation();
+      assertEquals(
+          TSStatusCode.SUCCESS_STATUS.getStatusCode(),
+          dataNodeConfigurationResp.getStatus().getCode());
+      assertEquals(1, infoMap.size());
+      assertEquals(dataNodeLocation, dnLocation);
+
+      // test remove DataNode
+      removeDataNodeLocationList.add(dataNodeLocation);
+      removeReq = new TDataNodeRemoveReq(removeDataNodeLocationList);
+      removeResp = client.removeDataNode(removeReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), removeResp.getStatus().getCode());
+
+      for (int i = 0; i < retryNum; i++) {
+        showDataNodesResp = client.showDataNodes();
+        if (showDataNodesResp.getDataNodesInfoListSize() == 3) {
+          break;
+        }
+        Thread.sleep(1000);
+      }
+      assertEquals(3, showDataNodesResp.getDataNodesInfoListSize());
+
+      dataNodeInfos = showDataNodesResp.getDataNodesInfoList();
+      for (TDataNodeInfo dnInfo : dataNodeInfos) {
+        assertNotEquals(dataNodeLocation.getDataNodeId(), dnInfo.getDataNodeId());
+      }
+      dataNodeConfigurationResp = client.getDataNodeConfiguration(dataNodeLocation.getDataNodeId());
+      assertEquals(
+          TSStatusCode.SUCCESS_STATUS.getStatusCode(),
+          dataNodeConfigurationResp.getStatus().getCode());
+      assertEquals(0, dataNodeConfigurationResp.getDataNodeConfigurationMap().size());
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }

Review Comment:
   Just throw any Exceptions in the interface, we don't need to catch and print them since it's a test code



##########
integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBConfigNodeIT.java:
##########
@@ -204,6 +228,597 @@ public void removeAndStopConfigNodeTest() {
       assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
     } catch (Exception e) {
       e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
+
+  @Test
+  public void queryAndRemoveDataNodeTest() {
+    TShowDataNodesResp showDataNodesResp = null;
+    TDataNodeRegisterReq dataNodeRegisterReq;
+    TDataNodeRegisterResp dataNodeRegisterResp;
+    TDataNodeConfigurationResp dataNodeConfigurationResp;
+    TDataNodeRemoveReq removeReq;
+    TDataNodeRemoveResp removeResp;
+
+    List<ConfigNodeWrapper> configNodeWrappers = EnvFactory.getEnv().getConfigNodeWrapperList();
+    List<DataNodeWrapper> dataNodeWrappers = EnvFactory.getEnv().getDataNodeWrapperList();
+    TDataNodeLocation dataNodeLocation = new TDataNodeLocation();
+    TDataNodeConfiguration dataNodeConfiguration = new TDataNodeConfiguration();
+    List<TDataNodeLocation> removeDataNodeLocationList = new ArrayList<>();
+    List<TDataNodeInfo> dataNodeInfos;
+
+    try (SyncConfigNodeIServiceClient client =
+        (SyncConfigNodeIServiceClient) EnvFactory.getEnv().getConfigNodeConnection()) {
+      // add DataNode
+      DataNodeWrapper dataNodeWrapper =
+          new DataNodeWrapper(
+              configNodeWrappers.get(0).getIpAndPortString(),
+              "IoTDBConfigNodeIT",
+              "dataNodeTest",
+              EnvUtils.searchAvailablePorts());
+      dataNodeWrapper.createDir();
+      dataNodeWrapper.changeConfig(ConfigFactory.getConfig().getEngineProperties());
+      dataNodeWrapper.start();
+      dataNodeWrappers.add(dataNodeWrapper);
+
+      EnvFactory.getEnv().setDataNodeWrapperList(dataNodeWrappers);
+      for (int i = 0; i < retryNum; i++) {
+        showDataNodesResp = client.showDataNodes();
+        if (showDataNodesResp.getDataNodesInfoListSize() == 4) {
+          break;
+        }
+        Thread.sleep(1000);
+      }
+      assertEquals(4, showDataNodesResp.getDataNodesInfoListSize());
+
+      dataNodeInfos = showDataNodesResp.getDataNodesInfoList();
+      dataNodeConfiguration.setLocation(dataNodeLocation);
+      dataNodeConfiguration.setResource(new TNodeResource(8, 1024 * 1024));
+      dataNodeRegisterReq = new TDataNodeRegisterReq(dataNodeConfiguration);
+      TDataNodeInfo dataNodeInfo = dataNodeInfos.get(3);
+
+      // test success re-register
+      dataNodeLocation.setDataNodeId(dataNodeInfo.getDataNodeId());
+      dataNodeLocation.setClientRpcEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort()));
+      dataNodeLocation.setMPPDataExchangeEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 1));
+      dataNodeLocation.setInternalEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 2));
+      dataNodeLocation.setDataRegionConsensusEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 3));
+      dataNodeLocation.setSchemaRegionConsensusEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 4));
+
+      dataNodeRegisterResp = client.registerDataNode(dataNodeRegisterReq);
+      assertEquals(
+          TSStatusCode.DATANODE_ALREADY_REGISTERED.getStatusCode(),
+          dataNodeRegisterResp.getStatus().getCode());
+
+      // test query all DataNodeInfos
+      dataNodeConfigurationResp = client.getDataNodeConfiguration(-1);
+      Map<Integer, TDataNodeConfiguration> infoMap =
+          dataNodeConfigurationResp.getDataNodeConfigurationMap();
+      assertEquals(
+          TSStatusCode.SUCCESS_STATUS.getStatusCode(),
+          dataNodeConfigurationResp.getStatus().getCode());
+      assertEquals(4, infoMap.size());
+      List<Map.Entry<Integer, TDataNodeConfiguration>> infoList =
+          new ArrayList<>(infoMap.entrySet());
+      infoList.sort(Comparator.comparingInt(Map.Entry::getKey));
+      int count = 0;
+      for (DataNodeWrapper expectedDataNode : dataNodeWrappers) {
+        for (int i = 0; i < 4; i++) {
+          TDataNodeLocation dnLocation = infoList.get(i).getValue().getLocation();
+          if (expectedDataNode.getInternalPort() == dnLocation.getInternalEndPoint().getPort()
+              && expectedDataNode.getMppDataExchangePort()
+                  == dnLocation.getMPPDataExchangeEndPoint().getPort()
+              && expectedDataNode.getSchemaRegionConsensusPort()
+                  == dnLocation.getSchemaRegionConsensusEndPoint().getPort()
+              && expectedDataNode.getDataRegionConsensusPort()
+                  == dnLocation.getDataRegionConsensusEndPoint().getPort()) {
+            count++;
+            break;
+          }
+        }
+      }
+      assertEquals(4, count);
+
+      // test query one DataNodeInfo
+      dataNodeConfigurationResp = client.getDataNodeConfiguration(dataNodeLocation.getDataNodeId());
+      infoMap = dataNodeConfigurationResp.getDataNodeConfigurationMap();
+      TDataNodeLocation dnLocation =
+          dataNodeConfigurationResp
+              .getDataNodeConfigurationMap()
+              .get(dataNodeLocation.getDataNodeId())
+              .getLocation();
+      assertEquals(
+          TSStatusCode.SUCCESS_STATUS.getStatusCode(),
+          dataNodeConfigurationResp.getStatus().getCode());
+      assertEquals(1, infoMap.size());
+      assertEquals(dataNodeLocation, dnLocation);
+
+      // test remove DataNode
+      removeDataNodeLocationList.add(dataNodeLocation);
+      removeReq = new TDataNodeRemoveReq(removeDataNodeLocationList);
+      removeResp = client.removeDataNode(removeReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), removeResp.getStatus().getCode());
+
+      for (int i = 0; i < retryNum; i++) {
+        showDataNodesResp = client.showDataNodes();
+        if (showDataNodesResp.getDataNodesInfoListSize() == 3) {
+          break;
+        }
+        Thread.sleep(1000);
+      }
+      assertEquals(3, showDataNodesResp.getDataNodesInfoListSize());
+
+      dataNodeInfos = showDataNodesResp.getDataNodesInfoList();
+      for (TDataNodeInfo dnInfo : dataNodeInfos) {
+        assertNotEquals(dataNodeLocation.getDataNodeId(), dnInfo.getDataNodeId());
+      }
+      dataNodeConfigurationResp = client.getDataNodeConfiguration(dataNodeLocation.getDataNodeId());
+      assertEquals(
+          TSStatusCode.SUCCESS_STATUS.getStatusCode(),
+          dataNodeConfigurationResp.getStatus().getCode());
+      assertEquals(0, dataNodeConfigurationResp.getDataNodeConfigurationMap().size());
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
+
+  @Test
+  public void showClusterAndDataNodesTest() {
+    try (SyncConfigNodeIServiceClient client =
+        (SyncConfigNodeIServiceClient) EnvFactory.getEnv().getConfigNodeConnection()) {
+      List<ConfigNodeWrapper> configNodeWrappers = EnvFactory.getEnv().getConfigNodeWrapperList();
+      List<DataNodeWrapper> dataNodeWrappers = EnvFactory.getEnv().getDataNodeWrapperList();
+
+      // test showCluster
+      TShowClusterResp clusterNodes = getClusterNodeInfos(client, 1, 3);
+      List<TConfigNodeLocation> configNodeLocations = clusterNodes.getConfigNodeList();
+      List<TDataNodeLocation> dataNodeLocations = clusterNodes.getDataNodeList();
+
+      for (TConfigNodeLocation configNodeLocation : configNodeLocations) {
+        boolean found = false;
+        for (ConfigNodeWrapper configNodeWrapper : configNodeWrappers) {
+          if (configNodeWrapper.getIp().equals(configNodeLocation.getInternalEndPoint().getIp())
+              && configNodeWrapper.getPort() == configNodeLocation.getInternalEndPoint().getPort()
+              && configNodeWrapper.getConsensusPort()
+                  == configNodeLocation.getConsensusEndPoint().getPort()) {
+            found = true;
+            break;
+          }
+        }
+        assertTrue(found);
+      }
+
+      for (TDataNodeLocation dataNodeLocation : dataNodeLocations) {
+        boolean found = false;
+        for (DataNodeWrapper dataNodeWrapper : dataNodeWrappers) {
+          if (dataNodeWrapper.getIp().equals(dataNodeLocation.getInternalEndPoint().getIp())
+              && dataNodeWrapper.getPort() == dataNodeLocation.getClientRpcEndPoint().getPort()
+              && dataNodeWrapper.getInternalPort()
+                  == dataNodeLocation.getInternalEndPoint().getPort()
+              && dataNodeWrapper.getMppDataExchangePort()
+                  == dataNodeLocation.getMPPDataExchangeEndPoint().getPort()
+              && dataNodeWrapper.getSchemaRegionConsensusPort()
+                  == dataNodeLocation.getSchemaRegionConsensusEndPoint().getPort()
+              && dataNodeWrapper.getDataRegionConsensusPort()
+                  == dataNodeLocation.getDataRegionConsensusEndPoint().getPort()) {
+            found = true;
+            break;
+          }
+        }
+        assertTrue(found);
+      }
+
+      // test showDataNodes
+      TShowDataNodesResp showDataNodesResp = client.showDataNodes();
+      List<TDataNodeInfo> dataNodesInfo = showDataNodesResp.getDataNodesInfoList();
+
+      for (TDataNodeInfo dataNodeInfo : dataNodesInfo) {
+        boolean found = false;
+        for (DataNodeWrapper dataNodeWrapper : dataNodeWrappers) {
+          if (dataNodeWrapper.getIp().equals(dataNodeInfo.getRpcAddresss())
+              && dataNodeWrapper.getPort() == dataNodeInfo.getRpcPort()) {
+            found = true;
+            break;
+          }
+        }
+        assertTrue(found);
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }

Review Comment:
   Just throw any Exceptions in the interface, we don't need to catch and print them since it's a test code



##########
integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBConfigNodeIT.java:
##########
@@ -204,6 +228,597 @@ public void removeAndStopConfigNodeTest() {
       assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
     } catch (Exception e) {
       e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
+
+  @Test
+  public void queryAndRemoveDataNodeTest() {
+    TShowDataNodesResp showDataNodesResp = null;
+    TDataNodeRegisterReq dataNodeRegisterReq;
+    TDataNodeRegisterResp dataNodeRegisterResp;
+    TDataNodeConfigurationResp dataNodeConfigurationResp;
+    TDataNodeRemoveReq removeReq;
+    TDataNodeRemoveResp removeResp;
+
+    List<ConfigNodeWrapper> configNodeWrappers = EnvFactory.getEnv().getConfigNodeWrapperList();
+    List<DataNodeWrapper> dataNodeWrappers = EnvFactory.getEnv().getDataNodeWrapperList();
+    TDataNodeLocation dataNodeLocation = new TDataNodeLocation();
+    TDataNodeConfiguration dataNodeConfiguration = new TDataNodeConfiguration();
+    List<TDataNodeLocation> removeDataNodeLocationList = new ArrayList<>();
+    List<TDataNodeInfo> dataNodeInfos;
+
+    try (SyncConfigNodeIServiceClient client =
+        (SyncConfigNodeIServiceClient) EnvFactory.getEnv().getConfigNodeConnection()) {
+      // add DataNode
+      DataNodeWrapper dataNodeWrapper =
+          new DataNodeWrapper(
+              configNodeWrappers.get(0).getIpAndPortString(),
+              "IoTDBConfigNodeIT",
+              "dataNodeTest",
+              EnvUtils.searchAvailablePorts());
+      dataNodeWrapper.createDir();
+      dataNodeWrapper.changeConfig(ConfigFactory.getConfig().getEngineProperties());
+      dataNodeWrapper.start();
+      dataNodeWrappers.add(dataNodeWrapper);
+
+      EnvFactory.getEnv().setDataNodeWrapperList(dataNodeWrappers);
+      for (int i = 0; i < retryNum; i++) {
+        showDataNodesResp = client.showDataNodes();
+        if (showDataNodesResp.getDataNodesInfoListSize() == 4) {
+          break;
+        }
+        Thread.sleep(1000);
+      }
+      assertEquals(4, showDataNodesResp.getDataNodesInfoListSize());
+
+      dataNodeInfos = showDataNodesResp.getDataNodesInfoList();
+      dataNodeConfiguration.setLocation(dataNodeLocation);
+      dataNodeConfiguration.setResource(new TNodeResource(8, 1024 * 1024));
+      dataNodeRegisterReq = new TDataNodeRegisterReq(dataNodeConfiguration);
+      TDataNodeInfo dataNodeInfo = dataNodeInfos.get(3);
+
+      // test success re-register
+      dataNodeLocation.setDataNodeId(dataNodeInfo.getDataNodeId());
+      dataNodeLocation.setClientRpcEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort()));
+      dataNodeLocation.setMPPDataExchangeEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 1));
+      dataNodeLocation.setInternalEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 2));
+      dataNodeLocation.setDataRegionConsensusEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 3));
+      dataNodeLocation.setSchemaRegionConsensusEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 4));
+
+      dataNodeRegisterResp = client.registerDataNode(dataNodeRegisterReq);
+      assertEquals(
+          TSStatusCode.DATANODE_ALREADY_REGISTERED.getStatusCode(),
+          dataNodeRegisterResp.getStatus().getCode());
+
+      // test query all DataNodeInfos
+      dataNodeConfigurationResp = client.getDataNodeConfiguration(-1);
+      Map<Integer, TDataNodeConfiguration> infoMap =
+          dataNodeConfigurationResp.getDataNodeConfigurationMap();
+      assertEquals(
+          TSStatusCode.SUCCESS_STATUS.getStatusCode(),
+          dataNodeConfigurationResp.getStatus().getCode());
+      assertEquals(4, infoMap.size());
+      List<Map.Entry<Integer, TDataNodeConfiguration>> infoList =
+          new ArrayList<>(infoMap.entrySet());
+      infoList.sort(Comparator.comparingInt(Map.Entry::getKey));
+      int count = 0;
+      for (DataNodeWrapper expectedDataNode : dataNodeWrappers) {
+        for (int i = 0; i < 4; i++) {
+          TDataNodeLocation dnLocation = infoList.get(i).getValue().getLocation();
+          if (expectedDataNode.getInternalPort() == dnLocation.getInternalEndPoint().getPort()
+              && expectedDataNode.getMppDataExchangePort()
+                  == dnLocation.getMPPDataExchangeEndPoint().getPort()
+              && expectedDataNode.getSchemaRegionConsensusPort()
+                  == dnLocation.getSchemaRegionConsensusEndPoint().getPort()
+              && expectedDataNode.getDataRegionConsensusPort()
+                  == dnLocation.getDataRegionConsensusEndPoint().getPort()) {
+            count++;
+            break;
+          }
+        }
+      }
+      assertEquals(4, count);
+
+      // test query one DataNodeInfo
+      dataNodeConfigurationResp = client.getDataNodeConfiguration(dataNodeLocation.getDataNodeId());
+      infoMap = dataNodeConfigurationResp.getDataNodeConfigurationMap();
+      TDataNodeLocation dnLocation =
+          dataNodeConfigurationResp
+              .getDataNodeConfigurationMap()
+              .get(dataNodeLocation.getDataNodeId())
+              .getLocation();
+      assertEquals(
+          TSStatusCode.SUCCESS_STATUS.getStatusCode(),
+          dataNodeConfigurationResp.getStatus().getCode());
+      assertEquals(1, infoMap.size());
+      assertEquals(dataNodeLocation, dnLocation);
+
+      // test remove DataNode
+      removeDataNodeLocationList.add(dataNodeLocation);
+      removeReq = new TDataNodeRemoveReq(removeDataNodeLocationList);
+      removeResp = client.removeDataNode(removeReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), removeResp.getStatus().getCode());
+
+      for (int i = 0; i < retryNum; i++) {
+        showDataNodesResp = client.showDataNodes();
+        if (showDataNodesResp.getDataNodesInfoListSize() == 3) {
+          break;
+        }
+        Thread.sleep(1000);
+      }
+      assertEquals(3, showDataNodesResp.getDataNodesInfoListSize());
+
+      dataNodeInfos = showDataNodesResp.getDataNodesInfoList();
+      for (TDataNodeInfo dnInfo : dataNodeInfos) {
+        assertNotEquals(dataNodeLocation.getDataNodeId(), dnInfo.getDataNodeId());
+      }
+      dataNodeConfigurationResp = client.getDataNodeConfiguration(dataNodeLocation.getDataNodeId());
+      assertEquals(
+          TSStatusCode.SUCCESS_STATUS.getStatusCode(),
+          dataNodeConfigurationResp.getStatus().getCode());
+      assertEquals(0, dataNodeConfigurationResp.getDataNodeConfigurationMap().size());
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
+
+  @Test
+  public void showClusterAndDataNodesTest() {
+    try (SyncConfigNodeIServiceClient client =
+        (SyncConfigNodeIServiceClient) EnvFactory.getEnv().getConfigNodeConnection()) {
+      List<ConfigNodeWrapper> configNodeWrappers = EnvFactory.getEnv().getConfigNodeWrapperList();
+      List<DataNodeWrapper> dataNodeWrappers = EnvFactory.getEnv().getDataNodeWrapperList();
+
+      // test showCluster
+      TShowClusterResp clusterNodes = getClusterNodeInfos(client, 1, 3);
+      List<TConfigNodeLocation> configNodeLocations = clusterNodes.getConfigNodeList();
+      List<TDataNodeLocation> dataNodeLocations = clusterNodes.getDataNodeList();
+
+      for (TConfigNodeLocation configNodeLocation : configNodeLocations) {
+        boolean found = false;
+        for (ConfigNodeWrapper configNodeWrapper : configNodeWrappers) {
+          if (configNodeWrapper.getIp().equals(configNodeLocation.getInternalEndPoint().getIp())
+              && configNodeWrapper.getPort() == configNodeLocation.getInternalEndPoint().getPort()
+              && configNodeWrapper.getConsensusPort()
+                  == configNodeLocation.getConsensusEndPoint().getPort()) {
+            found = true;
+            break;
+          }
+        }
+        assertTrue(found);
+      }
+
+      for (TDataNodeLocation dataNodeLocation : dataNodeLocations) {
+        boolean found = false;
+        for (DataNodeWrapper dataNodeWrapper : dataNodeWrappers) {
+          if (dataNodeWrapper.getIp().equals(dataNodeLocation.getInternalEndPoint().getIp())
+              && dataNodeWrapper.getPort() == dataNodeLocation.getClientRpcEndPoint().getPort()
+              && dataNodeWrapper.getInternalPort()
+                  == dataNodeLocation.getInternalEndPoint().getPort()
+              && dataNodeWrapper.getMppDataExchangePort()
+                  == dataNodeLocation.getMPPDataExchangeEndPoint().getPort()
+              && dataNodeWrapper.getSchemaRegionConsensusPort()
+                  == dataNodeLocation.getSchemaRegionConsensusEndPoint().getPort()
+              && dataNodeWrapper.getDataRegionConsensusPort()
+                  == dataNodeLocation.getDataRegionConsensusEndPoint().getPort()) {
+            found = true;
+            break;
+          }
+        }
+        assertTrue(found);
+      }
+
+      // test showDataNodes
+      TShowDataNodesResp showDataNodesResp = client.showDataNodes();
+      List<TDataNodeInfo> dataNodesInfo = showDataNodesResp.getDataNodesInfoList();
+
+      for (TDataNodeInfo dataNodeInfo : dataNodesInfo) {
+        boolean found = false;
+        for (DataNodeWrapper dataNodeWrapper : dataNodeWrappers) {
+          if (dataNodeWrapper.getIp().equals(dataNodeInfo.getRpcAddresss())
+              && dataNodeWrapper.getPort() == dataNodeInfo.getRpcPort()) {
+            found = true;
+            break;
+          }
+        }
+        assertTrue(found);
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
+
+  private void cleanUserAndRole(IConfigNodeRPCService.Iface client) throws TException {
+    TSStatus status;
+
+    // clean user
+    TAuthorizerReq authorizerReq =
+        new TAuthorizerReq(
+            AuthorOperator.AuthorType.LIST_USER.ordinal(),
+            "",
+            "",
+            "",
+            "",
+            new HashSet<>(),
+            Collections.singletonList(""));
+    TAuthorizerResp authorizerResp = client.queryPermission(authorizerReq);
+    status = authorizerResp.getStatus();
+    assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+    List<String> allUsers = authorizerResp.getAuthorizerInfo().get(IoTDBConstant.COLUMN_USER);
+    for (String user : allUsers) {
+      if (!user.equals("root")) {
+        authorizerReq =
+            new TAuthorizerReq(
+                AuthorOperator.AuthorType.DROP_USER.ordinal(),
+                user,
+                "",
+                "",
+                "",
+                new HashSet<>(),
+                Collections.singletonList(""));
+        status = client.operatePermission(authorizerReq);
+        assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+      }
+    }
+  }
+
+  @Test
+  public void permissionTest() {
+    TSStatus status;
+    List<String> userList = new ArrayList<>();
+    userList.add("root");
+    userList.add("tempuser0");
+    userList.add("tempuser1");
+
+    List<String> roleList = new ArrayList<>();
+    roleList.add("temprole0");
+    roleList.add("temprole1");
+
+    TAuthorizerReq authorizerReq;
+    TAuthorizerResp authorizerResp;
+    TCheckUserPrivilegesReq checkUserPrivilegesReq;
+
+    Set<Integer> privilegeList = new HashSet<>();
+    privilegeList.add(PrivilegeType.DELETE_USER.ordinal());
+    privilegeList.add(PrivilegeType.CREATE_USER.ordinal());
+
+    Set<Integer> revokePrivilege = new HashSet<>();
+    revokePrivilege.add(PrivilegeType.DELETE_USER.ordinal());
+
+    List<String> privilege = new ArrayList<>();
+    privilege.add("root.** : CREATE_USER");
+    privilege.add("root.** : CREATE_USER");
+
+    List<String> paths = new ArrayList<>();
+    paths.add("root.ln.**");
+
+    try (SyncConfigNodeIServiceClient client =
+        (SyncConfigNodeIServiceClient) EnvFactory.getEnv().getConfigNodeConnection()) {
+      cleanUserAndRole(client);
+
+      // create user
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.CREATE_USER.ordinal(),
+              "tempuser0",
+              "",
+              "passwd",
+              "",
+              new HashSet<>(),
+              new ArrayList<>());
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+      authorizerReq.setUserName("tempuser1");
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+      // check user privileges
+      checkUserPrivilegesReq =
+          new TCheckUserPrivilegesReq("tempuser0", paths, PrivilegeType.DELETE_USER.ordinal());
+      status = client.checkUserPrivileges(checkUserPrivilegesReq).getStatus();
+      assertEquals(TSStatusCode.NO_PERMISSION_ERROR.getStatusCode(), status.getCode());
+
+      // drop user
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.DROP_USER.ordinal(),
+              "tempuser1",
+              "",
+              "",
+              "",
+              new HashSet<>(),
+              new ArrayList<>());
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+      // list user
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.LIST_USER.ordinal(),
+              "",
+              "",
+              "",
+              "",
+              new HashSet<>(),
+              new ArrayList<>());
+      authorizerResp = client.queryPermission(authorizerReq);
+      status = authorizerResp.getStatus();
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+      userList.remove("tempuser1");
+      assertEquals(userList, authorizerResp.getAuthorizerInfo().get(IoTDBConstant.COLUMN_USER));
+
+      // create role
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.CREATE_ROLE.ordinal(),
+              "",
+              "temprole0",
+              "",
+              "",
+              new HashSet<>(),
+              new ArrayList<>());
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+      authorizerReq.setRoleName("temprole1");
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+      // drop role
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.DROP_ROLE.ordinal(),
+              "",
+              "temprole1",
+              "",
+              "",
+              new HashSet<>(),
+              new ArrayList<>());
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+      // list role
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.LIST_ROLE.ordinal(),
+              "",
+              "",
+              "",
+              "",
+              new HashSet<>(),
+              new ArrayList<>());
+      authorizerResp = client.queryPermission(authorizerReq);
+      status = authorizerResp.getStatus();
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+      roleList.remove("temprole1");
+      assertEquals(roleList, authorizerResp.getAuthorizerInfo().get(IoTDBConstant.COLUMN_ROLE));
+
+      // alter user
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.UPDATE_USER.ordinal(),
+              "tempuser0",
+              "",
+              "",
+              "newpwd",
+              new HashSet<>(),
+              new ArrayList<>());
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+      // grant user
+      List<String> nodeNameList = new ArrayList<>();
+      nodeNameList.add("root.ln.**");
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.GRANT_USER.ordinal(),
+              "tempuser0",
+              "",
+              "",
+              "",
+              privilegeList,
+              nodeNameList);
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+      // check user privileges
+      checkUserPrivilegesReq =
+          new TCheckUserPrivilegesReq("tempuser0", paths, PrivilegeType.DELETE_USER.ordinal());
+      status = client.checkUserPrivileges(checkUserPrivilegesReq).getStatus();
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+      // grant role
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.GRANT_ROLE.ordinal(),
+              "",
+              "temprole0",
+              "",
+              "",
+              privilegeList,
+              nodeNameList);
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+      // grant role to user
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.GRANT_ROLE_TO_USER.ordinal(),
+              "tempuser0",
+              "temprole0",
+              "",
+              "",
+              new HashSet<>(),
+              nodeNameList);
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+      // revoke user
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.REVOKE_USER.ordinal(),
+              "tempuser0",
+              "",
+              "",
+              "",
+              revokePrivilege,
+              nodeNameList);
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+      // revoke role
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.REVOKE_ROLE.ordinal(),
+              "",
+              "temprole0",
+              "",
+              "",
+              revokePrivilege,
+              nodeNameList);
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+      // list privileges user
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.LIST_USER_PRIVILEGE.ordinal(),
+              "tempuser0",
+              "",
+              "",
+              "",
+              new HashSet<>(),
+              nodeNameList);
+      authorizerResp = client.queryPermission(authorizerReq);
+      status = authorizerResp.getStatus();
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+      assertEquals(
+          privilege, authorizerResp.getAuthorizerInfo().get(IoTDBConstant.COLUMN_PRIVILEGE));
+
+      // list user privileges
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.LIST_USER_PRIVILEGE.ordinal(),
+              "tempuser0",
+              "",
+              "",
+              "",
+              new HashSet<>(),
+              new ArrayList<>());
+      authorizerResp = client.queryPermission(authorizerReq);
+      status = authorizerResp.getStatus();
+      Assert.assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+      Assert.assertEquals(
+          privilege, authorizerResp.getAuthorizerInfo().get(IoTDBConstant.COLUMN_PRIVILEGE));
+
+      // list privileges role
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.LIST_ROLE_PRIVILEGE.ordinal(),
+              "",
+              "temprole0",
+              "",
+              "",
+              new HashSet<>(),
+              nodeNameList);
+      authorizerResp = client.queryPermission(authorizerReq);
+      status = authorizerResp.getStatus();
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+      privilege.remove(0);
+      assertEquals(
+          privilege, authorizerResp.getAuthorizerInfo().get(IoTDBConstant.COLUMN_PRIVILEGE));
+
+      // list role privileges
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.LIST_ROLE_PRIVILEGE.ordinal(),
+              "",
+              "temprole0",
+              "",
+              "",
+              new HashSet<>(),
+              new ArrayList<>());
+      authorizerResp = client.queryPermission(authorizerReq);
+      status = authorizerResp.getStatus();
+      Assert.assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+      Assert.assertEquals(
+          privilege, authorizerResp.getAuthorizerInfo().get(IoTDBConstant.COLUMN_PRIVILEGE));
+
+      // list all role of user
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.LIST_ROLE.ordinal(),
+              "tempuser0",
+              "",
+              "",
+              "",
+              new HashSet<>(),
+              new ArrayList<>());
+      authorizerResp = client.queryPermission(authorizerReq);
+      status = authorizerResp.getStatus();
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+      roleList.remove("temprole1");
+      assertEquals(roleList, authorizerResp.getAuthorizerInfo().get(IoTDBConstant.COLUMN_ROLE));
+
+      // list all user of role
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.LIST_USER.ordinal(),
+              "",
+              "temprole0",
+              "",
+              "",
+              new HashSet<>(),
+              new ArrayList<>());
+      authorizerResp = client.queryPermission(authorizerReq);
+      status = authorizerResp.getStatus();
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+      userList.remove("tempuser1");
+      userList.remove("root");
+      assertEquals(userList, authorizerResp.getAuthorizerInfo().get(IoTDBConstant.COLUMN_USER));
+
+      // revoke role from user
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.REVOKE_ROLE_FROM_USER.ordinal(),
+              "tempuser0",
+              "temprole0",
+              "",
+              "",
+              new HashSet<>(),
+              new ArrayList<>());
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+      // list root privileges
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.LIST_USER_PRIVILEGE.ordinal(),
+              "root",
+              "",
+              "",
+              "",
+              new HashSet<>(),
+              new ArrayList<>());
+      authorizerResp = client.queryPermission(authorizerReq);
+      status = authorizerResp.getStatus();
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+      for (int i = 0; i < PrivilegeType.values().length; i++) {
+        assertEquals(
+            PrivilegeType.values()[i].toString(),
+            authorizerResp.getAuthorizerInfo().get(IoTDBConstant.COLUMN_PRIVILEGE).get(i));
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.getMessage());

Review Comment:
   Just throw any Exceptions in the interface, we don't need to catch and print them since it's a test code



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] Beyyes merged pull request #6906: [IOTDB-3821] add some new test cases for ConfigNodeIT

Posted by GitBox <gi...@apache.org>.
Beyyes merged PR #6906:
URL: https://github.com/apache/iotdb/pull/6906


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] MiniSho commented on pull request #6906: [IOTDB-3821] add some new test cases for ConfigNodeIT

Posted by GitBox <gi...@apache.org>.
MiniSho commented on PR #6906:
URL: https://github.com/apache/iotdb/pull/6906#issuecomment-1209393309

   PermissionTest  costs the least time compared to the other tests.
   Run tests on my computer:
   13s permissionTest, 17s showClusterAndNodesTest, 20s queryAndRemoveDataTest, 23s removeAndStopConfigNode


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] CRZbulabula commented on a diff in pull request #6906: [IOTDB-3821] add some new test cases for ConfigNodeIT

Posted by GitBox <gi...@apache.org>.
CRZbulabula commented on code in PR #6906:
URL: https://github.com/apache/iotdb/pull/6906#discussion_r939767798


##########
integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBConfigNodeIT.java:
##########
@@ -204,6 +228,597 @@ public void removeAndStopConfigNodeTest() {
       assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
     } catch (Exception e) {
       e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
+
+  @Test
+  public void queryAndRemoveDataNodeTest() {
+    TShowDataNodesResp showDataNodesResp = null;
+    TDataNodeRegisterReq dataNodeRegisterReq;
+    TDataNodeRegisterResp dataNodeRegisterResp;
+    TDataNodeConfigurationResp dataNodeConfigurationResp;
+    TDataNodeRemoveReq removeReq;
+    TDataNodeRemoveResp removeResp;
+
+    List<ConfigNodeWrapper> configNodeWrappers = EnvFactory.getEnv().getConfigNodeWrapperList();
+    List<DataNodeWrapper> dataNodeWrappers = EnvFactory.getEnv().getDataNodeWrapperList();
+    TDataNodeLocation dataNodeLocation = new TDataNodeLocation();
+    TDataNodeConfiguration dataNodeConfiguration = new TDataNodeConfiguration();
+    List<TDataNodeLocation> removeDataNodeLocationList = new ArrayList<>();
+    List<TDataNodeInfo> dataNodeInfos;
+
+    try (SyncConfigNodeIServiceClient client =
+        (SyncConfigNodeIServiceClient) EnvFactory.getEnv().getConfigNodeConnection()) {
+      // add DataNode
+      DataNodeWrapper dataNodeWrapper =
+          new DataNodeWrapper(
+              configNodeWrappers.get(0).getIpAndPortString(),
+              "IoTDBConfigNodeIT",
+              "dataNodeTest",
+              EnvUtils.searchAvailablePorts());
+      dataNodeWrapper.createDir();
+      dataNodeWrapper.changeConfig(ConfigFactory.getConfig().getEngineProperties());
+      dataNodeWrapper.start();
+      dataNodeWrappers.add(dataNodeWrapper);
+
+      EnvFactory.getEnv().setDataNodeWrapperList(dataNodeWrappers);
+      for (int i = 0; i < retryNum; i++) {
+        showDataNodesResp = client.showDataNodes();
+        if (showDataNodesResp.getDataNodesInfoListSize() == 4) {
+          break;
+        }
+        Thread.sleep(1000);
+      }
+      assertEquals(4, showDataNodesResp.getDataNodesInfoListSize());
+
+      dataNodeInfos = showDataNodesResp.getDataNodesInfoList();
+      dataNodeConfiguration.setLocation(dataNodeLocation);
+      dataNodeConfiguration.setResource(new TNodeResource(8, 1024 * 1024));
+      dataNodeRegisterReq = new TDataNodeRegisterReq(dataNodeConfiguration);
+      TDataNodeInfo dataNodeInfo = dataNodeInfos.get(3);
+
+      // test success re-register
+      dataNodeLocation.setDataNodeId(dataNodeInfo.getDataNodeId());
+      dataNodeLocation.setClientRpcEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort()));
+      dataNodeLocation.setMPPDataExchangeEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 1));
+      dataNodeLocation.setInternalEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 2));
+      dataNodeLocation.setDataRegionConsensusEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 3));
+      dataNodeLocation.setSchemaRegionConsensusEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 4));
+
+      dataNodeRegisterResp = client.registerDataNode(dataNodeRegisterReq);
+      assertEquals(
+          TSStatusCode.DATANODE_ALREADY_REGISTERED.getStatusCode(),
+          dataNodeRegisterResp.getStatus().getCode());
+
+      // test query all DataNodeInfos
+      dataNodeConfigurationResp = client.getDataNodeConfiguration(-1);
+      Map<Integer, TDataNodeConfiguration> infoMap =
+          dataNodeConfigurationResp.getDataNodeConfigurationMap();
+      assertEquals(
+          TSStatusCode.SUCCESS_STATUS.getStatusCode(),
+          dataNodeConfigurationResp.getStatus().getCode());
+      assertEquals(4, infoMap.size());
+      List<Map.Entry<Integer, TDataNodeConfiguration>> infoList =
+          new ArrayList<>(infoMap.entrySet());
+      infoList.sort(Comparator.comparingInt(Map.Entry::getKey));
+      int count = 0;
+      for (DataNodeWrapper expectedDataNode : dataNodeWrappers) {
+        for (int i = 0; i < 4; i++) {
+          TDataNodeLocation dnLocation = infoList.get(i).getValue().getLocation();
+          if (expectedDataNode.getInternalPort() == dnLocation.getInternalEndPoint().getPort()
+              && expectedDataNode.getMppDataExchangePort()
+                  == dnLocation.getMPPDataExchangeEndPoint().getPort()
+              && expectedDataNode.getSchemaRegionConsensusPort()
+                  == dnLocation.getSchemaRegionConsensusEndPoint().getPort()
+              && expectedDataNode.getDataRegionConsensusPort()
+                  == dnLocation.getDataRegionConsensusEndPoint().getPort()) {
+            count++;
+            break;
+          }
+        }
+      }
+      assertEquals(4, count);
+
+      // test query one DataNodeInfo
+      dataNodeConfigurationResp = client.getDataNodeConfiguration(dataNodeLocation.getDataNodeId());
+      infoMap = dataNodeConfigurationResp.getDataNodeConfigurationMap();
+      TDataNodeLocation dnLocation =
+          dataNodeConfigurationResp
+              .getDataNodeConfigurationMap()
+              .get(dataNodeLocation.getDataNodeId())
+              .getLocation();
+      assertEquals(
+          TSStatusCode.SUCCESS_STATUS.getStatusCode(),
+          dataNodeConfigurationResp.getStatus().getCode());
+      assertEquals(1, infoMap.size());
+      assertEquals(dataNodeLocation, dnLocation);
+
+      // test remove DataNode
+      removeDataNodeLocationList.add(dataNodeLocation);
+      removeReq = new TDataNodeRemoveReq(removeDataNodeLocationList);
+      removeResp = client.removeDataNode(removeReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), removeResp.getStatus().getCode());
+
+      for (int i = 0; i < retryNum; i++) {
+        showDataNodesResp = client.showDataNodes();
+        if (showDataNodesResp.getDataNodesInfoListSize() == 3) {
+          break;
+        }
+        Thread.sleep(1000);
+      }
+      assertEquals(3, showDataNodesResp.getDataNodesInfoListSize());
+
+      dataNodeInfos = showDataNodesResp.getDataNodesInfoList();
+      for (TDataNodeInfo dnInfo : dataNodeInfos) {
+        assertNotEquals(dataNodeLocation.getDataNodeId(), dnInfo.getDataNodeId());
+      }
+      dataNodeConfigurationResp = client.getDataNodeConfiguration(dataNodeLocation.getDataNodeId());
+      assertEquals(
+          TSStatusCode.SUCCESS_STATUS.getStatusCode(),
+          dataNodeConfigurationResp.getStatus().getCode());
+      assertEquals(0, dataNodeConfigurationResp.getDataNodeConfigurationMap().size());
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
+
+  @Test
+  public void showClusterAndDataNodesTest() {
+    try (SyncConfigNodeIServiceClient client =
+        (SyncConfigNodeIServiceClient) EnvFactory.getEnv().getConfigNodeConnection()) {
+      List<ConfigNodeWrapper> configNodeWrappers = EnvFactory.getEnv().getConfigNodeWrapperList();
+      List<DataNodeWrapper> dataNodeWrappers = EnvFactory.getEnv().getDataNodeWrapperList();
+
+      // test showCluster
+      TShowClusterResp clusterNodes = getClusterNodeInfos(client, 1, 3);
+      List<TConfigNodeLocation> configNodeLocations = clusterNodes.getConfigNodeList();
+      List<TDataNodeLocation> dataNodeLocations = clusterNodes.getDataNodeList();
+
+      for (TConfigNodeLocation configNodeLocation : configNodeLocations) {
+        boolean found = false;
+        for (ConfigNodeWrapper configNodeWrapper : configNodeWrappers) {
+          if (configNodeWrapper.getIp().equals(configNodeLocation.getInternalEndPoint().getIp())
+              && configNodeWrapper.getPort() == configNodeLocation.getInternalEndPoint().getPort()
+              && configNodeWrapper.getConsensusPort()
+                  == configNodeLocation.getConsensusEndPoint().getPort()) {
+            found = true;
+            break;
+          }
+        }
+        assertTrue(found);
+      }
+
+      for (TDataNodeLocation dataNodeLocation : dataNodeLocations) {
+        boolean found = false;
+        for (DataNodeWrapper dataNodeWrapper : dataNodeWrappers) {
+          if (dataNodeWrapper.getIp().equals(dataNodeLocation.getInternalEndPoint().getIp())
+              && dataNodeWrapper.getPort() == dataNodeLocation.getClientRpcEndPoint().getPort()
+              && dataNodeWrapper.getInternalPort()
+                  == dataNodeLocation.getInternalEndPoint().getPort()
+              && dataNodeWrapper.getMppDataExchangePort()
+                  == dataNodeLocation.getMPPDataExchangeEndPoint().getPort()
+              && dataNodeWrapper.getSchemaRegionConsensusPort()
+                  == dataNodeLocation.getSchemaRegionConsensusEndPoint().getPort()
+              && dataNodeWrapper.getDataRegionConsensusPort()
+                  == dataNodeLocation.getDataRegionConsensusEndPoint().getPort()) {
+            found = true;
+            break;
+          }
+        }
+        assertTrue(found);
+      }
+
+      // test showDataNodes
+      TShowDataNodesResp showDataNodesResp = client.showDataNodes();
+      List<TDataNodeInfo> dataNodesInfo = showDataNodesResp.getDataNodesInfoList();
+
+      for (TDataNodeInfo dataNodeInfo : dataNodesInfo) {
+        boolean found = false;
+        for (DataNodeWrapper dataNodeWrapper : dataNodeWrappers) {
+          if (dataNodeWrapper.getIp().equals(dataNodeInfo.getRpcAddresss())
+              && dataNodeWrapper.getPort() == dataNodeInfo.getRpcPort()) {
+            found = true;
+            break;
+          }
+        }
+        assertTrue(found);
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }

Review Comment:
   Just throw any Exceptions in the interface, we don't need to catch and print them since it's a test code



##########
integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBConfigNodeIT.java:
##########
@@ -204,6 +228,597 @@ public void removeAndStopConfigNodeTest() {
       assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
     } catch (Exception e) {
       e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
+
+  @Test
+  public void queryAndRemoveDataNodeTest() {
+    TShowDataNodesResp showDataNodesResp = null;
+    TDataNodeRegisterReq dataNodeRegisterReq;
+    TDataNodeRegisterResp dataNodeRegisterResp;
+    TDataNodeConfigurationResp dataNodeConfigurationResp;
+    TDataNodeRemoveReq removeReq;
+    TDataNodeRemoveResp removeResp;
+
+    List<ConfigNodeWrapper> configNodeWrappers = EnvFactory.getEnv().getConfigNodeWrapperList();
+    List<DataNodeWrapper> dataNodeWrappers = EnvFactory.getEnv().getDataNodeWrapperList();
+    TDataNodeLocation dataNodeLocation = new TDataNodeLocation();
+    TDataNodeConfiguration dataNodeConfiguration = new TDataNodeConfiguration();
+    List<TDataNodeLocation> removeDataNodeLocationList = new ArrayList<>();
+    List<TDataNodeInfo> dataNodeInfos;
+
+    try (SyncConfigNodeIServiceClient client =
+        (SyncConfigNodeIServiceClient) EnvFactory.getEnv().getConfigNodeConnection()) {
+      // add DataNode
+      DataNodeWrapper dataNodeWrapper =
+          new DataNodeWrapper(
+              configNodeWrappers.get(0).getIpAndPortString(),
+              "IoTDBConfigNodeIT",
+              "dataNodeTest",
+              EnvUtils.searchAvailablePorts());
+      dataNodeWrapper.createDir();
+      dataNodeWrapper.changeConfig(ConfigFactory.getConfig().getEngineProperties());
+      dataNodeWrapper.start();
+      dataNodeWrappers.add(dataNodeWrapper);
+
+      EnvFactory.getEnv().setDataNodeWrapperList(dataNodeWrappers);
+      for (int i = 0; i < retryNum; i++) {
+        showDataNodesResp = client.showDataNodes();
+        if (showDataNodesResp.getDataNodesInfoListSize() == 4) {
+          break;
+        }
+        Thread.sleep(1000);
+      }
+      assertEquals(4, showDataNodesResp.getDataNodesInfoListSize());
+
+      dataNodeInfos = showDataNodesResp.getDataNodesInfoList();
+      dataNodeConfiguration.setLocation(dataNodeLocation);
+      dataNodeConfiguration.setResource(new TNodeResource(8, 1024 * 1024));
+      dataNodeRegisterReq = new TDataNodeRegisterReq(dataNodeConfiguration);
+      TDataNodeInfo dataNodeInfo = dataNodeInfos.get(3);
+
+      // test success re-register
+      dataNodeLocation.setDataNodeId(dataNodeInfo.getDataNodeId());
+      dataNodeLocation.setClientRpcEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort()));
+      dataNodeLocation.setMPPDataExchangeEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 1));
+      dataNodeLocation.setInternalEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 2));
+      dataNodeLocation.setDataRegionConsensusEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 3));
+      dataNodeLocation.setSchemaRegionConsensusEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 4));
+
+      dataNodeRegisterResp = client.registerDataNode(dataNodeRegisterReq);
+      assertEquals(
+          TSStatusCode.DATANODE_ALREADY_REGISTERED.getStatusCode(),
+          dataNodeRegisterResp.getStatus().getCode());
+
+      // test query all DataNodeInfos
+      dataNodeConfigurationResp = client.getDataNodeConfiguration(-1);
+      Map<Integer, TDataNodeConfiguration> infoMap =
+          dataNodeConfigurationResp.getDataNodeConfigurationMap();
+      assertEquals(
+          TSStatusCode.SUCCESS_STATUS.getStatusCode(),
+          dataNodeConfigurationResp.getStatus().getCode());
+      assertEquals(4, infoMap.size());
+      List<Map.Entry<Integer, TDataNodeConfiguration>> infoList =
+          new ArrayList<>(infoMap.entrySet());
+      infoList.sort(Comparator.comparingInt(Map.Entry::getKey));
+      int count = 0;
+      for (DataNodeWrapper expectedDataNode : dataNodeWrappers) {
+        for (int i = 0; i < 4; i++) {
+          TDataNodeLocation dnLocation = infoList.get(i).getValue().getLocation();
+          if (expectedDataNode.getInternalPort() == dnLocation.getInternalEndPoint().getPort()
+              && expectedDataNode.getMppDataExchangePort()
+                  == dnLocation.getMPPDataExchangeEndPoint().getPort()
+              && expectedDataNode.getSchemaRegionConsensusPort()
+                  == dnLocation.getSchemaRegionConsensusEndPoint().getPort()
+              && expectedDataNode.getDataRegionConsensusPort()
+                  == dnLocation.getDataRegionConsensusEndPoint().getPort()) {
+            count++;
+            break;
+          }
+        }
+      }
+      assertEquals(4, count);
+
+      // test query one DataNodeInfo
+      dataNodeConfigurationResp = client.getDataNodeConfiguration(dataNodeLocation.getDataNodeId());
+      infoMap = dataNodeConfigurationResp.getDataNodeConfigurationMap();
+      TDataNodeLocation dnLocation =
+          dataNodeConfigurationResp
+              .getDataNodeConfigurationMap()
+              .get(dataNodeLocation.getDataNodeId())
+              .getLocation();
+      assertEquals(
+          TSStatusCode.SUCCESS_STATUS.getStatusCode(),
+          dataNodeConfigurationResp.getStatus().getCode());
+      assertEquals(1, infoMap.size());
+      assertEquals(dataNodeLocation, dnLocation);
+
+      // test remove DataNode
+      removeDataNodeLocationList.add(dataNodeLocation);
+      removeReq = new TDataNodeRemoveReq(removeDataNodeLocationList);
+      removeResp = client.removeDataNode(removeReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), removeResp.getStatus().getCode());
+
+      for (int i = 0; i < retryNum; i++) {
+        showDataNodesResp = client.showDataNodes();
+        if (showDataNodesResp.getDataNodesInfoListSize() == 3) {
+          break;
+        }
+        Thread.sleep(1000);
+      }
+      assertEquals(3, showDataNodesResp.getDataNodesInfoListSize());
+
+      dataNodeInfos = showDataNodesResp.getDataNodesInfoList();
+      for (TDataNodeInfo dnInfo : dataNodeInfos) {
+        assertNotEquals(dataNodeLocation.getDataNodeId(), dnInfo.getDataNodeId());
+      }
+      dataNodeConfigurationResp = client.getDataNodeConfiguration(dataNodeLocation.getDataNodeId());
+      assertEquals(
+          TSStatusCode.SUCCESS_STATUS.getStatusCode(),
+          dataNodeConfigurationResp.getStatus().getCode());
+      assertEquals(0, dataNodeConfigurationResp.getDataNodeConfigurationMap().size());
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
+
+  @Test
+  public void showClusterAndDataNodesTest() {

Review Comment:
   We also need show confignodes test



##########
integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBConfigNodeIT.java:
##########
@@ -204,6 +228,597 @@ public void removeAndStopConfigNodeTest() {
       assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
     } catch (Exception e) {
       e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
+
+  @Test
+  public void queryAndRemoveDataNodeTest() {
+    TShowDataNodesResp showDataNodesResp = null;
+    TDataNodeRegisterReq dataNodeRegisterReq;
+    TDataNodeRegisterResp dataNodeRegisterResp;
+    TDataNodeConfigurationResp dataNodeConfigurationResp;
+    TDataNodeRemoveReq removeReq;
+    TDataNodeRemoveResp removeResp;
+
+    List<ConfigNodeWrapper> configNodeWrappers = EnvFactory.getEnv().getConfigNodeWrapperList();
+    List<DataNodeWrapper> dataNodeWrappers = EnvFactory.getEnv().getDataNodeWrapperList();
+    TDataNodeLocation dataNodeLocation = new TDataNodeLocation();
+    TDataNodeConfiguration dataNodeConfiguration = new TDataNodeConfiguration();
+    List<TDataNodeLocation> removeDataNodeLocationList = new ArrayList<>();
+    List<TDataNodeInfo> dataNodeInfos;
+
+    try (SyncConfigNodeIServiceClient client =
+        (SyncConfigNodeIServiceClient) EnvFactory.getEnv().getConfigNodeConnection()) {
+      // add DataNode
+      DataNodeWrapper dataNodeWrapper =
+          new DataNodeWrapper(
+              configNodeWrappers.get(0).getIpAndPortString(),
+              "IoTDBConfigNodeIT",
+              "dataNodeTest",
+              EnvUtils.searchAvailablePorts());
+      dataNodeWrapper.createDir();
+      dataNodeWrapper.changeConfig(ConfigFactory.getConfig().getEngineProperties());
+      dataNodeWrapper.start();
+      dataNodeWrappers.add(dataNodeWrapper);
+
+      EnvFactory.getEnv().setDataNodeWrapperList(dataNodeWrappers);
+      for (int i = 0; i < retryNum; i++) {
+        showDataNodesResp = client.showDataNodes();
+        if (showDataNodesResp.getDataNodesInfoListSize() == 4) {
+          break;
+        }
+        Thread.sleep(1000);
+      }
+      assertEquals(4, showDataNodesResp.getDataNodesInfoListSize());
+
+      dataNodeInfos = showDataNodesResp.getDataNodesInfoList();
+      dataNodeConfiguration.setLocation(dataNodeLocation);
+      dataNodeConfiguration.setResource(new TNodeResource(8, 1024 * 1024));
+      dataNodeRegisterReq = new TDataNodeRegisterReq(dataNodeConfiguration);
+      TDataNodeInfo dataNodeInfo = dataNodeInfos.get(3);
+
+      // test success re-register
+      dataNodeLocation.setDataNodeId(dataNodeInfo.getDataNodeId());
+      dataNodeLocation.setClientRpcEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort()));
+      dataNodeLocation.setMPPDataExchangeEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 1));
+      dataNodeLocation.setInternalEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 2));
+      dataNodeLocation.setDataRegionConsensusEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 3));
+      dataNodeLocation.setSchemaRegionConsensusEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 4));
+
+      dataNodeRegisterResp = client.registerDataNode(dataNodeRegisterReq);
+      assertEquals(
+          TSStatusCode.DATANODE_ALREADY_REGISTERED.getStatusCode(),
+          dataNodeRegisterResp.getStatus().getCode());
+
+      // test query all DataNodeInfos
+      dataNodeConfigurationResp = client.getDataNodeConfiguration(-1);
+      Map<Integer, TDataNodeConfiguration> infoMap =
+          dataNodeConfigurationResp.getDataNodeConfigurationMap();
+      assertEquals(
+          TSStatusCode.SUCCESS_STATUS.getStatusCode(),
+          dataNodeConfigurationResp.getStatus().getCode());
+      assertEquals(4, infoMap.size());
+      List<Map.Entry<Integer, TDataNodeConfiguration>> infoList =
+          new ArrayList<>(infoMap.entrySet());
+      infoList.sort(Comparator.comparingInt(Map.Entry::getKey));
+      int count = 0;
+      for (DataNodeWrapper expectedDataNode : dataNodeWrappers) {
+        for (int i = 0; i < 4; i++) {
+          TDataNodeLocation dnLocation = infoList.get(i).getValue().getLocation();
+          if (expectedDataNode.getInternalPort() == dnLocation.getInternalEndPoint().getPort()
+              && expectedDataNode.getMppDataExchangePort()
+                  == dnLocation.getMPPDataExchangeEndPoint().getPort()
+              && expectedDataNode.getSchemaRegionConsensusPort()
+                  == dnLocation.getSchemaRegionConsensusEndPoint().getPort()
+              && expectedDataNode.getDataRegionConsensusPort()
+                  == dnLocation.getDataRegionConsensusEndPoint().getPort()) {
+            count++;
+            break;
+          }
+        }
+      }
+      assertEquals(4, count);
+
+      // test query one DataNodeInfo
+      dataNodeConfigurationResp = client.getDataNodeConfiguration(dataNodeLocation.getDataNodeId());
+      infoMap = dataNodeConfigurationResp.getDataNodeConfigurationMap();
+      TDataNodeLocation dnLocation =
+          dataNodeConfigurationResp
+              .getDataNodeConfigurationMap()
+              .get(dataNodeLocation.getDataNodeId())
+              .getLocation();
+      assertEquals(
+          TSStatusCode.SUCCESS_STATUS.getStatusCode(),
+          dataNodeConfigurationResp.getStatus().getCode());
+      assertEquals(1, infoMap.size());
+      assertEquals(dataNodeLocation, dnLocation);
+
+      // test remove DataNode
+      removeDataNodeLocationList.add(dataNodeLocation);
+      removeReq = new TDataNodeRemoveReq(removeDataNodeLocationList);
+      removeResp = client.removeDataNode(removeReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), removeResp.getStatus().getCode());
+
+      for (int i = 0; i < retryNum; i++) {
+        showDataNodesResp = client.showDataNodes();
+        if (showDataNodesResp.getDataNodesInfoListSize() == 3) {
+          break;
+        }
+        Thread.sleep(1000);
+      }
+      assertEquals(3, showDataNodesResp.getDataNodesInfoListSize());
+
+      dataNodeInfos = showDataNodesResp.getDataNodesInfoList();
+      for (TDataNodeInfo dnInfo : dataNodeInfos) {
+        assertNotEquals(dataNodeLocation.getDataNodeId(), dnInfo.getDataNodeId());
+      }
+      dataNodeConfigurationResp = client.getDataNodeConfiguration(dataNodeLocation.getDataNodeId());
+      assertEquals(
+          TSStatusCode.SUCCESS_STATUS.getStatusCode(),
+          dataNodeConfigurationResp.getStatus().getCode());
+      assertEquals(0, dataNodeConfigurationResp.getDataNodeConfigurationMap().size());
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
+
+  @Test
+  public void showClusterAndDataNodesTest() {
+    try (SyncConfigNodeIServiceClient client =
+        (SyncConfigNodeIServiceClient) EnvFactory.getEnv().getConfigNodeConnection()) {
+      List<ConfigNodeWrapper> configNodeWrappers = EnvFactory.getEnv().getConfigNodeWrapperList();
+      List<DataNodeWrapper> dataNodeWrappers = EnvFactory.getEnv().getDataNodeWrapperList();
+
+      // test showCluster
+      TShowClusterResp clusterNodes = getClusterNodeInfos(client, 1, 3);
+      List<TConfigNodeLocation> configNodeLocations = clusterNodes.getConfigNodeList();
+      List<TDataNodeLocation> dataNodeLocations = clusterNodes.getDataNodeList();
+
+      for (TConfigNodeLocation configNodeLocation : configNodeLocations) {
+        boolean found = false;
+        for (ConfigNodeWrapper configNodeWrapper : configNodeWrappers) {
+          if (configNodeWrapper.getIp().equals(configNodeLocation.getInternalEndPoint().getIp())
+              && configNodeWrapper.getPort() == configNodeLocation.getInternalEndPoint().getPort()
+              && configNodeWrapper.getConsensusPort()
+                  == configNodeLocation.getConsensusEndPoint().getPort()) {
+            found = true;
+            break;
+          }
+        }
+        assertTrue(found);
+      }
+
+      for (TDataNodeLocation dataNodeLocation : dataNodeLocations) {
+        boolean found = false;
+        for (DataNodeWrapper dataNodeWrapper : dataNodeWrappers) {
+          if (dataNodeWrapper.getIp().equals(dataNodeLocation.getInternalEndPoint().getIp())
+              && dataNodeWrapper.getPort() == dataNodeLocation.getClientRpcEndPoint().getPort()
+              && dataNodeWrapper.getInternalPort()
+                  == dataNodeLocation.getInternalEndPoint().getPort()
+              && dataNodeWrapper.getMppDataExchangePort()
+                  == dataNodeLocation.getMPPDataExchangeEndPoint().getPort()
+              && dataNodeWrapper.getSchemaRegionConsensusPort()
+                  == dataNodeLocation.getSchemaRegionConsensusEndPoint().getPort()
+              && dataNodeWrapper.getDataRegionConsensusPort()
+                  == dataNodeLocation.getDataRegionConsensusEndPoint().getPort()) {
+            found = true;
+            break;
+          }
+        }
+        assertTrue(found);
+      }
+
+      // test showDataNodes
+      TShowDataNodesResp showDataNodesResp = client.showDataNodes();
+      List<TDataNodeInfo> dataNodesInfo = showDataNodesResp.getDataNodesInfoList();
+
+      for (TDataNodeInfo dataNodeInfo : dataNodesInfo) {
+        boolean found = false;
+        for (DataNodeWrapper dataNodeWrapper : dataNodeWrappers) {
+          if (dataNodeWrapper.getIp().equals(dataNodeInfo.getRpcAddresss())
+              && dataNodeWrapper.getPort() == dataNodeInfo.getRpcPort()) {
+            found = true;
+            break;
+          }
+        }
+        assertTrue(found);
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
+
+  private void cleanUserAndRole(IConfigNodeRPCService.Iface client) throws TException {
+    TSStatus status;
+
+    // clean user
+    TAuthorizerReq authorizerReq =
+        new TAuthorizerReq(
+            AuthorOperator.AuthorType.LIST_USER.ordinal(),
+            "",
+            "",
+            "",
+            "",
+            new HashSet<>(),
+            Collections.singletonList(""));
+    TAuthorizerResp authorizerResp = client.queryPermission(authorizerReq);
+    status = authorizerResp.getStatus();
+    assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+    List<String> allUsers = authorizerResp.getAuthorizerInfo().get(IoTDBConstant.COLUMN_USER);
+    for (String user : allUsers) {
+      if (!user.equals("root")) {
+        authorizerReq =
+            new TAuthorizerReq(
+                AuthorOperator.AuthorType.DROP_USER.ordinal(),
+                user,
+                "",
+                "",
+                "",
+                new HashSet<>(),
+                Collections.singletonList(""));
+        status = client.operatePermission(authorizerReq);
+        assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+      }
+    }
+  }
+
+  @Test
+  public void permissionTest() {
+    TSStatus status;
+    List<String> userList = new ArrayList<>();
+    userList.add("root");
+    userList.add("tempuser0");
+    userList.add("tempuser1");
+
+    List<String> roleList = new ArrayList<>();
+    roleList.add("temprole0");
+    roleList.add("temprole1");
+
+    TAuthorizerReq authorizerReq;
+    TAuthorizerResp authorizerResp;
+    TCheckUserPrivilegesReq checkUserPrivilegesReq;
+
+    Set<Integer> privilegeList = new HashSet<>();
+    privilegeList.add(PrivilegeType.DELETE_USER.ordinal());
+    privilegeList.add(PrivilegeType.CREATE_USER.ordinal());
+
+    Set<Integer> revokePrivilege = new HashSet<>();
+    revokePrivilege.add(PrivilegeType.DELETE_USER.ordinal());
+
+    List<String> privilege = new ArrayList<>();
+    privilege.add("root.** : CREATE_USER");
+    privilege.add("root.** : CREATE_USER");
+
+    List<String> paths = new ArrayList<>();
+    paths.add("root.ln.**");
+
+    try (SyncConfigNodeIServiceClient client =
+        (SyncConfigNodeIServiceClient) EnvFactory.getEnv().getConfigNodeConnection()) {
+      cleanUserAndRole(client);
+
+      // create user
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.CREATE_USER.ordinal(),
+              "tempuser0",
+              "",
+              "passwd",
+              "",
+              new HashSet<>(),
+              new ArrayList<>());
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+      authorizerReq.setUserName("tempuser1");
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+      // check user privileges
+      checkUserPrivilegesReq =
+          new TCheckUserPrivilegesReq("tempuser0", paths, PrivilegeType.DELETE_USER.ordinal());
+      status = client.checkUserPrivileges(checkUserPrivilegesReq).getStatus();
+      assertEquals(TSStatusCode.NO_PERMISSION_ERROR.getStatusCode(), status.getCode());
+
+      // drop user
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.DROP_USER.ordinal(),
+              "tempuser1",
+              "",
+              "",
+              "",
+              new HashSet<>(),
+              new ArrayList<>());
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+      // list user
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.LIST_USER.ordinal(),
+              "",
+              "",
+              "",
+              "",
+              new HashSet<>(),
+              new ArrayList<>());
+      authorizerResp = client.queryPermission(authorizerReq);
+      status = authorizerResp.getStatus();
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+      userList.remove("tempuser1");
+      assertEquals(userList, authorizerResp.getAuthorizerInfo().get(IoTDBConstant.COLUMN_USER));
+
+      // create role
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.CREATE_ROLE.ordinal(),
+              "",
+              "temprole0",
+              "",
+              "",
+              new HashSet<>(),
+              new ArrayList<>());
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+      authorizerReq.setRoleName("temprole1");
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+      // drop role
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.DROP_ROLE.ordinal(),
+              "",
+              "temprole1",
+              "",
+              "",
+              new HashSet<>(),
+              new ArrayList<>());
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+      // list role
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.LIST_ROLE.ordinal(),
+              "",
+              "",
+              "",
+              "",
+              new HashSet<>(),
+              new ArrayList<>());
+      authorizerResp = client.queryPermission(authorizerReq);
+      status = authorizerResp.getStatus();
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+      roleList.remove("temprole1");
+      assertEquals(roleList, authorizerResp.getAuthorizerInfo().get(IoTDBConstant.COLUMN_ROLE));
+
+      // alter user
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.UPDATE_USER.ordinal(),
+              "tempuser0",
+              "",
+              "",
+              "newpwd",
+              new HashSet<>(),
+              new ArrayList<>());
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+      // grant user
+      List<String> nodeNameList = new ArrayList<>();
+      nodeNameList.add("root.ln.**");
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.GRANT_USER.ordinal(),
+              "tempuser0",
+              "",
+              "",
+              "",
+              privilegeList,
+              nodeNameList);
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+      // check user privileges
+      checkUserPrivilegesReq =
+          new TCheckUserPrivilegesReq("tempuser0", paths, PrivilegeType.DELETE_USER.ordinal());
+      status = client.checkUserPrivileges(checkUserPrivilegesReq).getStatus();
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+      // grant role
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.GRANT_ROLE.ordinal(),
+              "",
+              "temprole0",
+              "",
+              "",
+              privilegeList,
+              nodeNameList);
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+      // grant role to user
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.GRANT_ROLE_TO_USER.ordinal(),
+              "tempuser0",
+              "temprole0",
+              "",
+              "",
+              new HashSet<>(),
+              nodeNameList);
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+      // revoke user
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.REVOKE_USER.ordinal(),
+              "tempuser0",
+              "",
+              "",
+              "",
+              revokePrivilege,
+              nodeNameList);
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+      // revoke role
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.REVOKE_ROLE.ordinal(),
+              "",
+              "temprole0",
+              "",
+              "",
+              revokePrivilege,
+              nodeNameList);
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+      // list privileges user
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.LIST_USER_PRIVILEGE.ordinal(),
+              "tempuser0",
+              "",
+              "",
+              "",
+              new HashSet<>(),
+              nodeNameList);
+      authorizerResp = client.queryPermission(authorizerReq);
+      status = authorizerResp.getStatus();
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+      assertEquals(
+          privilege, authorizerResp.getAuthorizerInfo().get(IoTDBConstant.COLUMN_PRIVILEGE));
+
+      // list user privileges
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.LIST_USER_PRIVILEGE.ordinal(),
+              "tempuser0",
+              "",
+              "",
+              "",
+              new HashSet<>(),
+              new ArrayList<>());
+      authorizerResp = client.queryPermission(authorizerReq);
+      status = authorizerResp.getStatus();
+      Assert.assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+      Assert.assertEquals(
+          privilege, authorizerResp.getAuthorizerInfo().get(IoTDBConstant.COLUMN_PRIVILEGE));
+
+      // list privileges role
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.LIST_ROLE_PRIVILEGE.ordinal(),
+              "",
+              "temprole0",
+              "",
+              "",
+              new HashSet<>(),
+              nodeNameList);
+      authorizerResp = client.queryPermission(authorizerReq);
+      status = authorizerResp.getStatus();
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+      privilege.remove(0);
+      assertEquals(
+          privilege, authorizerResp.getAuthorizerInfo().get(IoTDBConstant.COLUMN_PRIVILEGE));
+
+      // list role privileges
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.LIST_ROLE_PRIVILEGE.ordinal(),
+              "",
+              "temprole0",
+              "",
+              "",
+              new HashSet<>(),
+              new ArrayList<>());
+      authorizerResp = client.queryPermission(authorizerReq);
+      status = authorizerResp.getStatus();
+      Assert.assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+      Assert.assertEquals(
+          privilege, authorizerResp.getAuthorizerInfo().get(IoTDBConstant.COLUMN_PRIVILEGE));
+
+      // list all role of user
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.LIST_ROLE.ordinal(),
+              "tempuser0",
+              "",
+              "",
+              "",
+              new HashSet<>(),
+              new ArrayList<>());
+      authorizerResp = client.queryPermission(authorizerReq);
+      status = authorizerResp.getStatus();
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+      roleList.remove("temprole1");
+      assertEquals(roleList, authorizerResp.getAuthorizerInfo().get(IoTDBConstant.COLUMN_ROLE));
+
+      // list all user of role
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.LIST_USER.ordinal(),
+              "",
+              "temprole0",
+              "",
+              "",
+              new HashSet<>(),
+              new ArrayList<>());
+      authorizerResp = client.queryPermission(authorizerReq);
+      status = authorizerResp.getStatus();
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+      userList.remove("tempuser1");
+      userList.remove("root");
+      assertEquals(userList, authorizerResp.getAuthorizerInfo().get(IoTDBConstant.COLUMN_USER));
+
+      // revoke role from user
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.REVOKE_ROLE_FROM_USER.ordinal(),
+              "tempuser0",
+              "temprole0",
+              "",
+              "",
+              new HashSet<>(),
+              new ArrayList<>());
+      status = client.operatePermission(authorizerReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+
+      // list root privileges
+      authorizerReq =
+          new TAuthorizerReq(
+              AuthorOperator.AuthorType.LIST_USER_PRIVILEGE.ordinal(),
+              "root",
+              "",
+              "",
+              "",
+              new HashSet<>(),
+              new ArrayList<>());
+      authorizerResp = client.queryPermission(authorizerReq);
+      status = authorizerResp.getStatus();
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+      for (int i = 0; i < PrivilegeType.values().length; i++) {
+        assertEquals(
+            PrivilegeType.values()[i].toString(),
+            authorizerResp.getAuthorizerInfo().get(IoTDBConstant.COLUMN_PRIVILEGE).get(i));
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.getMessage());

Review Comment:
   Just throw any Exceptions in the interface, we don't need to catch and print them since it's a test code



##########
integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBConfigNodeIT.java:
##########
@@ -204,6 +228,597 @@ public void removeAndStopConfigNodeTest() {
       assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
     } catch (Exception e) {
       e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
+
+  @Test
+  public void queryAndRemoveDataNodeTest() {
+    TShowDataNodesResp showDataNodesResp = null;
+    TDataNodeRegisterReq dataNodeRegisterReq;
+    TDataNodeRegisterResp dataNodeRegisterResp;
+    TDataNodeConfigurationResp dataNodeConfigurationResp;
+    TDataNodeRemoveReq removeReq;
+    TDataNodeRemoveResp removeResp;
+
+    List<ConfigNodeWrapper> configNodeWrappers = EnvFactory.getEnv().getConfigNodeWrapperList();
+    List<DataNodeWrapper> dataNodeWrappers = EnvFactory.getEnv().getDataNodeWrapperList();
+    TDataNodeLocation dataNodeLocation = new TDataNodeLocation();
+    TDataNodeConfiguration dataNodeConfiguration = new TDataNodeConfiguration();
+    List<TDataNodeLocation> removeDataNodeLocationList = new ArrayList<>();
+    List<TDataNodeInfo> dataNodeInfos;
+
+    try (SyncConfigNodeIServiceClient client =
+        (SyncConfigNodeIServiceClient) EnvFactory.getEnv().getConfigNodeConnection()) {
+      // add DataNode
+      DataNodeWrapper dataNodeWrapper =
+          new DataNodeWrapper(
+              configNodeWrappers.get(0).getIpAndPortString(),
+              "IoTDBConfigNodeIT",
+              "dataNodeTest",
+              EnvUtils.searchAvailablePorts());
+      dataNodeWrapper.createDir();
+      dataNodeWrapper.changeConfig(ConfigFactory.getConfig().getEngineProperties());
+      dataNodeWrapper.start();
+      dataNodeWrappers.add(dataNodeWrapper);
+
+      EnvFactory.getEnv().setDataNodeWrapperList(dataNodeWrappers);
+      for (int i = 0; i < retryNum; i++) {
+        showDataNodesResp = client.showDataNodes();
+        if (showDataNodesResp.getDataNodesInfoListSize() == 4) {
+          break;
+        }
+        Thread.sleep(1000);
+      }
+      assertEquals(4, showDataNodesResp.getDataNodesInfoListSize());
+
+      dataNodeInfos = showDataNodesResp.getDataNodesInfoList();
+      dataNodeConfiguration.setLocation(dataNodeLocation);
+      dataNodeConfiguration.setResource(new TNodeResource(8, 1024 * 1024));
+      dataNodeRegisterReq = new TDataNodeRegisterReq(dataNodeConfiguration);
+      TDataNodeInfo dataNodeInfo = dataNodeInfos.get(3);
+
+      // test success re-register
+      dataNodeLocation.setDataNodeId(dataNodeInfo.getDataNodeId());
+      dataNodeLocation.setClientRpcEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort()));
+      dataNodeLocation.setMPPDataExchangeEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 1));
+      dataNodeLocation.setInternalEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 2));
+      dataNodeLocation.setDataRegionConsensusEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 3));
+      dataNodeLocation.setSchemaRegionConsensusEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 4));
+
+      dataNodeRegisterResp = client.registerDataNode(dataNodeRegisterReq);
+      assertEquals(
+          TSStatusCode.DATANODE_ALREADY_REGISTERED.getStatusCode(),
+          dataNodeRegisterResp.getStatus().getCode());
+
+      // test query all DataNodeInfos
+      dataNodeConfigurationResp = client.getDataNodeConfiguration(-1);
+      Map<Integer, TDataNodeConfiguration> infoMap =
+          dataNodeConfigurationResp.getDataNodeConfigurationMap();
+      assertEquals(
+          TSStatusCode.SUCCESS_STATUS.getStatusCode(),
+          dataNodeConfigurationResp.getStatus().getCode());
+      assertEquals(4, infoMap.size());
+      List<Map.Entry<Integer, TDataNodeConfiguration>> infoList =
+          new ArrayList<>(infoMap.entrySet());
+      infoList.sort(Comparator.comparingInt(Map.Entry::getKey));
+      int count = 0;
+      for (DataNodeWrapper expectedDataNode : dataNodeWrappers) {
+        for (int i = 0; i < 4; i++) {
+          TDataNodeLocation dnLocation = infoList.get(i).getValue().getLocation();
+          if (expectedDataNode.getInternalPort() == dnLocation.getInternalEndPoint().getPort()
+              && expectedDataNode.getMppDataExchangePort()
+                  == dnLocation.getMPPDataExchangeEndPoint().getPort()
+              && expectedDataNode.getSchemaRegionConsensusPort()
+                  == dnLocation.getSchemaRegionConsensusEndPoint().getPort()
+              && expectedDataNode.getDataRegionConsensusPort()
+                  == dnLocation.getDataRegionConsensusEndPoint().getPort()) {
+            count++;
+            break;
+          }
+        }
+      }
+      assertEquals(4, count);
+
+      // test query one DataNodeInfo
+      dataNodeConfigurationResp = client.getDataNodeConfiguration(dataNodeLocation.getDataNodeId());
+      infoMap = dataNodeConfigurationResp.getDataNodeConfigurationMap();
+      TDataNodeLocation dnLocation =
+          dataNodeConfigurationResp
+              .getDataNodeConfigurationMap()
+              .get(dataNodeLocation.getDataNodeId())
+              .getLocation();
+      assertEquals(
+          TSStatusCode.SUCCESS_STATUS.getStatusCode(),
+          dataNodeConfigurationResp.getStatus().getCode());
+      assertEquals(1, infoMap.size());
+      assertEquals(dataNodeLocation, dnLocation);
+
+      // test remove DataNode
+      removeDataNodeLocationList.add(dataNodeLocation);
+      removeReq = new TDataNodeRemoveReq(removeDataNodeLocationList);
+      removeResp = client.removeDataNode(removeReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), removeResp.getStatus().getCode());
+
+      for (int i = 0; i < retryNum; i++) {
+        showDataNodesResp = client.showDataNodes();
+        if (showDataNodesResp.getDataNodesInfoListSize() == 3) {
+          break;
+        }
+        Thread.sleep(1000);
+      }
+      assertEquals(3, showDataNodesResp.getDataNodesInfoListSize());
+
+      dataNodeInfos = showDataNodesResp.getDataNodesInfoList();
+      for (TDataNodeInfo dnInfo : dataNodeInfos) {
+        assertNotEquals(dataNodeLocation.getDataNodeId(), dnInfo.getDataNodeId());
+      }
+      dataNodeConfigurationResp = client.getDataNodeConfiguration(dataNodeLocation.getDataNodeId());
+      assertEquals(
+          TSStatusCode.SUCCESS_STATUS.getStatusCode(),
+          dataNodeConfigurationResp.getStatus().getCode());
+      assertEquals(0, dataNodeConfigurationResp.getDataNodeConfigurationMap().size());
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }

Review Comment:
   Just throw any Exceptions in the interface, we don't need to catch and print them since it's a test code



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] MiniSho commented on a diff in pull request #6906: [IOTDB-3821] add some new test cases for ConfigNodeIT

Posted by GitBox <gi...@apache.org>.
MiniSho commented on code in PR #6906:
URL: https://github.com/apache/iotdb/pull/6906#discussion_r939786236


##########
integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBConfigNodeIT.java:
##########
@@ -204,6 +228,597 @@ public void removeAndStopConfigNodeTest() {
       assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
     } catch (Exception e) {
       e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
+
+  @Test
+  public void queryAndRemoveDataNodeTest() {
+    TShowDataNodesResp showDataNodesResp = null;
+    TDataNodeRegisterReq dataNodeRegisterReq;
+    TDataNodeRegisterResp dataNodeRegisterResp;
+    TDataNodeConfigurationResp dataNodeConfigurationResp;
+    TDataNodeRemoveReq removeReq;
+    TDataNodeRemoveResp removeResp;
+
+    List<ConfigNodeWrapper> configNodeWrappers = EnvFactory.getEnv().getConfigNodeWrapperList();
+    List<DataNodeWrapper> dataNodeWrappers = EnvFactory.getEnv().getDataNodeWrapperList();
+    TDataNodeLocation dataNodeLocation = new TDataNodeLocation();
+    TDataNodeConfiguration dataNodeConfiguration = new TDataNodeConfiguration();
+    List<TDataNodeLocation> removeDataNodeLocationList = new ArrayList<>();
+    List<TDataNodeInfo> dataNodeInfos;
+
+    try (SyncConfigNodeIServiceClient client =
+        (SyncConfigNodeIServiceClient) EnvFactory.getEnv().getConfigNodeConnection()) {
+      // add DataNode
+      DataNodeWrapper dataNodeWrapper =
+          new DataNodeWrapper(
+              configNodeWrappers.get(0).getIpAndPortString(),
+              "IoTDBConfigNodeIT",
+              "dataNodeTest",
+              EnvUtils.searchAvailablePorts());
+      dataNodeWrapper.createDir();
+      dataNodeWrapper.changeConfig(ConfigFactory.getConfig().getEngineProperties());
+      dataNodeWrapper.start();
+      dataNodeWrappers.add(dataNodeWrapper);
+
+      EnvFactory.getEnv().setDataNodeWrapperList(dataNodeWrappers);
+      for (int i = 0; i < retryNum; i++) {
+        showDataNodesResp = client.showDataNodes();
+        if (showDataNodesResp.getDataNodesInfoListSize() == 4) {
+          break;
+        }
+        Thread.sleep(1000);
+      }
+      assertEquals(4, showDataNodesResp.getDataNodesInfoListSize());
+
+      dataNodeInfos = showDataNodesResp.getDataNodesInfoList();
+      dataNodeConfiguration.setLocation(dataNodeLocation);
+      dataNodeConfiguration.setResource(new TNodeResource(8, 1024 * 1024));
+      dataNodeRegisterReq = new TDataNodeRegisterReq(dataNodeConfiguration);
+      TDataNodeInfo dataNodeInfo = dataNodeInfos.get(3);
+
+      // test success re-register
+      dataNodeLocation.setDataNodeId(dataNodeInfo.getDataNodeId());
+      dataNodeLocation.setClientRpcEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort()));
+      dataNodeLocation.setMPPDataExchangeEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 1));
+      dataNodeLocation.setInternalEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 2));
+      dataNodeLocation.setDataRegionConsensusEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 3));
+      dataNodeLocation.setSchemaRegionConsensusEndPoint(
+          new TEndPoint(dataNodeInfo.getRpcAddresss(), dataNodeInfo.getRpcPort() + 4));
+
+      dataNodeRegisterResp = client.registerDataNode(dataNodeRegisterReq);
+      assertEquals(
+          TSStatusCode.DATANODE_ALREADY_REGISTERED.getStatusCode(),
+          dataNodeRegisterResp.getStatus().getCode());
+
+      // test query all DataNodeInfos
+      dataNodeConfigurationResp = client.getDataNodeConfiguration(-1);
+      Map<Integer, TDataNodeConfiguration> infoMap =
+          dataNodeConfigurationResp.getDataNodeConfigurationMap();
+      assertEquals(
+          TSStatusCode.SUCCESS_STATUS.getStatusCode(),
+          dataNodeConfigurationResp.getStatus().getCode());
+      assertEquals(4, infoMap.size());
+      List<Map.Entry<Integer, TDataNodeConfiguration>> infoList =
+          new ArrayList<>(infoMap.entrySet());
+      infoList.sort(Comparator.comparingInt(Map.Entry::getKey));
+      int count = 0;
+      for (DataNodeWrapper expectedDataNode : dataNodeWrappers) {
+        for (int i = 0; i < 4; i++) {
+          TDataNodeLocation dnLocation = infoList.get(i).getValue().getLocation();
+          if (expectedDataNode.getInternalPort() == dnLocation.getInternalEndPoint().getPort()
+              && expectedDataNode.getMppDataExchangePort()
+                  == dnLocation.getMPPDataExchangeEndPoint().getPort()
+              && expectedDataNode.getSchemaRegionConsensusPort()
+                  == dnLocation.getSchemaRegionConsensusEndPoint().getPort()
+              && expectedDataNode.getDataRegionConsensusPort()
+                  == dnLocation.getDataRegionConsensusEndPoint().getPort()) {
+            count++;
+            break;
+          }
+        }
+      }
+      assertEquals(4, count);
+
+      // test query one DataNodeInfo
+      dataNodeConfigurationResp = client.getDataNodeConfiguration(dataNodeLocation.getDataNodeId());
+      infoMap = dataNodeConfigurationResp.getDataNodeConfigurationMap();
+      TDataNodeLocation dnLocation =
+          dataNodeConfigurationResp
+              .getDataNodeConfigurationMap()
+              .get(dataNodeLocation.getDataNodeId())
+              .getLocation();
+      assertEquals(
+          TSStatusCode.SUCCESS_STATUS.getStatusCode(),
+          dataNodeConfigurationResp.getStatus().getCode());
+      assertEquals(1, infoMap.size());
+      assertEquals(dataNodeLocation, dnLocation);
+
+      // test remove DataNode
+      removeDataNodeLocationList.add(dataNodeLocation);
+      removeReq = new TDataNodeRemoveReq(removeDataNodeLocationList);
+      removeResp = client.removeDataNode(removeReq);
+      assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), removeResp.getStatus().getCode());
+
+      for (int i = 0; i < retryNum; i++) {
+        showDataNodesResp = client.showDataNodes();
+        if (showDataNodesResp.getDataNodesInfoListSize() == 3) {
+          break;
+        }
+        Thread.sleep(1000);
+      }
+      assertEquals(3, showDataNodesResp.getDataNodesInfoListSize());
+
+      dataNodeInfos = showDataNodesResp.getDataNodesInfoList();
+      for (TDataNodeInfo dnInfo : dataNodeInfos) {
+        assertNotEquals(dataNodeLocation.getDataNodeId(), dnInfo.getDataNodeId());
+      }
+      dataNodeConfigurationResp = client.getDataNodeConfiguration(dataNodeLocation.getDataNodeId());
+      assertEquals(
+          TSStatusCode.SUCCESS_STATUS.getStatusCode(),
+          dataNodeConfigurationResp.getStatus().getCode());
+      assertEquals(0, dataNodeConfigurationResp.getDataNodeConfigurationMap().size());
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
+
+  @Test
+  public void showClusterAndDataNodesTest() {

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org