xyuanlu commented on code in PR #2290:
URL: https://github.com/apache/helix/pull/2290#discussion_r1052755873


##########
helix-core/src/test/java/org/apache/helix/integration/multizk/TestMultiZkHelixJavaApis.java:
##########
@@ -177,347 +92,89 @@ public void beforeClass() throws Exception {
             new RealmAwareZkClient.RealmAwareZkClientConfig());
   }
 
-  @AfterClass
-  public void afterClass() throws Exception {
-    String testClassName = getClass().getSimpleName();
-
-    try {
-      // Kill all mock controllers and participants
-      MOCK_CONTROLLERS.values().forEach(ClusterControllerManager::syncStop);
-      MOCK_PARTICIPANTS.forEach(mockParticipantManager -> {
-        mockParticipantManager.syncStop();
-        StateMachineEngine stateMachine = 
mockParticipantManager.getStateMachineEngine();
-        if (stateMachine != null) {
-          StateModelFactory stateModelFactory = 
stateMachine.getStateModelFactory("Task");
-          if (stateModelFactory != null && stateModelFactory instanceof 
TaskStateModelFactory) {
-            ((TaskStateModelFactory) stateModelFactory).shutdown();
-          }
-        }
-      });
-
-      // Tear down all clusters
-      CLUSTER_LIST.forEach(cluster -> TestHelper.dropCluster(cluster, 
_zkClient));
-
-      // Verify that all clusters are gone in each zookeeper
-      Assert.assertTrue(TestHelper.verify(() -> {
-        for (Map.Entry<String, HelixZkClient> zkClientEntry : 
ZK_CLIENT_MAP.entrySet()) {
-          List<String> children = zkClientEntry.getValue().getChildren("/");
-          if (children.stream().anyMatch(CLUSTER_LIST::contains)) {
-            return false;
-          }
-        }
-        return true;
-      }, TestHelper.WAIT_DURATION));
-
-      // Tear down zookeepers
-      ZK_CLIENT_MAP.forEach((zkAddress, zkClient) -> zkClient.close());
-      ZK_SERVER_MAP.forEach((zkAddress, zkServer) -> zkServer.shutdown());
-
-      // Stop MockMSDS
-      _msds.stopServer();
-
-      // Close ZK client connections
-      _zkHelixAdmin.close();
-      if (_zkClient != null && !_zkClient.isClosed()) {
-        _zkClient.close();
-      }
-    } finally {
-      // Restore System property configs
-      if (_configStore.containsKey(SystemPropertyKeys.MULTI_ZK_ENABLED)) {
-        System.setProperty(SystemPropertyKeys.MULTI_ZK_ENABLED,
-            _configStore.get(SystemPropertyKeys.MULTI_ZK_ENABLED));
-      } else {
-        System.clearProperty(SystemPropertyKeys.MULTI_ZK_ENABLED);
-      }
-      if 
(_configStore.containsKey(MetadataStoreRoutingConstants.MSDS_SERVER_ENDPOINT_KEY))
 {
-        
System.setProperty(MetadataStoreRoutingConstants.MSDS_SERVER_ENDPOINT_KEY,
-            
_configStore.get(MetadataStoreRoutingConstants.MSDS_SERVER_ENDPOINT_KEY));
-      } else {
-        
System.clearProperty(MetadataStoreRoutingConstants.MSDS_SERVER_ENDPOINT_KEY);
-      }
-    }
+  @Override
+  public void setupCluster() {
+    // Create two ClusterSetups using two different constructors
+    // Note: ZK Address here could be anything because multiZk mode is on (it 
will be ignored)
+    _clusterSetupZkAddr = new 
ClusterSetup(ZK_SERVER_MAP.keySet().iterator().next());
+    _clusterSetupBuilder = new ClusterSetup.Builder().build();
   }
 
-  /**
-   * Test cluster creation according to the pre-set routing mapping.
-   * Helix Java API tested is ClusterSetup in this method.
-   */
+  @Override
+  protected void createZkConnectionConfigs(String clusterName) {
+    RealmAwareZkClient.RealmAwareZkConnectionConfig.Builder 
connectionConfigBuilder =
+        new RealmAwareZkClient.RealmAwareZkConnectionConfig.Builder();
+    // Try with a connection config without ZK realm sharding key set (should 
fail)
+    _invalidZkConnectionConfig = connectionConfigBuilder.build();
+    _validZkConnectionConfig = 
connectionConfigBuilder.setZkRealmShardingKey("/" + clusterName).build();
+  }
+  @Override
   @Test
   public void testCreateClusters() {
-    // Create two ClusterSetups using two different constructors
-    // Note: ZK Address here could be anything because multiZk mode is on (it 
will be ignored)
-    ClusterSetup clusterSetupZkAddr = new 
ClusterSetup(ZK_SERVER_MAP.keySet().iterator().next());
-    ClusterSetup clusterSetupBuilder = new ClusterSetup.Builder().build();
+    String methodName = TestHelper.getTestMethodName();
+    System.out.println("START " + _className + "_" + methodName + " at " + new 
Date(System.currentTimeMillis()));
 
-    createClusters(clusterSetupZkAddr);
-    verifyClusterCreation(clusterSetupZkAddr);
+    setupCluster();
 
-    createClusters(clusterSetupBuilder);
-    verifyClusterCreation(clusterSetupBuilder);
+    createClusters(_clusterSetupZkAddr);
+    verifyClusterCreation(_clusterSetupZkAddr);
 
-    // Create clusters again to continue with testing
-    createClusters(clusterSetupBuilder);
+    createClusters(_clusterSetupBuilder);
+    verifyClusterCreation(_clusterSetupBuilder);
 
-    clusterSetupZkAddr.close();
-    clusterSetupBuilder.close();
-  }
-
-  private void createClusters(ClusterSetup clusterSetup) {
-    // Create clusters
-    for (String clusterName : CLUSTER_LIST) {
-      clusterSetup.addCluster(clusterName, false);
-    }
-  }
-
-  private void verifyClusterCreation(ClusterSetup clusterSetup) {
-    // Verify that clusters have been created correctly according to routing 
mapping
-    _rawRoutingData.forEach((zkAddress, cluster) -> {
-      // Note: clusterNamePath already contains "/"
-      String clusterNamePath = cluster.iterator().next();
+    // Create clusters again to continue with testing
+    createClusters(_clusterSetupBuilder);
 
-      // Check with single-realm ZkClients
-      Assert.assertTrue(ZK_CLIENT_MAP.get(zkAddress).exists(clusterNamePath));
-      // Check with realm-aware ZkClient (federated)
-      Assert.assertTrue(_zkClient.exists(clusterNamePath));
+    _clusterSetupZkAddr.close();
+    _clusterSetupBuilder.close();
 
-      // Remove clusters
-      clusterSetup
-          .deleteCluster(clusterNamePath.substring(1)); // Need to remove "/" 
at the beginning
-    });
+    System.out.println("END " + _className + " at " + new 
Date(System.currentTimeMillis()));
   }
 
-  /**
-   * Test Helix Participant creation and addition.
-   * Helix Java APIs tested in this method are:
-   * ZkHelixAdmin and ZKHelixManager (mock participant/controller)
-   */
+  @Override
   @Test(dependsOnMethods = "testCreateClusters")
   public void testCreateParticipants() throws Exception {
-    // Create two ClusterSetups using two different constructors
-    // Note: ZK Address here could be anything because multiZk mode is on (it 
will be ignored)
-    HelixAdmin helixAdminZkAddr = new 
ZKHelixAdmin(ZK_SERVER_MAP.keySet().iterator().next());
-    HelixAdmin helixAdminBuilder = new ZKHelixAdmin.Builder().build();
-    _zkHelixAdmin = new ZKHelixAdmin.Builder().build();
-
-    String participantNamePrefix = "Node_";
-    int numParticipants = 5;
-    createParticipantsAndVerify(helixAdminZkAddr, numParticipants, 
participantNamePrefix);
-    createParticipantsAndVerify(helixAdminBuilder, numParticipants, 
participantNamePrefix);
-
-    // Create mock controller and participants for next tests
-    for (String cluster : CLUSTER_LIST) {
-      // Start a controller
-      // Note: in multiZK mode, ZK Addr is ignored
-      ClusterControllerManager mockController =
-          new ClusterControllerManager("DummyZK", cluster, "controller");
-      mockController.syncStart();
-      MOCK_CONTROLLERS.put(cluster, mockController);
-
-      for (int i = 0; i < numParticipants; i++) {
-        // Note: in multiZK mode, ZK Addr is ignored
-        InstanceConfig instanceConfig = new 
InstanceConfig(participantNamePrefix + i);
-        helixAdminBuilder.addInstance(cluster, instanceConfig);
-        MockParticipantManager mockNode =
-            new MockParticipantManager("DummyZK", cluster, 
participantNamePrefix + i);
-
-        // Register task state model for task framework testing in later 
methods
-        Map<String, TaskFactory> taskFactoryReg = new HashMap<>();
-        taskFactoryReg.put(MockTask.TASK_COMMAND, MockTask::new);
-        // Register a Task state model factory.
-        StateMachineEngine stateMachine = mockNode.getStateMachineEngine();
-        stateMachine
-            .registerStateModelFactory("Task", new 
TaskStateModelFactory(mockNode, taskFactoryReg));
-
-        mockNode.syncStart();
-        MOCK_PARTICIPANTS.add(mockNode);
-      }
-      // Check that mockNodes are up
-      Assert.assertTrue(TestHelper
-          .verify(() -> 
helixAdminBuilder.getInstancesInCluster(cluster).size() == numParticipants,
-              TestHelper.WAIT_DURATION));
-    }
-
-    helixAdminZkAddr.close();
-    helixAdminBuilder.close();
-  }
-
-  private void createParticipantsAndVerify(HelixAdmin admin, int 
numParticipants,
-      String participantNamePrefix) {
-    // Create participants in clusters
-    Set<String> participantNames = new HashSet<>();
-    CLUSTER_LIST.forEach(cluster -> {
-      for (int i = 0; i < numParticipants; i++) {
-        String participantName = participantNamePrefix + i;
-        participantNames.add(participantName);
-        InstanceConfig instanceConfig = new 
InstanceConfig(participantNamePrefix + i);
-        admin.addInstance(cluster, instanceConfig);
-      }
-    });
-
-    // Verify participants have been created properly
-    _rawRoutingData.forEach((zkAddress, cluster) -> {
-      // Note: clusterNamePath already contains "/"
-      String clusterNamePath = cluster.iterator().next();
-
-      // Check with single-realm ZkClients
-      List<String> instances =
-          ZK_CLIENT_MAP.get(zkAddress).getChildren(clusterNamePath + 
"/INSTANCES");
-      Assert.assertEquals(new HashSet<>(instances), participantNames);
+    String methodName = TestHelper.getTestMethodName();
+    System.out.println("START " + _className + "_" + methodName + " at " + new 
Date(System.currentTimeMillis()));
 
-      // Check with realm-aware ZkClient (federated)
-      instances = _zkClient.getChildren(clusterNamePath + "/INSTANCES");
-      Assert.assertEquals(new HashSet<>(instances), participantNames);
+    super.testCreateParticipants();
 
-      // Remove Participants
-      participantNames.forEach(participant -> {
-        InstanceConfig instanceConfig = new InstanceConfig(participant);
-        admin.dropInstance(clusterNamePath.substring(1), instanceConfig);
-      });
-    });
+    System.out.println("END " + _className + " at " + new 
Date(System.currentTimeMillis()));

Review Comment:
   Please include method name as well



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to