helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zzh...@apache.org
Subject git commit: [HELIX-12] add a test case for auto-rebalance mode during node startswq
Date Tue, 27 Nov 2012 18:22:16 GMT
Updated Branches:
  refs/heads/master fa2eb2c87 -> 02afc50b2


[HELIX-12] add a test case for auto-rebalance mode during node startswq


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

Branch: refs/heads/master
Commit: 02afc50b2ef26544666dd92bc732f7cee02f2888
Parents: fa2eb2c
Author: zzhang <zzhang@apache.org>
Authored: Tue Nov 27 10:22:02 2012 -0800
Committer: zzhang <zzhang@apache.org>
Committed: Tue Nov 27 10:22:02 2012 -0800

----------------------------------------------------------------------
 .../apache/helix/manager/zk/CallbackHandler.java   |    2 +-
 .../integration/TestAutoRebalanceDuringStart.java  |   68 +++++++++++++++
 .../helix/mock/participant/MockParticipant.java    |    7 +-
 3 files changed, 74 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/02afc50b/helix-core/src/main/java/org/apache/helix/manager/zk/CallbackHandler.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/CallbackHandler.java b/helix-core/src/main/java/org/apache/helix/manager/zk/CallbackHandler.java
index bc77b48..f4492cd 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/CallbackHandler.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/CallbackHandler.java
@@ -242,7 +242,7 @@ public class CallbackHandler implements IZkChildListener, IZkDataListener
         logger.info(_manager.getInstanceName() + " subscribe child change@" + path);
         _zkClient.subscribeChildChanges(path, this);
       }
-      else if (watchParent && type == NotificationContext.Type.FINALIZE)
+      else if (type == NotificationContext.Type.FINALIZE)
       {
         logger.info(_manager.getInstanceName() + " UNsubscribe child change@" + path);
         _zkClient.unsubscribeChildChanges(path, this);

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/02afc50b/helix-core/src/test/java/org/apache/helix/integration/TestAutoRebalanceDuringStart.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestAutoRebalanceDuringStart.java
b/helix-core/src/test/java/org/apache/helix/integration/TestAutoRebalanceDuringStart.java
new file mode 100644
index 0000000..2baf550
--- /dev/null
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestAutoRebalanceDuringStart.java
@@ -0,0 +1,68 @@
+package org.apache.helix.integration;
+
+import java.util.Date;
+
+import org.apache.helix.TestHelper;
+import org.apache.helix.mock.controller.ClusterController;
+import org.apache.helix.mock.participant.MockParticipant;
+import org.apache.helix.model.IdealState.IdealStateModeProperty;
+import org.apache.helix.tools.ClusterStateVerifier;
+import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+// test auto-rebalance ideal state mode
+// change ideal state when state transitions are in progress
+public class TestAutoRebalanceDuringStart extends ZkIntegrationTestBase {
+    @Test
+    public void test() throws Exception {
+	// Logger.getRootLogger().setLevel(Level.INFO);
+	String className = TestHelper.getTestClassName();
+	String methodName = TestHelper.getTestMethodName();
+	String clusterName = className + "_" + methodName;
+	final int n = 3;
+
+	System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
+
+	MockParticipant[] participants = new MockParticipant[n];
+
+	TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
+	        "localhost", // participant name prefix
+	        "TestDB", // resource name prefix
+	        1, // resources
+	        4, // partitions per resource
+	        n, // number of nodes
+	        3, // replicas
+	        "MasterSlave", 
+	        IdealStateModeProperty.AUTO_REBALANCE, 
+	        true); // do rebalance
+
+	// start controller
+	ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+	controller.syncStart();
+
+	// start participants
+	for (int i = 0; i < n; i++) {
+	    String instanceName = "localhost_" + (12918 + i);
+
+	    participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR,
+		    new MockParticipant.SleepTransition(1000));
+	    participants[i].syncStart();
+	    Thread.sleep(300);
+	}
+	boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(
+	        ZK_ADDR, clusterName));
+	Assert.assertTrue(result);
+
+	// clean up
+	controller.syncStop();
+	Thread.sleep(1000);  // wait for all zk callbacks done
+	for (int i = 0; i < n; i++) {
+	    participants[i].syncStop();
+	}
+
+	System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/02afc50b/helix-core/src/test/java/org/apache/helix/mock/participant/MockParticipant.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/mock/participant/MockParticipant.java
b/helix-core/src/test/java/org/apache/helix/mock/participant/MockParticipant.java
index 04af4d5..753c254 100644
--- a/helix-core/src/test/java/org/apache/helix/mock/participant/MockParticipant.java
+++ b/helix-core/src/test/java/org/apache/helix/mock/participant/MockParticipant.java
@@ -28,7 +28,6 @@ import java.util.concurrent.CountDownLatch;
 import org.I0Itec.zkclient.DataUpdater;
 import org.I0Itec.zkclient.exception.ZkNoNodeException;
 import org.apache.helix.AccessOption;
-import org.apache.helix.BaseDataAccessor;
 import org.apache.helix.HelixManager;
 import org.apache.helix.HelixManagerFactory;
 import org.apache.helix.InstanceType;
@@ -405,7 +404,11 @@ public class MockParticipant extends Thread
         }
         catch (ZkNoNodeException e)
         {
-          record = new ZNRecord(setPath);
+          // record = new ZNRecord(setPath);
+        }
+        if (record == null)
+        {
+            record = new ZNRecord(setPath);
         }
         record.setSimpleField("setTimestamp", "" + System.currentTimeMillis());
         store.set(setPath, record, AccessOption.PERSISTENT);


Mime
View raw message