Repository: helix
Updated Branches:
  refs/heads/master 6e0299d22 -> 343f8dd33


[HELIX-731] Fix TestStateTransitionThrottle and comparison operator change

Due to the change made in relation to allowing downward state transitions to 
take place while error or recovery balance transitions are present, this test 
was failing due to the change in the assumption. Parameters were adjusted, and 
test conditions were modified such that it is testing the new assumptions 
correctly.

Changelist:
1. TestStateTransitionThrottle assert statements were modified so that it 
assumes downward load balance transitions taking place
2. Comparison operator in IntermediateStateCalcState to make it more strictly 
backward-compatible


Project: http://git-wip-us.apache.org/repos/asf/helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/helix/commit/343f8dd3
Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/343f8dd3
Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/343f8dd3

Branch: refs/heads/master
Commit: 343f8dd33d49a74e6def97a9e58b4adf6b007ee3
Parents: 6e0299d
Author: Hunter Lee <[email protected]>
Authored: Mon Jul 16 11:48:19 2018 -0700
Committer: Hunter Lee <[email protected]>
Committed: Mon Jul 16 14:55:31 2018 -0700

----------------------------------------------------------------------
 .../stages/IntermediateStateCalcStage.java      |  6 ++--
 .../TestStateTransitionThrottle.java            | 32 +++++++++-----------
 2 files changed, 18 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/343f8dd3/helix-core/src/main/java/org/apache/helix/controller/stages/IntermediateStateCalcStage.java
----------------------------------------------------------------------
diff --git 
a/helix-core/src/main/java/org/apache/helix/controller/stages/IntermediateStateCalcStage.java
 
b/helix-core/src/main/java/org/apache/helix/controller/stages/IntermediateStateCalcStage.java
index 3bede5e..6d10c6f 100644
--- 
a/helix-core/src/main/java/org/apache/helix/controller/stages/IntermediateStateCalcStage.java
+++ 
b/helix-core/src/main/java/org/apache/helix/controller/stages/IntermediateStateCalcStage.java
@@ -316,7 +316,7 @@ public class IntermediateStateCalcStage extends 
AbstractBaseStage {
             
cache.getStateModelDef(resource.getStateModelDefRef()).getTopState());
 
     // Perform load balance upon checking conditions below
-    Set<Partition> loadbalanceThrottledPartitions = partitionsNeedLoadBalance;
+    Set<Partition> loadbalanceThrottledPartitions;
     ClusterConfig clusterConfig = cache.getClusterConfig();
 
     // If the threshold (ErrorOrRecovery) is set, then use it, if not, then 
check if the old
@@ -338,7 +338,7 @@ public class IntermediateStateCalcStage extends 
AbstractBaseStage {
 
     // Perform regular load balance only if the number of partitions in 
recovery and in error is
     // less than the threshold. Otherwise, only allow downward-transition load 
balance
-    boolean onlyDownwardLoadBalance = partitionCount >= threshold;
+    boolean onlyDownwardLoadBalance = partitionCount > threshold;
 
     loadbalanceThrottledPartitions = loadRebalance(resource, 
currentStateOutput,
         bestPossiblePartitionStateMap, throttleController, 
intermediatePartitionStateMap,
@@ -850,4 +850,4 @@ public class IntermediateStateCalcStage extends 
AbstractBaseStage {
       return matchedState;
     }
   }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/helix/blob/343f8dd3/helix-core/src/test/java/org/apache/helix/integration/TestStateTransitionThrottle.java
----------------------------------------------------------------------
diff --git 
a/helix-core/src/test/java/org/apache/helix/integration/TestStateTransitionThrottle.java
 
b/helix-core/src/test/java/org/apache/helix/integration/TestStateTransitionThrottle.java
index 216d951..861eee0 100644
--- 
a/helix-core/src/test/java/org/apache/helix/integration/TestStateTransitionThrottle.java
+++ 
b/helix-core/src/test/java/org/apache/helix/integration/TestStateTransitionThrottle.java
@@ -95,16 +95,15 @@ public class TestStateTransitionThrottle extends ZkTestBase 
{
         "localhost_" + (12918 + participantCount - 1));
     participants[participantCount - 1].syncStart();
 
-    // Load balance transition won't be scheduled since there is pending 
recovery balance transition
-    Assert.assertFalse(
-        pollForPartitionAssignment(accessor, participants[participantCount - 
1], resourceName,
-            5000));
+    // Load balance transition (downward) will be scheduled even though there 
is pending recovery
+    // balance transition
+    Assert.assertTrue(pollForPartitionAssignment(accessor, 
participants[participantCount - 1],
+        resourceName, 5000));
 
     // Stop participant, so blocking transition is removed.
     participants[0].syncStop();
-    Assert.assertTrue(
-        pollForPartitionAssignment(accessor, participants[participantCount - 
1], resourceName,
-            5000));
+    Assert.assertTrue(pollForPartitionAssignment(accessor, 
participants[participantCount - 1],
+        resourceName, 5000));
 
     // clean up
     controller.syncStop();
@@ -167,20 +166,19 @@ public class TestStateTransitionThrottle extends 
ZkTestBase {
     participants[participantCount - 1] = new MockParticipantManager(ZK_ADDR, 
clusterName,
         "localhost_" + (12918 + participantCount - 1));
     participants[participantCount - 1].syncStart();
-    // Since error partition exists, no load balance transition will be done
-    Assert.assertFalse(
-        pollForPartitionAssignment(accessor, participants[participantCount - 
1], resourceName,
-            5000));
+    // Even though there is an error partition, downward load balance will 
take place
+    Assert.assertTrue(pollForPartitionAssignment(accessor, 
participants[participantCount - 1],
+        resourceName, 5000));
 
     // Update cluster config to tolerate error partition, so load balance 
transition will be done
     clusterConfig = 
accessor.getProperty(accessor.keyBuilder().clusterConfig());
     clusterConfig.setErrorPartitionThresholdForLoadBalance(1);
     accessor.setProperty(keyBuilder.clusterConfig(), clusterConfig);
+
     _gSetupTool.rebalanceResource(clusterName, resourceName, 3);
 
-    Assert.assertTrue(
-        pollForPartitionAssignment(accessor, participants[participantCount - 
1], resourceName,
-            3000));
+    Assert.assertTrue(pollForPartitionAssignment(accessor, 
participants[participantCount - 1],
+        resourceName, 3000));
 
     // clean up
     controller.syncStop();
@@ -224,11 +222,11 @@ public class TestStateTransitionThrottle extends 
ZkTestBase {
       @Override
       public boolean verify() throws Exception {
         PropertyKey.Builder keyBuilder = accessor.keyBuilder();
-        PropertyKey partitionStatusKey = keyBuilder
-            .currentState(participant.getInstanceName(), 
participant.getSessionId(), resourceName);
+        PropertyKey partitionStatusKey = 
keyBuilder.currentState(participant.getInstanceName(),
+            participant.getSessionId(), resourceName);
         CurrentState currentState = accessor.getProperty(partitionStatusKey);
         return currentState != null && 
!currentState.getPartitionStateMap().isEmpty();
       }
     }, timeout);
   }
-}
+}
\ No newline at end of file

Reply via email to