pkuwm commented on a change in pull request #981:
URL: https://github.com/apache/helix/pull/981#discussion_r417666330



##########
File path: 
helix-core/src/test/java/org/apache/helix/integration/task/TestRebalanceRunningTask.java
##########
@@ -261,6 +263,28 @@ public void 
testFixedTargetTaskAndDisabledRebalanceAndNodeAdded() throws Interru
         new 
BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkClient(_gZkClient)
             .setResources(Sets.newHashSet(DATABASE)).build();
     Assert.assertTrue(clusterVerifier.verify(10 * 1000));
+
+    // Wait until master is switched to new instance and two masters existed 
on two different instance
+    boolean isMasterOnTwoDifferentNodes = TestHelper.verify(() -> {
+      HashSet<String> masterInstances = new HashSet<>();
+      ExternalView externalView =
+          
_gSetupTool.getClusterManagementTool().getResourceExternalView(CLUSTER_NAME, 
DATABASE);
+      Map<String, String> stateMap0 = externalView.getStateMap(DATABASE + 
"_0");
+      Map<String, String> stateMap1 = externalView.getStateMap(DATABASE + 
"_1");
+      for (Map.Entry<String, String> entry : stateMap0.entrySet()) {
+        if (entry.getValue().equals("MASTER")) {
+          masterInstances.add(entry.getKey());
+        }
+      }
+      for (Map.Entry<String, String> entry : stateMap1.entrySet()) {
+        if (entry.getValue().equals("MASTER")) {
+          masterInstances.add(entry.getKey());
+        }
+      }
+      return (masterInstances.size() == 2);

Review comment:
       A counter is enough, no need to create a HashSet, right?

##########
File path: 
helix-core/src/test/java/org/apache/helix/integration/task/TestJobFailure.java
##########
@@ -118,8 +118,15 @@ public void testNormalJobFailure(String comment, 
List<String> taskStates,
   }
 
   private Map<String, Map<String, String>> createPartitionConfig(List<String> 
taskStates,
-      List<String> expectedTaskEndingStates) {
+      List<String> expectedTaskEndingStates) throws Exception {
     Map<String, Map<String, String>> targetPartitionConfigs = new HashMap<>();
+    // Make sure external view is has been created for the resource
+    boolean isExternalViewCreated = TestHelper.verify(() -> {
+      ExternalView externalView =
+          
_manager.getClusterManagmentTool().getResourceExternalView(CLUSTER_NAME, 
DB_NAME);
+      return (externalView != null);
+    }, TestHelper.WAIT_DURATION);
+    Assert.assertTrue(isExternalViewCreated);

Review comment:
       Nit, I would just do `assertTrue(TestHelper.verify());` to get rid of 
the temp boolean `isExternalViewCreated` var to minimize variable scope. Same 
for following usages.

##########
File path: 
helix-core/src/test/java/org/apache/helix/integration/task/TestTaskSchedulingTwoCurrentStates.java
##########
@@ -138,6 +139,17 @@ public void testTargetedTaskTwoCurrentStates() throws 
Exception {
     JobQueue.Builder jobQueue = TaskTestUtil.buildJobQueue(jobQueueName);
     jobQueue.enqueueJob("JOB0", jobBuilder0);
 
+    // Make sure master has been correctly switched to Participant1
+    boolean isMasterSwitchedToCorrectInstance = TestHelper.verify(() -> {
+      ExternalView externalView = 
_gSetupTool.getClusterManagementTool().getResourceExternalView(CLUSTER_NAME, 
DATABASE);
+      Map <String, String> stateMap = externalView.getStateMap(DATABASE + 
"_0");

Review comment:
       Is externalView possible to be null?

##########
File path: 
helix-core/src/test/java/org/apache/helix/integration/task/TestTaskSchedulingTwoCurrentStates.java
##########
@@ -138,6 +139,17 @@ public void testTargetedTaskTwoCurrentStates() throws 
Exception {
     JobQueue.Builder jobQueue = TaskTestUtil.buildJobQueue(jobQueueName);
     jobQueue.enqueueJob("JOB0", jobBuilder0);
 
+    // Make sure master has been correctly switched to Participant1
+    boolean isMasterSwitchedToCorrectInstance = TestHelper.verify(() -> {
+      ExternalView externalView = 
_gSetupTool.getClusterManagementTool().getResourceExternalView(CLUSTER_NAME, 
DATABASE);
+      Map <String, String> stateMap = externalView.getStateMap(DATABASE + 
"_0");
+      if (!stateMap.containsKey(PARTICIPANT_PREFIX + "_" + (_startPort + 1))) {
+        return false;
+      }
+      return stateMap.get(PARTICIPANT_PREFIX + "_" + (_startPort + 
1)).equals("MASTER");

Review comment:
       These checks could be simplified to 
`"MASTER".equals(stateMap.get(PARTICIPANT_PREFIX + "_" + (_startPort + 1)));`




----------------------------------------------------------------
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.

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