Return-Path: X-Original-To: apmail-helix-commits-archive@minotaur.apache.org Delivered-To: apmail-helix-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A8F77110C2 for ; Tue, 22 Jul 2014 18:40:19 +0000 (UTC) Received: (qmail 72375 invoked by uid 500); 22 Jul 2014 18:40:19 -0000 Delivered-To: apmail-helix-commits-archive@helix.apache.org Received: (qmail 72322 invoked by uid 500); 22 Jul 2014 18:40:19 -0000 Mailing-List: contact commits-help@helix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@helix.apache.org Delivered-To: mailing list commits@helix.apache.org Received: (qmail 72310 invoked by uid 99); 22 Jul 2014 18:40:19 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Jul 2014 18:40:19 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 4CF209AFC84; Tue, 22 Jul 2014 18:40:19 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: zzhang@apache.org To: commits@helix.apache.org Date: Tue, 22 Jul 2014 18:40:19 -0000 Message-Id: <938cd599d37a4f349c93636663577cde@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/9] [HELIX-475] Remove code duplication for Zk tests Repository: helix Updated Branches: refs/heads/master 3534e6452 -> 410815d0f http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/tools/TestClusterSetup.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/tools/TestClusterSetup.java b/helix-core/src/test/java/org/apache/helix/tools/TestClusterSetup.java index a528a20..2f8e655 100644 --- a/helix-core/src/test/java/org/apache/helix/tools/TestClusterSetup.java +++ b/helix-core/src/test/java/org/apache/helix/tools/TestClusterSetup.java @@ -23,7 +23,6 @@ import java.io.IOException; import java.util.Arrays; import java.util.Date; -import org.apache.helix.BaseDataAccessor; import org.apache.helix.HelixDataAccessor; import org.apache.helix.HelixException; import org.apache.helix.PropertyKey; @@ -32,7 +31,7 @@ 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.api.id.PartitionId; import org.apache.helix.manager.zk.ZKHelixAdmin; import org.apache.helix.manager.zk.ZKHelixDataAccessor; import org.apache.helix.manager.zk.ZNRecordSerializer; @@ -40,7 +39,11 @@ import org.apache.helix.manager.zk.ZkBaseDataAccessor; import org.apache.helix.manager.zk.ZkClient; import org.apache.helix.model.HelixConfigScope.ConfigScopeProperty; 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.testutil.ZkTestBase; +import org.apache.helix.util.HelixUtil; import org.testng.Assert; import org.testng.AssertJUnit; import org.testng.annotations.AfterClass; @@ -48,16 +51,13 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -public class TestClusterSetup extends ZkUnitTestBase { +public class TestClusterSetup extends ZkTestBase { protected static final String CLUSTER_NAME = "TestClusterSetup"; protected static final String TEST_DB = "TestDB"; protected static final String INSTANCE_PREFIX = "instance_"; protected static final String STATE_MODEL = "MasterSlave"; protected static final String TEST_NODE = "testnode_1"; - ZkClient _zkClient; - ClusterSetup _clusterSetup; - private static String[] createArgs(String str) { String[] split = str.split("[ ]+"); System.out.println(Arrays.toString(split)); @@ -68,23 +68,61 @@ public class TestClusterSetup extends ZkUnitTestBase { public void beforeClass() throws IOException, Exception { System.out.println("START TestClusterSetup.beforeClass() " + new Date(System.currentTimeMillis())); - - _zkClient = new ZkClient(ZK_ADDR); - _zkClient.setZkSerializer(new ZNRecordSerializer()); } @AfterClass() public void afterClass() { - _zkClient.close(); System.out.println("END TestClusterSetup.afterClass() " + new Date(System.currentTimeMillis())); } @BeforeMethod() public void setup() { - _zkClient.deleteRecursive("/" + CLUSTER_NAME); - _clusterSetup = new ClusterSetup(ZK_ADDR); - _clusterSetup.addCluster(CLUSTER_NAME, true); + _zkclient.deleteRecursive("/" + CLUSTER_NAME); + _setupTool.addCluster(CLUSTER_NAME, true); + } + + private void verifyEnabled(ZkClient zkClient, String clusterName, String instance, + boolean wantEnabled) { + ZKHelixDataAccessor accessor = + new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(zkClient)); + Builder keyBuilder = accessor.keyBuilder(); + + InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instance)); + AssertJUnit.assertEquals(wantEnabled, config.getInstanceEnabled()); + } + + private void verifyInstance(ZkClient zkClient, String clusterName, String instance, + boolean wantExists) { + // String instanceConfigsPath = HelixUtil.getConfigPath(clusterName); + String instanceConfigsPath = + PropertyPathConfig.getPath(PropertyType.CONFIGS, clusterName, + ConfigScopeProperty.PARTICIPANT.toString()); + String instanceConfigPath = instanceConfigsPath + "/" + instance; + String instancePath = HelixUtil.getInstancePath(clusterName, instance); + AssertJUnit.assertEquals(wantExists, zkClient.exists(instanceConfigPath)); + AssertJUnit.assertEquals(wantExists, zkClient.exists(instancePath)); + } + + private void verifyResource(ZkClient zkClient, String clusterName, String resource, + boolean wantExists) { + String resourcePath = HelixUtil.getIdealStatePath(clusterName) + "/" + resource; + AssertJUnit.assertEquals(wantExists, zkClient.exists(resourcePath)); + } + + private void verifyReplication(ZkClient zkClient, String clusterName, String resource, int repl) { + ZKHelixDataAccessor accessor = + new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(zkClient)); + Builder keyBuilder = accessor.keyBuilder(); + + IdealState idealState = accessor.getProperty(keyBuilder.idealStates(resource)); + for (PartitionId partitionId : idealState.getPartitionIdSet()) { + if (idealState.getRebalanceMode() == RebalanceMode.SEMI_AUTO) { + AssertJUnit.assertEquals(repl, idealState.getPreferenceList(partitionId).size()); + } else if (idealState.getRebalanceMode() == RebalanceMode.CUSTOMIZED) { + AssertJUnit.assertEquals(repl, idealState.getParticipantStateMap(partitionId).size()); + } + } } @Test @@ -117,19 +155,19 @@ public class TestClusterSetup extends ZkUnitTestBase { } String nextInstanceAddress = INSTANCE_PREFIX + 3; - _clusterSetup.addInstancesToCluster(CLUSTER_NAME, instanceAddresses); + _setupTool.addInstancesToCluster(CLUSTER_NAME, instanceAddresses); // verify instances for (String instance : instanceAddresses) { - verifyInstance(_zkClient, CLUSTER_NAME, instance, true); + verifyInstance(_zkclient, CLUSTER_NAME, instance, true); } - _clusterSetup.addInstanceToCluster(CLUSTER_NAME, nextInstanceAddress); - verifyInstance(_zkClient, CLUSTER_NAME, nextInstanceAddress, true); + _setupTool.addInstanceToCluster(CLUSTER_NAME, nextInstanceAddress); + verifyInstance(_zkclient, CLUSTER_NAME, nextInstanceAddress, true); // re-add boolean caughtException = false; try { - _clusterSetup.addInstanceToCluster(CLUSTER_NAME, nextInstanceAddress); + _setupTool.addInstanceToCluster(CLUSTER_NAME, nextInstanceAddress); } catch (HelixException e) { caughtException = true; } @@ -149,32 +187,32 @@ public class TestClusterSetup extends ZkUnitTestBase { boolean caughtException = false; // drop without disabling try { - _clusterSetup.dropInstanceFromCluster(CLUSTER_NAME, nextInstanceAddress); + _setupTool.dropInstanceFromCluster(CLUSTER_NAME, nextInstanceAddress); } catch (HelixException e) { caughtException = true; } AssertJUnit.assertTrue(caughtException); // disable - _clusterSetup.getClusterManagementTool().enableInstance(CLUSTER_NAME, nextInstanceAddress, + _setupTool.getClusterManagementTool().enableInstance(CLUSTER_NAME, nextInstanceAddress, false); - verifyEnabled(_zkClient, CLUSTER_NAME, nextInstanceAddress, false); + verifyEnabled(_zkclient, CLUSTER_NAME, nextInstanceAddress, false); // drop - _clusterSetup.dropInstanceFromCluster(CLUSTER_NAME, nextInstanceAddress); - verifyInstance(_zkClient, CLUSTER_NAME, nextInstanceAddress, false); + _setupTool.dropInstanceFromCluster(CLUSTER_NAME, nextInstanceAddress); + verifyInstance(_zkclient, CLUSTER_NAME, nextInstanceAddress, false); // re-drop caughtException = false; try { - _clusterSetup.dropInstanceFromCluster(CLUSTER_NAME, nextInstanceAddress); + _setupTool.dropInstanceFromCluster(CLUSTER_NAME, nextInstanceAddress); } catch (HelixException e) { caughtException = true; } AssertJUnit.assertTrue(caughtException); /* - * //drop a set _clusterSetup.getClusterManagementTool().enableInstances(CLUSTER_NAME, - * instanceAddresses, false); _clusterSetup.dropInstancesFromCluster(CLUSTER_NAME, + * //drop a set setupTool.getClusterManagementTool().enableInstances(CLUSTER_NAME, + * instanceAddresses, false); setupTool.dropInstancesFromCluster(CLUSTER_NAME, * instanceAddresses); */ @@ -182,7 +220,7 @@ public class TestClusterSetup extends ZkUnitTestBase { String badFormatInstance = "badinstance"; caughtException = false; try { - _clusterSetup.getClusterManagementTool().enableInstance(CLUSTER_NAME, badFormatInstance, + _setupTool.getClusterManagementTool().enableInstance(CLUSTER_NAME, badFormatInstance, false); } catch (HelixException e) { caughtException = true; @@ -191,7 +229,7 @@ public class TestClusterSetup extends ZkUnitTestBase { caughtException = false; try { - _clusterSetup.dropInstanceFromCluster(CLUSTER_NAME, badFormatInstance); + _setupTool.dropInstanceFromCluster(CLUSTER_NAME, badFormatInstance); } catch (HelixException e) { caughtException = true; } @@ -201,27 +239,27 @@ public class TestClusterSetup extends ZkUnitTestBase { @Test() public void testAddResource() throws Exception { try { - _clusterSetup.addResourceToCluster(CLUSTER_NAME, TEST_DB, 16, STATE_MODEL); + _setupTool.addResourceToCluster(CLUSTER_NAME, TEST_DB, 16, STATE_MODEL); } catch (Exception e) { } - verifyResource(_zkClient, CLUSTER_NAME, TEST_DB, true); + verifyResource(_zkclient, CLUSTER_NAME, TEST_DB, true); } @Test() public void testRemoveResource() throws Exception { - _clusterSetup.setupTestCluster(CLUSTER_NAME); - verifyResource(_zkClient, CLUSTER_NAME, TEST_DB, true); - _clusterSetup.dropResourceFromCluster(CLUSTER_NAME, TEST_DB); - verifyResource(_zkClient, CLUSTER_NAME, TEST_DB, false); + _setupTool.setupTestCluster(CLUSTER_NAME); + verifyResource(_zkclient, CLUSTER_NAME, TEST_DB, true); + _setupTool.dropResourceFromCluster(CLUSTER_NAME, TEST_DB); + verifyResource(_zkclient, CLUSTER_NAME, TEST_DB, false); } @Test() public void testRebalanceCluster() throws Exception { - _clusterSetup.setupTestCluster(CLUSTER_NAME); + _setupTool.setupTestCluster(CLUSTER_NAME); // testAddInstancesToCluster(); testAddResource(); - _clusterSetup.rebalanceStorageCluster(CLUSTER_NAME, TEST_DB, 4); - verifyReplication(_zkClient, CLUSTER_NAME, TEST_DB, 4); + _setupTool.rebalanceStorageCluster(CLUSTER_NAME, TEST_DB, 4); + verifyReplication(_zkclient, CLUSTER_NAME, TEST_DB, 4); } /* @@ -233,64 +271,62 @@ public class TestClusterSetup extends ZkUnitTestBase { @Test() public void testParseCommandLinesArgs() throws Exception { // ClusterSetup - // .processCommandLineArgs(createArgs("-zkSvr "+ZK_ADDR+ " help")); + // .processCommandLineArgs(createArgs("-zkSvr "+zkaddr+ " help")); // wipe ZK - _zkClient.deleteRecursive("/" + CLUSTER_NAME); - _clusterSetup = new ClusterSetup(ZK_ADDR); + _zkclient.deleteRecursive("/" + CLUSTER_NAME); - ClusterSetup.processCommandLineArgs(createArgs("-zkSvr " + ZK_ADDR + " --addCluster " + ClusterSetup.processCommandLineArgs(createArgs("-zkSvr " + _zkaddr + " --addCluster " + CLUSTER_NAME)); // wipe again - _zkClient.deleteRecursive("/" + CLUSTER_NAME); - _clusterSetup = new ClusterSetup(ZK_ADDR); + _zkclient.deleteRecursive("/" + CLUSTER_NAME); - _clusterSetup.setupTestCluster(CLUSTER_NAME); + _setupTool.setupTestCluster(CLUSTER_NAME); - ClusterSetup.processCommandLineArgs(createArgs("-zkSvr " + ZK_ADDR + " --addNode " + ClusterSetup.processCommandLineArgs(createArgs("-zkSvr " + _zkaddr + " --addNode " + CLUSTER_NAME + " " + TEST_NODE)); - verifyInstance(_zkClient, CLUSTER_NAME, TEST_NODE, true); + verifyInstance(_zkclient, CLUSTER_NAME, TEST_NODE, true); try { - ClusterSetup.processCommandLineArgs(createArgs("-zkSvr " + ZK_ADDR + " --addResource " + ClusterSetup.processCommandLineArgs(createArgs("-zkSvr " + _zkaddr + " --addResource " + CLUSTER_NAME + " " + TEST_DB + " 4 " + STATE_MODEL)); } catch (Exception e) { } - verifyResource(_zkClient, CLUSTER_NAME, TEST_DB, true); + verifyResource(_zkclient, CLUSTER_NAME, TEST_DB, true); // ClusterSetup - // .processCommandLineArgs(createArgs("-zkSvr "+ZK_ADDR+" --addNode node-1")); - ClusterSetup.processCommandLineArgs(createArgs("-zkSvr " + ZK_ADDR + " --enableInstance " + // .processCommandLineArgs(createArgs("-zkSvr "+zkaddr+" --addNode node-1")); + ClusterSetup.processCommandLineArgs(createArgs("-zkSvr " + _zkaddr + " --enableInstance " + CLUSTER_NAME + " " + TEST_NODE + " true")); - verifyEnabled(_zkClient, CLUSTER_NAME, TEST_NODE, true); + verifyEnabled(_zkclient, CLUSTER_NAME, TEST_NODE, true); // TODO: verify list commands /* * ClusterSetup - * .processCommandLineArgs(createArgs("-zkSvr "+ZK_ADDR+" --listClusterInfo " + * .processCommandLineArgs(createArgs("-zkSvr "+zkaddr+" --listClusterInfo " * +CLUSTER_NAME)); ClusterSetup - * .processCommandLineArgs(createArgs("-zkSvr "+ZK_ADDR+" --listClusters")); + * .processCommandLineArgs(createArgs("-zkSvr "+zkaddr+" --listClusters")); * ClusterSetup - * .processCommandLineArgs(createArgs("-zkSvr "+ZK_ADDR+" --listInstanceInfo " + * .processCommandLineArgs(createArgs("-zkSvr "+zkaddr+" --listInstanceInfo " * +CLUSTER_NAME+" "+instanceColonToUnderscoreFormat(TEST_NODE))); ClusterSetup * .processCommandLineArgs - * (createArgs("-zkSvr "+ZK_ADDR+" --listInstances "+CLUSTER_NAME)); ClusterSetup + * (createArgs("-zkSvr "+zkaddr+" --listInstances "+CLUSTER_NAME)); ClusterSetup * .processCommandLineArgs - * (createArgs("-zkSvr "+ZK_ADDR+" --listResourceInfo "+CLUSTER_NAME +" "+TEST_DB)); + * (createArgs("-zkSvr "+zkaddr+" --listResourceInfo "+CLUSTER_NAME +" "+TEST_DB)); * ClusterSetup - * .processCommandLineArgs(createArgs("-zkSvr "+ZK_ADDR+" --listResources " + * .processCommandLineArgs(createArgs("-zkSvr "+zkaddr+" --listResources " * +CLUSTER_NAME)); ClusterSetup - * .processCommandLineArgs(createArgs("-zkSvr "+ZK_ADDR+" --listStateModel " + * .processCommandLineArgs(createArgs("-zkSvr "+zkaddr+" --listStateModel " * +CLUSTER_NAME+" "+STATE_MODEL)); ClusterSetup * .processCommandLineArgs(createArgs("-zkSvr " - * +ZK_ADDR+" --listStateModels "+CLUSTER_NAME)); + * +zkaddr+" --listStateModels "+CLUSTER_NAME)); */ // ClusterSetup - // .processCommandLineArgs(createArgs("-zkSvr "+ZK_ADDR+" --rebalance "+CLUSTER_NAME+" "+TEST_DB+" 1")); - ClusterSetup.processCommandLineArgs(createArgs("-zkSvr " + ZK_ADDR + " --enableInstance " + // .processCommandLineArgs(createArgs("-zkSvr "+zkaddr+" --rebalance "+CLUSTER_NAME+" "+TEST_DB+" 1")); + ClusterSetup.processCommandLineArgs(createArgs("-zkSvr " + _zkaddr + " --enableInstance " + CLUSTER_NAME + " " + TEST_NODE + " false")); - verifyEnabled(_zkClient, CLUSTER_NAME, TEST_NODE, false); - ClusterSetup.processCommandLineArgs(createArgs("-zkSvr " + ZK_ADDR + " --dropNode " + verifyEnabled(_zkclient, CLUSTER_NAME, TEST_NODE, false); + ClusterSetup.processCommandLineArgs(createArgs("-zkSvr " + _zkaddr + " --dropNode " + CLUSTER_NAME + " " + TEST_NODE)); } @@ -302,30 +338,30 @@ public class TestClusterSetup extends ZkUnitTestBase { System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis())); - _clusterSetup.addCluster(clusterName, true); - _clusterSetup.addInstanceToCluster(clusterName, "localhost_0"); + _setupTool.addCluster(clusterName, true); + _setupTool.addInstanceToCluster(clusterName, "localhost_0"); // test set/get/remove instance configs String scopeArgs = clusterName + ",localhost_0"; String keyValueMap = "key1=value1,key2=value2"; String keys = "key1,key2"; ClusterSetup.processCommandLineArgs(new String[] { - "--zkSvr", ZK_ADDR, "--setConfig", ConfigScopeProperty.PARTICIPANT.toString(), scopeArgs, + "--zkSvr", _zkaddr, "--setConfig", ConfigScopeProperty.PARTICIPANT.toString(), scopeArgs, keyValueMap }); // getConfig returns json-formatted key-value pairs - String valuesStr = _clusterSetup.getConfig(ConfigScopeProperty.PARTICIPANT, scopeArgs, keys); + String valuesStr = _setupTool.getConfig(ConfigScopeProperty.PARTICIPANT, scopeArgs, keys); ZNRecordSerializer serializer = new ZNRecordSerializer(); ZNRecord record = (ZNRecord) serializer.deserialize(valuesStr.getBytes()); Assert.assertEquals(record.getSimpleField("key1"), "value1"); Assert.assertEquals(record.getSimpleField("key2"), "value2"); ClusterSetup.processCommandLineArgs(new String[] { - "--zkSvr", ZK_ADDR, "--removeConfig", ConfigScopeProperty.PARTICIPANT.toString(), + "--zkSvr", _zkaddr, "--removeConfig", ConfigScopeProperty.PARTICIPANT.toString(), scopeArgs, keys }); - valuesStr = _clusterSetup.getConfig(ConfigScopeProperty.PARTICIPANT, scopeArgs, keys); + valuesStr = _setupTool.getConfig(ConfigScopeProperty.PARTICIPANT, scopeArgs, keys); record = (ZNRecord) serializer.deserialize(valuesStr.getBytes()); Assert.assertNull(record.getSimpleField("key1")); Assert.assertNull(record.getSimpleField("key2")); @@ -342,7 +378,7 @@ public class TestClusterSetup 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 @@ -353,19 +389,19 @@ public class TestClusterSetup extends ZkUnitTestBase { // pause cluster ClusterSetup.processCommandLineArgs(new String[] { - "--zkSvr", ZK_ADDR, "--enableCluster", clusterName, "false" + "--zkSvr", _zkaddr, "--enableCluster", clusterName, "false" }); Builder keyBuilder = new Builder(clusterName); - boolean exists = _gZkClient.exists(keyBuilder.pause().getPath()); + boolean exists = _zkclient.exists(keyBuilder.pause().getPath()); Assert.assertTrue(exists, "pause node under controller should be created"); // resume cluster ClusterSetup.processCommandLineArgs(new String[] { - "--zkSvr", ZK_ADDR, "--enableCluster", clusterName, "true" + "--zkSvr", _zkaddr, "--enableCluster", clusterName, "true" }); - exists = _gZkClient.exists(keyBuilder.pause().getPath()); + exists = _zkclient.exists(keyBuilder.pause().getPath()); Assert.assertFalse(exists, "pause node under controller should be removed"); System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis())); @@ -381,7 +417,7 @@ public class TestClusterSetup 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 @@ -392,7 +428,7 @@ public class TestClusterSetup extends ZkUnitTestBase { // add fake liveInstance ZKHelixDataAccessor accessor = - new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_gZkClient)); + new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_zkclient)); Builder keyBuilder = new Builder(clusterName); LiveInstance liveInstance = new LiveInstance("localhost_12918"); liveInstance.setSessionId("session_0"); @@ -402,7 +438,7 @@ public class TestClusterSetup extends ZkUnitTestBase { // drop without stop the process, should throw exception try { ClusterSetup.processCommandLineArgs(new String[] { - "--zkSvr", ZK_ADDR, "--dropNode", clusterName, "localhost:12918" + "--zkSvr", _zkaddr, "--dropNode", clusterName, "localhost:12918" }); Assert.fail("Should throw exception since localhost_12918 is still in LIVEINSTANCES/"); } catch (Exception e) { @@ -413,7 +449,7 @@ public class TestClusterSetup extends ZkUnitTestBase { // drop without disable, should throw exception try { ClusterSetup.processCommandLineArgs(new String[] { - "--zkSvr", ZK_ADDR, "--dropNode", clusterName, "localhost:12918" + "--zkSvr", _zkaddr, "--dropNode", clusterName, "localhost:12918" }); Assert.fail("Should throw exception since localhost_12918 is enabled"); } catch (Exception e) { @@ -423,15 +459,15 @@ public class TestClusterSetup extends ZkUnitTestBase { // drop it ClusterSetup.processCommandLineArgs(new String[] { - "--zkSvr", ZK_ADDR, "--enableInstance", clusterName, "localhost_12918", "false" + "--zkSvr", _zkaddr, "--enableInstance", clusterName, "localhost_12918", "false" }); ClusterSetup.processCommandLineArgs(new String[] { - "--zkSvr", ZK_ADDR, "--dropNode", clusterName, "localhost:12918" + "--zkSvr", _zkaddr, "--dropNode", clusterName, "localhost:12918" }); Assert.assertNull(accessor.getProperty(keyBuilder.instanceConfig("localhost_12918")), "Instance config should be dropped"); - Assert.assertFalse(_gZkClient.exists(PropertyPathConfig.getPath(PropertyType.INSTANCES, + Assert.assertFalse(_zkclient.exists(PropertyPathConfig.getPath(PropertyType.INSTANCES, clusterName, "localhost_12918")), "Instance/host should be dropped"); System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis())); @@ -444,7 +480,7 @@ public class TestClusterSetup extends ZkUnitTestBase { String methodName = TestHelper.getTestMethodName(); String clusterName = className + "_" + methodName; 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 @@ -454,16 +490,15 @@ public class TestClusterSetup extends ZkUnitTestBase { "MasterSlave", true); // do rebalance // disable "TestDB0" resource ClusterSetup.processCommandLineArgs(new String[] { - "--zkSvr", ZK_ADDR, "--enableResource", clusterName, "TestDB0", "false" + "--zkSvr", _zkaddr, "--enableResource", clusterName, "TestDB0", "false" }); - BaseDataAccessor baseAccessor = new ZkBaseDataAccessor(_gZkClient); - HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor); + HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, _baseAccessor); PropertyKey.Builder keyBuilder = accessor.keyBuilder(); IdealState idealState = accessor.getProperty(keyBuilder.idealStates("TestDB0")); Assert.assertFalse(idealState.isEnabled()); // enable "TestDB0" resource ClusterSetup.processCommandLineArgs(new String[] { - "--zkSvr", ZK_ADDR, "--enableResource", clusterName, "TestDB0", "true" + "--zkSvr", _zkaddr, "--enableResource", clusterName, "TestDB0", "true" }); idealState = accessor.getProperty(keyBuilder.idealStates("TestDB0")); Assert.assertTrue(idealState.isEnabled()); http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/tools/TestClusterStateVerifier.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/tools/TestClusterStateVerifier.java b/helix-core/src/test/java/org/apache/helix/tools/TestClusterStateVerifier.java index abd1dd8..ec43664 100644 --- a/helix-core/src/test/java/org/apache/helix/tools/TestClusterStateVerifier.java +++ b/helix-core/src/test/java/org/apache/helix/tools/TestClusterStateVerifier.java @@ -23,11 +23,11 @@ import java.util.Arrays; import org.apache.helix.HelixAdmin; 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; import org.apache.helix.model.IdealState.RebalanceMode; +import org.apache.helix.testutil.ZkTestBase; import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier; import org.testng.Assert; import org.testng.annotations.AfterMethod; @@ -36,7 +36,7 @@ import org.testng.annotations.Test; import com.google.common.collect.Sets; -public class TestClusterStateVerifier extends ZkUnitTestBase { +public class TestClusterStateVerifier extends ZkTestBase { final String[] RESOURCES = { "resource0", "resource1" }; @@ -54,12 +54,11 @@ public class TestClusterStateVerifier extends ZkUnitTestBase { String className = TestHelper.getTestClassName(); String methodName = TestHelper.getTestMethodName(); _clusterName = className + "_" + methodName; - ClusterSetup setupTool = new ClusterSetup(ZK_ADDR); - _admin = setupTool.getClusterManagementTool(); - setupTool.addCluster(_clusterName, true); - setupTool.addResourceToCluster(_clusterName, RESOURCES[0], NUM_PARTITIONS, "OnlineOffline", + _admin = _setupTool.getClusterManagementTool(); + _setupTool.addCluster(_clusterName, true); + _setupTool.addResourceToCluster(_clusterName, RESOURCES[0], NUM_PARTITIONS, "OnlineOffline", RebalanceMode.SEMI_AUTO.toString()); - setupTool.addResourceToCluster(_clusterName, RESOURCES[1], NUM_PARTITIONS, "OnlineOffline", + _setupTool.addResourceToCluster(_clusterName, RESOURCES[1], NUM_PARTITIONS, "OnlineOffline", RebalanceMode.SEMI_AUTO.toString()); // Configure and start the participants @@ -68,8 +67,8 @@ public class TestClusterStateVerifier extends ZkUnitTestBase { String host = "localhost"; int port = 12918 + i; String id = host + '_' + port; - setupTool.addInstanceToCluster(_clusterName, id); - _participants[i] = new MockParticipantManager(ZK_ADDR, _clusterName, id); + _setupTool.addInstanceToCluster(_clusterName, id); + _participants[i] = new MockParticipantManager(_zkaddr, _clusterName, id); _participants[i].syncStart(); } @@ -83,7 +82,7 @@ public class TestClusterStateVerifier extends ZkUnitTestBase { } // Start the controller - _controller = new ClusterControllerManager(ZK_ADDR, _clusterName, "controller_0"); + _controller = new ClusterControllerManager(_zkaddr, _clusterName, "controller_0"); _controller.syncStart(); Thread.sleep(1000); } @@ -103,7 +102,7 @@ public class TestClusterStateVerifier extends ZkUnitTestBase { // Just ensure that the entire cluster passes // ensure that the external view coalesces boolean result = - ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, + ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(_zkaddr, _clusterName)); Assert.assertTrue(result); } @@ -118,17 +117,17 @@ public class TestClusterStateVerifier extends ZkUnitTestBase { _admin.enableInstance(_clusterName, "localhost_12918", true); Thread.sleep(1000); boolean result = - ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, + ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(_zkaddr, _clusterName, null, Sets.newHashSet(RESOURCES[1]))); Assert.assertTrue(result); String[] args = { - "--zkSvr", ZK_ADDR, "--cluster", _clusterName, "--resources", RESOURCES[1] + "--zkSvr", _zkaddr, "--cluster", _clusterName, "--resources", RESOURCES[1] }; result = ClusterStateVerifier.verifyState(args); Assert.assertTrue(result); // But the full cluster verification should fail - boolean fullResult = new BestPossAndExtViewZkVerifier(ZK_ADDR, _clusterName).verify(); + boolean fullResult = new BestPossAndExtViewZkVerifier(_zkaddr, _clusterName).verify(); Assert.assertFalse(fullResult); _admin.enableCluster(_clusterName, true); } http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/tools/TestHelixAdminCli.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/tools/TestHelixAdminCli.java b/helix-core/src/test/java/org/apache/helix/tools/TestHelixAdminCli.java index 1d9198b..6d27dcb 100644 --- a/helix-core/src/test/java/org/apache/helix/tools/TestHelixAdminCli.java +++ b/helix-core/src/test/java/org/apache/helix/tools/TestHelixAdminCli.java @@ -31,7 +31,6 @@ import org.apache.helix.TestHelper; import org.apache.helix.ZNRecord; import org.apache.helix.api.id.ParticipantId; import org.apache.helix.api.id.PartitionId; -import org.apache.helix.integration.ZkIntegrationTestBase; import org.apache.helix.integration.manager.ClusterDistributedController; import org.apache.helix.integration.manager.MockParticipantManager; import org.apache.helix.manager.zk.ZKHelixDataAccessor; @@ -41,19 +40,20 @@ import org.apache.helix.model.IdealState; import org.apache.helix.model.InstanceConfig; import org.apache.helix.model.LiveInstance; import org.apache.helix.store.ZNRecordJsonSerializer; +import org.apache.helix.testutil.ZkTestBase; import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier; import org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier; import org.testng.Assert; import org.testng.annotations.Test; -public class TestHelixAdminCli extends ZkIntegrationTestBase { +public class TestHelixAdminCli extends ZkTestBase { @Test public void testAddCluster() throws Exception { - String command = "--zkSvr localhost:2183 -addCluster clusterTest"; + String command = "--zkSvr " + _zkaddr + " -addCluster clusterTest"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); // malformed cluster name - command = "--zkSvr localhost:2183 -addCluster /ClusterTest"; + command = "--zkSvr " + _zkaddr + " -addCluster /ClusterTest"; try { ClusterSetup.processCommandLineArgs(command.split("\\s+")); Assert.fail("ClusterSetup should fail since /ClusterTest is not a valid name"); @@ -63,14 +63,14 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase { // Add the grand cluster // " is ignored by zk - command = "--zkSvr localhost:2183 -addCluster \"Klazt3rz"; + command = "--zkSvr " + _zkaddr + " -addCluster \"Klazt3rz"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); - command = "--zkSvr localhost:2183 -addCluster \\ClusterTest"; + command = "--zkSvr " + _zkaddr + " -addCluster \\ClusterTest"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); // Add already exist cluster - command = "--zkSvr localhost:2183 -addCluster clusterTest"; + command = "--zkSvr " + _zkaddr + " -addCluster clusterTest"; try { ClusterSetup.processCommandLineArgs(command.split("\\s+")); Assert.fail("ClusterSetup should fail since clusterTest already exists"); @@ -79,9 +79,9 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase { } // make sure clusters are properly setup - Assert.assertTrue(ZKUtil.isClusterSetup("Klazt3rz", _gZkClient)); - Assert.assertTrue(ZKUtil.isClusterSetup("clusterTest", _gZkClient)); - Assert.assertTrue(ZKUtil.isClusterSetup("\\ClusterTest", _gZkClient)); + Assert.assertTrue(ZKUtil.isClusterSetup("Klazt3rz", _zkclient)); + Assert.assertTrue(ZKUtil.isClusterSetup("clusterTest", _zkclient)); + Assert.assertTrue(ZKUtil.isClusterSetup("\\ClusterTest", _zkclient)); // delete cluster without resource and instance command = "-zkSvr localhost:2183 -dropCluster \\ClusterTest"; @@ -93,9 +93,9 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase { command = "-zkSvr localhost:2183 -dropCluster clusterTest"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); - Assert.assertFalse(_gZkClient.exists("/clusterTest")); - Assert.assertFalse(_gZkClient.exists("/\\ClusterTest")); - Assert.assertFalse(_gZkClient.exists("/clusterTest1")); + Assert.assertFalse(_zkclient.exists("/clusterTest")); + Assert.assertFalse(_zkclient.exists("/\\ClusterTest")); + Assert.assertFalse(_zkclient.exists("/clusterTest1")); // System.out.println("END test"); } @@ -281,7 +281,7 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase { } // verify leader node - BaseDataAccessor baseAccessor = new ZkBaseDataAccessor(_gZkClient); + BaseDataAccessor baseAccessor = new ZkBaseDataAccessor(_zkclient); HelixDataAccessor accessor = new ZKHelixDataAccessor(grandClusterName, baseAccessor); LiveInstance controllerLeader = accessor.getProperty(accessor.keyBuilder().controllerLeader()); Assert.assertNotNull(controllerLeader, @@ -301,11 +301,11 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase { boolean verifyResult = ClusterStateVerifier - .verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, clusterName)); + .verifyByZkCallback(new MasterNbInExtViewVerifier(_zkaddr, clusterName)); Assert.assertTrue(verifyResult); verifyResult = - ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, + ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(_zkaddr, clusterName)); Assert.assertTrue(verifyResult); @@ -334,12 +334,12 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase { ClusterDistributedController[] controllers = new ClusterDistributedController[2]; setupCluster(clusterName, grandClusterName, n, participants, controllers); String command = - "-zkSvr " + ZK_ADDR + " -activateCluster " + clusterName + " " + grandClusterName + " true"; + "-zkSvr " + _zkaddr + " -activateCluster " + clusterName + " " + grandClusterName + " true"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); Thread.sleep(500); // save ideal state - BaseDataAccessor baseAccessor = new ZkBaseDataAccessor(_gZkClient); + BaseDataAccessor baseAccessor = new ZkBaseDataAccessor(_zkclient); HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor); IdealState idealState = accessor.getProperty(accessor.keyBuilder().idealStates("db_11")); ZNRecordJsonSerializer serializer = new ZNRecordJsonSerializer(); @@ -354,20 +354,20 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase { pw.write(new String(serializer.serialize(idealState.getRecord()))); pw.close(); - command = "-zkSvr " + ZK_ADDR + " -dropResource " + clusterName + " db_11 "; + command = "-zkSvr " + _zkaddr + " -dropResource " + clusterName + " db_11 "; ClusterSetup.processCommandLineArgs(command.split("\\s+")); boolean verifyResult = - ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, + ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(_zkaddr, clusterName)); Assert.assertTrue(verifyResult); command = - "-zkSvr " + ZK_ADDR + " -addIdealState " + clusterName + " db_11 " + tmpIdealStateFile; + "-zkSvr " + _zkaddr + " -addIdealState " + clusterName + " db_11 " + tmpIdealStateFile; ClusterSetup.processCommandLineArgs(command.split("\\s+")); verifyResult = - ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, + ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(_zkaddr, clusterName)); Assert.assertTrue(verifyResult); @@ -390,43 +390,43 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase { MockParticipantManager[] participants, ClusterDistributedController[] controllers) throws Exception, InterruptedException { // add cluster - String command = "-zkSvr " + ZK_ADDR + " -addCluster " + clusterName; + String command = "-zkSvr " + _zkaddr + " -addCluster " + clusterName; ClusterSetup.processCommandLineArgs(command.split("\\s+")); // add grand cluster - command = "-zkSvr " + ZK_ADDR + " -addCluster " + grandClusterName; + command = "-zkSvr " + _zkaddr + " -addCluster " + grandClusterName; ClusterSetup.processCommandLineArgs(command.split("\\s+")); // add nodes for (int i = 0; i < n; i++) { - command = "-zkSvr " + ZK_ADDR + " -addNode " + clusterName + " localhost:123" + i; + command = "-zkSvr " + _zkaddr + " -addNode " + clusterName + " localhost:123" + i; ClusterSetup.processCommandLineArgs(command.split("\\s+")); } // add resource - command = "-zkSvr " + ZK_ADDR + " -addResource " + clusterName + " db_11 48 MasterSlave"; + command = "-zkSvr " + _zkaddr + " -addResource " + clusterName + " db_11 48 MasterSlave"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); // rebalance with key prefix - command = "-zkSvr " + ZK_ADDR + " -rebalance " + clusterName + " db_11 2 -key alias"; + command = "-zkSvr " + _zkaddr + " -rebalance " + clusterName + " db_11 2 -key alias"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); // add nodes to grand cluster command = - "-zkSvr " + ZK_ADDR + " -addNode " + grandClusterName + " controller:9000;controller:9001"; + "-zkSvr " + _zkaddr + " -addNode " + grandClusterName + " controller:9000;controller:9001"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); // start mock nodes for (int i = 0; i < n; i++) { String instanceName = "localhost_123" + i; - participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName); + participants[i] = new MockParticipantManager(_zkaddr, clusterName, instanceName); participants[i].syncStart(); } // start controller nodes for (int i = 0; i < 2; i++) { controllers[i] = - new ClusterDistributedController(ZK_ADDR, grandClusterName, "controller_900" + i); + new ClusterDistributedController(_zkaddr, grandClusterName, "controller_900" + i); controllers[i].syncStart(); } @@ -447,12 +447,12 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase { ClusterDistributedController[] controllers = new ClusterDistributedController[2]; setupCluster(clusterName, grandClusterName, n, participants, controllers); String command = - "-zkSvr " + ZK_ADDR + " -activateCluster " + clusterName + " " + grandClusterName + " true"; + "-zkSvr " + _zkaddr + " -activateCluster " + clusterName + " " + grandClusterName + " true"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); Thread.sleep(500); // drop node should fail if the node is not disabled - command = "-zkSvr " + ZK_ADDR + " -dropNode " + clusterName + " localhost:1232"; + command = "-zkSvr " + _zkaddr + " -dropNode " + clusterName + " localhost:1232"; try { ClusterSetup.processCommandLineArgs(command.split("\\s+")); Assert.fail("dropNode should fail since the node is not disabled"); @@ -461,11 +461,11 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase { } // disabled node - command = "-zkSvr " + ZK_ADDR + " -enableInstance " + clusterName + " localhost:1232 false"; + command = "-zkSvr " + _zkaddr + " -enableInstance " + clusterName + " localhost:1232 false"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); // Cannot dropNode if the node is not disconnected - command = "-zkSvr " + ZK_ADDR + " -dropNode " + clusterName + " localhost:1232"; + command = "-zkSvr " + _zkaddr + " -dropNode " + clusterName + " localhost:1232"; try { ClusterSetup.processCommandLineArgs(command.split("\\s+")); Assert.fail("dropNode should fail since the node is not disconnected"); @@ -475,7 +475,7 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase { // Cannot swapNode if the node is not disconnected command = - "-zkSvr " + ZK_ADDR + " -swapInstance " + clusterName + " localhost_1232 localhost_12320"; + "-zkSvr " + _zkaddr + " -swapInstance " + clusterName + " localhost_1232 localhost_12320"; try { ClusterSetup.processCommandLineArgs(command.split("\\s+")); Assert.fail("swapInstance should fail since the node is not disconnected"); @@ -487,18 +487,18 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase { participants[2].syncStop(); // add new node then swap instance - command = "-zkSvr " + ZK_ADDR + " -addNode " + clusterName + " localhost:12320"; + command = "-zkSvr " + _zkaddr + " -addNode " + clusterName + " localhost:12320"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); // swap instance. The instance get swapped out should not exist anymore command = - "-zkSvr " + ZK_ADDR + " -swapInstance " + clusterName + " localhost_1232 localhost_12320"; + "-zkSvr " + _zkaddr + " -swapInstance " + clusterName + " localhost_1232 localhost_12320"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); - BaseDataAccessor baseAccessor = new ZkBaseDataAccessor(_gZkClient); + BaseDataAccessor baseAccessor = new ZkBaseDataAccessor(_zkclient); HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor); String path = accessor.keyBuilder().instanceConfig("localhost_1232").getPath(); - Assert.assertFalse(_gZkClient.exists(path), path + Assert.assertFalse(_zkclient.exists(path), path + " should not exist since localhost_1232 has been swapped by localhost_12320"); // clean up @@ -526,12 +526,12 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase { ClusterDistributedController[] controllers = new ClusterDistributedController[2]; setupCluster(clusterName, grandClusterName, n, participants, controllers); String command = - "-zkSvr " + ZK_ADDR + " -activateCluster " + clusterName + " " + grandClusterName + " true"; + "-zkSvr " + _zkaddr + " -activateCluster " + clusterName + " " + grandClusterName + " true"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); Thread.sleep(500); command = - "-zkSvr " + ZK_ADDR + " -addNode " + clusterName + "-zkSvr " + _zkaddr + " -addNode " + clusterName + " localhost:12331;localhost:12341;localhost:12351;localhost:12361"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); @@ -541,17 +541,17 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase { MockParticipantManager[] newParticipants = new MockParticipantManager[4]; for (int i = 3; i <= 6; i++) { String instanceName = "localhost_123" + i + "1"; - newParticipants[i - 3] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName); + newParticipants[i - 3] = new MockParticipantManager(_zkaddr, clusterName, instanceName); newParticipants[i - 3].syncStart(); } boolean verifyResult = ClusterStateVerifier - .verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, clusterName)); + .verifyByZkCallback(new MasterNbInExtViewVerifier(_zkaddr, clusterName)); Assert.assertTrue(verifyResult); verifyResult = - ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, + ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(_zkaddr, clusterName)); Assert.assertTrue(verifyResult); @@ -583,29 +583,29 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase { ClusterDistributedController[] controllers = new ClusterDistributedController[2]; setupCluster(clusterName, grandClusterName, n, participants, controllers); String command = - "-zkSvr " + ZK_ADDR + " -activateCluster " + clusterName + " " + grandClusterName + " true"; + "-zkSvr " + _zkaddr + " -activateCluster " + clusterName + " " + grandClusterName + " true"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); Thread.sleep(500); // deactivate cluster command = - "-zkSvr " + ZK_ADDR + " -activateCluster " + clusterName + " " + grandClusterName + "-zkSvr " + _zkaddr + " -activateCluster " + clusterName + " " + grandClusterName + " false"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); - BaseDataAccessor baseAccessor = new ZkBaseDataAccessor(_gZkClient); + BaseDataAccessor baseAccessor = new ZkBaseDataAccessor(_zkclient); HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor); String path = accessor.keyBuilder().controllerLeader().getPath(); for (int i = 0; i < 10; i++) { Thread.sleep(1000); - if (!_gZkClient.exists(path)) { + if (!_zkclient.exists(path)) { break; } } - Assert.assertFalse(_gZkClient.exists(path), + Assert.assertFalse(_zkclient.exists(path), "leader should be gone after deactivate the cluster"); - command = "-zkSvr " + ZK_ADDR + " -dropCluster " + clusterName; + command = "-zkSvr " + _zkaddr + " -dropCluster " + clusterName; try { ClusterSetup.processCommandLineArgs(command.split("\\s+")); Assert.fail("dropCluster should fail since there are still instances running"); @@ -636,35 +636,35 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase { String methodName = TestHelper.getTestMethodName(); String clusterName = className + "_" + methodName; - BaseDataAccessor baseAccessor = new ZkBaseDataAccessor(_gZkClient); + BaseDataAccessor baseAccessor = new ZkBaseDataAccessor(_zkclient); HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor); System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis())); - String command = "-zkSvr " + ZK_ADDR + " -addCluster " + clusterName; + String command = "-zkSvr " + _zkaddr + " -addCluster " + clusterName; ClusterSetup.processCommandLineArgs(command.split("\\s+")); command = "-zkSvr localhost:2183 -addResource " + clusterName + " db_11 12 MasterSlave"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); for (int i = 0; i < 6; i++) { - command = "-zkSvr " + ZK_ADDR + " -addNode " + clusterName + " localhost:123" + i; + command = "-zkSvr " + _zkaddr + " -addNode " + clusterName + " localhost:123" + i; ClusterSetup.processCommandLineArgs(command.split("\\s+")); } for (int i = 0; i < 2; i++) { command = - "-zkSvr " + ZK_ADDR + " -addInstanceTag " + clusterName + " localhost_123" + i + " tag1"; + "-zkSvr " + _zkaddr + " -addInstanceTag " + clusterName + " localhost_123" + i + " tag1"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); } for (int i = 2; i < 6; i++) { command = - "-zkSvr " + ZK_ADDR + " -addInstanceTag " + clusterName + " localhost_123" + i + " tag2"; + "-zkSvr " + _zkaddr + " -addInstanceTag " + clusterName + " localhost_123" + i + " tag2"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); } command = - "-zkSvr " + ZK_ADDR + " -rebalance " + clusterName + " db_11 2 -instanceGroupTag tag1"; + "-zkSvr " + _zkaddr + " -rebalance " + clusterName + " db_11 2 -instanceGroupTag tag1"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); IdealState dbIs = accessor.getProperty(accessor.keyBuilder().idealStates("db_11")); @@ -679,15 +679,15 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase { } Assert.assertEquals(hosts.size(), 2); - command = "-zkSvr " + ZK_ADDR + " -dropResource " + clusterName + " db_11 "; + command = "-zkSvr " + _zkaddr + " -dropResource " + clusterName + " db_11 "; ClusterSetup.processCommandLineArgs(command.split("\\s+")); // re-add and rebalance - command = "-zkSvr " + ZK_ADDR + " -addResource " + clusterName + " db_11 48 MasterSlave"; + command = "-zkSvr " + _zkaddr + " -addResource " + clusterName + " db_11 48 MasterSlave"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); command = - "-zkSvr " + ZK_ADDR + " -rebalance " + clusterName + " db_11 3 -instanceGroupTag tag2"; + "-zkSvr " + _zkaddr + " -rebalance " + clusterName + " db_11 3 -instanceGroupTag tag2"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); dbIs = accessor.getProperty(accessor.keyBuilder().idealStates("db_11")); @@ -702,22 +702,22 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase { } Assert.assertEquals(hosts.size(), 4); - command = "-zkSvr " + ZK_ADDR + " -dropResource " + clusterName + " db_11 "; + command = "-zkSvr " + _zkaddr + " -dropResource " + clusterName + " db_11 "; ClusterSetup.processCommandLineArgs(command.split("\\s+")); for (int i = 3; i <= 3; i++) { command = - "-zkSvr " + ZK_ADDR + " -removeInstanceTag " + clusterName + " localhost_123" + i + "-zkSvr " + _zkaddr + " -removeInstanceTag " + clusterName + " localhost_123" + i + " tag2"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); } // re-add and rebalance - command = "-zkSvr " + ZK_ADDR + " -addResource " + clusterName + " db_11 48 MasterSlave"; + command = "-zkSvr " + _zkaddr + " -addResource " + clusterName + " db_11 48 MasterSlave"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); command = - "-zkSvr " + ZK_ADDR + " -rebalance " + clusterName + " db_11 3 -instanceGroupTag tag2"; + "-zkSvr " + _zkaddr + " -rebalance " + clusterName + " db_11 3 -instanceGroupTag tag2"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); dbIs = accessor.getProperty(accessor.keyBuilder().idealStates("db_11")); hosts = new HashSet(); @@ -732,7 +732,7 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase { Assert.assertEquals(hosts.size(), 3); // rebalance with key prefix - command = "-zkSvr " + ZK_ADDR + " -rebalance " + clusterName + " db_11 2 -key alias"; + command = "-zkSvr " + _zkaddr + " -rebalance " + clusterName + " db_11 2 -key alias"; ClusterSetup.processCommandLineArgs(command.split("\\s+")); System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis())); http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/tools/TestZkCopy.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/tools/TestZkCopy.java b/helix-core/src/test/java/org/apache/helix/tools/TestZkCopy.java index ee3d2bd..26529bf 100644 --- a/helix-core/src/test/java/org/apache/helix/tools/TestZkCopy.java +++ b/helix-core/src/test/java/org/apache/helix/tools/TestZkCopy.java @@ -24,12 +24,12 @@ import java.util.Date; import org.apache.helix.InstanceType; import org.apache.helix.TestHelper; import org.apache.helix.ZNRecord; -import org.apache.helix.ZkUnitTestBase; import org.apache.helix.manager.zk.ZKUtil; +import org.apache.helix.testutil.ZkTestBase; import org.testng.Assert; import org.testng.annotations.Test; -public class TestZkCopy extends ZkUnitTestBase { +public class TestZkCopy extends ZkTestBase { @Test public void test() throws Exception { @@ -39,27 +39,27 @@ public class TestZkCopy extends ZkUnitTestBase { System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis())); String fromPath = "/" + clusterName + "/from"; - _gZkClient.createPersistent(fromPath, true); + _zkclient.createPersistent(fromPath, true); for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { String path = String.format("%s/%d/%d", fromPath, i, j); - _gZkClient.createPersistent(path, true); - _gZkClient.writeData(path, new ZNRecord(String.format("%d/%d", i, j))); + _zkclient.createPersistent(path, true); + _zkclient.writeData(path, new ZNRecord(String.format("%d/%d", i, j))); } } // Copy String toPath = "/" + clusterName + "/to"; - ZkCopy.main(new String[]{"--src", "zk://" + ZK_ADDR + fromPath, "--dst", "zk://" + ZK_ADDR + toPath}); + ZkCopy.main(new String[]{"--src", "zk://" + _zkaddr + fromPath, "--dst", "zk://" + _zkaddr + toPath}); // Verify - Assert.assertTrue(_gZkClient.exists(toPath)); - Assert.assertNull(_gZkClient.readData(toPath)); + Assert.assertTrue(_zkclient.exists(toPath)); + Assert.assertNull(_zkclient.readData(toPath)); for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { String path = String.format("%s/%d/%d", toPath, i, j); - Assert.assertTrue(_gZkClient.exists(path)); - ZNRecord record = _gZkClient.readData(path); + Assert.assertTrue(_zkclient.exists(path)); + ZNRecord record = _zkclient.readData(path); Assert.assertEquals(String.format("%d/%d", i, j), record.getId()); } } @@ -78,7 +78,7 @@ public class TestZkCopy extends ZkUnitTestBase { String dstClusterName = testName + "_dst"; int n = 5; - TestHelper.setupCluster(srcClusterName, ZK_ADDR, 12918, // participant port + TestHelper.setupCluster(srcClusterName, _zkaddr, 12918, // participant port "localhost", // participant name prefix "TestDB", // resource name prefix 1, // resources @@ -87,25 +87,25 @@ public class TestZkCopy extends ZkUnitTestBase { 2, // replicas "MasterSlave", true); // do rebalance - TestHelper.setupEmptyCluster(_gZkClient, dstClusterName); + TestHelper.setupEmptyCluster(_zkclient, dstClusterName); String fromPath = String.format("/%s/INSTANCES", srcClusterName); String toPath = String.format("/%s/INSTANCES", dstClusterName); ZkCopy.main(new String[] { - "--src", "zk://" + ZK_ADDR + fromPath, "--dst", "zk://" + ZK_ADDR + toPath + "--src", "zk://" + _zkaddr + fromPath, "--dst", "zk://" + _zkaddr + toPath }); fromPath = String.format("/%s/CONFIGS/PARTICIPANT", srcClusterName); toPath = String.format("/%s/CONFIGS/PARTICIPANT", dstClusterName); ZkCopy.main(new String[] { - "--src", "zk://" + ZK_ADDR + fromPath, "--dst", "zk://" + ZK_ADDR + toPath + "--src", "zk://" + _zkaddr + fromPath, "--dst", "zk://" + _zkaddr + toPath }); for (int i = 0; i < n; i++) { String instanceName = "localhost_" + (12918 + i); boolean ret = ZKUtil - .isInstanceSetup(_gZkClient, dstClusterName, instanceName, InstanceType.PARTICIPANT); + .isInstanceSetup(_zkclient, dstClusterName, instanceName, InstanceType.PARTICIPANT); Assert.assertTrue(ret); } System.out.println("END " + testName + " at " + new Date(System.currentTimeMillis()));