You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by zz...@apache.org on 2014/07/22 20:40:21 UTC
[3/9] [HELIX-475] Remove code duplication for Zk tests
http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancer.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancer.java b/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancer.java
index 0a59ee1..911832a 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancer.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancer.java
@@ -30,7 +30,6 @@ import org.apache.helix.HelixManagerFactory;
import org.apache.helix.InstanceType;
import org.apache.helix.PropertyKey;
import org.apache.helix.api.id.StateModelDefId;
-import org.apache.helix.integration.ZkIntegrationTestBase;
import org.apache.helix.integration.manager.ClusterControllerManager;
import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.participant.StateMachineEngine;
@@ -48,7 +47,7 @@ import org.apache.helix.task.TaskStateModelFactory;
import org.apache.helix.task.TaskUtil;
import org.apache.helix.task.Workflow;
import org.apache.helix.task.WorkflowContext;
-import org.apache.helix.tools.ClusterSetup;
+import org.apache.helix.testutil.ZkTestBase;
import org.apache.helix.tools.ClusterStateVerifier;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
@@ -59,14 +58,14 @@ import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-public class TestTaskRebalancer extends ZkIntegrationTestBase {
+public class TestTaskRebalancer extends ZkTestBase {
private static final int n = 5;
private static final int START_PORT = 12918;
private static final String MASTER_SLAVE_STATE_MODEL = "MasterSlave";
private static final String TIMEOUT_CONFIG = "Timeout";
private static final int NUM_PARTITIONS = 20;
private static final int NUM_REPLICAS = 3;
- private final String CLUSTER_NAME = CLUSTER_PREFIX + "_" + getShortClassName();
+ private final String CLUSTER_NAME = "TestTaskRebalancer";
private final MockParticipantManager[] _participants = new MockParticipantManager[n];
private ClusterControllerManager _controller;
@@ -76,21 +75,20 @@ public class TestTaskRebalancer extends ZkIntegrationTestBase {
@BeforeClass
public void beforeClass() throws Exception {
String namespace = "/" + CLUSTER_NAME;
- if (_gZkClient.exists(namespace)) {
- _gZkClient.deleteRecursive(namespace);
+ if (_zkclient.exists(namespace)) {
+ _zkclient.deleteRecursive(namespace);
}
- ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
- setupTool.addCluster(CLUSTER_NAME, true);
+ _setupTool.addCluster(CLUSTER_NAME, true);
for (int i = 0; i < n; i++) {
- String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
- setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
+ String storageNodeName = "localhost_" + (START_PORT + i);
+ _setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
}
// Set up target db
- setupTool.addResourceToCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB, NUM_PARTITIONS,
+ _setupTool.addResourceToCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB, NUM_PARTITIONS,
MASTER_SLAVE_STATE_MODEL);
- setupTool.rebalanceStorageCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB, NUM_REPLICAS);
+ _setupTool.rebalanceStorageCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB, NUM_REPLICAS);
Map<String, TaskFactory> taskFactoryReg = new HashMap<String, TaskFactory>();
taskFactoryReg.put("Reindex", new TaskFactory() {
@@ -102,8 +100,8 @@ public class TestTaskRebalancer extends ZkIntegrationTestBase {
// start dummy participants
for (int i = 0; i < n; i++) {
- String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
- _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
+ String instanceName = "localhost_" + (START_PORT + i);
+ _participants[i] = new MockParticipantManager(_zkaddr, CLUSTER_NAME, instanceName);
// Register a Task state model factory.
StateMachineEngine stateMachine = _participants[i].getStateMachineEngine();
@@ -113,20 +111,20 @@ public class TestTaskRebalancer extends ZkIntegrationTestBase {
}
// start controller
- String controllerName = CONTROLLER_PREFIX + "_0";
- _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
+ String controllerName = "controller_0";
+ _controller = new ClusterControllerManager(_zkaddr, CLUSTER_NAME, controllerName);
_controller.syncStart();
// create cluster manager
_manager =
HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, "Admin", InstanceType.ADMINISTRATOR,
- ZK_ADDR);
+ _zkaddr);
_manager.connect();
_driver = new TaskDriver(_manager);
boolean result =
ClusterStateVerifier
- .verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR,
+ .verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(_zkaddr,
CLUSTER_NAME));
Assert.assertTrue(result);
}
http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancerStopResume.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancerStopResume.java b/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancerStopResume.java
index e555468..6de361d 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancerStopResume.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/task/TestTaskRebalancerStopResume.java
@@ -27,7 +27,6 @@ import org.apache.helix.HelixManager;
import org.apache.helix.HelixManagerFactory;
import org.apache.helix.InstanceType;
import org.apache.helix.api.id.StateModelDefId;
-import org.apache.helix.integration.ZkIntegrationTestBase;
import org.apache.helix.integration.manager.ClusterControllerManager;
import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.participant.StateMachineEngine;
@@ -40,7 +39,7 @@ import org.apache.helix.task.TaskResult;
import org.apache.helix.task.TaskState;
import org.apache.helix.task.TaskStateModelFactory;
import org.apache.helix.task.Workflow;
-import org.apache.helix.tools.ClusterSetup;
+import org.apache.helix.testutil.ZkTestBase;
import org.apache.helix.tools.ClusterStateVerifier;
import org.apache.log4j.Logger;
import org.testng.Assert;
@@ -50,7 +49,7 @@ import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
-public class TestTaskRebalancerStopResume extends ZkIntegrationTestBase {
+public class TestTaskRebalancerStopResume extends ZkTestBase {
private static final Logger LOG = Logger.getLogger(TestTaskRebalancerStopResume.class);
private static final int n = 5;
private static final int START_PORT = 12918;
@@ -60,7 +59,7 @@ public class TestTaskRebalancerStopResume extends ZkIntegrationTestBase {
private static final String JOB_RESOURCE = "SomeJob";
private static final int NUM_PARTITIONS = 20;
private static final int NUM_REPLICAS = 3;
- private final String CLUSTER_NAME = CLUSTER_PREFIX + "_" + getShortClassName();
+ private final String CLUSTER_NAME = "TestTaskRebalancerStopResume";
private final MockParticipantManager[] _participants = new MockParticipantManager[n];
private ClusterControllerManager _controller;
@@ -70,20 +69,19 @@ public class TestTaskRebalancerStopResume extends ZkIntegrationTestBase {
@BeforeClass
public void beforeClass() throws Exception {
String namespace = "/" + CLUSTER_NAME;
- if (_gZkClient.exists(namespace)) {
- _gZkClient.deleteRecursive(namespace);
+ if (_zkclient.exists(namespace)) {
+ _zkclient.deleteRecursive(namespace);
}
- ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
- setupTool.addCluster(CLUSTER_NAME, true);
+ _setupTool.addCluster(CLUSTER_NAME, true);
for (int i = 0; i < n; i++) {
- String storageNodeName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
- setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
+ String storageNodeName = "localhost_" + (START_PORT + i);
+ _setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
}
// Set up target db
- setupTool.addResourceToCluster(CLUSTER_NAME, TGT_DB, NUM_PARTITIONS, MASTER_SLAVE_STATE_MODEL);
- setupTool.rebalanceStorageCluster(CLUSTER_NAME, TGT_DB, NUM_REPLICAS);
+ _setupTool.addResourceToCluster(CLUSTER_NAME, TGT_DB, NUM_PARTITIONS, MASTER_SLAVE_STATE_MODEL);
+ _setupTool.rebalanceStorageCluster(CLUSTER_NAME, TGT_DB, NUM_REPLICAS);
Map<String, TaskFactory> taskFactoryReg = new HashMap<String, TaskFactory>();
taskFactoryReg.put("Reindex", new TaskFactory() {
@@ -95,8 +93,8 @@ public class TestTaskRebalancerStopResume extends ZkIntegrationTestBase {
// start dummy participants
for (int i = 0; i < n; i++) {
- String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
- _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
+ String instanceName = "localhost_" + (START_PORT + i);
+ _participants[i] = new MockParticipantManager(_zkaddr, CLUSTER_NAME, instanceName);
// Register a Task state model factory.
StateMachineEngine stateMachine = _participants[i].getStateMachineEngine();
@@ -107,26 +105,26 @@ public class TestTaskRebalancerStopResume extends ZkIntegrationTestBase {
}
// start controller
- String controllerName = CONTROLLER_PREFIX + "_0";
- _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
+ String controllerName = "controller_0";
+ _controller = new ClusterControllerManager(_zkaddr, CLUSTER_NAME, controllerName);
_controller.syncStart();
// create cluster manager
_manager =
HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, "Admin", InstanceType.ADMINISTRATOR,
- ZK_ADDR);
+ _zkaddr);
_manager.connect();
_driver = new TaskDriver(_manager);
boolean result =
ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.MasterNbInExtViewVerifier(
- ZK_ADDR, CLUSTER_NAME));
+ _zkaddr, CLUSTER_NAME));
Assert.assertTrue(result);
result =
ClusterStateVerifier
- .verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR,
+ .verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(_zkaddr,
CLUSTER_NAME));
Assert.assertTrue(result);
}
http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/lock/zk/TestZKHelixLock.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/lock/zk/TestZKHelixLock.java b/helix-core/src/test/java/org/apache/helix/lock/zk/TestZKHelixLock.java
index f39ca11..4f43d72 100644
--- a/helix-core/src/test/java/org/apache/helix/lock/zk/TestZKHelixLock.java
+++ b/helix-core/src/test/java/org/apache/helix/lock/zk/TestZKHelixLock.java
@@ -4,10 +4,10 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.helix.ZkUnitTestBase;
import org.apache.helix.api.Scope;
import org.apache.helix.api.id.ClusterId;
import org.apache.helix.lock.HelixLock;
+import org.apache.helix.testutil.ZkTestBase;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -33,19 +33,19 @@ import org.testng.annotations.Test;
/**
* Tests that the Zookeeper-based Helix lock can acquire, block, and release as appropriate
*/
-public class TestZKHelixLock extends ZkUnitTestBase {
+public class TestZKHelixLock extends ZkTestBase {
@Test
public void basicTest() throws InterruptedException {
final long TIMEOUT = 30000;
final long RETRY_INTERVAL = 100;
- _gZkClient.waitUntilConnected(TIMEOUT, TimeUnit.MILLISECONDS);
+ _zkclient.waitUntilConnected(TIMEOUT, TimeUnit.MILLISECONDS);
final AtomicBoolean t1Locked = new AtomicBoolean(false);
final AtomicBoolean t1Done = new AtomicBoolean(false);
final AtomicInteger field1 = new AtomicInteger(0);
final AtomicInteger field2 = new AtomicInteger(1);
final ClusterId clusterId = ClusterId.from("testCluster");
- final HelixLock lock1 = new ZKHelixLock(clusterId, Scope.cluster(clusterId), _gZkClient);
- final HelixLock lock2 = new ZKHelixLock(clusterId, Scope.cluster(clusterId), _gZkClient);
+ final HelixLock lock1 = new ZKHelixLock(clusterId, Scope.cluster(clusterId), _zkclient);
+ final HelixLock lock2 = new ZKHelixLock(clusterId, Scope.cluster(clusterId), _zkclient);
// thread 1: get a lock, set fields to 1
Thread t1 = new Thread() {
http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/manager/zk/TestHandleNewSession.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestHandleNewSession.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestHandleNewSession.java
index 352cdd5..ca0d4ab 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestHandleNewSession.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestHandleNewSession.java
@@ -23,12 +23,12 @@ import java.util.Date;
import org.apache.helix.TestHelper;
import org.apache.helix.ZkTestHelper;
-import org.apache.helix.integration.ZkIntegrationTestBase;
import org.apache.helix.integration.manager.MockParticipantManager;
+import org.apache.helix.testutil.ZkTestBase;
import org.testng.Assert;
import org.testng.annotations.Test;
-public class TestHandleNewSession extends ZkIntegrationTestBase {
+public class TestHandleNewSession extends ZkTestBase {
@Test
public void testHandleNewSession() throws Exception {
// Logger.getRootLogger().setLevel(Level.INFO);
@@ -38,7 +38,7 @@ public class TestHandleNewSession extends ZkIntegrationTestBase {
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
@@ -48,7 +48,7 @@ public class TestHandleNewSession extends ZkIntegrationTestBase {
"MasterSlave", true); // do rebalance
MockParticipantManager participant =
- new MockParticipantManager(ZK_ADDR, clusterName, "localhost_12918");
+ new MockParticipantManager(_zkaddr, clusterName, "localhost_12918");
participant.syncStart();
// Logger.getRootLogger().setLevel(Level.INFO);
http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/manager/zk/TestLiveInstanceBounce.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestLiveInstanceBounce.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestLiveInstanceBounce.java
index c2982b2..e59dd0c 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestLiveInstanceBounce.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestLiveInstanceBounce.java
@@ -31,7 +31,7 @@ public class TestLiveInstanceBounce extends ZkStandAloneCMTestBase {
int handlerSize = _controller.getHandlers().size();
for (int i = 0; i < 2; i++) {
- String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
+ String instanceName = "localhost_" + (START_PORT + i);
// kill 2 participants
_participants[i].syncStop();
try {
@@ -40,7 +40,7 @@ public class TestLiveInstanceBounce extends ZkStandAloneCMTestBase {
e.printStackTrace();
}
// restart the participant
- _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
+ _participants[i] = new MockParticipantManager(_zkaddr, CLUSTER_NAME, instanceName);
_participants[i].syncStart();
Thread.sleep(100);
}
@@ -48,7 +48,7 @@ public class TestLiveInstanceBounce extends ZkStandAloneCMTestBase {
boolean result =
ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
- ZK_ADDR, CLUSTER_NAME), 50 * 1000);
+ _zkaddr, CLUSTER_NAME), 50 * 1000);
Assert.assertTrue(result);
// When a new live instance is created, we add current state listener to it
http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/manager/zk/TestWtCacheAsyncOpMultiThread.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestWtCacheAsyncOpMultiThread.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestWtCacheAsyncOpMultiThread.java
index c6875be..39b6f23 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestWtCacheAsyncOpMultiThread.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestWtCacheAsyncOpMultiThread.java
@@ -32,11 +32,11 @@ import org.apache.helix.PropertyType;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.ZNRecordUpdater;
-import org.apache.helix.ZkUnitTestBase;
+import org.apache.helix.testutil.ZkTestBase;
import org.testng.Assert;
import org.testng.annotations.Test;
-public class TestWtCacheAsyncOpMultiThread extends ZkUnitTestBase {
+public class TestWtCacheAsyncOpMultiThread extends ZkTestBase {
class TestCreateZkCacheBaseDataAccessor implements Callable<Boolean> {
final ZkCacheBaseDataAccessor<ZNRecord> _accessor;
final String _clusterName;
@@ -201,7 +201,7 @@ public class TestWtCacheAsyncOpMultiThread extends ZkUnitTestBase {
PropertyPathConfig.getPath(PropertyType.CURRENTSTATES, clusterName, "localhost_8901");
String extViewPath = PropertyPathConfig.getPath(PropertyType.EXTERNALVIEW, clusterName);
- ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+ ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
baseAccessor.create(curStatePath, null, AccessOption.PERSISTENT);
@@ -210,7 +210,7 @@ public class TestWtCacheAsyncOpMultiThread extends ZkUnitTestBase {
new ZkCacheBaseDataAccessor<ZNRecord>(baseAccessor, null, cachePaths, null);
// TestHelper.printCache(accessor._wtCache);
- boolean ret = TestHelper.verifyZkCache(cachePaths, accessor._wtCache._cache, _gZkClient, false);
+ boolean ret = TestHelper.verifyZkCache(cachePaths, accessor._wtCache._cache, _zkclient, false);
Assert.assertTrue(ret, "wtCache doesn't match data on Zk");
// create 10 current states using 2 threads
@@ -222,7 +222,7 @@ public class TestWtCacheAsyncOpMultiThread extends ZkUnitTestBase {
// verify wtCache
// TestHelper.printCache(accessor._wtCache);
- ret = TestHelper.verifyZkCache(cachePaths, accessor._wtCache._cache, _gZkClient, false);
+ ret = TestHelper.verifyZkCache(cachePaths, accessor._wtCache._cache, _zkclient, false);
Assert.assertTrue(ret, "wtCache doesn't match data on Zk");
// update 10 current states 10 times using 2 threads
@@ -234,7 +234,7 @@ public class TestWtCacheAsyncOpMultiThread extends ZkUnitTestBase {
// verify wtCache
// TestHelper.printCache(accessor._wtCache);
- ret = TestHelper.verifyZkCache(cachePaths, accessor._wtCache._cache, _gZkClient, false);
+ ret = TestHelper.verifyZkCache(cachePaths, accessor._wtCache._cache, _zkclient, false);
Assert.assertTrue(ret, "wtCache doesn't match data on Zk");
// set 10 external views using 2 threads
@@ -246,7 +246,7 @@ public class TestWtCacheAsyncOpMultiThread extends ZkUnitTestBase {
// verify wtCache
// TestHelper.printCache(accessor._wtCache);
- ret = TestHelper.verifyZkCache(cachePaths, accessor._wtCache._cache, _gZkClient, false);
+ ret = TestHelper.verifyZkCache(cachePaths, accessor._wtCache._cache, _zkclient, false);
Assert.assertTrue(ret, "wtCache doesn't match data on Zk");
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/manager/zk/TestWtCacheAsyncOpSingleThread.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestWtCacheAsyncOpSingleThread.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestWtCacheAsyncOpSingleThread.java
index ac7a0db..47c5ad4 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestWtCacheAsyncOpSingleThread.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestWtCacheAsyncOpSingleThread.java
@@ -31,11 +31,11 @@ import org.apache.helix.PropertyType;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.ZNRecordUpdater;
-import org.apache.helix.ZkUnitTestBase;
+import org.apache.helix.testutil.ZkTestBase;
import org.testng.Assert;
import org.testng.annotations.Test;
-public class TestWtCacheAsyncOpSingleThread extends ZkUnitTestBase {
+public class TestWtCacheAsyncOpSingleThread extends ZkTestBase {
@Test
public void testHappyPathZkCacheBaseDataAccessor() {
String className = TestHelper.getTestClassName();
@@ -48,7 +48,7 @@ public class TestWtCacheAsyncOpSingleThread extends ZkUnitTestBase {
PropertyPathConfig.getPath(PropertyType.CURRENTSTATES, clusterName, "localhost_8901");
String extViewPath = PropertyPathConfig.getPath(PropertyType.EXTERNALVIEW, clusterName);
- ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+ ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
baseAccessor.create(curStatePath, null, AccessOption.PERSISTENT);
@@ -56,7 +56,7 @@ public class TestWtCacheAsyncOpSingleThread extends ZkUnitTestBase {
ZkCacheBaseDataAccessor<ZNRecord> accessor =
new ZkCacheBaseDataAccessor<ZNRecord>(baseAccessor, null, cachePaths, null);
- boolean ret = TestHelper.verifyZkCache(cachePaths, accessor._wtCache._cache, _gZkClient, false);
+ boolean ret = TestHelper.verifyZkCache(cachePaths, accessor._wtCache._cache, _zkclient, false);
Assert.assertTrue(ret, "wtCache doesn't match data on Zk");
// create 10 current states
@@ -79,7 +79,7 @@ public class TestWtCacheAsyncOpSingleThread extends ZkUnitTestBase {
// verify wtCache
// TestHelper.printCache(accessor._wtCache);
- ret = TestHelper.verifyZkCache(cachePaths, accessor._wtCache._cache, _gZkClient, false);
+ ret = TestHelper.verifyZkCache(cachePaths, accessor._wtCache._cache, _zkclient, false);
Assert.assertTrue(ret, "wtCache doesn't match data on Zk");
// update each current state 10 times
@@ -104,7 +104,7 @@ public class TestWtCacheAsyncOpSingleThread extends ZkUnitTestBase {
// verify cache
// TestHelper.printCache(accessor._wtCache);
- ret = TestHelper.verifyZkCache(cachePaths, accessor._wtCache._cache, _gZkClient, false);
+ ret = TestHelper.verifyZkCache(cachePaths, accessor._wtCache._cache, _zkclient, false);
Assert.assertTrue(ret, "wtCache doesn't match data on Zk");
// set 10 external views
@@ -125,7 +125,7 @@ public class TestWtCacheAsyncOpSingleThread extends ZkUnitTestBase {
// verify wtCache
// TestHelper.printCache(accessor._wtCache);
- ret = TestHelper.verifyZkCache(cachePaths, accessor._wtCache._cache, _gZkClient, false);
+ ret = TestHelper.verifyZkCache(cachePaths, accessor._wtCache._cache, _zkclient, false);
Assert.assertTrue(ret, "wtCache doesn't match data on Zk");
// get 10 external views
@@ -177,7 +177,7 @@ public class TestWtCacheAsyncOpSingleThread extends ZkUnitTestBase {
PropertyPathConfig.getPath(PropertyType.CURRENTSTATES, clusterName, "localhost_8901");
String extViewPath = PropertyPathConfig.getPath(PropertyType.EXTERNALVIEW, clusterName);
- ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+ ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
baseAccessor.create(curStatePath, null, AccessOption.PERSISTENT);
http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/manager/zk/TestWtCacheSyncOpSingleThread.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestWtCacheSyncOpSingleThread.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestWtCacheSyncOpSingleThread.java
index 979a179..ba2072a 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestWtCacheSyncOpSingleThread.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestWtCacheSyncOpSingleThread.java
@@ -29,11 +29,11 @@ import org.apache.helix.PropertyType;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.ZNRecordUpdater;
-import org.apache.helix.ZkUnitTestBase;
+import org.apache.helix.testutil.ZkTestBase;
import org.testng.Assert;
import org.testng.annotations.Test;
-public class TestWtCacheSyncOpSingleThread extends ZkUnitTestBase {
+public class TestWtCacheSyncOpSingleThread extends ZkTestBase {
// TODO: add TestZkCacheSyncOpSingleThread
// TODO: add TestZkCacheAsyncOpMultiThread
@Test
@@ -48,7 +48,7 @@ public class TestWtCacheSyncOpSingleThread extends ZkUnitTestBase {
PropertyPathConfig.getPath(PropertyType.CURRENTSTATES, clusterName, "localhost_8901");
String extViewPath = PropertyPathConfig.getPath(PropertyType.EXTERNALVIEW, clusterName);
- ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+ ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
baseAccessor.create(curStatePath, null, AccessOption.PERSISTENT);
@@ -56,7 +56,7 @@ public class TestWtCacheSyncOpSingleThread extends ZkUnitTestBase {
ZkCacheBaseDataAccessor<ZNRecord> accessor =
new ZkCacheBaseDataAccessor<ZNRecord>(baseAccessor, null, cachePaths, null);
- boolean ret = TestHelper.verifyZkCache(cachePaths, accessor._wtCache._cache, _gZkClient, true);
+ boolean ret = TestHelper.verifyZkCache(cachePaths, accessor._wtCache._cache, _zkclient, true);
Assert.assertTrue(ret, "wtCache doesn't match data on Zk");
// create 10 current states
@@ -68,7 +68,7 @@ public class TestWtCacheSyncOpSingleThread extends ZkUnitTestBase {
// verify wtCache
// TestHelper.printCache(accessor._wtCache);
- ret = TestHelper.verifyZkCache(cachePaths, accessor._wtCache._cache, _gZkClient, false);
+ ret = TestHelper.verifyZkCache(cachePaths, accessor._wtCache._cache, _zkclient, false);
Assert.assertTrue(ret, "wtCache doesn't match data on Zk");
// update each current state 10 times, single thread
@@ -86,7 +86,7 @@ public class TestWtCacheSyncOpSingleThread extends ZkUnitTestBase {
// verify cache
// TestHelper.printCache(accessor._wtCache._cache);
- ret = TestHelper.verifyZkCache(cachePaths, accessor._wtCache._cache, _gZkClient, false);
+ ret = TestHelper.verifyZkCache(cachePaths, accessor._wtCache._cache, _zkclient, false);
Assert.assertTrue(ret, "wtCache doesn't match data on Zk");
// set 10 external views
@@ -99,7 +99,7 @@ public class TestWtCacheSyncOpSingleThread extends ZkUnitTestBase {
// verify wtCache
// accessor.printWtCache();
- ret = TestHelper.verifyZkCache(cachePaths, accessor._wtCache._cache, _gZkClient, false);
+ ret = TestHelper.verifyZkCache(cachePaths, accessor._wtCache._cache, _zkclient, false);
Assert.assertTrue(ret, "wtCache doesn't match data on Zk");
// get 10 external views
@@ -141,7 +141,7 @@ public class TestWtCacheSyncOpSingleThread extends ZkUnitTestBase {
String curStatePath =
PropertyPathConfig.getPath(PropertyType.CURRENTSTATES, clusterName, "localhost_8901");
- ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+ ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
ZkCacheBaseDataAccessor<ZNRecord> accessor =
new ZkCacheBaseDataAccessor<ZNRecord>(baseAccessor, null, Arrays.asList(curStatePath), null);
http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/manager/zk/TestZKLiveInstanceData.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZKLiveInstanceData.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZKLiveInstanceData.java
index 29207ca..54f81cd 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZKLiveInstanceData.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZKLiveInstanceData.java
@@ -34,22 +34,22 @@ import org.apache.helix.InstanceType;
import org.apache.helix.LiveInstanceChangeListener;
import org.apache.helix.NotificationContext;
import org.apache.helix.PropertyKey;
-import org.apache.helix.ZkUnitTestBase;
import org.apache.helix.model.LiveInstance;
+import org.apache.helix.testutil.ZkTestBase;
import org.apache.helix.tools.ClusterSetup;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-public class TestZKLiveInstanceData extends ZkUnitTestBase {
- private final String clusterName = CLUSTER_PREFIX + "_" + getShortClassName();
+public class TestZKLiveInstanceData extends ZkTestBase {
+ private final String clusterName = "TestZKLiveInstanceData";
@Test
public void testDataChange() throws Exception {
// Create an admin and add LiveInstanceChange listener to it
HelixManager adminManager =
HelixManagerFactory.getZKHelixManager(clusterName, null, InstanceType.ADMINISTRATOR,
- ZK_ADDR);
+ _zkaddr);
adminManager.connect();
final BlockingQueue<List<LiveInstance>> changeList =
new LinkedBlockingQueue<List<LiveInstance>>();
@@ -71,7 +71,7 @@ public class TestZKLiveInstanceData extends ZkUnitTestBase {
// Join as participant, should trigger a live instance change event
HelixManager manager =
HelixManagerFactory.getZKHelixManager(clusterName, "localhost_54321",
- InstanceType.PARTICIPANT, ZK_ADDR);
+ InstanceType.PARTICIPANT, _zkaddr);
manager.connect();
instances = changeList.poll(1, TimeUnit.SECONDS);
Assert.assertNotNull(instances, "Expecting a list of live instance");
@@ -108,7 +108,7 @@ public class TestZKLiveInstanceData extends ZkUnitTestBase {
public void beforeClass() throws Exception {
ZkClient zkClient = null;
try {
- zkClient = new ZkClient(ZK_ADDR);
+ zkClient = new ZkClient(_zkaddr);
zkClient.setZkSerializer(new ZNRecordSerializer());
if (zkClient.exists("/" + clusterName)) {
zkClient.deleteRecursive("/" + clusterName);
@@ -119,10 +119,10 @@ public class TestZKLiveInstanceData extends ZkUnitTestBase {
}
}
- ClusterSetup.processCommandLineArgs(getArgs("-zkSvr", ZK_ADDR, "-addCluster", clusterName));
- ClusterSetup.processCommandLineArgs(getArgs("-zkSvr", ZK_ADDR, "-addNode", clusterName,
+ ClusterSetup.processCommandLineArgs(getArgs("-zkSvr", _zkaddr, "-addCluster", clusterName));
+ ClusterSetup.processCommandLineArgs(getArgs("-zkSvr", _zkaddr, "-addNode", clusterName,
"localhost:54321"));
- ClusterSetup.processCommandLineArgs(getArgs("-zkSvr", ZK_ADDR, "-addNode", clusterName,
+ ClusterSetup.processCommandLineArgs(getArgs("-zkSvr", _zkaddr, "-addNode", clusterName,
"localhost:54322"));
}
http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/manager/zk/TestZKUtil.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZKUtil.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZKUtil.java
index f7dcb85..8ba6dac 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZKUtil.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZKUtil.java
@@ -27,23 +27,23 @@ 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.model.HelixConfigScope.ConfigScopeProperty;
+import org.apache.helix.testutil.ZkTestBase;
import org.apache.log4j.Logger;
import org.testng.AssertJUnit;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-public class TestZKUtil extends ZkUnitTestBase {
+public class TestZKUtil extends ZkTestBase {
private static Logger LOG = Logger.getLogger(TestZKUtil.class);
- String clusterName = CLUSTER_PREFIX + "_" + getShortClassName();
+ String clusterName = "TestZKUtil";
ZkClient _zkClient;
@BeforeClass()
public void beforeClass() throws IOException, Exception {
- _zkClient = new ZkClient(ZK_ADDR);
+ _zkClient = new ZkClient(_zkaddr);
_zkClient.setZkSerializer(new ZNRecordSerializer());
if (_zkClient.exists("/" + clusterName)) {
_zkClient.deleteRecursive("/" + clusterName);
http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/manager/zk/TestZNRecordSizeLimit.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZNRecordSizeLimit.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZNRecordSizeLimit.java
index c47ef6f..e05fd0a 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZNRecordSizeLimit.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZNRecordSizeLimit.java
@@ -26,27 +26,25 @@ import org.apache.helix.HelixException;
import org.apache.helix.HelixProperty;
import org.apache.helix.PropertyKey.Builder;
import org.apache.helix.ZNRecord;
-import org.apache.helix.ZkUnitTestBase;
import org.apache.helix.api.id.StateModelDefId;
import org.apache.helix.model.IdealState;
import org.apache.helix.model.IdealState.RebalanceMode;
import org.apache.helix.model.InstanceConfig;
+import org.apache.helix.testutil.TestUtil;
+import org.apache.helix.testutil.ZkTestBase;
import org.apache.log4j.Logger;
import org.testng.Assert;
import org.testng.annotations.Test;
-public class TestZNRecordSizeLimit extends ZkUnitTestBase {
+public class TestZNRecordSizeLimit extends ZkTestBase {
private static Logger LOG = Logger.getLogger(TestZNRecordSizeLimit.class);
@Test
public void testZNRecordSizeLimitUseZNRecordSerializer() {
- String className = getShortClassName();
+ String className = TestUtil.getTestName();
System.out.println("START testZNRecordSizeLimitUseZNRecordSerializer at "
+ new Date(System.currentTimeMillis()));
- ZNRecordSerializer serializer = new ZNRecordSerializer();
- ZkClient zkClient = new ZkClient(ZK_ADDR);
- zkClient.setZkSerializer(serializer);
String root = className;
byte[] buf = new byte[1024];
for (int i = 0; i < 1024; i++) {
@@ -54,7 +52,7 @@ public class TestZNRecordSizeLimit extends ZkUnitTestBase {
}
String bufStr = new String(buf);
- // test zkClient
+ // test zkclient
// legal-sized data gets written to zk
// write a znode of size less than 1m
final ZNRecord smallRecord = new ZNRecord("normalsize");
@@ -64,10 +62,11 @@ public class TestZNRecordSizeLimit extends ZkUnitTestBase {
}
String path1 = "/" + root + "/test1";
- zkClient.createPersistent(path1, true);
- zkClient.writeData(path1, smallRecord);
+ _zkclient.createPersistent(path1, true);
+ _zkclient.writeData(path1, smallRecord);
- ZNRecord record = zkClient.readData(path1);
+ ZNRecordStreamingSerializer serializer = new ZNRecordStreamingSerializer();
+ ZNRecord record = _zkclient.readData(path1);
Assert.assertTrue(serializer.serialize(record).length > 900 * 1024);
// oversized data doesn't create any data on zk
@@ -78,38 +77,38 @@ public class TestZNRecordSizeLimit extends ZkUnitTestBase {
largeRecord.setSimpleField(i + "", bufStr);
}
String path2 = "/" + root + "/test2";
- zkClient.createPersistent(path2, true);
+ _zkclient.createPersistent(path2, true);
try {
- zkClient.writeData(path2, largeRecord);
+ _zkclient.writeData(path2, largeRecord);
Assert.fail("Should fail because data size is larger than 1M");
} catch (HelixException e) {
// OK
}
- record = zkClient.readData(path2);
+ record = _zkclient.readData(path2);
Assert.assertNull(record);
// oversized write doesn't overwrite existing data on zk
- record = zkClient.readData(path1);
+ record = _zkclient.readData(path1);
try {
- zkClient.writeData(path1, largeRecord);
+ _zkclient.writeData(path1, largeRecord);
Assert.fail("Should fail because data size is larger than 1M");
} catch (HelixException e) {
// OK
}
- ZNRecord recordNew = zkClient.readData(path1);
+ ZNRecord recordNew = _zkclient.readData(path1);
byte[] arr = serializer.serialize(record);
byte[] arrNew = serializer.serialize(recordNew);
Assert.assertTrue(Arrays.equals(arr, arrNew));
// test ZkDataAccessor
- ZKHelixAdmin admin = new ZKHelixAdmin(zkClient);
+ ZKHelixAdmin admin = new ZKHelixAdmin(_zkclient);
admin.addCluster(className, true);
InstanceConfig instanceConfig = new InstanceConfig("localhost_12918");
admin.addInstance(className, instanceConfig);
// oversized data should not create any new data on zk
ZKHelixDataAccessor accessor =
- new ZKHelixDataAccessor(className, new ZkBaseDataAccessor<ZNRecord>(zkClient));
+ new ZKHelixDataAccessor(className, new ZkBaseDataAccessor<ZNRecord>(_zkclient));
Builder keyBuilder = accessor.keyBuilder();
IdealState idealState = new IdealState("currentState");
@@ -163,13 +162,11 @@ public class TestZNRecordSizeLimit extends ZkUnitTestBase {
@Test
public void testZNRecordSizeLimitUseZNRecordStreamingSerializer() {
- String className = getShortClassName();
+ String className = TestUtil.getTestName();
System.out.println("START testZNRecordSizeLimitUseZNRecordStreamingSerializer at "
+ new Date(System.currentTimeMillis()));
ZNRecordStreamingSerializer serializer = new ZNRecordStreamingSerializer();
- ZkClient zkClient = new ZkClient(ZK_ADDR);
- zkClient.setZkSerializer(serializer);
String root = className;
byte[] buf = new byte[1024];
for (int i = 0; i < 1024; i++) {
@@ -177,7 +174,7 @@ public class TestZNRecordSizeLimit extends ZkUnitTestBase {
}
String bufStr = new String(buf);
- // test zkClient
+ // test zkclient
// legal-sized data gets written to zk
// write a znode of size less than 1m
final ZNRecord smallRecord = new ZNRecord("normalsize");
@@ -187,10 +184,10 @@ public class TestZNRecordSizeLimit extends ZkUnitTestBase {
}
String path1 = "/" + root + "/test1";
- zkClient.createPersistent(path1, true);
- zkClient.writeData(path1, smallRecord);
+ _zkclient.createPersistent(path1, true);
+ _zkclient.writeData(path1, smallRecord);
- ZNRecord record = zkClient.readData(path1);
+ ZNRecord record = _zkclient.readData(path1);
Assert.assertTrue(serializer.serialize(record).length > 900 * 1024);
// oversized data doesn't create any data on zk
@@ -201,38 +198,38 @@ public class TestZNRecordSizeLimit extends ZkUnitTestBase {
largeRecord.setSimpleField(i + "", bufStr);
}
String path2 = "/" + root + "/test2";
- zkClient.createPersistent(path2, true);
+ _zkclient.createPersistent(path2, true);
try {
- zkClient.writeData(path2, largeRecord);
+ _zkclient.writeData(path2, largeRecord);
Assert.fail("Should fail because data size is larger than 1M");
} catch (HelixException e) {
// OK
}
- record = zkClient.readData(path2);
+ record = _zkclient.readData(path2);
Assert.assertNull(record);
// oversized write doesn't overwrite existing data on zk
- record = zkClient.readData(path1);
+ record = _zkclient.readData(path1);
try {
- zkClient.writeData(path1, largeRecord);
+ _zkclient.writeData(path1, largeRecord);
Assert.fail("Should fail because data size is larger than 1M");
} catch (HelixException e) {
// OK
}
- ZNRecord recordNew = zkClient.readData(path1);
+ ZNRecord recordNew = _zkclient.readData(path1);
byte[] arr = serializer.serialize(record);
byte[] arrNew = serializer.serialize(recordNew);
Assert.assertTrue(Arrays.equals(arr, arrNew));
// test ZkDataAccessor
- ZKHelixAdmin admin = new ZKHelixAdmin(zkClient);
+ ZKHelixAdmin admin = new ZKHelixAdmin(_zkclient);
admin.addCluster(className, true);
InstanceConfig instanceConfig = new InstanceConfig("localhost_12918");
admin.addInstance(className, instanceConfig);
// oversized data should not create any new data on zk
ZKHelixDataAccessor accessor =
- new ZKHelixDataAccessor(className, new ZkBaseDataAccessor<ZNRecord>(zkClient));
+ new ZKHelixDataAccessor(className, new ZkBaseDataAccessor<ZNRecord>(_zkclient));
Builder keyBuilder = accessor.keyBuilder();
// ZNRecord statusUpdates = new ZNRecord("statusUpdates");
http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkBaseDataAccessor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkBaseDataAccessor.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkBaseDataAccessor.java
index 66c069f..0f2bf2d 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkBaseDataAccessor.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkBaseDataAccessor.java
@@ -25,20 +25,19 @@ import java.util.List;
import org.I0Itec.zkclient.DataUpdater;
import org.apache.helix.AccessOption;
-import org.apache.helix.BaseDataAccessor;
import org.apache.helix.PropertyPathConfig;
import org.apache.helix.PropertyType;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.ZNRecordUpdater;
-import org.apache.helix.ZkUnitTestBase;
import org.apache.helix.manager.zk.ZkBaseDataAccessor.AccessResult;
import org.apache.helix.manager.zk.ZkBaseDataAccessor.RetCode;
+import org.apache.helix.testutil.ZkTestBase;
import org.apache.zookeeper.data.Stat;
import org.testng.Assert;
import org.testng.annotations.Test;
-public class TestZkBaseDataAccessor extends ZkUnitTestBase {
+public class TestZkBaseDataAccessor extends ZkTestBase {
@Test
public void testSyncSet() {
@@ -50,11 +49,10 @@ public class TestZkBaseDataAccessor extends ZkUnitTestBase {
String path = String.format("/%s/%s", testName, "msg_0");
ZNRecord record = new ZNRecord("msg_0");
- BaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
- boolean success = accessor.set(path, record, AccessOption.PERSISTENT);
+ boolean success = _baseAccessor.set(path, record, AccessOption.PERSISTENT);
Assert.assertTrue(success);
- ZNRecord getRecord = _gZkClient.readData(path);
+ ZNRecord getRecord = _zkclient.readData(path);
Assert.assertNotNull(getRecord);
Assert.assertEquals(getRecord.getId(), "msg_0");
@@ -72,46 +70,45 @@ public class TestZkBaseDataAccessor extends ZkUnitTestBase {
String path = String.format("/%s/%s", testName, "msg_0");
ZNRecord record = new ZNRecord("msg_0");
- BaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
// set persistent
- boolean success = accessor.set(path, record, 0, AccessOption.PERSISTENT);
+ boolean success = _baseAccessor.set(path, record, 0, AccessOption.PERSISTENT);
Assert.assertFalse(success, "Should fail since version not match");
try {
- _gZkClient.readData(path, false);
+ _zkclient.readData(path, false);
Assert.fail("Should get no node exception");
} catch (Exception e) {
// OK
}
- success = accessor.set(path, record, -1, AccessOption.PERSISTENT);
+ success = _baseAccessor.set(path, record, -1, AccessOption.PERSISTENT);
Assert.assertTrue(success);
- ZNRecord getRecord = _gZkClient.readData(path);
+ ZNRecord getRecord = _zkclient.readData(path);
Assert.assertNotNull(getRecord);
Assert.assertEquals(getRecord.getId(), "msg_0");
// set ephemeral
path = String.format("/%s/%s", testName, "msg_1");
record = new ZNRecord("msg_1");
- success = accessor.set(path, record, 0, AccessOption.EPHEMERAL);
+ success = _baseAccessor.set(path, record, 0, AccessOption.EPHEMERAL);
Assert.assertFalse(success);
try {
- _gZkClient.readData(path, false);
+ _zkclient.readData(path, false);
Assert.fail("Should get no node exception");
} catch (Exception e) {
// OK
}
- success = accessor.set(path, record, -1, AccessOption.EPHEMERAL);
+ success = _baseAccessor.set(path, record, -1, AccessOption.EPHEMERAL);
Assert.assertTrue(success);
- getRecord = _gZkClient.readData(path);
+ getRecord = _zkclient.readData(path);
Assert.assertNotNull(getRecord);
Assert.assertEquals(getRecord.getId(), "msg_1");
record.setSimpleField("key0", "value0");
- success = accessor.set(path, record, 0, AccessOption.PERSISTENT);
+ success = _baseAccessor.set(path, record, 0, AccessOption.PERSISTENT);
Assert.assertTrue(success, "Should pass. AccessOption.PERSISTENT is ignored");
- getRecord = _gZkClient.readData(path);
+ getRecord = _zkclient.readData(path);
Assert.assertNotNull(getRecord);
Assert.assertEquals(getRecord.getSimpleFields().size(), 1);
Assert.assertNotNull(getRecord.getSimpleField("key0"));
@@ -130,7 +127,7 @@ public class TestZkBaseDataAccessor extends ZkUnitTestBase {
String path = String.format("/%s/%s/%s", testName, "msg_0", "submsg_0");
ZNRecord record = new ZNRecord("submsg_0");
- ZkBaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+ ZkBaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
AccessResult result = accessor.doSet(path, record, -1, AccessOption.PERSISTENT);
Assert.assertEquals(result._retCode, RetCode.OK);
@@ -139,9 +136,9 @@ public class TestZkBaseDataAccessor extends ZkUnitTestBase {
Assert.assertTrue(result._pathCreated.contains(String.format("/%s/%s", testName, "msg_0")));
Assert.assertTrue(result._pathCreated.contains(path));
- Assert.assertTrue(_gZkClient.exists(String.format("/%s", testName)));
- Assert.assertTrue(_gZkClient.exists(String.format("/%s/%s", testName, "msg_0")));
- ZNRecord getRecord = _gZkClient.readData(path);
+ Assert.assertTrue(_zkclient.exists(String.format("/%s", testName)));
+ Assert.assertTrue(_zkclient.exists(String.format("/%s/%s", testName, "msg_0")));
+ ZNRecord getRecord = _zkclient.readData(path);
Assert.assertNotNull(getRecord);
Assert.assertEquals(getRecord.getId(), "submsg_0");
@@ -158,18 +155,18 @@ public class TestZkBaseDataAccessor extends ZkUnitTestBase {
String path = String.format("/%s/%s", testName, "msg_0");
ZNRecord record = new ZNRecord("msg_0");
- ZkBaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+ ZkBaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
boolean success = accessor.create(path, record, AccessOption.PERSISTENT);
Assert.assertTrue(success);
- ZNRecord getRecord = _gZkClient.readData(path);
+ ZNRecord getRecord = _zkclient.readData(path);
Assert.assertNotNull(getRecord);
Assert.assertEquals(getRecord.getId(), "msg_0");
record.setSimpleField("key0", "value0");
success = accessor.create(path, record, AccessOption.PERSISTENT);
Assert.assertFalse(success, "Should fail since node already exists");
- getRecord = _gZkClient.readData(path);
+ getRecord = _zkclient.readData(path);
Assert.assertNotNull(getRecord);
Assert.assertEquals(getRecord.getSimpleFields().size(), 0);
@@ -186,18 +183,18 @@ public class TestZkBaseDataAccessor extends ZkUnitTestBase {
String path = String.format("/%s/%s", testName, "msg_0");
ZNRecord record = new ZNRecord("msg_0");
- ZkBaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+ ZkBaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
boolean success = accessor.update(path, new ZNRecordUpdater(record), AccessOption.PERSISTENT);
Assert.assertTrue(success);
- ZNRecord getRecord = _gZkClient.readData(path);
+ ZNRecord getRecord = _zkclient.readData(path);
Assert.assertNotNull(getRecord);
Assert.assertEquals(getRecord.getId(), "msg_0");
record.setSimpleField("key0", "value0");
success = accessor.update(path, new ZNRecordUpdater(record), AccessOption.PERSISTENT);
Assert.assertTrue(success);
- getRecord = _gZkClient.readData(path);
+ getRecord = _zkclient.readData(path);
Assert.assertNotNull(getRecord);
Assert.assertEquals(getRecord.getSimpleFields().size(), 1);
Assert.assertNotNull(getRecord.getSimpleField("key0"));
@@ -212,7 +209,7 @@ public class TestZkBaseDataAccessor extends ZkUnitTestBase {
}
}, AccessOption.PERSISTENT);
Assert.assertFalse(success);
- getRecord = _gZkClient.readData(path);
+ getRecord = _zkclient.readData(path);
Assert.assertNotNull(getRecord);
Assert.assertEquals(getRecord.getSimpleFields().size(), 1);
@@ -229,20 +226,20 @@ public class TestZkBaseDataAccessor extends ZkUnitTestBase {
String path = String.format("/%s/%s", testName, "msg_0");
ZNRecord record = new ZNRecord("msg_0");
- ZkBaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+ ZkBaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
boolean success = accessor.remove(path, 0);
Assert.assertFalse(success);
success = accessor.create(path, record, AccessOption.PERSISTENT);
Assert.assertTrue(success);
- ZNRecord getRecord = _gZkClient.readData(path);
+ ZNRecord getRecord = _zkclient.readData(path);
Assert.assertNotNull(getRecord);
Assert.assertEquals(getRecord.getId(), "msg_0");
success = accessor.remove(path, 0);
Assert.assertTrue(success);
- Assert.assertFalse(_gZkClient.exists(path));
+ Assert.assertFalse(_zkclient.exists(path));
System.out.println("END " + testName + " at " + new Date(System.currentTimeMillis()));
}
@@ -257,7 +254,7 @@ public class TestZkBaseDataAccessor extends ZkUnitTestBase {
String path = String.format("/%s/%s", testName, "msg_0");
ZNRecord record = new ZNRecord("msg_0");
- ZkBaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+ ZkBaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
Stat stat = new Stat();
ZNRecord getRecord = accessor.get(path, stat, 0);
@@ -316,7 +313,7 @@ public class TestZkBaseDataAccessor extends ZkUnitTestBase {
String path = String.format("/%s/%s", testName, "msg_0");
ZNRecord record = new ZNRecord("msg_0");
- ZkBaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+ ZkBaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
boolean success = accessor.exists(path, 0);
Assert.assertFalse(success);
@@ -341,7 +338,7 @@ public class TestZkBaseDataAccessor extends ZkUnitTestBase {
String path = String.format("/%s/%s", testName, "msg_0");
ZNRecord record = new ZNRecord("msg_0");
- ZkBaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+ ZkBaseDataAccessor<ZNRecord> accessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
Stat stat = accessor.getStat(path, 0);
Assert.assertNull(stat);
@@ -364,7 +361,7 @@ public class TestZkBaseDataAccessor extends ZkUnitTestBase {
+ new Date(System.currentTimeMillis()));
String root = "TestZkBaseDataAccessor_asyn";
- ZkClient zkClient = new ZkClient(ZK_ADDR);
+ ZkClient zkClient = new ZkClient(_zkaddr);
zkClient.setZkSerializer(new ZNRecordSerializer());
zkClient.deleteRecursive("/" + root);
http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkCacheAsyncOpSingleThread.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkCacheAsyncOpSingleThread.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkCacheAsyncOpSingleThread.java
index ed84719..08a6381 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkCacheAsyncOpSingleThread.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkCacheAsyncOpSingleThread.java
@@ -31,11 +31,11 @@ import org.apache.helix.PropertyType;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.ZNRecordUpdater;
-import org.apache.helix.ZkUnitTestBase;
+import org.apache.helix.testutil.ZkTestBase;
import org.testng.Assert;
import org.testng.annotations.Test;
-public class TestZkCacheAsyncOpSingleThread extends ZkUnitTestBase {
+public class TestZkCacheAsyncOpSingleThread extends ZkTestBase {
@Test
public void testHappyPathExtOpZkCacheBaseDataAccessor() throws Exception {
String className = TestHelper.getTestClassName();
@@ -44,7 +44,7 @@ public class TestZkCacheAsyncOpSingleThread extends ZkUnitTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
// init external base data accessor
- ZkClient extZkclient = new ZkClient(ZK_ADDR);
+ ZkClient extZkclient = new ZkClient(_zkaddr);
extZkclient.setZkSerializer(new ZNRecordSerializer());
ZkBaseDataAccessor<ZNRecord> extBaseAccessor = new ZkBaseDataAccessor<ZNRecord>(extZkclient);
@@ -53,7 +53,7 @@ public class TestZkCacheAsyncOpSingleThread extends ZkUnitTestBase {
PropertyPathConfig.getPath(PropertyType.CURRENTSTATES, clusterName, "localhost_8901");
String extViewPath = PropertyPathConfig.getPath(PropertyType.EXTERNALVIEW, clusterName);
- ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+ ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
extBaseAccessor.create(curStatePath, null, AccessOption.PERSISTENT);
@@ -63,7 +63,7 @@ public class TestZkCacheAsyncOpSingleThread extends ZkUnitTestBase {
// TestHelper.printCache(accessor._zkCache);
boolean ret =
- TestHelper.verifyZkCache(zkCacheInitPaths, accessor._zkCache._cache, _gZkClient, true);
+ TestHelper.verifyZkCache(zkCacheInitPaths, accessor._zkCache._cache, _zkclient, true);
Assert.assertTrue(ret, "zkCache doesn't match data on Zk");
// create 10 current states using external base accessor
@@ -88,7 +88,7 @@ public class TestZkCacheAsyncOpSingleThread extends ZkUnitTestBase {
// verify wtCache
for (int i = 0; i < 10; i++) {
// TestHelper.printCache(accessor._zkCache);
- ret = TestHelper.verifyZkCache(zkCacheInitPaths, accessor._zkCache._cache, _gZkClient, true);
+ ret = TestHelper.verifyZkCache(zkCacheInitPaths, accessor._zkCache._cache, _zkclient, true);
if (ret == true)
break;
Thread.sleep(100);
@@ -122,7 +122,7 @@ public class TestZkCacheAsyncOpSingleThread extends ZkUnitTestBase {
// verify cache
// TestHelper.printCache(accessor._zkCache);
- ret = TestHelper.verifyZkCache(zkCacheInitPaths, accessor._zkCache._cache, _gZkClient, true);
+ ret = TestHelper.verifyZkCache(zkCacheInitPaths, accessor._zkCache._cache, _zkclient, true);
Assert.assertTrue(ret, "zkCache doesn't match data on Zk");
// set 10 external views by external accessor
@@ -146,7 +146,7 @@ public class TestZkCacheAsyncOpSingleThread extends ZkUnitTestBase {
// verify cache
// TestHelper.printCache(accessor._zkCache._cache);
- ret = TestHelper.verifyZkCache(zkCacheInitPaths, accessor._zkCache._cache, _gZkClient, true);
+ ret = TestHelper.verifyZkCache(zkCacheInitPaths, accessor._zkCache._cache, _zkclient, true);
Assert.assertTrue(ret, "zkCache doesn't match data on Zk");
// remove 10 external views by external accessor
@@ -167,7 +167,7 @@ public class TestZkCacheAsyncOpSingleThread extends ZkUnitTestBase {
// verify cache
// TestHelper.printCache(accessor._zkCache._cache);
- ret = TestHelper.verifyZkCache(zkCacheInitPaths, accessor._zkCache._cache, _gZkClient, true);
+ ret = TestHelper.verifyZkCache(zkCacheInitPaths, accessor._zkCache._cache, _zkclient, true);
Assert.assertTrue(ret, "zkCache doesn't match data on Zk");
// clean up
@@ -188,7 +188,7 @@ public class TestZkCacheAsyncOpSingleThread extends ZkUnitTestBase {
PropertyPathConfig.getPath(PropertyType.CURRENTSTATES, clusterName, "localhost_8901");
String extViewPath = PropertyPathConfig.getPath(PropertyType.EXTERNALVIEW, clusterName);
- ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+ ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
baseAccessor.create(curStatePath, null, AccessOption.PERSISTENT);
@@ -198,7 +198,7 @@ public class TestZkCacheAsyncOpSingleThread extends ZkUnitTestBase {
// TestHelper.printCache(accessor._zkCache._cache);
boolean ret =
- TestHelper.verifyZkCache(zkCacheInitPaths, accessor._zkCache._cache, _gZkClient, true);
+ TestHelper.verifyZkCache(zkCacheInitPaths, accessor._zkCache._cache, _zkclient, true);
Assert.assertTrue(ret, "zkCache doesn't match data on Zk");
// create 10 current states using this accessor
@@ -221,7 +221,7 @@ public class TestZkCacheAsyncOpSingleThread extends ZkUnitTestBase {
// verify cache
// TestHelper.printCache(accessor._zkCache._cache);
- ret = TestHelper.verifyZkCache(zkCacheInitPaths, accessor._zkCache._cache, _gZkClient, false);
+ ret = TestHelper.verifyZkCache(zkCacheInitPaths, accessor._zkCache._cache, _zkclient, false);
Assert.assertTrue(ret, "zkCache doesn't match data on Zk");
// update each current state 10 times by this accessor
@@ -248,8 +248,8 @@ public class TestZkCacheAsyncOpSingleThread extends ZkUnitTestBase {
// TestHelper.printCache(accessor._zkCache._cache);
ret =
TestHelper.verifyZkCache(zkCacheInitPaths, zkCacheInitPaths, accessor._zkCache._cache,
- _gZkClient, true);
- // ret = TestHelper.verifyZkCache(zkCacheInitPaths, accessor, _gZkClient, true);
+ _zkclient, true);
+ // ret = TestHelper.verifyZkCache(zkCacheInitPaths, accessor, zkclient, true);
// System.out.println("ret: " + ret);
Assert.assertTrue(ret, "zkCache doesn't match data on Zk");
@@ -274,7 +274,7 @@ public class TestZkCacheAsyncOpSingleThread extends ZkUnitTestBase {
// verify cache
// TestHelper.printCache(accessor._zkCache._cache);
- ret = TestHelper.verifyZkCache(zkCacheInitPaths, accessor._zkCache._cache, _gZkClient, true);
+ ret = TestHelper.verifyZkCache(zkCacheInitPaths, accessor._zkCache._cache, _zkclient, true);
// System.out.println("ret: " + ret);
Assert.assertTrue(ret, "zkCache doesn't match data on Zk");
http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkCacheSyncOpSingleThread.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkCacheSyncOpSingleThread.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkCacheSyncOpSingleThread.java
index 985a82f..b882c91 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkCacheSyncOpSingleThread.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkCacheSyncOpSingleThread.java
@@ -34,12 +34,12 @@ import org.apache.helix.PropertyType;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.ZNRecordUpdater;
-import org.apache.helix.ZkUnitTestBase;
import org.apache.helix.store.HelixPropertyListener;
+import org.apache.helix.testutil.ZkTestBase;
import org.testng.Assert;
import org.testng.annotations.Test;
-public class TestZkCacheSyncOpSingleThread extends ZkUnitTestBase {
+public class TestZkCacheSyncOpSingleThread extends ZkTestBase {
class TestListener implements HelixPropertyListener {
ConcurrentLinkedQueue<String> _deletePathQueue = new ConcurrentLinkedQueue<String>();
ConcurrentLinkedQueue<String> _createPathQueue = new ConcurrentLinkedQueue<String>();
@@ -78,7 +78,7 @@ public class TestZkCacheSyncOpSingleThread extends ZkUnitTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
// init external base data accessor
- ZkClient zkclient = new ZkClient(ZK_ADDR);
+ ZkClient zkclient = new ZkClient(_zkaddr);
zkclient.setZkSerializer(new ZNRecordSerializer());
ZkBaseDataAccessor<ZNRecord> extBaseAccessor = new ZkBaseDataAccessor<ZNRecord>(zkclient);
@@ -87,7 +87,7 @@ public class TestZkCacheSyncOpSingleThread extends ZkUnitTestBase {
PropertyPathConfig.getPath(PropertyType.CURRENTSTATES, clusterName, "localhost_8901");
String extViewPath = PropertyPathConfig.getPath(PropertyType.EXTERNALVIEW, clusterName);
- ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+ ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(zkclient);
extBaseAccessor.create(curStatePath, null, AccessOption.PERSISTENT);
@@ -113,7 +113,7 @@ public class TestZkCacheSyncOpSingleThread extends ZkUnitTestBase {
// verify cache
// TestHelper.printCache(accessor._zkCache._cache);
- boolean ret = TestHelper.verifyZkCache(cachePaths, accessor._zkCache._cache, _gZkClient, true);
+ boolean ret = TestHelper.verifyZkCache(cachePaths, accessor._zkCache._cache, zkclient, true);
// System.out.println("ret: " + ret);
Assert.assertTrue(ret, "zkCache doesn't match data on Zk");
System.out.println("createCnt: " + listener._createPathQueue.size());
@@ -146,7 +146,7 @@ public class TestZkCacheSyncOpSingleThread extends ZkUnitTestBase {
// verify cache
// TestHelper.printCache(accessor._zkCache._cache);
- ret = TestHelper.verifyZkCache(cachePaths, accessor._zkCache._cache, _gZkClient, true);
+ ret = TestHelper.verifyZkCache(cachePaths, accessor._zkCache._cache, zkclient, true);
// System.out.println("ret: " + ret);
Assert.assertTrue(ret, "zkCache doesn't match data on Zk");
System.out.println("changeCnt: " + listener._changePathQueue.size());
@@ -172,7 +172,7 @@ public class TestZkCacheSyncOpSingleThread extends ZkUnitTestBase {
// verify cache
// TestHelper.printCache(accessor._zkCache._cache);
- ret = TestHelper.verifyZkCache(cachePaths, accessor._zkCache._cache, _gZkClient, true);
+ ret = TestHelper.verifyZkCache(cachePaths, accessor._zkCache._cache, zkclient, true);
// System.out.println("ret: " + ret);
Assert.assertTrue(ret, "zkCache doesn't match data on Zk");
System.out.println("deleteCnt: " + listener._deletePathQueue.size());
http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkClusterManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkClusterManager.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkClusterManager.java
index bcab38e..0a770d0 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkClusterManager.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkClusterManager.java
@@ -31,6 +31,7 @@ import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.model.ConfigScope;
import org.apache.helix.model.HelixConfigScope;
import org.apache.helix.model.HelixConfigScope.ConfigScopeProperty;
+import org.apache.helix.model.InstanceConfig;
import org.apache.helix.model.builder.ConfigScopeBuilder;
import org.apache.helix.model.builder.HelixConfigScopeBuilder;
import org.apache.helix.HelixAdmin;
@@ -42,31 +43,32 @@ import org.apache.helix.PropertyKey.Builder;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.ZkTestHelper;
-import org.apache.helix.ZkUnitTestBase;
import org.apache.helix.manager.MockListener;
import org.apache.helix.model.LiveInstance;
import org.apache.helix.store.zk.ZkHelixPropertyStore;
+import org.apache.helix.testutil.TestUtil;
+import org.apache.helix.testutil.ZkTestBase;
import org.apache.zookeeper.data.Stat;
import org.testng.Assert;
import org.testng.AssertJUnit;
import org.testng.annotations.Test;
-public class TestZkClusterManager extends ZkUnitTestBase {
- final String className = getShortClassName();
+public class TestZkClusterManager extends ZkTestBase {
@Test()
public void testController() throws Exception {
- System.out.println("START " + className + ".testController() at "
+ final String clusterName = TestUtil.getTestName();
+
+ System.out.println("START " + clusterName + ".testController() at "
+ new Date(System.currentTimeMillis()));
- final String clusterName = CLUSTER_PREFIX + "_" + className + "_controller";
// basic test
- if (_gZkClient.exists("/" + clusterName)) {
- _gZkClient.deleteRecursive("/" + clusterName);
+ if (_zkclient.exists("/" + clusterName)) {
+ _zkclient.deleteRecursive("/" + clusterName);
}
ZKHelixManager controller =
- new ZKHelixManager(clusterName, null, InstanceType.CONTROLLER, ZK_ADDR);
+ new ZKHelixManager(clusterName, null, InstanceType.CONTROLLER, _zkaddr);
try {
controller.connect();
@@ -75,7 +77,7 @@ public class TestZkClusterManager extends ZkUnitTestBase {
// OK
}
- TestHelper.setupEmptyCluster(_gZkClient, clusterName);
+ TestHelper.setupEmptyCluster(_zkclient, clusterName);
controller.connect();
AssertJUnit.assertTrue(controller.isConnected());
@@ -112,15 +114,15 @@ public class TestZkClusterManager extends ZkUnitTestBase {
controller.disconnect();
AssertJUnit.assertFalse(controller.isConnected());
- System.out.println("END " + className + ".testController() at "
+ System.out.println("END " + clusterName + ".testController() at "
+ new Date(System.currentTimeMillis()));
}
@Test
public void testLiveInstanceInfoProvider() throws Exception {
- System.out.println("START " + className + ".testLiveInstanceInfoProvider() at "
+ final String clusterName = TestUtil.getTestName();
+ System.out.println("START " + clusterName + ".testLiveInstanceInfoProvider() at "
+ new Date(System.currentTimeMillis()));
- final String clusterName = CLUSTER_PREFIX + "_" + className + "_liveInstanceInfoProvider";
class provider implements LiveInstanceInfoProvider {
boolean _flag = false;
@@ -151,7 +153,7 @@ public class TestZkClusterManager extends ZkUnitTestBase {
}
}
- TestHelper.setupEmptyCluster(_gZkClient, clusterName);
+ TestHelper.setupEmptyCluster(_zkclient, clusterName);
int[] ids = {
0, 1, 2, 3, 4, 5
};
@@ -159,7 +161,7 @@ public class TestZkClusterManager extends ZkUnitTestBase {
// ///////////////////
ZKHelixManager manager =
- new ZKHelixManager(clusterName, "localhost_0", InstanceType.PARTICIPANT, ZK_ADDR);
+ new ZKHelixManager(clusterName, "localhost_0", InstanceType.PARTICIPANT, _zkaddr);
manager.connect();
HelixDataAccessor accessor = manager.getHelixDataAccessor();
@@ -169,7 +171,7 @@ public class TestZkClusterManager extends ZkUnitTestBase {
Assert.assertTrue(liveInstance.getRecord().getMapFields().size() == 0);
Assert.assertTrue(liveInstance.getRecord().getSimpleFields().size() == 3);
- manager = new ZKHelixManager(clusterName, "localhost_1", InstanceType.PARTICIPANT, ZK_ADDR);
+ manager = new ZKHelixManager(clusterName, "localhost_1", InstanceType.PARTICIPANT, _zkaddr);
manager.setLiveInstanceInfoProvider(new provider(false));
manager.connect();
@@ -180,7 +182,7 @@ public class TestZkClusterManager extends ZkUnitTestBase {
Assert.assertTrue(liveInstance.getRecord().getMapFields().size() == 1);
Assert.assertTrue(liveInstance.getRecord().getSimpleFields().size() == 4);
- manager = new ZKHelixManager(clusterName, "localhost_2", InstanceType.PARTICIPANT, ZK_ADDR);
+ manager = new ZKHelixManager(clusterName, "localhost_2", InstanceType.PARTICIPANT, _zkaddr);
manager.setLiveInstanceInfoProvider(new provider(true));
manager.connect();
@@ -196,7 +198,7 @@ public class TestZkClusterManager extends ZkUnitTestBase {
// //////////////////////////////////
MockParticipantManager manager2 =
- new MockParticipantManager(ZK_ADDR, clusterName, "localhost_3");
+ new MockParticipantManager(_zkaddr, clusterName, "localhost_3");
manager2.setLiveInstanceInfoProvider(new provider(true));
@@ -222,25 +224,25 @@ public class TestZkClusterManager extends ZkUnitTestBase {
Assert.assertFalse(liveInstance.getLiveInstance().equals("value"));
Assert.assertFalse(sessionId.equals(liveInstance.getTypedSessionId().stringify()));
- System.out.println("END " + className + ".testLiveInstanceInfoProvider() at "
+ System.out.println("END " + clusterName + ".testLiveInstanceInfoProvider() at "
+ new Date(System.currentTimeMillis()));
}
@Test()
public void testAdministrator() throws Exception {
- System.out.println("START " + className + ".testAdministrator() at "
+ final String clusterName = TestUtil.getTestName();
+ System.out.println("START " + clusterName + ".testAdministrator() at "
+ new Date(System.currentTimeMillis()));
- final String clusterName = CLUSTER_PREFIX + "_" + className + "_admin";
// basic test
- if (_gZkClient.exists("/" + clusterName)) {
- _gZkClient.deleteRecursive("/" + clusterName);
+ if (_zkclient.exists("/" + clusterName)) {
+ _zkclient.deleteRecursive("/" + clusterName);
}
ZKHelixManager admin =
- new ZKHelixManager(clusterName, null, InstanceType.ADMINISTRATOR, ZK_ADDR);
+ new ZKHelixManager(clusterName, null, InstanceType.ADMINISTRATOR, _zkaddr);
- TestHelper.setupEmptyCluster(_gZkClient, clusterName);
+ TestHelper.setupEmptyCluster(_zkclient, clusterName);
admin.connect();
AssertJUnit.assertTrue(admin.isConnected());
@@ -263,7 +265,19 @@ public class TestZkClusterManager extends ZkUnitTestBase {
admin.disconnect();
AssertJUnit.assertFalse(admin.isConnected());
- System.out.println("END " + className + ".testAdministrator() at "
+ System.out.println("END " + clusterName + ".testAdministrator() at "
+ new Date(System.currentTimeMillis()));
}
+
+ private void setupInstances(String clusterName, int[] instances) {
+ HelixAdmin admin = new ZKHelixAdmin(_zkclient);
+ 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);
+ admin.addInstance(clusterName, instanceConfig);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkFlapping.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkFlapping.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkFlapping.java
index 79c74f5..6a5f002 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkFlapping.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkFlapping.java
@@ -31,15 +31,15 @@ import org.apache.helix.HelixDataAccessor;
import org.apache.helix.TestHelper;
import org.apache.helix.TestHelper.Verifier;
import org.apache.helix.ZkTestHelper;
-import org.apache.helix.ZkUnitTestBase;
import org.apache.helix.integration.manager.ClusterControllerManager;
import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.model.LiveInstance;
+import org.apache.helix.testutil.ZkTestBase;
import org.apache.zookeeper.Watcher.Event.KeeperState;
import org.testng.Assert;
import org.testng.annotations.Test;
-public class TestZkFlapping extends ZkUnitTestBase {
+public class TestZkFlapping extends ZkTestBase {
@Test
public void testZkSessionExpiry() throws Exception {
@@ -49,7 +49,7 @@ public class TestZkFlapping extends ZkUnitTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
ZkClient client =
- new ZkClient(ZK_ADDR, ZkClient.DEFAULT_SESSION_TIMEOUT,
+ new ZkClient(_zkaddr, ZkClient.DEFAULT_SESSION_TIMEOUT,
ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer());
String path = String.format("/%s", clusterName);
@@ -71,13 +71,13 @@ public class TestZkFlapping extends ZkUnitTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
ZkClient client =
- new ZkClient(ZK_ADDR, ZkClient.DEFAULT_SESSION_TIMEOUT,
+ new ZkClient(_zkaddr, ZkClient.DEFAULT_SESSION_TIMEOUT,
ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer());
String path = String.format("/%s", clusterName);
client.createEphemeral(path);
client.close();
- Assert.assertFalse(_gZkClient.exists(path), "Ephemeral node: " + path
+ Assert.assertFalse(_zkclient.exists(path), "Ephemeral node: " + path
+ " should be removed after ZkClient#close()");
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
@@ -91,7 +91,7 @@ public class TestZkFlapping extends ZkUnitTestBase {
final CountDownLatch waitCallback = new CountDownLatch(1);
final ZkClient client =
- new ZkClient(ZK_ADDR, ZkClient.DEFAULT_SESSION_TIMEOUT,
+ new ZkClient(_zkaddr, ZkClient.DEFAULT_SESSION_TIMEOUT,
ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer());
String path = String.format("/%s", clusterName);
client.createEphemeral(path);
@@ -110,7 +110,7 @@ public class TestZkFlapping extends ZkUnitTestBase {
client.writeData(path, new ZNRecord("test"));
waitCallback.await();
- Assert.assertFalse(_gZkClient.exists(path), "Ephemeral node: " + path
+ Assert.assertFalse(_zkclient.exists(path), "Ephemeral node: " + path
+ " should be removed after ZkClient#close() in its own event-thread");
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
@@ -138,12 +138,12 @@ public class TestZkFlapping extends ZkUnitTestBase {
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
final HelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
+ new ZKHelixDataAccessor(clusterName, _baseAccessor);
final PropertyKey.Builder keyBuilder = accessor.keyBuilder();
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
@@ -154,7 +154,7 @@ public class TestZkFlapping extends ZkUnitTestBase {
final String instanceName = "localhost_12918";
MockParticipantManager participant =
- new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ new MockParticipantManager(_zkaddr, clusterName, instanceName);
participant.syncStart();
final ZkClient client = participant.getZkClient();
@@ -218,12 +218,12 @@ public class TestZkFlapping extends ZkUnitTestBase {
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
final HelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
+ new ZKHelixDataAccessor(clusterName, _baseAccessor);
final PropertyKey.Builder keyBuilder = accessor.keyBuilder();
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
@@ -233,7 +233,7 @@ public class TestZkFlapping extends ZkUnitTestBase {
"MasterSlave", false);
ClusterControllerManager controller =
- new ClusterControllerManager(ZK_ADDR, clusterName, "controller");
+ new ClusterControllerManager(_zkaddr, clusterName, "controller");
controller.syncStart();
final ZkClient client = controller.getZkClient();
http://git-wip-us.apache.org/repos/asf/helix/blob/410815d0/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixAdmin.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixAdmin.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixAdmin.java
index d3925be..8ade0af 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixAdmin.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkHelixAdmin.java
@@ -34,7 +34,6 @@ 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.ConstraintId;
import org.apache.helix.model.ClusterConstraints;
import org.apache.helix.model.ClusterConstraints.ConstraintAttribute;
@@ -48,39 +47,41 @@ import org.apache.helix.model.InstanceConfig;
import org.apache.helix.model.StateModelDefinition;
import org.apache.helix.model.builder.ConstraintItemBuilder;
import org.apache.helix.model.builder.HelixConfigScopeBuilder;
+import org.apache.helix.testutil.TestUtil;
+import org.apache.helix.testutil.ZkTestBase;
import org.apache.helix.tools.StateModelConfigGenerator;
import org.apache.zookeeper.data.Stat;
import org.testng.Assert;
import org.testng.AssertJUnit;
import org.testng.annotations.Test;
-public class TestZkHelixAdmin extends ZkUnitTestBase {
+public class TestZkHelixAdmin extends ZkTestBase {
@Test()
public void testZkHelixAdmin() {
System.out.println("START testZkHelixAdmin at " + new Date(System.currentTimeMillis()));
- final String clusterName = getShortClassName();
+ final String clusterName = TestUtil.getTestName();
String rootPath = "/" + clusterName;
- if (_gZkClient.exists(rootPath)) {
- _gZkClient.deleteRecursive(rootPath);
+ if (_zkclient.exists(rootPath)) {
+ _zkclient.deleteRecursive(rootPath);
}
- HelixAdmin tool = new ZKHelixAdmin(_gZkClient);
+ HelixAdmin tool = new ZKHelixAdmin(_zkclient);
tool.addCluster(clusterName, true);
- Assert.assertTrue(ZKUtil.isClusterSetup(clusterName, _gZkClient));
+ Assert.assertTrue(ZKUtil.isClusterSetup(clusterName, _zkclient));
tool.addCluster(clusterName, true);
- Assert.assertTrue(ZKUtil.isClusterSetup(clusterName, _gZkClient));
+ Assert.assertTrue(ZKUtil.isClusterSetup(clusterName, _zkclient));
List<String> list = tool.getClusters();
AssertJUnit.assertTrue(list.size() > 0);
try {
- Stat oldstat = _gZkClient.getStat(rootPath);
+ Stat oldstat = _zkclient.getStat(rootPath);
Assert.assertNotNull(oldstat);
boolean success = tool.addCluster(clusterName, false);
// Even though it exists, it should return true but it should not make any changes in zk
Assert.assertTrue(success);
- Stat newstat = _gZkClient.getStat(rootPath);
+ Stat newstat = _zkclient.getStat(rootPath);
Assert.assertEquals(oldstat, newstat);
} catch (HelixException e) {
// OK
@@ -92,7 +93,7 @@ public class TestZkHelixAdmin extends ZkUnitTestBase {
tool.addInstance(clusterName, config);
tool.enableInstance(clusterName, "host1_9999", true);
String path = PropertyPathConfig.getPath(PropertyType.INSTANCES, clusterName, "host1_9999");
- AssertJUnit.assertTrue(_gZkClient.exists(path));
+ AssertJUnit.assertTrue(_zkclient.exists(path));
try {
tool.addInstance(clusterName, config);
@@ -126,7 +127,7 @@ public class TestZkHelixAdmin extends ZkUnitTestBase {
try {
tool.addStateModelDef(clusterName, "id1", new StateModelDefinition(stateModelRecord));
path = PropertyPathConfig.getPath(PropertyType.STATEMODELDEFS, clusterName, "id1");
- AssertJUnit.assertTrue(_gZkClient.exists(path));
+ AssertJUnit.assertTrue(_zkclient.exists(path));
Assert.fail("should fail");
} catch (HelixException e) {
// OK
@@ -208,9 +209,9 @@ public class TestZkHelixAdmin extends ZkUnitTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
- HelixAdmin tool = new ZKHelixAdmin(_gZkClient);
+ HelixAdmin tool = new ZKHelixAdmin(_zkclient);
tool.addCluster(clusterName, true);
- Assert.assertTrue(ZKUtil.isClusterSetup(clusterName, _gZkClient), "Cluster should be setup");
+ Assert.assertTrue(ZKUtil.isClusterSetup(clusterName, _zkclient), "Cluster should be setup");
tool.addStateModelDef(clusterName, "MasterSlave", new StateModelDefinition(
StateModelConfigGenerator.generateConfigForMasterSlave()));
@@ -221,15 +222,15 @@ public class TestZkHelixAdmin extends ZkUnitTestBase {
.forCluster(clusterName).forResource("test-db").build(), resourceConfig);
PropertyKey.Builder keyBuilder = new PropertyKey.Builder(clusterName);
- Assert.assertTrue(_gZkClient.exists(keyBuilder.idealStates("test-db").getPath()),
+ Assert.assertTrue(_zkclient.exists(keyBuilder.idealStates("test-db").getPath()),
"test-db ideal-state should exist");
- Assert.assertTrue(_gZkClient.exists(keyBuilder.resourceConfig("test-db").getPath()),
+ Assert.assertTrue(_zkclient.exists(keyBuilder.resourceConfig("test-db").getPath()),
"test-db resource config should exist");
tool.dropResource(clusterName, "test-db");
- Assert.assertFalse(_gZkClient.exists(keyBuilder.idealStates("test-db").getPath()),
+ Assert.assertFalse(_zkclient.exists(keyBuilder.idealStates("test-db").getPath()),
"test-db ideal-state should be dropped");
- Assert.assertFalse(_gZkClient.exists(keyBuilder.resourceConfig("test-db").getPath()),
+ Assert.assertFalse(_zkclient.exists(keyBuilder.resourceConfig("test-db").getPath()),
"test-db resource config should be dropped");
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
@@ -244,9 +245,9 @@ public class TestZkHelixAdmin extends ZkUnitTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
- HelixAdmin tool = new ZKHelixAdmin(_gZkClient);
+ HelixAdmin tool = new ZKHelixAdmin(_zkclient);
tool.addCluster(clusterName, true);
- Assert.assertTrue(ZKUtil.isClusterSetup(clusterName, _gZkClient), "Cluster should be setup");
+ Assert.assertTrue(ZKUtil.isClusterSetup(clusterName, _zkclient), "Cluster should be setup");
// test admin.getMessageConstraints()
ClusterConstraints constraints =
@@ -269,7 +270,7 @@ public class TestZkHelixAdmin extends ZkUnitTestBase {
builder.build());
HelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
+ new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkclient));
PropertyKey.Builder keyBuilder = new PropertyKey.Builder(clusterName);
constraints =
accessor.getProperty(keyBuilder.constraint(ConstraintType.MESSAGE_CONSTRAINT.toString()));
@@ -304,15 +305,15 @@ public class TestZkHelixAdmin extends ZkUnitTestBase {
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
- HelixAdmin admin = new ZKHelixAdmin(_gZkClient);
+ HelixAdmin admin = new ZKHelixAdmin(_zkclient);
admin.addCluster(clusterName, true);
- Assert.assertTrue(ZKUtil.isClusterSetup(clusterName, _gZkClient), "Cluster should be setup");
+ Assert.assertTrue(ZKUtil.isClusterSetup(clusterName, _zkclient), "Cluster should be setup");
String resourceName = "TestDB";
admin.addStateModelDef(clusterName, "MasterSlave", new StateModelDefinition(
StateModelConfigGenerator.generateConfigForMasterSlave()));
admin.addResource(clusterName, resourceName, 4, "MasterSlave");
admin.enableResource(clusterName, resourceName, false);
- BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
+ BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor);
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
IdealState idealState = accessor.getProperty(keyBuilder.idealStates(resourceName));