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/08 03:02:23 UTC

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

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