You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by jx...@apache.org on 2020/07/29 17:32:07 UTC

[helix] branch master updated: Remove race condition in TestTaskSchedulingTwoCurrentStates (#1180)

This is an automated email from the ASF dual-hosted git repository.

jxue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git


The following commit(s) were added to refs/heads/master by this push:
     new 69aaf43  Remove race condition in TestTaskSchedulingTwoCurrentStates (#1180)
69aaf43 is described below

commit 69aaf43db4489445d6883d0111a0eb72a73e32ba
Author: Ali Reza Zamani Zadeh Najari <an...@linkedin.com>
AuthorDate: Wed Jul 29 10:31:58 2020 -0700

    Remove race condition in TestTaskSchedulingTwoCurrentStates (#1180)
    
    Remove race condition in TestTaskSchedulingTwoCurrentStates
    
    In this commit, TestTaskSchedulingTwoCurrentStates has been stabilized
    by creating SEMI-AUTO resource and update the preferenceList to avoid
    race condition that happens when test and controller update the
    preferenceList at the same time.
---
 .../task/TestTaskSchedulingTwoCurrentStates.java   | 34 +++++++++-------------
 1 file changed, 13 insertions(+), 21 deletions(-)

diff --git a/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskSchedulingTwoCurrentStates.java b/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskSchedulingTwoCurrentStates.java
index a40ce45..ae8a220 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskSchedulingTwoCurrentStates.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskSchedulingTwoCurrentStates.java
@@ -27,14 +27,10 @@ import java.util.Map;
 import java.util.concurrent.atomic.AtomicInteger;
 import org.apache.helix.AccessOption;
 import org.apache.helix.HelixDataAccessor;
-import org.apache.helix.HelixManagerFactory;
-import org.apache.helix.InstanceType;
 import org.apache.helix.PropertyKey;
 import org.apache.helix.TestHelper;
 import org.apache.helix.ZkTestHelper;
 import org.apache.helix.integration.manager.MockParticipantManager;
-import org.apache.helix.manager.zk.ZKHelixDataAccessor;
-import org.apache.helix.model.ClusterConfig;
 import org.apache.helix.model.CurrentState;
 import org.apache.helix.model.ExternalView;
 import org.apache.helix.model.IdealState;
@@ -46,7 +42,6 @@ import org.apache.helix.task.JobConfig;
 import org.apache.helix.task.JobContext;
 import org.apache.helix.task.JobQueue;
 import org.apache.helix.task.TaskCallbackContext;
-import org.apache.helix.task.TaskDriver;
 import org.apache.helix.task.TaskFactory;
 import org.apache.helix.task.TaskPartitionState;
 import org.apache.helix.task.TaskState;
@@ -56,6 +51,7 @@ import org.apache.helix.zookeeper.datamodel.ZNRecord;
 import org.apache.helix.zookeeper.impl.client.ZkClient;
 import org.apache.zookeeper.data.Stat;
 import org.testng.Assert;
+import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 import com.google.common.collect.ImmutableMap;
@@ -65,7 +61,7 @@ import com.google.common.collect.ImmutableMap;
  * sent when there are two CurrentStates.
  */
 public class TestTaskSchedulingTwoCurrentStates extends TaskTestBase {
-  private static final String DATABASE = WorkflowGenerator.DEFAULT_TGT_DB;
+  private static final String DATABASE = "TestDB_" + TestHelper.getTestClassName();
   protected HelixDataAccessor _accessor;
   private PropertyKey.Builder _keyBuilder;
   private static final AtomicInteger CANCEL_COUNT = new AtomicInteger(0);
@@ -98,33 +94,29 @@ public class TestTaskSchedulingTwoCurrentStates extends TaskTestBase {
     }
   }
 
+  @AfterClass()
+  public void afterClass() throws Exception {
+    super.afterClass();
+  }
+
   @Test
   public void testTargetedTaskTwoCurrentStates() throws Exception {
-    String jobQueueName = TestHelper.getTestMethodName();
-
-    _accessor = new ZKHelixDataAccessor(CLUSTER_NAME, _baseAccessor);
-    _keyBuilder = _accessor.keyBuilder();
-    ClusterConfig clusterConfig = _accessor.getProperty(_keyBuilder.clusterConfig());
-    clusterConfig.setPersistIntermediateAssignment(true);
-    clusterConfig.setRebalanceTimePeriod(10000L);
-    _accessor.setProperty(_keyBuilder.clusterConfig(), clusterConfig);
-
+    _gSetupTool.addResourceToCluster(CLUSTER_NAME, DATABASE, _numPartitions,
+        MASTER_SLAVE_STATE_MODEL, IdealState.RebalanceMode.SEMI_AUTO.name());
+    _gSetupTool.rebalanceResource(CLUSTER_NAME, DATABASE, 3);
     List<String> preferenceList = new ArrayList<>();
     preferenceList.add(PARTICIPANT_PREFIX + "_" + (_startPort + 1));
     preferenceList.add(PARTICIPANT_PREFIX + "_" + (_startPort + 0));
     preferenceList.add(PARTICIPANT_PREFIX + "_" + (_startPort + 2));
-    // Change the Rebalance Mode to SEMI_AUTO
-    IdealState idealState =
-        _gSetupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, DATABASE);
+    IdealState idealState = new IdealState(DATABASE);
     idealState.setPreferenceList(DATABASE + "_0", preferenceList);
-    idealState.setRebalanceMode(IdealState.RebalanceMode.SEMI_AUTO);
-    _gSetupTool.getClusterManagementTool().setResourceIdealState(CLUSTER_NAME, DATABASE,
-        idealState);
+    _gSetupTool.getClusterManagementTool().updateIdealState(CLUSTER_NAME, DATABASE, idealState);
 
     // [Participant0: localhost_12918, Participant1: localhost_12919, Participant2: localhost_12920]
     // Preference list [localhost_12919, localhost_12918, localhost_12920]
     // Status: [Participant1: Master, Participant0: Slave, Participant2: Slave]
     // Based on the above preference list and since is is SEMI_AUTO, localhost_12919 will be Master.
+    String jobQueueName = TestHelper.getTestMethodName();
     JobConfig.Builder jobBuilder0 =
         new JobConfig.Builder().setWorkflow(jobQueueName).setTargetResource(DATABASE)
             .setTargetPartitionStates(Sets.newHashSet(MasterSlaveSMD.States.MASTER.name()))