helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zzh...@apache.org
Subject [2/9] [HELIX-475] Remove code duplication for Zk tests
Date Tue, 22 Jul 2014 18:40:20 GMT
http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixAutoController.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixAutoController.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixAutoController.java
index 856707b..96952d0 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixAutoController.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixAutoController.java
@@ -26,15 +26,14 @@ import org.apache.helix.HelixConnection;
 import org.apache.helix.HelixDataAccessor;
 import org.apache.helix.PropertyKey;
 import org.apache.helix.TestHelper;
-import org.apache.helix.ZNRecord;
-import org.apache.helix.ZkUnitTestBase;
 import org.apache.helix.api.id.ClusterId;
 import org.apache.helix.api.id.ControllerId;
 import org.apache.helix.model.LiveInstance;
+import org.apache.helix.testutil.ZkTestBase;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
-public class TestZkHelixAutoController extends ZkUnitTestBase {
+public class TestZkHelixAutoController extends ZkTestBase {
   @Test
   public void testOnConnectedAndDisconnecting() throws Exception {
     // Logger.getRootLogger().setLevel(Level.INFO);
@@ -45,7 +44,7 @@ public class TestZkHelixAutoController extends ZkUnitTestBase {
 
     System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
 
-    TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
+    TestHelper.setupCluster(clusterName, _zkaddr, 12918, // participant port
         "localhost", // participant name prefix
         "TestDB", // resource name prefix
         1, // resources
@@ -55,7 +54,7 @@ public class TestZkHelixAutoController extends ZkUnitTestBase {
         "MasterSlave", true); // do rebalance
 
     // create connection
-    HelixConnection connection = new ZkHelixConnection(ZK_ADDR);
+    HelixConnection connection = new ZkHelixConnection(_zkaddr);
     connection.connect();
 
     // start auto-controller
@@ -70,7 +69,7 @@ public class TestZkHelixAutoController extends ZkUnitTestBase {
 
     // check live-instance znode for localhost_12918/12919 exists
     final HelixDataAccessor accessor =
-        new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
+        new ZKHelixDataAccessor(clusterName, _baseAccessor);
     final PropertyKey.Builder keyBuilder = accessor.keyBuilder();
 
     for (int i = 0; i < n; i++) {

http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixController.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixController.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixController.java
index beac6aa..9304cf8 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixController.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixController.java
@@ -26,15 +26,14 @@ import org.apache.helix.HelixController;
 import org.apache.helix.HelixDataAccessor;
 import org.apache.helix.PropertyKey;
 import org.apache.helix.TestHelper;
-import org.apache.helix.ZNRecord;
-import org.apache.helix.ZkUnitTestBase;
 import org.apache.helix.api.id.ClusterId;
 import org.apache.helix.api.id.ControllerId;
 import org.apache.helix.model.LiveInstance;
+import org.apache.helix.testutil.ZkTestBase;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
-public class TestZkHelixController extends ZkUnitTestBase {
+public class TestZkHelixController extends ZkTestBase {
 
   @Test
   public void testOnConnectedAndDisconnecting() throws Exception {
@@ -46,7 +45,7 @@ public class TestZkHelixController extends ZkUnitTestBase {
 
     System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
 
-    TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
+    TestHelper.setupCluster(clusterName, _zkaddr, 12918, // participant port
         "localhost", // participant name prefix
         "TestDB", // resource name prefix
         1, // resources
@@ -56,7 +55,7 @@ public class TestZkHelixController extends ZkUnitTestBase {
         "MasterSlave", true); // do rebalance
 
     // create connection
-    HelixConnection connection = new ZkHelixConnection(ZK_ADDR);
+    HelixConnection connection = new ZkHelixConnection(_zkaddr);
     connection.connect();
 
     // start controller
@@ -101,7 +100,7 @@ public class TestZkHelixController extends ZkUnitTestBase {
 
     System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
 
-    TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
+    TestHelper.setupCluster(clusterName, _zkaddr, 12918, // participant port
         "localhost", // participant name prefix
         "TestDB", // resource name prefix
         1, // resources
@@ -111,7 +110,7 @@ public class TestZkHelixController extends ZkUnitTestBase {
         "MasterSlave", true); // do rebalance
 
     // create connection
-    HelixConnection connection = new ZkHelixConnection(ZK_ADDR);
+    HelixConnection connection = new ZkHelixConnection(_zkaddr);
     connection.connect();
 
     // start controller
@@ -124,7 +123,7 @@ public class TestZkHelixController extends ZkUnitTestBase {
 
     // check live-instance znode for localhost_12918 exists
     final HelixDataAccessor accessor =
-        new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
+        new ZKHelixDataAccessor(clusterName, _baseAccessor);
     final PropertyKey.Builder keyBuilder = accessor.keyBuilder();
     LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
     Assert.assertNotNull(leader);

http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixParticipant.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixParticipant.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixParticipant.java
index e566ef2..887a9a5 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixParticipant.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixParticipant.java
@@ -26,16 +26,15 @@ import org.apache.helix.HelixDataAccessor;
 import org.apache.helix.HelixParticipant;
 import org.apache.helix.PropertyKey;
 import org.apache.helix.TestHelper;
-import org.apache.helix.ZNRecord;
-import org.apache.helix.ZkUnitTestBase;
 import org.apache.helix.api.id.ClusterId;
 import org.apache.helix.api.id.ParticipantId;
 import org.apache.helix.api.id.StateModelDefId;
 import org.apache.helix.integration.TestHelixConnection;
+import org.apache.helix.testutil.ZkTestBase;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
-public class TestZkHelixParticipant extends ZkUnitTestBase {
+public class TestZkHelixParticipant extends ZkTestBase {
 
   @Test
   public void testOnConnectedAndDisconnecting() throws Exception {
@@ -47,7 +46,7 @@ public class TestZkHelixParticipant extends ZkUnitTestBase {
 
     System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
 
-    TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
+    TestHelper.setupCluster(clusterName, _zkaddr, 12918, // participant port
         "localhost", // participant name prefix
         "TestDB", // resource name prefix
         1, // resources
@@ -57,7 +56,7 @@ public class TestZkHelixParticipant extends ZkUnitTestBase {
         "MasterSlave", true); // do rebalance
 
     // create connection
-    HelixConnection connection = new ZkHelixConnection(ZK_ADDR);
+    HelixConnection connection = new ZkHelixConnection(_zkaddr);
     connection.connect();
 
     // start participant
@@ -76,7 +75,7 @@ public class TestZkHelixParticipant extends ZkUnitTestBase {
 
     // check live-instance znode for localhost_12918/12919 exist
     HelixDataAccessor accessor =
-        new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
+        new ZKHelixDataAccessor(clusterName, _baseAccessor);
     PropertyKey.Builder keyBuilder = accessor.keyBuilder();
 
     for (int i = 0; i < n; i++) {

http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkManagerFlappingDetection.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkManagerFlappingDetection.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkManagerFlappingDetection.java
index 78d1668..86aa6e3 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkManagerFlappingDetection.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkManagerFlappingDetection.java
@@ -21,20 +21,20 @@ package org.apache.helix.manager.zk;
 
 import org.apache.helix.TestHelper;
 import org.apache.helix.ZkTestHelper;
-import org.apache.helix.integration.ZkIntegrationTestBase;
 import org.apache.helix.integration.manager.ClusterControllerManager;
 import org.apache.helix.integration.manager.MockParticipantManager;
+import org.apache.helix.testutil.ZkTestBase;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
-public class TestZkManagerFlappingDetection extends ZkIntegrationTestBase {
+public class TestZkManagerFlappingDetection extends ZkTestBase {
   @Test
   public void testDisconnectHistory() throws Exception {
     String className = TestHelper.getTestClassName();
     String methodName = TestHelper.getTestMethodName();
     final String clusterName = className + "_" + methodName;
 
-    TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
+    TestHelper.setupCluster(clusterName, _zkaddr, 12918, // participant port
         "localhost", // participant name prefix
         "TestDB", // resource name prefix
         1, // resources
@@ -44,7 +44,7 @@ public class TestZkManagerFlappingDetection extends ZkIntegrationTestBase {
         "MasterSlave", true); // do rebalance
 
     String instanceName = "localhost_" + (12918 + 0);
-    MockParticipantManager manager = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+    MockParticipantManager manager = new MockParticipantManager(_zkaddr, clusterName, instanceName);
 
     manager.connect();
     ZkClient zkClient = manager.getZkClient();
@@ -85,7 +85,7 @@ public class TestZkManagerFlappingDetection extends ZkIntegrationTestBase {
   // String methodName = TestHelper.getTestMethodName();
   // final String clusterName = className + "_" + methodName + UUID.randomUUID();
   //
-  // TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
+  // TestHelper.setupCluster(clusterName, zkaddr, 12918, // participant port
   // "localhost", // participant name prefix
   // "TestDB", // resource name prefix
   // 1, // resources
@@ -97,7 +97,7 @@ public class TestZkManagerFlappingDetection extends ZkIntegrationTestBase {
   // // flapping time window to 5 sec
   // System.setProperty("helixmanager.flappingTimeWindow", "15000");
   // System.setProperty("helixmanager.maxDisconnectThreshold", "7");
-  // ZkHelixTestManager manager2 = new ZkHelixTestManager(clusterName, instanceName, type, ZK_ADDR);
+  // ZkHelixTestManager manager2 = new ZkHelixTestManager(clusterName, instanceName, type, zkaddr);
   // manager2.connect();
   // ZkClient zkClient = manager2.getZkClient();
   // for (int i = 0; i < 3; i++) {
@@ -127,7 +127,7 @@ public class TestZkManagerFlappingDetection extends ZkIntegrationTestBase {
     String methodName = TestHelper.getTestMethodName();
     final String clusterName = className + "_" + methodName;
 
-    TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
+    TestHelper.setupCluster(clusterName, _zkaddr, 12918, // participant port
         "localhost", // participant name prefix
         "TestDB", // resource name prefix
         1, // resources
@@ -139,7 +139,7 @@ public class TestZkManagerFlappingDetection extends ZkIntegrationTestBase {
     // flapping time window to 5 sec
     System.setProperty("helixmanager.flappingTimeWindow", "5000");
     System.setProperty("helixmanager.maxDisconnectThreshold", "3");
-    ClusterControllerManager manager2 = new ClusterControllerManager(ZK_ADDR, clusterName, null);
+    ClusterControllerManager manager2 = new ClusterControllerManager(_zkaddr, clusterName, null);
     manager2.connect();
     Thread.sleep(100);
     ZkClient zkClient = manager2.getZkClient();

http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/messaging/handling/TestConfigThreadpoolSize.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/messaging/handling/TestConfigThreadpoolSize.java b/helix-core/src/test/java/org/apache/helix/messaging/handling/TestConfigThreadpoolSize.java
index 0f8c841..80a46fa 100644
--- a/helix-core/src/test/java/org/apache/helix/messaging/handling/TestConfigThreadpoolSize.java
+++ b/helix-core/src/test/java/org/apache/helix/messaging/handling/TestConfigThreadpoolSize.java
@@ -76,7 +76,7 @@ public class TestConfigThreadpoolSize extends ZkStandAloneCMTestBase {
 
   @Test
   public void TestThreadPoolSizeConfig() {
-    String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + 0);
+    String instanceName = "localhost_" + (START_PORT + 0);
     HelixManager manager = _participants[0];
 
     ConfigAccessor accessor = manager.getConfigAccessor();
@@ -89,7 +89,7 @@ public class TestConfigThreadpoolSize extends ZkStandAloneCMTestBase {
     accessor.set(scope, "TestMsg." + HelixTaskExecutor.MAX_THREADS, "" + 8);
 
     for (int i = 0; i < NODE_NR; i++) {
-      instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
+      instanceName = "localhost_" + (START_PORT + i);
 
       _participants[i].getMessagingService().registerMessageHandlerFactory("TestMsg",
           new TestMessagingHandlerFactory());
@@ -99,7 +99,7 @@ public class TestConfigThreadpoolSize extends ZkStandAloneCMTestBase {
     }
 
     for (int i = 0; i < NODE_NR; i++) {
-      instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
+      instanceName = "localhost_" + (START_PORT + i);
 
       DefaultMessagingService svc =
           (DefaultMessagingService) (_participants[i].getMessagingService());

http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/messaging/handling/TestResourceThreadpoolSize.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/messaging/handling/TestResourceThreadpoolSize.java b/helix-core/src/test/java/org/apache/helix/messaging/handling/TestResourceThreadpoolSize.java
index a5777ab..97a56be 100644
--- a/helix-core/src/test/java/org/apache/helix/messaging/handling/TestResourceThreadpoolSize.java
+++ b/helix-core/src/test/java/org/apache/helix/messaging/handling/TestResourceThreadpoolSize.java
@@ -46,7 +46,7 @@ public class TestResourceThreadpoolSize extends ZkStandAloneCMTestBase {
 
     boolean result =
         ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
-            ZK_ADDR, CLUSTER_NAME));
+            _zkaddr, CLUSTER_NAME));
     Assert.assertTrue(result);
 
     long taskcount = 0;

http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/model/TestConstraint.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/model/TestConstraint.java b/helix-core/src/test/java/org/apache/helix/model/TestConstraint.java
index 691492e..4d5dd95 100644
--- a/helix-core/src/test/java/org/apache/helix/model/TestConstraint.java
+++ b/helix-core/src/test/java/org/apache/helix/model/TestConstraint.java
@@ -28,25 +28,29 @@ import java.util.TreeMap;
 import org.apache.helix.PropertyKey.Builder;
 import org.apache.helix.TestHelper;
 import org.apache.helix.ZNRecord;
-import org.apache.helix.ZkUnitTestBase;
+import org.apache.helix.api.State;
 import org.apache.helix.api.id.MessageId;
 import org.apache.helix.manager.zk.ZKHelixDataAccessor;
 import org.apache.helix.manager.zk.ZkBaseDataAccessor;
 import org.apache.helix.model.ClusterConstraints.ConstraintAttribute;
 import org.apache.helix.model.ClusterConstraints.ConstraintType;
+import org.apache.helix.model.Message.Attributes;
 import org.apache.helix.model.Message.MessageType;
+import org.apache.helix.testutil.HelixTestUtil;
+import org.apache.helix.testutil.TestUtil;
+import org.apache.helix.testutil.ZkTestBase;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
-public class TestConstraint extends ZkUnitTestBase {
+public class TestConstraint extends ZkTestBase {
 
   @Test
   public void testMsgConstraint() {
-    String className = getShortClassName();
+    String className = TestUtil.getTestName();
     System.out.println("START testMsgConstraint() at " + new Date(System.currentTimeMillis()));
 
     String clusterName = "CLUSTER_" + className + "_msg";
-    TestHelper.setupEmptyCluster(_gZkClient, clusterName);
+    TestHelper.setupEmptyCluster(_zkclient, clusterName);
     ZNRecord record = new ZNRecord("testMsgConstraint");
 
     // constraint0:
@@ -105,7 +109,7 @@ public class TestConstraint extends ZkUnitTestBase {
     ConstraintItem constraint5 = new ConstraintItem(record.getMapField("constraint5"));
 
     ZKHelixDataAccessor accessor =
-        new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_gZkClient));
+        new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_zkclient));
     Builder keyBuilder = accessor.keyBuilder();
 
     accessor.setProperty(keyBuilder.constraint(ConstraintType.MESSAGE_CONSTRAINT.toString()),
@@ -119,7 +123,7 @@ public class TestConstraint extends ZkUnitTestBase {
 
     // message1
     Message msg1 =
-        createMessage(MessageType.STATE_TRANSITION, MessageId.from("msgId-001"), "OFFLINE",
+        HelixTestUtil.newMessage(MessageType.STATE_TRANSITION, MessageId.from("msgId-001"), "OFFLINE",
             "SLAVE", "TestDB", "localhost_12918");
 
     Map<ConstraintAttribute, String> msgAttr = ClusterConstraints.toConstraintAttributes(msg1);
@@ -134,7 +138,7 @@ public class TestConstraint extends ZkUnitTestBase {
 
     // message2
     Message msg2 =
-        createMessage(MessageType.STATE_TRANSITION, MessageId.from("msgId-002"), "OFFLINE",
+        HelixTestUtil.newMessage(MessageType.STATE_TRANSITION, MessageId.from("msgId-002"), "OFFLINE",
             "SLAVE", "TestDB", "localhost_12919");
 
     msgAttr = ClusterConstraints.toConstraintAttributes(msg2);
@@ -152,11 +156,11 @@ public class TestConstraint extends ZkUnitTestBase {
 
   @Test
   public void testStateConstraint() {
-    String className = getShortClassName();
+    String className = TestUtil.getTestName();
     System.out.println("START testStateConstraint() at " + new Date(System.currentTimeMillis()));
 
     String clusterName = "CLUSTER_" + className + "_state";
-    TestHelper.setupEmptyCluster(_gZkClient, clusterName);
+    TestHelper.setupEmptyCluster(_zkclient, clusterName);
     ZNRecord record = new ZNRecord("testStateConstraint");
 
     // constraint0:
@@ -183,7 +187,7 @@ public class TestConstraint extends ZkUnitTestBase {
     ConstraintItem constraint2 = new ConstraintItem(record.getMapField("constraint2"));
 
     ZKHelixDataAccessor accessor =
-        new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
+        new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkclient));
     Builder keyBuilder = accessor.keyBuilder();
 
     accessor.setProperty(keyBuilder.constraint(ConstraintType.STATE_CONSTRAINT.toString()),

http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/monitoring/TestClusterStatusMonitorLifecycle.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/monitoring/TestClusterStatusMonitorLifecycle.java b/helix-core/src/test/java/org/apache/helix/monitoring/TestClusterStatusMonitorLifecycle.java
index d8e1cab..c31b641 100644
--- a/helix-core/src/test/java/org/apache/helix/monitoring/TestClusterStatusMonitorLifecycle.java
+++ b/helix-core/src/test/java/org/apache/helix/monitoring/TestClusterStatusMonitorLifecycle.java
@@ -29,11 +29,11 @@ import javax.management.MalformedObjectNameException;
 
 import org.apache.helix.HelixDataAccessor;
 import org.apache.helix.TestHelper;
-import org.apache.helix.integration.ZkIntegrationTestBase;
 import org.apache.helix.integration.manager.ClusterDistributedController;
 import org.apache.helix.integration.manager.MockParticipantManager;
 import org.apache.helix.model.IdealState;
 import org.apache.helix.monitoring.mbeans.ClusterMBeanObserver;
+import org.apache.helix.testutil.ZkTestBase;
 import org.apache.helix.tools.ClusterSetup;
 import org.apache.helix.tools.ClusterStateVerifier;
 import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier;
@@ -43,7 +43,7 @@ import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
-public class TestClusterStatusMonitorLifecycle extends ZkIntegrationTestBase {
+public class TestClusterStatusMonitorLifecycle extends ZkTestBase {
   private static final Logger LOG = Logger.getLogger(TestClusterStatusMonitorLifecycle.class);
 
   MockParticipantManager[] _participants;
@@ -69,7 +69,7 @@ public class TestClusterStatusMonitorLifecycle extends ZkIntegrationTestBase {
       String clusterName = _clusterNamePrefix + "0_" + i;
       String participantName = "localhost" + i;
       String resourceName = "TestDB" + i;
-      TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
+      TestHelper.setupCluster(clusterName, _zkaddr, 12918, // participant port
           participantName, // participant name prefix
           resourceName, // resource name prefix
           1, // resources
@@ -81,7 +81,7 @@ public class TestClusterStatusMonitorLifecycle extends ZkIntegrationTestBase {
 
     // setup controller cluster
     _controllerClusterName = "CONTROLLER_" + _clusterNamePrefix;
-    TestHelper.setupCluster("CONTROLLER_" + _clusterNamePrefix, ZK_ADDR, 0, // controller
+    TestHelper.setupCluster("CONTROLLER_" + _clusterNamePrefix, _zkaddr, 0, // controller
                                                                             // port
         "controller", // participant name prefix
         _clusterNamePrefix, // resource name prefix
@@ -95,13 +95,13 @@ public class TestClusterStatusMonitorLifecycle extends ZkIntegrationTestBase {
     _controllers = new ClusterDistributedController[n + n];
     for (int i = 0; i < n; i++) {
       _controllers[i] =
-          new ClusterDistributedController(ZK_ADDR, _controllerClusterName, "controller_" + i);
+          new ClusterDistributedController(_zkaddr, _controllerClusterName, "controller_" + i);
       _controllers[i].syncStart();
     }
 
     boolean result =
         ClusterStateVerifier.verifyByZkCallback(
-            new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, _controllerClusterName),
+            new ClusterStateVerifier.BestPossAndExtViewZkVerifier(_zkaddr, _controllerClusterName),
             30000);
     Assert.assertTrue(result, "Controller cluster NOT in ideal state");
 
@@ -110,38 +110,37 @@ public class TestClusterStatusMonitorLifecycle extends ZkIntegrationTestBase {
     _firstClusterName = _clusterNamePrefix + "0_0";
     for (int i = 0; i < n; i++) {
       String instanceName = "localhost0_" + (12918 + i);
-      _participants[i] = new MockParticipantManager(ZK_ADDR, _firstClusterName, instanceName);
+      _participants[i] = new MockParticipantManager(_zkaddr, _firstClusterName, instanceName);
       _participants[i].syncStart();
     }
 
     result =
-        ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
+        ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(_zkaddr,
             _firstClusterName));
     Assert.assertTrue(result, "first cluster NOT in ideal state");
 
     // add more controllers to controller cluster
-    ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
     for (int i = 0; i < n; i++) {
       String controller = "controller_" + (n + i);
-      setupTool.addInstanceToCluster(_controllerClusterName, controller);
+      _setupTool.addInstanceToCluster(_controllerClusterName, controller);
     }
-    setupTool.rebalanceStorageCluster(_controllerClusterName, _clusterNamePrefix + "0", 6);
+    _setupTool.rebalanceStorageCluster(_controllerClusterName, _clusterNamePrefix + "0", 6);
     for (int i = n; i < 2 * n; i++) {
       _controllers[i] =
-          new ClusterDistributedController(ZK_ADDR, _controllerClusterName, "controller_" + i);
+          new ClusterDistributedController(_zkaddr, _controllerClusterName, "controller_" + i);
       _controllers[i].syncStart();
     }
 
     // verify controller cluster
     result =
         ClusterStateVerifier
-            .verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR,
+            .verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(_zkaddr,
                 _controllerClusterName));
     Assert.assertTrue(result, "Controller cluster NOT in ideal state");
 
     // verify first cluster
     result =
-        ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
+        ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(_zkaddr,
             _firstClusterName));
     Assert.assertTrue(result, "first cluster NOT in ideal state");
   }
@@ -223,7 +222,7 @@ public class TestClusterStatusMonitorLifecycle extends ZkIntegrationTestBase {
     Assert.assertEquals(nMbeansRegistered, listener._nMbeansRegistered - 12);
 
     String instanceName = "localhost0_" + (12918 + 0);
-    _participants[0] = new MockParticipantManager(ZK_ADDR, _firstClusterName, instanceName);
+    _participants[0] = new MockParticipantManager(_zkaddr, _firstClusterName, instanceName);
     _participants[0].syncStart();
 
     // 1 participant comes back
@@ -236,12 +235,11 @@ public class TestClusterStatusMonitorLifecycle extends ZkIntegrationTestBase {
     // Add a resource
     // Register 1 resource mbean
     // Register 5 per-instance resource mbean
-    ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
     IdealState idealState = accessor.getProperty(accessor.keyBuilder().idealStates("TestDB00"));
 
-    setupTool.addResourceToCluster(_firstClusterName, "TestDB1", idealState.getNumPartitions(),
+    _setupTool.addResourceToCluster(_firstClusterName, "TestDB1", idealState.getNumPartitions(),
         "MasterSlave");
-    setupTool.rebalanceResource(_firstClusterName, "TestDB1",
+    _setupTool.rebalanceResource(_firstClusterName, "TestDB1",
         Integer.parseInt(idealState.getReplicas()));
 
     Thread.sleep(1000);
@@ -251,7 +249,7 @@ public class TestClusterStatusMonitorLifecycle extends ZkIntegrationTestBase {
     // Remove a resource
     // No change in instance/resource mbean
     // Unregister 5 per-instance resource mbean
-    setupTool.dropResourceFromCluster(_firstClusterName, "TestDB1");
+    _setupTool.dropResourceFromCluster(_firstClusterName, "TestDB1");
     Thread.sleep(1000);
     Assert.assertEquals(nMbeansUnregistered, listener._nMbeansUnregistered - 22);
     Assert.assertEquals(nMbeansRegistered, listener._nMbeansRegistered - 20);

http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/monitoring/TestZKPathDataDumpTask.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/monitoring/TestZKPathDataDumpTask.java b/helix-core/src/test/java/org/apache/helix/monitoring/TestZKPathDataDumpTask.java
index d073dd2..2eb3321 100644
--- a/helix-core/src/test/java/org/apache/helix/monitoring/TestZKPathDataDumpTask.java
+++ b/helix-core/src/test/java/org/apache/helix/monitoring/TestZKPathDataDumpTask.java
@@ -30,15 +30,14 @@ import org.apache.helix.HelixManager;
 import org.apache.helix.PropertyKey;
 import org.apache.helix.TestHelper;
 import org.apache.helix.ZNRecord;
-import org.apache.helix.ZkUnitTestBase;
 import org.apache.helix.manager.zk.ZKHelixDataAccessor;
-import org.apache.helix.manager.zk.ZkBaseDataAccessor;
 import org.apache.helix.model.Error;
 import org.apache.helix.model.StatusUpdate;
+import org.apache.helix.testutil.ZkTestBase;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
-public class TestZKPathDataDumpTask extends ZkUnitTestBase {
+public class TestZKPathDataDumpTask extends ZkTestBase {
 
   @Test
   public void test() throws Exception {
@@ -49,7 +48,7 @@ public class TestZKPathDataDumpTask extends ZkUnitTestBase {
 
     System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
 
-    TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
+    TestHelper.setupCluster(clusterName, _zkaddr, 12918, // participant port
         "localhost", // participant name prefix
         "TestDB", // resource name prefix
         1, // resources
@@ -59,7 +58,7 @@ public class TestZKPathDataDumpTask extends ZkUnitTestBase {
         "MasterSlave", true); // do rebalance
 
     HelixDataAccessor accessor =
-        new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
+        new ZKHelixDataAccessor(clusterName, _baseAccessor);
     PropertyKey.Builder keyBuilder = accessor.keyBuilder();
     BaseDataAccessor<ZNRecord> baseAccessor = accessor.getBaseDataAccessor();
 
@@ -122,7 +121,7 @@ public class TestZKPathDataDumpTask extends ZkUnitTestBase {
 
     System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
 
-    TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
+    TestHelper.setupCluster(clusterName, _zkaddr, 12918, // participant port
         "localhost", // participant name prefix
         "TestDB", // resource name prefix
         1, // resources
@@ -132,7 +131,7 @@ public class TestZKPathDataDumpTask extends ZkUnitTestBase {
         "MasterSlave", true); // do rebalance
 
     HelixDataAccessor accessor =
-        new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
+        new ZKHelixDataAccessor(clusterName, _baseAccessor);
     PropertyKey.Builder keyBuilder = accessor.keyBuilder();
     BaseDataAccessor<ZNRecord> baseAccessor = accessor.getBaseDataAccessor();
 

http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/monitoring/mbeans/TestDropResourceMetricsReset.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/monitoring/mbeans/TestDropResourceMetricsReset.java b/helix-core/src/test/java/org/apache/helix/monitoring/mbeans/TestDropResourceMetricsReset.java
index 17d45de..17e1837 100644
--- a/helix-core/src/test/java/org/apache/helix/monitoring/mbeans/TestDropResourceMetricsReset.java
+++ b/helix-core/src/test/java/org/apache/helix/monitoring/mbeans/TestDropResourceMetricsReset.java
@@ -31,15 +31,15 @@ import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
 import org.apache.helix.TestHelper;
-import org.apache.helix.ZkUnitTestBase;
 import org.apache.helix.integration.manager.ClusterControllerManager;
 import org.apache.helix.integration.manager.MockParticipantManager;
 import org.apache.helix.model.IdealState.RebalanceMode;
+import org.apache.helix.testutil.ZkTestBase;
 import org.apache.helix.tools.ClusterSetup;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
-public class TestDropResourceMetricsReset extends ZkUnitTestBase {
+public class TestDropResourceMetricsReset extends ZkTestBase {
   private final CountDownLatch _registerLatch = new CountDownLatch(1);
   private final CountDownLatch _unregisterLatch = new CountDownLatch(1);
 
@@ -59,7 +59,7 @@ public class TestDropResourceMetricsReset extends ZkUnitTestBase {
         new ParticipantMonitorListener("ClusterStatus", clusterName, RESOURCE_NAME);
 
     // Set up cluster
-    TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
+    TestHelper.setupCluster(clusterName, _zkaddr, 12918, // participant port
         "localhost", // participant name prefix
         "TestDB", // resource name prefix
         1, // resources
@@ -70,15 +70,15 @@ public class TestDropResourceMetricsReset extends ZkUnitTestBase {
         true); // do rebalance
 
     // Start participants and controller
-    ClusterSetup setupTool = new ClusterSetup(_gZkClient);
+    ClusterSetup setupTool = new ClusterSetup(_zkclient);
     MockParticipantManager[] participants = new MockParticipantManager[NUM_PARTICIPANTS];
     for (int i = 0; i < NUM_PARTICIPANTS; i++) {
       participants[i] =
-          new MockParticipantManager(ZK_ADDR, clusterName, "localhost_" + (12918 + i));
+          new MockParticipantManager(_zkaddr, clusterName, "localhost_" + (12918 + i));
       participants[i].syncStart();
     }
     ClusterControllerManager controller =
-        new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+        new ClusterControllerManager(_zkaddr, clusterName, "controller_0");
     controller.syncStart();
 
     // Verify that the bean was created

http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/monitoring/mbeans/TestResetClusterMetrics.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/monitoring/mbeans/TestResetClusterMetrics.java b/helix-core/src/test/java/org/apache/helix/monitoring/mbeans/TestResetClusterMetrics.java
index 74f84e8..5497138 100644
--- a/helix-core/src/test/java/org/apache/helix/monitoring/mbeans/TestResetClusterMetrics.java
+++ b/helix-core/src/test/java/org/apache/helix/monitoring/mbeans/TestResetClusterMetrics.java
@@ -27,15 +27,15 @@ import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
 import org.apache.helix.TestHelper;
-import org.apache.helix.ZkUnitTestBase;
 import org.apache.helix.integration.manager.ClusterControllerManager;
 import org.apache.helix.integration.manager.MockParticipantManager;
 import org.apache.helix.model.IdealState.RebalanceMode;
+import org.apache.helix.testutil.ZkTestBase;
 import org.apache.helix.tools.ClusterStateVerifier;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
-public class TestResetClusterMetrics extends ZkUnitTestBase {
+public class TestResetClusterMetrics extends ZkTestBase {
   /**
    * Ensure cluster status lifecycle is tied to controller leader status
    */
@@ -46,24 +46,24 @@ public class TestResetClusterMetrics extends ZkUnitTestBase {
     String clusterName = className + "_" + methodName;
 
     // Set up a cluster with one of everything
-    TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, "localhost", "Resource", 1, 1, 1, 1,
+    TestHelper.setupCluster(clusterName, _zkaddr, 12918, "localhost", "Resource", 1, 1, 1, 1,
         "OnlineOffline", RebalanceMode.FULL_AUTO, true);
 
     // Add a participant
     MockParticipantManager participant =
-        new MockParticipantManager(ZK_ADDR, clusterName, "localhost_12918");
+        new MockParticipantManager(_zkaddr, clusterName, "localhost_12918");
     participant.syncStart();
 
     // Add a controller
     ClusterControllerManager controller =
-        new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+        new ClusterControllerManager(_zkaddr, clusterName, "controller_0");
     controller.syncStart();
 
     // Make sure everything gets assigned
     Thread.sleep(1000);
     boolean result =
         ClusterStateVerifier
-            .verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR,
+            .verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(_zkaddr,
                 clusterName));
     Assert.assertTrue(result);
 

http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerElection.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerElection.java b/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerElection.java
index 2e175d5..de510c1 100644
--- a/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerElection.java
+++ b/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerElection.java
@@ -32,40 +32,40 @@ import org.apache.helix.PropertyPathConfig;
 import org.apache.helix.PropertyType;
 import org.apache.helix.TestHelper;
 import org.apache.helix.ZNRecord;
-import org.apache.helix.ZkUnitTestBase;
 import org.apache.helix.controller.GenericHelixController;
 import org.apache.helix.manager.zk.DistributedLeaderElection;
 import org.apache.helix.manager.zk.ZKHelixDataAccessor;
-import org.apache.helix.manager.zk.ZkBaseDataAccessor;
 import org.apache.helix.model.LiveInstance;
+import org.apache.helix.testutil.TestUtil;
+import org.apache.helix.testutil.ZkTestBase;
 import org.apache.log4j.Logger;
 import org.testng.AssertJUnit;
 import org.testng.annotations.Test;
 
-public class TestDistControllerElection extends ZkUnitTestBase {
+public class TestDistControllerElection extends ZkTestBase {
   private static Logger LOG = Logger.getLogger(TestDistControllerElection.class);
 
   @Test()
   public void testController() throws Exception {
     System.out.println("START TestDistControllerElection at "
         + new Date(System.currentTimeMillis()));
-    String className = getShortClassName();
+    String className = TestUtil.getTestName();
 
-    final String clusterName = CLUSTER_PREFIX + "_" + className + "_" + "testController";
+    final String clusterName = className;
     String path = "/" + clusterName;
-    if (_gZkClient.exists(path)) {
-      _gZkClient.deleteRecursive(path);
+    if (_zkclient.exists(path)) {
+      _zkclient.deleteRecursive(path);
     }
 
     ZKHelixDataAccessor accessor =
-        new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_gZkClient));
+        new ZKHelixDataAccessor(clusterName, _baseAccessor);
     Builder keyBuilder = accessor.keyBuilder();
 
-    TestHelper.setupEmptyCluster(_gZkClient, clusterName);
+    TestHelper.setupEmptyCluster(_zkclient, clusterName);
 
     final String controllerName = "controller_0";
     HelixManager manager =
-        new MockZKHelixManager(clusterName, controllerName, InstanceType.CONTROLLER, _gZkClient);
+        new MockZKHelixManager(clusterName, controllerName, InstanceType.CONTROLLER, _zkclient);
     GenericHelixController controller0 = new GenericHelixController();
 
     List<HelixTimerTask> timerTasks = Collections.emptyList();
@@ -76,20 +76,20 @@ public class TestDistControllerElection extends ZkUnitTestBase {
     election.onControllerChange(context);
 
     // path = PropertyPathConfig.getPath(PropertyType.LEADER, clusterName);
-    // ZNRecord leaderRecord = _gZkClient.<ZNRecord> readData(path);
+    // ZNRecord leaderRecord = zkclient.<ZNRecord> readData(path);
     LiveInstance liveInstance = accessor.getProperty(keyBuilder.controllerLeader());
     AssertJUnit.assertEquals(controllerName, liveInstance.getInstanceName());
     // AssertJUnit.assertNotNull(election.getController());
     // AssertJUnit.assertNull(election.getLeader());
 
     manager =
-        new MockZKHelixManager(clusterName, "controller_1", InstanceType.CONTROLLER, _gZkClient);
+        new MockZKHelixManager(clusterName, "controller_1", InstanceType.CONTROLLER, _zkclient);
     GenericHelixController controller1 = new GenericHelixController();
     election = new DistributedLeaderElection(manager, controller1, timerTasks);
     context = new NotificationContext(manager);
     context.setType(NotificationContext.Type.INIT);
     election.onControllerChange(context);
-    // leaderRecord = _gZkClient.<ZNRecord> readData(path);
+    // leaderRecord = zkclient.<ZNRecord> readData(path);
     liveInstance = accessor.getProperty(keyBuilder.controllerLeader());
     AssertJUnit.assertEquals(controllerName, liveInstance.getInstanceName());
     // AssertJUnit.assertNull(election.getController());
@@ -100,26 +100,26 @@ public class TestDistControllerElection extends ZkUnitTestBase {
 
   @Test()
   public void testControllerParticipant() throws Exception {
-    String className = getShortClassName();
+    String className = TestUtil.getTestName();
     LOG.info("RUN " + className + " at " + new Date(System.currentTimeMillis()));
 
-    final String clusterName =
-        CONTROLLER_CLUSTER_PREFIX + "_" + className + "_" + "testControllerParticipant";
+    final String clusterName = className;
+
     String path = "/" + clusterName;
-    if (_gZkClient.exists(path)) {
-      _gZkClient.deleteRecursive(path);
+    if (_zkclient.exists(path)) {
+      _zkclient.deleteRecursive(path);
     }
 
     ZKHelixDataAccessor accessor =
-        new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_gZkClient));
+        new ZKHelixDataAccessor(clusterName, _baseAccessor);
     Builder keyBuilder = accessor.keyBuilder();
 
-    TestHelper.setupEmptyCluster(_gZkClient, clusterName);
+    TestHelper.setupEmptyCluster(_zkclient, clusterName);
 
     final String controllerName = "controller_0";
     HelixManager manager =
         new MockZKHelixManager(clusterName, controllerName, InstanceType.CONTROLLER_PARTICIPANT,
-            _gZkClient);
+            _zkclient);
     GenericHelixController controller0 = new GenericHelixController();
     List<HelixTimerTask> timerTasks = Collections.emptyList();
 
@@ -133,14 +133,14 @@ public class TestDistControllerElection extends ZkUnitTestBase {
     AssertJUnit.assertEquals(controllerName, liveInstance.getInstanceName());
 
     // path = PropertyPathConfig.getPath(PropertyType.LEADER, clusterName);
-    // ZNRecord leaderRecord = _gZkClient.<ZNRecord> readData(path);
+    // ZNRecord leaderRecord = zkclient.<ZNRecord> readData(path);
     // AssertJUnit.assertEquals(controllerName, leaderRecord.getSimpleField("LEADER"));
     // AssertJUnit.assertNotNull(election.getController());
     // AssertJUnit.assertNotNull(election.getLeader());
 
     manager =
         new MockZKHelixManager(clusterName, "controller_1", InstanceType.CONTROLLER_PARTICIPANT,
-            _gZkClient);
+            _zkclient);
     GenericHelixController controller1 = new GenericHelixController();
     election = new DistributedLeaderElection(manager, controller1, timerTasks);
     context = new NotificationContext(manager);
@@ -150,29 +150,29 @@ public class TestDistControllerElection extends ZkUnitTestBase {
     liveInstance = accessor.getProperty(keyBuilder.controllerLeader());
     AssertJUnit.assertEquals(controllerName, liveInstance.getInstanceName());
 
-    // leaderRecord = _gZkClient.<ZNRecord> readData(path);
+    // leaderRecord = zkclient.<ZNRecord> readData(path);
     // AssertJUnit.assertEquals(controllerName, leaderRecord.getSimpleField("LEADER"));
     // AssertJUnit.assertNull(election.getController());
     // AssertJUnit.assertNull(election.getLeader());
 
-    LOG.info("END " + getShortClassName() + " at " + new Date(System.currentTimeMillis()));
+    LOG.info("END " + className + " at " + new Date(System.currentTimeMillis()));
   }
 
   @Test()
   public void testParticipant() throws Exception {
-    String className = getShortClassName();
+    String className = TestUtil.getTestName();
     LOG.info("RUN " + className + " at " + new Date(System.currentTimeMillis()));
 
-    final String clusterName = CLUSTER_PREFIX + "_" + className + "_" + "testParticipant";
+    final String clusterName = className;
     String path = "/" + clusterName;
-    if (_gZkClient.exists(path)) {
-      _gZkClient.deleteRecursive(path);
+    if (_zkclient.exists(path)) {
+      _zkclient.deleteRecursive(path);
     }
-    TestHelper.setupEmptyCluster(_gZkClient, clusterName);
+    TestHelper.setupEmptyCluster(_zkclient, clusterName);
 
     final String controllerName = "participant_0";
     HelixManager manager =
-        new MockZKHelixManager(clusterName, controllerName, InstanceType.PARTICIPANT, _gZkClient);
+        new MockZKHelixManager(clusterName, controllerName, InstanceType.PARTICIPANT, _zkclient);
     GenericHelixController participant0 = new GenericHelixController();
     List<HelixTimerTask> timerTasks = Collections.emptyList();
 
@@ -183,7 +183,7 @@ public class TestDistControllerElection extends ZkUnitTestBase {
     election.onControllerChange(context);
 
     path = PropertyPathConfig.getPath(PropertyType.LEADER, clusterName);
-    ZNRecord leaderRecord = _gZkClient.<ZNRecord> readData(path, true);
+    ZNRecord leaderRecord = _zkclient.<ZNRecord> readData(path, true);
     AssertJUnit.assertNull(leaderRecord);
     // AssertJUnit.assertNull(election.getController());
     // AssertJUnit.assertNull(election.getLeader());

http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerStateModel.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerStateModel.java b/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerStateModel.java
index 9036cf3..116cd72 100644
--- a/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerStateModel.java
+++ b/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerStateModel.java
@@ -21,29 +21,29 @@ package org.apache.helix.participant;
 
 import org.apache.helix.NotificationContext;
 import org.apache.helix.TestHelper;
-import org.apache.helix.ZkUnitTestBase;
 import org.apache.helix.api.id.MessageId;
 import org.apache.helix.api.id.PartitionId;
 import org.apache.helix.model.Message;
 import org.apache.helix.model.Message.MessageType;
 import org.apache.helix.participant.DistClusterControllerStateModel;
+import org.apache.helix.testutil.ZkTestBase;
 import org.apache.log4j.Logger;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
-public class TestDistControllerStateModel extends ZkUnitTestBase {
+public class TestDistControllerStateModel extends ZkTestBase {
   private static Logger LOG = Logger.getLogger(TestDistControllerStateModel.class);
 
-  final String clusterName = CLUSTER_PREFIX + "_" + getShortClassName();
+  final String clusterName = "TestDistControllerStateModel";
   DistClusterControllerStateModel stateModel = null;
 
   @BeforeMethod()
   public void beforeMethod() {
-    stateModel = new DistClusterControllerStateModel(ZK_ADDR);
-    if (_gZkClient.exists("/" + clusterName)) {
-      _gZkClient.deleteRecursive("/" + clusterName);
+    stateModel = new DistClusterControllerStateModel(_zkaddr);
+    if (_zkclient.exists("/" + clusterName)) {
+      _zkclient.deleteRecursive("/" + clusterName);
     }
-    TestHelper.setupEmptyCluster(_gZkClient, clusterName);
+    TestHelper.setupEmptyCluster(_zkclient, clusterName);
   }
 
   @Test()

http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerStateModelFactory.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerStateModelFactory.java b/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerStateModelFactory.java
index 43ffb9a..26d65f0 100644
--- a/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerStateModelFactory.java
+++ b/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerStateModelFactory.java
@@ -19,18 +19,14 @@ package org.apache.helix.participant;
  * under the License.
  */
 
-import org.apache.helix.ZkUnitTestBase;
 import org.testng.annotations.Test;
 
 public class TestDistControllerStateModelFactory {
-  final String zkAddr = ZkUnitTestBase.ZK_ADDR;
 
-  @Test(groups = {
-    "unitTest"
-  })
+  @Test()
   public void testDistControllerStateModelFactory() {
     DistClusterControllerStateModelFactory factory =
-        new DistClusterControllerStateModelFactory(zkAddr);
+        new DistClusterControllerStateModelFactory("localhost:2181");
     DistClusterControllerStateModel stateModel = factory.createNewStateModel("key");
     stateModel.onBecomeStandbyFromOffline(null, null);
   }

http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/store/zk/TestAutoFallbackPropertyStore.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/store/zk/TestAutoFallbackPropertyStore.java b/helix-core/src/test/java/org/apache/helix/store/zk/TestAutoFallbackPropertyStore.java
index 8bb1686..54ea3a9 100644
--- a/helix-core/src/test/java/org/apache/helix/store/zk/TestAutoFallbackPropertyStore.java
+++ b/helix-core/src/test/java/org/apache/helix/store/zk/TestAutoFallbackPropertyStore.java
@@ -28,13 +28,13 @@ import org.apache.helix.AccessOption;
 import org.apache.helix.PropertyType;
 import org.apache.helix.TestHelper;
 import org.apache.helix.ZNRecord;
-import org.apache.helix.ZkUnitTestBase;
 import org.apache.helix.manager.zk.ZkBaseDataAccessor;
+import org.apache.helix.testutil.ZkTestBase;
 import org.apache.zookeeper.data.Stat;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
-public class TestAutoFallbackPropertyStore extends ZkUnitTestBase {
+public class TestAutoFallbackPropertyStore extends ZkTestBase {
 
   class MyDataUpdater implements DataUpdater<ZNRecord> {
     final String _id;
@@ -63,7 +63,7 @@ public class TestAutoFallbackPropertyStore extends ZkUnitTestBase {
     System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
     String root = String.format("/%s/%s", clusterName, PropertyType.PROPERTYSTORE.name());
     String fallbackRoot = String.format("/%s/%s", clusterName, "HELIX_PROPERTYSTORE");
-    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
 
     // create 0 under fallbackRoot
     for (int i = 0; i < 1; i++) {
@@ -108,7 +108,7 @@ public class TestAutoFallbackPropertyStore extends ZkUnitTestBase {
     System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
     String root = String.format("/%s/%s", clusterName, PropertyType.PROPERTYSTORE.name());
     String fallbackRoot = String.format("/%s/%s", clusterName, "HELIX_PROPERTYSTORE");
-    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
 
     // create 0 under both fallbackRoot and root
     for (int i = 0; i < 1; i++) {
@@ -154,7 +154,7 @@ public class TestAutoFallbackPropertyStore extends ZkUnitTestBase {
     System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
     String root = String.format("/%s/%s", clusterName, PropertyType.PROPERTYSTORE.name());
     String fallbackRoot = String.format("/%s/%s", clusterName, "HELIX_PROPERTYSTORE");
-    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
 
     // create 0-9 under fallbackRoot
     for (int i = 0; i < 10; i++) {
@@ -208,7 +208,7 @@ public class TestAutoFallbackPropertyStore extends ZkUnitTestBase {
     System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
     String root = String.format("/%s/%s", clusterName, PropertyType.PROPERTYSTORE.name());
     String fallbackRoot = String.format("/%s/%s", clusterName, "HELIX_PROPERTYSTORE");
-    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
 
     // create 0-9 under both fallbackRoot and new root
     for (int i = 0; i < 10; i++) {
@@ -282,7 +282,7 @@ public class TestAutoFallbackPropertyStore extends ZkUnitTestBase {
     System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
     String root = String.format("/%s/%s", clusterName, PropertyType.PROPERTYSTORE.name());
     String fallbackRoot = String.format("/%s/%s", clusterName, "HELIX_PROPERTYSTORE");
-    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
 
     // create 0 under fallbackRoot
     for (int i = 0; i < 1; i++) {
@@ -322,7 +322,7 @@ public class TestAutoFallbackPropertyStore extends ZkUnitTestBase {
     System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
     String root = String.format("/%s/%s", clusterName, PropertyType.PROPERTYSTORE.name());
     String fallbackRoot = String.format("/%s/%s", clusterName, "HELIX_PROPERTYSTORE");
-    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
 
     // create 0-9 under fallbackRoot
     for (int i = 0; i < 10; i++) {
@@ -371,7 +371,7 @@ public class TestAutoFallbackPropertyStore extends ZkUnitTestBase {
     System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
     String root = String.format("/%s/%s", clusterName, PropertyType.PROPERTYSTORE.name());
     String fallbackRoot = String.format("/%s/%s", clusterName, "HELIX_PROPERTYSTORE");
-    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
 
     // create 0 under fallbackRoot
     for (int i = 0; i < 1; i++) {
@@ -416,7 +416,7 @@ public class TestAutoFallbackPropertyStore extends ZkUnitTestBase {
     System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
     String root = String.format("/%s/%s", clusterName, PropertyType.PROPERTYSTORE.name());
     String fallbackRoot = String.format("/%s/%s", clusterName, "HELIX_PROPERTYSTORE");
-    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
 
     // create 0-9 under fallbackRoot
     for (int i = 0; i < 10; i++) {
@@ -474,7 +474,7 @@ public class TestAutoFallbackPropertyStore extends ZkUnitTestBase {
     System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
     String root = String.format("/%s/%s", clusterName, PropertyType.PROPERTYSTORE.name());
     String fallbackRoot = String.format("/%s/%s", clusterName, "HELIX_PROPERTYSTORE");
-    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
 
     AutoFallbackPropertyStore<ZNRecord> store =
         new AutoFallbackPropertyStore<ZNRecord>(baseAccessor, root, fallbackRoot);
@@ -509,7 +509,7 @@ public class TestAutoFallbackPropertyStore extends ZkUnitTestBase {
     System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
     String root = String.format("/%s/%s", clusterName, PropertyType.PROPERTYSTORE.name());
     String fallbackRoot = String.format("/%s/%s", clusterName, "HELIX_PROPERTYSTORE");
-    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
 
     // create 0-9 under fallbackRoot
     for (int i = 0; i < 10; i++) {
@@ -584,7 +584,7 @@ public class TestAutoFallbackPropertyStore extends ZkUnitTestBase {
     System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
     String root = String.format("/%s/%s", clusterName, PropertyType.PROPERTYSTORE.name());
     String fallbackRoot = String.format("/%s/%s", clusterName, "HELIX_PROPERTYSTORE");
-    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+    ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
 
     // create 0-9 under fallbackRoot and 10-19 under root
     for (int i = 0; i < 20; i++) {

http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/store/zk/TestZkHelixPropertyStore.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/store/zk/TestZkHelixPropertyStore.java b/helix-core/src/test/java/org/apache/helix/store/zk/TestZkHelixPropertyStore.java
index b07cf8f..0dfe696 100644
--- a/helix-core/src/test/java/org/apache/helix/store/zk/TestZkHelixPropertyStore.java
+++ b/helix-core/src/test/java/org/apache/helix/store/zk/TestZkHelixPropertyStore.java
@@ -30,15 +30,15 @@ import java.util.TreeMap;
 import org.I0Itec.zkclient.exception.ZkNoNodeException;
 import org.apache.helix.AccessOption;
 import org.apache.helix.ZNRecord;
-import org.apache.helix.ZkUnitTestBase;
 import org.apache.helix.manager.zk.ZkBaseDataAccessor;
 import org.apache.helix.manager.zk.ZkClient;
 import org.apache.helix.store.HelixPropertyListener;
+import org.apache.helix.testutil.ZkTestBase;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
-public class TestZkHelixPropertyStore extends ZkUnitTestBase {
-  final String _root = "/" + getShortClassName();
+public class TestZkHelixPropertyStore extends ZkTestBase {
+  final String _root = "/TestZkHelixPropertyStore";
   final int bufSize = 128;
   final int mapNr = 10;
   final int firstLevelNr = 10;
@@ -83,7 +83,7 @@ public class TestZkHelixPropertyStore extends ZkUnitTestBase {
     List<String> subscribedPaths = new ArrayList<String>();
     subscribedPaths.add(subRoot);
     ZkHelixPropertyStore<ZNRecord> store =
-        new ZkHelixPropertyStore<ZNRecord>(new ZkBaseDataAccessor<ZNRecord>(_gZkClient), subRoot,
+        new ZkHelixPropertyStore<ZNRecord>(new ZkBaseDataAccessor<ZNRecord>(_zkclient), subRoot,
             subscribedPaths);
 
     // test set
@@ -117,7 +117,7 @@ public class TestZkHelixPropertyStore extends ZkUnitTestBase {
   public void testSetInvalidPath() {
     String subRoot = _root + "/" + "setInvalidPath";
     ZkHelixPropertyStore<ZNRecord> store =
-        new ZkHelixPropertyStore<ZNRecord>(new ZkBaseDataAccessor<ZNRecord>(_gZkClient), subRoot,
+        new ZkHelixPropertyStore<ZNRecord>(new ZkBaseDataAccessor<ZNRecord>(_zkclient), subRoot,
             null);
     try {
       store.set("abc/xyz", new ZNRecord("testInvalid"), AccessOption.PERSISTENT);
@@ -139,7 +139,7 @@ public class TestZkHelixPropertyStore extends ZkUnitTestBase {
     List<String> subscribedPaths = new ArrayList<String>();
     subscribedPaths.add(subRoot);
     ZkHelixPropertyStore<ZNRecord> store =
-        new ZkHelixPropertyStore<ZNRecord>(new ZkBaseDataAccessor<ZNRecord>(_gZkClient), subRoot,
+        new ZkHelixPropertyStore<ZNRecord>(new ZkBaseDataAccessor<ZNRecord>(_zkclient), subRoot,
             subscribedPaths);
 
     // change nodes via property store interface
@@ -200,7 +200,7 @@ public class TestZkHelixPropertyStore extends ZkUnitTestBase {
     String subRoot = _root + "/" + "zkCallback";
     List<String> subscribedPaths = Arrays.asList(subRoot);
     ZkHelixPropertyStore<ZNRecord> store =
-        new ZkHelixPropertyStore<ZNRecord>(new ZkBaseDataAccessor<ZNRecord>(_gZkClient), subRoot,
+        new ZkHelixPropertyStore<ZNRecord>(new ZkBaseDataAccessor<ZNRecord>(_zkclient), subRoot,
             subscribedPaths);
 
     // change nodes via property store interface
@@ -210,7 +210,7 @@ public class TestZkHelixPropertyStore extends ZkUnitTestBase {
 
     // test create callbacks
     listener.reset();
-    setNodes(_gZkClient, subRoot, 'a', true);
+    setNodes(_zkclient, subRoot, 'a', true);
     int expectCreateNodes = 1 + firstLevelNr + firstLevelNr * secondLevelNr;
     Thread.sleep(500);
 
@@ -221,7 +221,7 @@ public class TestZkHelixPropertyStore extends ZkUnitTestBase {
 
     // test change callbacks
     listener.reset();
-    setNodes(_gZkClient, subRoot, 'b', true);
+    setNodes(_zkclient, subRoot, 'b', true);
     int expectChangeNodes = firstLevelNr * secondLevelNr;
     for (int i = 0; i < 10; i++) {
       if (listener._changeKeys.size() >= expectChangeNodes)
@@ -237,7 +237,7 @@ public class TestZkHelixPropertyStore extends ZkUnitTestBase {
     // test delete callbacks
     listener.reset();
     int expectDeleteNodes = 1 + firstLevelNr + firstLevelNr * secondLevelNr;
-    _gZkClient.deleteRecursive(subRoot);
+    _zkclient.deleteRecursive(subRoot);
     Thread.sleep(1000);
 
     System.out.println("createKey#:" + listener._createKeys.size() + ", changeKey#:"
@@ -258,7 +258,7 @@ public class TestZkHelixPropertyStore extends ZkUnitTestBase {
     List<String> subscribedPaths = new ArrayList<String>();
     subscribedPaths.add(subRoot);
     ZkHelixPropertyStore<ZNRecord> store =
-        new ZkHelixPropertyStore<ZNRecord>(new ZkBaseDataAccessor<ZNRecord>(_gZkClient), subRoot,
+        new ZkHelixPropertyStore<ZNRecord>(new ZkBaseDataAccessor<ZNRecord>(_zkclient), subRoot,
             subscribedPaths);
 
     store.set("/child0", new ZNRecord("child0"), AccessOption.PERSISTENT);
@@ -269,8 +269,8 @@ public class TestZkHelixPropertyStore extends ZkUnitTestBase {
 
     String child0Path = subRoot + "/child0";
     for (int i = 0; i < 2; i++) {
-      _gZkClient.delete(child0Path);
-      _gZkClient.createPersistent(child0Path, new ZNRecord("child0-new-" + i));
+      _zkclient.delete(child0Path);
+      _zkclient.createPersistent(child0Path, new ZNRecord("child0-new-" + i));
     }
 
     Thread.sleep(500); // should wait for zk callback to add "/child0" into cache
@@ -279,7 +279,7 @@ public class TestZkHelixPropertyStore extends ZkUnitTestBase {
         .assertEquals(record.getId(), "child0-new-1", "Cache shoulde be updated to latest create");
     // System.out.println("2:get:" + record);
 
-    _gZkClient.delete(child0Path);
+    _zkclient.delete(child0Path);
     Thread.sleep(500); // should wait for zk callback to remove "/child0" from cache
     try {
       record = store.get("/child0", null, AccessOption.THROW_EXCEPTION_IFNOTEXIST);

http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/store/zk/TestZkManagerWithAutoFallbackStore.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/store/zk/TestZkManagerWithAutoFallbackStore.java b/helix-core/src/test/java/org/apache/helix/store/zk/TestZkManagerWithAutoFallbackStore.java
index f2f8b35..3e5e068 100644
--- a/helix-core/src/test/java/org/apache/helix/store/zk/TestZkManagerWithAutoFallbackStore.java
+++ b/helix-core/src/test/java/org/apache/helix/store/zk/TestZkManagerWithAutoFallbackStore.java
@@ -26,12 +26,12 @@ import org.apache.helix.AccessOption;
 import org.apache.helix.BaseDataAccessor;
 import org.apache.helix.TestHelper;
 import org.apache.helix.ZNRecord;
-import org.apache.helix.ZkUnitTestBase;
 import org.apache.helix.integration.manager.MockParticipantManager;
+import org.apache.helix.testutil.ZkTestBase;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
-public class TestZkManagerWithAutoFallbackStore extends ZkUnitTestBase {
+public class TestZkManagerWithAutoFallbackStore extends ZkTestBase {
   @Test
   public void testBasic() throws Exception {
     // Logger.getRootLogger().setLevel(Level.INFO);
@@ -42,7 +42,7 @@ public class TestZkManagerWithAutoFallbackStore extends ZkUnitTestBase {
 
     System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
 
-    TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
+    TestHelper.setupCluster(clusterName, _zkaddr, 12918, // participant port
         "localhost", // participant name prefix
         "TestDB", // resource name prefix
         1, // resources
@@ -56,7 +56,7 @@ public class TestZkManagerWithAutoFallbackStore extends ZkUnitTestBase {
     for (int i = 0; i < 1; i++) {
       String instanceName = "localhost_" + (12918 + i);
 
-      participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+      participants[i] = new MockParticipantManager(_zkaddr, clusterName, instanceName);
       participants[i].syncStart();
     }
 

http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/testutil/HelixTestUtil.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/testutil/HelixTestUtil.java b/helix-core/src/test/java/org/apache/helix/testutil/HelixTestUtil.java
new file mode 100644
index 0000000..32106e1
--- /dev/null
+++ b/helix-core/src/test/java/org/apache/helix/testutil/HelixTestUtil.java
@@ -0,0 +1,240 @@
+package org.apache.helix.testutil;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.helix.BaseDataAccessor;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.HelixProperty;
+import org.apache.helix.PropertyKey;
+import org.apache.helix.ZNRecord;
+import org.apache.helix.api.State;
+import org.apache.helix.api.id.MessageId;
+import org.apache.helix.api.id.StateModelDefId;
+import org.apache.helix.controller.pipeline.Pipeline;
+import org.apache.helix.controller.pipeline.Stage;
+import org.apache.helix.controller.pipeline.StageContext;
+import org.apache.helix.controller.stages.ClusterEvent;
+import org.apache.helix.manager.zk.ZKHelixDataAccessor;
+import org.apache.helix.manager.zk.ZkBaseDataAccessor;
+import org.apache.helix.manager.zk.ZkClient;
+import org.apache.helix.model.CurrentState;
+import org.apache.helix.model.ExternalView;
+import org.apache.helix.model.IdealState;
+import org.apache.helix.model.IdealState.RebalanceMode;
+import org.apache.helix.model.InstanceConfig;
+import org.apache.helix.model.LiveInstance;
+import org.apache.helix.model.Message;
+import org.apache.helix.model.Message.Attributes;
+import org.apache.helix.model.Message.MessageType;
+import org.apache.helix.model.StateModelDefinition;
+import org.apache.helix.tools.ClusterStateVerifier.ZkVerifier;
+import org.apache.helix.tools.StateModelConfigGenerator;
+import org.apache.log4j.Logger;
+
+public class HelixTestUtil {
+  private static Logger LOG = Logger.getLogger(HelixTestUtil.class);
+
+  /**
+   * Ensures that external view and current state are empty
+   */
+  public static class EmptyZkVerifier extends ZkVerifier {
+    private final String _resourceName;
+
+    /**
+     * Instantiate the verifier
+     * @param clusterName the cluster to verify
+     * @param resourceName the resource to verify
+     */
+    public EmptyZkVerifier(String clusterName, String resourceName, ZkClient zkclient) {
+      super(clusterName, zkclient);
+      _resourceName = resourceName;
+    }
+
+    @Override
+    public boolean verify() {
+      BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(getZkClient());
+      HelixDataAccessor accessor = new ZKHelixDataAccessor(getClusterName(), baseAccessor);
+      PropertyKey.Builder keyBuilder = accessor.keyBuilder();
+      ExternalView externalView = accessor.getProperty(keyBuilder.externalView(_resourceName));
+
+      // verify external view empty
+      if (externalView != null) {
+        for (String partition : externalView.getPartitionSet()) {
+          Map<String, String> stateMap = externalView.getStateMap(partition);
+          if (stateMap != null && !stateMap.isEmpty()) {
+            LOG.error("External view not empty for " + partition);
+            return false;
+          }
+        }
+      }
+
+      // verify current state empty
+      List<String> liveParticipants = accessor.getChildNames(keyBuilder.liveInstances());
+      for (String participant : liveParticipants) {
+        List<String> sessionIds = accessor.getChildNames(keyBuilder.sessions(participant));
+        for (String sessionId : sessionIds) {
+          CurrentState currentState =
+              accessor.getProperty(keyBuilder.currentState(participant, sessionId, _resourceName));
+          Map<String, String> partitionStateMap = currentState.getPartitionStateMap();
+          if (partitionStateMap != null && !partitionStateMap.isEmpty()) {
+            LOG.error("Current state not empty for " + participant);
+            return false;
+          }
+        }
+      }
+      return true;
+    }
+  }
+
+  /**
+   * Poll for the existence (or lack thereof) of a specific Helix property
+   * @param clazz the HelixProeprty subclass
+   * @param accessor connected HelixDataAccessor
+   * @param key the property key to look up
+   * @param shouldExist true if the property should exist, false otherwise
+   * @return the property if found, or null if it does not exist
+   */
+  public static <T extends HelixProperty> T pollForProperty(Class<T> clazz,
+      HelixDataAccessor accessor, PropertyKey key, boolean shouldExist) throws InterruptedException {
+    final int POLL_TIMEOUT = 5000;
+    final int POLL_INTERVAL = 50;
+    T property = accessor.getProperty(key);
+    int timeWaited = 0;
+    while (((shouldExist && property == null) || (!shouldExist && property != null))
+        && timeWaited < POLL_TIMEOUT) {
+      Thread.sleep(POLL_INTERVAL);
+      timeWaited += POLL_INTERVAL;
+      property = accessor.getProperty(key);
+    }
+    return property;
+  }
+
+  public static void setupStateModel(BaseDataAccessor<ZNRecord> baseAccessor, String clusterName) {
+    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor);
+    PropertyKey.Builder keyBuilder = accessor.keyBuilder();
+
+    StateModelDefinition masterSlave =
+        new StateModelDefinition(StateModelConfigGenerator.generateConfigForMasterSlave());
+    accessor.setProperty(keyBuilder.stateModelDef(masterSlave.getId()), masterSlave);
+
+    StateModelDefinition leaderStandby =
+        new StateModelDefinition(StateModelConfigGenerator.generateConfigForLeaderStandby());
+    accessor.setProperty(keyBuilder.stateModelDef(leaderStandby.getId()), leaderStandby);
+
+    StateModelDefinition onlineOffline =
+        new StateModelDefinition(StateModelConfigGenerator.generateConfigForOnlineOffline());
+    accessor.setProperty(keyBuilder.stateModelDef(onlineOffline.getId()), onlineOffline);
+  }
+
+  public static List<IdealState> setupIdealState(BaseDataAccessor<ZNRecord> baseAccessor,
+      String clusterName, int[] nodes, String[] resources, int partitions, int replicas) {
+    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor);
+    PropertyKey.Builder keyBuilder = accessor.keyBuilder();
+
+    List<IdealState> idealStates = new ArrayList<IdealState>();
+    List<String> instances = new ArrayList<String>();
+    for (int i : nodes) {
+      instances.add("localhost_" + i);
+    }
+
+    for (String resourceName : resources) {
+      IdealState idealState = new IdealState(resourceName);
+      for (int p = 0; p < partitions; p++) {
+        List<String> value = new ArrayList<String>();
+        for (int r = 0; r < replicas; r++) {
+          int n = nodes[(p + r) % nodes.length];
+          value.add("localhost_" + n);
+        }
+        idealState.getRecord().setListField(resourceName + "_" + p, value);
+      }
+
+      idealState.setReplicas(Integer.toString(replicas));
+      idealState.setStateModelDefId(StateModelDefId.from("MasterSlave"));
+      idealState.setRebalanceMode(RebalanceMode.SEMI_AUTO);
+      idealState.setNumPartitions(partitions);
+      idealStates.add(idealState);
+
+      // System.out.println(idealState);
+      accessor.setProperty(keyBuilder.idealStates(resourceName), idealState);
+    }
+    return idealStates;
+  }
+
+  public static void setupLiveInstances(BaseDataAccessor<ZNRecord> baseAccessor,
+      String clusterName, int[] liveInstances) {
+    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor);
+    PropertyKey.Builder keyBuilder = accessor.keyBuilder();
+
+    for (int i = 0; i < liveInstances.length; i++) {
+      String instance = "localhost_" + liveInstances[i];
+      LiveInstance liveInstance = new LiveInstance(instance);
+      liveInstance.setSessionId("session_" + liveInstances[i]);
+      liveInstance.setHelixVersion("0.4.0");
+      accessor.setProperty(keyBuilder.liveInstance(instance), liveInstance);
+    }
+  }
+
+  public static void setupInstances(BaseDataAccessor<ZNRecord> baseAccessor, String clusterName,
+      int[] instances) {
+    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor);
+    PropertyKey.Builder keyBuilder = accessor.keyBuilder();
+    for (int i = 0; i < instances.length; i++) {
+      String instance = "localhost_" + instances[i];
+      InstanceConfig instanceConfig = new InstanceConfig(instance);
+      instanceConfig.setHostName("localhost");
+      instanceConfig.setPort("" + instances[i]);
+      instanceConfig.setInstanceEnabled(true);
+      accessor.setProperty(keyBuilder.instanceConfig(instance), instanceConfig);
+    }
+  }
+
+  public static void runPipeline(ClusterEvent event, Pipeline pipeline) {
+    try {
+      pipeline.handle(event);
+      pipeline.finish();
+    } catch (Exception e) {
+      LOG.error("Exception while executing pipeline:" + pipeline
+          + ". Will not continue to next pipeline", e);
+    }
+  }
+
+
+  public static void runStage(ClusterEvent event, Stage stage) throws Exception {
+    StageContext context = new StageContext();
+    stage.init(context);
+    stage.preProcess();
+    stage.process(event);
+    stage.postProcess();
+  }
+
+  public static Message newMessage(MessageType type, MessageId msgId, String fromState,
+      String toState, String resourceName, String tgtName) {
+    Message msg = new Message(type.toString(), msgId);
+    msg.setFromState(State.from(fromState));
+    msg.setToState(State.from(toState));
+    msg.getRecord().setSimpleField(Attributes.RESOURCE_NAME.toString(), resourceName);
+    msg.setTgtName(tgtName);
+    return msg;
+  }
+}

http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/testutil/TestUtil.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/testutil/TestUtil.java b/helix-core/src/test/java/org/apache/helix/testutil/TestUtil.java
new file mode 100644
index 0000000..bc62fca
--- /dev/null
+++ b/helix-core/src/test/java/org/apache/helix/testutil/TestUtil.java
@@ -0,0 +1,79 @@
+package org.apache.helix.testutil;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+
+import org.apache.log4j.Logger;
+
+public class TestUtil {
+  static Logger logger = Logger.getLogger(TestUtil.class);
+
+  public static boolean isTestNGAnnotated(Class clazz, String methodName) {
+    final String annotationsPkgName = "org.testng.annotations";
+
+    // Check if the class itself is annotated.
+    Annotation[] classAnnotations = clazz.getAnnotations();
+    for (Annotation a : classAnnotations) {
+      if (a.annotationType().getPackage().getName().equals(annotationsPkgName)) {
+        return true;
+      }
+    }
+
+    // Check if given method is annotated.
+    Method[] methods = clazz.getMethods();
+    for (Method m : methods) {
+      if (!m.getName().equals(methodName)) {
+        continue;
+      }
+      Annotation[] methodAnnotations = m.getAnnotations();
+      for (Annotation a : methodAnnotations) {
+        if (a.annotationType().getPackage().getName().equals(annotationsPkgName)) {
+          return true;
+        }
+      }
+    }
+
+    return false;
+  }
+
+  public static String getTestName() {
+    try {
+      StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
+
+      // The first 2 elements in the stack are getStackTrace and this method itself, so ignore them.
+      for (int i = 2; i < stackTrace.length; i++) {
+        Class clazz = Class.forName(stackTrace[i].getClassName());
+        if (isTestNGAnnotated(clazz, stackTrace[i].getMethodName())) {
+          String testName = String.format("%s_%s", clazz.getSimpleName(), stackTrace[i].getMethodName());
+          logger.debug("Detected " + testName + " as the test name");
+          return testName;
+        }
+      }
+    }
+    catch (ClassNotFoundException e) {
+      throw new RuntimeException("Error while trying to guess test name.", e);
+    }
+
+    // No TestNG annotated classes in the stack trace.
+    throw new RuntimeException("Unable to guess test name. No TestNG annotated classes or methods in stack trace.");
+  }
+}

http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/testutil/ZkTestBase.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/testutil/ZkTestBase.java b/helix-core/src/test/java/org/apache/helix/testutil/ZkTestBase.java
new file mode 100644
index 0000000..a4caff6
--- /dev/null
+++ b/helix-core/src/test/java/org/apache/helix/testutil/ZkTestBase.java
@@ -0,0 +1,80 @@
+package org.apache.helix.testutil;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.I0Itec.zkclient.ZkServer;
+import org.apache.helix.BaseDataAccessor;
+import org.apache.helix.ZNRecord;
+import org.apache.helix.manager.zk.ZNRecordSerializer;
+import org.apache.helix.manager.zk.ZkBaseDataAccessor;
+import org.apache.helix.manager.zk.ZkClient;
+import org.apache.helix.tools.ClusterSetup;
+import org.apache.helix.util.ZKClientPool;
+import org.apache.log4j.Logger;
+import org.testng.annotations.AfterSuite;
+import org.testng.annotations.BeforeSuite;
+
+public class ZkTestBase {
+  static Logger logger = Logger.getLogger(ZkTestBase.class);
+  static ZkServer zkserver;
+
+  // Used by tests
+  protected static ZkClient _zkclient;
+  protected static String _zkaddr;
+  protected static BaseDataAccessor<ZNRecord> _baseAccessor;
+  protected static ClusterSetup _setupTool;
+
+  public static synchronized void startZkServerIfNot() {
+    if (zkserver == null) {
+      zkserver = ZkTestUtil.startZkServer();
+      _zkaddr = "localhost:" + zkserver.getPort();
+      _zkclient =
+          new ZkClient(_zkaddr, ZkClient.DEFAULT_SESSION_TIMEOUT,
+              ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer());
+
+      _baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
+      _setupTool = new ClusterSetup(_zkclient);
+
+      ZKClientPool.reset();
+    }
+  }
+
+  public static synchronized void stopZkServer() {
+    if (zkserver != null) {
+      _baseAccessor = null;
+      _zkclient.close();
+      _zkclient = null;
+      _setupTool = null;
+      _zkaddr = null;
+      zkserver.shutdown();
+      zkserver = null;
+    }
+  }
+
+  @BeforeSuite
+  public void beforeSuite() {
+    startZkServerIfNot();
+  }
+
+  @AfterSuite
+  public void afterSuite() {
+    stopZkServer();
+  }
+}

http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/testutil/ZkTestUtil.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/testutil/ZkTestUtil.java b/helix-core/src/test/java/org/apache/helix/testutil/ZkTestUtil.java
new file mode 100644
index 0000000..019aa9b
--- /dev/null
+++ b/helix-core/src/test/java/org/apache/helix/testutil/ZkTestUtil.java
@@ -0,0 +1,99 @@
+package org.apache.helix.testutil;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.net.ServerSocket;
+
+import org.I0Itec.zkclient.IDefaultNameSpace;
+import org.I0Itec.zkclient.NetworkUtil;
+import org.I0Itec.zkclient.ZkServer;
+import org.apache.log4j.Logger;
+
+import com.google.common.io.Files;
+
+public class ZkTestUtil {
+  static Logger logger = Logger.getLogger(ZkTestUtil.class);
+  static final int MAX_PORT = 65535;
+  static final int DEFAULT_ZK_START_PORT = 2183;
+
+  public static int availableTcpPort() {
+    ServerSocket ss = null;
+    try {
+      ss = new ServerSocket(0);
+      ss.setReuseAddress(true);
+      return ss.getLocalPort();
+    } catch (IOException e) {
+
+    } finally {
+      if (ss != null) {
+        try {
+          ss.close();
+        } catch (IOException e) {
+          // should not be thrown
+        }
+      }
+    }
+    return -1;
+  }
+
+  public static int availableTcpPort(int startPort) {
+    int port = startPort;
+    for (; port <= MAX_PORT; port++) {
+      if (NetworkUtil.isPortFree(port))
+        break;
+    }
+
+    return port > MAX_PORT ? -1 : port;
+  }
+
+  public static File createAutoDeleteTempDir() {
+    File tempdir = Files.createTempDir();
+    tempdir.delete();
+    tempdir.mkdir();
+    logger.info("Create temp dir: " + tempdir.getAbsolutePath());
+    tempdir.deleteOnExit();
+    return tempdir;
+  }
+
+  public static ZkServer startZkServer() {
+    File tmpdir = createAutoDeleteTempDir();
+    File logdir = new File(tmpdir + File.separator + "translog");
+    File datadir = new File(tmpdir + File.separator + "snapshot");
+
+    IDefaultNameSpace defaultNameSpace = new IDefaultNameSpace() {
+      @Override
+      public void createDefaultNameSpace(org.I0Itec.zkclient.ZkClient zkClient) {
+        // init any zk paths if needed
+      }
+    };
+    int port = availableTcpPort(DEFAULT_ZK_START_PORT);
+    ZkServer zkServer =
+        new ZkServer(datadir.getAbsolutePath(), logdir.getAbsolutePath(), defaultNameSpace, port);
+    zkServer.start();
+
+    logger.info("Start zookeeper at localhost:" + zkServer.getPort() + " in thread "
+        + Thread.currentThread().getName());
+
+    return zkServer;
+  }
+
+}


Mime
View raw message