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 2013/10/25 03:21:14 UTC
[01/10] [HELIX-279] Apply gc handling fixes to main ZKHelixManager
class
Updated Branches:
refs/heads/helix-0.6.2-release 610b28be9 -> 002acfd64
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/participant/MockZKHelixManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/participant/MockZKHelixManager.java b/helix-core/src/test/java/org/apache/helix/participant/MockZKHelixManager.java
index 6de77b2..d97b22a 100644
--- a/helix-core/src/test/java/org/apache/helix/participant/MockZKHelixManager.java
+++ b/helix-core/src/test/java/org/apache/helix/participant/MockZKHelixManager.java
@@ -261,4 +261,10 @@ public class MockZKHelixManager implements HelixManager {
return null;
}
+ @Override
+ public void addControllerMessageListener(MessageListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerStateModel.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerStateModel.java b/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerStateModel.java
index ae700a4..0eabe71 100644
--- a/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerStateModel.java
+++ b/helix-core/src/test/java/org/apache/helix/participant/TestDistControllerStateModel.java
@@ -25,10 +25,13 @@ import org.apache.helix.ZkUnitTestBase;
import org.apache.helix.model.Message;
import org.apache.helix.model.Message.MessageType;
import org.apache.helix.participant.DistClusterControllerStateModel;
+import org.apache.log4j.Logger;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class TestDistControllerStateModel extends ZkUnitTestBase {
+ private static Logger LOG = Logger.getLogger(TestDistControllerStateModel.class);
+
final String clusterName = CLUSTER_PREFIX + "_" + getShortClassName();
DistClusterControllerStateModel stateModel = null;
@@ -54,8 +57,7 @@ public class TestDistControllerStateModel extends ZkUnitTestBase {
try {
stateModel.onBecomeLeaderFromStandby(message, new NotificationContext(null));
} catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.error("Exception becoming leader from standby", e);
}
stateModel.onBecomeStandbyFromLeader(message, new NotificationContext(null));
}
@@ -95,8 +97,7 @@ public class TestDistControllerStateModel extends ZkUnitTestBase {
try {
stateModel.onBecomeLeaderFromStandby(message, new NotificationContext(null));
} catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.error("Exception becoming leader from standby", e);
}
stateModel.rollbackOnError(message, new NotificationContext(null), null);
}
@@ -109,8 +110,7 @@ public class TestDistControllerStateModel extends ZkUnitTestBase {
try {
stateModel.onBecomeLeaderFromStandby(message, new NotificationContext(null));
} catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.error("Exception becoming leader from standby", e);
}
stateModel.reset();
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/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 c58f94d..9fcacbd 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
@@ -29,13 +29,12 @@ import org.apache.helix.BaseDataAccessor;
import org.apache.helix.HelixDataAccessor;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
-import org.apache.helix.controller.HelixControllerMain;
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;
import org.apache.helix.manager.zk.ZKUtil;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.mock.controller.ClusterController;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.model.IdealState;
import org.apache.helix.model.InstanceConfig;
import org.apache.helix.model.LiveInstance;
@@ -238,8 +237,8 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase {
final int n = 6;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
- MockParticipant[] participants = new MockParticipant[n];
- ClusterController[] controllers = new ClusterController[2];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
+ ClusterDistributedController[] controllers = new ClusterDistributedController[2];
setupCluster(clusterName, grandClusterName, n, participants, controllers);
// activate clusters
@@ -309,14 +308,12 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase {
Assert.assertTrue(verifyResult);
// clean up
- // for (int i = 0; i < 2; i++) {
- // controllers[i].syncStop();
- // Thread.sleep(1000); // wait for all zk callbacks done
- // }
- // Thread.sleep(5000);
- // for (int i = 0; i < n; i++) {
- // participants[i].syncStop();
- // }
+ for (ClusterDistributedController controller : controllers) {
+ controller.syncStop();
+ }
+ for (int i = 0; i < participants.length; i++) {
+ participants[i].syncStop();
+ }
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
@@ -331,11 +328,11 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
- MockParticipant[] participants = new MockParticipant[n];
- ClusterController[] controllers = new ClusterController[2];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
+ ClusterDistributedController[] controllers = new ClusterDistributedController[2];
setupCluster(clusterName, grandClusterName, n, participants, controllers);
String command =
- "-zkSvr localhost:2183 -activateCluster " + clusterName + " " + grandClusterName + " true";
+ "-zkSvr " + ZK_ADDR + " -activateCluster " + clusterName + " " + grandClusterName + " true";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
Thread.sleep(500);
@@ -355,7 +352,7 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase {
pw.write(new String(serializer.serialize(idealState.getRecord())));
pw.close();
- command = "-zkSvr localhost:2183 -dropResource " + clusterName + " db_11 ";
+ command = "-zkSvr " + ZK_ADDR + " -dropResource " + clusterName + " db_11 ";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
boolean verifyResult =
@@ -363,7 +360,8 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase {
clusterName));
Assert.assertTrue(verifyResult);
- command = "-zkSvr localhost:2183 -addIdealState " + clusterName + " db_11 " + tmpIdealStateFile;
+ command =
+ "-zkSvr " + ZK_ADDR + " -addIdealState " + clusterName + " db_11 " + tmpIdealStateFile;
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
verifyResult =
@@ -375,61 +373,59 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase {
Assert.assertTrue(idealState2.getRecord().equals(idealState.getRecord()));
// clean up
- // for (int i = 0; i < 2; i++) {
- // controllers[i].syncStop();
- // Thread.sleep(1000); // wait for all zk callbacks done
- // }
- // Thread.sleep(5000);
- // for (int i = 0; i < n; i++) {
- // participants[i].syncStop();
- // }
+ for (int i = 0; i < controllers.length; i++) {
+ controllers[i].syncStop();
+ }
+ for (int i = 0; i < participants.length; i++) {
+ participants[i].syncStop();
+ }
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
private void setupCluster(String clusterName, String grandClusterName, final int n,
- MockParticipant[] participants, ClusterController[] controllers) throws Exception,
+ MockParticipantManager[] participants, ClusterDistributedController[] controllers)
+ throws Exception,
InterruptedException {
// add cluster
- String command = "-zkSvr localhost:2183 -addCluster " + clusterName;
+ String command = "-zkSvr " + ZK_ADDR + " -addCluster " + clusterName;
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
// add grand cluster
- command = "-zkSvr localhost:2183 -addCluster " + grandClusterName;
+ command = "-zkSvr " + ZK_ADDR + " -addCluster " + grandClusterName;
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
// add nodes
for (int i = 0; i < n; i++) {
- command = "-zkSvr localhost:2183 -addNode " + clusterName + " localhost:123" + i;
+ command = "-zkSvr " + ZK_ADDR + " -addNode " + clusterName + " localhost:123" + i;
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
}
// add resource
- command = "-zkSvr localhost:2183 -addResource " + clusterName + " db_11 48 MasterSlave";
+ command = "-zkSvr " + ZK_ADDR + " -addResource " + clusterName + " db_11 48 MasterSlave";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
// rebalance with key prefix
- command = "-zkSvr localhost:2183 -rebalance " + clusterName + " db_11 2 -key alias";
+ command = "-zkSvr " + ZK_ADDR + " -rebalance " + clusterName + " db_11 2 -key alias";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
// add nodes to grand cluster
command =
- "-zkSvr localhost:2183 -addNode " + grandClusterName + " controller:9000;controller:9001";
+ "-zkSvr " + ZK_ADDR + " -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 MockParticipant(clusterName, instanceName, ZK_ADDR);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
// start controller nodes
for (int i = 0; i < 2; i++) {
controllers[i] =
- new ClusterController(grandClusterName, "controller_900" + i, ZK_ADDR,
- HelixControllerMain.DISTRIBUTED);
+ new ClusterDistributedController(ZK_ADDR, grandClusterName, "controller_900" + i);
controllers[i].syncStart();
}
@@ -446,16 +442,16 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
- MockParticipant[] participants = new MockParticipant[n];
- ClusterController[] controllers = new ClusterController[2];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
+ ClusterDistributedController[] controllers = new ClusterDistributedController[2];
setupCluster(clusterName, grandClusterName, n, participants, controllers);
String command =
- "-zkSvr localhost:2183 -activateCluster " + clusterName + " " + grandClusterName + " true";
+ "-zkSvr " + ZK_ADDR + " -activateCluster " + clusterName + " " + grandClusterName + " true";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
Thread.sleep(500);
// drop node should fail if the node is not disabled
- command = "-zkSvr localhost:2183 -dropNode " + clusterName + " localhost:1232";
+ command = "-zkSvr " + ZK_ADDR + " -dropNode " + clusterName + " localhost:1232";
try {
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
Assert.fail("dropNode should fail since the node is not disabled");
@@ -464,11 +460,11 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase {
}
// disabled node
- command = "-zkSvr localhost:2183 -enableInstance " + clusterName + " localhost:1232 false";
+ command = "-zkSvr " + ZK_ADDR + " -enableInstance " + clusterName + " localhost:1232 false";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
// Cannot dropNode if the node is not disconnected
- command = "-zkSvr localhost:2183 -dropNode " + clusterName + " localhost:1232";
+ command = "-zkSvr " + ZK_ADDR + " -dropNode " + clusterName + " localhost:1232";
try {
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
Assert.fail("dropNode should fail since the node is not disconnected");
@@ -478,7 +474,7 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase {
// Cannot swapNode if the node is not disconnected
command =
- "-zkSvr localhost:2183 -swapInstance " + clusterName + " localhost_1232 localhost_12320";
+ "-zkSvr " + ZK_ADDR + " -swapInstance " + clusterName + " localhost_1232 localhost_12320";
try {
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
Assert.fail("swapInstance should fail since the node is not disconnected");
@@ -490,12 +486,12 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase {
participants[2].syncStop();
// add new node then swap instance
- command = "-zkSvr localhost:2183 -addNode " + clusterName + " localhost:12320";
+ command = "-zkSvr " + ZK_ADDR + " -addNode " + clusterName + " localhost:12320";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
// swap instance. The instance get swapped out should not exist anymore
command =
- "-zkSvr localhost:2183 -swapInstance " + clusterName + " localhost_1232 localhost_12320";
+ "-zkSvr " + ZK_ADDR + " -swapInstance " + clusterName + " localhost_1232 localhost_12320";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
@@ -504,6 +500,14 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase {
Assert.assertFalse(_gZkClient.exists(path), path
+ " should not exist since localhost_1232 has been swapped by localhost_12320");
+ // clean up
+ for (int i = 0; i < controllers.length; i++) {
+ controllers[i].syncStop();
+ }
+ for (int i = 0; i < participants.length; i++) {
+ participants[i].syncStop();
+ }
+
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
@@ -517,26 +521,26 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
- MockParticipant[] participants = new MockParticipant[n];
- ClusterController[] controllers = new ClusterController[2];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
+ ClusterDistributedController[] controllers = new ClusterDistributedController[2];
setupCluster(clusterName, grandClusterName, n, participants, controllers);
String command =
- "-zkSvr localhost:2183 -activateCluster " + clusterName + " " + grandClusterName + " true";
+ "-zkSvr " + ZK_ADDR + " -activateCluster " + clusterName + " " + grandClusterName + " true";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
Thread.sleep(500);
command =
- "-zkSvr localhost:2183 -addNode " + clusterName
+ "-zkSvr " + ZK_ADDR + " -addNode " + clusterName
+ " localhost:12331;localhost:12341;localhost:12351;localhost:12361";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
command = "-zkSvr localhost:2183 -expandCluster " + clusterName;
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
- MockParticipant[] newParticipants = new MockParticipant[4];
+ MockParticipantManager[] newParticipants = new MockParticipantManager[4];
for (int i = 3; i <= 6; i++) {
String instanceName = "localhost_123" + i + "1";
- newParticipants[i - 3] = new MockParticipant(clusterName, instanceName, ZK_ADDR);
+ newParticipants[i - 3] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
newParticipants[i - 3].syncStart();
}
@@ -550,6 +554,17 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase {
clusterName));
Assert.assertTrue(verifyResult);
+ // clean up
+ for (int i = 0; i < controllers.length; i++) {
+ controllers[i].syncStop();
+ }
+ for (int i = 0; i < participants.length; i++) {
+ participants[i].syncStop();
+ }
+ for (int i = 0; i < newParticipants.length; i++) {
+ newParticipants[i].syncStop();
+ }
+
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
@@ -563,17 +578,18 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
- MockParticipant[] participants = new MockParticipant[n];
- ClusterController[] controllers = new ClusterController[2];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
+ ClusterDistributedController[] controllers = new ClusterDistributedController[2];
setupCluster(clusterName, grandClusterName, n, participants, controllers);
String command =
- "-zkSvr localhost:2183 -activateCluster " + clusterName + " " + grandClusterName + " true";
+ "-zkSvr " + ZK_ADDR + " -activateCluster " + clusterName + " " + grandClusterName + " true";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
Thread.sleep(500);
// deactivate cluster
command =
- "-zkSvr localhost:2183 -activateCluster " + clusterName + " " + grandClusterName + " false";
+ "-zkSvr " + ZK_ADDR + " -activateCluster " + clusterName + " " + grandClusterName
+ + " false";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
@@ -588,7 +604,7 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase {
Assert.assertFalse(_gZkClient.exists(path),
"leader should be gone after deactivate the cluster");
- command = "-zkSvr localhost:2183 -dropCluster " + clusterName;
+ command = "-zkSvr " + ZK_ADDR + " -dropCluster " + clusterName;
try {
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
Assert.fail("dropCluster should fail since there are still instances running");
@@ -596,16 +612,15 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase {
// OK
}
- for (int i = 0; i < n; i++) {
+ for (int i = 0; i < participants.length; i++) {
participants[i].syncStop();
}
command = "-zkSvr localhost:2183 -dropCluster " + clusterName;
ClusterSetup.processCommandLineArgs(command.split("\\s"));
- for (int i = 0; i < 2; i++) {
+ for (int i = 0; i < controllers.length; i++) {
controllers[i].syncStop();
- Thread.sleep(1000);
}
command = "-zkSvr localhost:2183 -dropCluster " + grandClusterName;
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
@@ -625,29 +640,30 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
- String command = "-zkSvr localhost:2183 -addCluster " + clusterName;
+ String command = "-zkSvr " + ZK_ADDR + " -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 localhost:2183 -addNode " + clusterName + " localhost:123" + i;
+ command = "-zkSvr " + ZK_ADDR + " -addNode " + clusterName + " localhost:123" + i;
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
}
for (int i = 0; i < 2; i++) {
command =
- "-zkSvr localhost:2183 -addInstanceTag " + clusterName + " localhost_123" + i + " tag1";
+ "-zkSvr " + ZK_ADDR + " -addInstanceTag " + clusterName + " localhost_123" + i + " tag1";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
}
for (int i = 2; i < 6; i++) {
command =
- "-zkSvr localhost:2183 -addInstanceTag " + clusterName + " localhost_123" + i + " tag2";
+ "-zkSvr " + ZK_ADDR + " -addInstanceTag " + clusterName + " localhost_123" + i + " tag2";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
}
- command = "-zkSvr localhost:2183 -rebalance " + clusterName + " db_11 2 -instanceGroupTag tag1";
+ command =
+ "-zkSvr " + ZK_ADDR + " -rebalance " + clusterName + " db_11 2 -instanceGroupTag tag1";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
IdealState dbIs = accessor.getProperty(accessor.keyBuilder().idealStates("db_11"));
@@ -662,14 +678,15 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase {
}
Assert.assertEquals(hosts.size(), 2);
- command = "-zkSvr localhost:2183 -dropResource " + clusterName + " db_11 ";
+ command = "-zkSvr " + ZK_ADDR + " -dropResource " + clusterName + " db_11 ";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
// re-add and rebalance
- command = "-zkSvr localhost:2183 -addResource " + clusterName + " db_11 48 MasterSlave";
+ command = "-zkSvr " + ZK_ADDR + " -addResource " + clusterName + " db_11 48 MasterSlave";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
- command = "-zkSvr localhost:2183 -rebalance " + clusterName + " db_11 3 -instanceGroupTag tag2";
+ command =
+ "-zkSvr " + ZK_ADDR + " -rebalance " + clusterName + " db_11 3 -instanceGroupTag tag2";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
dbIs = accessor.getProperty(accessor.keyBuilder().idealStates("db_11"));
@@ -684,21 +701,22 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase {
}
Assert.assertEquals(hosts.size(), 4);
- command = "-zkSvr localhost:2183 -dropResource " + clusterName + " db_11 ";
+ command = "-zkSvr " + ZK_ADDR + " -dropResource " + clusterName + " db_11 ";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
for (int i = 3; i <= 3; i++) {
command =
- "-zkSvr localhost:2183 -removeInstanceTag " + clusterName + " localhost_123" + i
+ "-zkSvr " + ZK_ADDR + " -removeInstanceTag " + clusterName + " localhost_123" + i
+ " tag2";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
}
// re-add and rebalance
- command = "-zkSvr localhost:2183 -addResource " + clusterName + " db_11 48 MasterSlave";
+ command = "-zkSvr " + ZK_ADDR + " -addResource " + clusterName + " db_11 48 MasterSlave";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
- command = "-zkSvr localhost:2183 -rebalance " + clusterName + " db_11 3 -instanceGroupTag tag2";
+ command =
+ "-zkSvr " + ZK_ADDR + " -rebalance " + clusterName + " db_11 3 -instanceGroupTag tag2";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
dbIs = accessor.getProperty(accessor.keyBuilder().idealStates("db_11"));
hosts = new HashSet<String>();
@@ -713,7 +731,7 @@ public class TestHelixAdminCli extends ZkIntegrationTestBase {
Assert.assertEquals(hosts.size(), 3);
// rebalance with key prefix
- command = "-zkSvr localhost:2183 -rebalance " + clusterName + " db_11 2 -key alias";
+ command = "-zkSvr " + ZK_ADDR + " -rebalance " + clusterName + " db_11 2 -key alias";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
[09/10] git commit: Merge branch 'helix-0.6.2-release' of
https://git-wip-us.apache.org/repos/asf/incubator-helix into
helix-0.6.2-release
Posted by zz...@apache.org.
Merge branch 'helix-0.6.2-release' of https://git-wip-us.apache.org/repos/asf/incubator-helix into helix-0.6.2-release
Conflicts:
helix-admin-webapp/src/test/java/org/apache/helix/tools/TestHelixAdminScenariosRest.java
helix-core/src/test/java/org/apache/helix/integration/TestCustomizedIdealStateRebalancer.java
Project: http://git-wip-us.apache.org/repos/asf/incubator-helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-helix/commit/a416e744
Tree: http://git-wip-us.apache.org/repos/asf/incubator-helix/tree/a416e744
Diff: http://git-wip-us.apache.org/repos/asf/incubator-helix/diff/a416e744
Branch: refs/heads/helix-0.6.2-release
Commit: a416e74463a03ea072b36409b39cc1693f6d93af
Parents: 579baa5 610b28b
Author: zzhang <zz...@apache.org>
Authored: Thu Oct 24 15:54:31 2013 -0700
Committer: zzhang <zz...@apache.org>
Committed: Thu Oct 24 15:54:31 2013 -0700
----------------------------------------------------------------------
helix-admin-webapp/pom.xml | 4 +-
.../helix/webapp/RestAdminApplication.java | 18 +-
.../resources/ClusterRepresentationUtil.java | 2 +-
.../helix/webapp/resources/ClusterResource.java | 54 ++--
.../webapp/resources/ClustersResource.java | 41 +--
.../helix/webapp/resources/ConfigResource.java | 32 +-
.../webapp/resources/ConstraintResource.java | 28 +-
.../webapp/resources/ControllerResource.java | 45 +--
.../ControllerStatusUpdateResource.java | 39 +--
.../webapp/resources/CurrentStateResource.java | 39 +--
.../webapp/resources/CurrentStatesResource.java | 35 +--
.../helix/webapp/resources/ErrorResource.java | 39 +--
.../helix/webapp/resources/ErrorsResource.java | 36 +--
.../webapp/resources/ExternalViewResource.java | 39 +--
.../webapp/resources/IdealStateResource.java | 44 +--
.../webapp/resources/InstanceResource.java | 45 +--
.../webapp/resources/InstancesResource.java | 42 +--
.../helix/webapp/resources/JsonParameters.java | 2 +-
.../webapp/resources/ResourceGroupResource.java | 45 +--
.../resources/ResourceGroupsResource.java | 42 +--
.../resources/SchedulerTasksResource.java | 42 +--
.../webapp/resources/StateModelResource.java | 44 +--
.../webapp/resources/StateModelsResource.java | 43 +--
.../webapp/resources/StatusUpdateResource.java | 39 +--
.../webapp/resources/StatusUpdatesResource.java | 39 +--
.../helix/webapp/resources/ZkChildResource.java | 42 +--
.../helix/webapp/resources/ZkPathResource.java | 47 +--
.../tools/TestHelixAdminScenariosRest.java | 8 +-
.../webapp/TestClusterManagementWebapp.java | 8 +-
helix-agent/pom.xml | 4 +-
helix-core/pom.xml | 12 +-
.../controller/rebalancer/AutoRebalancer.java | 34 +-
.../controller/rebalancer/CustomRebalancer.java | 9 +-
.../helix/controller/rebalancer/Rebalancer.java | 14 -
.../rebalancer/SemiAutoRebalancer.java | 9 +-
.../rebalancer/internal/MappingCalculator.java | 46 +++
.../restlet/ZKPropertyTransferServer.java | 5 +
.../restlet/ZNRecordUpdateResource.java | 99 +++---
.../restlet/ZkPropertyTransferApplication.java | 4 +-
.../restlet/ZkPropertyTransferClient.java | 9 +-
.../stages/BestPossibleStateCalcStage.java | 26 +-
.../controller/stages/ResourceAssignment.java | 58 ++++
.../controller/stages/ResourceMapping.java | 58 ----
.../apache/helix/manager/zk/ZKHelixAdmin.java | 8 +-
.../helix/manager/zk/ZKHelixDataAccessor.java | 18 +-
.../manager/zk/ZNRecordStreamingSerializer.java | 2 +-
.../java/org/apache/helix/model/IdealState.java | 21 ++
.../helix/model/StateModelDefinition.java | 23 +-
.../util/StateModelDefinitionValidator.java | 290 +++++++++++++++++
.../test/java/org/apache/helix/TestHelper.java | 2 +-
.../TestCustomizedIdealStateRebalancer.java | 6 +-
.../integration/TestFullAutoNodeTagging.java | 314 +++++++++++++++++++
.../helix/model/TestStateModelValidity.java | 252 +++++++++++++++
pom.xml | 6 +-
src/site/markdown/tutorial_state.md | 79 ++++-
55 files changed, 1483 insertions(+), 908 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/a416e744/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestHelixAdminScenariosRest.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/a416e744/helix-core/src/test/java/org/apache/helix/TestHelper.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/a416e744/helix-core/src/test/java/org/apache/helix/integration/TestCustomizedIdealStateRebalancer.java
----------------------------------------------------------------------
[02/10] [HELIX-279] Apply gc handling fixes to main ZKHelixManager
class
Posted by zz...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestZkCallbackHandlerLeak.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestZkCallbackHandlerLeak.java b/helix-core/src/test/java/org/apache/helix/integration/TestZkCallbackHandlerLeak.java
index 347fcb6..7759761 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestZkCallbackHandlerLeak.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestZkCallbackHandlerLeak.java
@@ -27,10 +27,11 @@ import java.util.Set;
import org.I0Itec.zkclient.IZkChildListener;
import org.I0Itec.zkclient.IZkDataListener;
import org.apache.helix.*;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
+import org.apache.helix.integration.manager.ZkTestManager;
import org.apache.helix.manager.zk.CallbackHandler;
import org.apache.helix.manager.zk.ZkClient;
-import org.apache.helix.mock.controller.ClusterController;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.model.CurrentState;
import org.apache.helix.tools.ClusterStateVerifier;
import org.testng.Assert;
@@ -57,15 +58,16 @@ public class TestZkCallbackHandlerLeak extends ZkUnitTestBase {
2, // replicas
"MasterSlave", true); // do rebalance
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ final ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
@@ -74,9 +76,7 @@ public class TestZkCallbackHandlerLeak extends ZkUnitTestBase {
.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR,
clusterName));
Assert.assertTrue(result);
- final ZkHelixTestManager controllerManager = controller.getManager();
- final ZkHelixTestManager participantManagerToExpire =
- (ZkHelixTestManager) participants[1].getManager();
+ final MockParticipantManager participantManagerToExpire = participants[1];
// check controller zk-watchers
result = TestHelper.verify(new TestHelper.Verifier() {
@@ -84,7 +84,8 @@ public class TestZkCallbackHandlerLeak extends ZkUnitTestBase {
@Override
public boolean verify() throws Exception {
Map<String, Set<String>> watchers = ZkTestHelper.getListenersBySession(ZK_ADDR);
- Set<String> watchPaths = watchers.get("0x" + controllerManager.getSessionId());
+ // Set<String> watchPaths = watchers.get("0x" + controllerManager.getSessionId());
+ Set<String> watchPaths = watchers.get("0x" + controller.getSessionId());
// System.out.println("controller watch paths: " + watchPaths);
// controller should have 5 + 2n + m + (m+2)n zk-watchers
@@ -112,7 +113,7 @@ public class TestZkCallbackHandlerLeak extends ZkUnitTestBase {
// check HelixManager#_handlers
// printHandlers(controllerManager);
// printHandlers(participantManagerToExpire);
- int controllerHandlerNb = controllerManager.getHandlers().size();
+ int controllerHandlerNb = controller.getHandlers().size();
int particHandlerNb = participantManagerToExpire.getHandlers().size();
Assert.assertEquals(controllerHandlerNb, 9,
"HelixController should have 9 (5+2n) callback handlers for 2 (n) participant");
@@ -139,7 +140,7 @@ public class TestZkCallbackHandlerLeak extends ZkUnitTestBase {
@Override
public boolean verify() throws Exception {
Map<String, Set<String>> watchers = ZkTestHelper.getListenersBySession(ZK_ADDR);
- Set<String> watchPaths = watchers.get("0x" + controllerManager.getSessionId());
+ Set<String> watchPaths = watchers.get("0x" + controller.getSessionId());
// System.out.println("controller watch paths after session expiry: " + watchPaths);
// controller should have 5 + 2n + m + (m+2)n zk-watchers
@@ -167,13 +168,19 @@ public class TestZkCallbackHandlerLeak extends ZkUnitTestBase {
// check handlers
// printHandlers(controllerManager);
// printHandlers(participantManagerToExpire);
- int handlerNb = controllerManager.getHandlers().size();
+ int handlerNb = controller.getHandlers().size();
Assert.assertEquals(handlerNb, controllerHandlerNb,
"controller callback handlers should not increase after participant session expiry");
handlerNb = participantManagerToExpire.getHandlers().size();
Assert.assertEquals(handlerNb, particHandlerNb,
"participant callback handlers should not increase after participant session expiry");
+ // clean up
+ controller.syncStop();
+ for (int i = 0; i < n; i++) {
+ participants[i].syncStop();
+ }
+
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
@@ -196,15 +203,16 @@ public class TestZkCallbackHandlerLeak extends ZkUnitTestBase {
2, // replicas
"MasterSlave", true); // do rebalance
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ final ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
@@ -213,15 +221,16 @@ public class TestZkCallbackHandlerLeak extends ZkUnitTestBase {
.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR,
clusterName));
Assert.assertTrue(result);
- final ZkHelixTestManager controllerManager = controller.getManager();
- final ZkHelixTestManager participantManager = participants[0].getManager();
+ // final ZkHelixTestManager controllerManager = controller.getManager();
+ // final ZkHelixTestManager participantManager = participants[0].getManager();
+ final MockParticipantManager participantManager = participants[0];
// wait until we get all the listeners registered
result = TestHelper.verify(new TestHelper.Verifier() {
@Override
public boolean verify() throws Exception {
- int controllerHandlerNb = controllerManager.getHandlers().size();
+ int controllerHandlerNb = controller.getHandlers().size();
int particHandlerNb = participantManager.getHandlers().size();
if (controllerHandlerNb == 9 && particHandlerNb == 2)
return true;
@@ -230,21 +239,21 @@ public class TestZkCallbackHandlerLeak extends ZkUnitTestBase {
}
}, 1000);
- int controllerHandlerNb = controllerManager.getHandlers().size();
+ int controllerHandlerNb = controller.getHandlers().size();
int particHandlerNb = participantManager.getHandlers().size();
Assert.assertEquals(controllerHandlerNb, 9,
"HelixController should have 9 (5+2n) callback handlers for 2 participant, but was "
- + controllerHandlerNb + ", " + printHandlers(controllerManager));
+ + controllerHandlerNb + ", " + printHandlers(controller));
Assert.assertEquals(particHandlerNb, 2,
"HelixParticipant should have 2 (msg+cur-state) callback handlers, but was "
+ particHandlerNb + ", " + printHandlers(participantManager));
// expire controller
System.out.println("Expiring controller session...");
- String oldSessionId = controllerManager.getSessionId();
+ String oldSessionId = controller.getSessionId();
- ZkTestHelper.expireSession(controllerManager.getZkClient());
- String newSessionId = controllerManager.getSessionId();
+ ZkTestHelper.expireSession(controller.getZkClient());
+ String newSessionId = controller.getSessionId();
System.out.println("Expired controller session. oldSessionId: " + oldSessionId
+ ", newSessionId: " + newSessionId);
@@ -259,7 +268,7 @@ public class TestZkCallbackHandlerLeak extends ZkUnitTestBase {
@Override
public boolean verify() throws Exception {
Map<String, Set<String>> watchers = ZkTestHelper.getListenersBySession(ZK_ADDR);
- Set<String> watchPaths = watchers.get("0x" + controllerManager.getSessionId());
+ Set<String> watchPaths = watchers.get("0x" + controller.getSessionId());
// System.out.println("controller watch paths after session expiry: " + watchPaths);
// controller should have 5 + 2n + m + (m+2)n zk-watchers
@@ -286,15 +295,21 @@ public class TestZkCallbackHandlerLeak extends ZkUnitTestBase {
// check HelixManager#_handlers
// printHandlers(controllerManager);
- int handlerNb = controllerManager.getHandlers().size();
+ int handlerNb = controller.getHandlers().size();
Assert.assertEquals(handlerNb, controllerHandlerNb,
"controller callback handlers should not increase after participant session expiry, but was "
- + printHandlers(controllerManager));
+ + printHandlers(controller));
handlerNb = participantManager.getHandlers().size();
Assert.assertEquals(handlerNb, particHandlerNb,
"participant callback handlers should not increase after participant session expiry, but was "
+ printHandlers(participantManager));
+ // clean up
+ controller.syncStop();
+ for (int i = 0; i < n; i++) {
+ participants[i].syncStop();
+ }
+
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
@@ -313,18 +328,20 @@ public class TestZkCallbackHandlerLeak extends ZkUnitTestBase {
2, // replicas
"MasterSlave", true);
- ClusterController controller = new ClusterController(clusterName, "controller_0", zkAddr);
+ final ClusterControllerManager controller =
+ new ClusterControllerManager(zkAddr, clusterName, "controller_0");
controller.syncStart();
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, zkAddr, null);
+ participants[i] = new MockParticipantManager(zkAddr, clusterName, instanceName);
participants[i].syncStart();
// register a controller listener on participant_0
if (i == 0) {
- ZkHelixTestManager manager = participants[0].getManager();
+ // ZkHelixTestManager manager = participants[0].getManager();
+ MockParticipantManager manager = participants[0];
manager.addCurrentStateChangeListener(new CurrentStateChangeListener() {
@Override
public void onStateChange(String instanceName, List<CurrentState> statesInfo,
@@ -343,7 +360,7 @@ public class TestZkCallbackHandlerLeak extends ZkUnitTestBase {
clusterName));
Assert.assertTrue(result);
- ZkHelixTestManager participantToExpire = participants[0].getManager();
+ MockParticipantManager participantToExpire = participants[0];
String oldSessionId = participantToExpire.getSessionId();
PropertyKey.Builder keyBuilder = new PropertyKey.Builder(clusterName);
@@ -468,11 +485,18 @@ public class TestZkCallbackHandlerLeak extends ZkUnitTestBase {
"Should have no exist-watches. exist-watches on CURRENTSTATE/{oldSessionId} and CURRENTSTATE/{oldSessionId}/TestDB0 should be cleared during handleNewSession");
// Thread.sleep(1000);
+
+ // clean up
+ controller.syncStop();
+ for (int i = 0; i < n; i++) {
+ participants[i].syncStop();
+ }
+
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
// debug code
- static String printHandlers(ZkHelixTestManager manager) {
+ static String printHandlers(ZkTestManager manager) {
StringBuilder sb = new StringBuilder();
List<CallbackHandler> handlers = manager.getHandlers();
sb.append(manager.getInstanceName() + " has " + handlers.size() + " cb-handlers. [");
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/ZkIntegrationTestBase.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/ZkIntegrationTestBase.java b/helix-core/src/test/java/org/apache/helix/integration/ZkIntegrationTestBase.java
index 2ab0aaf..3ccdaa7 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/ZkIntegrationTestBase.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/ZkIntegrationTestBase.java
@@ -19,7 +19,6 @@ package org.apache.helix.integration;
* under the License.
*/
-import java.util.Map;
import java.util.logging.Level;
import org.I0Itec.zkclient.ZkServer;
@@ -28,7 +27,7 @@ import org.apache.helix.model.ConfigScope;
import org.apache.helix.model.builder.ConfigScopeBuilder;
import org.apache.helix.TestHelper;
import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.TestHelper.StartCMResult;
+import org.apache.helix.ZNRecord;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZNRecordSerializer;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
@@ -37,7 +36,6 @@ import org.apache.helix.model.LiveInstance;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.util.ZKClientPool;
import org.apache.log4j.Logger;
-import org.testng.Assert;
import org.testng.AssertJUnit;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
@@ -85,7 +83,7 @@ public class ZkIntegrationTestBase {
protected String getCurrentLeader(ZkClient zkClient, String clusterName) {
ZKHelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(zkClient));
+ new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(zkClient));
Builder keyBuilder = accessor.keyBuilder();
LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
@@ -95,49 +93,6 @@ public class ZkIntegrationTestBase {
return leader.getInstanceName();
}
- /**
- * Stop current leader and returns the new leader
- * @param zkClient
- * @param clusterName
- * @param startCMResultMap
- * @return
- */
- protected String stopCurrentLeader(ZkClient zkClient, String clusterName,
- Map<String, StartCMResult> startCMResultMap) {
- String leader = getCurrentLeader(zkClient, clusterName);
- Assert.assertTrue(leader != null);
- System.out.println("stop leader: " + leader + " in " + clusterName);
- Assert.assertTrue(leader != null);
-
- StartCMResult result = startCMResultMap.remove(leader);
- Assert.assertTrue(result._manager != null);
- result._manager.disconnect();
-
- Assert.assertTrue(result._thread != null);
- result._thread.interrupt();
-
- boolean isNewLeaderElected = false;
- String newLeader = null;
- try {
- for (int i = 0; i < 5; i++) {
- Thread.sleep(1000);
- newLeader = getCurrentLeader(zkClient, clusterName);
- if (!newLeader.equals(leader)) {
- isNewLeaderElected = true;
- System.out.println("new leader elected: " + newLeader + " in " + clusterName);
- break;
- }
- }
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- if (isNewLeaderElected == false) {
- System.out.println("fail to elect a new leader in " + clusterName);
- }
- AssertJUnit.assertTrue(isNewLeaderElected);
- return newLeader;
- }
-
protected void enableHealthCheck(String clusterName) {
ConfigScope scope = new ConfigScopeBuilder().forCluster(clusterName).build();
new ConfigAccessor(_gZkClient).set(scope, "healthChange" + ".enabled", "" + true);
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/ZkStandAloneCMTestBase.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/ZkStandAloneCMTestBase.java b/helix-core/src/test/java/org/apache/helix/integration/ZkStandAloneCMTestBase.java
index e759fc7..5d169d5 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/ZkStandAloneCMTestBase.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/ZkStandAloneCMTestBase.java
@@ -20,16 +20,9 @@ package org.apache.helix.integration;
*/
import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.apache.helix.TestHelper;
-import org.apache.helix.TestHelper.StartCMResult;
-import org.apache.helix.controller.HelixControllerMain;
-import org.apache.helix.manager.zk.ZNRecordSerializer;
-import org.apache.helix.manager.zk.ZkClient;
+
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.tools.ClusterStateVerifier;
import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier;
@@ -57,8 +50,8 @@ public class ZkStandAloneCMTestBase extends ZkIntegrationTestBase {
protected final String CLASS_NAME = getShortClassName();
protected final String CLUSTER_NAME = CLUSTER_PREFIX + "_" + CLASS_NAME;
- protected Map<String, StartCMResult> _startCMResultMap = new HashMap<String, StartCMResult>();
- protected ZkClient _zkClient;
+ protected MockParticipantManager[] _participants = new MockParticipantManager[NODE_NR];
+ protected ClusterControllerManager _controller;
int _replica = 3;
@@ -67,11 +60,9 @@ public class ZkStandAloneCMTestBase extends ZkIntegrationTestBase {
// Logger.getRootLogger().setLevel(Level.INFO);
System.out.println("START " + CLASS_NAME + " at " + new Date(System.currentTimeMillis()));
- _zkClient = new ZkClient(ZK_ADDR);
- _zkClient.setZkSerializer(new ZNRecordSerializer());
String namespace = "/" + CLUSTER_NAME;
- if (_zkClient.exists(namespace)) {
- _zkClient.deleteRecursive(namespace);
+ if (_gZkClient.exists(namespace)) {
+ _gZkClient.deleteRecursive(namespace);
}
_setupTool = new ClusterSetup(ZK_ADDR);
@@ -87,21 +78,14 @@ public class ZkStandAloneCMTestBase extends ZkIntegrationTestBase {
// start dummy participants
for (int i = 0; i < NODE_NR; i++) {
String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
- if (_startCMResultMap.get(instanceName) != null) {
- LOG.error("fail to start particpant:" + instanceName
- + "(participant with same name already exists)");
- } else {
- StartCMResult result = TestHelper.startDummyProcess(ZK_ADDR, CLUSTER_NAME, instanceName);
- _startCMResultMap.put(instanceName, result);
- }
+ _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
+ _participants[i].syncStart();
}
// start controller
String controllerName = CONTROLLER_PREFIX + "_0";
- StartCMResult startResult =
- TestHelper.startController(CLUSTER_NAME, controllerName, ZK_ADDR,
- HelixControllerMain.STANDALONE);
- _startCMResultMap.put(controllerName, startResult);
+ _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
+ _controller.syncStart();
boolean result =
ClusterStateVerifier
@@ -119,30 +103,11 @@ public class ZkStandAloneCMTestBase extends ZkIntegrationTestBase {
* shutdown order: 1) disconnect the controller 2) disconnect participants
*/
- StartCMResult result;
- Iterator<Entry<String, StartCMResult>> it = _startCMResultMap.entrySet().iterator();
- while (it.hasNext()) {
- String instanceName = it.next().getKey();
- if (instanceName.startsWith(CONTROLLER_PREFIX)) {
- result = _startCMResultMap.get(instanceName);
- result._manager.disconnect();
- result._thread.interrupt();
- it.remove();
- }
- }
-
- Thread.sleep(100);
- it = _startCMResultMap.entrySet().iterator();
- while (it.hasNext()) {
- String instanceName = it.next().getKey();
- result = _startCMResultMap.get(instanceName);
- result._manager.disconnect();
- result._thread.interrupt();
- it.remove();
+ _controller.syncStop();
+ for (int i = 0; i < NODE_NR; i++) {
+ _participants[i].syncStop();
}
- _zkClient.close();
- // logger.info("END at " + new Date(System.currentTimeMillis()));
System.out.println("END " + CLASS_NAME + " at " + new Date(System.currentTimeMillis()));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/ZkStandAloneCMTestBaseWithPropertyServerCheck.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/ZkStandAloneCMTestBaseWithPropertyServerCheck.java b/helix-core/src/test/java/org/apache/helix/integration/ZkStandAloneCMTestBaseWithPropertyServerCheck.java
index f19e5dd..c6fbea6 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/ZkStandAloneCMTestBaseWithPropertyServerCheck.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/ZkStandAloneCMTestBaseWithPropertyServerCheck.java
@@ -23,8 +23,11 @@ import java.util.List;
import org.apache.helix.HelixDataAccessor;
import org.apache.helix.PropertyKey.Builder;
+import org.apache.helix.ZNRecord;
import org.apache.helix.controller.restlet.ZKPropertyTransferServer;
import org.apache.helix.controller.restlet.ZkPropertyTransferClient;
+import org.apache.helix.manager.zk.ZKHelixDataAccessor;
+import org.apache.helix.manager.zk.ZkBaseDataAccessor;
import org.apache.helix.model.StatusUpdate;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
@@ -36,6 +39,7 @@ import org.testng.annotations.BeforeClass;
*/
public class ZkStandAloneCMTestBaseWithPropertyServerCheck extends ZkStandAloneCMTestBase {
+ @Override
@BeforeClass
public void beforeClass() throws Exception {
ZKPropertyTransferServer.PERIOD = 500;
@@ -44,19 +48,20 @@ public class ZkStandAloneCMTestBaseWithPropertyServerCheck extends ZkStandAloneC
super.beforeClass();
Thread.sleep(1000);
+ HelixDataAccessor accessor =
+ new ZKHelixDataAccessor(CLUSTER_NAME, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
+ Builder kb = accessor.keyBuilder();
+
for (int i = 0; i < NODE_NR; i++) {
- String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
- if (_startCMResultMap.get(instanceName) != null) {
- HelixDataAccessor accessor =
- _startCMResultMap.get(instanceName)._manager.getHelixDataAccessor();
- Builder kb = accessor.keyBuilder();
- List<StatusUpdate> statusUpdates =
- accessor.getChildValues(kb.stateTransitionStatus(instanceName,
- _startCMResultMap.get(instanceName)._manager.getSessionId(), TEST_DB));
+ String instanceName = _participants[i].getInstanceName();
+ List<StatusUpdate> statusUpdates =
+ accessor.getChildValues(kb.stateTransitionStatus(instanceName,
+ _participants[i].getSessionId(), TEST_DB));
+
for (int j = 0; j < 10; j++) {
statusUpdates =
accessor.getChildValues(kb.stateTransitionStatus(instanceName,
- _startCMResultMap.get(instanceName)._manager.getSessionId(), TEST_DB));
+ _participants[i].getSessionId(), TEST_DB));
if (statusUpdates.size() == 0) {
Thread.sleep(500);
} else {
@@ -70,10 +75,10 @@ public class ZkStandAloneCMTestBaseWithPropertyServerCheck extends ZkStandAloneC
Assert
.assertTrue(update.getRecord().getSimpleField(ZKPropertyTransferServer.SERVER) != null);
}
- }
}
}
+ @Override
@AfterClass
public void afterClass() throws Exception {
super.afterClass();
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/manager/ClusterControllerManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/manager/ClusterControllerManager.java b/helix-core/src/test/java/org/apache/helix/integration/manager/ClusterControllerManager.java
index e0da9fb..b8f0f2b 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/manager/ClusterControllerManager.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/manager/ClusterControllerManager.java
@@ -22,12 +22,14 @@ package org.apache.helix.integration.manager;
import java.util.List;
import java.util.concurrent.CountDownLatch;
+import org.apache.helix.HelixTimerTask;
+import org.apache.helix.InstanceType;
import org.apache.helix.manager.zk.CallbackHandler;
-import org.apache.helix.manager.zk.ControllerManager;
+import org.apache.helix.manager.zk.ZKHelixManager;
import org.apache.helix.manager.zk.ZkClient;
import org.apache.log4j.Logger;
-public class ClusterControllerManager extends ControllerManager implements Runnable, ZkTestManager {
+public class ClusterControllerManager extends ZKHelixManager implements Runnable, ZkTestManager {
private static Logger LOG = Logger.getLogger(ClusterControllerManager.class);
private final CountDownLatch _startCountDown = new CountDownLatch(1);
@@ -35,7 +37,7 @@ public class ClusterControllerManager extends ControllerManager implements Runna
private final CountDownLatch _waitStopFinishCountDown = new CountDownLatch(1);
public ClusterControllerManager(String zkAddr, String clusterName, String controllerName) {
- super(zkAddr, clusterName, controllerName);
+ super(clusterName, controllerName, InstanceType.CONTROLLER, zkAddr);
}
public void syncStop() {
@@ -43,8 +45,7 @@ public class ClusterControllerManager extends ControllerManager implements Runna
try {
_waitStopFinishCountDown.await();
} catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.error("Interrupted waiting for finish", e);
}
}
@@ -54,8 +55,7 @@ public class ClusterControllerManager extends ControllerManager implements Runna
try {
_startCountDown.await();
} catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.error("Interrupted waiting for start", e);
}
}
@@ -84,4 +84,7 @@ public class ClusterControllerManager extends ControllerManager implements Runna
return _handlers;
}
+ public List<HelixTimerTask> getControllerTimerTasks() {
+ return _controllerTimerTasks;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/manager/ClusterDistributedController.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/manager/ClusterDistributedController.java b/helix-core/src/test/java/org/apache/helix/integration/manager/ClusterDistributedController.java
index 751c3cb..44d0957 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/manager/ClusterDistributedController.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/manager/ClusterDistributedController.java
@@ -22,12 +22,15 @@ package org.apache.helix.integration.manager;
import java.util.List;
import java.util.concurrent.CountDownLatch;
+import org.apache.helix.InstanceType;
import org.apache.helix.manager.zk.CallbackHandler;
-import org.apache.helix.manager.zk.DistributedControllerManager;
+import org.apache.helix.manager.zk.ZKHelixManager;
import org.apache.helix.manager.zk.ZkClient;
+import org.apache.helix.participant.DistClusterControllerStateModelFactory;
+import org.apache.helix.participant.StateMachineEngine;
import org.apache.log4j.Logger;
-public class ClusterDistributedController extends DistributedControllerManager implements Runnable,
+public class ClusterDistributedController extends ZKHelixManager implements Runnable,
ZkTestManager {
private static Logger LOG = Logger.getLogger(ClusterDistributedController.class);
@@ -36,7 +39,7 @@ public class ClusterDistributedController extends DistributedControllerManager i
private final CountDownLatch _waitStopFinishCountDown = new CountDownLatch(1);
public ClusterDistributedController(String zkAddr, String clusterName, String controllerName) {
- super(zkAddr, clusterName, controllerName);
+ super(clusterName, controllerName, InstanceType.CONTROLLER_PARTICIPANT, zkAddr);
}
public void syncStop() {
@@ -44,8 +47,7 @@ public class ClusterDistributedController extends DistributedControllerManager i
try {
_waitStopFinishCountDown.await();
} catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.error("Interrupted waiting for finish", e);
}
}
@@ -55,14 +57,18 @@ public class ClusterDistributedController extends DistributedControllerManager i
try {
_startCountDown.await();
} catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.error("Interrupted waiting for start", e);
}
}
@Override
public void run() {
try {
+ StateMachineEngine stateMach = getStateMachineEngine();
+ DistClusterControllerStateModelFactory lsModelFactory =
+ new DistClusterControllerStateModelFactory(_zkAddress);
+ stateMach.registerStateModelFactory("LeaderStandby", lsModelFactory);
+
connect();
_startCountDown.countDown();
_stopCountDown.await();
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/manager/MockParticipantManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/manager/MockParticipantManager.java b/helix-core/src/test/java/org/apache/helix/integration/manager/MockParticipantManager.java
index 8249f4a..34efe34 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/manager/MockParticipantManager.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/manager/MockParticipantManager.java
@@ -22,18 +22,20 @@ package org.apache.helix.integration.manager;
import java.util.List;
import java.util.concurrent.CountDownLatch;
+import org.apache.helix.InstanceType;
import org.apache.helix.manager.zk.CallbackHandler;
-import org.apache.helix.manager.zk.ParticipantManager;
+import org.apache.helix.manager.zk.ZKHelixManager;
import org.apache.helix.manager.zk.ZkClient;
import org.apache.helix.mock.participant.DummyProcess.DummyLeaderStandbyStateModelFactory;
import org.apache.helix.mock.participant.DummyProcess.DummyOnlineOfflineStateModelFactory;
+import org.apache.helix.mock.participant.MockJobIntf;
import org.apache.helix.mock.participant.MockMSModelFactory;
import org.apache.helix.mock.participant.MockSchemataModelFactory;
import org.apache.helix.mock.participant.MockTransition;
import org.apache.helix.participant.StateMachineEngine;
import org.apache.log4j.Logger;
-public class MockParticipantManager extends ParticipantManager implements Runnable, ZkTestManager {
+public class MockParticipantManager extends ZKHelixManager implements Runnable, ZkTestManager {
private static Logger LOG = Logger.getLogger(MockParticipantManager.class);
private final CountDownLatch _startCountDown = new CountDownLatch(1);
@@ -43,7 +45,7 @@ public class MockParticipantManager extends ParticipantManager implements Runnab
private final MockMSModelFactory _msModelFactory = new MockMSModelFactory(null);
public MockParticipantManager(String zkAddr, String clusterName, String instanceName) {
- super(zkAddr, clusterName, instanceName);
+ super(clusterName, instanceName, InstanceType.PARTICIPANT, zkAddr);
}
public void setTransition(MockTransition transition) {
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/manager/TestConsecutiveZkSessionExpiry.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/manager/TestConsecutiveZkSessionExpiry.java b/helix-core/src/test/java/org/apache/helix/integration/manager/TestConsecutiveZkSessionExpiry.java
index 296181b..8625c0c 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/manager/TestConsecutiveZkSessionExpiry.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/manager/TestConsecutiveZkSessionExpiry.java
@@ -30,7 +30,6 @@ import org.apache.helix.ZNRecord;
import org.apache.helix.ZkTestHelper;
import org.apache.helix.ZkUnitTestBase;
import org.apache.helix.manager.zk.CallbackHandler;
-import org.apache.helix.manager.zk.DistributedControllerManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
import org.apache.helix.mock.participant.MockMSModelFactory;
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/manager/TestDistributedControllerManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/manager/TestDistributedControllerManager.java b/helix-core/src/test/java/org/apache/helix/integration/manager/TestDistributedControllerManager.java
index b5ef255..aa00a8d 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/manager/TestDistributedControllerManager.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/manager/TestDistributedControllerManager.java
@@ -22,14 +22,16 @@ package org.apache.helix.integration.manager;
import java.util.Date;
import java.util.List;
+import org.apache.helix.HelixManager;
+import org.apache.helix.InstanceType;
import org.apache.helix.PropertyKey;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.ZkTestHelper;
import org.apache.helix.integration.ZkIntegrationTestBase;
import org.apache.helix.manager.zk.CallbackHandler;
-import org.apache.helix.manager.zk.DistributedControllerManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
+import org.apache.helix.manager.zk.ZKHelixManager;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
import org.apache.helix.mock.participant.MockMSModelFactory;
import org.apache.helix.model.LiveInstance;
@@ -61,11 +63,12 @@ public class TestDistributedControllerManager extends ZkIntegrationTestBase {
2, // replicas
"MasterSlave", true); // do rebalance
- DistributedControllerManager[] distributedControllers = new DistributedControllerManager[n];
+ HelixManager[] distributedControllers = new HelixManager[n];
for (int i = 0; i < n; i++) {
int port = 12918 + i;
distributedControllers[i] =
- new DistributedControllerManager(ZK_ADDR, clusterName, "localhost_" + port);
+ new ZKHelixManager(clusterName, "localhost_" + port, InstanceType.CONTROLLER_PARTICIPANT,
+ ZK_ADDR);
distributedControllers[i].getStateMachineEngine().registerStateModelFactory("MasterSlave",
new MockMSModelFactory());
distributedControllers[i].connect();
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/manager/TestParticipantManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/manager/TestParticipantManager.java b/helix-core/src/test/java/org/apache/helix/integration/manager/TestParticipantManager.java
index 85dc029..73945fe 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/manager/TestParticipantManager.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/manager/TestParticipantManager.java
@@ -24,6 +24,8 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.helix.HelixManager;
+import org.apache.helix.InstanceType;
import org.apache.helix.NotificationContext;
import org.apache.helix.PropertyKey;
import org.apache.helix.PropertyPathConfig;
@@ -32,9 +34,8 @@ import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.ZkTestHelper;
import org.apache.helix.integration.ZkIntegrationTestBase;
-import org.apache.helix.manager.zk.ControllerManager;
-import org.apache.helix.manager.zk.ParticipantManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
+import org.apache.helix.manager.zk.ZKHelixManager;
import org.apache.helix.manager.zk.ZNRecordSerializer;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
import org.apache.helix.mock.participant.MockMSModelFactory;
@@ -70,13 +71,14 @@ public class TestParticipantManager extends ZkIntegrationTestBase {
1, // replicas
"MasterSlave", true); // do rebalance
- ParticipantManager participant =
- new ParticipantManager(ZK_ADDR, clusterName, "localhost_12918");
+ HelixManager participant =
+ new ZKHelixManager(clusterName, "localhost_12918", InstanceType.PARTICIPANT, ZK_ADDR);
participant.getStateMachineEngine().registerStateModelFactory("MasterSlave",
new MockMSModelFactory());
participant.connect();
- ControllerManager controller = new ControllerManager(ZK_ADDR, clusterName, "controller_0");
+ HelixManager controller =
+ new ZKHelixManager(clusterName, "controller_0", InstanceType.CONTROLLER, ZK_ADDR);
controller.connect();
boolean result =
@@ -121,8 +123,9 @@ public class TestParticipantManager extends ZkIntegrationTestBase {
"MasterSlave", true); // do rebalance
// start controller
- ControllerManager controller = new ControllerManager(ZK_ADDR, clusterName, "controller_0");
- controller.connect();
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+ controller.syncStart();
// start participants
for (int i = 0; i < n; i++) {
@@ -151,7 +154,7 @@ public class TestParticipantManager extends ZkIntegrationTestBase {
Assert.assertNotSame(newSessionId, oldSessionId);
// cleanup
- controller.disconnect();
+ controller.syncStop();
for (int i = 0; i < n; i++) {
participants[i].syncStop();
}
@@ -207,8 +210,9 @@ public class TestParticipantManager extends ZkIntegrationTestBase {
"MasterSlave", true); // do rebalance
// start controller
- ControllerManager controller = new ControllerManager(ZK_ADDR, clusterName, "controller_0");
- controller.connect();
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+ controller.syncStart();
// start participants
for (int i = 0; i < n; i++) {
@@ -245,7 +249,7 @@ public class TestParticipantManager extends ZkIntegrationTestBase {
Assert.assertTrue(errString.indexOf("InterruptedException") != -1);
// cleanup
- controller.disconnect();
+ controller.syncStop();
for (int i = 0; i < n; i++) {
participants[i].syncStop();
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/josql/TestJosqlProcessor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/josql/TestJosqlProcessor.java b/helix-core/src/test/java/org/apache/helix/josql/TestJosqlProcessor.java
index aabc2b9..c70f984 100644
--- a/helix-core/src/test/java/org/apache/helix/josql/TestJosqlProcessor.java
+++ b/helix-core/src/test/java/org/apache/helix/josql/TestJosqlProcessor.java
@@ -41,8 +41,8 @@ public class TestJosqlProcessor extends ZkStandAloneCMTestBase {
"integrationTest"
})
public void testJosqlQuery() throws Exception {
- HelixManager manager =
- ((TestHelper.StartCMResult) (_startCMResultMap.values().toArray()[0]))._manager;
+ HelixManager manager = _participants[0];
+ // ((TestHelper.StartCMResult) (_startCMResultMap.values().toArray()[0]))._manager;
// Find the instance name that contains partition TestDB_2 and state is 'MASTER'
String SQL =
@@ -184,8 +184,8 @@ public class TestJosqlProcessor extends ZkStandAloneCMTestBase {
@Test(groups = ("unitTest"))
public void testOrderby() throws Exception {
- HelixManager manager =
- ((TestHelper.StartCMResult) (_startCMResultMap.values().toArray()[0]))._manager;
+ HelixManager manager = _participants[0];
+ // ((TestHelper.StartCMResult) (_startCMResultMap.values().toArray()[0]))._manager;
Map<String, ZNRecord> scnMap = new HashMap<String, ZNRecord>();
for (int i = 0; i < NODE_NR; i++) {
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/manager/zk/TestDefaultControllerMsgHandlerFactory.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestDefaultControllerMsgHandlerFactory.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestDefaultControllerMsgHandlerFactory.java
index a6aeb03..47245e0 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestDefaultControllerMsgHandlerFactory.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestDefaultControllerMsgHandlerFactory.java
@@ -30,10 +30,13 @@ import org.apache.helix.manager.zk.DefaultControllerMessageHandlerFactory.Defaul
import org.apache.helix.messaging.handling.MessageHandler;
import org.apache.helix.model.Message;
import org.apache.helix.model.Message.MessageType;
+import org.apache.log4j.Logger;
import org.testng.AssertJUnit;
import org.testng.annotations.Test;
public class TestDefaultControllerMsgHandlerFactory {
+ private static Logger LOG = Logger.getLogger(TestDefaultControllerMsgHandlerFactory.class);
+
@Test()
public void testDefaultControllerMsgHandlerFactory() {
System.out.println("START TestDefaultControllerMsgHandlerFactory at "
@@ -70,8 +73,7 @@ public class TestDefaultControllerMsgHandlerFactory {
} catch (HelixException e) {
exceptionCaught = true;
} catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.error("Interrupted handling message", e);
}
AssertJUnit.assertTrue(exceptionCaught);
@@ -83,8 +85,7 @@ public class TestDefaultControllerMsgHandlerFactory {
} catch (HelixException e) {
exceptionCaught = true;
} catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.error("Interrupted handling message", e);
}
AssertJUnit.assertFalse(exceptionCaught);
System.out.println("END TestDefaultControllerMsgHandlerFactory at "
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/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 f9afe91..352cdd5 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
@@ -21,11 +21,10 @@ package org.apache.helix.manager.zk;
import java.util.Date;
-import org.apache.helix.InstanceType;
import org.apache.helix.TestHelper;
import org.apache.helix.ZkTestHelper;
import org.apache.helix.integration.ZkIntegrationTestBase;
-import org.apache.helix.manager.zk.ZKHelixManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -48,17 +47,17 @@ public class TestHandleNewSession extends ZkIntegrationTestBase {
3, // replicas
"MasterSlave", true); // do rebalance
- ZKHelixManager manager =
- new ZKHelixManager(clusterName, "localhost_12918", InstanceType.PARTICIPANT, ZK_ADDR);
- manager.connect();
+ MockParticipantManager participant =
+ new MockParticipantManager(ZK_ADDR, clusterName, "localhost_12918");
+ participant.syncStart();
// Logger.getRootLogger().setLevel(Level.INFO);
- String lastSessionId = manager.getSessionId();
+ String lastSessionId = participant.getSessionId();
for (int i = 0; i < 3; i++) {
// System.err.println("curSessionId: " + lastSessionId);
- ZkTestHelper.expireSession(manager._zkClient);
+ ZkTestHelper.expireSession(participant.getZkClient());
- String sessionId = manager.getSessionId();
+ String sessionId = participant.getSessionId();
Assert.assertTrue(sessionId.compareTo(lastSessionId) > 0,
"Session id should be increased after expiry");
lastSessionId = sessionId;
@@ -72,7 +71,7 @@ public class TestHandleNewSession extends ZkIntegrationTestBase {
// Logger.getRootLogger().setLevel(Level.INFO);
System.out.println("Disconnecting ...");
- manager.disconnect();
+ participant.syncStop();
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/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 23fdbfa..547e863 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
@@ -19,12 +19,8 @@ package org.apache.helix.manager.zk;
* under the License.
*/
-import org.apache.helix.TestHelper;
-import org.apache.helix.TestHelper.StartCMResult;
-import org.apache.helix.ZkHelixTestManager;
-import org.apache.helix.integration.ZkStandAloneCMTestBase;
import org.apache.helix.integration.ZkStandAloneCMTestBaseWithPropertyServerCheck;
-import org.apache.helix.manager.zk.ZKHelixManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.tools.ClusterStateVerifier;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -32,24 +28,20 @@ import org.testng.annotations.Test;
public class TestLiveInstanceBounce extends ZkStandAloneCMTestBaseWithPropertyServerCheck {
@Test
public void testInstanceBounce() throws Exception {
- String controllerName = CONTROLLER_PREFIX + "_0";
- StartCMResult controllerResult = _startCMResultMap.get(controllerName);
- ZkHelixTestManager controller = (ZkHelixTestManager) controllerResult._manager;
- int handlerSize = controller.getHandlers().size();
+ int handlerSize = _controller.getHandlers().size();
for (int i = 0; i < 2; i++) {
String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
// kill 2 participants
- _startCMResultMap.get(instanceName)._manager.disconnect();
- _startCMResultMap.get(instanceName)._thread.interrupt();
+ _participants[i].syncStop();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// restart the participant
- StartCMResult result = TestHelper.startDummyProcess(ZK_ADDR, CLUSTER_NAME, instanceName);
- _startCMResultMap.put(instanceName, result);
+ _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
+ _participants[i].syncStart();
Thread.sleep(100);
}
Thread.sleep(4000);
@@ -63,11 +55,11 @@ public class TestLiveInstanceBounce extends ZkStandAloneCMTestBaseWithPropertySe
// and we will remove current-state listener on expired session
// so the number of callback handlers is unchanged
for (int j = 0; j < 10; j++) {
- if (controller.getHandlers().size() == (handlerSize)) {
+ if (_controller.getHandlers().size() == (handlerSize)) {
break;
}
Thread.sleep(400);
}
- Assert.assertEquals(controller.getHandlers().size(), handlerSize);
+ Assert.assertEquals(_controller.getHandlers().size(), handlerSize);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZKPropertyTransferServer.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZKPropertyTransferServer.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZKPropertyTransferServer.java
index f40445e..50a9a78 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZKPropertyTransferServer.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZKPropertyTransferServer.java
@@ -20,11 +20,9 @@ package org.apache.helix.manager.zk;
*/
import org.apache.helix.HelixDataAccessor;
-import org.apache.helix.TestHelper;
-import org.apache.helix.TestHelper.StartCMResult;
-import org.apache.helix.controller.HelixControllerMain;
import org.apache.helix.controller.restlet.ZKPropertyTransferServer;
import org.apache.helix.integration.ZkStandAloneCMTestBaseWithPropertyServerCheck;
+import org.apache.helix.integration.manager.ClusterControllerManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.log4j.Logger;
import org.testng.Assert;
@@ -36,34 +34,28 @@ public class TestZKPropertyTransferServer extends ZkStandAloneCMTestBaseWithProp
@Test
public void TestControllerChange() throws Exception {
String controllerName = CONTROLLER_PREFIX + "_0";
- _startCMResultMap.get(controllerName)._manager.disconnect();
+ _controller.syncStop();
Thread.sleep(1000);
// kill controller, participant should not know about the svc url
for (int i = 0; i < NODE_NR; i++) {
- String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
HelixDataAccessor accessor =
- _startCMResultMap.get(instanceName)._manager.getHelixDataAccessor();
+ _participants[i].getHelixDataAccessor();
ZKHelixDataAccessor zkAccessor = (ZKHelixDataAccessor) accessor;
Assert.assertTrue(zkAccessor._zkPropertyTransferSvcUrl == null
|| zkAccessor._zkPropertyTransferSvcUrl.equals(""));
}
- _startCMResultMap.get(controllerName)._thread.interrupt();
- _startCMResultMap.remove(controllerName);
- StartCMResult startResult =
- TestHelper.startController(CLUSTER_NAME, controllerName, ZK_ADDR,
- HelixControllerMain.STANDALONE);
- _startCMResultMap.put(controllerName, startResult);
+ _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
+ _controller.syncStart();
Thread.sleep(1000);
// create controller again, the svc url is notified to the participants
for (int i = 0; i < NODE_NR; i++) {
- String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
HelixDataAccessor accessor =
- _startCMResultMap.get(instanceName)._manager.getHelixDataAccessor();
+ _participants[i].getHelixDataAccessor();
ZKHelixDataAccessor zkAccessor = (ZKHelixDataAccessor) accessor;
Assert.assertTrue(zkAccessor._zkPropertyTransferSvcUrl.equals(ZKPropertyTransferServer
.getInstance().getWebserviceUrl()));
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/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 7809711..9496963 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
@@ -27,6 +27,7 @@ import java.util.List;
import java.util.Map;
import org.apache.helix.AccessOption;
+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;
@@ -35,12 +36,12 @@ import org.apache.helix.model.builder.HelixConfigScopeBuilder;
import org.apache.helix.HelixAdmin;
import org.apache.helix.HelixDataAccessor;
import org.apache.helix.HelixException;
+import org.apache.helix.HelixManager;
import org.apache.helix.InstanceType;
import org.apache.helix.LiveInstanceInfoProvider;
import org.apache.helix.PropertyKey.Builder;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
-import org.apache.helix.ZkHelixTestManager;
import org.apache.helix.ZkTestHelper;
import org.apache.helix.ZkUnitTestBase;
import org.apache.helix.manager.MockListener;
@@ -68,6 +69,7 @@ public class TestZkClusterManager extends ZkUnitTestBase {
ZKHelixManager controller =
new ZKHelixManager(clusterName, null, InstanceType.CONTROLLER, ZK_ADDR);
+
try {
controller.connect();
Assert.fail("Should throw HelixException if initial cluster structure is not setup");
@@ -196,8 +198,9 @@ public class TestZkClusterManager extends ZkUnitTestBase {
// //////////////////////////////////
- ZkHelixTestManager manager2 =
- new ZkHelixTestManager(clusterName, "localhost_3", InstanceType.PARTICIPANT, ZK_ADDR);
+ MockParticipantManager manager2 =
+ new MockParticipantManager(ZK_ADDR, clusterName, "localhost_3");
+
manager2.setLiveInstanceInfoProvider(new provider(true));
manager2.connect();
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/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 b10fb96..37709fc 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
@@ -13,8 +13,8 @@ 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.mock.controller.ClusterController;
-import org.apache.helix.mock.participant.MockParticipant;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.model.LiveInstance;
import org.apache.zookeeper.Watcher.Event.KeeperState;
import org.testng.Assert;
@@ -134,10 +134,11 @@ public class TestZkFlapping extends ZkUnitTestBase {
"MasterSlave", false);
final String instanceName = "localhost_12918";
- MockParticipant participant = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ MockParticipantManager participant =
+ new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participant.syncStart();
- final ZkClient client = participant.getManager().getZkClient();
+ final ZkClient client = participant.getZkClient();
final ZkStateCountListener listener = new ZkStateCountListener();
client.subscribeStateChanges(listener);
@@ -212,10 +213,11 @@ public class TestZkFlapping extends ZkUnitTestBase {
1, // replicas
"MasterSlave", false);
- ClusterController controller = new ClusterController(clusterName, "controller", ZK_ADDR);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller");
controller.syncStart();
- final ZkClient client = controller.getManager().getZkClient();
+ final ZkClient client = controller.getZkClient();
final ZkStateCountListener listener = new ZkStateCountListener();
client.subscribeStateChanges(listener);
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkManagerFlappingDetection.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkManagerFlappingDetection.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkManagerFlappingDetection.java
index 249fcea..a62e39d 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkManagerFlappingDetection.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkManagerFlappingDetection.java
@@ -19,13 +19,12 @@ package org.apache.helix.manager.zk;
* under the License.
*/
-import java.util.UUID;
-import org.apache.helix.InstanceType;
import org.apache.helix.TestHelper;
-import org.apache.helix.ZkHelixTestManager;
import org.apache.helix.ZkTestHelper;
import org.apache.helix.integration.ZkIntegrationTestBase;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -46,8 +45,8 @@ public class TestZkManagerFlappingDetection extends ZkIntegrationTestBase {
"MasterSlave", true); // do rebalance
String instanceName = "localhost_" + (12918 + 0);
- ZkHelixTestManager manager =
- new ZkHelixTestManager(clusterName, instanceName, InstanceType.PARTICIPANT, ZK_ADDR);
+ MockParticipantManager manager = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+
manager.connect();
ZkClient zkClient = manager.getZkClient();
ZkTestHelper.expireSession(zkClient);
@@ -69,58 +68,59 @@ public class TestZkManagerFlappingDetection extends ZkIntegrationTestBase {
Assert.assertFalse(manager.isConnected());
}
- @Test(enabled = false)
- public void testDisconnectFlappingWindow() throws Exception {
- String className = TestHelper.getTestClassName();
- String methodName = TestHelper.getTestMethodName();
- String instanceName = "localhost_" + (12918 + 1);
- final String clusterName = className + "_" + methodName + UUID.randomUUID();
-
- testDisconnectFlappingWindow2(instanceName, InstanceType.PARTICIPANT);
- testDisconnectFlappingWindow2("admin", InstanceType.ADMINISTRATOR);
- }
-
- public void testDisconnectFlappingWindow2(String instanceName, InstanceType type)
- throws Exception {
- String className = TestHelper.getTestClassName();
- String methodName = TestHelper.getTestMethodName();
- final String clusterName = className + "_" + methodName + UUID.randomUUID();
-
- TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
- "localhost", // participant name prefix
- "TestDB", // resource name prefix
- 1, // resources
- 10, // partitions per resource
- 5, // number of nodes
- 3, // replicas
- "MasterSlave", true); // do rebalance
-
- // flapping time window to 5 sec
- System.setProperty("helixmanager.flappingTimeWindow", "15000");
- System.setProperty("helixmanager.maxDisconnectThreshold", "7");
- ZkHelixTestManager manager2 = new ZkHelixTestManager(clusterName, instanceName, type, ZK_ADDR);
- manager2.connect();
- ZkClient zkClient = manager2.getZkClient();
- for (int i = 0; i < 3; i++) {
- ZkTestHelper.expireSession(zkClient);
- Thread.sleep(500);
- Assert.assertTrue(manager2.isConnected());
- }
- Thread.sleep(15000);
- // Old entries should be cleaned up
- for (int i = 0; i < 7; i++) {
- ZkTestHelper.expireSession(zkClient);
- Thread.sleep(1000);
- Assert.assertTrue(manager2.isConnected());
- }
- ZkTestHelper.disconnectSession(zkClient);
- for (int i = 0; i < 20; i++) {
- Thread.sleep(500);
- if (!manager2.isConnected())
- break;
- }
- Assert.assertFalse(manager2.isConnected());
- }
+ // TODO test was disabled. check if it is still needed
+ // @Test(enabled = false)
+ // public void testDisconnectFlappingWindow() throws Exception {
+ // String className = TestHelper.getTestClassName();
+ // String methodName = TestHelper.getTestMethodName();
+ // String instanceName = "localhost_" + (12918 + 1);
+ // final String clusterName = className + "_" + methodName + UUID.randomUUID();
+ //
+ // testDisconnectFlappingWindow2(instanceName, InstanceType.PARTICIPANT);
+ // testDisconnectFlappingWindow2("admin", InstanceType.ADMINISTRATOR);
+ // }
+ //
+ // public void testDisconnectFlappingWindow2(String instanceName, InstanceType type)
+ // throws Exception {
+ // String className = TestHelper.getTestClassName();
+ // String methodName = TestHelper.getTestMethodName();
+ // final String clusterName = className + "_" + methodName + UUID.randomUUID();
+ //
+ // TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
+ // "localhost", // participant name prefix
+ // "TestDB", // resource name prefix
+ // 1, // resources
+ // 10, // partitions per resource
+ // 5, // number of nodes
+ // 3, // replicas
+ // "MasterSlave", true); // do rebalance
+ //
+ // // flapping time window to 5 sec
+ // System.setProperty("helixmanager.flappingTimeWindow", "15000");
+ // System.setProperty("helixmanager.maxDisconnectThreshold", "7");
+ // ZkHelixTestManager manager2 = new ZkHelixTestManager(clusterName, instanceName, type, ZK_ADDR);
+ // manager2.connect();
+ // ZkClient zkClient = manager2.getZkClient();
+ // for (int i = 0; i < 3; i++) {
+ // ZkTestHelper.expireSession(zkClient);
+ // Thread.sleep(500);
+ // Assert.assertTrue(manager2.isConnected());
+ // }
+ // Thread.sleep(15000);
+ // // Old entries should be cleaned up
+ // for (int i = 0; i < 7; i++) {
+ // ZkTestHelper.expireSession(zkClient);
+ // Thread.sleep(1000);
+ // Assert.assertTrue(manager2.isConnected());
+ // }
+ // ZkTestHelper.disconnectSession(zkClient);
+ // for (int i = 0; i < 20; i++) {
+ // Thread.sleep(500);
+ // if (!manager2.isConnected())
+ // break;
+ // }
+ // Assert.assertFalse(manager2.isConnected());
+ // }
// @Test
public void testDisconnectFlappingWindowController() throws Exception {
@@ -140,8 +140,7 @@ public class TestZkManagerFlappingDetection extends ZkIntegrationTestBase {
// flapping time window to 5 sec
System.setProperty("helixmanager.flappingTimeWindow", "5000");
System.setProperty("helixmanager.maxDisconnectThreshold", "3");
- ZkHelixTestManager manager2 =
- new ZkHelixTestManager(clusterName, null, InstanceType.CONTROLLER, ZK_ADDR);
+ ClusterControllerManager manager2 = new ClusterControllerManager(ZK_ADDR, clusterName, null);
manager2.connect();
Thread.sleep(100);
ZkClient zkClient = manager2.getZkClient();
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkStateChangeListener.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkStateChangeListener.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkStateChangeListener.java
index c208cbf..98ce3a4 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkStateChangeListener.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestZkStateChangeListener.java
@@ -19,68 +19,70 @@ package org.apache.helix.manager.zk;
* under the License.
*/
-import org.apache.helix.TestHelper.StartCMResult;
import org.apache.helix.integration.ZkStandAloneCMTestBaseWithPropertyServerCheck;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.apache.zookeeper.Watcher.Event.KeeperState;
public class TestZkStateChangeListener extends ZkStandAloneCMTestBaseWithPropertyServerCheck {
- @Test
+ // TODO this test has been covered by TestZkFlapping. check if still needed
+ // @Test
public void testDisconnectHistory() throws Exception {
- String controllerName = CONTROLLER_PREFIX + "_0";
- StartCMResult controllerResult = _startCMResultMap.get(controllerName);
- ZKHelixManager controller = (ZKHelixManager) controllerResult._manager;
- ZkStateChangeListener listener1 = new ZkStateChangeListener(controller, 5000, 10);
+ // String controllerName = CONTROLLER_PREFIX + "_0";
+ // StartCMResult controllerResult = _startCMResultMap.get(controllerName);
+ // ZKHelixManager controller = (ZKHelixManager) controllerResult._manager;
+ // ZkStateChangeListener listener1 = new ZkStateChangeListener(controller, 5000, 10);
+ // ZkStateChangeListener listener1 = new ZkStateChangeListener(_controller, 5000, 10);
+
// 11 disconnects in 5 sec
for (int i = 0; i < 11; i++) {
Thread.sleep(200);
- listener1.handleStateChanged(KeeperState.Disconnected);
+ _controller.handleStateChanged(KeeperState.Disconnected);
if (i < 10) {
- Assert.assertTrue(controller.isConnected());
+ Assert.assertTrue(_controller.isConnected());
} else {
- Assert.assertFalse(controller.isConnected());
+ Assert.assertFalse(_controller.isConnected());
}
}
// If maxDisconnectThreshold is 0 it should be set to 1
- String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + 0);
- ZKHelixManager manager = (ZKHelixManager) _startCMResultMap.get(instanceName)._manager;
+ // String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + 0);
+ // ZKHelixManager manager = (ZKHelixManager) _startCMResultMap.get(instanceName)._manager;
- ZkStateChangeListener listener2 = new ZkStateChangeListener(manager, 5000, 0);
+ // ZkStateChangeListener listener2 = new ZkStateChangeListener(_participants[0], 5000, 0);
for (int i = 0; i < 2; i++) {
Thread.sleep(200);
- listener2.handleStateChanged(KeeperState.Disconnected);
+ _participants[0].handleStateChanged(KeeperState.Disconnected);
if (i < 1) {
- Assert.assertTrue(manager.isConnected());
+ Assert.assertTrue(_participants[0].isConnected());
} else {
- Assert.assertFalse(manager.isConnected());
+ Assert.assertFalse(_participants[0].isConnected());
}
}
// If there are long time after disconnect, older history should be cleanup
- instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + 1);
- manager = (ZKHelixManager) _startCMResultMap.get(instanceName)._manager;
+ // instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + 1);
+ // manager = (ZKHelixManager) _startCMResultMap.get(instanceName)._manager;
- ZkStateChangeListener listener3 = new ZkStateChangeListener(manager, 5000, 5);
+ // ZkStateChangeListener listener3 = new ZkStateChangeListener(_participants[1], 5000, 5);
for (int i = 0; i < 3; i++) {
Thread.sleep(200);
- listener3.handleStateChanged(KeeperState.Disconnected);
- Assert.assertTrue(manager.isConnected());
+ _participants[1].handleStateChanged(KeeperState.Disconnected);
+ Assert.assertTrue(_participants[1].isConnected());
}
Thread.sleep(5000);
// Old entries should be cleaned up
for (int i = 0; i < 3; i++) {
Thread.sleep(200);
- listener3.handleStateChanged(KeeperState.Disconnected);
- Assert.assertTrue(manager.isConnected());
+ _participants[1].handleStateChanged(KeeperState.Disconnected);
+ Assert.assertTrue(_participants[1].isConnected());
}
for (int i = 0; i < 2; i++) {
Thread.sleep(200);
- listener3.handleStateChanged(KeeperState.Disconnected);
- Assert.assertTrue(manager.isConnected());
+ _participants[1].handleStateChanged(KeeperState.Disconnected);
+ Assert.assertTrue(_participants[1].isConnected());
}
- listener3.handleStateChanged(KeeperState.Disconnected);
- Assert.assertFalse(manager.isConnected());
+ _participants[1].handleStateChanged(KeeperState.Disconnected);
+ Assert.assertFalse(_participants[1].isConnected());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/messaging/handling/TestConfigThreadpoolSize.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/messaging/handling/TestConfigThreadpoolSize.java b/helix-core/src/test/java/org/apache/helix/messaging/handling/TestConfigThreadpoolSize.java
index 374f30d..c018f4c 100644
--- a/helix-core/src/test/java/org/apache/helix/messaging/handling/TestConfigThreadpoolSize.java
+++ b/helix-core/src/test/java/org/apache/helix/messaging/handling/TestConfigThreadpoolSize.java
@@ -77,7 +77,7 @@ public class TestConfigThreadpoolSize extends ZkStandAloneCMTestBase {
@Test
public void TestThreadPoolSizeConfig() {
String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + 0);
- HelixManager manager = _startCMResultMap.get(instanceName)._manager;
+ HelixManager manager = _participants[0];
ConfigAccessor accessor = manager.getConfigAccessor();
ConfigScope scope =
@@ -91,9 +91,9 @@ public class TestConfigThreadpoolSize extends ZkStandAloneCMTestBase {
for (int i = 0; i < NODE_NR; i++) {
instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
- _startCMResultMap.get(instanceName)._manager.getMessagingService()
- .registerMessageHandlerFactory("TestMsg", new TestMessagingHandlerFactory());
- _startCMResultMap.get(instanceName)._manager.getMessagingService()
+ _participants[i].getMessagingService().registerMessageHandlerFactory("TestMsg",
+ new TestMessagingHandlerFactory());
+ _participants[i].getMessagingService()
.registerMessageHandlerFactory("TestMsg2", new TestMessagingHandlerFactory2());
}
@@ -102,7 +102,7 @@ public class TestConfigThreadpoolSize extends ZkStandAloneCMTestBase {
instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
DefaultMessagingService svc =
- (DefaultMessagingService) (_startCMResultMap.get(instanceName)._manager
+ (DefaultMessagingService) (_participants[i]
.getMessagingService());
HelixTaskExecutor helixExecutor = svc.getExecutor();
ThreadPoolExecutor executor =
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/messaging/handling/TestResourceThreadpoolSize.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/messaging/handling/TestResourceThreadpoolSize.java b/helix-core/src/test/java/org/apache/helix/messaging/handling/TestResourceThreadpoolSize.java
index 7ce677d..c7f1276 100644
--- a/helix-core/src/test/java/org/apache/helix/messaging/handling/TestResourceThreadpoolSize.java
+++ b/helix-core/src/test/java/org/apache/helix/messaging/handling/TestResourceThreadpoolSize.java
@@ -35,8 +35,7 @@ import org.testng.annotations.Test;
public class TestResourceThreadpoolSize extends ZkStandAloneCMTestBase {
@Test
public void TestThreadPoolSizeConfig() {
- String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + 0);
- HelixManager manager = _startCMResultMap.get(instanceName)._manager;
+ HelixManager manager = _participants[0];
ConfigAccessor accessor = manager.getConfigAccessor();
ConfigScope scope =
new ConfigScopeBuilder().forCluster(manager.getClusterName()).forResource("NextDB").build();
@@ -52,11 +51,8 @@ public class TestResourceThreadpoolSize extends ZkStandAloneCMTestBase {
long taskcount = 0;
for (int i = 0; i < NODE_NR; i++) {
- instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
-
DefaultMessagingService svc =
- (DefaultMessagingService) (_startCMResultMap.get(instanceName)._manager
- .getMessagingService());
+ (DefaultMessagingService) (_participants[i].getMessagingService());
HelixTaskExecutor helixExecutor = svc.getExecutor();
ThreadPoolExecutor executor =
(ThreadPoolExecutor) (helixExecutor._executorMap.get(MessageType.STATE_TRANSITION + "."
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/mock/controller/ClusterController.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/mock/controller/ClusterController.java b/helix-core/src/test/java/org/apache/helix/mock/controller/ClusterController.java
deleted file mode 100644
index ae0a7fd..0000000
--- a/helix-core/src/test/java/org/apache/helix/mock/controller/ClusterController.java
+++ /dev/null
@@ -1,129 +0,0 @@
-package org.apache.helix.mock.controller;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.concurrent.CountDownLatch;
-
-import org.apache.helix.HelixManager;
-import org.apache.helix.HelixManagerFactory;
-import org.apache.helix.InstanceType;
-import org.apache.helix.ZkHelixTestManager;
-import org.apache.helix.controller.HelixControllerMain;
-import org.apache.helix.participant.DistClusterControllerStateModelFactory;
-import org.apache.helix.participant.StateMachineEngine;
-import org.apache.log4j.Logger;
-
-public class ClusterController extends Thread {
- private static Logger LOG = Logger.getLogger(ClusterController.class);
-
- private final CountDownLatch _startCountDown = new CountDownLatch(1);
- private final CountDownLatch _stopCountDown = new CountDownLatch(1);
- private final CountDownLatch _waitStopFinishCountDown = new CountDownLatch(1);
- private final String _controllerMode;
- private final String _zkAddr;
-
- private ZkHelixTestManager _manager;
-
- public ClusterController(String clusterName, String controllerName, String zkAddr)
- throws Exception {
- this(clusterName, controllerName, zkAddr, HelixControllerMain.STANDALONE.toString());
- }
-
- public ClusterController(String clusterName, String controllerName, String zkAddr,
- String controllerMode) throws Exception {
- _controllerMode = controllerMode;
- _zkAddr = zkAddr;
-
- if (_controllerMode.equals(HelixControllerMain.STANDALONE.toString())) {
- _manager =
- new ZkHelixTestManager(clusterName, controllerName, InstanceType.CONTROLLER, zkAddr);
- } else if (_controllerMode.equals(HelixControllerMain.DISTRIBUTED.toString())) {
- _manager =
- new ZkHelixTestManager(clusterName, controllerName, InstanceType.CONTROLLER_PARTICIPANT,
- zkAddr);
- } else {
- throw new IllegalArgumentException("Controller mode: " + controllerMode + " NOT recoginized");
- }
- }
-
- public ZkHelixTestManager getManager() {
- return _manager;
- }
-
- public void syncStop() {
- if (_manager == null) {
- LOG.warn("manager already stopped");
- return;
- }
-
- _stopCountDown.countDown();
- try {
- _waitStopFinishCountDown.await();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- public void syncStart() {
- // TODO: prevent start multiple times
-
- super.start();
- try {
- _startCountDown.await();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- @Override
- public void run() {
- try {
- try {
- if (_controllerMode.equals(HelixControllerMain.STANDALONE.toString())) {
- _manager.connect();
- } else if (_controllerMode.equals(HelixControllerMain.DISTRIBUTED.toString())) {
- DistClusterControllerStateModelFactory stateModelFactory =
- new DistClusterControllerStateModelFactory(_zkAddr);
-
- StateMachineEngine stateMach = _manager.getStateMachineEngine();
- stateMach.registerStateModelFactory("LeaderStandby", stateModelFactory);
- _manager.connect();
- }
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- _startCountDown.countDown();
- _stopCountDown.await();
- }
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- synchronized (_manager) {
- _manager.disconnect();
- _manager = null;
- }
- _waitStopFinishCountDown.countDown();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/mock/participant/MockHealthReportParticipant.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/mock/participant/MockHealthReportParticipant.java b/helix-core/src/test/java/org/apache/helix/mock/participant/MockHealthReportParticipant.java
index 59d9a0a..31811bb 100644
--- a/helix-core/src/test/java/org/apache/helix/mock/participant/MockHealthReportParticipant.java
+++ b/helix-core/src/test/java/org/apache/helix/mock/participant/MockHealthReportParticipant.java
@@ -33,6 +33,7 @@ import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.helix.HelixManager;
import org.apache.helix.healthcheck.HealthReportProvider;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.log4j.Logger;
public class MockHealthReportParticipant {
@@ -209,9 +210,9 @@ public class MockHealthReportParticipant {
// NOT working for kill -9, working for kill -2/-15
static class MockHealthReportParticipantShutdownHook extends Thread {
- final MockParticipant _participant;
+ final MockParticipantManager _participant;
- MockHealthReportParticipantShutdownHook(MockParticipant participant) {
+ MockHealthReportParticipantShutdownHook(MockParticipantManager participant) {
_participant = participant;
}
@@ -231,12 +232,11 @@ public class MockHealthReportParticipant {
String instanceName = hostStr + "_" + portStr;
- MockParticipant participant =
- new MockParticipant(clusterName, instanceName, zkConnectStr, null, // new
- // StoreAccessDiffNodeTransition(),
- // // new
- // StoreAccessOneNodeTransition(),
- new MockHealthReportJob());
+ MockParticipantManager participant =
+ new MockParticipantManager(zkConnectStr, clusterName, instanceName);
+ // participant.setTransition(new StoreAccessDiffNodeTransition());
+ // participant.setTransition(new StoreAccessOneNodeTransition()));
+ // new MockHealthReportJob());
Runtime.getRuntime().addShutdownHook(new MockHealthReportParticipantShutdownHook(participant));
// Espresso_driver.py will consume this
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/mock/participant/MockParticipant.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/mock/participant/MockParticipant.java b/helix-core/src/test/java/org/apache/helix/mock/participant/MockParticipant.java
deleted file mode 100644
index 9eb4bb9..0000000
--- a/helix-core/src/test/java/org/apache/helix/mock/participant/MockParticipant.java
+++ /dev/null
@@ -1,197 +0,0 @@
-package org.apache.helix.mock.participant;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.CountDownLatch;
-
-import org.I0Itec.zkclient.DataUpdater;
-import org.I0Itec.zkclient.exception.ZkNoNodeException;
-import org.apache.helix.AccessOption;
-import org.apache.helix.HelixManager;
-import org.apache.helix.HelixManagerFactory;
-import org.apache.helix.InstanceType;
-import org.apache.helix.NotificationContext;
-import org.apache.helix.ZNRecord;
-import org.apache.helix.ZkHelixTestManager;
-import org.apache.helix.mock.participant.DummyProcess.DummyLeaderStandbyStateModelFactory;
-import org.apache.helix.mock.participant.DummyProcess.DummyOnlineOfflineStateModelFactory;
-import org.apache.helix.model.Message;
-import org.apache.helix.participant.StateMachineEngine;
-import org.apache.helix.participant.statemachine.StateModel;
-import org.apache.helix.participant.statemachine.StateModelFactory;
-import org.apache.helix.participant.statemachine.StateModelInfo;
-import org.apache.helix.participant.statemachine.Transition;
-import org.apache.helix.store.zk.ZkHelixPropertyStore;
-import org.apache.log4j.Logger;
-
-public class MockParticipant extends Thread {
- private static Logger LOG = Logger.getLogger(MockParticipant.class);
- private final String _clusterName;
- private final String _instanceName;
- // private final String _zkAddr;
-
- private final CountDownLatch _startCountDown = new CountDownLatch(1);
- private final CountDownLatch _stopCountDown = new CountDownLatch(1);
- private final CountDownLatch _waitStopFinishCountDown = new CountDownLatch(1);
-
- private final ZkHelixTestManager _manager;
- private final StateModelFactory _msModelFactory;
- private final MockJobIntf _job;
-
- public MockParticipant(String clusterName, String instanceName, String zkAddr) throws Exception {
- this(clusterName, instanceName, zkAddr, null, null);
- }
-
- public MockParticipant(String clusterName, String instanceName, String zkAddr,
- MockTransition transition) throws Exception {
- this(clusterName, instanceName, zkAddr, transition, null);
- }
-
- public MockParticipant(String clusterName, String instanceName, String zkAddr,
- MockTransition transition, MockJobIntf job) throws Exception {
- _clusterName = clusterName;
- _instanceName = instanceName;
- _msModelFactory = new MockMSModelFactory(transition);
-
- _manager =
- new ZkHelixTestManager(_clusterName, _instanceName, InstanceType.PARTICIPANT, zkAddr);
- _job = job;
- }
-
- public MockParticipant(StateModelFactory factory, String clusterName, String instanceName,
- String zkAddr, MockJobIntf job) throws Exception {
- _clusterName = clusterName;
- _instanceName = instanceName;
- _msModelFactory = factory;
-
- _manager =
- new ZkHelixTestManager(_clusterName, _instanceName, InstanceType.PARTICIPANT, zkAddr);
- _job = job;
- }
-
- public StateModelFactory getStateModelFactory() {
- return _msModelFactory;
- }
-
- public MockParticipant(ZkHelixTestManager manager, MockTransition transition) {
- _clusterName = manager.getClusterName();
- _instanceName = manager.getInstanceName();
- _manager = manager;
-
- _msModelFactory = new MockMSModelFactory(transition);
- _job = null;
- }
-
- public void setTransition(MockTransition transition) {
- if (_msModelFactory instanceof MockMSModelFactory) {
- ((MockMSModelFactory) _msModelFactory).setTrasition(transition);
- }
- }
-
- public ZkHelixTestManager getManager() {
- return _manager;
- }
-
- public String getInstanceName() {
- return _instanceName;
- }
-
- public String getClusterName() {
- return _clusterName;
- }
-
- public void syncStop() {
- _stopCountDown.countDown();
- try {
- _waitStopFinishCountDown.await();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- // synchronized (_manager)
- // {
- // _manager.disconnect();
- // }
- }
-
- public void syncStart() {
- super.start();
- try {
- _startCountDown.await();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- @Override
- public void run() {
- try {
- StateMachineEngine stateMach = _manager.getStateMachineEngine();
- stateMach.registerStateModelFactory("MasterSlave", _msModelFactory);
-
- DummyLeaderStandbyStateModelFactory lsModelFactory =
- new DummyLeaderStandbyStateModelFactory(10);
- DummyOnlineOfflineStateModelFactory ofModelFactory =
- new DummyOnlineOfflineStateModelFactory(10);
- stateMach.registerStateModelFactory("LeaderStandby", lsModelFactory);
- stateMach.registerStateModelFactory("OnlineOffline", ofModelFactory);
-
- MockSchemataModelFactory schemataFactory = new MockSchemataModelFactory();
- stateMach.registerStateModelFactory("STORAGE_DEFAULT_SM_SCHEMATA", schemataFactory);
- // MockBootstrapModelFactory bootstrapFactory = new MockBootstrapModelFactory();
- // stateMach.registerStateModelFactory("Bootstrap", bootstrapFactory);
-
- if (_job != null) {
- _job.doPreConnectJob(_manager);
- }
-
- _manager.connect();
- _startCountDown.countDown();
-
- if (_job != null) {
- _job.doPostConnectJob(_manager);
- }
-
- _stopCountDown.await();
- } catch (InterruptedException e) {
- String msg =
- "participant: " + _instanceName + ", " + Thread.currentThread().getName()
- + " is interrupted";
- LOG.info(msg);
- System.err.println(msg);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- _startCountDown.countDown();
-
- synchronized (_manager) {
- _manager.disconnect();
- }
- _waitStopFinishCountDown.countDown();
- }
- }
-}
[08/10] git commit: [HELIX-279] Apply gc handling fixes to main
ZKHelixManager class
Posted by zz...@apache.org.
[HELIX-279] Apply gc handling fixes to main ZKHelixManager class
Project: http://git-wip-us.apache.org/repos/asf/incubator-helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-helix/commit/579baa5b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-helix/tree/579baa5b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-helix/diff/579baa5b
Branch: refs/heads/helix-0.6.2-release
Commit: 579baa5bb061bec9d5b38731f20f51ea29a05f42
Parents: 0c3796b
Author: zzhang <zz...@apache.org>
Authored: Thu Oct 24 15:40:55 2013 -0700
Committer: zzhang <zz...@apache.org>
Committed: Thu Oct 24 15:40:55 2013 -0700
----------------------------------------------------------------------
.../tools/TestHelixAdminScenariosRest.java | 889 +++++++++------
.../apache/helix/tools/TestResetInstance.java | 21 +-
.../helix/tools/TestResetPartitionState.java | 24 +-
.../apache/helix/tools/TestResetResource.java | 22 +-
.../org/apache/helix/agent/TestHelixAgent.java | 29 +-
.../java/org/apache/helix/HelixManager.java | 9 +-
.../java/org/apache/helix/HelixProperty.java | 7 +-
.../helix/manager/zk/AbstractManager.java | 693 ------------
.../helix/manager/zk/ControllerManager.java | 175 ---
.../manager/zk/ControllerManagerHelper.java | 6 +-
.../zk/DistributedControllerManager.java | 190 ----
.../manager/zk/DistributedLeaderElection.java | 16 +-
.../helix/manager/zk/ParticipantManager.java | 155 ---
.../manager/zk/ParticipantManagerHelper.java | 27 +-
.../apache/helix/manager/zk/ZKHelixManager.java | 1039 +++++++++---------
.../helix/manager/zk/ZkAsyncCallbacks.java | 3 +-
.../helix/manager/zk/ZkStateChangeListener.java | 127 ---
.../src/test/java/org/apache/helix/Mocks.java | 6 +
.../test/java/org/apache/helix/TestHelper.java | 101 +-
.../apache/helix/TestShuffledIdealState.java | 68 +-
.../org/apache/helix/TestZkClientWrapper.java | 45 +-
.../java/org/apache/helix/TestZnodeModify.java | 3 +-
.../org/apache/helix/ZkHelixTestManager.java | 44 -
.../controller/stages/DummyClusterManager.java | 6 +
.../stages/TestParseInfoFromAlert.java | 18 +-
.../stages/TestRebalancePipeline.java | 17 +-
.../helix/healthcheck/TestAddDropAlert.java | 35 +-
.../healthcheck/TestAlertActionTriggering.java | 21 +-
.../helix/healthcheck/TestAlertFireHistory.java | 37 +-
.../helix/healthcheck/TestDummyAlerts.java | 14 +-
.../helix/healthcheck/TestExpandAlert.java | 40 +-
.../helix/healthcheck/TestSimpleAlert.java | 40 +-
.../healthcheck/TestSimpleWildcardAlert.java | 42 +-
.../helix/healthcheck/TestStalenessAlert.java | 36 +-
.../helix/healthcheck/TestWildcardAlert.java | 36 +-
.../helix/integration/TestAddClusterV2.java | 80 +-
.../TestAddNodeAfterControllerStart.java | 58 +-
.../TestAddStateModelFactoryAfterConnect.java | 17 +-
.../integration/TestAutoIsWithEmptyMap.java | 14 +-
.../helix/integration/TestAutoRebalance.java | 66 +-
.../TestAutoRebalancePartitionLimit.java | 87 +-
.../helix/integration/TestBatchMessage.java | 50 +-
.../integration/TestBatchMessageWrapper.java | 18 +-
.../integration/TestBucketizedResource.java | 15 +-
.../integration/TestCarryOverBadCurState.java | 19 +-
.../integration/TestCleanupExternalView.java | 20 +-
.../helix/integration/TestClusterStartsup.java | 15 +-
.../helix/integration/TestCustomIdealState.java | 12 -
.../TestCustomizedIdealStateRebalancer.java | 6 +-
.../apache/helix/integration/TestDisable.java | 36 +-
.../helix/integration/TestDisableNode.java | 2 +-
.../helix/integration/TestDisablePartition.java | 2 +-
.../integration/TestDistributedCMMain.java | 18 +-
.../TestDistributedClusterController.java | 18 +-
.../apache/helix/integration/TestDriver.java | 75 +-
.../org/apache/helix/integration/TestDrop.java | 85 +-
.../helix/integration/TestDropResource.java | 9 +-
.../TestEnablePartitionDuringDisable.java | 22 +-
.../helix/integration/TestErrorPartition.java | 28 +-
.../integration/TestExternalViewUpdates.java | 21 +-
.../integration/TestHelixCustomCodeRunner.java | 42 +-
.../helix/integration/TestHelixInstanceTag.java | 3 +-
.../helix/integration/TestInstanceAutoJoin.java | 25 +-
.../integration/TestInvalidAutoIdealState.java | 14 +-
.../TestMessagePartitionStateMismatch.java | 4 +-
.../helix/integration/TestMessageThrottle.java | 22 +-
.../helix/integration/TestMessageThrottle2.java | 4 +-
.../helix/integration/TestMessagingService.java | 81 +-
.../integration/TestNonOfflineInitState.java | 27 +-
.../helix/integration/TestNullReplica.java | 15 +-
.../TestParticipantErrorMessage.java | 14 +-
.../TestParticipantNameCollision.java | 9 +-
.../helix/integration/TestPauseSignal.java | 15 +-
.../helix/integration/TestRenamePartition.java | 47 +-
.../helix/integration/TestResetInstance.java | 18 +-
.../integration/TestResetPartitionState.java | 17 +-
.../helix/integration/TestResetResource.java | 18 +-
.../integration/TestRestartParticipant.java | 41 +-
.../helix/integration/TestSchedulerMessage.java | 76 +-
.../helix/integration/TestSchemataSM.java | 14 +-
.../TestSessionExpiryInTransition.java | 27 +-
.../helix/integration/TestStandAloneCMMain.java | 40 +-
.../TestStandAloneCMSessionExpiry.java | 21 +-
...estStartMultipleControllersWithSameName.java | 9 +-
.../integration/TestStateTransitionTimeout.java | 40 +-
.../helix/integration/TestSwapInstance.java | 16 +-
.../integration/TestZkCallbackHandlerLeak.java | 88 +-
.../integration/ZkIntegrationTestBase.java | 49 +-
.../integration/ZkStandAloneCMTestBase.java | 63 +-
...dAloneCMTestBaseWithPropertyServerCheck.java | 25 +-
.../manager/ClusterControllerManager.java | 17 +-
.../manager/ClusterDistributedController.java | 20 +-
.../manager/MockParticipantManager.java | 8 +-
.../manager/TestConsecutiveZkSessionExpiry.java | 1 -
.../TestDistributedControllerManager.java | 9 +-
.../manager/TestParticipantManager.java | 26 +-
.../apache/helix/josql/TestJosqlProcessor.java | 8 +-
.../TestDefaultControllerMsgHandlerFactory.java | 9 +-
.../helix/manager/zk/TestHandleNewSession.java | 17 +-
.../manager/zk/TestLiveInstanceBounce.java | 22 +-
.../zk/TestZKPropertyTransferServer.java | 20 +-
.../helix/manager/zk/TestZkClusterManager.java | 9 +-
.../apache/helix/manager/zk/TestZkFlapping.java | 14 +-
.../zk/TestZkManagerFlappingDetection.java | 117 +-
.../manager/zk/TestZkStateChangeListener.java | 54 +-
.../handling/TestConfigThreadpoolSize.java | 10 +-
.../handling/TestResourceThreadpoolSize.java | 8 +-
.../mock/controller/ClusterController.java | 129 ---
.../MockHealthReportParticipant.java | 16 +-
.../helix/mock/participant/MockParticipant.java | 197 ----
.../helix/participant/MockZKHelixManager.java | 6 +
.../TestDistControllerStateModel.java | 12 +-
.../apache/helix/tools/TestHelixAdminCli.java | 162 +--
113 files changed, 2477 insertions(+), 4132 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestHelixAdminScenariosRest.java
----------------------------------------------------------------------
diff --git a/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestHelixAdminScenariosRest.java b/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestHelixAdminScenariosRest.java
index 4730e76..55693b7 100644
--- a/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestHelixAdminScenariosRest.java
+++ b/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestHelixAdminScenariosRest.java
@@ -19,24 +19,19 @@ package org.apache.helix.tools;
* under the License.
*/
-/*
- * Simulate all the admin tasks needed by using command line tool
- *
- * */
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import org.apache.helix.HelixDataAccessor;
-import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
-import org.apache.helix.TestHelper.StartCMResult;
-import org.apache.helix.controller.HelixControllerMain;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.ClusterDistributedController;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKUtil;
import org.apache.helix.model.ExternalView;
import org.apache.helix.model.IdealState.IdealStateProperty;
@@ -66,8 +61,10 @@ import org.restlet.resource.Representation;
import org.testng.Assert;
import org.testng.annotations.Test;
+/**
+ * Simulate all the admin tasks needed by using command line tool
+ */
public class TestHelixAdminScenariosRest extends AdminTestBase {
- Map<String, StartCMResult> _startCMResultMap = new HashMap<String, StartCMResult>();
RestAdminApplication _adminApp;
Component _component;
String _tag1 = "tag1123";
@@ -92,55 +89,6 @@ public class TestHelixAdminScenariosRest extends AdminTestBase {
return mapper.readValue(sr, clazz);
}
- @Test
- public void testAddDeleteClusterAndInstanceAndResource() throws Exception {
- // Helix bug helix-102
- // ZKPropertyTransferServer.PERIOD = 500;
- // ZkPropertyTransferClient.SEND_PERIOD = 500;
- // ZKPropertyTransferServer.getInstance().init(19999, ZK_ADDR);
-
- /** ======================= Add clusters ============================== */
-
- testAddCluster();
-
- /** ================= Add / drop some resources =========================== */
-
- testAddResource();
-
- /** ====================== Add / delete instances =========================== */
-
- testAddInstance();
-
- /** ===================== Rebalance resource =========================== */
-
- testRebalanceResource();
-
- /** ==================== start the clusters ============================= */
-
- testStartCluster();
-
- /** ==================== drop add resource in live clusters =================== */
- testDropAddResource();
-
- /** ======================Operations with live node ============================ */
-
- testInstanceOperations();
-
- /** ======================Operations with partitions ============================ */
-
- testEnablePartitions();
-
- /** ============================ expand cluster =========================== */
-
- testExpandCluster();
-
- /** ============================ deactivate cluster =========================== */
- testDeactivateCluster();
-
- // wait all zk callbacks done
- Thread.sleep(1000);
- }
-
static String assertSuccessPostOperation(String url, Map<String, String> jsonParameters,
boolean hasException) throws IOException {
Reference resourceRef = new Reference(url);
@@ -228,41 +176,46 @@ public class TestHelixAdminScenariosRest extends AdminTestBase {
Assert.assertTrue(exceptionThrown);
}
+ private Map<String, String> addClusterCmd(String clusterName) {
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put(JsonParameters.CLUSTER_NAME, clusterName);
+ parameters.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addCluster);
+
+ return parameters;
+ }
+
+ private void addCluster(String clusterName) throws IOException {
+ String url = "http://localhost:" + ADMIN_PORT + "/clusters";
+ String response = assertSuccessPostOperation(url, addClusterCmd(clusterName), false);
+ Assert.assertTrue(response.contains(clusterName));
+ }
+
+ @Test
public void testAddCluster() throws Exception {
String url = "http://localhost:" + ADMIN_PORT + "/clusters";
- Map<String, String> paraMap = new HashMap<String, String>();
// Normal add
- paraMap.put(JsonParameters.CLUSTER_NAME, "clusterTest");
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addCluster);
-
- String response = assertSuccessPostOperation(url, paraMap, false);
+ String response = assertSuccessPostOperation(url, addClusterCmd("clusterTest"), false);
Assert.assertTrue(response.contains("clusterTest"));
// malformed cluster name
- paraMap.put(JsonParameters.CLUSTER_NAME, "/ClusterTest");
- response = assertSuccessPostOperation(url, paraMap, true);
+ response = assertSuccessPostOperation(url, addClusterCmd("/ClusterTest"), true);
// Add the grand cluster
- paraMap.put(JsonParameters.CLUSTER_NAME, "Klazt3rz");
- response = assertSuccessPostOperation(url, paraMap, false);
+ response = assertSuccessPostOperation(url, addClusterCmd("Klazt3rz"), false);
Assert.assertTrue(response.contains("Klazt3rz"));
- paraMap.put(JsonParameters.CLUSTER_NAME, "\\ClusterTest");
- response = assertSuccessPostOperation(url, paraMap, false);
+ response = assertSuccessPostOperation(url, addClusterCmd("\\ClusterTest"), false);
Assert.assertTrue(response.contains("\\ClusterTest"));
// Add already exist cluster
- paraMap.put(JsonParameters.CLUSTER_NAME, "clusterTest");
- response = assertSuccessPostOperation(url, paraMap, true);
+ response = assertSuccessPostOperation(url, addClusterCmd("clusterTest"), true);
// delete cluster without resource and instance
Assert.assertTrue(ZKUtil.isClusterSetup("Klazt3rz", _gZkClient));
Assert.assertTrue(ZKUtil.isClusterSetup("clusterTest", _gZkClient));
Assert.assertTrue(ZKUtil.isClusterSetup("\\ClusterTest", _gZkClient));
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.dropCluster);
-
String clusterUrl = getClusterUrl("\\ClusterTest");
deleteUrl(clusterUrl, false);
@@ -286,94 +239,180 @@ public class TestHelixAdminScenariosRest extends AdminTestBase {
Assert.assertFalse(_gZkClient.exists("/clusterTest1"));
Assert.assertFalse(_gZkClient.exists("/clusterTestOK"));
- paraMap.put(JsonParameters.CLUSTER_NAME, "clusterTest1");
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addCluster);
- response = assertSuccessPostOperation(url, paraMap, false);
+ response = assertSuccessPostOperation(url, addClusterCmd("clusterTest1"), false);
response = getUrl(clustersUrl);
Assert.assertTrue(response.contains("clusterTest1"));
}
- public void testAddResource() throws Exception {
- String reourcesUrl = "http://localhost:" + ADMIN_PORT + "/clusters/clusterTest1/resourceGroups";
+ private Map<String, String> addResourceCmd(String resourceName, String stateModelDef,
+ int partition) {
+ Map<String, String> parameters = new HashMap<String, String>();
- Map<String, String> paraMap = new HashMap<String, String>();
- paraMap.put(JsonParameters.RESOURCE_GROUP_NAME, "db_22");
- paraMap.put(JsonParameters.STATE_MODEL_DEF_REF, "MasterSlave");
- paraMap.put(JsonParameters.PARTITIONS, "144");
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addResource);
+ parameters.put(JsonParameters.RESOURCE_GROUP_NAME, resourceName);
+ parameters.put(JsonParameters.STATE_MODEL_DEF_REF, stateModelDef);
+ parameters.put(JsonParameters.PARTITIONS, "" + partition);
+ parameters.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addResource);
- String response = assertSuccessPostOperation(reourcesUrl, paraMap, false);
- Assert.assertTrue(response.contains("db_22"));
+ return parameters;
+ }
+
+ private void addResource(String clusterName, String resourceName, int partitions)
+ throws IOException {
+ final String reourcesUrl =
+ "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/resourceGroups";
+ String response =
+ assertSuccessPostOperation(reourcesUrl,
+ addResourceCmd(resourceName, "MasterSlave", partitions), false);
+ Assert.assertTrue(response.contains(resourceName));
+ }
- paraMap.put(JsonParameters.RESOURCE_GROUP_NAME, "db_11");
- paraMap.put(JsonParameters.STATE_MODEL_DEF_REF, "MasterSlave");
- paraMap.put(JsonParameters.PARTITIONS, "44");
+ @Test
+ public void testAddResource() throws Exception {
+ final String clusterName = "clusterTestAddResource";
+ addCluster(clusterName);
+
+ String reourcesUrl =
+ "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/resourceGroups";
+ String response =
+ assertSuccessPostOperation(reourcesUrl, addResourceCmd("db_22", "MasterSlave", 144), false);
+ Assert.assertTrue(response.contains("db_22"));
- response = assertSuccessPostOperation(reourcesUrl, paraMap, false);
+ response =
+ assertSuccessPostOperation(reourcesUrl, addResourceCmd("db_11", "MasterSlave", 44), false);
Assert.assertTrue(response.contains("db_11"));
// Add duplicate resource
- paraMap.put(JsonParameters.RESOURCE_GROUP_NAME, "db_22");
- paraMap.put(JsonParameters.STATE_MODEL_DEF_REF, "OnlineOffline");
- paraMap.put(JsonParameters.PARTITIONS, "55");
-
- response = assertSuccessPostOperation(reourcesUrl, paraMap, true);
+ response =
+ assertSuccessPostOperation(reourcesUrl, addResourceCmd("db_22", "OnlineOffline", 55), true);
// drop resource now
- String resourceUrl = getResourceUrl("clusterTest1", "db_11");
+ String resourceUrl = getResourceUrl(clusterName, "db_11");
deleteUrl(resourceUrl, false);
- Assert.assertFalse(_gZkClient.exists("/clusterTest1/IDEALSTATES/db_11"));
+ Assert.assertFalse(_gZkClient.exists("/" + clusterName + "/IDEALSTATES/db_11"));
- paraMap.put(JsonParameters.RESOURCE_GROUP_NAME, "db_11");
- paraMap.put(JsonParameters.STATE_MODEL_DEF_REF, "MasterSlave");
- paraMap.put(JsonParameters.PARTITIONS, "44");
- response = assertSuccessPostOperation(reourcesUrl, paraMap, false);
+ response =
+ assertSuccessPostOperation(reourcesUrl, addResourceCmd("db_11", "MasterSlave", 44), false);
Assert.assertTrue(response.contains("db_11"));
- Assert.assertTrue(_gZkClient.exists("/clusterTest1/IDEALSTATES/db_11"));
+ Assert.assertTrue(_gZkClient.exists("/" + clusterName + "/IDEALSTATES/db_11"));
- paraMap.put(JsonParameters.RESOURCE_GROUP_NAME, "db_33");
- response = assertSuccessPostOperation(reourcesUrl, paraMap, false);
+ response =
+ assertSuccessPostOperation(reourcesUrl, addResourceCmd("db_33", "MasterSlave", 44), false);
Assert.assertTrue(response.contains("db_33"));
- paraMap.put(JsonParameters.RESOURCE_GROUP_NAME, "db_44");
- response = assertSuccessPostOperation(reourcesUrl, paraMap, false);
+ response =
+ assertSuccessPostOperation(reourcesUrl, addResourceCmd("db_44", "MasterSlave", 44), false);
Assert.assertTrue(response.contains("db_44"));
}
- private void testDeactivateCluster() throws Exception, InterruptedException {
- HelixDataAccessor accessor;
- String path;
- // deactivate cluster
- String clusterUrl = getClusterUrl("clusterTest1");
- Map<String, String> paraMap = new HashMap<String, String>();
- paraMap.put(JsonParameters.ENABLED, "false");
- paraMap.put(JsonParameters.GRAND_CLUSTER, "Klazt3rz");
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.activateCluster);
+ private Map<String, String> activateClusterCmd(String grandClusterName, boolean enabled) {
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put(JsonParameters.GRAND_CLUSTER, grandClusterName);
+ parameters.put(JsonParameters.ENABLED, "" + enabled);
+ parameters.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.activateCluster);
- String response = assertSuccessPostOperation(clusterUrl, paraMap, false);
+ return parameters;
+ }
+
+ @Test
+ public void testDeactivateCluster() throws Exception {
+ final String clusterName = "clusterTestDeactivateCluster";
+ final String controllerClusterName = "controllerClusterTestDeactivateCluster";
+
+ Map<String, MockParticipantManager> participants =
+ new HashMap<String, MockParticipantManager>();
+ Map<String, ClusterDistributedController> distControllers =
+ new HashMap<String, ClusterDistributedController>();
+
+ // setup cluster
+ addCluster(clusterName);
+ addInstancesToCluster(clusterName, "localhost:123", 6, null);
+ addResource(clusterName, "db_11", 16);
+ rebalanceResource(clusterName, "db_11");
+
+ addCluster(controllerClusterName);
+ addInstancesToCluster(controllerClusterName, "controller_900", 2, null);
+
+ // start mock nodes
+ for (int i = 0; i < 6; i++) {
+ String instanceName = "localhost_123" + i;
+ MockParticipantManager participant =
+ new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participant.syncStart();
+ participants.put(instanceName, participant);
+ }
+
+ // start controller nodes
+ for (int i = 0; i < 2; i++) {
+ String controllerName = "controller_900" + i;
+ ClusterDistributedController distController =
+ new ClusterDistributedController(ZK_ADDR, controllerClusterName, controllerName);
+ distController.syncStart();
+ distControllers.put(controllerName, distController);
+ }
+
+ String clusterUrl = getClusterUrl(clusterName);
+
+ // activate cluster
+ assertSuccessPostOperation(clusterUrl, activateClusterCmd(controllerClusterName, true), false);
+ boolean verifyResult =
+ ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
+ controllerClusterName));
+ Assert.assertTrue(verifyResult);
+
+ verifyResult =
+ ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
+ clusterName));
+ Assert.assertTrue(verifyResult);
+
+ // deactivate cluster
+ assertSuccessPostOperation(clusterUrl, activateClusterCmd(controllerClusterName, false), false);
Thread.sleep(6000);
- Assert.assertFalse(_gZkClient.exists("/Klazt3rz/IDEALSTATES/clusterTest1"));
+ Assert.assertFalse(_gZkClient.exists("/" + controllerClusterName + "/IDEALSTATES/"
+ + clusterName));
- accessor = _startCMResultMap.get("localhost_1231")._manager.getHelixDataAccessor();
- path = accessor.keyBuilder().controllerLeader().getPath();
+ HelixDataAccessor accessor = participants.get("localhost_1231").getHelixDataAccessor();
+ String path = accessor.keyBuilder().controllerLeader().getPath();
Assert.assertFalse(_gZkClient.exists(path));
deleteUrl(clusterUrl, true);
+ Assert.assertTrue(_gZkClient.exists("/" + clusterName));
- Assert.assertTrue(_gZkClient.exists("/clusterTest1"));
// leader node should be gone
- for (StartCMResult result : _startCMResultMap.values()) {
- result._manager.disconnect();
- result._thread.interrupt();
+ for (MockParticipantManager participant : participants.values()) {
+ participant.syncStop();
}
deleteUrl(clusterUrl, false);
- Assert.assertFalse(_gZkClient.exists("/clusterTest1"));
+ Assert.assertFalse(_gZkClient.exists("/" + clusterName));
+
+ // clean up
+ for (ClusterDistributedController controller : distControllers.values()) {
+ controller.syncStop();
+ }
+
+ for (MockParticipantManager participant : participants.values()) {
+ participant.syncStop();
+ }
+ }
+
+ private Map<String, String> addIdealStateCmd() {
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addIdealState);
+
+ return parameters;
}
- private void testDropAddResource() throws Exception {
- ZNRecord record = _gSetupTool._admin.getResourceIdealState("clusterTest1", "db_11").getRecord();
+ @Test
+ public void testDropAddResource() throws Exception {
+ final String clusterName = "clusterTestDropAddResource";
+
+ // setup cluster
+ addCluster(clusterName);
+ addResource(clusterName, "db_11", 22);
+ addInstancesToCluster(clusterName, "localhost_123", 6, null);
+ rebalanceResource(clusterName, "db_11");
+ ZNRecord record = _gSetupTool._admin.getResourceIdealState(clusterName, "db_11").getRecord();
String x = ObjectToJson(record);
FileWriter fos = new FileWriter("/tmp/temp.log");
@@ -381,217 +420,370 @@ public class TestHelixAdminScenariosRest extends AdminTestBase {
pw.write(x);
pw.close();
- String resourceUrl = getResourceUrl("clusterTest1", "db_11");
- deleteUrl(resourceUrl, false);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_9900");
+ controller.syncStart();
+ // start mock nodes
+ Map<String, MockParticipantManager> participants =
+ new HashMap<String, MockParticipantManager>();
+ for (int i = 0; i < 6; i++) {
+ String instanceName = "localhost_123" + i;
+ MockParticipantManager participant =
+ new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participant.syncStart();
+ participants.put(instanceName, participant);
+ }
boolean verifyResult =
ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
- "clusterTest1"));
+ clusterName));
Assert.assertTrue(verifyResult);
- Map<String, String> paraMap = new HashMap<String, String>();
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addResource);
- paraMap.put(JsonParameters.RESOURCE_GROUP_NAME, "db_11");
- paraMap.put(JsonParameters.PARTITIONS, "22");
- paraMap.put(JsonParameters.STATE_MODEL_DEF_REF, "MasterSlave");
- String response =
- assertSuccessPostOperation(getClusterUrl("clusterTest1") + "/resourceGroups", paraMap,
- false);
- String idealStateUrl = getResourceUrl("clusterTest1", "db_11") + "/idealState";
- Assert.assertTrue(response.contains("db_11"));
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addIdealState);
+ String resourceUrl = getResourceUrl(clusterName, "db_11");
+ deleteUrl(resourceUrl, false);
+
+ verifyResult =
+ ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
+ clusterName));
+ Assert.assertTrue(verifyResult);
+ addResource(clusterName, "db_11", 22);
+
+ String idealStateUrl = getResourceUrl(clusterName, "db_11") + "/idealState";
Map<String, String> extraform = new HashMap<String, String>();
extraform.put(JsonParameters.NEW_IDEAL_STATE, x);
- response = assertSuccessPostOperation(idealStateUrl, paraMap, extraform, false);
+ assertSuccessPostOperation(idealStateUrl, addIdealStateCmd(), extraform, false);
verifyResult =
ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
- "clusterTest1"));
+ clusterName));
Assert.assertTrue(verifyResult);
- ZNRecord record2 =
- _gSetupTool._admin.getResourceIdealState("clusterTest1", "db_11").getRecord();
+ ZNRecord record2 = _gSetupTool._admin.getResourceIdealState(clusterName, "db_11").getRecord();
Assert.assertTrue(record2.equals(record));
+
+ // clean up
+ controller.syncStop();
+ for (MockParticipantManager participant : participants.values()) {
+ participant.syncStop();
+ }
}
- private void testExpandCluster() throws Exception {
- boolean verifyResult;
+ private Map<String, String> addInstanceCmd(String instances) {
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put(JsonParameters.INSTANCE_NAMES, instances);
+ parameters.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addInstance);
- String clusterUrl = getClusterUrl("clusterTest1");
- String instancesUrl = clusterUrl + "/instances";
+ return parameters;
+ }
+
+ private Map<String, String> expandClusterCmd() {
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.expandCluster);
+
+ return parameters;
+ }
+
+ @Test
+ public void testExpandCluster() throws Exception {
- Map<String, String> paraMap = new HashMap<String, String>();
- paraMap.put(JsonParameters.INSTANCE_NAMES,
- "localhost:12331;localhost:12341;localhost:12351;localhost:12361");
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addInstance);
+ final String clusterName = "clusterTestExpandCluster";
- String response = assertSuccessPostOperation(instancesUrl, paraMap, false);
- String[] hosts = "localhost:12331;localhost:12341;localhost:12351;localhost:12361".split(";");
+ // setup cluster
+ addCluster(clusterName);
+ addInstancesToCluster(clusterName, "localhost:123", 6, null);
+ addResource(clusterName, "db_11", 22);
+ rebalanceResource(clusterName, "db_11");
+
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_9900");
+ controller.syncStart();
+
+ // start mock nodes
+ Map<String, MockParticipantManager> participants =
+ new HashMap<String, MockParticipantManager>();
+ for (int i = 0; i < 6; i++) {
+ String instanceName = "localhost_123" + i;
+ MockParticipantManager participant =
+ new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participant.syncStart();
+ participants.put(instanceName, participant);
+ }
+
+ boolean verifyResult =
+ ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
+ clusterName));
+ Assert.assertTrue(verifyResult);
+
+ String clusterUrl = getClusterUrl(clusterName);
+ String instancesUrl = clusterUrl + "/instances";
+
+ String instances = "localhost:12331;localhost:12341;localhost:12351;localhost:12361";
+ String response = assertSuccessPostOperation(instancesUrl, addInstanceCmd(instances), false);
+ String[] hosts = instances.split(";");
for (String host : hosts) {
Assert.assertTrue(response.contains(host.replace(':', '_')));
}
- paraMap.clear();
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.expandCluster);
- response = assertSuccessPostOperation(clusterUrl, paraMap, false);
+
+ response = assertSuccessPostOperation(clusterUrl, expandClusterCmd(), false);
for (int i = 3; i <= 6; i++) {
- StartCMResult result =
- TestHelper.startDummyProcess(ZK_ADDR, "clusterTest1", "localhost_123" + i + "1");
- _startCMResultMap.put("localhost_123" + i + "1", result);
+ String instanceName = "localhost_123" + i + "1";
+ MockParticipantManager participant =
+ new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participant.syncStart();
+ participants.put(instanceName, participant);
}
verifyResult =
- ClusterStateVerifier.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR,
- "clusterTest1"));
+ ClusterStateVerifier
+ .verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(verifyResult);
verifyResult =
ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
- "clusterTest1"));
+ clusterName));
Assert.assertTrue(verifyResult);
+
+ // clean up
+ controller.syncStop();
+ for (MockParticipantManager participant : participants.values()) {
+ participant.syncStop();
+ }
}
- private void testEnablePartitions() throws IOException, InterruptedException {
- HelixDataAccessor accessor;
- accessor = _startCMResultMap.get("localhost_1231")._manager.getHelixDataAccessor();
+ private Map<String, String> enablePartitionCmd(String resourceName, String partitions,
+ boolean enabled) {
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.enablePartition);
+ parameters.put(JsonParameters.ENABLED, "" + enabled);
+ parameters.put(JsonParameters.PARTITION, partitions);
+ parameters.put(JsonParameters.RESOURCE, resourceName);
+
+ return parameters;
+ }
+
+ @Test
+ public void testEnablePartitions() throws IOException, InterruptedException {
+ final String clusterName = "clusterTestEnablePartitions";
+
+ // setup cluster
+ addCluster(clusterName);
+ addInstancesToCluster(clusterName, "localhost:123", 6, null);
+ addResource(clusterName, "db_11", 22);
+ rebalanceResource(clusterName, "db_11");
+
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_9900");
+ controller.syncStart();
+
+ // start mock nodes
+ Map<String, MockParticipantManager> participants =
+ new HashMap<String, MockParticipantManager>();
+ for (int i = 0; i < 6; i++) {
+ String instanceName = "localhost_123" + i;
+ MockParticipantManager participant =
+ new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participant.syncStart();
+ participants.put(instanceName, participant);
+ }
+
+ HelixDataAccessor accessor = participants.get("localhost_1231").getHelixDataAccessor();
// drop node should fail as not disabled
String hostName = "localhost_1231";
- String instanceUrl = getInstanceUrl("clusterTest1", hostName);
+ String instanceUrl = getInstanceUrl(clusterName, hostName);
ExternalView ev = accessor.getProperty(accessor.keyBuilder().externalView("db_11"));
- Map<String, String> paraMap = new HashMap<String, String>();
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.enablePartition);
- paraMap.put(JsonParameters.ENABLED, "false");
- paraMap.put(JsonParameters.PARTITION, "db_11_0;db_11_15");
- paraMap.put(JsonParameters.RESOURCE, "db_11");
-
- String response = assertSuccessPostOperation(instanceUrl, paraMap, false);
+ String response =
+ assertSuccessPostOperation(instanceUrl,
+ enablePartitionCmd("db_11", "db_11_0;db_11_11", false), false);
Assert.assertTrue(response.contains("DISABLED_PARTITION"));
Assert.assertTrue(response.contains("db_11_0"));
- Assert.assertTrue(response.contains("db_11_15"));
+ Assert.assertTrue(response.contains("db_11_11"));
boolean verifyResult =
ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
- "clusterTest1"));
+ clusterName));
Assert.assertTrue(verifyResult);
ev = accessor.getProperty(accessor.keyBuilder().externalView("db_11"));
Assert.assertEquals(ev.getStateMap("db_11_0").get(hostName), "OFFLINE");
- Assert.assertEquals(ev.getStateMap("db_11_15").get(hostName), "OFFLINE");
+ Assert.assertEquals(ev.getStateMap("db_11_11").get(hostName), "OFFLINE");
- paraMap.put(JsonParameters.ENABLED, "true");
- response = assertSuccessPostOperation(instanceUrl, paraMap, false);
+ response =
+ assertSuccessPostOperation(instanceUrl,
+ enablePartitionCmd("db_11", "db_11_0;db_11_11", true), false);
Assert.assertFalse(response.contains("db_11_0"));
- Assert.assertFalse(response.contains("db_11_15"));
+ Assert.assertFalse(response.contains("db_11_11"));
verifyResult =
ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
- "clusterTest1"));
+ clusterName));
Assert.assertTrue(verifyResult);
ev = accessor.getProperty(accessor.keyBuilder().externalView("db_11"));
Assert.assertEquals(ev.getStateMap("db_11_0").get(hostName), "MASTER");
- Assert.assertEquals(ev.getStateMap("db_11_15").get(hostName), "SLAVE");
+ Assert.assertEquals(ev.getStateMap("db_11_11").get(hostName), "SLAVE");
+
+ // clean up
+ controller.syncStop();
+ for (MockParticipantManager participant : participants.values()) {
+ participant.syncStop();
+ }
+ }
+
+ private Map<String, String> enableInstanceCmd(boolean enabled) {
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.enableInstance);
+ parameters.put(JsonParameters.ENABLED, "" + enabled);
+ return parameters;
}
- private void testInstanceOperations() throws Exception {
+ private Map<String, String> swapInstanceCmd(String oldInstance, String newInstance) {
+ Map<String, String> parameters = new HashMap<String, String>();
+
+ parameters.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.swapInstance);
+ parameters.put(JsonParameters.OLD_INSTANCE, oldInstance);
+ parameters.put(JsonParameters.NEW_INSTANCE, newInstance);
+
+ return parameters;
+ }
+
+ @Test
+ public void testInstanceOperations() throws Exception {
+ final String clusterName = "clusterTestInstanceOperations";
+
+ // setup cluster
+ addCluster(clusterName);
+ addInstancesToCluster(clusterName, "localhost:123", 6, null);
+ addResource(clusterName, "db_11", 8);
+ rebalanceResource(clusterName, "db_11");
+
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_9900");
+ controller.syncStart();
+
+ // start mock nodes
+ Map<String, MockParticipantManager> participants =
+ new HashMap<String, MockParticipantManager>();
+ for (int i = 0; i < 6; i++) {
+ String instanceName = "localhost_123" + i;
+ MockParticipantManager participant =
+ new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participant.syncStart();
+ participants.put(instanceName, participant);
+ }
+
HelixDataAccessor accessor;
// drop node should fail as not disabled
- String instanceUrl = getInstanceUrl("clusterTest1", "localhost_1232");
+ String instanceUrl = getInstanceUrl(clusterName, "localhost_1232");
deleteUrl(instanceUrl, true);
// disabled node
- Map<String, String> paraMap = new HashMap<String, String>();
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.enableInstance);
- paraMap.put(JsonParameters.ENABLED, "false");
- String response = assertSuccessPostOperation(instanceUrl, paraMap, false);
+ String response = assertSuccessPostOperation(instanceUrl, enableInstanceCmd(false), false);
Assert.assertTrue(response.contains("false"));
// Cannot drop / swap
deleteUrl(instanceUrl, true);
- String instancesUrl = getClusterUrl("clusterTest1") + "/instances";
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.swapInstance);
- paraMap.put(JsonParameters.OLD_INSTANCE, "localhost_1232");
- paraMap.put(JsonParameters.NEW_INSTANCE, "localhost_12320");
- response = assertSuccessPostOperation(instancesUrl, paraMap, true);
+ String instancesUrl = getClusterUrl(clusterName) + "/instances";
+ response =
+ assertSuccessPostOperation(instancesUrl,
+ swapInstanceCmd("localhost_1232", "localhost_12320"), true);
// disconnect the node
- _startCMResultMap.get("localhost_1232")._manager.disconnect();
- _startCMResultMap.get("localhost_1232")._thread.interrupt();
+ participants.get("localhost_1232").syncStop();
// add new node then swap instance
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addInstance);
- paraMap.put(JsonParameters.INSTANCE_NAME, "localhost_12320");
- response = assertSuccessPostOperation(instancesUrl, paraMap, false);
+ response = assertSuccessPostOperation(instancesUrl, addInstanceCmd("localhost_12320"), false);
Assert.assertTrue(response.contains("localhost_12320"));
// swap instance. The instance get swapped out should not exist anymore
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.swapInstance);
- paraMap.put(JsonParameters.OLD_INSTANCE, "localhost_1232");
- paraMap.put(JsonParameters.NEW_INSTANCE, "localhost_12320");
- response = assertSuccessPostOperation(instancesUrl, paraMap, false);
+ response =
+ assertSuccessPostOperation(instancesUrl,
+ swapInstanceCmd("localhost_1232", "localhost_12320"), false);
Assert.assertTrue(response.contains("localhost_12320"));
Assert.assertFalse(response.contains("localhost_1232\""));
- accessor = _startCMResultMap.get("localhost_1231")._manager.getHelixDataAccessor();
+ accessor = participants.get("localhost_1231").getHelixDataAccessor();
String path = accessor.keyBuilder().instanceConfig("localhost_1232").getPath();
Assert.assertFalse(_gZkClient.exists(path));
- _startCMResultMap.put("localhost_12320",
- TestHelper.startDummyProcess(ZK_ADDR, "clusterTest1", "localhost_12320"));
+ MockParticipantManager newParticipant =
+ new MockParticipantManager(ZK_ADDR, clusterName, "localhost_12320");
+ newParticipant.syncStart();
+ participants.put("localhost_12320", newParticipant);
+
+ boolean verifyResult =
+ ClusterStateVerifier
+ .verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, clusterName));
+ Assert.assertTrue(verifyResult);
+
+ // clean up
+ controller.syncStop();
+ for (MockParticipantManager participant : participants.values()) {
+ participant.syncStop();
+ }
}
- private void testStartCluster() throws Exception, InterruptedException {
+ @Test
+ public void testStartCluster() throws Exception {
+ final String clusterName = "clusterTestStartCluster";
+ final String controllerClusterName = "controllerClusterTestStartCluster";
+
+ Map<String, MockParticipantManager> participants =
+ new HashMap<String, MockParticipantManager>();
+ Map<String, ClusterDistributedController> distControllers =
+ new HashMap<String, ClusterDistributedController>();
+
+ // setup cluster
+ addCluster(clusterName);
+ addInstancesToCluster(clusterName, "localhost:123", 6, null);
+ addResource(clusterName, "db_11", 8);
+ rebalanceResource(clusterName, "db_11");
+
+ addCluster(controllerClusterName);
+ addInstancesToCluster(controllerClusterName, "controller_900", 2, null);
+
// start mock nodes
for (int i = 0; i < 6; i++) {
- StartCMResult result =
- TestHelper.startDummyProcess(ZK_ADDR, "clusterTest1", "localhost_123" + i);
- _startCMResultMap.put("localhost_123" + i, result);
+ String instanceName = "localhost_123" + i;
+ MockParticipantManager participant =
+ new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participant.syncStart();
+ participants.put(instanceName, participant);
}
// start controller nodes
for (int i = 0; i < 2; i++) {
- StartCMResult result =
- TestHelper.startController("Klazt3rz", "controller_900" + i, ZK_ADDR,
- HelixControllerMain.DISTRIBUTED);
-
- _startCMResultMap.put("controller_900" + i, result);
+ String controllerName = "controller_900" + i;
+ ClusterDistributedController distController =
+ new ClusterDistributedController(ZK_ADDR, controllerClusterName, controllerName);
+ distController.syncStart();
+ distControllers.put(controllerName, distController);
}
Thread.sleep(100);
// activate clusters
// wrong grand clustername
-
- String clusterUrl = getClusterUrl("clusterTest1");
- Map<String, String> paraMap = new HashMap<String, String>();
- paraMap.put(JsonParameters.ENABLED, "true");
- paraMap.put(JsonParameters.GRAND_CLUSTER, "Klazters");
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.activateCluster);
-
- String response = assertSuccessPostOperation(clusterUrl, paraMap, true);
+ String clusterUrl = getClusterUrl(clusterName);
+ assertSuccessPostOperation(clusterUrl, activateClusterCmd("nonExistCluster", true), true);
// wrong cluster name
- clusterUrl = getClusterUrl("clusterTest2");
- paraMap.put(JsonParameters.GRAND_CLUSTER, "Klazt3rz");
- response = assertSuccessPostOperation(clusterUrl, paraMap, true);
+ clusterUrl = getClusterUrl("nonExistCluster");
+ assertSuccessPostOperation(clusterUrl, activateClusterCmd(controllerClusterName, true), true);
- paraMap.put(JsonParameters.ENABLED, "true");
- paraMap.put(JsonParameters.GRAND_CLUSTER, "Klazt3rz");
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.activateCluster);
- clusterUrl = getClusterUrl("clusterTest1");
- response = assertSuccessPostOperation(clusterUrl, paraMap, false);
+ clusterUrl = getClusterUrl(clusterName);
+ assertSuccessPostOperation(clusterUrl, activateClusterCmd(controllerClusterName, true), false);
Thread.sleep(500);
deleteUrl(clusterUrl, true);
// verify leader node
- HelixDataAccessor accessor =
- _startCMResultMap.get("controller_9001")._manager.getHelixDataAccessor();
+ HelixDataAccessor accessor = distControllers.get("controller_9001").getHelixDataAccessor();
LiveInstance controllerLeader = accessor.getProperty(accessor.keyBuilder().controllerLeader());
Assert.assertTrue(controllerLeader.getInstanceName().startsWith("controller_900"));
- accessor = _startCMResultMap.get("localhost_1232")._manager.getHelixDataAccessor();
+ accessor = participants.get("localhost_1232").getHelixDataAccessor();
LiveInstance leader = accessor.getProperty(accessor.keyBuilder().controllerLeader());
for (int i = 0; i < 5; i++) {
if (leader != null) {
@@ -603,81 +795,98 @@ public class TestHelixAdminScenariosRest extends AdminTestBase {
Assert.assertTrue(leader.getInstanceName().startsWith("controller_900"));
boolean verifyResult =
- ClusterStateVerifier.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR,
- "clusterTest1"));
+ ClusterStateVerifier
+ .verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(verifyResult);
verifyResult =
ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
- "clusterTest1"));
+ clusterName));
Assert.assertTrue(verifyResult);
+ Thread.sleep(1000);
+
+ // clean up
+ for (ClusterDistributedController controller : distControllers.values()) {
+ controller.syncStop();
+ }
+ for (MockParticipantManager participant : participants.values()) {
+ participant.syncStop();
+ }
+ }
+
+ private Map<String, String> rebalanceCmd(int replicas, String prefix, String tag) {
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put(JsonParameters.REPLICAS, "" + replicas);
+ if (prefix != null) {
+ parameters.put(JsonParameters.RESOURCE_KEY_PREFIX, prefix);
+ }
+ if (tag != null) {
+ parameters.put(ClusterSetup.instanceGroupTag, tag);
+ }
+ parameters.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.rebalance);
+
+ return parameters;
}
- private void testRebalanceResource() throws Exception {
- String resourceUrl = getResourceUrl("clusterTest1", "db_11");
- Map<String, String> paraMap = new HashMap<String, String>();
- paraMap.put(JsonParameters.REPLICAS, "3");
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.rebalance);
+ private void rebalanceResource(String clusterName, String resourceName) throws IOException {
+ String resourceUrl = getResourceUrl(clusterName, resourceName);
+ String idealStateUrl = resourceUrl + "/idealState";
+
+ assertSuccessPostOperation(idealStateUrl, rebalanceCmd(3, null, null), false);
+ }
+
+ @Test
+ public void testRebalanceResource() throws Exception {
+ // add a normal cluster
+ final String clusterName = "clusterTestRebalanceResource";
+ addCluster(clusterName);
- String ISUrl = resourceUrl + "/idealState";
- String response = assertSuccessPostOperation(ISUrl, paraMap, false);
+ addInstancesToCluster(clusterName, "localhost:123", 3, _tag1);
+ addResource(clusterName, "db_11", 44);
+
+ String resourceUrl = getResourceUrl(clusterName, "db_11");
+
+ String idealStateUrl = resourceUrl + "/idealState";
+ String response = assertSuccessPostOperation(idealStateUrl, rebalanceCmd(3, null, null), false);
ZNRecord record = JsonToObject(ZNRecord.class, response);
Assert.assertTrue(record.getId().equalsIgnoreCase("db_11"));
- Assert
- .assertTrue((((List<String>) (record.getListFields().values().toArray()[0]))).size() == 3);
- Assert.assertTrue((((Map<String, String>) (record.getMapFields().values().toArray()[0])))
- .size() == 3);
+ Assert.assertEquals(record.getListField("db_11_0").size(), 3);
+ Assert.assertEquals(record.getMapField("db_11_0").size(), 3);
deleteUrl(resourceUrl, false);
// re-add and rebalance
- String reourcesUrl = "http://localhost:" + ADMIN_PORT + "/clusters/clusterTest1/resourceGroups";
+ final String reourcesUrl =
+ "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/resourceGroups";
+
response = getUrl(reourcesUrl);
Assert.assertFalse(response.contains("db_11"));
- paraMap = new HashMap<String, String>();
- paraMap.put(JsonParameters.RESOURCE_GROUP_NAME, "db_11");
- paraMap.put(JsonParameters.STATE_MODEL_DEF_REF, "MasterSlave");
- paraMap.put(JsonParameters.PARTITIONS, "48");
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addResource);
-
- response = assertSuccessPostOperation(reourcesUrl, paraMap, false);
- Assert.assertTrue(response.contains("db_11"));
-
- ISUrl = resourceUrl + "/idealState";
- paraMap.put(JsonParameters.REPLICAS, "3");
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.rebalance);
- response = assertSuccessPostOperation(ISUrl, paraMap, false);
+ addResource(clusterName, "db_11", 48);
+ idealStateUrl = resourceUrl + "/idealState";
+ response = assertSuccessPostOperation(idealStateUrl, rebalanceCmd(3, null, null), false);
record = JsonToObject(ZNRecord.class, response);
Assert.assertTrue(record.getId().equalsIgnoreCase("db_11"));
- Assert
- .assertTrue((((List<String>) (record.getListFields().values().toArray()[0]))).size() == 3);
- Assert.assertTrue((((Map<String, String>) (record.getMapFields().values().toArray()[0])))
- .size() == 3);
+ Assert.assertEquals(record.getListField("db_11_0").size(), 3);
+ Assert.assertEquals(record.getMapField("db_11_0").size(), 3);
// rebalance with key prefix
- resourceUrl = getResourceUrl("clusterTest1", "db_22");
- ISUrl = resourceUrl + "/idealState";
- paraMap.put(JsonParameters.REPLICAS, "2");
- paraMap.put(JsonParameters.RESOURCE_KEY_PREFIX, "alias");
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.rebalance);
- response = assertSuccessPostOperation(ISUrl, paraMap, false);
+ addResource(clusterName, "db_22", 55);
+ resourceUrl = getResourceUrl(clusterName, "db_22");
+ idealStateUrl = resourceUrl + "/idealState";
+ response = assertSuccessPostOperation(idealStateUrl, rebalanceCmd(2, "alias", null), false);
record = JsonToObject(ZNRecord.class, response);
Assert.assertTrue(record.getId().equalsIgnoreCase("db_22"));
- Assert
- .assertTrue((((List<String>) (record.getListFields().values().toArray()[0]))).size() == 2);
- Assert.assertTrue((((Map<String, String>) (record.getMapFields().values().toArray()[0])))
- .size() == 2);
+ Assert.assertEquals(record.getListField("alias_0").size(), 2);
+ Assert.assertEquals(record.getMapField("alias_0").size(), 2);
Assert.assertTrue((((String) (record.getMapFields().keySet().toArray()[0])))
.startsWith("alias_"));
Assert.assertFalse(response.contains(IdealStateProperty.INSTANCE_GROUP_TAG.toString()));
- resourceUrl = getResourceUrl("clusterTest1", "db_33");
- ISUrl = resourceUrl + "/idealState";
- paraMap.put(JsonParameters.REPLICAS, "2");
- paraMap.remove(JsonParameters.RESOURCE_KEY_PREFIX);
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.rebalance);
- paraMap.put(ClusterSetup.instanceGroupTag, _tag1);
- response = assertSuccessPostOperation(ISUrl, paraMap, false);
+
+ addResource(clusterName, "db_33", 44);
+ resourceUrl = getResourceUrl(clusterName, "db_33");
+ idealStateUrl = resourceUrl + "/idealState";
+ response = assertSuccessPostOperation(idealStateUrl, rebalanceCmd(2, null, _tag1), false);
Assert.assertTrue(response.contains(IdealStateProperty.INSTANCE_GROUP_TAG.toString()));
Assert.assertTrue(response.contains(_tag1));
@@ -690,14 +899,10 @@ public class TestHelixAdminScenariosRest extends AdminTestBase {
}
}
- resourceUrl = getResourceUrl("clusterTest1", "db_44");
- ISUrl = resourceUrl + "/idealState";
- paraMap.put(JsonParameters.REPLICAS, "2");
- paraMap.remove(JsonParameters.RESOURCE_KEY_PREFIX);
- paraMap.put(JsonParameters.RESOURCE_KEY_PREFIX, "alias");
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.rebalance);
- paraMap.put(ClusterSetup.instanceGroupTag, _tag1);
- response = assertSuccessPostOperation(ISUrl, paraMap, false);
+ addResource(clusterName, "db_44", 44);
+ resourceUrl = getResourceUrl(clusterName, "db_44");
+ idealStateUrl = resourceUrl + "/idealState";
+ response = assertSuccessPostOperation(idealStateUrl, rebalanceCmd(2, "alias", _tag1), false);
Assert.assertTrue(response.contains(IdealStateProperty.INSTANCE_GROUP_TAG.toString()));
Assert.assertTrue(response.contains(_tag1));
@@ -715,24 +920,66 @@ public class TestHelixAdminScenariosRest extends AdminTestBase {
}
}
- private void testAddInstance() throws Exception {
- String clusterUrl = getClusterUrl("clusterTest1");
- Map<String, String> paraMap = new HashMap<String, String>();
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addInstance);
- String response = null;
- // Add instances to cluster
+ private void addInstancesToCluster(String clusterName, String instanceNamePrefix, int n,
+ String tag) throws IOException {
+ Map<String, String> parameters = new HashMap<String, String>();
+ final String clusterUrl = getClusterUrl(clusterName);
+ parameters.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addInstance);
+
+ // add instances to cluster
String instancesUrl = clusterUrl + "/instances";
- for (int i = 0; i < 3; i++) {
+ for (int i = 0; i < n; i++) {
- paraMap.put(JsonParameters.INSTANCE_NAME, "localhost:123" + i);
- response = assertSuccessPostOperation(instancesUrl, paraMap, false);
- Assert.assertTrue(response.contains(("localhost:123" + i).replace(':', '_')));
+ parameters.put(JsonParameters.INSTANCE_NAME, instanceNamePrefix + i);
+ String response = assertSuccessPostOperation(instancesUrl, parameters, false);
+ Assert.assertTrue(response.contains((instanceNamePrefix + i).replace(':', '_')));
}
- paraMap.remove(JsonParameters.INSTANCE_NAME);
- paraMap.put(JsonParameters.INSTANCE_NAMES,
- "localhost:1233;localhost:1234;localhost:1235;localhost:1236");
- response = assertSuccessPostOperation(instancesUrl, paraMap, false);
+ // add tag to instance
+ if (tag != null && !tag.isEmpty()) {
+ parameters.clear();
+ parameters.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addInstanceTag);
+ parameters.put(ClusterSetup.instanceGroupTag, tag);
+ for (int i = 0; i < n; i++) {
+ String instanceUrl = instancesUrl + "/" + (instanceNamePrefix + i).replace(':', '_');
+ String response = assertSuccessPostOperation(instanceUrl, parameters, false);
+ Assert.assertTrue(response.contains(_tag1));
+ }
+ }
+
+ }
+
+ private Map<String, String> addInstanceTagCmd(String tag) {
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addInstanceTag);
+ parameters.put(ClusterSetup.instanceGroupTag, tag);
+
+ return parameters;
+ }
+
+ private Map<String, String> removeInstanceTagCmd(String tag) {
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.removeInstanceTag);
+ parameters.put(ClusterSetup.instanceGroupTag, tag);
+
+ return parameters;
+ }
+
+ @Test
+ public void testAddInstance() throws Exception {
+ final String clusterName = "clusterTestAddInstance";
+
+ // add normal cluster
+ addCluster(clusterName);
+
+ String clusterUrl = getClusterUrl(clusterName);
+
+ // Add instances to cluster
+ String instancesUrl = clusterUrl + "/instances";
+ addInstancesToCluster(clusterName, "localhost:123", 3, null);
+
+ String instances = "localhost:1233;localhost:1234;localhost:1235;localhost:1236";
+ String response = assertSuccessPostOperation(instancesUrl, addInstanceCmd(instances), false);
for (int i = 3; i <= 6; i++) {
Assert.assertTrue(response.contains("localhost_123" + i));
}
@@ -751,42 +998,34 @@ public class TestHelixAdminScenariosRest extends AdminTestBase {
// disable node
instanceUrl = instancesUrl + "/localhost_1236";
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.enableInstance);
- paraMap.put(JsonParameters.ENABLED, "false");
- response = assertSuccessPostOperation(instanceUrl, paraMap, false);
+ response = assertSuccessPostOperation(instanceUrl, enableInstanceCmd(false), false);
Assert.assertTrue(response.contains("false"));
deleteUrl(instanceUrl, false);
+ // add controller cluster
+ final String controllerClusterName = "controllerClusterTestAddInstance";
+ addCluster(controllerClusterName);
+
// add node to controller cluster
- paraMap.remove(JsonParameters.INSTANCE_NAME);
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addInstance);
- paraMap.put(JsonParameters.INSTANCE_NAMES, "controller:9000;controller:9001");
- String controllerUrl = getClusterUrl("Klazt3rz") + "/instances";
- response = assertSuccessPostOperation(controllerUrl, paraMap, false);
+ String controllers = "controller:9000;controller:9001";
+ String controllerUrl = getClusterUrl(controllerClusterName) + "/instances";
+ response = assertSuccessPostOperation(controllerUrl, addInstanceCmd(controllers), false);
Assert.assertTrue(response.contains("controller_9000"));
Assert.assertTrue(response.contains("controller_9001"));
- // add a dup host
- paraMap.remove(JsonParameters.INSTANCE_NAMES);
- paraMap.put(JsonParameters.INSTANCE_NAME, "localhost:1234");
- response = assertSuccessPostOperation(instancesUrl, paraMap, true);
-
- // add tags
+ // add a duplicated host
+ response = assertSuccessPostOperation(instancesUrl, addInstanceCmd("localhost:1234"), true);
- paraMap.clear();
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addInstanceTag);
- paraMap.put(ClusterSetup.instanceGroupTag, _tag1);
+ // add/remove tags
for (int i = 0; i < 4; i++) {
instanceUrl = instancesUrl + "/localhost_123" + i;
- response = assertSuccessPostOperation(instanceUrl, paraMap, false);
+ response = assertSuccessPostOperation(instanceUrl, addInstanceTagCmd(_tag1), false);
Assert.assertTrue(response.contains(_tag1));
-
}
- paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.removeInstanceTag);
+
instanceUrl = instancesUrl + "/localhost_1233";
- response = assertSuccessPostOperation(instanceUrl, paraMap, false);
+ response = assertSuccessPostOperation(instanceUrl, removeInstanceTagCmd(_tag1), false);
Assert.assertFalse(response.contains(_tag1));
-
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetInstance.java
----------------------------------------------------------------------
diff --git a/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetInstance.java b/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetInstance.java
index 9534cf5..fd12080 100644
--- a/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetInstance.java
+++ b/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetInstance.java
@@ -25,8 +25,8 @@ import java.util.Map;
import java.util.Set;
import org.apache.helix.TestHelper;
-import org.apache.helix.mock.controller.ClusterController;
-import org.apache.helix.mock.participant.MockParticipant;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.mock.participant.ErrTransition;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.tools.ClusterStateVerifier;
@@ -53,12 +53,8 @@ public class TestResetInstance extends AdminTestBase {
3, // replicas
"MasterSlave", true); // do rebalance
- // // start admin thread
- // AdminThread adminThread = new AdminThread(ZK_ADDR, _port);
- // adminThread.start();
-
// start controller
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
Map<String, Set<String>> errPartitions = new HashMap<String, Set<String>>() {
@@ -69,16 +65,16 @@ public class TestResetInstance extends AdminTestBase {
};
// start mock participants
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
if (i == 0) {
participants[i] =
- new MockParticipant(clusterName, instanceName, ZK_ADDR,
- new ErrTransition(errPartitions));
+ new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participants[i].setTransition(new ErrTransition(errPartitions));
} else {
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
}
participants[i].syncStart();
}
@@ -111,9 +107,6 @@ public class TestResetInstance extends AdminTestBase {
Assert.assertTrue(result, "Cluster verification fails");
// clean up
- // wait for all zk callbacks done
- Thread.sleep(1000);
- // adminThread.stop();
controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetPartitionState.java
----------------------------------------------------------------------
diff --git a/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetPartitionState.java b/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetPartitionState.java
index c8099a4..4d54bd7 100644
--- a/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetPartitionState.java
+++ b/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetPartitionState.java
@@ -29,10 +29,10 @@ import org.apache.helix.NotificationContext;
import org.apache.helix.PropertyKey.Builder;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.mock.controller.ClusterController;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.mock.participant.ErrTransition;
import org.apache.helix.model.LiveInstance;
import org.apache.helix.model.Message;
@@ -94,12 +94,8 @@ public class TestResetPartitionState extends AdminTestBase {
3, // replicas
"MasterSlave", true); // do rebalance
- // start admin thread
- // AdminThread adminThread = new AdminThread(ZK_ADDR, _port);
- // adminThread.start();
-
// start controller
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
Map<String, Set<String>> errPartitions = new HashMap<String, Set<String>>();
@@ -107,16 +103,16 @@ public class TestResetPartitionState extends AdminTestBase {
errPartitions.put("OFFLINE-SLAVE", TestHelper.setOf("TestDB0_8"));
// start mock participants
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
if (i == 0) {
participants[i] =
- new MockParticipant(clusterName, instanceName, ZK_ADDR,
- new ErrTransition(errPartitions));
+ new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participants[i].setTransition(new ErrTransition(errPartitions));
} else {
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
}
participants[i].syncStart();
}
@@ -170,9 +166,6 @@ public class TestResetPartitionState extends AdminTestBase {
Assert.assertEquals(_errToOfflineInvoked.get(), 2, "reset() should be invoked 2 times");
// clean up
- // wait for all zk callbacks done
- Thread.sleep(1000);
- // adminThread.stop();
controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
@@ -184,8 +177,7 @@ public class TestResetPartitionState extends AdminTestBase {
private void clearStatusUpdate(String clusterName, String instance, String resource,
String partition) {
// clear status update for error partition so verify() will not fail on
- // old
- // errors
+ // old errors
ZKHelixDataAccessor accessor =
new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetResource.java
----------------------------------------------------------------------
diff --git a/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetResource.java b/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetResource.java
index 96f4f6c..db9e9bb 100644
--- a/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetResource.java
+++ b/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetResource.java
@@ -25,8 +25,8 @@ import java.util.Map;
import java.util.Set;
import org.apache.helix.TestHelper;
-import org.apache.helix.mock.controller.ClusterController;
-import org.apache.helix.mock.participant.MockParticipant;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.mock.participant.ErrTransition;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.tools.ClusterStateVerifier;
@@ -53,12 +53,8 @@ public class TestResetResource extends AdminTestBase {
3, // replicas
"MasterSlave", true); // do rebalance
- // start admin thread
- // AdminThread adminThread = new AdminThread(ZK_ADDR, _port);
- // adminThread.start();
-
// start controller
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
Map<String, Set<String>> errPartitions = new HashMap<String, Set<String>>() {
@@ -69,16 +65,16 @@ public class TestResetResource extends AdminTestBase {
};
// start mock participants
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
if (i == 0) {
participants[i] =
- new MockParticipant(clusterName, instanceName, ZK_ADDR,
- new ErrTransition(errPartitions));
+ new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participants[i].setTransition(new ErrTransition(errPartitions));
} else {
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
}
participants[i].syncStart();
}
@@ -112,15 +108,11 @@ public class TestResetResource extends AdminTestBase {
Assert.assertTrue(result, "Cluster verification fails");
// clean up
- // wait for all zk callbacks done
- Thread.sleep(1000);
- // adminThread.stop();
controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
-
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-agent/src/test/java/org/apache/helix/agent/TestHelixAgent.java
----------------------------------------------------------------------
diff --git a/helix-agent/src/test/java/org/apache/helix/agent/TestHelixAgent.java b/helix-agent/src/test/java/org/apache/helix/agent/TestHelixAgent.java
index e723296..27b4d36 100644
--- a/helix-agent/src/test/java/org/apache/helix/agent/TestHelixAgent.java
+++ b/helix-agent/src/test/java/org/apache/helix/agent/TestHelixAgent.java
@@ -20,30 +20,31 @@ package org.apache.helix.agent;
*/
import java.io.File;
-import java.io.IOException;
import java.util.Date;
-import java.util.concurrent.TimeUnit;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.helix.ConfigAccessor;
import org.apache.helix.ExternalCommand;
import org.apache.helix.ScriptTestHelper;
import org.apache.helix.TestHelper;
import org.apache.helix.ZkUnitTestBase;
-import org.apache.helix.manager.zk.ZNRecordSerializer;
-import org.apache.helix.manager.zk.ZkClient;
-import org.apache.helix.mock.controller.ClusterController;
+import org.apache.helix.integration.manager.ClusterControllerManager;
import org.apache.helix.model.HelixConfigScope;
import org.apache.helix.model.HelixConfigScope.ConfigScopeProperty;
import org.apache.helix.model.builder.HelixConfigScopeBuilder;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.tools.ClusterStateVerifier;
import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier;
+import org.apache.log4j.Logger;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class TestHelixAgent extends ZkUnitTestBase {
+ private final static Logger LOG = Logger.getLogger(TestHelixAgent.class);
+
final String workingDir = ScriptTestHelper.getPrefix() + ScriptTestHelper.INTEGRATION_SCRIPT_DIR;
ExternalCommand serverCmd = null;
@@ -96,13 +97,9 @@ public class TestHelixAgent extends ZkUnitTestBase {
"MasterSlave", true); // do rebalance
// set cluster config
- ZkClient client =
- new ZkClient(zkAddr, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT,
- new ZNRecordSerializer());
-
HelixConfigScope scope =
new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(clusterName).build();
- ConfigAccessor configAccessor = new ConfigAccessor(client);
+ ConfigAccessor configAccessor = new ConfigAccessor(_gZkClient);
// String pidFile = ScriptTestHelper.getPrefix() + ScriptTestHelper.INTEGRATION_LOG_DIR +
// "/default/foo_{PARTITION_NAME}_pid.txt";
@@ -150,10 +147,11 @@ public class TestHelixAgent extends ZkUnitTestBase {
configAccessor.set(scope, cmdConfig.toKeyValueMap());
// start controller
- ClusterController controller = new ClusterController(clusterName, "controller_0", zkAddr);
+ ClusterControllerManager controller = new ClusterControllerManager(zkAddr, clusterName, "controller_0");
controller.syncStart();
// start helix-agent
+ Map<String, Thread> agents = new HashMap<String, Thread>();
for (int i = 0; i < n; i++) {
final String instanceName = "localhost_" + (12918 + i);
Thread agentThread = new Thread() {
@@ -165,11 +163,11 @@ public class TestHelixAgent extends ZkUnitTestBase {
"--stateModel", "MasterSlave"
});
} catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.error("Exception start helix-agent", e);
}
}
};
+ agents.put(instanceName, agentThread);
agentThread.start();
// wait participant thread to start
@@ -199,6 +197,11 @@ public class TestHelixAgent extends ZkUnitTestBase {
clusterName));
Assert.assertTrue(result);
+ // clean up
+ controller.syncStop();
+ for (Thread agentThread : agents.values()) {
+ agentThread.interrupt();
+ }
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/main/java/org/apache/helix/HelixManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/HelixManager.java b/helix-core/src/main/java/org/apache/helix/HelixManager.java
index 808705b..d129792 100644
--- a/helix-core/src/main/java/org/apache/helix/HelixManager.java
+++ b/helix-core/src/main/java/org/apache/helix/HelixManager.java
@@ -54,8 +54,6 @@ import org.apache.helix.store.zk.ZkHelixPropertyStore;
*/
public interface HelixManager {
- public static final String ALLOW_PARTICIPANT_AUTO_JOIN = "ALLOW_PARTICIPANT_AUTO_JOIN";
-
/**
* Start participating in the cluster operations. All listeners will be
* initialized and will be notified for every cluster state change This method
@@ -98,6 +96,7 @@ public interface HelixManager {
* @param listener
* @deprecated replaced by addInstanceConfigChangeListener()
*/
+ @Deprecated
void addConfigChangeListener(ConfigChangeListener listener) throws Exception;
/**
@@ -151,6 +150,12 @@ public interface HelixManager {
void addControllerListener(ControllerChangeListener listener);
/**
+ * Add message listener for controller
+ * @param listener
+ */
+ void addControllerMessageListener(MessageListener listener);
+
+ /**
* Removes the listener. If the same listener was used for multiple changes,
* all change notifications will be removed.<br/>
* This will invoke onChange method on the listener with
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/main/java/org/apache/helix/HelixProperty.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/HelixProperty.java b/helix-core/src/main/java/org/apache/helix/HelixProperty.java
index 2e19231..6c52a47 100644
--- a/helix-core/src/main/java/org/apache/helix/HelixProperty.java
+++ b/helix-core/src/main/java/org/apache/helix/HelixProperty.java
@@ -27,10 +27,14 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.apache.log4j.Logger;
+
/**
* A wrapper class for ZNRecord. Used as a base class for IdealState, CurrentState, etc.
*/
public class HelixProperty {
+ private static Logger LOG = Logger.getLogger(HelixProperty.class);
+
public enum HelixPropertyAttribute {
BUCKET_SIZE,
BATCH_MESSAGE_MODE
@@ -128,8 +132,7 @@ public class HelixProperty {
});
return constructor.newInstance(record);
} catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.error("Exception convert znrecord: " + record + " to class: " + clazz, e);
}
return null;
[03/10] [HELIX-279] Apply gc handling fixes to main ZKHelixManager
class
Posted by zz...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestMessagingService.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestMessagingService.java b/helix-core/src/test/java/org/apache/helix/integration/TestMessagingService.java
index 2354ebd..457b5fb 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestMessagingService.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestMessagingService.java
@@ -87,8 +87,8 @@ public class TestMessagingService extends ZkStandAloneCMTestBaseWithPropertyServ
String hostDest = "localhost_" + (START_PORT + 1);
TestMessagingHandlerFactory factory = new TestMessagingHandlerFactory();
- _startCMResultMap.get(hostDest)._manager.getMessagingService().registerMessageHandlerFactory(
- factory.getMessageType(), factory);
+ _participants[1].getMessagingService().registerMessageHandlerFactory(factory.getMessageType(),
+ factory);
String msgId = new UUID(123, 456).toString();
Message msg = new Message(factory.getMessageType(), msgId);
@@ -104,7 +104,8 @@ public class TestMessagingService extends ZkStandAloneCMTestBaseWithPropertyServ
cr.setRecipientInstanceType(InstanceType.PARTICIPANT);
cr.setSessionSpecific(false);
- int nMsgs = _startCMResultMap.get(hostSrc)._manager.getMessagingService().send(cr, msg);
+ // int nMsgs = _startCMResultMap.get(hostSrc)._manager.getMessagingService().send(cr, msg);
+ int nMsgs = _participants[0].getMessagingService().send(cr, msg);
AssertJUnit.assertTrue(nMsgs == 1);
Thread.sleep(2500);
// Thread.currentThread().join();
@@ -116,7 +117,8 @@ public class TestMessagingService extends ZkStandAloneCMTestBaseWithPropertyServ
cr.setSessionSpecific(false);
cr.setDataSource(DataSource.IDEALSTATES);
- nMsgs = _startCMResultMap.get(hostSrc)._manager.getMessagingService().send(cr, msg);
+ // nMsgs = _startCMResultMap.get(hostSrc)._manager.getMessagingService().send(cr, msg);
+ nMsgs = _participants[0].getMessagingService().send(cr, msg);
AssertJUnit.assertTrue(nMsgs == 1);
Thread.sleep(2500);
// Thread.currentThread().join();
@@ -179,11 +181,11 @@ public class TestMessagingService extends ZkStandAloneCMTestBaseWithPropertyServ
String hostDest = "localhost_" + (START_PORT + 1);
TestMessagingHandlerFactory factory = new TestMessagingHandlerFactory();
- _startCMResultMap.get(hostDest)._manager.getMessagingService().registerMessageHandlerFactory(
- factory.getMessageType(), factory);
+ _participants[1].getMessagingService().registerMessageHandlerFactory(factory.getMessageType(),
+ factory);
- _startCMResultMap.get(hostSrc)._manager.getMessagingService().registerMessageHandlerFactory(
- factory.getMessageType(), factory);
+ _participants[0].getMessagingService().registerMessageHandlerFactory(factory.getMessageType(),
+ factory);
String msgId = new UUID(123, 456).toString();
Message msg = new Message(factory.getMessageType(), msgId);
@@ -202,7 +204,7 @@ public class TestMessagingService extends ZkStandAloneCMTestBaseWithPropertyServ
TestAsyncCallback callback = new TestAsyncCallback(60000);
- _startCMResultMap.get(hostSrc)._manager.getMessagingService().send(cr, msg, callback, 60000);
+ _participants[0].getMessagingService().send(cr, msg, callback, 60000);
Thread.sleep(2000);
// Thread.currentThread().join();
@@ -210,7 +212,7 @@ public class TestMessagingService extends ZkStandAloneCMTestBaseWithPropertyServ
AssertJUnit.assertTrue(callback.getMessageReplied().size() == 1);
TestAsyncCallback callback2 = new TestAsyncCallback(500);
- _startCMResultMap.get(hostSrc)._manager.getMessagingService().send(cr, msg, callback2, 500);
+ _participants[0].getMessagingService().send(cr, msg, callback2, 500);
Thread.sleep(3000);
// Thread.currentThread().join();
@@ -224,7 +226,7 @@ public class TestMessagingService extends ZkStandAloneCMTestBaseWithPropertyServ
callback = new TestAsyncCallback(60000);
- _startCMResultMap.get(hostSrc)._manager.getMessagingService().send(cr, msg, callback, 60000);
+ _participants[0].getMessagingService().send(cr, msg, callback, 60000);
Thread.sleep(2000);
// Thread.currentThread().join();
@@ -232,7 +234,7 @@ public class TestMessagingService extends ZkStandAloneCMTestBaseWithPropertyServ
AssertJUnit.assertTrue(callback.getMessageReplied().size() == 1);
callback2 = new TestAsyncCallback(500);
- _startCMResultMap.get(hostSrc)._manager.getMessagingService().send(cr, msg, callback2, 500);
+ _participants[0].getMessagingService().send(cr, msg, callback2, 500);
Thread.sleep(3000);
// Thread.currentThread().join();
@@ -246,8 +248,8 @@ public class TestMessagingService extends ZkStandAloneCMTestBaseWithPropertyServ
String hostDest = "localhost_" + (START_PORT + 1);
TestMessagingHandlerFactory factory = new TestMessagingHandlerFactory();
- _startCMResultMap.get(hostDest)._manager.getMessagingService().registerMessageHandlerFactory(
- factory.getMessageType(), factory);
+ _participants[1].getMessagingService().registerMessageHandlerFactory(factory.getMessageType(),
+ factory);
String msgId = new UUID(123, 456).toString();
Message msg = new Message(factory.getMessageType(), msgId);
@@ -266,8 +268,7 @@ public class TestMessagingService extends ZkStandAloneCMTestBaseWithPropertyServ
AsyncCallback asyncCallback = new MockAsyncCallback();
int messagesSent =
- _startCMResultMap.get(hostSrc)._manager.getMessagingService().sendAndWait(cr, msg,
- asyncCallback, 60000);
+ _participants[0].getMessagingService().sendAndWait(cr, msg, asyncCallback, 60000);
AssertJUnit.assertTrue(asyncCallback.getMessageReplied().get(0).getRecord()
.getMapField(Message.Attributes.MESSAGE_RESULT.toString()).get("ReplyMessage")
@@ -275,9 +276,7 @@ public class TestMessagingService extends ZkStandAloneCMTestBaseWithPropertyServ
AssertJUnit.assertTrue(asyncCallback.getMessageReplied().size() == 1);
AsyncCallback asyncCallback2 = new MockAsyncCallback();
- messagesSent =
- _startCMResultMap.get(hostSrc)._manager.getMessagingService().sendAndWait(cr, msg,
- asyncCallback2, 500);
+ messagesSent = _participants[0].getMessagingService().sendAndWait(cr, msg, asyncCallback2, 500);
AssertJUnit.assertTrue(asyncCallback2.isTimedOut());
}
@@ -289,8 +288,9 @@ public class TestMessagingService extends ZkStandAloneCMTestBaseWithPropertyServ
for (int i = 0; i < NODE_NR; i++) {
TestMessagingHandlerFactory factory = new TestMessagingHandlerFactory();
String hostDest = "localhost_" + (START_PORT + i);
- _startCMResultMap.get(hostDest)._manager.getMessagingService().registerMessageHandlerFactory(
+ _participants[0].getMessagingService().registerMessageHandlerFactory(
factory.getMessageType(), factory);
+
}
String msgId = new UUID(123, 456).toString();
Message msg = new Message(new TestMessagingHandlerFactory().getMessageType(), msgId);
@@ -308,8 +308,7 @@ public class TestMessagingService extends ZkStandAloneCMTestBaseWithPropertyServ
cr.setSessionSpecific(false);
AsyncCallback callback1 = new MockAsyncCallback();
int messageSent1 =
- _startCMResultMap.get(hostSrc)._manager.getMessagingService().sendAndWait(cr, msg,
- callback1, 10000);
+ _participants[0].getMessagingService().sendAndWait(cr, msg, callback1, 10000);
AssertJUnit.assertTrue(callback1.getMessageReplied().get(0).getRecord()
.getMapField(Message.Attributes.MESSAGE_RESULT.toString()).get("ReplyMessage")
@@ -317,37 +316,32 @@ public class TestMessagingService extends ZkStandAloneCMTestBaseWithPropertyServ
AssertJUnit.assertTrue(callback1.getMessageReplied().size() == NODE_NR - 1);
AsyncCallback callback2 = new MockAsyncCallback();
- int messageSent2 =
- _startCMResultMap.get(hostSrc)._manager.getMessagingService().sendAndWait(cr, msg,
- callback2, 500);
+ int messageSent2 = _participants[0].getMessagingService().sendAndWait(cr, msg, callback2, 500);
+
AssertJUnit.assertTrue(callback2.isTimedOut());
cr.setPartition("TestDB_17");
AsyncCallback callback3 = new MockAsyncCallback();
int messageSent3 =
- _startCMResultMap.get(hostSrc)._manager.getMessagingService().sendAndWait(cr, msg,
- callback3, 10000);
+ _participants[0].getMessagingService().sendAndWait(cr, msg, callback3, 10000);
AssertJUnit.assertTrue(callback3.getMessageReplied().size() == _replica - 1);
cr.setPartition("TestDB_15");
AsyncCallback callback4 = new MockAsyncCallback();
int messageSent4 =
- _startCMResultMap.get(hostSrc)._manager.getMessagingService().sendAndWait(cr, msg,
- callback4, 10000);
+ _participants[0].getMessagingService().sendAndWait(cr, msg, callback4, 10000);
AssertJUnit.assertTrue(callback4.getMessageReplied().size() == _replica);
cr.setPartitionState("SLAVE");
AsyncCallback callback5 = new MockAsyncCallback();
int messageSent5 =
- _startCMResultMap.get(hostSrc)._manager.getMessagingService().sendAndWait(cr, msg,
- callback5, 10000);
+ _participants[0].getMessagingService().sendAndWait(cr, msg, callback5, 10000);
AssertJUnit.assertTrue(callback5.getMessageReplied().size() == _replica - 1);
cr.setDataSource(DataSource.IDEALSTATES);
AsyncCallback callback6 = new MockAsyncCallback();
int messageSent6 =
- _startCMResultMap.get(hostSrc)._manager.getMessagingService().sendAndWait(cr, msg,
- callback6, 10000);
+ _participants[0].getMessagingService().sendAndWait(cr, msg, callback6, 10000);
AssertJUnit.assertTrue(callback6.getMessageReplied().size() == _replica - 1);
}
@@ -358,8 +352,9 @@ public class TestMessagingService extends ZkStandAloneCMTestBaseWithPropertyServ
for (int i = 0; i < NODE_NR; i++) {
TestMessagingHandlerFactory factory = new TestMessagingHandlerFactory();
String hostDest = "localhost_" + (START_PORT + i);
- _startCMResultMap.get(hostDest)._manager.getMessagingService().registerMessageHandlerFactory(
+ _participants[i].getMessagingService().registerMessageHandlerFactory(
factory.getMessageType(), factory);
+
}
String msgId = new UUID(123, 456).toString();
Message msg = new Message(new TestMessagingHandlerFactory().getMessageType(), msgId);
@@ -378,8 +373,7 @@ public class TestMessagingService extends ZkStandAloneCMTestBaseWithPropertyServ
cr.setSelfExcluded(false);
AsyncCallback callback1 = new MockAsyncCallback();
int messageSent1 =
- _startCMResultMap.get(hostSrc)._manager.getMessagingService().sendAndWait(cr, msg,
- callback1, 10000);
+ _participants[0].getMessagingService().sendAndWait(cr, msg, callback1, 10000);
AssertJUnit.assertTrue(callback1.getMessageReplied().size() == NODE_NR);
AssertJUnit.assertTrue(callback1.getMessageReplied().get(0).getRecord()
@@ -394,8 +388,9 @@ public class TestMessagingService extends ZkStandAloneCMTestBaseWithPropertyServ
for (int i = 0; i < NODE_NR; i++) {
TestMessagingHandlerFactory factory = new TestMessagingHandlerFactory();
String hostDest = "localhost_" + (START_PORT + i);
- _startCMResultMap.get(hostDest)._manager.getMessagingService().registerMessageHandlerFactory(
+ _participants[i].getMessagingService().registerMessageHandlerFactory(
factory.getMessageType(), factory);
+
}
String msgId = new UUID(123, 456).toString();
Message msg = new Message(MessageType.CONTROLLER_MSG, msgId);
@@ -414,8 +409,7 @@ public class TestMessagingService extends ZkStandAloneCMTestBaseWithPropertyServ
AsyncCallback callback1 = new MockAsyncCallback();
int messagesSent =
- _startCMResultMap.get(hostSrc)._manager.getMessagingService().sendAndWait(cr, msg,
- callback1, 10000);
+ _participants[0].getMessagingService().sendAndWait(cr, msg, callback1, 10000);
AssertJUnit.assertTrue(callback1.getMessageReplied().get(0).getRecord()
.getMapField(Message.Attributes.MESSAGE_RESULT.toString()).get("ControllerResult")
@@ -426,9 +420,8 @@ public class TestMessagingService extends ZkStandAloneCMTestBaseWithPropertyServ
msg.setMsgId(msgId);
cr.setPartition("TestDB_17");
AsyncCallback callback2 = new MockAsyncCallback();
- messagesSent =
- _startCMResultMap.get(hostSrc)._manager.getMessagingService().sendAndWait(cr, msg,
- callback2, 10000);
+ messagesSent = _participants[0].getMessagingService().sendAndWait(cr, msg, callback2, 10000);
+
AssertJUnit.assertTrue(callback2.getMessageReplied().get(0).getRecord()
.getMapField(Message.Attributes.MESSAGE_RESULT.toString()).get("ControllerResult")
.indexOf(hostSrc) != -1);
@@ -439,9 +432,7 @@ public class TestMessagingService extends ZkStandAloneCMTestBaseWithPropertyServ
msg.setMsgId(msgId);
cr.setPartitionState("SLAVE");
AsyncCallback callback3 = new MockAsyncCallback();
- messagesSent =
- _startCMResultMap.get(hostSrc)._manager.getMessagingService().sendAndWait(cr, msg,
- callback3, 10000);
+ messagesSent = _participants[0].getMessagingService().sendAndWait(cr, msg, callback3, 10000);
AssertJUnit.assertTrue(callback3.getMessageReplied().get(0).getRecord()
.getMapField(Message.Attributes.MESSAGE_RESULT.toString()).get("ControllerResult")
.indexOf(hostSrc) != -1);
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestNonOfflineInitState.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestNonOfflineInitState.java b/helix-core/src/test/java/org/apache/helix/integration/TestNonOfflineInitState.java
index 5a6e5e6..734e2b4 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestNonOfflineInitState.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestNonOfflineInitState.java
@@ -22,9 +22,9 @@ package org.apache.helix.integration;
import java.util.Date;
import org.apache.helix.TestHelper;
-import org.apache.helix.controller.HelixControllerMain;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZkClient;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.mock.participant.MockBootstrapModelFactory;
import org.apache.helix.participant.StateMachineEngine;
import org.apache.helix.tools.ClusterSetup;
@@ -51,18 +51,19 @@ public class TestNonOfflineInitState extends ZkIntegrationTestBase {
1, // replicas
"Bootstrap", true); // do rebalance
- TestHelper
- .startController(clusterName, "controller_0", ZK_ADDR, HelixControllerMain.STANDALONE);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+ controller.syncStart();
// start participants
- MockParticipant[] participants = new MockParticipant[5];
+ MockParticipantManager[] participants = new MockParticipantManager[5];
for (int i = 0; i < 5; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
// add a state model with non-OFFLINE initial state
- StateMachineEngine stateMach = participants[i].getManager().getStateMachineEngine();
+ StateMachineEngine stateMach = participants[i].getStateMachineEngine();
MockBootstrapModelFactory bootstrapFactory = new MockBootstrapModelFactory();
stateMach.registerStateModelFactory("Bootstrap", bootstrapFactory);
@@ -74,16 +75,21 @@ public class TestNonOfflineInitState extends ZkIntegrationTestBase {
clusterName));
Assert.assertTrue(result);
+ // clean up
+ controller.syncStop();
+ for (int i = 0; i < 5; i++) {
+ participants[i].syncStop();
+ }
+
System.out.println("END testNonOfflineInitState at " + new Date(System.currentTimeMillis()));
}
private static void setupCluster(String clusterName, String ZkAddr, int startPort,
String participantNamePrefix, String resourceNamePrefix, int resourceNb, int partitionNb,
int nodesNb, int replica, String stateModelDef, boolean doRebalance) throws Exception {
- ZkClient zkClient = new ZkClient(ZkAddr);
- if (zkClient.exists("/" + clusterName)) {
+ if (_gZkClient.exists("/" + clusterName)) {
LOG.warn("Cluster already exists:" + clusterName + ". Deleting it");
- zkClient.deleteRecursive("/" + clusterName);
+ _gZkClient.deleteRecursive("/" + clusterName);
}
ClusterSetup setupTool = new ClusterSetup(ZkAddr);
@@ -103,7 +109,6 @@ public class TestNonOfflineInitState extends ZkIntegrationTestBase {
setupTool.rebalanceStorageCluster(clusterName, dbName, replica);
}
}
- zkClient.close();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestNullReplica.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestNullReplica.java b/helix-core/src/test/java/org/apache/helix/integration/TestNullReplica.java
index 496d1a6..0f5cc72 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestNullReplica.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestNullReplica.java
@@ -25,8 +25,8 @@ import org.apache.helix.PropertyPathConfig;
import org.apache.helix.PropertyType;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
-import org.apache.helix.mock.controller.ClusterController;
-import org.apache.helix.mock.participant.MockParticipant;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.model.IdealState;
import org.apache.helix.tools.ClusterStateVerifier;
import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier;
@@ -44,7 +44,7 @@ public class TestNullReplica extends ZkIntegrationTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
- MockParticipant[] participants = new MockParticipant[5];
+ MockParticipantManager[] participants = new MockParticipantManager[5];
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
"localhost", // participant name prefix
@@ -61,14 +61,15 @@ public class TestNullReplica extends ZkIntegrationTestBase {
idealState.getSimpleFields().remove(IdealState.IdealStateProperty.REPLICAS.toString());
_gZkClient.writeData(idealStatePath, idealState);
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
for (int i = 0; i < 5; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
@@ -78,13 +79,11 @@ public class TestNullReplica extends ZkIntegrationTestBase {
Assert.assertTrue(result);
// clean up
+ controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
}
- Thread.sleep(2000);
- controller.syncStop();
-
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestParticipantErrorMessage.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestParticipantErrorMessage.java b/helix-core/src/test/java/org/apache/helix/integration/TestParticipantErrorMessage.java
index 8336939..cf59ed0 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestParticipantErrorMessage.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestParticipantErrorMessage.java
@@ -31,10 +31,13 @@ import org.apache.helix.model.Message;
import org.apache.helix.model.Message.MessageType;
import org.apache.helix.tools.ClusterStateVerifier;
import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier;
+import org.apache.log4j.Logger;
import org.testng.Assert;
import org.testng.annotations.Test;
public class TestParticipantErrorMessage extends ZkStandAloneCMTestBase {
+ private static Logger LOG = Logger.getLogger(TestParticipantErrorMessage.class);
+
@Test()
public void TestParticipantErrorMessageSend() {
String participant1 = "localhost_" + START_PORT;
@@ -49,7 +52,7 @@ public class TestParticipantErrorMessage extends ZkStandAloneCMTestBase {
Criteria recipientCriteria = new Criteria();
recipientCriteria.setRecipientInstanceType(InstanceType.CONTROLLER);
recipientCriteria.setSessionSpecific(false);
- _startCMResultMap.get(participant1)._manager.getMessagingService().send(recipientCriteria,
+ _participants[0].getMessagingService().send(recipientCriteria,
errorMessage1);
Message errorMessage2 =
@@ -63,23 +66,22 @@ public class TestParticipantErrorMessage extends ZkStandAloneCMTestBase {
Criteria recipientCriteria2 = new Criteria();
recipientCriteria2.setRecipientInstanceType(InstanceType.CONTROLLER);
recipientCriteria2.setSessionSpecific(false);
- _startCMResultMap.get(participant2)._manager.getMessagingService().send(recipientCriteria2,
+ _participants[1].getMessagingService().send(recipientCriteria2,
errorMessage2);
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.error("Interrupted sleep", e);
}
boolean result =
ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
CLUSTER_NAME));
Assert.assertTrue(result);
- Builder kb = _startCMResultMap.get(participant2)._manager.getHelixDataAccessor().keyBuilder();
+ Builder kb = _participants[1].getHelixDataAccessor().keyBuilder();
ExternalView externalView =
- _startCMResultMap.get(participant2)._manager.getHelixDataAccessor().getProperty(
+ _participants[1].getHelixDataAccessor().getProperty(
kb.externalView("TestDB"));
for (String partitionName : externalView.getRecord().getMapFields().keySet()) {
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestParticipantNameCollision.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestParticipantNameCollision.java b/helix-core/src/test/java/org/apache/helix/integration/TestParticipantNameCollision.java
index 4227688..aa67ac9 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestParticipantNameCollision.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestParticipantNameCollision.java
@@ -22,7 +22,7 @@ package org.apache.helix.integration;
import java.util.Date;
import org.apache.helix.TestHelper;
-import org.apache.helix.TestHelper.StartCMResult;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.log4j.Logger;
import org.testng.annotations.Test;
@@ -33,20 +33,21 @@ public class TestParticipantNameCollision extends ZkStandAloneCMTestBase {
public void testParticiptantNameCollision() throws Exception {
logger.info("RUN TestParticipantNameCollision() at " + new Date(System.currentTimeMillis()));
- StartCMResult result = null;
+ MockParticipantManager newParticipant = null;
for (int i = 0; i < 1; i++) {
String instanceName = "localhost_" + (START_PORT + i);
try {
// the call fails on getClusterManagerForParticipant()
// no threads start
- result = TestHelper.startDummyProcess(ZK_ADDR, CLUSTER_NAME, instanceName);
+ newParticipant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
+ newParticipant.syncStart();
} catch (Exception e) {
e.printStackTrace();
}
}
Thread.sleep(30000);
- TestHelper.verifyWithTimeout("verifyNotConnected", 30 * 1000, result._manager);
+ TestHelper.verifyWithTimeout("verifyNotConnected", 30 * 1000, newParticipant);
logger.info("STOP TestParticipantNameCollision() at " + new Date(System.currentTimeMillis()));
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestPauseSignal.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestPauseSignal.java b/helix-core/src/test/java/org/apache/helix/integration/TestPauseSignal.java
index d900d98..a1c413b 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestPauseSignal.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestPauseSignal.java
@@ -24,12 +24,12 @@ import java.util.Date;
import org.apache.helix.HelixDataAccessor;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZNRecordSerializer;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
import org.apache.helix.manager.zk.ZkClient;
-import org.apache.helix.mock.controller.ClusterController;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.model.PauseSignal;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.tools.ClusterStateVerifier;
@@ -47,7 +47,7 @@ public class TestPauseSignal extends ZkIntegrationTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
- MockParticipant[] participants = new MockParticipant[5];
+ MockParticipantManager[] participants = new MockParticipantManager[5];
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
"localhost", // participant name prefix
@@ -59,14 +59,15 @@ public class TestPauseSignal extends ZkIntegrationTestBase {
"MasterSlave", true); // do rebalance
// start controller
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
for (int i = 0; i < 5; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
@@ -112,13 +113,11 @@ public class TestPauseSignal extends ZkIntegrationTestBase {
Assert.assertTrue(result);
// clean up
+ controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
}
- Thread.sleep(2000);
- controller.syncStop();
-
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestRenamePartition.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestRenamePartition.java b/helix-core/src/test/java/org/apache/helix/integration/TestRenamePartition.java
index ed056ab..5f4377d 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestRenamePartition.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestRenamePartition.java
@@ -23,14 +23,15 @@ import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.controller.HelixControllerMain;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.model.IdealState;
import org.apache.helix.model.IdealState.RebalanceMode;
import org.apache.helix.tools.ClusterStateVerifier;
@@ -39,6 +40,14 @@ import org.testng.Assert;
import org.testng.annotations.Test;
public class TestRenamePartition extends ZkIntegrationTestBase {
+ // map from clusterName to participants
+ final Map<String, MockParticipantManager[]> _participantMap =
+ new ConcurrentHashMap<String, MockParticipantManager[]>();
+
+ // map from clusterName to controllers
+ final Map<String, ClusterControllerManager> _controllerMap =
+ new ConcurrentHashMap<String, ClusterControllerManager>();
+
@Test()
public void testRenamePartitionAutoIS() throws Exception {
String clusterName = "CLUSTER_" + getShortClassName() + "_auto";
@@ -57,7 +66,7 @@ public class TestRenamePartition extends ZkIntegrationTestBase {
// rename partition name TestDB0_0 tp TestDB0_100
ZKHelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_gZkClient));
+ new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
IdealState idealState = accessor.getProperty(keyBuilder.idealStates("TestDB0"));
@@ -71,8 +80,8 @@ public class TestRenamePartition extends ZkIntegrationTestBase {
ZK_ADDR, clusterName));
Assert.assertTrue(result);
+ stop(clusterName);
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
-
}
@Test()
@@ -103,7 +112,7 @@ public class TestRenamePartition extends ZkIntegrationTestBase {
idealState.setStateModelDefRef("MasterSlave");
ZKHelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_gZkClient));
+ new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
accessor.setProperty(keyBuilder.idealStates("TestDB0"), idealState);
@@ -118,23 +127,25 @@ public class TestRenamePartition extends ZkIntegrationTestBase {
ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
ZK_ADDR, clusterName));
Assert.assertTrue(result);
+
+ stop(clusterName);
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
private void startAndVerify(String clusterName) throws Exception {
- MockParticipant[] participants = new MockParticipant[5];
+ MockParticipantManager[] participants = new MockParticipantManager[5];
- TestHelper
- .startController(clusterName, "controller_0", ZK_ADDR, HelixControllerMain.STANDALONE);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+ controller.syncStart();
// start participants
for (int i = 0; i < 5; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
- // new Thread(participants[i]).start();
}
boolean result =
@@ -142,5 +153,21 @@ public class TestRenamePartition extends ZkIntegrationTestBase {
ZK_ADDR, clusterName));
Assert.assertTrue(result);
+ _participantMap.put(clusterName, participants);
+ _controllerMap.put(clusterName, controller);
+ }
+
+ private void stop(String clusterName) {
+ ClusterControllerManager controller = _controllerMap.get(clusterName);
+ if (controller != null) {
+ controller.syncStop();
+ }
+
+ MockParticipantManager[] participants = _participantMap.get(clusterName);
+ if (participants != null) {
+ for (MockParticipantManager participant : participants) {
+ participant.syncStop();
+ }
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestResetInstance.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestResetInstance.java b/helix-core/src/test/java/org/apache/helix/integration/TestResetInstance.java
index 2715932..7159a17 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestResetInstance.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestResetInstance.java
@@ -25,8 +25,8 @@ import java.util.Map;
import java.util.Set;
import org.apache.helix.TestHelper;
-import org.apache.helix.mock.controller.ClusterController;
-import org.apache.helix.mock.participant.MockParticipant;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.mock.participant.ErrTransition;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.tools.ClusterStateVerifier;
@@ -54,7 +54,8 @@ public class TestResetInstance extends ZkIntegrationTestBase {
"MasterSlave", true); // do rebalance
// start controller
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
Map<String, Set<String>> errPartitions = new HashMap<String, Set<String>>() {
@@ -65,16 +66,15 @@ public class TestResetInstance extends ZkIntegrationTestBase {
};
// start mock participants
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
if (i == 0) {
- participants[i] =
- new MockParticipant(clusterName, instanceName, ZK_ADDR,
- new ErrTransition(errPartitions));
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participants[i].setTransition(new ErrTransition(errPartitions));
} else {
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
}
participants[i].syncStart();
}
@@ -102,8 +102,6 @@ public class TestResetInstance extends ZkIntegrationTestBase {
Assert.assertTrue(result, "Cluster verification fails");
// clean up
- // wait for all zk callbacks done
- Thread.sleep(1000);
controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestResetPartitionState.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestResetPartitionState.java b/helix-core/src/test/java/org/apache/helix/integration/TestResetPartitionState.java
index 09e57c6..c37a5ea 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestResetPartitionState.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestResetPartitionState.java
@@ -28,10 +28,10 @@ import org.apache.helix.NotificationContext;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.PropertyKey.Builder;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.mock.controller.ClusterController;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.mock.participant.ErrTransition;
import org.apache.helix.model.LiveInstance;
import org.apache.helix.model.Message;
@@ -80,7 +80,8 @@ public class TestResetPartitionState extends ZkIntegrationTestBase {
"MasterSlave", true); // do rebalance
// start controller
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
Map<String, Set<String>> errPartitions = new HashMap<String, Set<String>>() {
@@ -91,16 +92,16 @@ public class TestResetPartitionState extends ZkIntegrationTestBase {
};
// start mock participants
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
if (i == 0) {
participants[i] =
- new MockParticipant(clusterName, instanceName, ZK_ADDR,
- new ErrTransition(errPartitions));
+ new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participants[i].setTransition(new ErrTransition(errPartitions));
} else {
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
}
participants[i].syncStart();
}
@@ -169,8 +170,6 @@ public class TestResetPartitionState extends ZkIntegrationTestBase {
Assert.assertEquals(_errToOfflineInvoked, 2, "Should reset 2 partitions");
// clean up
- // wait for all zk callbacks done
- Thread.sleep(1000);
controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestResetResource.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestResetResource.java b/helix-core/src/test/java/org/apache/helix/integration/TestResetResource.java
index de4ad1a..46a05d8 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestResetResource.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestResetResource.java
@@ -25,8 +25,8 @@ import java.util.Map;
import java.util.Set;
import org.apache.helix.TestHelper;
-import org.apache.helix.mock.controller.ClusterController;
-import org.apache.helix.mock.participant.MockParticipant;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.mock.participant.ErrTransition;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.tools.ClusterStateVerifier;
@@ -53,7 +53,8 @@ public class TestResetResource extends ZkIntegrationTestBase {
"MasterSlave", true); // do rebalance
// start controller
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
Map<String, Set<String>> errPartitions = new HashMap<String, Set<String>>() {
@@ -64,16 +65,15 @@ public class TestResetResource extends ZkIntegrationTestBase {
};
// start mock participants
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
if (i == 0) {
- participants[i] =
- new MockParticipant(clusterName, instanceName, ZK_ADDR,
- new ErrTransition(errPartitions));
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participants[i].setTransition(new ErrTransition(errPartitions));
} else {
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
}
participants[i].syncStart();
}
@@ -101,8 +101,6 @@ public class TestResetResource extends ZkIntegrationTestBase {
Assert.assertTrue(result, "Cluster verification fails");
// clean up
- // wait for all zk callbacks done
- Thread.sleep(1000);
controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestRestartParticipant.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestRestartParticipant.java b/helix-core/src/test/java/org/apache/helix/integration/TestRestartParticipant.java
index 008782c..64043ed 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestRestartParticipant.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestRestartParticipant.java
@@ -24,8 +24,8 @@ import java.util.concurrent.atomic.AtomicReference;
import org.apache.helix.NotificationContext;
import org.apache.helix.TestHelper;
-import org.apache.helix.controller.HelixControllerMain;
-import org.apache.helix.mock.participant.MockParticipant;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.mock.participant.MockTransition;
import org.apache.helix.model.Message;
import org.apache.helix.tools.ClusterStateVerifier;
@@ -35,15 +35,15 @@ import org.testng.annotations.Test;
public class TestRestartParticipant extends ZkIntegrationTestBase {
public class KillOtherTransition extends MockTransition {
- final AtomicReference<MockParticipant> _other;
+ final AtomicReference<MockParticipantManager> _other;
- public KillOtherTransition(MockParticipant other) {
- _other = new AtomicReference<MockParticipant>(other);
+ public KillOtherTransition(MockParticipantManager other) {
+ _other = new AtomicReference<MockParticipantManager>(other);
}
@Override
public void doTransition(Message message, NotificationContext context) {
- MockParticipant other = _other.getAndSet(null);
+ MockParticipantManager other = _other.getAndSet(null);
if (other != null) {
System.err.println("Kill " + other.getInstanceName()
+ ". Interrupted exceptions are IGNORABLE");
@@ -58,7 +58,7 @@ public class TestRestartParticipant extends ZkIntegrationTestBase {
System.out.println("START testRestartParticipant at " + new Date(System.currentTimeMillis()));
String clusterName = getShortClassName();
- MockParticipant[] participants = new MockParticipant[5];
+ MockParticipantManager[] participants = new MockParticipantManager[5];
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
"localhost", // participant name prefix
@@ -69,19 +69,19 @@ public class TestRestartParticipant extends ZkIntegrationTestBase {
3, // replicas
"MasterSlave", true); // do rebalance
- TestHelper
- .startController(clusterName, "controller_0", ZK_ADDR, HelixControllerMain.STANDALONE);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+ controller.syncStart();
+
// start participants
for (int i = 0; i < 5; i++) {
String instanceName = "localhost_" + (12918 + i);
if (i == 4) {
- participants[i] =
- new MockParticipant(clusterName, instanceName, ZK_ADDR, new KillOtherTransition(
- participants[0]));
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participants[i].setTransition(new KillOtherTransition(participants[0]));
} else {
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
- // Thread.sleep(100);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
}
participants[i].syncStart();
@@ -94,9 +94,9 @@ public class TestRestartParticipant extends ZkIntegrationTestBase {
// restart
Thread.sleep(500);
- MockParticipant participant =
- new MockParticipant(participants[0].getClusterName(), participants[0].getInstanceName(),
- ZK_ADDR, null);
+ MockParticipantManager participant =
+ new MockParticipantManager(ZK_ADDR, participants[0].getClusterName(),
+ participants[0].getInstanceName());
System.err.println("Restart " + participant.getInstanceName());
participant.syncStart();
result =
@@ -104,6 +104,13 @@ public class TestRestartParticipant extends ZkIntegrationTestBase {
clusterName));
Assert.assertTrue(result);
+ // clean up
+ controller.syncStop();
+ for (int i = 0; i < 5; i++) {
+ participants[i].syncStop();
+ }
+ participant.syncStop();
+
System.out.println("START testRestartParticipant at " + new Date(System.currentTimeMillis()));
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestSchedulerMessage.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestSchedulerMessage.java b/helix-core/src/test/java/org/apache/helix/integration/TestSchedulerMessage.java
index 2c174c4..bf851cc 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestSchedulerMessage.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestSchedulerMessage.java
@@ -194,10 +194,10 @@ public class TestSchedulerMessage extends ZkStandAloneCMTestBaseWithPropertyServ
_factory._results.clear();
HelixManager manager = null;
for (int i = 0; i < NODE_NR; i++) {
- String hostDest = "localhost_" + (START_PORT + i);
- _startCMResultMap.get(hostDest)._manager.getMessagingService().registerMessageHandlerFactory(
+ _participants[i].getMessagingService().registerMessageHandlerFactory(
_factory.getMessageType(), _factory);
- manager = _startCMResultMap.get(hostDest)._manager;
+
+ manager = _participants[i]; // _startCMResultMap.get(hostDest)._manager;
}
Message schedulerMessage =
@@ -282,10 +282,10 @@ public class TestSchedulerMessage extends ZkStandAloneCMTestBaseWithPropertyServ
_factory._results.clear();
HelixManager manager = null;
for (int i = 0; i < NODE_NR; i++) {
- String hostDest = "localhost_" + (START_PORT + i);
- _startCMResultMap.get(hostDest)._manager.getMessagingService().registerMessageHandlerFactory(
+ _participants[i].getMessagingService().registerMessageHandlerFactory(
_factory.getMessageType(), _factory);
- manager = _startCMResultMap.get(hostDest)._manager;
+
+ manager = _participants[i]; // _startCMResultMap.get(hostDest)._manager;
}
Message schedulerMessage =
@@ -367,11 +367,11 @@ public class TestSchedulerMessage extends ZkStandAloneCMTestBaseWithPropertyServ
String controllerStatusPath =
HelixUtil.getControllerPropertyPath(manager.getClusterName(),
PropertyType.STATUSUPDATES_CONTROLLER);
- List<String> subPaths = _zkClient.getChildren(controllerStatusPath);
+ List<String> subPaths = _gZkClient.getChildren(controllerStatusPath);
Assert.assertTrue(subPaths.size() > 0);
for (String subPath : subPaths) {
String nextPath = controllerStatusPath + "/" + subPath;
- List<String> subsubPaths = _zkClient.getChildren(nextPath);
+ List<String> subsubPaths = _gZkClient.getChildren(nextPath);
Assert.assertTrue(subsubPaths.size() > 0);
}
@@ -379,38 +379,38 @@ public class TestSchedulerMessage extends ZkStandAloneCMTestBaseWithPropertyServ
HelixUtil.getInstancePropertyPath(manager.getClusterName(), "localhost_" + (START_PORT),
PropertyType.STATUSUPDATES);
- subPaths = _zkClient.getChildren(instanceStatusPath);
+ subPaths = _gZkClient.getChildren(instanceStatusPath);
Assert.assertTrue(subPaths.size() > 0);
for (String subPath : subPaths) {
String nextPath = instanceStatusPath + "/" + subPath;
- List<String> subsubPaths = _zkClient.getChildren(nextPath);
+ List<String> subsubPaths = _gZkClient.getChildren(nextPath);
Assert.assertTrue(subsubPaths.size() > 0);
for (String subsubPath : subsubPaths) {
String nextnextPath = nextPath + "/" + subsubPath;
- Assert.assertTrue(_zkClient.getChildren(nextnextPath).size() > 0);
+ Assert.assertTrue(_gZkClient.getChildren(nextnextPath).size() > 0);
}
}
Thread.sleep(3000);
- ZKPathDataDumpTask dumpTask = new ZKPathDataDumpTask(manager, _zkClient, 0);
+ ZKPathDataDumpTask dumpTask = new ZKPathDataDumpTask(manager, _gZkClient, 0);
dumpTask.run();
- subPaths = _zkClient.getChildren(controllerStatusPath);
+ subPaths = _gZkClient.getChildren(controllerStatusPath);
Assert.assertTrue(subPaths.size() > 0);
for (String subPath : subPaths) {
String nextPath = controllerStatusPath + "/" + subPath;
- List<String> subsubPaths = _zkClient.getChildren(nextPath);
+ List<String> subsubPaths = _gZkClient.getChildren(nextPath);
Assert.assertTrue(subsubPaths.size() == 0);
}
- subPaths = _zkClient.getChildren(instanceStatusPath);
+ subPaths = _gZkClient.getChildren(instanceStatusPath);
Assert.assertTrue(subPaths.size() > 0);
for (String subPath : subPaths) {
String nextPath = instanceStatusPath + "/" + subPath;
- List<String> subsubPaths = _zkClient.getChildren(nextPath);
+ List<String> subsubPaths = _gZkClient.getChildren(nextPath);
Assert.assertTrue(subsubPaths.size() > 0);
for (String subsubPath : subsubPaths) {
String nextnextPath = nextPath + "/" + subsubPath;
- Assert.assertTrue(_zkClient.getChildren(nextnextPath).size() == 0);
+ Assert.assertTrue(_gZkClient.getChildren(nextnextPath).size() == 0);
}
}
}
@@ -420,10 +420,10 @@ public class TestSchedulerMessage extends ZkStandAloneCMTestBaseWithPropertyServ
_factory._results.clear();
HelixManager manager = null;
for (int i = 0; i < NODE_NR; i++) {
- String hostDest = "localhost_" + (START_PORT + i);
- _startCMResultMap.get(hostDest)._manager.getMessagingService().registerMessageHandlerFactory(
+ _participants[i].getMessagingService().registerMessageHandlerFactory(
_factory.getMessageType(), _factory);
- manager = _startCMResultMap.get(hostDest)._manager;
+
+ manager = _participants[i]; // _startCMResultMap.get(hostDest)._manager;
}
Message schedulerMessage =
@@ -511,10 +511,10 @@ public class TestSchedulerMessage extends ZkStandAloneCMTestBaseWithPropertyServ
TestMessagingHandlerFactory factory = new TestMessagingHandlerFactory();
HelixManager manager = null;
for (int i = 0; i < NODE_NR; i++) {
- String hostDest = "localhost_" + (START_PORT + i);
- _startCMResultMap.get(hostDest)._manager.getMessagingService().registerMessageHandlerFactory(
+ _participants[i].getMessagingService().registerMessageHandlerFactory(
factory.getMessageType(), factory);
- manager = _startCMResultMap.get(hostDest)._manager;
+
+ manager = _participants[i]; // _startCMResultMap.get(hostDest)._manager;
}
Message schedulerMessage =
@@ -581,13 +581,13 @@ public class TestSchedulerMessage extends ZkStandAloneCMTestBaseWithPropertyServ
_factory._results.clear();
HelixManager manager = null;
for (int i = 0; i < NODE_NR; i++) {
- String hostDest = "localhost_" + (START_PORT + i);
- _startCMResultMap.get(hostDest)._manager.getMessagingService().registerMessageHandlerFactory(
+ _participants[i].getMessagingService().registerMessageHandlerFactory(
_factory.getMessageType(), _factory);
- //
- _startCMResultMap.get(hostDest)._manager.getMessagingService().registerMessageHandlerFactory(
+
+ _participants[i].getMessagingService().registerMessageHandlerFactory(
_factory.getMessageType(), _factory);
- manager = _startCMResultMap.get(hostDest)._manager;
+
+ manager = _participants[i]; // _startCMResultMap.get(hostDest)._manager;
}
Message schedulerMessage =
@@ -702,13 +702,13 @@ public class TestSchedulerMessage extends ZkStandAloneCMTestBaseWithPropertyServ
_factory._results.clear();
HelixManager manager = null;
for (int i = 0; i < NODE_NR; i++) {
- String hostDest = "localhost_" + (START_PORT + i);
- _startCMResultMap.get(hostDest)._manager.getMessagingService().registerMessageHandlerFactory(
+ _participants[i].getMessagingService().registerMessageHandlerFactory(
_factory.getMessageType(), _factory);
- //
- _startCMResultMap.get(hostDest)._manager.getMessagingService().registerMessageHandlerFactory(
+
+ _participants[i].getMessagingService().registerMessageHandlerFactory(
_factory.getMessageType(), _factory);
- manager = _startCMResultMap.get(hostDest)._manager;
+
+ manager = _participants[i]; // _startCMResultMap.get(hostDest)._manager;
}
Message schedulerMessage =
@@ -852,13 +852,13 @@ public class TestSchedulerMessage extends ZkStandAloneCMTestBaseWithPropertyServ
TestMessagingHandlerFactoryLatch factory = new TestMessagingHandlerFactoryLatch();
HelixManager manager = null;
for (int i = 0; i < NODE_NR; i++) {
- String hostDest = "localhost_" + (START_PORT + i);
- _startCMResultMap.get(hostDest)._manager.getMessagingService().registerMessageHandlerFactory(
+ _participants[i].getMessagingService().registerMessageHandlerFactory(
factory.getMessageType(), factory);
- //
- _startCMResultMap.get(hostDest)._manager.getMessagingService().registerMessageHandlerFactory(
+
+ _participants[i].getMessagingService().registerMessageHandlerFactory(
factory.getMessageType(), factory);
- manager = _startCMResultMap.get(hostDest)._manager;
+
+ manager = _participants[i]; // _startCMResultMap.get(hostDest)._manager;
}
Message schedulerMessage =
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestSchemataSM.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestSchemataSM.java b/helix-core/src/test/java/org/apache/helix/integration/TestSchemataSM.java
index 3024f45..a927520 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestSchemataSM.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestSchemataSM.java
@@ -27,10 +27,10 @@ import org.apache.helix.HelixConstants;
import org.apache.helix.PropertyKey;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.mock.controller.ClusterController;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.model.ExternalView;
import org.apache.helix.model.IdealState;
import org.apache.helix.tools.ClusterStateVerifier;
@@ -46,7 +46,7 @@ public class TestSchemataSM extends ZkIntegrationTestBase {
String clusterName = className + "_" + methodName;
int n = 5;
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
@@ -70,14 +70,15 @@ public class TestSchemataSM extends ZkIntegrationTestBase {
Arrays.asList(HelixConstants.StateModelToken.ANY_LIVEINSTANCE.toString()));
accessor.setProperty(key, idealState);
- ClusterController controller = new ClusterController(clusterName, "controller", ZK_ADDR);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller");
controller.syncStart();
// start n-1 participants
for (int i = 1; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
@@ -87,7 +88,7 @@ public class TestSchemataSM extends ZkIntegrationTestBase {
Assert.assertTrue(result);
// start the remaining 1 participant
- participants[0] = new MockParticipant(clusterName, "localhost_12918", ZK_ADDR, null);
+ participants[0] = new MockParticipantManager(ZK_ADDR, clusterName, "localhost_12918");
participants[0].syncStart();
// make sure we have all participants in MASTER state
@@ -107,6 +108,7 @@ public class TestSchemataSM extends ZkIntegrationTestBase {
}
// clean up
+ controller.syncStop();
for (int i = 0; i < n; i++) {
participants[i].syncStop();
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestSessionExpiryInTransition.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestSessionExpiryInTransition.java b/helix-core/src/test/java/org/apache/helix/integration/TestSessionExpiryInTransition.java
index f38c6de..965b8ef 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestSessionExpiryInTransition.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestSessionExpiryInTransition.java
@@ -25,10 +25,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.helix.InstanceType;
import org.apache.helix.NotificationContext;
import org.apache.helix.TestHelper;
-import org.apache.helix.ZkHelixTestManager;
import org.apache.helix.ZkTestHelper;
-import org.apache.helix.mock.controller.ClusterController;
-import org.apache.helix.mock.participant.MockParticipant;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.mock.participant.MockTransition;
import org.apache.helix.model.Message;
import org.apache.helix.tools.ClusterStateVerifier;
@@ -39,13 +38,14 @@ import org.testng.Assert;
import org.testng.annotations.Test;
public class TestSessionExpiryInTransition extends ZkIntegrationTestBase {
+ private static Logger LOG = Logger.getLogger(TestSessionExpiryInTransition.class);
public class SessionExpiryTransition extends MockTransition {
private final AtomicBoolean _done = new AtomicBoolean();
@Override
public void doTransition(Message message, NotificationContext context) {
- ZkHelixTestManager manager = (ZkHelixTestManager) context.getManager();
+ MockParticipantManager manager = (MockParticipantManager) context.getManager();
String instance = message.getTgtName();
String partition = message.getPartitionName();
@@ -55,8 +55,7 @@ public class TestSessionExpiryInTransition extends ZkIntegrationTestBase {
try {
ZkTestHelper.expireSession(manager.getZkClient());
} catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.error("Exception expire zk-session", e);
}
}
}
@@ -64,7 +63,7 @@ public class TestSessionExpiryInTransition extends ZkIntegrationTestBase {
@Test
public void testSessionExpiryInTransition() throws Exception {
- Logger.getRootLogger().setLevel(Level.WARN);
+ // Logger.getRootLogger().setLevel(Level.WARN);
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
@@ -72,7 +71,7 @@ public class TestSessionExpiryInTransition extends ZkIntegrationTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
- MockParticipant[] participants = new MockParticipant[5];
+ MockParticipantManager[] participants = new MockParticipantManager[5];
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
"localhost", // participant name prefix
@@ -84,15 +83,15 @@ public class TestSessionExpiryInTransition extends ZkIntegrationTestBase {
"MasterSlave", true); // do rebalance
// start controller
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
for (int i = 0; i < 5; i++) {
String instanceName = "localhost_" + (12918 + i);
- ZkHelixTestManager manager =
- new ZkHelixTestManager(clusterName, instanceName, InstanceType.PARTICIPANT, ZK_ADDR);
- participants[i] = new MockParticipant(manager, new SessionExpiryTransition());
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participants[i].setTransition(new SessionExpiryTransition());
participants[i].syncStart();
}
@@ -102,13 +101,11 @@ public class TestSessionExpiryInTransition extends ZkIntegrationTestBase {
Assert.assertTrue(result);
// clean up
+ controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
}
- Thread.sleep(2000);
- controller.syncStop();
-
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestStandAloneCMMain.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestStandAloneCMMain.java b/helix-core/src/test/java/org/apache/helix/integration/TestStandAloneCMMain.java
index 02a34d8..6eb7a8c 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestStandAloneCMMain.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestStandAloneCMMain.java
@@ -21,9 +21,15 @@ package org.apache.helix.integration;
import java.util.Date;
+import org.apache.helix.HelixDataAccessor;
+import org.apache.helix.PropertyKey;
import org.apache.helix.TestHelper;
-import org.apache.helix.TestHelper.StartCMResult;
-import org.apache.helix.controller.HelixControllerMain;
+import org.apache.helix.TestHelper.Verifier;
+import org.apache.helix.ZNRecord;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.manager.zk.ZKHelixDataAccessor;
+import org.apache.helix.manager.zk.ZkBaseDataAccessor;
+import org.apache.helix.model.LiveInstance;
import org.apache.helix.tools.ClusterStateVerifier;
import org.apache.log4j.Logger;
import org.testng.Assert;
@@ -35,16 +41,34 @@ public class TestStandAloneCMMain extends ZkStandAloneCMTestBase {
@Test()
public void testStandAloneCMMain() throws Exception {
logger.info("RUN testStandAloneCMMain() at " + new Date(System.currentTimeMillis()));
-
+ ClusterControllerManager newController = null;
for (int i = 1; i <= 2; i++) {
String controllerName = "controller_" + i;
- StartCMResult startResult =
- TestHelper.startController(CLUSTER_NAME, controllerName, ZK_ADDR,
- HelixControllerMain.STANDALONE);
- _startCMResultMap.put(controllerName, startResult);
+ newController =
+ new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
+ newController.syncStart();
}
- stopCurrentLeader(_zkClient, CLUSTER_NAME, _startCMResultMap);
+ // stopCurrentLeader(_zkClient, CLUSTER_NAME, _startCMResultMap);
+ _controller.syncStop();
+
+ final HelixDataAccessor accessor =
+ new ZKHelixDataAccessor(CLUSTER_NAME, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
+ final PropertyKey.Builder keyBuilder = accessor.keyBuilder();
+ final String newControllerName = newController.getInstanceName();
+ TestHelper.verify(new Verifier() {
+
+ @Override
+ public boolean verify() throws Exception {
+ LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
+ if (leader == null) {
+ return false;
+ }
+ return leader.getInstanceName().equals(newControllerName);
+
+ }
+ }, 30 * 1000);
+
boolean result =
ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
ZK_ADDR, CLUSTER_NAME));
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestStandAloneCMSessionExpiry.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestStandAloneCMSessionExpiry.java b/helix-core/src/test/java/org/apache/helix/integration/TestStandAloneCMSessionExpiry.java
index 347ff7e..e8adf03 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestStandAloneCMSessionExpiry.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestStandAloneCMSessionExpiry.java
@@ -23,9 +23,9 @@ import java.util.Date;
import org.apache.helix.InstanceType;
import org.apache.helix.TestHelper;
-import org.apache.helix.ZkHelixTestManager;
import org.apache.helix.ZkTestHelper;
-import org.apache.helix.mock.participant.MockParticipant;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.tools.ClusterStateVerifier;
import org.apache.log4j.Logger;
@@ -47,18 +47,16 @@ public class TestStandAloneCMSessionExpiry extends ZkIntegrationTestBase {
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, PARTICIPANT_PREFIX, "TestDB", 1, 20, 5, 3,
"MasterSlave", true);
- MockParticipant[] participants = new MockParticipant[5];
+ MockParticipantManager[] participants = new MockParticipantManager[5];
for (int i = 0; i < 5; i++) {
String instanceName = "localhost_" + (12918 + i);
- ZkHelixTestManager manager =
- new ZkHelixTestManager(clusterName, instanceName, InstanceType.PARTICIPANT, ZK_ADDR);
- participants[i] = new MockParticipant(manager, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
- ZkHelixTestManager controller =
- new ZkHelixTestManager(clusterName, "controller_0", InstanceType.CONTROLLER, ZK_ADDR);
- controller.connect();
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+ controller.syncStart();
boolean result;
result =
@@ -67,7 +65,7 @@ public class TestStandAloneCMSessionExpiry extends ZkIntegrationTestBase {
Assert.assertTrue(result);
// participant session expiry
- ZkHelixTestManager participantToExpire = (ZkHelixTestManager) participants[1].getManager();
+ MockParticipantManager participantToExpire = participants[1];
System.out.println("Expire participant session");
String oldSessionId = participantToExpire.getSessionId();
@@ -107,8 +105,7 @@ public class TestStandAloneCMSessionExpiry extends ZkIntegrationTestBase {
// clean up
System.out.println("Clean up ...");
// Logger.getRootLogger().setLevel(Level.DEBUG);
- controller.disconnect();
- Thread.sleep(100);
+ controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestStartMultipleControllersWithSameName.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestStartMultipleControllersWithSameName.java b/helix-core/src/test/java/org/apache/helix/integration/TestStartMultipleControllersWithSameName.java
index dce3fd4..d191c18 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestStartMultipleControllersWithSameName.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestStartMultipleControllersWithSameName.java
@@ -25,7 +25,7 @@ import org.apache.helix.PropertyPathConfig;
import org.apache.helix.PropertyType;
import org.apache.helix.TestHelper;
import org.apache.helix.ZkTestHelper;
-import org.apache.helix.mock.controller.ClusterController;
+import org.apache.helix.integration.manager.ClusterControllerManager;
import org.apache.helix.model.IdealState.RebalanceMode;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
@@ -54,10 +54,10 @@ public class TestStartMultipleControllersWithSameName extends ZkIntegrationTestB
// rebalance
// start controller
- ClusterController[] controllers = new ClusterController[4];
+ ClusterControllerManager[] controllers = new ClusterControllerManager[4];
for (int i = 0; i < 4; i++) {
- controllers[i] = new ClusterController(clusterName, "controller_0", ZK_ADDR);
- controllers[i].start();
+ controllers[i] = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+ controllers[i].syncStart();
}
Thread.sleep(500); // wait leader election finishes
@@ -69,7 +69,6 @@ public class TestStartMultipleControllersWithSameName extends ZkIntegrationTestB
// clean up
for (int i = 0; i < 4; i++) {
controllers[i].syncStop();
- Thread.sleep(1000); // wait for all zk callbacks done
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestStateTransitionTimeout.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestStateTransitionTimeout.java b/helix-core/src/test/java/org/apache/helix/integration/TestStateTransitionTimeout.java
index edc10c6..a297752 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestStateTransitionTimeout.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestStateTransitionTimeout.java
@@ -28,22 +28,16 @@ import java.util.Set;
import org.apache.helix.HelixDataAccessor;
import org.apache.helix.NotificationContext;
-import org.apache.helix.TestHelper;
import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.TestHelper.StartCMResult;
-import org.apache.helix.controller.HelixControllerMain;
-import org.apache.helix.manager.zk.ZNRecordSerializer;
-import org.apache.helix.manager.zk.ZkClient;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.messaging.handling.MessageHandler.ErrorCode;
-import org.apache.helix.mock.participant.MockJobIntf;
import org.apache.helix.mock.participant.MockMSStateModel;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.mock.participant.MockTransition;
import org.apache.helix.mock.participant.SleepTransition;
import org.apache.helix.model.ExternalView;
import org.apache.helix.model.IdealState;
import org.apache.helix.model.Message;
-import org.apache.helix.participant.statemachine.StateModel;
import org.apache.helix.participant.statemachine.StateModelFactory;
import org.apache.helix.participant.statemachine.StateModelInfo;
import org.apache.helix.participant.statemachine.StateTransitionError;
@@ -59,15 +53,14 @@ import org.testng.annotations.Test;
public class TestStateTransitionTimeout extends ZkStandAloneCMTestBase {
private static Logger LOG = Logger.getLogger(TestStateTransitionTimeout.class);
+ @Override
@BeforeClass
public void beforeClass() throws Exception {
System.out.println("START " + CLASS_NAME + " at " + new Date(System.currentTimeMillis()));
- _zkClient = new ZkClient(ZK_ADDR);
- _zkClient.setZkSerializer(new ZNRecordSerializer());
String namespace = "/" + CLUSTER_NAME;
- if (_zkClient.exists(namespace)) {
- _zkClient.deleteRecursive(namespace);
+ if (_gZkClient.exists(namespace)) {
+ _gZkClient.deleteRecursive(namespace);
}
_setupTool = new ClusterSetup(ZK_ADDR);
@@ -106,12 +99,14 @@ public class TestStateTransitionTimeout extends ZkStandAloneCMTestBase {
_sleep = sleep;
}
+ @Override
@Transition(to = "SLAVE", from = "OFFLINE")
public void onBecomeSlaveFromOffline(Message message, NotificationContext context) {
LOG.info("Become SLAVE from OFFLINE");
}
+ @Override
@Transition(to = "MASTER", from = "SLAVE")
public void onBecomeMasterFromSlave(Message message, NotificationContext context)
throws InterruptedException {
@@ -121,23 +116,27 @@ public class TestStateTransitionTimeout extends ZkStandAloneCMTestBase {
}
}
+ @Override
@Transition(to = "SLAVE", from = "MASTER")
public void onBecomeSlaveFromMaster(Message message, NotificationContext context) {
LOG.info("Become SLAVE from MASTER");
}
+ @Override
@Transition(to = "OFFLINE", from = "SLAVE")
public void onBecomeOfflineFromSlave(Message message, NotificationContext context) {
LOG.info("Become OFFLINE from SLAVE");
}
+ @Override
@Transition(to = "DROPPED", from = "OFFLINE")
public void onBecomeDroppedFromOffline(Message message, NotificationContext context) {
LOG.info("Become DROPPED from OFFLINE");
}
+ @Override
public void rollbackOnError(Message message, NotificationContext context,
StateTransitionError error) {
_error = error;
@@ -171,7 +170,7 @@ public class TestStateTransitionTimeout extends ZkStandAloneCMTestBase {
@Test
public void testStateTransitionTimeOut() throws Exception {
Map<String, SleepStateModelFactory> factories = new HashMap<String, SleepStateModelFactory>();
- MockParticipant[] participants = new MockParticipant[NODE_NR];
+ // MockParticipantManager[] participants = new MockParticipantManager[NODE_NR];
IdealState idealState =
_setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, TEST_DB);
for (int i = 0; i < NODE_NR; i++) {
@@ -184,19 +183,20 @@ public class TestStateTransitionTimeout extends ZkStandAloneCMTestBase {
}
}
- participants[i] = new MockParticipant(factory, CLUSTER_NAME, instanceName, ZK_ADDR, null);
- participants[i].syncStart();
+ _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
+ _participants[i].getStateMachineEngine().registerStateModelFactory("MasterSlave", factory);
+ _participants[i].syncStart();
}
String controllerName = CONTROLLER_PREFIX + "_0";
- StartCMResult startResult =
- TestHelper.startController(CLUSTER_NAME, controllerName, ZK_ADDR,
- HelixControllerMain.STANDALONE);
- _startCMResultMap.put(controllerName, startResult);
+ _controller =
+ new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
+ _controller.syncStart();
+
boolean result =
ClusterStateVerifier
.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, CLUSTER_NAME));
Assert.assertTrue(result);
- HelixDataAccessor accessor = participants[0].getManager().getHelixDataAccessor();
+ HelixDataAccessor accessor = _participants[0].getHelixDataAccessor();
Builder kb = accessor.keyBuilder();
ExternalView ev = accessor.getProperty(kb.externalView(TEST_DB));
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestSwapInstance.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestSwapInstance.java b/helix-core/src/test/java/org/apache/helix/integration/TestSwapInstance.java
index a1f63aa..6cce716 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestSwapInstance.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestSwapInstance.java
@@ -21,9 +21,8 @@ package org.apache.helix.integration;
import org.apache.helix.HelixDataAccessor;
import org.apache.helix.HelixManager;
-import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
-import org.apache.helix.TestHelper.StartCMResult;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixAdmin;
import org.apache.helix.model.IdealState;
import org.apache.helix.tools.ClusterStateVerifier;
@@ -33,8 +32,7 @@ import org.testng.annotations.Test;
public class TestSwapInstance extends ZkStandAloneCMTestBase {
@Test
public void TestSwap() throws Exception {
- String controllerName = CONTROLLER_PREFIX + "_0";
- HelixManager manager = _startCMResultMap.get(controllerName)._manager;
+ HelixManager manager = _controller;
HelixDataAccessor helixAccessor = manager.getHelixDataAccessor();
_setupTool.addResourceToCluster(CLUSTER_NAME, "MyDB", 64, STATE_MODEL);
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, "MyDB", _replica);
@@ -49,7 +47,7 @@ public class TestSwapInstance extends ZkStandAloneCMTestBase {
idealStateOld2.merge(is2.getRecord());
String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + 0);
- ZKHelixAdmin tool = new ZKHelixAdmin(_zkClient);
+ ZKHelixAdmin tool = new ZKHelixAdmin(_gZkClient);
_setupTool.getClusterManagementTool().enableInstance(CLUSTER_NAME, instanceName, false);
boolean result =
@@ -68,8 +66,7 @@ public class TestSwapInstance extends ZkStandAloneCMTestBase {
}
Assert.assertTrue(exception);
- _startCMResultMap.get(instanceName)._manager.disconnect();
- _startCMResultMap.get(instanceName)._thread.interrupt();
+ _participants[0].syncStop();
Thread.sleep(1000);
exception = false;
@@ -80,8 +77,9 @@ public class TestSwapInstance extends ZkStandAloneCMTestBase {
exception = true;
}
Assert.assertFalse(exception);
- StartCMResult result2 = TestHelper.startDummyProcess(ZK_ADDR, CLUSTER_NAME, instanceName2);
- _startCMResultMap.put(instanceName2, result2);
+ MockParticipantManager newParticipant =
+ new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName2);
+ newParticipant.syncStart();
result =
ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
[10/10] git commit: [HELIX-279] Apply gc handling fixes to main
ZKHelixManager class,
adding back HelixManager#ALLOW_PARTICIPANT_AUTO_JOIN and mark it deprecated
Posted by zz...@apache.org.
[HELIX-279] Apply gc handling fixes to main ZKHelixManager class, adding back HelixManager#ALLOW_PARTICIPANT_AUTO_JOIN and mark it deprecated
Project: http://git-wip-us.apache.org/repos/asf/incubator-helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-helix/commit/002acfd6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-helix/tree/002acfd6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-helix/diff/002acfd6
Branch: refs/heads/helix-0.6.2-release
Commit: 002acfd64c95c3119d746c8f7aef92b6383b9e7f
Parents: a416e74
Author: zzhang <zz...@apache.org>
Authored: Thu Oct 24 17:15:58 2013 -0700
Committer: zzhang <zz...@apache.org>
Committed: Thu Oct 24 17:15:58 2013 -0700
----------------------------------------------------------------------
helix-core/src/main/java/org/apache/helix/HelixManager.java | 4 ++++
1 file changed, 4 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/002acfd6/helix-core/src/main/java/org/apache/helix/HelixManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/HelixManager.java b/helix-core/src/main/java/org/apache/helix/HelixManager.java
index d129792..a400686 100644
--- a/helix-core/src/main/java/org/apache/helix/HelixManager.java
+++ b/helix-core/src/main/java/org/apache/helix/HelixManager.java
@@ -23,6 +23,7 @@ import java.util.List;
import org.apache.helix.controller.GenericHelixController;
import org.apache.helix.healthcheck.ParticipantHealthReportCollector;
+import org.apache.helix.manager.zk.ZKHelixManager;
import org.apache.helix.model.HelixConfigScope.ConfigScopeProperty;
import org.apache.helix.participant.HelixStateMachineEngine;
import org.apache.helix.participant.StateMachineEngine;
@@ -53,6 +54,9 @@ import org.apache.helix.store.zk.ZkHelixPropertyStore;
* @see GenericHelixController RoutingTableProvider for controller
*/
public interface HelixManager {
+ @Deprecated
+ public static final String ALLOW_PARTICIPANT_AUTO_JOIN =
+ ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN;
/**
* Start participating in the cluster operations. All listeners will be
[04/10] [HELIX-279] Apply gc handling fixes to main ZKHelixManager
class
Posted by zz...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestCarryOverBadCurState.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestCarryOverBadCurState.java b/helix-core/src/test/java/org/apache/helix/integration/TestCarryOverBadCurState.java
index 9d63a65..97b6ebb 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestCarryOverBadCurState.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestCarryOverBadCurState.java
@@ -25,8 +25,8 @@ import org.apache.helix.PropertyPathConfig;
import org.apache.helix.PropertyType;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
-import org.apache.helix.controller.HelixControllerMain;
-import org.apache.helix.mock.participant.MockParticipant;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.tools.ClusterStateVerifier;
import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier;
import org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier;
@@ -39,7 +39,7 @@ public class TestCarryOverBadCurState extends ZkIntegrationTestBase {
System.out.println("START testCarryOverBadCurState at " + new Date(System.currentTimeMillis()));
String clusterName = getShortClassName();
- MockParticipant[] participants = new MockParticipant[5];
+ MockParticipantManager[] participants = new MockParticipantManager[5];
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
"localhost", // participant name prefix
@@ -58,13 +58,15 @@ public class TestCarryOverBadCurState extends ZkIntegrationTestBase {
_gZkClient.createPersistent(path, true);
_gZkClient.writeData(path, badCurState);
- TestHelper
- .startController(clusterName, "controller_0", ZK_ADDR, HelixControllerMain.STANDALONE);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+ controller.syncStart();
+
// start participants
for (int i = 0; i < 5; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
@@ -78,6 +80,11 @@ public class TestCarryOverBadCurState extends ZkIntegrationTestBase {
clusterName));
Assert.assertTrue(result);
+ // clean up
+ controller.syncStop();
+ for (int i = 0; i < 5; i++) {
+ participants[i].syncStop();
+ }
System.out.println("END testCarryOverBadCurState at " + new Date(System.currentTimeMillis()));
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestCleanupExternalView.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestCleanupExternalView.java b/helix-core/src/test/java/org/apache/helix/integration/TestCleanupExternalView.java
index 781aa89..e7a7ea0 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestCleanupExternalView.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestCleanupExternalView.java
@@ -20,11 +20,11 @@ package org.apache.helix.integration;
*/
import org.apache.helix.*;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixAdmin;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.mock.controller.ClusterController;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.model.ExternalView;
import org.apache.helix.model.LiveInstance;
import org.apache.helix.tools.ClusterStateVerifier;
@@ -57,15 +57,16 @@ public class TestCleanupExternalView extends ZkUnitTestBase {
2, // replicas
"MasterSlave", true); // do rebalance
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
@@ -80,7 +81,7 @@ public class TestCleanupExternalView extends ZkUnitTestBase {
admin.enableCluster(clusterName, false);
// wait all pending zk-events being processed, otherwise remove current-state will cause
// controller send O->S message
- ZkTestHelper.tryWaitZkEventsCleaned(controller.getManager().getZkClient());
+ ZkTestHelper.tryWaitZkEventsCleaned(controller.getZkClient());
// System.out.println("paused controller");
// drop resource
@@ -117,8 +118,13 @@ public class TestCleanupExternalView extends ZkUnitTestBase {
Assert.assertNull(externalView, "external-view for TestDB0 should be removed, but was: "
+ externalView);
- System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
+ // clean up
+ controller.syncStop();
+ for (int i = 0; i < n; i++) {
+ participants[i].syncStop();
+ }
+ System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestClusterStartsup.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestClusterStartsup.java b/helix-core/src/test/java/org/apache/helix/integration/TestClusterStartsup.java
index c0ced72..e844a27 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestClusterStartsup.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestClusterStartsup.java
@@ -26,7 +26,6 @@ import org.apache.helix.HelixManager;
import org.apache.helix.HelixManagerFactory;
import org.apache.helix.InstanceType;
import org.apache.helix.PropertyType;
-import org.apache.helix.manager.zk.ZkClient;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.util.HelixUtil;
import org.testng.Assert;
@@ -40,8 +39,8 @@ public class TestClusterStartsup extends ZkStandAloneCMTestBase {
System.out.println("START " + CLASS_NAME + " at " + new Date(System.currentTimeMillis()));
String namespace = "/" + CLUSTER_NAME;
- if (_zkClient.exists(namespace)) {
- _zkClient.deleteRecursive(namespace);
+ if (_gZkClient.exists(namespace)) {
+ _gZkClient.deleteRecursive(namespace);
}
_setupTool = new ClusterSetup(ZK_ADDR);
@@ -58,13 +57,12 @@ public class TestClusterStartsup extends ZkStandAloneCMTestBase {
@Override
@BeforeClass()
public void beforeClass() throws Exception {
- _zkClient = new ZkClient(ZK_ADDR);
+
}
@Override
@AfterClass()
public void afterClass() {
- _zkClient.close();
}
@Test()
@@ -72,9 +70,8 @@ public class TestClusterStartsup extends ZkStandAloneCMTestBase {
setupCluster();
String controllerMsgPath =
HelixUtil.getControllerPropertyPath(CLUSTER_NAME, PropertyType.MESSAGES_CONTROLLER);
- _zkClient.deleteRecursive(controllerMsgPath);
+ _gZkClient.deleteRecursive(controllerMsgPath);
HelixManager manager = null;
- ;
try {
manager =
@@ -106,7 +103,7 @@ public class TestClusterStartsup extends ZkStandAloneCMTestBase {
setupCluster();
String stateModelPath = HelixUtil.getStateModelDefinitionPath(CLUSTER_NAME);
- _zkClient.deleteRecursive(stateModelPath);
+ _gZkClient.deleteRecursive(stateModelPath);
try {
manager =
@@ -125,7 +122,7 @@ public class TestClusterStartsup extends ZkStandAloneCMTestBase {
String instanceStatusUpdatePath =
HelixUtil.getInstancePropertyPath(CLUSTER_NAME, "localhost_" + (START_PORT + 1),
PropertyType.STATUSUPDATES);
- _zkClient.deleteRecursive(instanceStatusUpdatePath);
+ _gZkClient.deleteRecursive(instanceStatusUpdatePath);
try {
manager =
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestCustomIdealState.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestCustomIdealState.java b/helix-core/src/test/java/org/apache/helix/integration/TestCustomIdealState.java
index 43cfa5a..5467932 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestCustomIdealState.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestCustomIdealState.java
@@ -32,18 +32,6 @@ import org.testng.annotations.Test;
public class TestCustomIdealState extends ZkIntegrationTestBase {
private static Logger LOG = Logger.getLogger(TestCustomIdealState.class);
- ZkClient _zkClient;
-
- @BeforeClass
- public void beforeClass() throws Exception {
- _zkClient = new ZkClient(ZK_ADDR);
- _zkClient.setZkSerializer(new ZNRecordSerializer());
- }
-
- @AfterClass
- public void afterClass() {
- _zkClient.close();
- }
@Test
public void testBasic() throws Exception {
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestCustomizedIdealStateRebalancer.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestCustomizedIdealStateRebalancer.java b/helix-core/src/test/java/org/apache/helix/integration/TestCustomizedIdealStateRebalancer.java
index 7811c0d..f797d0f 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestCustomizedIdealStateRebalancer.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestCustomizedIdealStateRebalancer.java
@@ -81,12 +81,12 @@ public class TestCustomizedIdealStateRebalancer extends
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, db2, 3);
boolean result =
- ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_zkClient,
+ ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_gZkClient,
CLUSTER_NAME, db2));
Assert.assertTrue(result);
Thread.sleep(1000);
HelixDataAccessor accessor =
- new ZKHelixDataAccessor(CLUSTER_NAME, new ZkBaseDataAccessor(_zkClient));
+ new ZKHelixDataAccessor(CLUSTER_NAME, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
ExternalView ev = accessor.getProperty(keyBuilder.externalView(db2));
Assert.assertEquals(ev.getPartitionSet().size(), 60);
@@ -116,7 +116,7 @@ public class TestCustomizedIdealStateRebalancer extends
public boolean verify() {
try {
HelixDataAccessor accessor =
- new ZKHelixDataAccessor(_clusterName, new ZkBaseDataAccessor(_client));
+ new ZKHelixDataAccessor(_clusterName, new ZkBaseDataAccessor<ZNRecord>(_client));
Builder keyBuilder = accessor.keyBuilder();
int numberOfPartitions =
accessor.getProperty(keyBuilder.idealStates(_resourceName)).getRecord().getListFields()
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestDisable.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestDisable.java b/helix-core/src/test/java/org/apache/helix/integration/TestDisable.java
index 3341e6b..4744508 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestDisable.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestDisable.java
@@ -27,10 +27,10 @@ import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.ZkTestHelper;
import org.apache.helix.PropertyKey.Builder;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.mock.controller.ClusterController;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.model.IdealState;
import org.apache.helix.model.IdealState.RebalanceMode;
import org.apache.helix.tools.ClusterSetup;
@@ -52,7 +52,7 @@ public class TestDisable extends ZkIntegrationTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
"localhost", // participant name prefix
@@ -72,14 +72,15 @@ public class TestDisable extends ZkIntegrationTestBase {
accessor.setProperty(keyBuilder.idealStates("TestDB0"), idealState);
// start controller
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
@@ -120,7 +121,6 @@ public class TestDisable extends ZkIntegrationTestBase {
// clean up
// wait for all zk callbacks done
- Thread.sleep(1000);
controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
@@ -140,7 +140,7 @@ public class TestDisable extends ZkIntegrationTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
"localhost", // participant name prefix
@@ -152,14 +152,15 @@ public class TestDisable extends ZkIntegrationTestBase {
"MasterSlave", true); // do rebalance
// start controller
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
@@ -200,7 +201,6 @@ public class TestDisable extends ZkIntegrationTestBase {
// clean up
// wait for all zk callbacks done
- Thread.sleep(1000);
controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
@@ -219,7 +219,7 @@ public class TestDisable extends ZkIntegrationTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
"localhost", // participant name prefix
@@ -239,14 +239,15 @@ public class TestDisable extends ZkIntegrationTestBase {
accessor.setProperty(keyBuilder.idealStates("TestDB0"), idealState);
// start controller
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
@@ -292,7 +293,6 @@ public class TestDisable extends ZkIntegrationTestBase {
// clean up
// wait for all zk callbacks done
- Thread.sleep(1000);
controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
@@ -311,7 +311,7 @@ public class TestDisable extends ZkIntegrationTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
"localhost", // participant name prefix
@@ -323,14 +323,15 @@ public class TestDisable extends ZkIntegrationTestBase {
"MasterSlave", true); // do rebalance
// start controller
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
@@ -376,7 +377,6 @@ public class TestDisable extends ZkIntegrationTestBase {
// clean up
// wait for all zk callbacks done
- Thread.sleep(1000);
controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestDisableNode.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestDisableNode.java b/helix-core/src/test/java/org/apache/helix/integration/TestDisableNode.java
index 93c765c..be523d0 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestDisableNode.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestDisableNode.java
@@ -38,7 +38,7 @@ public class TestDisableNode extends ZkStandAloneCMTestBaseWithPropertyServerChe
ZK_ADDR, CLUSTER_NAME));
Assert.assertTrue(result);
- ZKHelixAdmin tool = new ZKHelixAdmin(_zkClient);
+ ZKHelixAdmin tool = new ZKHelixAdmin(_gZkClient);
tool.enableInstance(CLUSTER_NAME, PARTICIPANT_PREFIX + "_12918", true);
result =
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestDisablePartition.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestDisablePartition.java b/helix-core/src/test/java/org/apache/helix/integration/TestDisablePartition.java
index 3067a0b..ba7e8e4 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestDisablePartition.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestDisablePartition.java
@@ -56,7 +56,7 @@ public class TestDisablePartition extends ZkStandAloneCMTestBaseWithPropertyServ
TestHelper.verifyState(CLUSTER_NAME, ZK_ADDR, map, "OFFLINE");
- ZKHelixAdmin tool = new ZKHelixAdmin(_zkClient);
+ ZKHelixAdmin tool = new ZKHelixAdmin(_gZkClient);
tool.enablePartition(true, CLUSTER_NAME, "localhost_12919", "TestDB", Arrays.asList("TestDB_9"));
result =
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestDistributedCMMain.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestDistributedCMMain.java b/helix-core/src/test/java/org/apache/helix/integration/TestDistributedCMMain.java
index 29627a2..e3b0cc7 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestDistributedCMMain.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestDistributedCMMain.java
@@ -25,10 +25,10 @@ import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.PropertyKey.Builder;
import org.apache.helix.controller.HelixControllerMain;
+import org.apache.helix.integration.manager.ClusterDistributedController;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.mock.controller.ClusterController;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.model.LiveInstance;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.tools.ClusterStateVerifier;
@@ -77,11 +77,10 @@ public class TestDistributedCMMain extends ZkIntegrationTestBase {
"LeaderStandby", true); // do rebalance
// start distributed cluster controllers
- ClusterController[] controllers = new ClusterController[n + n];
+ ClusterDistributedController[] controllers = new ClusterDistributedController[n + n];
for (int i = 0; i < n; i++) {
controllers[i] =
- new ClusterController(controllerClusterName, "controller_" + i, ZK_ADDR,
- HelixControllerMain.DISTRIBUTED.toString());
+ new ClusterDistributedController(ZK_ADDR, controllerClusterName, "controller_" + i);
controllers[i].syncStart();
}
@@ -92,11 +91,11 @@ public class TestDistributedCMMain extends ZkIntegrationTestBase {
Assert.assertTrue(result, "Controller cluster NOT in ideal state");
// start first cluster
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
final String firstClusterName = clusterNamePrefix + "0_0";
for (int i = 0; i < n; i++) {
String instanceName = "localhost0_" + (12918 + i);
- participants[i] = new MockParticipant(firstClusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, firstClusterName, instanceName);
participants[i].syncStart();
}
@@ -114,8 +113,7 @@ public class TestDistributedCMMain extends ZkIntegrationTestBase {
setupTool.rebalanceStorageCluster(controllerClusterName, clusterNamePrefix + "0", 6);
for (int i = n; i < 2 * n; i++) {
controllers[i] =
- new ClusterController(controllerClusterName, "controller_" + i, ZK_ADDR,
- HelixControllerMain.DISTRIBUTED.toString());
+ new ClusterDistributedController(ZK_ADDR, controllerClusterName, "controller_" + i);
controllers[i].syncStart();
}
@@ -157,7 +155,6 @@ public class TestDistributedCMMain extends ZkIntegrationTestBase {
// clean up
// wait for all zk callbacks done
System.out.println("Cleaning up...");
- Thread.sleep(2000);
for (int i = 0; i < 5; i++) {
result =
ClusterStateVerifier
@@ -166,7 +163,6 @@ public class TestDistributedCMMain extends ZkIntegrationTestBase {
controllers[i].syncStop();
}
- // Thread.sleep(2000);
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestDistributedClusterController.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestDistributedClusterController.java b/helix-core/src/test/java/org/apache/helix/integration/TestDistributedClusterController.java
index ed60971..3cf4ed5 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestDistributedClusterController.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestDistributedClusterController.java
@@ -25,10 +25,10 @@ import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.PropertyKey.Builder;
import org.apache.helix.controller.HelixControllerMain;
+import org.apache.helix.integration.manager.ClusterDistributedController;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.mock.controller.ClusterController;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.model.LiveInstance;
import org.apache.helix.tools.ClusterStateVerifier;
import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier;
@@ -76,11 +76,10 @@ public class TestDistributedClusterController extends ZkIntegrationTestBase {
"LeaderStandby", true); // do rebalance
// start distributed cluster controllers
- ClusterController[] controllers = new ClusterController[n];
+ ClusterDistributedController[] controllers = new ClusterDistributedController[n];
for (int i = 0; i < n; i++) {
controllers[i] =
- new ClusterController(controllerClusterName, "controller_" + i, ZK_ADDR,
- HelixControllerMain.DISTRIBUTED.toString());
+ new ClusterDistributedController(ZK_ADDR, controllerClusterName, "controller_" + i);
controllers[i].syncStart();
}
@@ -91,11 +90,11 @@ public class TestDistributedClusterController extends ZkIntegrationTestBase {
Assert.assertTrue(result, "Controller cluster NOT in ideal state");
// start first cluster
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
final String firstClusterName = clusterNamePrefix + "0_0";
for (int i = 0; i < n; i++) {
String instanceName = "localhost0_" + (12918 + i);
- participants[i] = new MockParticipant(firstClusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, firstClusterName, instanceName);
participants[i].syncStart();
}
@@ -114,11 +113,11 @@ public class TestDistributedClusterController extends ZkIntegrationTestBase {
controllers[j].syncStop();
// setup the second cluster
- MockParticipant[] participants2 = new MockParticipant[n];
+ MockParticipantManager[] participants2 = new MockParticipantManager[n];
final String secondClusterName = clusterNamePrefix + "0_1";
for (int i = 0; i < n; i++) {
String instanceName = "localhost1_" + (12918 + i);
- participants2[i] = new MockParticipant(secondClusterName, instanceName, ZK_ADDR, null);
+ participants2[i] = new MockParticipantManager(ZK_ADDR, secondClusterName, instanceName);
participants2[i].syncStart();
}
@@ -130,7 +129,6 @@ public class TestDistributedClusterController extends ZkIntegrationTestBase {
// clean up
// wait for all zk callbacks done
System.out.println("Cleaning up...");
- Thread.sleep(1000);
for (int i = 0; i < 5; i++) {
result =
ClusterStateVerifier
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestDriver.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestDriver.java b/helix-core/src/test/java/org/apache/helix/integration/TestDriver.java
index 951607b..4dad7c0 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestDriver.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestDriver.java
@@ -33,8 +33,9 @@ import org.apache.helix.PropertyPathConfig;
import org.apache.helix.PropertyType;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
-import org.apache.helix.TestHelper.StartCMResult;
import org.apache.helix.controller.HelixControllerMain;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZNRecordSerializer;
import org.apache.helix.manager.zk.ZkClient;
import org.apache.helix.model.IdealState.IdealStateProperty;
@@ -79,10 +80,8 @@ public class TestDriver {
public final int _numNode;
public final int _replica;
- // public final Map<String, ZNRecord> _idealStateMap = new
- // ConcurrentHashMap<String, ZNRecord>();
- public final Map<String, StartCMResult> _startCMResultMap =
- new ConcurrentHashMap<String, StartCMResult>();
+ public final Map<String, HelixManager> _managers =
+ new ConcurrentHashMap<String, HelixManager>();
public TestInfo(String clusterName, ZkClient zkClient, int numDb, int numPartitionsPerDb,
int numNode, int replica) {
@@ -118,10 +117,6 @@ public class TestDriver {
replica, true);
}
- // public static void setupCluster(String uniqTestName, ZkClient zkClient, int
- // numDb,
- // int numPartitionPerDb, int numNodes, int replica, boolean doRebalance)
- // throws Exception
public static void setupCluster(String uniqClusterName, String zkAddr, int numResources,
int numPartitionsPerResource, int numInstances, int replica, boolean doRebalance)
throws Exception {
@@ -193,11 +188,15 @@ public class TestDriver {
for (int id : instanceIds) {
String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + id);
- if (testInfo._startCMResultMap.containsKey(instanceName)) {
+ // if (testInfo._startCMResultMap.containsKey(instanceName)) {
+ if (testInfo._managers.containsKey(instanceName)) {
LOG.warn("Dummy participant:" + instanceName + " has already started; skip starting it");
} else {
- StartCMResult result = TestHelper.startDummyProcess(ZK_ADDR, clusterName, instanceName);
- testInfo._startCMResultMap.put(instanceName, result);
+ // StartCMResult result = TestHelper.startDummyProcess(ZK_ADDR, clusterName, instanceName);
+ MockParticipantManager participant =
+ new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participant.syncStart();
+ testInfo._managers.put(instanceName, participant);
// testInfo._instanceStarted.countDown();
}
}
@@ -220,13 +219,13 @@ public class TestDriver {
for (int id : nodeIds) {
String controllerName = CONTROLLER_PREFIX + "_" + id;
- if (testInfo._startCMResultMap.containsKey(controllerName)) {
+ if (testInfo._managers.containsKey(controllerName)) {
LOG.warn("Controller:" + controllerName + " has already started; skip starting it");
} else {
- StartCMResult result =
- TestHelper.startController(clusterName, controllerName, ZK_ADDR,
- HelixControllerMain.STANDALONE);
- testInfo._startCMResultMap.put(controllerName, result);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, controllerName);
+ controller.syncStart();
+ testInfo._managers.put(controllerName, controller);
}
}
}
@@ -257,27 +256,22 @@ public class TestDriver {
TestInfo testInfo = _testInfoMap.remove(uniqClusterName);
// stop controller first
- for (Iterator<Entry<String, StartCMResult>> it =
- testInfo._startCMResultMap.entrySet().iterator(); it.hasNext();) {
- Map.Entry<String, StartCMResult> entry = it.next();
- String instanceName = entry.getKey();
+ for (String instanceName : testInfo._managers.keySet()) {
if (instanceName.startsWith(CONTROLLER_PREFIX)) {
- it.remove();
- HelixManager manager = entry.getValue()._manager;
- manager.disconnect();
- Thread thread = entry.getValue()._thread;
- thread.interrupt();
+ ClusterControllerManager controller =
+ (ClusterControllerManager) testInfo._managers.get(instanceName);
+ controller.syncStop();
}
}
Thread.sleep(1000);
- // stop the rest
- for (Map.Entry<String, StartCMResult> entry : testInfo._startCMResultMap.entrySet()) {
- HelixManager manager = entry.getValue()._manager;
- manager.disconnect();
- Thread thread = entry.getValue()._thread;
- thread.interrupt();
+ for (String instanceName : testInfo._managers.keySet()) {
+ if (!instanceName.startsWith(CONTROLLER_PREFIX)) {
+ MockParticipantManager participant =
+ (MockParticipantManager) testInfo._managers.get(instanceName);
+ participant.syncStop();
+ }
}
testInfo._zkClient.close();
@@ -292,23 +286,24 @@ public class TestDriver {
}
TestInfo testInfo = _testInfoMap.get(uniqClusterName);
- // String clusterName = testInfo._clusterName;
String failHost = PARTICIPANT_PREFIX + "_" + (START_PORT + instanceId);
- StartCMResult result = testInfo._startCMResultMap.remove(failHost);
+ MockParticipantManager participant =
+ (MockParticipantManager) testInfo._managers.remove(failHost);
// TODO need sync
- if (result == null || result._manager == null || result._thread == null) {
+ if (participant == null) {
String errMsg = "Dummy participant:" + failHost + " seems not running";
LOG.error(errMsg);
} else {
// System.err.println("try to stop participant: " +
// result._manager.getInstanceName());
- NodeOpArg arg = new NodeOpArg(result._manager, result._thread);
- TestCommand command = new TestCommand(CommandType.STOP, new TestTrigger(beginTime), arg);
- List<TestCommand> commandList = new ArrayList<TestCommand>();
- commandList.add(command);
- TestExecutor.executeTestAsync(commandList, ZK_ADDR);
+ // NodeOpArg arg = new NodeOpArg(result._manager, result._thread);
+ // TestCommand command = new TestCommand(CommandType.STOP, new TestTrigger(beginTime), arg);
+ // List<TestCommand> commandList = new ArrayList<TestCommand>();
+ // commandList.add(command);
+ // TestExecutor.executeTestAsync(commandList, ZK_ADDR);
+ participant.syncStop();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestDrop.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestDrop.java b/helix-core/src/test/java/org/apache/helix/integration/TestDrop.java
index b1fcc60..5b54fad 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestDrop.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestDrop.java
@@ -25,27 +25,21 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.I0Itec.zkclient.DataUpdater;
-import org.I0Itec.zkclient.IZkChildListener;
-import org.I0Itec.zkclient.IZkDataListener;
-import org.apache.helix.BaseDataAccessor;
import org.apache.helix.HelixDataAccessor;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.PropertyKey.Builder;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.mock.controller.ClusterController;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.mock.participant.ErrTransition;
import org.apache.helix.model.ExternalView;
import org.apache.helix.model.InstanceConfig;
import org.apache.helix.model.builder.CustomModeISBuilder;
-import org.apache.helix.model.builder.IdealStateBuilder;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.tools.ClusterStateVerifier;
import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier;
-import org.apache.zookeeper.data.Stat;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -60,7 +54,7 @@ public class TestDrop extends ZkIntegrationTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
"localhost", // participant name prefix
@@ -72,7 +66,8 @@ public class TestDrop extends ZkIntegrationTestBase {
"MasterSlave", true); // do rebalance
// start controller
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
@@ -84,11 +79,10 @@ public class TestDrop extends ZkIntegrationTestBase {
String instanceName = "localhost_" + (12918 + i);
if (i == 0) {
- participants[i] =
- new MockParticipant(clusterName, instanceName, ZK_ADDR, new ErrTransition(
- errTransitions));
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participants[i].setTransition(new ErrTransition(errTransitions));
} else {
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
}
participants[i].syncStart();
}
@@ -114,13 +108,10 @@ public class TestDrop extends ZkIntegrationTestBase {
Assert.assertTrue(result);
// clean up
- // wait for all zk callbacks done
- // Thread.sleep(1000);
- // controller.syncStop();
- // for (int i = 0; i < 5; i++)
- // {
- // participants[i].syncStop();
- // }
+ controller.syncStop();
+ for (int i = 0; i < n; i++) {
+ participants[i].syncStop();
+ }
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
@@ -135,7 +126,7 @@ public class TestDrop extends ZkIntegrationTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
"localhost", // participant name prefix
@@ -147,7 +138,8 @@ public class TestDrop extends ZkIntegrationTestBase {
"MasterSlave", true); // do rebalance
// start controller
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
@@ -159,11 +151,10 @@ public class TestDrop extends ZkIntegrationTestBase {
String instanceName = "localhost_" + (12918 + i);
if (i == 0) {
- participants[i] =
- new MockParticipant(clusterName, instanceName, ZK_ADDR, new ErrTransition(
- errTransitions));
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participants[i].setTransition(new ErrTransition(errTransitions));
} else {
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
}
participants[i].syncStart();
}
@@ -198,13 +189,10 @@ public class TestDrop extends ZkIntegrationTestBase {
Assert.assertEquals(disabledPartitions.get(0), "TestDB0_4");
// clean up
- // wait for all zk callbacks done
- // Thread.sleep(1000);
- // controller.syncStop();
- // for (int i = 0; i < 5; i++)
- // {
- // participants[i].syncStop();
- // }
+ controller.syncStop();
+ for (int i = 0; i < n; i++) {
+ participants[i].syncStop();
+ }
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
@@ -219,7 +207,7 @@ public class TestDrop extends ZkIntegrationTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
"localhost", // participant name prefix
@@ -246,7 +234,8 @@ public class TestDrop extends ZkIntegrationTestBase {
accessor.setProperty(keyBuiler.idealStates("TestDB0"), isBuilder.build());
// start controller
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
@@ -257,11 +246,10 @@ public class TestDrop extends ZkIntegrationTestBase {
String instanceName = "localhost_" + (12918 + i);
if (i == 0) {
- participants[i] =
- new MockParticipant(clusterName, instanceName, ZK_ADDR, new ErrTransition(
- errTransitions));
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participants[i].setTransition(new ErrTransition(errTransitions));
} else {
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
}
participants[i].syncStart();
}
@@ -285,6 +273,12 @@ public class TestDrop extends ZkIntegrationTestBase {
clusterName));
Assert.assertTrue(result, "Should be empty exeternal-view");
+ // clean up
+ controller.syncStop();
+ for (int i = 0; i < n; i++) {
+ participants[i].syncStop();
+ }
+
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
@@ -298,7 +292,7 @@ public class TestDrop extends ZkIntegrationTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
"localhost", // participant name prefix
@@ -310,14 +304,15 @@ public class TestDrop extends ZkIntegrationTestBase {
"MasterSlave", true); // do rebalance
// start controller
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
@@ -357,10 +352,8 @@ public class TestDrop extends ZkIntegrationTestBase {
"schemata externalView should be empty but was \"" + extView + "\"");
// clean up
- // wait for all zk callbacks done
- Thread.sleep(1000);
controller.syncStop();
- for (int i = 0; i < 5; i++) {
+ for (int i = 0; i < n; i++) {
participants[i].syncStop();
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestDropResource.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestDropResource.java b/helix-core/src/test/java/org/apache/helix/integration/TestDropResource.java
index ba88370..0d02d12 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestDropResource.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestDropResource.java
@@ -20,7 +20,7 @@ package org.apache.helix.integration;
*/
import org.apache.helix.TestHelper;
-import org.apache.helix.TestHelper.StartCMResult;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.tools.ClusterStateVerifier;
import org.testng.Assert;
@@ -59,9 +59,8 @@ public class TestDropResource extends ZkStandAloneCMTestBaseWithPropertyServerCh
String hostToKill = "localhost_12920";
- _startCMResultMap.get(hostToKill)._manager.disconnect();
+ _participants[2].syncStop();
Thread.sleep(1000);
- _startCMResultMap.get(hostToKill)._thread.interrupt();
String command = "-zkSvr " + ZK_ADDR + " -dropResource " + CLUSTER_NAME + " " + "MyDB2";
ClusterSetup.processCommandLineArgs(command.split(" "));
@@ -70,8 +69,8 @@ public class TestDropResource extends ZkStandAloneCMTestBaseWithPropertyServerCh
TestHelper.<String> setOf("localhost_12918", "localhost_12919",
/* "localhost_12920", */"localhost_12921", "localhost_12922"), ZK_ADDR);
- StartCMResult result = TestHelper.startDummyProcess(ZK_ADDR, CLUSTER_NAME, hostToKill);
- _startCMResultMap.put(hostToKill, result);
+ _participants[2] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, hostToKill);
+ _participants[2].syncStart();
TestHelper.verifyWithTimeout("verifyEmptyCurStateAndExtView", 30 * 1000, CLUSTER_NAME, "MyDB2",
TestHelper.<String> setOf("localhost_12918", "localhost_12919", "localhost_12920",
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestEnablePartitionDuringDisable.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestEnablePartitionDuringDisable.java b/helix-core/src/test/java/org/apache/helix/integration/TestEnablePartitionDuringDisable.java
index 48cabbd..3dc92f7 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestEnablePartitionDuringDisable.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestEnablePartitionDuringDisable.java
@@ -24,17 +24,20 @@ import java.util.Date;
import org.apache.helix.HelixManager;
import org.apache.helix.NotificationContext;
import org.apache.helix.TestHelper;
-import org.apache.helix.mock.controller.ClusterController;
-import org.apache.helix.mock.participant.MockParticipant;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.mock.participant.MockTransition;
import org.apache.helix.model.Message;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.tools.ClusterStateVerifier;
import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier;
+import org.apache.log4j.Logger;
import org.testng.Assert;
import org.testng.annotations.Test;
public class TestEnablePartitionDuringDisable extends ZkIntegrationTestBase {
+ private static Logger LOG = Logger.getLogger(TestEnablePartitionDuringDisable.class);
+
static {
// Logger.getRootLogger().setLevel(Level.INFO);
}
@@ -63,8 +66,7 @@ public class TestEnablePartitionDuringDisable extends ZkIntegrationTestBase {
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
} catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.error("Exception in cluster setup", e);
}
} else if (slaveToOfflineCnt > 0 && fromState.equals("OFFLINE") && toState.equals("SLAVE")) {
@@ -93,19 +95,21 @@ public class TestEnablePartitionDuringDisable extends ZkIntegrationTestBase {
3, // replicas
"MasterSlave", true); // do rebalance
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
EnablePartitionTransition transition = new EnablePartitionTransition();
- MockParticipant[] participants = new MockParticipant[5];
+ MockParticipantManager[] participants = new MockParticipantManager[5];
for (int i = 0; i < 5; i++) {
String instanceName = "localhost_" + (12918 + i);
if (instanceName.equals("localhost_12919")) {
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, transition);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participants[i].setTransition(transition);
} else {
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
}
participants[i].syncStart();
}
@@ -138,8 +142,6 @@ public class TestEnablePartitionDuringDisable extends ZkIntegrationTestBase {
Assert.assertEquals(transition.offlineToSlave, 1, "should get 1 offlineToSlave transition");
// clean up
- // wait for all zk callbacks done
- Thread.sleep(1000);
controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestErrorPartition.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestErrorPartition.java b/helix-core/src/test/java/org/apache/helix/integration/TestErrorPartition.java
index bebefd1..71c4339 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestErrorPartition.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestErrorPartition.java
@@ -26,9 +26,9 @@ import java.util.Map;
import java.util.Set;
import org.apache.helix.TestHelper;
-import org.apache.helix.controller.HelixControllerMain;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixAdmin;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.mock.participant.ErrTransition;
import org.apache.helix.tools.ClusterStateVerifier;
import org.testng.Assert;
@@ -38,7 +38,7 @@ public class TestErrorPartition extends ZkIntegrationTestBase {
@Test()
public void testErrorPartition() throws Exception {
String clusterName = getShortClassName();
- MockParticipant[] participants = new MockParticipant[5];
+ MockParticipantManager[] participants = new MockParticipantManager[5];
System.out.println("START testErrorPartition() at " + new Date(System.currentTimeMillis()));
ZKHelixAdmin tool = new ZKHelixAdmin(_gZkClient);
@@ -46,8 +46,10 @@ public class TestErrorPartition extends ZkIntegrationTestBase {
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, "localhost", "TestDB", 1, 10, 5, 3,
"MasterSlave", true);
- TestHelper
- .startController(clusterName, "controller_0", ZK_ADDR, HelixControllerMain.STANDALONE);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+ controller.syncStart();
+
for (int i = 0; i < 5; i++) {
String instanceName = "localhost_" + (12918 + i);
@@ -57,14 +59,12 @@ public class TestErrorPartition extends ZkIntegrationTestBase {
put("SLAVE-MASTER", TestHelper.setOf("TestDB0_4"));
}
};
- participants[i] =
- new MockParticipant(clusterName, instanceName, ZK_ADDR,
- new ErrTransition(errPartitions));
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participants[i].setTransition(new ErrTransition(errPartitions));
} else {
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
}
participants[i].syncStart();
- // new Thread(participants[i]).start();
}
Map<String, Map<String, String>> errStates = new HashMap<String, Map<String, String>>();
@@ -113,7 +113,7 @@ public class TestErrorPartition extends ZkIntegrationTestBase {
ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
ZK_ADDR, clusterName));
Assert.assertTrue(result);
- participants[0] = new MockParticipant(clusterName, "localhost_12918", ZK_ADDR);
+ participants[0] = new MockParticipantManager(ZK_ADDR, clusterName, "localhost_12918");
new Thread(participants[0]).start();
result =
@@ -121,6 +121,12 @@ public class TestErrorPartition extends ZkIntegrationTestBase {
ZK_ADDR, clusterName));
Assert.assertTrue(result);
+ // clean up
+ controller.syncStop();
+ for (int i = 0; i < 5; i++) {
+ participants[i].syncStop();
+ }
+
System.out.println("END testErrorPartition() at " + new Date(System.currentTimeMillis()));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestExternalViewUpdates.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestExternalViewUpdates.java b/helix-core/src/test/java/org/apache/helix/integration/TestExternalViewUpdates.java
index 26da639..b3c34e4 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestExternalViewUpdates.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestExternalViewUpdates.java
@@ -26,9 +26,9 @@ import java.util.List;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.controller.HelixControllerMain;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.tools.ClusterStateVerifier;
import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier;
import org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier;
@@ -42,7 +42,7 @@ public class TestExternalViewUpdates extends ZkIntegrationTestBase {
System.out.println("START testExternalViewUpdates at " + new Date(System.currentTimeMillis()));
String clusterName = getShortClassName();
- MockParticipant[] participants = new MockParticipant[5];
+ MockParticipantManager[] participants = new MockParticipantManager[5];
int resourceNb = 10;
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
"localhost", // participant name prefix
@@ -53,13 +53,15 @@ public class TestExternalViewUpdates extends ZkIntegrationTestBase {
1, // replicas
"MasterSlave", true); // do rebalance
- TestHelper
- .startController(clusterName, "controller_0", ZK_ADDR, HelixControllerMain.STANDALONE);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+ controller.syncStart();
+
// start participants
for (int i = 0; i < 5; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
@@ -90,8 +92,11 @@ public class TestExternalViewUpdates extends ZkIntegrationTestBase {
Assert.assertTrue(stat.getVersion() <= 2, "ExternalView should be updated at most 2 times");
}
- // TODO: need stop controller and participants
-
+ // clean up
+ controller.syncStop();
+ for (int i = 0; i < 5; i++) {
+ participants[i].syncStop();
+ }
System.out.println("END testExternalViewUpdates at " + new Date(System.currentTimeMillis()));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestHelixCustomCodeRunner.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestHelixCustomCodeRunner.java b/helix-core/src/test/java/org/apache/helix/integration/TestHelixCustomCodeRunner.java
index b2bb561..f6a7098 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestHelixCustomCodeRunner.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestHelixCustomCodeRunner.java
@@ -27,21 +27,23 @@ import org.apache.helix.TestHelper;
import org.apache.helix.HelixConstants.ChangeType;
import org.apache.helix.NotificationContext.Type;
import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.controller.HelixControllerMain;
+import org.apache.helix.ZNRecord;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
-import org.apache.helix.manager.zk.ZNRecordSerializer;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.manager.zk.ZkClient;
import org.apache.helix.mock.participant.MockJobIntf;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.model.LiveInstance;
import org.apache.helix.participant.CustomCodeCallbackHandler;
import org.apache.helix.participant.HelixCustomCodeRunner;
import org.apache.helix.tools.ClusterStateVerifier;
+import org.apache.log4j.Logger;
import org.testng.Assert;
import org.testng.annotations.Test;
public class TestHelixCustomCodeRunner extends ZkIntegrationTestBase {
+ private static Logger LOG = Logger.getLogger(TestHelixCustomCodeRunner.class);
+
private final String _clusterName = "CLUSTER_" + getShortClassName();
private final int _nodeNb = 5;
private final int _startPort = 12918;
@@ -74,8 +76,7 @@ public class TestHelixCustomCodeRunner extends ZkIntegrationTestBase {
customCodeRunner.invoke(_callback).on(ChangeType.LIVE_INSTANCE)
.usingLeaderStandbyModel("TestParticLeader").start();
} catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.error("Exception do pre-connect job", e);
}
}
@@ -100,16 +101,19 @@ public class TestHelixCustomCodeRunner extends ZkIntegrationTestBase {
_nodeNb, // replica
"MasterSlave", true);
- TestHelper.startController(_clusterName, "controller_0", ZK_ADDR,
- HelixControllerMain.STANDALONE);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, _clusterName, "controller_0");
+ controller.syncStart();
- MockParticipant[] partics = new MockParticipant[5];
+ MockParticipantManager[] participants = new MockParticipantManager[5];
for (int i = 0; i < _nodeNb; i++) {
String instanceName = "localhost_" + (_startPort + i);
- partics[i] = new MockParticipant(_clusterName, instanceName, ZK_ADDR, null, new MockJob());
- partics[i].syncStart();
- // new Thread(partics[i]).start();
+ MockJob job = new MockJob();
+ participants[i] = new MockParticipantManager(ZK_ADDR, _clusterName, instanceName);
+
+ job.doPreConnectJob(participants[i]);
+ participants[i].syncStart();
}
boolean result =
ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
@@ -121,20 +125,26 @@ public class TestHelixCustomCodeRunner extends ZkIntegrationTestBase {
_callback._isCallbackInvoked = false;
// add a new live instance
- ZkClient zkClient = new ZkClient(ZK_ADDR);
- zkClient.setZkSerializer(new ZNRecordSerializer());
+ // ZkClient zkClient = new ZkClient(ZK_ADDR);
+ // zkClient.setZkSerializer(new ZNRecordSerializer());
ZKHelixDataAccessor accessor =
- new ZKHelixDataAccessor(_clusterName, new ZkBaseDataAccessor(zkClient));
+ new ZKHelixDataAccessor(_clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
LiveInstance newLiveIns = new LiveInstance("newLiveInstance");
- newLiveIns.setHelixVersion("0.0.0");
+ newLiveIns.setHelixVersion("0.6.0");
newLiveIns.setSessionId("randomSessionId");
accessor.setProperty(keyBuilder.liveInstance("newLiveInstance"), newLiveIns);
Thread.sleep(1000); // wait for the CALLBACK type callback to finish
Assert.assertTrue(_callback._isCallbackInvoked);
+ // clean up
+ controller.syncStop();
+ for (int i = 0; i < _nodeNb; i++) {
+ participants[i].syncStop();
+ }
+
System.out.println("END " + _clusterName + " at " + new Date(System.currentTimeMillis()));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestHelixInstanceTag.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestHelixInstanceTag.java b/helix-core/src/test/java/org/apache/helix/integration/TestHelixInstanceTag.java
index 4484386..1f906d0 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestHelixInstanceTag.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestHelixInstanceTag.java
@@ -33,8 +33,7 @@ import org.testng.annotations.Test;
public class TestHelixInstanceTag extends ZkStandAloneCMTestBase {
@Test
public void testInstanceTag() throws Exception {
- String controllerName = CONTROLLER_PREFIX + "_0";
- HelixManager manager = _startCMResultMap.get(controllerName)._manager;
+ HelixManager manager = _controller;
HelixDataAccessor accessor = manager.getHelixDataAccessor();
String DB2 = "TestDB2";
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestInstanceAutoJoin.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestInstanceAutoJoin.java b/helix-core/src/test/java/org/apache/helix/integration/TestInstanceAutoJoin.java
index f69aeec..2761634 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestInstanceAutoJoin.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestInstanceAutoJoin.java
@@ -2,8 +2,7 @@ package org.apache.helix.integration;
import org.apache.helix.HelixDataAccessor;
import org.apache.helix.HelixManager;
-import org.apache.helix.TestHelper;
-import org.apache.helix.TestHelper.StartCMResult;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixManager;
import org.apache.helix.model.ConfigScope;
import org.apache.helix.model.IdealState.RebalanceMode;
@@ -35,8 +34,7 @@ public class TestInstanceAutoJoin extends ZkStandAloneCMTestBase {
@Test
public void testInstanceAutoJoin() throws Exception {
- String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + 0);
- HelixManager manager = _startCMResultMap.get(instanceName)._manager;
+ HelixManager manager = _participants[0];
HelixDataAccessor accessor = manager.getHelixDataAccessor();
_setupTool.addResourceToCluster(CLUSTER_NAME, db2, 60, "OnlineOffline", RebalanceMode.FULL_AUTO
@@ -44,10 +42,13 @@ public class TestInstanceAutoJoin extends ZkStandAloneCMTestBase {
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, db2, 1);
String instance2 = "localhost_279699";
- StartCMResult result = TestHelper.startDummyProcess(ZK_ADDR, CLUSTER_NAME, instance2);
+ // StartCMResult result = TestHelper.startDummyProcess(ZK_ADDR, CLUSTER_NAME, instance2);
+ MockParticipantManager newParticipant =
+ new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instance2);
+ newParticipant.syncStart();
Thread.sleep(500);
- Assert.assertFalse(result._thread.isAlive());
+ // Assert.assertFalse(result._thread.isAlive());
Assert.assertTrue(null == manager.getHelixDataAccessor().getProperty(
accessor.keyBuilder().liveInstance(instance2)));
@@ -55,12 +56,11 @@ public class TestInstanceAutoJoin extends ZkStandAloneCMTestBase {
manager.getConfigAccessor().set(scope, ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN, "true");
- result = TestHelper.startDummyProcess(ZK_ADDR, CLUSTER_NAME, instance2);
-
- StartCMResult result2 = TestHelper.startDummyProcess(ZK_ADDR, CLUSTER_NAME, instance2);
+ newParticipant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instance2);
+ newParticipant.syncStart();
Thread.sleep(500);
- Assert.assertTrue(result._thread.isAlive() || result2._thread.isAlive());
+ // Assert.assertTrue(result._thread.isAlive() || result2._thread.isAlive());
for (int i = 0; i < 20; i++) {
if (null == manager.getHelixDataAccessor().getProperty(
accessor.keyBuilder().liveInstance(instance2))) {
@@ -71,9 +71,6 @@ public class TestInstanceAutoJoin extends ZkStandAloneCMTestBase {
Assert.assertTrue(null != manager.getHelixDataAccessor().getProperty(
accessor.keyBuilder().liveInstance(instance2)));
- result._manager.disconnect();
- result2._manager.disconnect();
- result._thread.interrupt();
- result2._thread.interrupt();
+ newParticipant.syncStop();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestInvalidAutoIdealState.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestInvalidAutoIdealState.java b/helix-core/src/test/java/org/apache/helix/integration/TestInvalidAutoIdealState.java
index 837d0a1..8768760 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestInvalidAutoIdealState.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestInvalidAutoIdealState.java
@@ -28,9 +28,9 @@ import org.apache.helix.HelixDataAccessor;
import org.apache.helix.TestHelper;
import org.apache.helix.ZkUnitTestBase;
import org.apache.helix.PropertyKey.Builder;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixAdmin;
-import org.apache.helix.mock.controller.ClusterController;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.model.ExternalView;
import org.apache.helix.model.IdealState;
import org.apache.helix.model.IdealState.RebalanceMode;
@@ -40,6 +40,7 @@ import org.apache.helix.tools.ClusterStateVerifier;
import org.apache.helix.tools.StateModelConfigGenerator;
import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier;
import org.testng.Assert;
+import org.testng.annotations.Test;
// Helix-50: integration test for generate message based on state priority
public class TestInvalidAutoIdealState extends ZkUnitTestBase {
@@ -90,15 +91,16 @@ public class TestInvalidAutoIdealState extends ZkUnitTestBase {
admin.setResourceIdealState(clusterName, "TestDB", idealState);
// start participants
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
boolean result =
@@ -107,7 +109,7 @@ public class TestInvalidAutoIdealState extends ZkUnitTestBase {
Assert.assertTrue(result);
// make sure localhost_12919 is master on TestDB_1
- HelixDataAccessor accessor = controller.getManager().getHelixDataAccessor();
+ HelixDataAccessor accessor = controller.getHelixDataAccessor();
Builder keyBuilder = accessor.keyBuilder();
ExternalView extView = accessor.getProperty(keyBuilder.externalView(db));
Map<String, String> stateMap = extView.getStateMap(db + "_1");
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestMessagePartitionStateMismatch.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestMessagePartitionStateMismatch.java b/helix-core/src/test/java/org/apache/helix/integration/TestMessagePartitionStateMismatch.java
index 487e689..745f2f2 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestMessagePartitionStateMismatch.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestMessagePartitionStateMismatch.java
@@ -37,9 +37,9 @@ import org.testng.annotations.Test;
public class TestMessagePartitionStateMismatch extends ZkStandAloneCMTestBase {
@Test
public void testStateMismatch() throws InterruptedException {
- String controllerName = CONTROLLER_PREFIX + "_0";
+ // String controllerName = CONTROLLER_PREFIX + "_0";
- HelixManager manager = _startCMResultMap.get(controllerName)._manager;
+ HelixManager manager = _controller; // _startCMResultMap.get(controllerName)._manager;
HelixDataAccessor accessor = manager.getHelixDataAccessor();
Builder kb = accessor.keyBuilder();
ExternalView ev = accessor.getProperty(kb.externalView(TEST_DB));
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestMessageThrottle.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestMessageThrottle.java b/helix-core/src/test/java/org/apache/helix/integration/TestMessageThrottle.java
index fbff4e1..fc6d6bc 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestMessageThrottle.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestMessageThrottle.java
@@ -21,8 +21,6 @@ package org.apache.helix.integration;
import java.util.Date;
import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicBoolean;
import org.I0Itec.zkclient.IZkChildListener;
@@ -31,17 +29,13 @@ import org.apache.helix.PropertyPathConfig;
import org.apache.helix.PropertyType;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
-import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.controller.HelixControllerMain;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixAdmin;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.mock.participant.MockParticipant;
-import org.apache.helix.model.ClusterConstraints;
-import org.apache.helix.model.ConstraintItem;
import org.apache.helix.model.Message;
import org.apache.helix.model.ClusterConstraints.ConstraintType;
-import org.apache.helix.model.builder.ClusterConstraintsBuilder;
import org.apache.helix.model.builder.ConstraintItemBuilder;
import org.apache.helix.tools.ClusterStateVerifier;
import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier;
@@ -55,8 +49,7 @@ public class TestMessageThrottle extends ZkIntegrationTestBase {
// Logger.getRootLogger().setLevel(Level.INFO);
String clusterName = getShortClassName();
- MockParticipant[] participants = new MockParticipant[5];
- // ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
+ MockParticipantManager[] participants = new MockParticipantManager[5];
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
@@ -120,13 +113,15 @@ public class TestMessageThrottle extends ZkIntegrationTestBase {
});
}
- TestHelper
- .startController(clusterName, "controller_0", ZK_ADDR, HelixControllerMain.STANDALONE);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+ controller.syncStart();
+
// start participants
for (int i = 0; i < 5; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
@@ -143,6 +138,7 @@ public class TestMessageThrottle extends ZkIntegrationTestBase {
Assert.assertTrue(success.get());
// clean up
+ controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestMessageThrottle2.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestMessageThrottle2.java b/helix-core/src/test/java/org/apache/helix/integration/TestMessageThrottle2.java
index cdd644b..7d66780 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestMessageThrottle2.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestMessageThrottle2.java
@@ -32,7 +32,6 @@ import org.apache.helix.ExternalViewChangeListener;
import org.apache.helix.HelixAdmin;
import org.apache.helix.HelixDataAccessor;
import org.apache.helix.HelixManager;
-import org.apache.helix.HelixManagerFactory;
import org.apache.helix.IdealStateChangeListener;
import org.apache.helix.InstanceConfigChangeListener;
import org.apache.helix.InstanceType;
@@ -245,8 +244,7 @@ public class TestMessageThrottle2 extends ZkIntegrationTestBase {
public void start() throws Exception {
helixManager =
- HelixManagerFactory.getZKHelixManager(clusterName, instanceName,
- InstanceType.PARTICIPANT, ZK_ADDR);
+ new ZKHelixManager(clusterName, instanceName, InstanceType.PARTICIPANT, ZK_ADDR);
{
// hack to set sessionTimeout
Field sessionTimeout = ZKHelixManager.class.getDeclaredField("_sessionTimeout");
[07/10] [HELIX-279] Apply gc handling fixes to main ZKHelixManager
class
Posted by zz...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/main/java/org/apache/helix/manager/zk/AbstractManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/AbstractManager.java b/helix-core/src/main/java/org/apache/helix/manager/zk/AbstractManager.java
deleted file mode 100644
index 4f549e4..0000000
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/AbstractManager.java
+++ /dev/null
@@ -1,693 +0,0 @@
-package org.apache.helix.manager.zk;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-
-import org.I0Itec.zkclient.IZkStateListener;
-import org.I0Itec.zkclient.ZkConnection;
-import org.apache.helix.BaseDataAccessor;
-import org.apache.helix.ClusterMessagingService;
-import org.apache.helix.ConfigAccessor;
-import org.apache.helix.ConfigChangeListener;
-import org.apache.helix.ControllerChangeListener;
-import org.apache.helix.CurrentStateChangeListener;
-import org.apache.helix.ExternalViewChangeListener;
-import org.apache.helix.HealthStateChangeListener;
-import org.apache.helix.HelixAdmin;
-import org.apache.helix.HelixDataAccessor;
-import org.apache.helix.HelixException;
-import org.apache.helix.HelixManager;
-import org.apache.helix.HelixManagerProperties;
-import org.apache.helix.HelixTimerTask;
-import org.apache.helix.IdealStateChangeListener;
-import org.apache.helix.InstanceConfigChangeListener;
-import org.apache.helix.InstanceType;
-import org.apache.helix.LiveInstanceChangeListener;
-import org.apache.helix.LiveInstanceInfoProvider;
-import org.apache.helix.MessageListener;
-import org.apache.helix.PreConnectCallback;
-import org.apache.helix.PropertyKey;
-import org.apache.helix.PropertyPathConfig;
-import org.apache.helix.PropertyType;
-import org.apache.helix.ScopedConfigChangeListener;
-import org.apache.helix.ZNRecord;
-import org.apache.helix.HelixConstants.ChangeType;
-import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.healthcheck.ParticipantHealthReportCollector;
-import org.apache.helix.messaging.DefaultMessagingService;
-import org.apache.helix.model.HelixConfigScope.ConfigScopeProperty;
-import org.apache.helix.participant.StateMachineEngine;
-import org.apache.helix.store.zk.ZkHelixPropertyStore;
-import org.apache.log4j.Logger;
-import org.apache.zookeeper.Watcher.Event.EventType;
-import org.apache.zookeeper.Watcher.Event.KeeperState;
-import org.apache.zookeeper.ZooKeeper.States;
-
-public abstract class AbstractManager implements HelixManager, IZkStateListener {
- private static Logger LOG = Logger.getLogger(AbstractManager.class);
-
- final String _zkAddress;
- final String _clusterName;
- final String _instanceName;
- final InstanceType _instanceType;
- final int _sessionTimeout;
- final List<PreConnectCallback> _preConnectCallbacks;
- protected final List<CallbackHandler> _handlers;
- final HelixManagerProperties _properties;
-
- /**
- * helix version#
- */
- final String _version;
-
- protected ZkClient _zkclient = null;
- final DefaultMessagingService _messagingService;
-
- BaseDataAccessor<ZNRecord> _baseDataAccessor;
- ZKHelixDataAccessor _dataAccessor;
- final Builder _keyBuilder;
- ConfigAccessor _configAccessor;
- ZkHelixPropertyStore<ZNRecord> _helixPropertyStore;
- LiveInstanceInfoProvider _liveInstanceInfoProvider = null;
- final List<HelixTimerTask> _timerTasks = new ArrayList<HelixTimerTask>();
-
- volatile String _sessionId;
-
- /**
- * Keep track of timestamps that zk State has become Disconnected
- * If in a _timeWindowLengthMs window zk State has become Disconnected
- * for more than_maxDisconnectThreshold times disconnect the zkHelixManager
- */
- final List<Long> _disconnectTimeHistory = new LinkedList<Long>();
-
- final int _flappingTimeWindowMs;
- final int _maxDisconnectThreshold;
-
- public AbstractManager(String zkAddress, String clusterName, String instanceName,
- InstanceType instanceType) {
-
- LOG.info("Create a zk-based cluster manager. zkSvr: " + zkAddress + ", clusterName: "
- + clusterName + ", instanceName: " + instanceName + ", type: " + instanceType);
-
- _zkAddress = zkAddress;
- _clusterName = clusterName;
- _instanceType = instanceType;
- _instanceName = instanceName;
- _preConnectCallbacks = new LinkedList<PreConnectCallback>();
- _handlers = new ArrayList<CallbackHandler>();
- _properties = new HelixManagerProperties("cluster-manager-version.properties");
- _version = _properties.getVersion();
-
- _keyBuilder = new Builder(clusterName);
- _messagingService = new DefaultMessagingService(this);
-
- /**
- * use system property if available
- */
- _flappingTimeWindowMs =
- getSystemPropertyAsInt("helixmanager.flappingTimeWindow",
- ZKHelixManager.FLAPPING_TIME_WINDIOW);
-
- _maxDisconnectThreshold =
- getSystemPropertyAsInt("helixmanager.maxDisconnectThreshold",
- ZKHelixManager.MAX_DISCONNECT_THRESHOLD);
-
- _sessionTimeout =
- getSystemPropertyAsInt("zk.session.timeout", ZkClient.DEFAULT_SESSION_TIMEOUT);
-
- }
-
- private int getSystemPropertyAsInt(String propertyKey, int propertyDefaultValue) {
- String valueString = System.getProperty(propertyKey, "" + propertyDefaultValue);
-
- try {
- int value = Integer.parseInt(valueString);
- if (value > 0) {
- return value;
- }
- } catch (NumberFormatException e) {
- LOG.warn("Exception while parsing property: " + propertyKey + ", string: " + valueString
- + ", using default value: " + propertyDefaultValue);
- }
-
- return propertyDefaultValue;
- }
-
- /**
- * different types of helix manager should impl its own handle new session logic
- */
- // public abstract void handleNewSession();
-
- @Override
- public void connect() throws Exception {
- LOG.info("ClusterManager.connect()");
- if (isConnected()) {
- LOG.warn("Cluster manager: " + _instanceName + " for cluster: " + _clusterName
- + " already connected. skip connect");
- return;
- }
-
- try {
- createClient();
- _messagingService.onConnected();
- } catch (Exception e) {
- LOG.error("fail to connect " + _instanceName, e);
- disconnect();
- throw e;
- }
- }
-
- @Override
- public boolean isConnected() {
- if (_zkclient == null) {
- return false;
- }
- ZkConnection zkconnection = (ZkConnection) _zkclient.getConnection();
- if (zkconnection != null) {
- States state = zkconnection.getZookeeperState();
- return state == States.CONNECTED;
- }
- return false;
- }
-
- /**
- * specific disconnect logic for each helix-manager type
- */
- abstract void doDisconnect();
-
- /**
- * This function can be called when the connection are in bad state(e.g. flapping),
- * in which isConnected() could be false and we want to disconnect from cluster.
- */
- @Override
- public void disconnect() {
- LOG.info("disconnect " + _instanceName + "(" + _instanceType + ") from " + _clusterName);
-
- try {
- /**
- * stop all timer tasks
- */
- stopTimerTasks();
-
- /**
- * shutdown thread pool first to avoid reset() being invoked in the middle of state
- * transition
- */
- _messagingService.getExecutor().shutdown();
-
- // TODO reset user defined handlers only
- resetHandlers();
-
- _dataAccessor.shutdown();
-
- doDisconnect();
-
- _zkclient.unsubscribeAll();
- } finally {
- _zkclient.close();
- LOG.info("Cluster manager: " + _instanceName + " disconnected");
- }
- }
-
- @Override
- public void addIdealStateChangeListener(IdealStateChangeListener listener) throws Exception {
- addListener(listener, new Builder(_clusterName).idealStates(), ChangeType.IDEAL_STATE,
- new EventType[] {
- EventType.NodeDataChanged, EventType.NodeDeleted, EventType.NodeCreated
- });
- }
-
- @Override
- public void addLiveInstanceChangeListener(LiveInstanceChangeListener listener) throws Exception {
- addListener(listener, new Builder(_clusterName).liveInstances(), ChangeType.LIVE_INSTANCE,
- new EventType[] {
- EventType.NodeDataChanged, EventType.NodeChildrenChanged, EventType.NodeDeleted,
- EventType.NodeCreated
- });
- }
-
- @Override
- public void addConfigChangeListener(ConfigChangeListener listener) throws Exception {
- addListener(listener, new Builder(_clusterName).instanceConfigs(), ChangeType.INSTANCE_CONFIG,
- new EventType[] {
- EventType.NodeChildrenChanged
- });
- }
-
- @Override
- public void addInstanceConfigChangeListener(InstanceConfigChangeListener listener)
- throws Exception {
- addListener(listener, new Builder(_clusterName).instanceConfigs(), ChangeType.INSTANCE_CONFIG,
- new EventType[] {
- EventType.NodeChildrenChanged
- });
- }
-
- @Override
- public void addConfigChangeListener(ScopedConfigChangeListener listener, ConfigScopeProperty scope)
- throws Exception {
- Builder keyBuilder = new Builder(_clusterName);
-
- PropertyKey propertyKey = null;
- switch (scope) {
- case CLUSTER:
- propertyKey = keyBuilder.clusterConfigs();
- break;
- case PARTICIPANT:
- propertyKey = keyBuilder.instanceConfigs();
- break;
- case RESOURCE:
- propertyKey = keyBuilder.resourceConfigs();
- break;
- default:
- break;
- }
-
- if (propertyKey != null) {
- addListener(listener, propertyKey, ChangeType.CONFIG, new EventType[] {
- EventType.NodeChildrenChanged
- });
- } else {
- LOG.error("Can't add listener to config scope: " + scope);
- }
- }
-
- @Override
- public void addMessageListener(MessageListener listener, String instanceName) {
- addListener(listener, new Builder(_clusterName).messages(instanceName), ChangeType.MESSAGE,
- new EventType[] {
- EventType.NodeChildrenChanged, EventType.NodeDeleted, EventType.NodeCreated
- });
- }
-
- @Override
- public void addCurrentStateChangeListener(CurrentStateChangeListener listener,
- String instanceName, String sessionId) throws Exception {
- addListener(listener, new Builder(_clusterName).currentStates(instanceName, sessionId),
- ChangeType.CURRENT_STATE, new EventType[] {
- EventType.NodeChildrenChanged, EventType.NodeDeleted, EventType.NodeCreated
- });
- }
-
- @Override
- public void addHealthStateChangeListener(HealthStateChangeListener listener, String instanceName)
- throws Exception {
- addListener(listener, new Builder(_clusterName).healthReports(instanceName), ChangeType.HEALTH,
- new EventType[] {
- EventType.NodeChildrenChanged, EventType.NodeDeleted, EventType.NodeCreated
- });
- }
-
- @Override
- public void addExternalViewChangeListener(ExternalViewChangeListener listener) throws Exception {
- addListener(listener, new Builder(_clusterName).externalViews(), ChangeType.EXTERNAL_VIEW,
- new EventType[] {
- EventType.NodeChildrenChanged, EventType.NodeDeleted, EventType.NodeCreated
- });
- }
-
- @Override
- public void addControllerListener(ControllerChangeListener listener) {
- addListener(listener, new Builder(_clusterName).controller(), ChangeType.CONTROLLER,
- new EventType[] {
- EventType.NodeChildrenChanged, EventType.NodeDeleted, EventType.NodeCreated
- });
- }
-
- void addControllerMessageListener(MessageListener listener) {
- addListener(listener, new Builder(_clusterName).controllerMessages(),
- ChangeType.MESSAGES_CONTROLLER, new EventType[] {
- EventType.NodeChildrenChanged, EventType.NodeDeleted, EventType.NodeCreated
- });
- }
-
- @Override
- public boolean removeListener(PropertyKey key, Object listener) {
- LOG.info("Removing listener: " + listener + " on path: " + key.getPath() + " from cluster: "
- + _clusterName + " by instance: " + _instanceName);
-
- synchronized (this) {
- List<CallbackHandler> toRemove = new ArrayList<CallbackHandler>();
- for (CallbackHandler handler : _handlers) {
- // compare property-key path and listener reference
- if (handler.getPath().equals(key.getPath()) && handler.getListener().equals(listener)) {
- toRemove.add(handler);
- }
- }
-
- _handlers.removeAll(toRemove);
-
- // handler.reset() may modify the handlers list, so do it outside the iteration
- for (CallbackHandler handler : toRemove) {
- handler.reset();
- }
- }
-
- return true;
- }
-
- @Override
- public HelixDataAccessor getHelixDataAccessor() {
- checkConnected();
- return _dataAccessor;
- }
-
- @Override
- public ConfigAccessor getConfigAccessor() {
- checkConnected();
- return _configAccessor;
- }
-
- @Override
- public String getClusterName() {
- return _clusterName;
- }
-
- @Override
- public String getInstanceName() {
- return _instanceName;
- }
-
- @Override
- public String getSessionId() {
- checkConnected();
- return _sessionId;
- }
-
- @Override
- public long getLastNotificationTime() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- public HelixAdmin getClusterManagmentTool() {
- checkConnected();
- if (_zkclient != null) {
- return new ZKHelixAdmin(_zkclient);
- }
-
- LOG.error("Couldn't get ZKClusterManagementTool because zkclient is null");
- return null;
- }
-
- @Override
- public synchronized ZkHelixPropertyStore<ZNRecord> getHelixPropertyStore() {
- checkConnected();
-
- if (_helixPropertyStore == null) {
- String path = PropertyPathConfig.getPath(PropertyType.PROPERTYSTORE, _clusterName);
-
- _helixPropertyStore =
- new ZkHelixPropertyStore<ZNRecord>(new ZkBaseDataAccessor<ZNRecord>(_zkclient), path,
- null);
- }
-
- return _helixPropertyStore;
- }
-
- @Override
- public ClusterMessagingService getMessagingService() {
- // The caller can register message handler factories on messaging service before the
- // helix manager is connected. Thus we do not check connected here
- return _messagingService;
- }
-
- @Override
- public ParticipantHealthReportCollector getHealthReportCollector() {
- // helix-participant will override this
- return null;
- }
-
- @Override
- public InstanceType getInstanceType() {
- return _instanceType;
- }
-
- @Override
- public String getVersion() {
- return _version;
- }
-
- @Override
- public HelixManagerProperties getProperties() {
- return _properties;
- }
-
- @Override
- public StateMachineEngine getStateMachineEngine() {
- // helix-participant will override this
- return null;
- }
-
- @Override
- public abstract boolean isLeader();
-
- @Override
- public void startTimerTasks() {
- for (HelixTimerTask task : _timerTasks) {
- task.start();
- }
-
- }
-
- @Override
- public void stopTimerTasks() {
- for (HelixTimerTask task : _timerTasks) {
- task.stop();
- }
-
- }
-
- @Override
- public void addPreConnectCallback(PreConnectCallback callback) {
- LOG.info("Adding preconnect callback: " + callback);
- _preConnectCallbacks.add(callback);
- }
-
- @Override
- public void setLiveInstanceInfoProvider(LiveInstanceInfoProvider liveInstanceInfoProvider) {
- _liveInstanceInfoProvider = liveInstanceInfoProvider;
- }
-
- /**
- * wait until we get a non-zero session-id. note that we might lose zkconnection
- * right after we read session-id. but it's ok to get stale session-id and we will have
- * another handle-new-session callback to correct this.
- */
- protected void waitUntilConnected() {
- boolean isConnected;
- do {
- isConnected =
- _zkclient.waitUntilConnected(ZkClient.DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
- if (!isConnected) {
- LOG.error("fail to connect zkserver: " + _zkAddress + " in "
- + ZkClient.DEFAULT_CONNECTION_TIMEOUT + "ms. expiredSessionId: " + _sessionId
- + ", clusterName: " + _clusterName);
- continue;
- }
-
- ZkConnection zkConnection = ((ZkConnection) _zkclient.getConnection());
- _sessionId = Long.toHexString(zkConnection.getZookeeper().getSessionId());
-
- /**
- * at the time we read session-id, zkconnection might be lost again
- * wait until we get a non-zero session-id
- */
- } while ("0".equals(_sessionId));
-
- LOG.info("Handling new session, session id: " + _sessionId + ", instance: " + _instanceName
- + ", instanceTye: " + _instanceType + ", cluster: " + _clusterName + ", zkconnection: "
- + ((ZkConnection) _zkclient.getConnection()).getZookeeper());
- }
-
- protected void checkConnected() {
- if (!isConnected()) {
- throw new HelixException("ClusterManager not connected. Call clusterManager.connect()");
- }
- }
-
- protected void addListener(Object listener, PropertyKey propertyKey, ChangeType changeType,
- EventType[] eventType) {
- checkConnected();
-
- PropertyType type = propertyKey.getType();
-
- synchronized (this) {
- for (CallbackHandler handler : _handlers) {
- // compare property-key path and listener reference
- if (handler.getPath().equals(propertyKey.getPath())
- && handler.getListener().equals(listener)) {
- LOG.info("Listener: " + listener + " on path: " + propertyKey.getPath()
- + " already exists. skip add");
-
- return;
- }
- }
-
- CallbackHandler newHandler =
- new CallbackHandler(this, _zkclient, propertyKey, listener, eventType, changeType);
-
- _handlers.add(newHandler);
- LOG.info("Added listener: " + listener + " for type: " + type + " to path: "
- + newHandler.getPath());
- }
- }
-
- protected void initHandlers(List<CallbackHandler> handlers) {
- synchronized (this) {
- if (handlers != null) {
- for (CallbackHandler handler : handlers) {
- handler.init();
- LOG.info("init handler: " + handler.getPath() + ", " + handler.getListener());
- }
- }
- }
- }
-
- protected void resetHandlers() {
- synchronized (this) {
- if (_handlers != null) {
- // get a copy of the list and iterate over the copy list
- // in case handler.reset() modify the original handler list
- List<CallbackHandler> tmpHandlers = new ArrayList<CallbackHandler>();
- tmpHandlers.addAll(_handlers);
-
- for (CallbackHandler handler : tmpHandlers) {
- handler.reset();
- LOG.info("reset handler: " + handler.getPath() + ", " + handler.getListener());
- }
- }
- }
- }
-
- /**
- * different helix-manager may override this to have a cache-enabled based-data-accessor
- * @param baseDataAccessor
- * @return
- */
- BaseDataAccessor<ZNRecord> createBaseDataAccessor(ZkBaseDataAccessor<ZNRecord> baseDataAccessor) {
- return baseDataAccessor;
- }
-
- void createClient() throws Exception {
- PathBasedZkSerializer zkSerializer =
- ChainedPathZkSerializer.builder(new ZNRecordStreamingSerializer()).build();
-
- _zkclient =
- new ZkClient(_zkAddress, _sessionTimeout, ZkClient.DEFAULT_CONNECTION_TIMEOUT, zkSerializer);
-
- ZkBaseDataAccessor<ZNRecord> baseDataAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
-
- _baseDataAccessor = createBaseDataAccessor(baseDataAccessor);
-
- _dataAccessor = new ZKHelixDataAccessor(_clusterName, _instanceType, _baseDataAccessor);
- _configAccessor = new ConfigAccessor(_zkclient);
-
- int retryCount = 0;
-
- _zkclient.subscribeStateChanges(this);
- while (retryCount < 3) {
- try {
- _zkclient.waitUntilConnected(_sessionTimeout, TimeUnit.MILLISECONDS);
- handleStateChanged(KeeperState.SyncConnected);
- handleNewSession();
- break;
- } catch (HelixException e) {
- LOG.error("fail to createClient.", e);
- throw e;
- } catch (Exception e) {
- retryCount++;
-
- LOG.error("fail to createClient. retry " + retryCount, e);
- if (retryCount == 3) {
- throw e;
- }
- }
- }
- }
-
- // TODO separate out flapping detection code
- @Override
- public void handleStateChanged(KeeperState state) throws Exception {
- switch (state) {
- case SyncConnected:
- ZkConnection zkConnection = (ZkConnection) _zkclient.getConnection();
- LOG.info("KeeperState: " + state + ", zookeeper:" + zkConnection.getZookeeper());
- break;
- case Disconnected:
- LOG.info("KeeperState:" + state + ", disconnectedSessionId: " + _sessionId + ", instance: "
- + _instanceName + ", type: " + _instanceType);
-
- /**
- * Track the time stamp that the disconnected happens, then check history and see if
- * we should disconnect the helix-manager
- */
- _disconnectTimeHistory.add(System.currentTimeMillis());
- if (isFlapping()) {
- LOG.error("instanceName: " + _instanceName + " is flapping. diconnect it. "
- + " maxDisconnectThreshold: " + _maxDisconnectThreshold + " disconnects in "
- + _flappingTimeWindowMs + "ms.");
- disconnect();
- }
- break;
- case Expired:
- LOG.info("KeeperState:" + state + ", expiredSessionId: " + _sessionId + ", instance: "
- + _instanceName + ", type: " + _instanceType);
- break;
- default:
- break;
- }
- }
-
- /**
- * If zk state has changed into Disconnected for _maxDisconnectThreshold times during previous
- * _timeWindowLengthMs Ms
- * time window, we think that there are something wrong going on and disconnect the zkHelixManager
- * from zk.
- */
- private boolean isFlapping() {
- if (_disconnectTimeHistory.size() == 0) {
- return false;
- }
- long mostRecentTimestamp = _disconnectTimeHistory.get(_disconnectTimeHistory.size() - 1);
-
- // Remove disconnect history timestamp that are older than _flappingTimeWindowMs ago
- while ((_disconnectTimeHistory.get(0) + _flappingTimeWindowMs) < mostRecentTimestamp) {
- _disconnectTimeHistory.remove(0);
- }
- return _disconnectTimeHistory.size() > _maxDisconnectThreshold;
- }
-
- /**
- * controller should override it to return a list of timers that need to start/stop when
- * leadership changes
- * @return
- */
- protected List<HelixTimerTask> getControllerHelixTimerTasks() {
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/main/java/org/apache/helix/manager/zk/ControllerManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ControllerManager.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ControllerManager.java
deleted file mode 100644
index 1ed6dea..0000000
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ControllerManager.java
+++ /dev/null
@@ -1,175 +0,0 @@
-package org.apache.helix.manager.zk;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Timer;
-
-import org.apache.helix.BaseDataAccessor;
-import org.apache.helix.HelixTimerTask;
-import org.apache.helix.InstanceType;
-import org.apache.helix.PropertyPathConfig;
-import org.apache.helix.PropertyType;
-import org.apache.helix.ZNRecord;
-import org.apache.helix.HelixConstants.ChangeType;
-import org.apache.helix.controller.GenericHelixController;
-import org.apache.helix.healthcheck.HealthStatsAggregationTask;
-import org.apache.helix.healthcheck.HealthStatsAggregator;
-import org.apache.helix.model.LiveInstance;
-import org.apache.helix.monitoring.ZKPathDataDumpTask;
-import org.apache.log4j.Logger;
-import org.apache.zookeeper.Watcher.Event.EventType;
-
-public class ControllerManager extends AbstractManager {
- private static Logger LOG = Logger.getLogger(ControllerManager.class);
-
- final GenericHelixController _controller = new GenericHelixController();
-
- // TODO merge into GenericHelixController
- private CallbackHandler _leaderElectionHandler = null;
-
- /**
- * status dump timer-task
- */
- static class StatusDumpTask extends HelixTimerTask {
- Timer _timer = null;
- final ZkClient zkclient;
- final AbstractManager helixController;
-
- public StatusDumpTask(ZkClient zkclient, AbstractManager helixController) {
- this.zkclient = zkclient;
- this.helixController = helixController;
- }
-
- @Override
- public void start() {
- long initialDelay = 30 * 60 * 1000;
- long period = 120 * 60 * 1000;
- int timeThresholdNoChange = 180 * 60 * 1000;
-
- if (_timer == null) {
- LOG.info("Start StatusDumpTask");
- _timer = new Timer("StatusDumpTimerTask", true);
- _timer.scheduleAtFixedRate(new ZKPathDataDumpTask(helixController, zkclient,
- timeThresholdNoChange), initialDelay, period);
- }
-
- }
-
- @Override
- public void stop() {
- if (_timer != null) {
- LOG.info("Stop StatusDumpTask");
- _timer.cancel();
- _timer = null;
- }
- }
- }
-
- public ControllerManager(String zkAddress, String clusterName, String instanceName) {
- super(zkAddress, clusterName, instanceName, InstanceType.CONTROLLER);
-
- _timerTasks.add(new HealthStatsAggregationTask(new HealthStatsAggregator(this)));
- _timerTasks.add(new StatusDumpTask(_zkclient, this));
- }
-
- @Override
- protected List<HelixTimerTask> getControllerHelixTimerTasks() {
- return _timerTasks;
- }
-
- @Override
- public void handleNewSession() throws Exception {
- waitUntilConnected();
-
- /**
- * reset all handlers, make sure cleanup completed for previous session
- * disconnect if fail to cleanup
- */
- if (_leaderElectionHandler != null) {
- _leaderElectionHandler.reset();
- }
- // TODO reset user defined handlers only
- resetHandlers();
-
- /**
- * from here on, we are dealing with new session
- */
-
- if (_leaderElectionHandler != null) {
- _leaderElectionHandler.init();
- } else {
- _leaderElectionHandler =
- new CallbackHandler(this, _zkclient, _keyBuilder.controller(),
- new DistributedLeaderElection(this, _controller), new EventType[] {
- EventType.NodeChildrenChanged, EventType.NodeDeleted, EventType.NodeCreated
- }, ChangeType.CONTROLLER);
- }
-
- /**
- * init handlers
- * ok to init message handler and controller handlers twice
- * the second init will be skipped (see CallbackHandler)
- */
- initHandlers(_handlers);
- }
-
- @Override
- void doDisconnect() {
- if (_leaderElectionHandler != null) {
- _leaderElectionHandler.reset();
- }
- }
-
- @Override
- public boolean isLeader() {
- if (!isConnected()) {
- return false;
- }
-
- try {
- LiveInstance leader = _dataAccessor.getProperty(_keyBuilder.controllerLeader());
- if (leader != null) {
- String leaderName = leader.getInstanceName();
- String sessionId = leader.getSessionId();
- if (leaderName != null && leaderName.equals(_instanceName) && sessionId != null
- && sessionId.equals(_sessionId)) {
- return true;
- }
- }
- } catch (Exception e) {
- // log
- }
- return false;
- }
-
- /**
- * helix-controller uses a write-through cache for external-view
- */
- @Override
- BaseDataAccessor<ZNRecord> createBaseDataAccessor(ZkBaseDataAccessor<ZNRecord> baseDataAccessor) {
- String extViewPath = PropertyPathConfig.getPath(PropertyType.EXTERNALVIEW, _clusterName);
- return new ZkCacheBaseDataAccessor<ZNRecord>(baseDataAccessor, Arrays.asList(extViewPath));
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/main/java/org/apache/helix/manager/zk/ControllerManagerHelper.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ControllerManagerHelper.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ControllerManagerHelper.java
index ff3a264..d2b520b 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ControllerManagerHelper.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ControllerManagerHelper.java
@@ -36,14 +36,14 @@ import org.apache.log4j.Logger;
public class ControllerManagerHelper {
private static Logger LOG = Logger.getLogger(ControllerManagerHelper.class);
- final AbstractManager _manager;
+ final HelixManager _manager;
final DefaultMessagingService _messagingService;
final List<HelixTimerTask> _controllerTimerTasks;
- public ControllerManagerHelper(AbstractManager manager) {
+ public ControllerManagerHelper(HelixManager manager, List<HelixTimerTask> controllerTimerTasks) {
_manager = manager;
_messagingService = (DefaultMessagingService) manager.getMessagingService();
- _controllerTimerTasks = manager.getControllerHelixTimerTasks();
+ _controllerTimerTasks = controllerTimerTasks;
}
public void addListenersToController(GenericHelixController controller) {
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/main/java/org/apache/helix/manager/zk/DistributedControllerManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/DistributedControllerManager.java b/helix-core/src/main/java/org/apache/helix/manager/zk/DistributedControllerManager.java
deleted file mode 100644
index c9ad0f3..0000000
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/DistributedControllerManager.java
+++ /dev/null
@@ -1,190 +0,0 @@
-package org.apache.helix.manager.zk;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.helix.HelixException;
-import org.apache.helix.HelixTimerTask;
-import org.apache.helix.InstanceType;
-import org.apache.helix.PreConnectCallback;
-import org.apache.helix.HelixConstants.ChangeType;
-import org.apache.helix.controller.GenericHelixController;
-import org.apache.helix.healthcheck.HealthStatsAggregationTask;
-import org.apache.helix.healthcheck.HealthStatsAggregator;
-import org.apache.helix.healthcheck.ParticipantHealthReportCollector;
-import org.apache.helix.healthcheck.ParticipantHealthReportCollectorImpl;
-import org.apache.helix.healthcheck.ParticipantHealthReportTask;
-import org.apache.helix.model.LiveInstance;
-import org.apache.helix.participant.HelixStateMachineEngine;
-import org.apache.helix.participant.StateMachineEngine;
-import org.apache.log4j.Logger;
-import org.apache.zookeeper.Watcher.Event.EventType;
-
-public class DistributedControllerManager extends AbstractManager {
- private static Logger LOG = Logger.getLogger(DistributedControllerManager.class);
-
- final StateMachineEngine _stateMachineEngine;
- final ParticipantHealthReportCollectorImpl _participantHealthInfoCollector;
-
- CallbackHandler _leaderElectionHandler = null;
- final GenericHelixController _controller = new GenericHelixController();
-
- /**
- * hold timer tasks for controller only
- * we need to add/remove controller timer tasks during handle new session
- */
- final List<HelixTimerTask> _controllerTimerTasks = new ArrayList<HelixTimerTask>();
-
- public DistributedControllerManager(String zkAddress, String clusterName, String instanceName) {
- super(zkAddress, clusterName, instanceName, InstanceType.CONTROLLER_PARTICIPANT);
-
- _stateMachineEngine = new HelixStateMachineEngine(this);
- _participantHealthInfoCollector = new ParticipantHealthReportCollectorImpl(this, _instanceName);
-
- _timerTasks.add(new ParticipantHealthReportTask(_participantHealthInfoCollector));
-
- _controllerTimerTasks.add(new HealthStatsAggregationTask(new HealthStatsAggregator(this)));
- _controllerTimerTasks.add(new ControllerManager.StatusDumpTask(_zkclient, this));
-
- }
-
- @Override
- public ParticipantHealthReportCollector getHealthReportCollector() {
- checkConnected();
- return _participantHealthInfoCollector;
- }
-
- @Override
- public StateMachineEngine getStateMachineEngine() {
- return _stateMachineEngine;
- }
-
- @Override
- protected List<HelixTimerTask> getControllerHelixTimerTasks() {
- return _controllerTimerTasks;
- }
-
- @Override
- public void handleNewSession() throws Exception {
- waitUntilConnected();
-
- ParticipantManagerHelper participantHelper =
- new ParticipantManagerHelper(this, _zkclient, _sessionTimeout);
-
- /**
- * stop all timer tasks, reset all handlers, make sure cleanup completed for previous session
- * disconnect if fail to cleanup
- */
- stopTimerTasks();
- if (_leaderElectionHandler != null) {
- _leaderElectionHandler.reset();
- }
- resetHandlers();
-
- /**
- * clean up write-through cache
- */
- _baseDataAccessor.reset();
-
- /**
- * from here on, we are dealing with new session
- */
- if (!ZKUtil.isClusterSetup(_clusterName, _zkclient)) {
- throw new HelixException("Cluster structure is not set up for cluster: " + _clusterName);
- }
-
- /**
- * auto-join
- */
- participantHelper.joinCluster();
-
- /**
- * Invoke PreConnectCallbacks
- */
- for (PreConnectCallback callback : _preConnectCallbacks) {
- callback.onPreConnect();
- }
-
- participantHelper.createLiveInstance();
-
- participantHelper.carryOverPreviousCurrentState();
-
- participantHelper.setupMsgHandler();
-
- /**
- * leader election
- */
- if (_leaderElectionHandler != null) {
- _leaderElectionHandler.init();
- } else {
- _leaderElectionHandler =
- new CallbackHandler(this, _zkclient, _keyBuilder.controller(),
- new DistributedLeaderElection(this, _controller), new EventType[] {
- EventType.NodeChildrenChanged, EventType.NodeDeleted, EventType.NodeCreated
- }, ChangeType.CONTROLLER);
- }
-
- /**
- * start health-check timer task
- */
- participantHelper.createHealthCheckPath();
- startTimerTasks();
-
- /**
- * init handlers
- * ok to init message handler, data-accessor, and controller handlers twice
- * the second init will be skipped (see CallbackHandler)
- */
- initHandlers(_handlers);
-
- }
-
- @Override
- void doDisconnect() {
- if (_leaderElectionHandler != null) {
- _leaderElectionHandler.reset();
- }
- }
-
- @Override
- public boolean isLeader() {
- if (!isConnected()) {
- return false;
- }
-
- try {
- LiveInstance leader = _dataAccessor.getProperty(_keyBuilder.controllerLeader());
- if (leader != null) {
- String leaderName = leader.getInstanceName();
- String sessionId = leader.getSessionId();
- if (leaderName != null && leaderName.equals(_instanceName) && sessionId != null
- && sessionId.equals(_sessionId)) {
- return true;
- }
- }
- } catch (Exception e) {
- // log
- }
- return false;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/main/java/org/apache/helix/manager/zk/DistributedLeaderElection.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/DistributedLeaderElection.java b/helix-core/src/main/java/org/apache/helix/manager/zk/DistributedLeaderElection.java
index 0ab8342..6a6d296 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/DistributedLeaderElection.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/DistributedLeaderElection.java
@@ -20,10 +20,12 @@ package org.apache.helix.manager.zk;
*/
import java.lang.management.ManagementFactory;
+import java.util.List;
import org.apache.helix.ControllerChangeListener;
import org.apache.helix.HelixDataAccessor;
import org.apache.helix.HelixManager;
+import org.apache.helix.HelixTimerTask;
import org.apache.helix.InstanceType;
import org.apache.helix.NotificationContext;
import org.apache.helix.PropertyType;
@@ -40,12 +42,15 @@ import org.apache.log4j.Logger;
public class DistributedLeaderElection implements ControllerChangeListener {
private static Logger LOG = Logger.getLogger(DistributedLeaderElection.class);
- final AbstractManager _manager;
+ final HelixManager _manager;
final GenericHelixController _controller;
+ final List<HelixTimerTask> _controllerTimerTasks;
- public DistributedLeaderElection(AbstractManager manager, GenericHelixController controller) {
+ public DistributedLeaderElection(HelixManager manager, GenericHelixController controller,
+ List<HelixTimerTask> controllerTimerTasks) {
_manager = manager;
_controller = controller;
+ _controllerTimerTasks = controllerTimerTasks;
}
/**
@@ -68,7 +73,8 @@ public class DistributedLeaderElection implements ControllerChangeListener {
return;
}
- ControllerManagerHelper controllerHelper = new ControllerManagerHelper(_manager);
+ ControllerManagerHelper controllerHelper =
+ new ControllerManagerHelper(_manager, _controllerTimerTasks);
try {
if (changeContext.getType().equals(NotificationContext.Type.INIT)
|| changeContext.getType().equals(NotificationContext.Type.CALLBACK)) {
@@ -84,7 +90,7 @@ public class DistributedLeaderElection implements ControllerChangeListener {
+ _manager.getClusterName());
updateHistory(manager);
- _manager._baseDataAccessor.reset();
+ _manager.getHelixDataAccessor().getBaseDataAccessor().reset();
controllerHelper.addListenersToController(_controller);
controllerHelper.startControllerTimerTasks();
}
@@ -98,7 +104,7 @@ public class DistributedLeaderElection implements ControllerChangeListener {
/**
* clear write-through cache
*/
- _manager._baseDataAccessor.reset();
+ _manager.getHelixDataAccessor().getBaseDataAccessor().reset();
}
} catch (Exception e) {
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/main/java/org/apache/helix/manager/zk/ParticipantManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ParticipantManager.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ParticipantManager.java
deleted file mode 100644
index 0af7e77..0000000
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ParticipantManager.java
+++ /dev/null
@@ -1,155 +0,0 @@
-package org.apache.helix.manager.zk;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.helix.BaseDataAccessor;
-import org.apache.helix.HelixException;
-import org.apache.helix.InstanceType;
-import org.apache.helix.PreConnectCallback;
-import org.apache.helix.PropertyPathConfig;
-import org.apache.helix.PropertyType;
-import org.apache.helix.ZNRecord;
-import org.apache.helix.healthcheck.ParticipantHealthReportCollector;
-import org.apache.helix.healthcheck.ParticipantHealthReportCollectorImpl;
-import org.apache.helix.healthcheck.ParticipantHealthReportTask;
-import org.apache.helix.participant.HelixStateMachineEngine;
-import org.apache.helix.participant.StateMachineEngine;
-import org.apache.log4j.Logger;
-
-public class ParticipantManager extends AbstractManager {
-
- private static Logger LOG = Logger.getLogger(ParticipantManager.class);
-
- /**
- * state-transition message handler factory for helix-participant
- */
- final StateMachineEngine _stateMachineEngine;
-
- final ParticipantHealthReportCollectorImpl _participantHealthInfoCollector;
-
- public ParticipantManager(String zkAddress, String clusterName, String instanceName) {
- super(zkAddress, clusterName, instanceName, InstanceType.PARTICIPANT);
-
- _stateMachineEngine = new HelixStateMachineEngine(this);
- _participantHealthInfoCollector = new ParticipantHealthReportCollectorImpl(this, _instanceName);
-
- _timerTasks.add(new ParticipantHealthReportTask(_participantHealthInfoCollector));
- }
-
- @Override
- public ParticipantHealthReportCollector getHealthReportCollector() {
- checkConnected();
- return _participantHealthInfoCollector;
- }
-
- @Override
- public StateMachineEngine getStateMachineEngine() {
- return _stateMachineEngine;
- }
-
- @Override
- public void handleNewSession() {
- waitUntilConnected();
-
- /**
- * stop timer tasks, reset all handlers, make sure cleanup completed for previous session
- * disconnect if cleanup fails
- */
- stopTimerTasks();
- resetHandlers();
-
- /**
- * clear write-through cache
- */
- _baseDataAccessor.reset();
-
- /**
- * from here on, we are dealing with new session
- */
- if (!ZKUtil.isClusterSetup(_clusterName, _zkclient)) {
- throw new HelixException("Cluster structure is not set up for cluster: " + _clusterName);
- }
-
- /**
- * auto-join
- */
- ParticipantManagerHelper participantHelper =
- new ParticipantManagerHelper(this, _zkclient, _sessionTimeout);
- participantHelper.joinCluster();
-
- /**
- * Invoke PreConnectCallbacks
- */
- for (PreConnectCallback callback : _preConnectCallbacks) {
- callback.onPreConnect();
- }
-
- participantHelper.createLiveInstance();
-
- participantHelper.carryOverPreviousCurrentState();
-
- /**
- * setup message listener
- */
- participantHelper.setupMsgHandler();
-
- /**
- * start health check timer task
- */
- participantHelper.createHealthCheckPath();
- startTimerTasks();
-
- /**
- * init handlers
- * ok to init message handler and data-accessor twice
- * the second init will be skipped (see CallbackHandler)
- */
- initHandlers(_handlers);
-
- }
-
- /**
- * helix-participant uses a write-through cache for current-state
- */
- @Override
- BaseDataAccessor<ZNRecord> createBaseDataAccessor(ZkBaseDataAccessor<ZNRecord> baseDataAccessor) {
- String curStatePath =
- PropertyPathConfig.getPath(PropertyType.CURRENTSTATES, _clusterName, _instanceName);
- return new ZkCacheBaseDataAccessor<ZNRecord>(baseDataAccessor, Arrays.asList(curStatePath));
-
- }
-
- @Override
- public boolean isLeader() {
- return false;
- }
-
- /**
- * disconnect logic for helix-participant
- */
- @Override
- void doDisconnect() {
- // nothing for participant
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/main/java/org/apache/helix/manager/zk/ParticipantManagerHelper.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ParticipantManagerHelper.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ParticipantManagerHelper.java
index 70dd592..e7f9efb 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ParticipantManagerHelper.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ParticipantManagerHelper.java
@@ -31,6 +31,7 @@ import org.apache.helix.HelixDataAccessor;
import org.apache.helix.HelixException;
import org.apache.helix.HelixManager;
import org.apache.helix.InstanceType;
+import org.apache.helix.LiveInstanceInfoProvider;
import org.apache.helix.PropertyKey;
import org.apache.helix.ZNRecord;
import org.apache.helix.messaging.DefaultMessagingService;
@@ -55,7 +56,7 @@ public class ParticipantManagerHelper {
private static Logger LOG = Logger.getLogger(ParticipantManagerHelper.class);
final ZkClient _zkclient;
- final AbstractManager _manager;
+ final HelixManager _manager;
final PropertyKey.Builder _keyBuilder;
final String _clusterName;
final String _instanceName;
@@ -67,8 +68,10 @@ public class ParticipantManagerHelper {
final ZKHelixDataAccessor _dataAccessor;
final DefaultMessagingService _messagingService;
final StateMachineEngine _stateMachineEngine;
+ final LiveInstanceInfoProvider _liveInstanceInfoProvider;
- public ParticipantManagerHelper(AbstractManager manager, ZkClient zkclient, int sessionTimeout) {
+ public ParticipantManagerHelper(HelixManager manager, ZkClient zkclient, int sessionTimeout,
+ LiveInstanceInfoProvider liveInstanceInfoProvider) {
_zkclient = zkclient;
_manager = manager;
_clusterName = manager.getClusterName();
@@ -82,6 +85,7 @@ public class ParticipantManagerHelper {
_dataAccessor = (ZKHelixDataAccessor) manager.getHelixDataAccessor();
_messagingService = (DefaultMessagingService) manager.getMessagingService();
_stateMachineEngine = manager.getStateMachineEngine();
+ _liveInstanceInfoProvider = liveInstanceInfoProvider;
}
public void joinCluster() {
@@ -92,8 +96,8 @@ public class ParticipantManagerHelper {
new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(
_manager.getClusterName()).build();
autoJoin =
- Boolean
- .parseBoolean(_configAccessor.get(scope, HelixManager.ALLOW_PARTICIPANT_AUTO_JOIN));
+ Boolean.parseBoolean(_configAccessor.get(scope,
+ ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN));
LOG.info("instance: " + _instanceName + " auto-joining " + _clusterName + " is " + autoJoin);
} catch (Exception e) {
// autoJoin is false
@@ -128,6 +132,19 @@ public class ParticipantManagerHelper {
liveInstance.setHelixVersion(_manager.getVersion());
liveInstance.setLiveInstance(ManagementFactory.getRuntimeMXBean().getName());
+ // LiveInstanceInfoProvider liveInstanceInfoProvider = _manager._liveInstanceInfoProvider;
+ if (_liveInstanceInfoProvider != null) {
+ LOG.info("invoke liveInstanceInfoProvider");
+ ZNRecord additionalLiveInstanceInfo =
+ _liveInstanceInfoProvider.getAdditionalLiveInstanceInfo();
+ if (additionalLiveInstanceInfo != null) {
+ additionalLiveInstanceInfo.merge(liveInstance.getRecord());
+ ZNRecord mergedLiveInstance = new ZNRecord(additionalLiveInstanceInfo, _instanceName);
+ liveInstance = new LiveInstance(mergedLiveInstance);
+ LOG.info("instanceName: " + _instanceName + ", mergedLiveInstance: " + liveInstance);
+ }
+ }
+
boolean retry;
do {
retry = false;
@@ -250,7 +267,7 @@ public class ParticipantManagerHelper {
}
}
- public void setupMsgHandler() {
+ public void setupMsgHandler() throws Exception {
_messagingService.registerMessageHandlerFactory(MessageType.STATE_TRANSITION.toString(),
_stateMachineEngine);
_manager.addMessageListener(_messagingService.getExecutor(), _instanceName);
[05/10] [HELIX-279] Apply gc handling fixes to main ZKHelixManager
class
Posted by zz...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/healthcheck/TestAlertActionTriggering.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/healthcheck/TestAlertActionTriggering.java b/helix-core/src/test/java/org/apache/helix/healthcheck/TestAlertActionTriggering.java
index 7f004d3..b00e26c 100644
--- a/helix-core/src/test/java/org/apache/helix/healthcheck/TestAlertActionTriggering.java
+++ b/helix-core/src/test/java/org/apache/helix/healthcheck/TestAlertActionTriggering.java
@@ -40,10 +40,13 @@ import org.apache.helix.model.InstanceConfig;
import org.apache.helix.model.InstanceConfig.InstanceConfigProperty;
import org.apache.helix.tools.ClusterStateVerifier;
import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier;
+import org.apache.log4j.Logger;
import org.testng.Assert;
import org.testng.annotations.Test;
public class TestAlertActionTriggering extends ZkStandAloneCMTestBaseWithPropertyServerCheck {
+ private static Logger LOG = Logger.getLogger(TestAlertActionTriggering.class);
+
String _statName = "TestStat@DB=db1";
String _stat = "TestStat";
String metricName1 = "TestMetric1";
@@ -51,8 +54,7 @@ public class TestAlertActionTriggering extends ZkStandAloneCMTestBaseWithPropert
void setHealthData(int[] val1, int[] val2) {
for (int i = 0; i < NODE_NR; i++) {
- String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
- HelixManager manager = _startCMResultMap.get(instanceName)._manager;
+ HelixManager manager = _participants[i];
ZNRecord record = new ZNRecord(_stat);
Map<String, String> valMap = new HashMap<String, String>();
valMap.put(metricName1, val1[i] + "");
@@ -68,15 +70,13 @@ public class TestAlertActionTriggering extends ZkStandAloneCMTestBaseWithPropert
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.error("sleep interrupted", e);
}
}
void setHealthData2(int[] val1) {
for (int i = 0; i < NODE_NR; i++) {
- String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
- HelixManager manager = _startCMResultMap.get(instanceName)._manager;
+ HelixManager manager = _participants[i];
ZNRecord record = new ZNRecord(_stat);
Map<String, String> valMap = new HashMap<String, String>();
valMap.put(metricName2, val1[i] + "");
@@ -91,8 +91,7 @@ public class TestAlertActionTriggering extends ZkStandAloneCMTestBaseWithPropert
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.error("sleep interrupted", e);
}
}
@@ -127,11 +126,9 @@ public class TestAlertActionTriggering extends ZkStandAloneCMTestBaseWithPropert
};
setHealthData(metrics1, metrics2);
- String controllerName = CONTROLLER_PREFIX + "_0";
- HelixManager manager = _startCMResultMap.get(controllerName)._manager;
+ HelixManager manager = _controller;
- HealthStatsAggregator task =
- new HealthStatsAggregator(_startCMResultMap.get(controllerName)._manager);
+ HealthStatsAggregator task = new HealthStatsAggregator(manager);
task.aggregate();
Thread.sleep(4000);
HelixDataAccessor helixDataAccessor = manager.getHelixDataAccessor();
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/healthcheck/TestAlertFireHistory.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/healthcheck/TestAlertFireHistory.java b/helix-core/src/test/java/org/apache/helix/healthcheck/TestAlertFireHistory.java
index 125f61f..c18b643 100644
--- a/helix-core/src/test/java/org/apache/helix/healthcheck/TestAlertFireHistory.java
+++ b/helix-core/src/test/java/org/apache/helix/healthcheck/TestAlertFireHistory.java
@@ -31,12 +31,15 @@ import org.apache.helix.model.builder.HelixConfigScopeBuilder;
import org.apache.helix.HelixDataAccessor;
import org.apache.helix.HelixManager;
import org.apache.helix.HelixProperty;
+import org.apache.helix.HelixTimerTask;
+import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.PropertyKey.Builder;
import org.apache.helix.integration.ZkStandAloneCMTestBaseWithPropertyServerCheck;
import org.apache.helix.model.AlertHistory;
import org.apache.helix.model.HealthStat;
import org.apache.helix.model.HelixConfigScope;
+import org.apache.log4j.Logger;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -46,6 +49,8 @@ import org.testng.annotations.Test;
*/
public class TestAlertFireHistory extends ZkStandAloneCMTestBaseWithPropertyServerCheck {
+ private final static Logger LOG = Logger.getLogger(TestAlertFireHistory.class);
+
String _statName = "TestStat@DB=db1";
String _stat = "TestStat";
String metricName1 = "TestMetric1";
@@ -57,8 +62,7 @@ public class TestAlertFireHistory extends ZkStandAloneCMTestBaseWithPropertyServ
void setHealthData(int[] val1, int[] val2) {
for (int i = 0; i < NODE_NR; i++) {
- String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
- HelixManager manager = _startCMResultMap.get(instanceName)._manager;
+ HelixManager manager = _participants[i];
ZNRecord record = new ZNRecord(_stat);
Map<String, String> valMap = new HashMap<String, String>();
valMap.put(metricName1, val1[i] + "");
@@ -74,13 +78,12 @@ public class TestAlertFireHistory extends ZkStandAloneCMTestBaseWithPropertyServ
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.error("Interrupted sleep", e);
}
}
@Test
- public void TestAlertDisable() throws InterruptedException {
+ public void testAlertDisable() throws InterruptedException {
int[] metrics1 = {
10, 15, 22, 24, 16
@@ -90,29 +93,27 @@ public class TestAlertFireHistory extends ZkStandAloneCMTestBaseWithPropertyServ
};
setHealthData(metrics1, metrics2);
- String controllerName = CONTROLLER_PREFIX + "_0";
- HelixManager manager = _startCMResultMap.get(controllerName)._manager;
+ HelixManager manager = _controller;
manager.startTimerTasks();
_setupTool.getClusterManagementTool().addAlert(CLUSTER_NAME, _alertStr1);
_setupTool.getClusterManagementTool().addAlert(CLUSTER_NAME, _alertStr2);
- // ConfigScope scope = new ConfigScopeBuilder().forCluster(CLUSTER_NAME).build();
HelixConfigScope scope =
new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(CLUSTER_NAME).build();
Map<String, String> properties = new HashMap<String, String>();
properties.put("healthChange.enabled", "false");
_setupTool.getClusterManagementTool().setConfig(scope, properties);
- HealthStatsAggregator task =
- new HealthStatsAggregator(_startCMResultMap.get(controllerName)._manager);
+ HealthStatsAggregator task = new HealthStatsAggregator(_controller);
+
task.aggregate();
Thread.sleep(100);
HelixDataAccessor helixDataAccessor = manager.getHelixDataAccessor();
Builder keyBuilder = helixDataAccessor.keyBuilder();
AlertHistory history = manager.getHelixDataAccessor().getProperty(keyBuilder.alertHistory());
- //
+
Assert.assertEquals(history, null);
properties.put("healthChange.enabled", "true");
@@ -128,7 +129,7 @@ public class TestAlertFireHistory extends ZkStandAloneCMTestBaseWithPropertyServ
}
@Test
- public void TestAlertHistory() throws InterruptedException {
+ public void testAlertHistory() throws InterruptedException {
int[] metrics1 = {
10, 15, 22, 24, 16
};
@@ -137,9 +138,10 @@ public class TestAlertFireHistory extends ZkStandAloneCMTestBaseWithPropertyServ
};
setHealthData(metrics1, metrics2);
- String controllerName = CONTROLLER_PREFIX + "_0";
- HelixManager manager = _startCMResultMap.get(controllerName)._manager;
- manager.stopTimerTasks();
+ HelixManager manager = _controller;
+ for (HelixTimerTask task : _controller.getControllerTimerTasks()) {
+ task.stop();
+ }
_setupTool.getClusterManagementTool().addAlert(CLUSTER_NAME, _alertStr1);
_setupTool.getClusterManagementTool().addAlert(CLUSTER_NAME, _alertStr2);
@@ -154,8 +156,8 @@ public class TestAlertFireHistory extends ZkStandAloneCMTestBaseWithPropertyServ
historySize = property.getRecord().getMapFields().size();
}
- HealthStatsAggregator task =
- new HealthStatsAggregator(_startCMResultMap.get(controllerName)._manager);
+ HealthStatsAggregator task = new HealthStatsAggregator(_controller);
+
task.aggregate();
Thread.sleep(100);
@@ -421,3 +423,4 @@ public class TestAlertFireHistory extends ZkStandAloneCMTestBaseWithPropertyServ
}
}
+
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/healthcheck/TestDummyAlerts.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/healthcheck/TestDummyAlerts.java b/helix-core/src/test/java/org/apache/helix/healthcheck/TestDummyAlerts.java
index c5f373c..b8bd634 100644
--- a/helix-core/src/test/java/org/apache/helix/healthcheck/TestDummyAlerts.java
+++ b/helix-core/src/test/java/org/apache/helix/healthcheck/TestDummyAlerts.java
@@ -29,10 +29,10 @@ import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.PropertyKey.Builder;
import org.apache.helix.integration.ZkIntegrationTestBase;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.mock.controller.ClusterController;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.mock.participant.MockTransition;
import org.apache.helix.model.HealthStat;
import org.apache.helix.model.Message;
@@ -73,7 +73,7 @@ public class TestDummyAlerts extends ZkIntegrationTestBase {
String clusterName = className + "_" + methodName;
final int n = 5;
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
@@ -95,15 +95,16 @@ public class TestDummyAlerts extends ZkIntegrationTestBase {
"EXP(decay(1.0)(*.defaultPerfCounters@defaultPerfCounters.availableCPUs))CMP(GREATER)CON(2)");
// start controller
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] =
- new MockParticipant(clusterName, instanceName, ZK_ADDR, new DummyAlertsTransition());
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participants[i].setTransition(new DummyAlertsTransition());
participants[i].syncStart();
}
@@ -137,7 +138,6 @@ public class TestDummyAlerts extends ZkIntegrationTestBase {
}
// clean up
- Thread.sleep(1000);
controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/healthcheck/TestExpandAlert.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/healthcheck/TestExpandAlert.java b/helix-core/src/test/java/org/apache/helix/healthcheck/TestExpandAlert.java
index 69d1062..69b52e7 100644
--- a/helix-core/src/test/java/org/apache/helix/healthcheck/TestExpandAlert.java
+++ b/helix-core/src/test/java/org/apache/helix/healthcheck/TestExpandAlert.java
@@ -29,18 +29,14 @@ import org.apache.helix.NotificationContext;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.TestHelper.StartCMResult;
import org.apache.helix.alerts.AlertValueAndStatus;
-import org.apache.helix.controller.HelixControllerMain;
-import org.apache.helix.healthcheck.HealthStatsAggregationTask;
import org.apache.helix.healthcheck.ParticipantHealthReportCollectorImpl;
import org.apache.helix.integration.ZkIntegrationTestBase;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
-import org.apache.helix.manager.zk.ZNRecordSerializer;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.manager.zk.ZkClient;
import org.apache.helix.mock.participant.MockEspressoHealthReportProvider;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.mock.participant.MockTransition;
import org.apache.helix.model.Message;
import org.apache.helix.tools.ClusterSetup;
@@ -51,7 +47,6 @@ import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class TestExpandAlert extends ZkIntegrationTestBase {
- ZkClient _zkClient;
protected ClusterSetup _setupTool = null;
protected final String _alertStr =
"EXP(decay(1.0)(localhost_*.RestQueryStats@DBName=TestDB0.latency))CMP(GREATER)CON(16)";
@@ -61,15 +56,12 @@ public class TestExpandAlert extends ZkIntegrationTestBase {
@BeforeClass()
public void beforeClass() throws Exception {
- _zkClient = new ZkClient(ZK_ADDR);
- _zkClient.setZkSerializer(new ZNRecordSerializer());
- _setupTool = new ClusterSetup(ZK_ADDR);
+ _setupTool = new ClusterSetup(_gZkClient);
}
@AfterClass
public void afterClass() {
- _zkClient.close();
}
public class ExpandAlertTransition extends MockTransition {
@@ -120,7 +112,7 @@ public class TestExpandAlert extends ZkIntegrationTestBase {
@Test()
public void testExpandAlert() throws Exception {
String clusterName = getShortClassName();
- MockParticipant[] participants = new MockParticipant[5];
+ MockParticipantManager[] participants = new MockParticipantManager[5];
System.out.println("START TestExpandAlert at " + new Date(System.currentTimeMillis()));
@@ -136,18 +128,19 @@ public class TestExpandAlert extends ZkIntegrationTestBase {
_setupTool.getClusterManagementTool().addAlert(clusterName, _alertStr);
- StartCMResult cmResult =
- TestHelper.startController(clusterName, "controller_0", ZK_ADDR,
- HelixControllerMain.STANDALONE);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+ controller.syncStart();
+
// start participants
for (int i = 0; i < 5; i++) // !!!change back to 5
{
String instanceName = "localhost_" + (12918 + i);
participants[i] =
- new MockParticipant(clusterName, instanceName, ZK_ADDR, new ExpandAlertTransition());
- participants[i].start();
- // new Thread(participants[i]).start();
+ new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participants[i].setTransition(new ExpandAlertTransition());
+ participants[i].syncStart();
}
boolean result =
@@ -158,13 +151,14 @@ public class TestExpandAlert extends ZkIntegrationTestBase {
Thread.sleep(1000);
// HealthAggregationTask is supposed to run by a timer every 30s
// To make sure HealthAggregationTask is run, we invoke it explicitly for this test
- new HealthStatsAggregator(cmResult._manager).aggregate();
+ // new HealthStatsAggregator(cmResult._manager).aggregate();
+ new HealthStatsAggregator(controller).aggregate();
// sleep for a few seconds to give stats stage time to trigger
Thread.sleep(3000);
// other verifications go here
ZKHelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_zkClient));
+ new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
// for (int i = 0; i < 1; i++) //change 1 back to 5
@@ -181,6 +175,12 @@ public class TestExpandAlert extends ZkIntegrationTestBase {
Assert.assertFalse(fired);
// }
+ // clean up
+ controller.syncStop();
+ for (int i = 0; i < 5; i++) {
+ participants[i].syncStop();
+
+ }
System.out.println("END TestExpandAlert at " + new Date(System.currentTimeMillis()));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/healthcheck/TestSimpleAlert.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/healthcheck/TestSimpleAlert.java b/helix-core/src/test/java/org/apache/helix/healthcheck/TestSimpleAlert.java
index 1db5ddd..ccc0a79 100644
--- a/helix-core/src/test/java/org/apache/helix/healthcheck/TestSimpleAlert.java
+++ b/helix-core/src/test/java/org/apache/helix/healthcheck/TestSimpleAlert.java
@@ -29,18 +29,14 @@ import org.apache.helix.NotificationContext;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.TestHelper.StartCMResult;
import org.apache.helix.alerts.AlertValueAndStatus;
-import org.apache.helix.controller.HelixControllerMain;
-import org.apache.helix.healthcheck.HealthStatsAggregationTask;
import org.apache.helix.healthcheck.ParticipantHealthReportCollectorImpl;
import org.apache.helix.integration.ZkIntegrationTestBase;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
-import org.apache.helix.manager.zk.ZNRecordSerializer;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.manager.zk.ZkClient;
import org.apache.helix.mock.participant.MockEspressoHealthReportProvider;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.mock.participant.MockTransition;
import org.apache.helix.model.Message;
import org.apache.helix.tools.ClusterSetup;
@@ -51,7 +47,6 @@ import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class TestSimpleAlert extends ZkIntegrationTestBase {
- ZkClient _zkClient;
protected ClusterSetup _setupTool = null;
protected final String _alertStr =
"EXP(decay(1.0)(localhost_12918.RestQueryStats@DBName=TestDB0.latency))CMP(GREATER)CON(10)";
@@ -60,15 +55,11 @@ public class TestSimpleAlert extends ZkIntegrationTestBase {
@BeforeClass()
public void beforeClass() throws Exception {
- _zkClient = new ZkClient(ZK_ADDR);
- _zkClient.setZkSerializer(new ZNRecordSerializer());
-
- _setupTool = new ClusterSetup(ZK_ADDR);
+ _setupTool = new ClusterSetup(_gZkClient);
}
@AfterClass
public void afterClass() {
- _zkClient.close();
}
public class SimpleAlertTransition extends MockTransition {
@@ -125,7 +116,7 @@ public class TestSimpleAlert extends ZkIntegrationTestBase {
@Test()
public void testSimpleAlert() throws Exception {
String clusterName = getShortClassName();
- MockParticipant[] participants = new MockParticipant[5];
+ MockParticipantManager[] participants = new MockParticipantManager[5];
System.out.println("START TestSimpleAlert at " + new Date(System.currentTimeMillis()));
@@ -140,10 +131,11 @@ public class TestSimpleAlert extends ZkIntegrationTestBase {
// enableHealthCheck(clusterName);
- StartCMResult cmResult =
- TestHelper.startController(clusterName, "controller_0", ZK_ADDR,
- HelixControllerMain.STANDALONE);
- cmResult._manager.startTimerTasks();
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+ controller.syncStart();
+ controller.startTimerTasks();
+
_setupTool.getClusterManagementTool().addAlert(clusterName, _alertStr);
// start participants
for (int i = 0; i < 5; i++) // !!!change back to 5
@@ -151,9 +143,9 @@ public class TestSimpleAlert extends ZkIntegrationTestBase {
String instanceName = "localhost_" + (12918 + i);
participants[i] =
- new MockParticipant(clusterName, instanceName, ZK_ADDR, new SimpleAlertTransition(15));
+ new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participants[i].setTransition(new SimpleAlertTransition(15));
participants[i].syncStart();
- // new Thread(participants[i]).start();
}
boolean result =
@@ -163,13 +155,14 @@ public class TestSimpleAlert extends ZkIntegrationTestBase {
// HealthAggregationTask is supposed to run by a timer every 30s
// To make sure HealthAggregationTask is run, we invoke it explicitly for this test
- new HealthStatsAggregator(cmResult._manager).aggregate();
+ // new HealthStatsAggregator(cmResult._manager).aggregate();
+ new HealthStatsAggregator(controller).aggregate();
// sleep for a few seconds to give stats stage time to trigger
Thread.sleep(3000);
// other verifications go here
ZKHelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_zkClient));
+ new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
// for (int i = 0; i < 1; i++) //change 1 back to 5
// {
@@ -197,6 +190,11 @@ public class TestSimpleAlert extends ZkIntegrationTestBase {
.equals("ON"));
// }
+ // clean up
+ controller.syncStop();
+ for (int i = 0; i < 5; i++) {
+ participants[i].syncStop();
+ }
System.out.println("END TestSimpleAlert at " + new Date(System.currentTimeMillis()));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/healthcheck/TestSimpleWildcardAlert.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/healthcheck/TestSimpleWildcardAlert.java b/helix-core/src/test/java/org/apache/helix/healthcheck/TestSimpleWildcardAlert.java
index c5b55da..417a53a 100644
--- a/helix-core/src/test/java/org/apache/helix/healthcheck/TestSimpleWildcardAlert.java
+++ b/helix-core/src/test/java/org/apache/helix/healthcheck/TestSimpleWildcardAlert.java
@@ -28,29 +28,27 @@ import org.apache.helix.NotificationContext;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.TestHelper.StartCMResult;
import org.apache.helix.alerts.AlertValueAndStatus;
-import org.apache.helix.controller.HelixControllerMain;
-import org.apache.helix.healthcheck.HealthStatsAggregationTask;
import org.apache.helix.healthcheck.ParticipantHealthReportCollectorImpl;
import org.apache.helix.integration.ZkIntegrationTestBase;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
-import org.apache.helix.manager.zk.ZNRecordSerializer;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.manager.zk.ZkClient;
import org.apache.helix.mock.participant.MockEspressoHealthReportProvider;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.mock.participant.MockTransition;
import org.apache.helix.model.Message;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.tools.ClusterStateVerifier;
+import org.apache.log4j.Logger;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class TestSimpleWildcardAlert extends ZkIntegrationTestBase {
- ZkClient _zkClient;
+ private static Logger LOG = Logger.getLogger(TestSimpleWildcardAlert.class);
+
protected ClusterSetup _setupTool = null;
protected final String _alertStr =
"EXP(decay(1.0)(localhost_12918.RestQueryStats@DBName=TestDB0.latency))CMP(GREATER)CON(10)";
@@ -59,15 +57,12 @@ public class TestSimpleWildcardAlert extends ZkIntegrationTestBase {
@BeforeClass()
public void beforeClass() throws Exception {
- _zkClient = new ZkClient(ZK_ADDR);
- _zkClient.setZkSerializer(new ZNRecordSerializer());
- _setupTool = new ClusterSetup(ZK_ADDR);
+ _setupTool = new ClusterSetup(_gZkClient);
}
@AfterClass
public void afterClass() {
- _zkClient.close();
}
public class SimpleAlertTransition extends MockTransition {
@@ -124,7 +119,7 @@ public class TestSimpleWildcardAlert extends ZkIntegrationTestBase {
@Test()
public void testSimpleWildcardAlert() throws Exception {
String clusterName = getShortClassName();
- MockParticipant[] participants = new MockParticipant[5];
+ MockParticipantManager[] participants = new MockParticipantManager[5];
System.out.println("START testSimpleWildcardAlert at " + new Date(System.currentTimeMillis()));
@@ -139,10 +134,10 @@ public class TestSimpleWildcardAlert extends ZkIntegrationTestBase {
// enableHealthCheck(clusterName);
- StartCMResult cmResult =
- TestHelper.startController(clusterName, "controller_0", ZK_ADDR,
- HelixControllerMain.STANDALONE);
- cmResult._manager.stopTimerTasks();
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+ controller.syncStart();
+ controller.stopTimerTasks();
String alertwildcard =
"EXP(decay(1.0)(localhost*.RestQueryStats@DBName=TestDB0.latency))CMP(GREATER)CON(10)";
@@ -154,9 +149,9 @@ public class TestSimpleWildcardAlert extends ZkIntegrationTestBase {
String instanceName = "localhost_" + (12944 + i);
participants[i] =
- new MockParticipant(clusterName, instanceName, ZK_ADDR, new SimpleAlertTransition(i * 5));
+ new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participants[i].setTransition(new SimpleAlertTransition(i * 5));
participants[i].syncStart();
- // new Thread(participants[i]).start();
}
boolean result =
@@ -167,13 +162,13 @@ public class TestSimpleWildcardAlert extends ZkIntegrationTestBase {
Thread.sleep(1000);
// HealthAggregationTask is supposed to run by a timer every 30s
// To make sure HealthAggregationTask is run, we invoke it explicitly for this test
- new HealthStatsAggregator(cmResult._manager).aggregate();
+ new HealthStatsAggregator(controller).aggregate();
// sleep for a few seconds to give stats stage time to trigger
Thread.sleep(1000);
// other verifications go here
ZKHelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_zkClient));
+ new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
ZNRecord record = accessor.getProperty(keyBuilder.alertStatus()).getRecord();
Map<String, Map<String, String>> recMap = record.getMapFields();
@@ -209,7 +204,7 @@ public class TestSimpleWildcardAlert extends ZkIntegrationTestBase {
alertwildcard =
"EXP(decay(1.0)(localhost*.RestQueryStats@DBName=TestDB0.latency))CMP(GREATER)CON(15)";
_setupTool.getClusterManagementTool().addAlert(clusterName, alertwildcard);
- new HealthStatsAggregator(cmResult._manager).aggregate();
+ new HealthStatsAggregator(controller).aggregate();
Thread.sleep(1000);
record = accessor.getProperty(keyBuilder.alertStatus()).getRecord();
@@ -241,6 +236,11 @@ public class TestSimpleWildcardAlert extends ZkIntegrationTestBase {
Assert.assertTrue(delta.get(alertString).equals("ON"));
}
+ // clean up
+ controller.syncStop();
+ for (int i = 0; i < 5; i++) {
+ participants[i].syncStop();
+ }
System.out.println("END testSimpleWildcardAlert at " + new Date(System.currentTimeMillis()));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/healthcheck/TestStalenessAlert.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/healthcheck/TestStalenessAlert.java b/helix-core/src/test/java/org/apache/helix/healthcheck/TestStalenessAlert.java
index 2304b41..cdb7d1d 100644
--- a/helix-core/src/test/java/org/apache/helix/healthcheck/TestStalenessAlert.java
+++ b/helix-core/src/test/java/org/apache/helix/healthcheck/TestStalenessAlert.java
@@ -29,18 +29,14 @@ import org.apache.helix.NotificationContext;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.TestHelper.StartCMResult;
import org.apache.helix.alerts.AlertValueAndStatus;
-import org.apache.helix.controller.HelixControllerMain;
-import org.apache.helix.healthcheck.HealthStatsAggregationTask;
import org.apache.helix.healthcheck.ParticipantHealthReportCollectorImpl;
import org.apache.helix.integration.ZkIntegrationTestBase;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
-import org.apache.helix.manager.zk.ZNRecordSerializer;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.manager.zk.ZkClient;
import org.apache.helix.mock.participant.MockEspressoHealthReportProvider;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.mock.participant.MockTransition;
import org.apache.helix.model.Message;
import org.apache.helix.tools.ClusterSetup;
@@ -51,7 +47,6 @@ import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class TestStalenessAlert extends ZkIntegrationTestBase {
- ZkClient _zkClient;
protected ClusterSetup _setupTool = null;
protected final String _alertStr = "EXP(decay(1)(localhost_*.reportingage))CMP(GREATER)CON(600)";
protected final String _alertStatusStr = _alertStr + " : (localhost_12918.reportingage)";
@@ -59,15 +54,12 @@ public class TestStalenessAlert extends ZkIntegrationTestBase {
@BeforeClass()
public void beforeClass() throws Exception {
- _zkClient = new ZkClient(ZK_ADDR);
- _zkClient.setZkSerializer(new ZNRecordSerializer());
- _setupTool = new ClusterSetup(ZK_ADDR);
+ _setupTool = new ClusterSetup(_gZkClient);
}
@AfterClass
public void afterClass() {
- _zkClient.close();
}
public class StalenessAlertTransition extends MockTransition {
@@ -118,7 +110,7 @@ public class TestStalenessAlert extends ZkIntegrationTestBase {
@Test()
public void testStalenessAlert() throws Exception {
String clusterName = getShortClassName();
- MockParticipant[] participants = new MockParticipant[5];
+ MockParticipantManager[] participants = new MockParticipantManager[5];
System.out.println("START TestStalenessAlert at " + new Date(System.currentTimeMillis()));
@@ -134,18 +126,19 @@ public class TestStalenessAlert extends ZkIntegrationTestBase {
_setupTool.getClusterManagementTool().addAlert(clusterName, _alertStr);
- StartCMResult cmResult =
- TestHelper.startController(clusterName, "controller_0", ZK_ADDR,
- HelixControllerMain.STANDALONE);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+ controller.syncStart();
+
// start participants
for (int i = 0; i < 5; i++) // !!!change back to 5
{
String instanceName = "localhost_" + (12918 + i);
participants[i] =
- new MockParticipant(clusterName, instanceName, ZK_ADDR, new StalenessAlertTransition());
+ new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participants[i].setTransition(new StalenessAlertTransition());
participants[i].syncStart();
- // new Thread(participants[i]).start();
}
boolean result =
@@ -155,13 +148,13 @@ public class TestStalenessAlert extends ZkIntegrationTestBase {
// HealthAggregationTask is supposed to run by a timer every 30s
// To make sure HealthAggregationTask is run, we invoke it explicitly for this test
- new HealthStatsAggregator(cmResult._manager).aggregate();
+ new HealthStatsAggregator(controller).aggregate();
// sleep for a few seconds to give stats stage time to trigger
Thread.sleep(3000);
// other verifications go here
ZKHelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_zkClient));
+ new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
// for (int i = 0; i < 1; i++) //change 1 back to 5
// {
@@ -177,6 +170,11 @@ public class TestStalenessAlert extends ZkIntegrationTestBase {
// Assert.assertFalse(fired);
// }
+ // clean up
+ controller.syncStop();
+ for (int i = 0; i < 5; i++) {
+ participants[i].syncStop();
+ }
System.out.println("END TestStalenessAlert at " + new Date(System.currentTimeMillis()));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/healthcheck/TestWildcardAlert.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/healthcheck/TestWildcardAlert.java b/helix-core/src/test/java/org/apache/helix/healthcheck/TestWildcardAlert.java
index a0456a7..cc819de 100644
--- a/helix-core/src/test/java/org/apache/helix/healthcheck/TestWildcardAlert.java
+++ b/helix-core/src/test/java/org/apache/helix/healthcheck/TestWildcardAlert.java
@@ -44,18 +44,14 @@ import org.apache.helix.NotificationContext;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.TestHelper.StartCMResult;
import org.apache.helix.alerts.AlertValueAndStatus;
-import org.apache.helix.controller.HelixControllerMain;
-import org.apache.helix.healthcheck.HealthStatsAggregationTask;
import org.apache.helix.healthcheck.ParticipantHealthReportCollectorImpl;
import org.apache.helix.integration.ZkIntegrationTestBase;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
-import org.apache.helix.manager.zk.ZNRecordSerializer;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.manager.zk.ZkClient;
import org.apache.helix.mock.participant.MockEspressoHealthReportProvider;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.mock.participant.MockTransition;
import org.apache.helix.model.Message;
import org.apache.helix.monitoring.mbeans.ClusterAlertMBeanCollection;
@@ -126,7 +122,6 @@ public class TestWildcardAlert extends ZkIntegrationTestBase {
}
private static final Logger _logger = Logger.getLogger(TestWildcardAlert.class);
- ZkClient _zkClient;
protected ClusterSetup _setupTool = null;
protected final String _alertStr =
"EXP(decay(1)(localhost_*.RestQueryStats@DBName=TestDB0.latency)|EXPAND|SUMEACH)CMP(GREATER)CON(10)";
@@ -135,15 +130,12 @@ public class TestWildcardAlert extends ZkIntegrationTestBase {
@BeforeClass()
public void beforeClass() throws Exception {
- _zkClient = new ZkClient(ZK_ADDR);
- _zkClient.setZkSerializer(new ZNRecordSerializer());
- _setupTool = new ClusterSetup(ZK_ADDR);
+ _setupTool = new ClusterSetup(_gZkClient);
}
@AfterClass
public void afterClass() {
- _zkClient.close();
}
public class WildcardAlertTransition extends MockTransition {
@@ -209,7 +201,7 @@ public class TestWildcardAlert extends ZkIntegrationTestBase {
@Test()
public void testWildcardAlert() throws Exception {
String clusterName = getShortClassName();
- MockParticipant[] participants = new MockParticipant[5];
+ MockParticipantManager[] participants = new MockParticipantManager[5];
System.out.println("START TestWildcardAlert at " + new Date(System.currentTimeMillis()));
@@ -228,18 +220,18 @@ public class TestWildcardAlert extends ZkIntegrationTestBase {
_setupTool.getClusterManagementTool().addAlert(clusterName, _alertStr);
// _setupTool.getClusterManagementTool().addAlert(clusterName, _alertStr2);
- StartCMResult cmResult =
- TestHelper.startController(clusterName, "controller_0", ZK_ADDR,
- HelixControllerMain.STANDALONE);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+ controller.syncStart();
// start participants
for (int i = 0; i < 5; i++) // !!!change back to 5
{
String instanceName = "localhost_" + (12918 + i);
participants[i] =
- new MockParticipant(clusterName, instanceName, ZK_ADDR, new WildcardAlertTransition());
+ new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participants[i].setTransition(new WildcardAlertTransition());
participants[i].syncStart();
- // new Thread(participants[i]).start();
}
TestClusterMBeanObserver jmxMBeanObserver =
@@ -252,13 +244,13 @@ public class TestWildcardAlert extends ZkIntegrationTestBase {
Thread.sleep(3000);
// HealthAggregationTask is supposed to run by a timer every 30s
// To make sure HealthAggregationTask is run, we invoke it explicitly for this test
- new HealthStatsAggregator(cmResult._manager).aggregate();
+ new HealthStatsAggregator(controller).aggregate();
// sleep for a few seconds to give stats stage time to trigger and for bean to trigger
Thread.sleep(3000);
ZKHelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_zkClient));
+ new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
// for (int i = 0; i < 1; i++) //change 1 back to 5
@@ -293,6 +285,12 @@ public class TestWildcardAlert extends ZkIntegrationTestBase {
"EXP(decay(1)(localhost_%.RestQueryStats@DBName#TestDB0.latency)|EXPAND|SUMEACH)CMP(GREATER)CON(10)--(%)");
// }
+ // clean up
+ controller.syncStop();
+ for (int i = 0; i < 5; i++) {
+ participants[i].syncStop();
+ }
+
System.out.println("END TestWildcardAlert at " + new Date(System.currentTimeMillis()));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestAddClusterV2.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestAddClusterV2.java b/helix-core/src/test/java/org/apache/helix/integration/TestAddClusterV2.java
index 8547666..32fdcff 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestAddClusterV2.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestAddClusterV2.java
@@ -20,16 +20,9 @@ package org.apache.helix.integration;
*/
import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.apache.helix.PropertyType;
-import org.apache.helix.TestHelper;
-import org.apache.helix.TestHelper.StartCMResult;
-import org.apache.helix.controller.HelixControllerMain;
-import org.apache.helix.model.PauseSignal;
+
+import org.apache.helix.integration.manager.ClusterDistributedController;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.tools.ClusterStateVerifier;
import org.apache.log4j.Logger;
@@ -46,13 +39,15 @@ public class TestAddClusterV2 extends ZkIntegrationTestBase {
protected static final int START_PORT = 12918;
protected static final String STATE_MODEL = "MasterSlave";
protected ClusterSetup _setupTool = null;
- protected Map<String, StartCMResult> _startCMResultMap = new HashMap<String, StartCMResult>();
protected final String CLASS_NAME = getShortClassName();
protected final String CONTROLLER_CLUSTER = CONTROLLER_CLUSTER_PREFIX + "_" + CLASS_NAME;
protected static final String TEST_DB = "TestDB";
+ MockParticipantManager[] _participants = new MockParticipantManager[NODE_NR];
+ ClusterDistributedController[] _distControllers = new ClusterDistributedController[NODE_NR];
+
@BeforeClass
public void beforeClass() throws Exception {
System.out.println("START " + CLASS_NAME + " at " + new Date(System.currentTimeMillis()));
@@ -90,29 +85,18 @@ public class TestAddClusterV2 extends ZkIntegrationTestBase {
"MasterSlave", 3, true);
// start dummy participants for the first cluster
- for (int i = 0; i < 5; i++) {
+ for (int i = 0; i < NODE_NR; i++) {
String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
- if (_startCMResultMap.get(instanceName) != null) {
- LOG.error("fail to start participant:" + instanceName
- + "(participant with the same name already running");
- } else {
- StartCMResult result = TestHelper.startDummyProcess(ZK_ADDR, firstCluster, instanceName);
- _startCMResultMap.put(instanceName, result);
- }
+ _participants[i] = new MockParticipantManager(ZK_ADDR, firstCluster, instanceName);
+ _participants[i].syncStart();
}
// start distributed cluster controllers
- for (int i = 0; i < 5; i++) {
+ for (int i = 0; i < NODE_NR; i++) {
String controllerName = CONTROLLER_PREFIX + "_" + i;
- if (_startCMResultMap.get(controllerName) != null) {
- LOG.error("fail to start controller:" + controllerName
- + "(controller with the same name already running");
- } else {
- StartCMResult result =
- TestHelper.startController(CONTROLLER_CLUSTER, controllerName, ZK_ADDR,
- HelixControllerMain.DISTRIBUTED);
- _startCMResultMap.put(controllerName, result);
- }
+ _distControllers[i] =
+ new ClusterDistributedController(ZK_ADDR, CONTROLLER_CLUSTER, controllerName);
+ _distControllers[i].syncStart();
}
verifyClusters();
@@ -134,36 +118,22 @@ public class TestAddClusterV2 extends ZkIntegrationTestBase {
* 3) disconnect leader/disconnect participant
*/
String leader = getCurrentLeader(_gZkClient, CONTROLLER_CLUSTER);
- // pauseController(_startCMResultMap.get(leader)._manager.getDataAccessor());
-
- StartCMResult result;
-
- Iterator<Entry<String, StartCMResult>> it = _startCMResultMap.entrySet().iterator();
-
- while (it.hasNext()) {
- String instanceName = it.next().getKey();
- if (!instanceName.equals(leader) && instanceName.startsWith(CONTROLLER_PREFIX)) {
- result = _startCMResultMap.get(instanceName);
- result._manager.disconnect();
- result._thread.interrupt();
- it.remove();
+ int leaderIdx = -1;
+ for (int i = 0; i < NODE_NR; i++) {
+ if (!_distControllers[i].getInstanceName().equals(leader)) {
+ _distControllers[i].syncStop();
+ verifyClusters();
+ } else {
+ leaderIdx = i;
}
- verifyClusters();
}
+ Assert.assertNotSame(leaderIdx, -1);
- result = _startCMResultMap.remove(leader);
- result._manager.disconnect();
- result._thread.interrupt();
-
- it = _startCMResultMap.entrySet().iterator();
- while (it.hasNext()) {
- String instanceName = it.next().getKey();
- result = _startCMResultMap.get(instanceName);
- result._manager.disconnect();
- result._thread.interrupt();
- it.remove();
- }
+ _distControllers[leaderIdx].syncStop();
+ for (int i = 0; i < NODE_NR; i++) {
+ _participants[i].syncStop();
+ }
System.out.println("END " + CLASS_NAME + " at " + new Date(System.currentTimeMillis()));
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestAddNodeAfterControllerStart.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestAddNodeAfterControllerStart.java b/helix-core/src/test/java/org/apache/helix/integration/TestAddNodeAfterControllerStart.java
index b135d92..79d8b89 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestAddNodeAfterControllerStart.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestAddNodeAfterControllerStart.java
@@ -21,18 +21,15 @@ package org.apache.helix.integration;
import java.util.Date;
import java.util.List;
-import java.util.Set;
-import org.apache.helix.InstanceType;
import org.apache.helix.PropertyPathConfig;
import org.apache.helix.PropertyType;
import org.apache.helix.TestHelper;
-import org.apache.helix.ZkHelixTestManager;
import org.apache.helix.ZkTestHelper;
-import org.apache.helix.controller.HelixControllerMain;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.ClusterDistributedController;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.CallbackHandler;
-import org.apache.helix.manager.zk.ZKHelixManager;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.tools.ClusterStateVerifier;
import org.apache.log4j.Logger;
import org.testng.Assert;
@@ -52,16 +49,17 @@ public class TestAddNodeAfterControllerStart extends ZkIntegrationTestBase {
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, "localhost", "TestDB", 1, 20, nodeNr - 1,
3, "MasterSlave", true);
- MockParticipant[] participants = new MockParticipant[nodeNr];
+ MockParticipantManager[] participants = new MockParticipantManager[nodeNr];
for (int i = 0; i < nodeNr - 1; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR);
- new Thread(participants[i]).start();
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participants[i].syncStart();
}
- ZkHelixTestManager controller =
- new ZkHelixTestManager(clusterName, "controller_0", InstanceType.CONTROLLER, ZK_ADDR);
- controller.connect();
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+ controller.syncStart();
+
boolean result;
result =
ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
@@ -75,7 +73,7 @@ public class TestAddNodeAfterControllerStart extends ZkIntegrationTestBase {
_gSetupTool.addInstanceToCluster(clusterName, "localhost_12922");
_gSetupTool.rebalanceStorageCluster(clusterName, "TestDB0", 3);
- participants[nodeNr - 1] = new MockParticipant(clusterName, "localhost_12922", ZK_ADDR);
+ participants[nodeNr - 1] = new MockParticipantManager(ZK_ADDR, clusterName, "localhost_12922");
new Thread(participants[nodeNr - 1]).start();
result =
ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
@@ -86,11 +84,10 @@ public class TestAddNodeAfterControllerStart extends ZkIntegrationTestBase {
Assert.assertTrue(result);
// clean up
- // controller.disconnect();
- // for (int i = 0; i < nodeNr; i++)
- // {
- // participants[i].syncStop();
- // }
+ controller.syncStop();
+ for (int i = 0; i < nodeNr; i++) {
+ participants[i].syncStop();
+ }
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
@@ -101,11 +98,13 @@ public class TestAddNodeAfterControllerStart extends ZkIntegrationTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
// setup grand cluster
- TestHelper.setupCluster("GRAND_" + clusterName, ZK_ADDR, 0, "controller", null, 0, 0, 1, 0,
+ final String grandClusterName = "GRAND_" + clusterName;
+ TestHelper.setupCluster(grandClusterName, ZK_ADDR, 0, "controller", null, 0, 0, 1, 0,
null, true);
- TestHelper.startController("GRAND_" + clusterName, "controller_0", ZK_ADDR,
- HelixControllerMain.DISTRIBUTED);
+ ClusterDistributedController distController =
+ new ClusterDistributedController(ZK_ADDR, grandClusterName, "controller_0");
+ distController.syncStart();
// setup cluster
_gSetupTool.addCluster(clusterName, true);
@@ -127,12 +126,11 @@ public class TestAddNodeAfterControllerStart extends ZkIntegrationTestBase {
_gSetupTool.addResourceToCluster(clusterName, "TestDB0", 1, "LeaderStandby");
_gSetupTool.rebalanceStorageCluster(clusterName, "TestDB0", 1);
- MockParticipant[] participants = new MockParticipant[nodeNr];
+ MockParticipantManager[] participants = new MockParticipantManager[nodeNr];
for (int i = 0; i < nodeNr - 1; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
- // new Thread(participants[i]).start();
}
result =
@@ -150,10 +148,8 @@ public class TestAddNodeAfterControllerStart extends ZkIntegrationTestBase {
_gSetupTool.addInstanceToCluster(clusterName, "localhost_12919");
_gSetupTool.rebalanceStorageCluster(clusterName, "TestDB0", 2);
- participants[nodeNr - 1] = new MockParticipant(clusterName, "localhost_12919", ZK_ADDR);
+ participants[nodeNr - 1] = new MockParticipantManager(ZK_ADDR, clusterName, "localhost_12919");
participants[nodeNr - 1].syncStart();
- // new Thread(participants[nodeNr - 1]).start();
-
result =
ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
ZK_ADDR, clusterName));
@@ -165,10 +161,10 @@ public class TestAddNodeAfterControllerStart extends ZkIntegrationTestBase {
Assert.assertEquals(numberOfListeners, 2); // 1 of participant, and 1 of controller
// clean up
- // for (int i = 0; i < nodeNr; i++)
- // {
- // participants[i].syncStop();
- // }
+ distController.syncStop();
+ for (int i = 0; i < nodeNr; i++) {
+ participants[i].syncStop();
+ }
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestAddStateModelFactoryAfterConnect.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestAddStateModelFactoryAfterConnect.java b/helix-core/src/test/java/org/apache/helix/integration/TestAddStateModelFactoryAfterConnect.java
index 33938ad..cd888d7 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestAddStateModelFactoryAfterConnect.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestAddStateModelFactoryAfterConnect.java
@@ -19,20 +19,17 @@ package org.apache.helix.integration;
* under the License.
*/
-import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.PropertyKey.Builder;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.mock.controller.ClusterController;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.mock.participant.MockMSModelFactory;
-import org.apache.helix.model.CurrentState;
-import org.apache.helix.model.ExternalView;
import org.apache.helix.model.IdealState;
import org.apache.helix.model.Message;
import org.apache.helix.tools.ClusterSetup;
@@ -52,7 +49,7 @@ public class TestAddStateModelFactoryAfterConnect extends ZkIntegrationTestBase
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
"localhost", // participant name prefix
@@ -63,14 +60,15 @@ public class TestAddStateModelFactoryAfterConnect extends ZkIntegrationTestBase
3, // replicas
"MasterSlave", true); // do rebalance
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
@@ -116,7 +114,7 @@ public class TestAddStateModelFactoryAfterConnect extends ZkIntegrationTestBase
// register "TestDB1_Factory" state model factory
// Logger.getRootLogger().setLevel(Level.INFO);
for (int i = 0; i < n; i++) {
- participants[i].getManager().getStateMachineEngine()
+ participants[i].getStateMachineEngine()
.registerStateModelFactory("MasterSlave", new MockMSModelFactory(), "TestDB1_Factory");
}
@@ -127,7 +125,6 @@ public class TestAddStateModelFactoryAfterConnect extends ZkIntegrationTestBase
// clean up
// wait for all zk callbacks done
- Thread.sleep(1000);
controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestAutoIsWithEmptyMap.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestAutoIsWithEmptyMap.java b/helix-core/src/test/java/org/apache/helix/integration/TestAutoIsWithEmptyMap.java
index 1ffb86f..bc1c1b0 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestAutoIsWithEmptyMap.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestAutoIsWithEmptyMap.java
@@ -27,8 +27,8 @@ import org.apache.helix.PropertyPathConfig;
import org.apache.helix.PropertyType;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
-import org.apache.helix.controller.HelixControllerMain;
-import org.apache.helix.mock.participant.MockParticipant;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.model.IdealState;
import org.apache.helix.tools.ClusterStateVerifier;
import org.apache.helix.tools.DefaultIdealStateCalculator;
@@ -74,15 +74,16 @@ public class TestAutoIsWithEmptyMap extends ZkIntegrationTestBase {
_gZkClient.writeData(idealPath, curIdealState);
// start controller
- TestHelper
- .startController(clusterName, "controller_0", ZK_ADDR, HelixControllerMain.STANDALONE);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+ controller.syncStart();
// start participants
- MockParticipant[] participants = new MockParticipant[5];
+ MockParticipantManager[] participants = new MockParticipantManager[5];
for (int i = 0; i < 5; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
@@ -92,6 +93,7 @@ public class TestAutoIsWithEmptyMap extends ZkIntegrationTestBase {
Assert.assertTrue(result);
// clean up
+ controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestAutoRebalance.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestAutoRebalance.java b/helix-core/src/test/java/org/apache/helix/integration/TestAutoRebalance.java
index 1943364..b4f9223 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestAutoRebalance.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestAutoRebalance.java
@@ -29,11 +29,10 @@ import org.apache.helix.HelixDataAccessor;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.TestHelper.StartCMResult;
-import org.apache.helix.controller.HelixControllerMain;
import org.apache.helix.controller.stages.ClusterDataCache;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
-import org.apache.helix.manager.zk.ZNRecordSerializer;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
import org.apache.helix.manager.zk.ZkClient;
import org.apache.helix.model.ExternalView;
@@ -51,18 +50,17 @@ public class TestAutoRebalance extends ZkStandAloneCMTestBaseWithPropertyServerC
String db2 = TEST_DB + "2";
String _tag = "SSDSSD";
+ @Override
@BeforeClass
public void beforeClass() throws Exception {
// Logger.getRootLogger().setLevel(Level.INFO);
System.out.println("START " + CLASS_NAME + " at " + new Date(System.currentTimeMillis()));
- _zkClient = new ZkClient(ZK_ADDR);
- _zkClient.setZkSerializer(new ZNRecordSerializer());
String namespace = "/" + CLUSTER_NAME;
- if (_zkClient.exists(namespace)) {
- _zkClient.deleteRecursive(namespace);
+ if (_gZkClient.exists(namespace)) {
+ _gZkClient.deleteRecursive(namespace);
}
- _setupTool = new ClusterSetup(ZK_ADDR);
+ _setupTool = new ClusterSetup(_gZkClient);
// setup storage cluster
_setupTool.addCluster(CLUSTER_NAME, true);
@@ -89,24 +87,21 @@ public class TestAutoRebalance extends ZkStandAloneCMTestBaseWithPropertyServerC
// start dummy participants
for (int i = 0; i < NODE_NR; i++) {
String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
- if (_startCMResultMap.get(instanceName) != null) {
- LOG.error("fail to start particpant:" + instanceName
- + "(participant with same name already exists)");
- } else {
- StartCMResult result = TestHelper.startDummyProcess(ZK_ADDR, CLUSTER_NAME, instanceName);
- _startCMResultMap.put(instanceName, result);
- }
+ MockParticipantManager participant =
+ new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
+ participant.syncStart();
+ _participants[i] = participant;
+
}
// start controller
String controllerName = CONTROLLER_PREFIX + "_0";
- StartCMResult startResult =
- TestHelper.startController(CLUSTER_NAME, controllerName, ZK_ADDR,
- HelixControllerMain.STANDALONE);
- _startCMResultMap.put(controllerName, startResult);
+ _controller =
+ new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
+ _controller.syncStart();
boolean result =
- ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_zkClient,
+ ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_gZkClient,
CLUSTER_NAME, TEST_DB));
Assert.assertTrue(result);
@@ -122,7 +117,7 @@ public class TestAutoRebalance extends ZkStandAloneCMTestBaseWithPropertyServerC
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, "MyDB", 1);
boolean result =
- ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_zkClient,
+ ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_gZkClient,
CLUSTER_NAME, "MyDB"));
Assert.assertTrue(result);
@@ -140,7 +135,7 @@ public class TestAutoRebalance extends ZkStandAloneCMTestBaseWithPropertyServerC
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, "MyDB2", 3);
result =
- ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_zkClient,
+ ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_gZkClient,
CLUSTER_NAME, "MyDB2"));
Assert.assertTrue(result);
@@ -154,16 +149,11 @@ public class TestAutoRebalance extends ZkStandAloneCMTestBaseWithPropertyServerC
@Test()
public void testAutoRebalance() throws Exception {
-
// kill 1 node
- String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + 0);
- _startCMResultMap.get(instanceName)._manager.disconnect();
- Thread.currentThread().sleep(1000);
- _startCMResultMap.get(instanceName)._thread.interrupt();
+ _participants[0].syncStop();
- // verifyBalanceExternalView();
boolean result =
- ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_zkClient,
+ ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_gZkClient,
CLUSTER_NAME, TEST_DB));
Assert.assertTrue(result);
@@ -172,22 +162,22 @@ public class TestAutoRebalance extends ZkStandAloneCMTestBaseWithPropertyServerC
String storageNodeName = PARTICIPANT_PREFIX + "_" + (1000 + i);
_setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
- StartCMResult resultx =
- TestHelper.startDummyProcess(ZK_ADDR, CLUSTER_NAME, storageNodeName.replace(':', '_'));
- _startCMResultMap.put(storageNodeName, resultx);
+ MockParticipantManager participant =
+ new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, storageNodeName.replace(':', '_'));
+ participant.syncStart();
}
Thread.sleep(1000);
result =
- ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_zkClient,
+ ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_gZkClient,
CLUSTER_NAME, TEST_DB));
Assert.assertTrue(result);
result =
- ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_zkClient,
+ ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_gZkClient,
CLUSTER_NAME, db2));
Assert.assertTrue(result);
HelixDataAccessor accessor =
- new ZKHelixDataAccessor(CLUSTER_NAME, new ZkBaseDataAccessor(_zkClient));
+ new ZKHelixDataAccessor(CLUSTER_NAME, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
ExternalView ev = accessor.getProperty(keyBuilder.externalView(db2));
Set<String> instancesSet = new HashSet<String>();
@@ -242,12 +232,10 @@ public class TestAutoRebalance extends ZkStandAloneCMTestBaseWithPropertyServerC
}
public static class ExternalViewBalancedVerifier implements ZkVerifier {
- ZkClient _client;
String _clusterName;
String _resourceName;
public ExternalViewBalancedVerifier(ZkClient client, String clusterName, String resourceName) {
- _client = client;
_clusterName = clusterName;
_resourceName = resourceName;
}
@@ -255,7 +243,7 @@ public class TestAutoRebalance extends ZkStandAloneCMTestBaseWithPropertyServerC
@Override
public boolean verify() {
HelixDataAccessor accessor =
- new ZKHelixDataAccessor(_clusterName, new ZkBaseDataAccessor(_client));
+ new ZKHelixDataAccessor(_clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
int numberOfPartitions =
accessor.getProperty(keyBuilder.idealStates(_resourceName)).getRecord().getListFields()
@@ -286,7 +274,7 @@ public class TestAutoRebalance extends ZkStandAloneCMTestBaseWithPropertyServerC
@Override
public ZkClient getZkClient() {
- return _client;
+ return _gZkClient;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestAutoRebalancePartitionLimit.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestAutoRebalancePartitionLimit.java b/helix-core/src/test/java/org/apache/helix/integration/TestAutoRebalancePartitionLimit.java
index 32cafcf..74a5699 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestAutoRebalancePartitionLimit.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestAutoRebalancePartitionLimit.java
@@ -25,14 +25,12 @@ import java.util.Map;
import org.apache.helix.HelixDataAccessor;
import org.apache.helix.HelixManager;
-import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.TestHelper.StartCMResult;
-import org.apache.helix.controller.HelixControllerMain;
import org.apache.helix.controller.stages.ClusterDataCache;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
-import org.apache.helix.manager.zk.ZNRecordSerializer;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
import org.apache.helix.manager.zk.ZkClient;
import org.apache.helix.model.ExternalView;
@@ -49,16 +47,15 @@ public class TestAutoRebalancePartitionLimit extends ZkStandAloneCMTestBaseWithP
private static final Logger LOG = Logger.getLogger(TestAutoRebalancePartitionLimit.class
.getName());
+ @Override
@BeforeClass
public void beforeClass() throws Exception {
// Logger.getRootLogger().setLevel(Level.INFO);
System.out.println("START " + CLASS_NAME + " at " + new Date(System.currentTimeMillis()));
- _zkClient = new ZkClient(ZK_ADDR);
- _zkClient.setZkSerializer(new ZNRecordSerializer());
String namespace = "/" + CLUSTER_NAME;
- if (_zkClient.exists(namespace)) {
- _zkClient.deleteRecursive(namespace);
+ if (_gZkClient.exists(namespace)) {
+ _gZkClient.deleteRecursive(namespace);
}
_setupTool = new ClusterSetup(ZK_ADDR);
@@ -75,40 +72,33 @@ public class TestAutoRebalancePartitionLimit extends ZkStandAloneCMTestBaseWithP
// start controller
String controllerName = CONTROLLER_PREFIX + "_0";
- StartCMResult startResult =
- TestHelper.startController(CLUSTER_NAME, controllerName, ZK_ADDR,
- HelixControllerMain.STANDALONE);
- _startCMResultMap.put(controllerName, startResult);
+ _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
+ _controller.syncStart();
- HelixManager manager = _startCMResultMap.get(controllerName)._manager;
+ HelixManager manager = _controller; // _startCMResultMap.get(controllerName)._manager;
HelixDataAccessor accessor = manager.getHelixDataAccessor();
// start dummy participants
for (int i = 0; i < NODE_NR; i++) {
String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
- if (_startCMResultMap.get(instanceName) != null) {
- LOG.error("fail to start particpant:" + instanceName
- + "(participant with same name already exists)");
+ _participants[i] = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, instanceName);
+ _participants[i].syncStart();
+ Thread.sleep(2000);
+ boolean result =
+ ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_gZkClient,
+ CLUSTER_NAME, TEST_DB));
+ Assert.assertTrue(result);
+ ExternalView ev =
+ manager.getHelixDataAccessor().getProperty(accessor.keyBuilder().externalView(TEST_DB));
+ System.out.println(ev.getPartitionSet().size());
+ if (i < 3) {
+ Assert.assertEquals(ev.getPartitionSet().size(), 25 * (i + 1));
} else {
- startResult = TestHelper.startDummyProcess(ZK_ADDR, CLUSTER_NAME, instanceName);
- _startCMResultMap.put(instanceName, startResult);
- Thread.sleep(2000);
- boolean result =
- ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_zkClient,
- CLUSTER_NAME, TEST_DB));
- Assert.assertTrue(result);
- ExternalView ev =
- manager.getHelixDataAccessor().getProperty(accessor.keyBuilder().externalView(TEST_DB));
- System.out.println(ev.getPartitionSet().size());
- if (i < 3) {
- Assert.assertEquals(ev.getPartitionSet().size(), 25 * (i + 1));
- } else {
- Assert.assertEquals(ev.getPartitionSet().size(), 100);
- }
+ Assert.assertEquals(ev.getPartitionSet().size(), 100);
}
}
boolean result =
- ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_zkClient,
+ ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_gZkClient,
CLUSTER_NAME, TEST_DB));
Assert.assertTrue(result);
@@ -116,17 +106,13 @@ public class TestAutoRebalancePartitionLimit extends ZkStandAloneCMTestBaseWithP
@Test()
public void testAutoRebalanceWithMaxPartitionPerNode() throws Exception {
- String controllerName = CONTROLLER_PREFIX + "_0";
- HelixManager manager = _startCMResultMap.get(controllerName)._manager;
+ HelixManager manager = _controller;
// kill 1 node
- String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + 0);
- _startCMResultMap.get(instanceName)._manager.disconnect();
- Thread.currentThread().sleep(1000);
- _startCMResultMap.get(instanceName)._thread.interrupt();
+ _participants[0].syncStop();
// verifyBalanceExternalView();
boolean result =
- ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_zkClient,
+ ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_gZkClient,
CLUSTER_NAME, TEST_DB));
Assert.assertTrue(result);
HelixDataAccessor accessor = manager.getHelixDataAccessor();
@@ -134,14 +120,11 @@ public class TestAutoRebalancePartitionLimit extends ZkStandAloneCMTestBaseWithP
manager.getHelixDataAccessor().getProperty(accessor.keyBuilder().externalView(TEST_DB));
Assert.assertEquals(ev.getPartitionSet().size(), 100);
- instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + 1);
- _startCMResultMap.get(instanceName)._manager.disconnect();
- Thread.currentThread().sleep(1000);
- _startCMResultMap.get(instanceName)._thread.interrupt();
+ _participants[1].syncStop();
// verifyBalanceExternalView();
result =
- ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_zkClient,
+ ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_gZkClient,
CLUSTER_NAME, TEST_DB));
Assert.assertTrue(result);
ev = manager.getHelixDataAccessor().getProperty(accessor.keyBuilder().externalView(TEST_DB));
@@ -152,13 +135,15 @@ public class TestAutoRebalancePartitionLimit extends ZkStandAloneCMTestBaseWithP
String storageNodeName = PARTICIPANT_PREFIX + "_" + (1000 + i);
_setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
- StartCMResult resultx =
- TestHelper.startDummyProcess(ZK_ADDR, CLUSTER_NAME, storageNodeName.replace(':', '_'));
- _startCMResultMap.put(storageNodeName, resultx);
+ String newInstanceName = storageNodeName.replace(':', '_');
+ MockParticipantManager participant =
+ new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, newInstanceName);
+ participant.syncStart();
}
+
Thread.sleep(1000);
result =
- ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_zkClient,
+ ClusterStateVerifier.verifyByZkCallback(new ExternalViewBalancedVerifier(_gZkClient,
CLUSTER_NAME, TEST_DB));
Assert.assertTrue(result);
}
@@ -209,12 +194,10 @@ public class TestAutoRebalancePartitionLimit extends ZkStandAloneCMTestBaseWithP
}
public static class ExternalViewBalancedVerifier implements ZkVerifier {
- ZkClient _client;
String _clusterName;
String _resourceName;
public ExternalViewBalancedVerifier(ZkClient client, String clusterName, String resourceName) {
- _client = client;
_clusterName = clusterName;
_resourceName = resourceName;
}
@@ -222,7 +205,7 @@ public class TestAutoRebalancePartitionLimit extends ZkStandAloneCMTestBaseWithP
@Override
public boolean verify() {
HelixDataAccessor accessor =
- new ZKHelixDataAccessor(_clusterName, new ZkBaseDataAccessor(_client));
+ new ZKHelixDataAccessor(_clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
int numberOfPartitions =
accessor.getProperty(keyBuilder.idealStates(_resourceName)).getRecord().getListFields()
@@ -240,7 +223,7 @@ public class TestAutoRebalancePartitionLimit extends ZkStandAloneCMTestBaseWithP
@Override
public ZkClient getZkClient() {
- return _client;
+ return _gZkClient;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestBatchMessage.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestBatchMessage.java b/helix-core/src/test/java/org/apache/helix/integration/TestBatchMessage.java
index bf2de1e..03fc85b 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestBatchMessage.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestBatchMessage.java
@@ -30,13 +30,10 @@ import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.HelixProperty.HelixPropertyAttribute;
import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.ZkTestHelper;
-import org.apache.helix.controller.HelixControllerMain;
-import org.apache.helix.manager.zk.ZKHelixAdmin;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.mock.controller.ClusterController;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.mock.participant.ErrTransition;
import org.apache.helix.model.IdealState;
import org.apache.helix.model.LiveInstance;
@@ -91,15 +88,16 @@ public class TestBatchMessage extends ZkIntegrationTestBase {
TestZkChildListener listener = new TestZkChildListener();
_gZkClient.subscribeChildChanges(keyBuilder.messages("localhost_12918").getPath(), listener);
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
@@ -112,7 +110,6 @@ public class TestBatchMessage extends ZkIntegrationTestBase {
// clean up
// wait for all zk callbacks done
- Thread.sleep(1000);
controller.syncStop();
for (int i = 0; i < n; i++) {
participants[i].syncStop();
@@ -141,15 +138,16 @@ public class TestBatchMessage extends ZkIntegrationTestBase {
2, // replicas
"MasterSlave", true); // do rebalance
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
@@ -159,7 +157,6 @@ public class TestBatchMessage extends ZkIntegrationTestBase {
Assert.assertTrue(result);
// stop all participants
- Thread.sleep(1000);
for (int i = 0; i < n; i++) {
participants[i].syncStop();
}
@@ -180,7 +177,7 @@ public class TestBatchMessage extends ZkIntegrationTestBase {
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
@@ -193,7 +190,6 @@ public class TestBatchMessage extends ZkIntegrationTestBase {
// clean up
// wait for all zk callbacks done
- Thread.sleep(1000);
controller.syncStop();
for (int i = 0; i < n; i++) {
participants[i].syncStop();
@@ -209,10 +205,9 @@ public class TestBatchMessage extends ZkIntegrationTestBase {
String clusterName = className + "_" + methodName;
final int n = 5;
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
- // ZKHelixAdmin tool = new ZKHelixAdmin(_gZkClient);
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, "localhost", "TestDB", 1, // resource#
6, // partition#
@@ -228,19 +223,20 @@ public class TestBatchMessage extends ZkIntegrationTestBase {
idealState.setBatchMessageMode(true);
accessor.setProperty(keyBuilder.idealStates("TestDB0"), idealState);
- TestHelper
- .startController(clusterName, "controller_0", ZK_ADDR, HelixControllerMain.STANDALONE);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+ controller.syncStart();
+
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
if (i == 1) {
Map<String, Set<String>> errPartitions = new HashMap<String, Set<String>>();
errPartitions.put("SLAVE-MASTER", TestHelper.setOf("TestDB0_4"));
- participants[i] =
- new MockParticipant(clusterName, instanceName, ZK_ADDR,
- new ErrTransition(errPartitions));
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participants[i].setTransition(new ErrTransition(errPartitions));
} else {
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
}
participants[i].syncStart();
}
@@ -297,7 +293,8 @@ public class TestBatchMessage extends ZkIntegrationTestBase {
TestZkChildListener listener = new TestZkChildListener();
_gZkClient.subscribeChildChanges(keyBuilder.messages("localhost_12918").getPath(), listener);
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// pause controller
@@ -307,11 +304,11 @@ public class TestBatchMessage extends ZkIntegrationTestBase {
});
// start participants
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
@@ -335,7 +332,6 @@ public class TestBatchMessage extends ZkIntegrationTestBase {
// clean up
// wait for all zk callbacks done
- Thread.sleep(1000);
controller.syncStop();
for (int i = 0; i < n; i++) {
participants[i].syncStop();
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestBatchMessageWrapper.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestBatchMessageWrapper.java b/helix-core/src/test/java/org/apache/helix/integration/TestBatchMessageWrapper.java
index 2ae8bf3..9bfdfb5 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestBatchMessageWrapper.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestBatchMessageWrapper.java
@@ -26,12 +26,12 @@ import org.apache.helix.PropertyKey.Builder;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.ZkUnitTestBase;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
import org.apache.helix.messaging.handling.BatchMessageWrapper;
-import org.apache.helix.mock.controller.ClusterController;
import org.apache.helix.mock.participant.MockMSModelFactory;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.model.IdealState;
import org.apache.helix.model.Message;
import org.apache.helix.tools.ClusterStateVerifier;
@@ -90,17 +90,19 @@ public class TestBatchMessageWrapper extends ZkUnitTestBase {
idealState.setBatchMessageMode(true);
accessor.setProperty(keyBuilder.idealStates("TestDB0"), idealState);
- ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// start participants
- MockParticipant[] participants = new MockParticipant[n];
+ MockParticipantManager[] participants = new MockParticipantManager[n];
TestMockMSModelFactory[] ftys = new TestMockMSModelFactory[n];
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
ftys[i] = new TestMockMSModelFactory();
- participants[i] = new MockParticipant(ftys[i], clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participants[i].getStateMachineEngine().registerStateModelFactory("MasterSlave", ftys[i]);
participants[i].syncStart();
// wait for each participant to complete state transitions, so we have deterministic results
@@ -133,6 +135,12 @@ public class TestBatchMessageWrapper extends ZkUnitTestBase {
Assert.assertEquals(wrapper._startCount, 2,
"Expect 2 batch.end: O->S and S->M for 2nd participant");
+ // clean up
+ controller.syncStop();
+ for (int i = 0; i < n; i++) {
+ participants[i].syncStop();
+ }
+
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/integration/TestBucketizedResource.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestBucketizedResource.java b/helix-core/src/test/java/org/apache/helix/integration/TestBucketizedResource.java
index 8e75537..207a318 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestBucketizedResource.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestBucketizedResource.java
@@ -24,10 +24,10 @@ import java.util.Date;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.controller.HelixControllerMain;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.model.IdealState;
import org.apache.helix.tools.ClusterStateVerifier;
import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier;
@@ -45,7 +45,7 @@ public class TestBucketizedResource extends ZkIntegrationTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
- MockParticipant[] participants = new MockParticipant[5];
+ MockParticipantManager[] participants = new MockParticipantManager[5];
// ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
@@ -66,13 +66,15 @@ public class TestBucketizedResource extends ZkIntegrationTestBase {
idealState.setBucketSize(1);
accessor.setProperty(keyBuilder.idealStates("TestDB0"), idealState);
- TestHelper
- .startController(clusterName, "controller_0", ZK_ADDR, HelixControllerMain.STANDALONE);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+ controller.syncStart();
+
// start participants
for (int i = 0; i < 5; i++) {
String instanceName = "localhost_" + (12918 + i);
- participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
@@ -87,6 +89,7 @@ public class TestBucketizedResource extends ZkIntegrationTestBase {
Assert.assertTrue(result);
// clean up
+ controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
}
[06/10] [HELIX-279] Apply gc handling fixes to main ZKHelixManager
class
Posted by zz...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java
index 621c18b..c54c901 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java
@@ -19,32 +19,29 @@ package org.apache.helix.manager.zk;
* under the License.
*/
-import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.LinkedList;
import java.util.List;
import java.util.Timer;
import java.util.concurrent.TimeUnit;
+import org.I0Itec.zkclient.IZkStateListener;
import org.I0Itec.zkclient.ZkConnection;
import org.apache.helix.BaseDataAccessor;
import org.apache.helix.ClusterMessagingService;
import org.apache.helix.ConfigAccessor;
import org.apache.helix.ConfigChangeListener;
-import org.apache.helix.AccessOption;
import org.apache.helix.ControllerChangeListener;
import org.apache.helix.CurrentStateChangeListener;
import org.apache.helix.ExternalViewChangeListener;
import org.apache.helix.HealthStateChangeListener;
import org.apache.helix.HelixAdmin;
-import org.apache.helix.HelixConstants.ChangeType;
import org.apache.helix.HelixDataAccessor;
import org.apache.helix.HelixException;
import org.apache.helix.HelixManager;
import org.apache.helix.HelixTimerTask;
+import org.apache.helix.HelixConstants.ChangeType;
import org.apache.helix.IdealStateChangeListener;
import org.apache.helix.InstanceConfigChangeListener;
import org.apache.helix.InstanceType;
@@ -59,143 +56,222 @@ import org.apache.helix.PropertyPathConfig;
import org.apache.helix.PropertyType;
import org.apache.helix.ScopedConfigChangeListener;
import org.apache.helix.ZNRecord;
-import org.apache.helix.controller.restlet.ZKPropertyTransferServer;
+import org.apache.helix.controller.GenericHelixController;
import org.apache.helix.healthcheck.HealthStatsAggregationTask;
import org.apache.helix.healthcheck.HealthStatsAggregator;
import org.apache.helix.healthcheck.ParticipantHealthReportCollector;
import org.apache.helix.healthcheck.ParticipantHealthReportCollectorImpl;
import org.apache.helix.healthcheck.ParticipantHealthReportTask;
import org.apache.helix.messaging.DefaultMessagingService;
-import org.apache.helix.messaging.handling.MessageHandlerFactory;
import org.apache.helix.model.ConfigScope;
-import org.apache.helix.model.CurrentState;
-import org.apache.helix.model.HelixConfigScope;
import org.apache.helix.model.HelixConfigScope.ConfigScopeProperty;
-import org.apache.helix.model.InstanceConfig;
import org.apache.helix.model.LiveInstance;
-import org.apache.helix.model.Message.MessageType;
import org.apache.helix.model.builder.ConfigScopeBuilder;
-import org.apache.helix.model.builder.HelixConfigScopeBuilder;
-import org.apache.helix.model.StateModelDefinition;
import org.apache.helix.monitoring.ZKPathDataDumpTask;
-import org.apache.helix.participant.DistClusterControllerElection;
import org.apache.helix.participant.HelixStateMachineEngine;
import org.apache.helix.participant.StateMachineEngine;
-import org.apache.helix.participant.statemachine.ScheduledTaskStateModelFactory;
import org.apache.helix.store.zk.ZkHelixPropertyStore;
import org.apache.log4j.Logger;
-import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.Watcher.Event.KeeperState;
+import org.apache.zookeeper.Watcher.Event.EventType;
+import org.apache.zookeeper.ZooKeeper.States;
+
+public class ZKHelixManager implements HelixManager, IZkStateListener {
+ private static Logger LOG = Logger.getLogger(ZKHelixManager.class);
+
+ public static final int FLAPPING_TIME_WINDIOW = 300000; // Default to 300 sec
+ public static final int MAX_DISCONNECT_THRESHOLD = 5;
+ public static final String ALLOW_PARTICIPANT_AUTO_JOIN = "allowParticipantAutoJoin";
-public class ZKHelixManager implements HelixManager {
- private static Logger logger = Logger.getLogger(ZKHelixManager.class);
- private static final int RETRY_LIMIT = 3;
- private static final int CONNECTIONTIMEOUT = 60 * 1000;
+ protected final String _zkAddress;
private final String _clusterName;
private final String _instanceName;
- private final String _zkConnectString;
- private static final int DEFAULT_SESSION_TIMEOUT = 30 * 1000;
- private ZKHelixDataAccessor _helixAccessor;
- private ConfigAccessor _configAccessor;
- protected ZkClient _zkClient;
- protected final List<CallbackHandler> _handlers = new ArrayList<CallbackHandler>();
- private final ZkStateChangeListener _zkStateChangeListener;
private final InstanceType _instanceType;
- volatile String _sessionId;
- private Timer _timer;
- private CallbackHandler _leaderElectionHandler;
- private ParticipantHealthReportCollectorImpl _participantHealthCheckInfoCollector;
- private ParticipantHealthReportTask _participantHealthReportTask;
- private final DefaultMessagingService _messagingService;
- private ZKHelixAdmin _managementTool;
- private final String _version;
+ private final int _sessionTimeout;
+ private final List<PreConnectCallback> _preConnectCallbacks;
+ protected final List<CallbackHandler> _handlers;
private final HelixManagerProperties _properties;
- private final StateMachineEngine _stateMachEngine;
- private int _sessionTimeout;
- private ZkHelixPropertyStore<ZNRecord> _helixPropertyStore;
- private final List<HelixTimerTask> _controllerTimerTasks;
+
+ /**
+ * helix version#
+ */
+ private final String _version;
+
+ protected ZkClient _zkclient = null;
+ private final DefaultMessagingService _messagingService;
+
private BaseDataAccessor<ZNRecord> _baseDataAccessor;
- List<PreConnectCallback> _preConnectCallbacks = new LinkedList<PreConnectCallback>();
- ZKPropertyTransferServer _transferServer = null;
- int _flappingTimeWindowMs;
- int _maxDisconnectThreshold;
- public static final int FLAPPING_TIME_WINDIOW = 300000; // Default to 300 sec
- public static final int MAX_DISCONNECT_THRESHOLD = 5;
- LiveInstanceInfoProvider _liveInstanceInfoProvider = null;
- public static final String ALLOW_PARTICIPANT_AUTO_JOIN = "allowParticipantAutoJoin";
+ private ZKHelixDataAccessor _dataAccessor;
+ private final Builder _keyBuilder;
+ private ConfigAccessor _configAccessor;
+ private ZkHelixPropertyStore<ZNRecord> _helixPropertyStore;
+ protected LiveInstanceInfoProvider _liveInstanceInfoProvider = null;
- public ZKHelixManager(String clusterName, String instanceName, InstanceType instanceType,
- String zkConnectString) {
- logger.info("Create a zk-based cluster manager. clusterName:" + clusterName + ", instanceName:"
- + instanceName + ", type:" + instanceType + ", zkSvr:" + zkConnectString);
- _flappingTimeWindowMs = FLAPPING_TIME_WINDIOW;
- try {
- _flappingTimeWindowMs =
- Integer.parseInt(System.getProperty("helixmanager.flappingTimeWindow", ""
- + FLAPPING_TIME_WINDIOW));
- } catch (NumberFormatException e) {
- logger.warn("Exception while parsing helixmanager.flappingTimeWindow: "
- + System.getProperty("helixmanager.flappingTimeWindow", "" + FLAPPING_TIME_WINDIOW));
- }
- _maxDisconnectThreshold = MAX_DISCONNECT_THRESHOLD;
- try {
- _maxDisconnectThreshold =
- Integer.parseInt(System.getProperty("helixmanager.maxDisconnectThreshold", ""
- + MAX_DISCONNECT_THRESHOLD));
- } catch (NumberFormatException e) {
- logger.warn("Exception while parsing helixmanager.maxDisconnectThreshold: "
- + System
- .getProperty("helixmanager.maxDisconnectThreshold", "" + MAX_DISCONNECT_THRESHOLD));
- }
- int sessionTimeoutInt = -1;
- try {
- sessionTimeoutInt =
- Integer.parseInt(System.getProperty("zk.session.timeout", "" + DEFAULT_SESSION_TIMEOUT));
- } catch (NumberFormatException e) {
- logger.warn("Exception while parsing session timeout: "
- + System.getProperty("zk.session.timeout", "" + DEFAULT_SESSION_TIMEOUT));
+ private volatile String _sessionId;
+
+ /**
+ * Keep track of timestamps that zk State has become Disconnected
+ * If in a _timeWindowLengthMs window zk State has become Disconnected
+ * for more than_maxDisconnectThreshold times disconnect the zkHelixManager
+ */
+ private final List<Long> _disconnectTimeHistory = new ArrayList<Long>();
+ private final int _flappingTimeWindowMs;
+ private final int _maxDisconnectThreshold;
+
+ /**
+ * participant fields
+ */
+ private final StateMachineEngine _stateMachineEngine;
+ private final ParticipantHealthReportCollectorImpl _participantHealthInfoCollector;
+ private final List<HelixTimerTask> _timerTasks = new ArrayList<HelixTimerTask>();
+
+ /**
+ * controller fields
+ */
+ private final GenericHelixController _controller = new GenericHelixController();
+ private CallbackHandler _leaderElectionHandler = null;
+ protected final List<HelixTimerTask> _controllerTimerTasks = new ArrayList<HelixTimerTask>();
+
+ /**
+ * status dump timer-task
+ */
+ static class StatusDumpTask extends HelixTimerTask {
+ Timer _timer = null;
+ final ZkClient zkclient;
+ final HelixManager helixController;
+
+ public StatusDumpTask(ZkClient zkclient, HelixManager helixController) {
+ this.zkclient = zkclient;
+ this.helixController = helixController;
+ }
+
+ @Override
+ public void start() {
+ long initialDelay = 30 * 60 * 1000;
+ long period = 120 * 60 * 1000;
+ int timeThresholdNoChange = 180 * 60 * 1000;
+
+ if (_timer == null) {
+ LOG.info("Start StatusDumpTask");
+ _timer = new Timer("StatusDumpTimerTask", true);
+ _timer.scheduleAtFixedRate(new ZKPathDataDumpTask(helixController, zkclient,
+ timeThresholdNoChange), initialDelay, period);
+ }
}
- if (sessionTimeoutInt > 0) {
- _sessionTimeout = sessionTimeoutInt;
- } else {
- _sessionTimeout = DEFAULT_SESSION_TIMEOUT;
+
+ @Override
+ public void stop() {
+ if (_timer != null) {
+ LOG.info("Stop StatusDumpTask");
+ _timer.cancel();
+ _timer = null;
+ }
}
+ }
+
+ public ZKHelixManager(String clusterName, String instanceName, InstanceType instanceType,
+ String zkAddress) {
+
+ LOG.info("Create a zk-based cluster manager. zkSvr: " + zkAddress + ", clusterName: "
+ + clusterName + ", instanceName: " + instanceName + ", type: " + instanceType);
+
+ _zkAddress = zkAddress;
+ _clusterName = clusterName;
+ _instanceType = instanceType;
+
if (instanceName == null) {
try {
instanceName =
InetAddress.getLocalHost().getCanonicalHostName() + "-" + instanceType.toString();
} catch (UnknownHostException e) {
// can ignore it
- logger.info("Unable to get host name. Will set it to UNKNOWN, mostly ignorable", e);
+ LOG.info("Unable to get host name. Will set it to UNKNOWN, mostly ignorable", e);
instanceName = "UNKNOWN";
}
}
- _clusterName = clusterName;
_instanceName = instanceName;
- _instanceType = instanceType;
- _zkConnectString = zkConnectString;
- _zkStateChangeListener =
- new ZkStateChangeListener(this, _flappingTimeWindowMs, _maxDisconnectThreshold);
- _timer = null;
+ _preConnectCallbacks = new ArrayList<PreConnectCallback>();
+ _handlers = new ArrayList<CallbackHandler>();
+ _properties = new HelixManagerProperties("cluster-manager-version.properties");
+ _version = _properties.getVersion();
+ _keyBuilder = new Builder(clusterName);
_messagingService = new DefaultMessagingService(this);
- _properties = new HelixManagerProperties("cluster-manager-version.properties");
- _version = _properties.getVersion();
+ /**
+ * use system property if available
+ */
+ _flappingTimeWindowMs =
+ getSystemPropertyAsInt("helixmanager.flappingTimeWindow",
+ ZKHelixManager.FLAPPING_TIME_WINDIOW);
+
+ _maxDisconnectThreshold =
+ getSystemPropertyAsInt("helixmanager.maxDisconnectThreshold",
+ ZKHelixManager.MAX_DISCONNECT_THRESHOLD);
- _stateMachEngine = new HelixStateMachineEngine(this);
+ _sessionTimeout =
+ getSystemPropertyAsInt("zk.session.timeout", ZkClient.DEFAULT_SESSION_TIMEOUT);
+
+ /**
+ * instance type specific init
+ */
+ switch (instanceType) {
+ case PARTICIPANT:
+ _stateMachineEngine = new HelixStateMachineEngine(this);
+ _participantHealthInfoCollector =
+ new ParticipantHealthReportCollectorImpl(this, _instanceName);
+
+ _timerTasks.add(new ParticipantHealthReportTask(_participantHealthInfoCollector));
+
+ break;
+ case CONTROLLER:
+ _stateMachineEngine = null;
+ _participantHealthInfoCollector = null;
+ _controllerTimerTasks.add(new HealthStatsAggregationTask(new HealthStatsAggregator(this)));
+ _controllerTimerTasks.add(new StatusDumpTask(_zkclient, this));
+
+ break;
+ case CONTROLLER_PARTICIPANT:
+ _stateMachineEngine = new HelixStateMachineEngine(this);
+ _participantHealthInfoCollector =
+ new ParticipantHealthReportCollectorImpl(this, _instanceName);
+
+ _timerTasks.add(new ParticipantHealthReportTask(_participantHealthInfoCollector));
- // add all timer tasks
- _controllerTimerTasks = new ArrayList<HelixTimerTask>();
- if (_instanceType == InstanceType.CONTROLLER) {
_controllerTimerTasks.add(new HealthStatsAggregationTask(new HealthStatsAggregator(this)));
+ _controllerTimerTasks.add(new StatusDumpTask(_zkclient, this));
+
+ break;
+ case ADMINISTRATOR:
+ case SPECTATOR:
+ _stateMachineEngine = null;
+ _participantHealthInfoCollector = null;
+ break;
+ default:
+ throw new IllegalArgumentException("unrecognized type: " + instanceType);
}
}
+ private int getSystemPropertyAsInt(String propertyKey, int propertyDefaultValue) {
+ String valueString = System.getProperty(propertyKey, "" + propertyDefaultValue);
+
+ try {
+ int value = Integer.parseInt(valueString);
+ if (value > 0) {
+ return value;
+ }
+ } catch (NumberFormatException e) {
+ LOG.warn("Exception while parsing property: " + propertyKey + ", string: " + valueString
+ + ", using default value: " + propertyDefaultValue);
+ }
+
+ return propertyDefaultValue;
+ }
+
@Override
public boolean removeListener(PropertyKey key, Object listener) {
- logger.info("Removing listener: " + listener + " on path: " + key.getPath() + " from cluster: "
+ LOG.info("Removing listener: " + listener + " on path: " + key.getPath() + " from cluster: "
+ _clusterName + " by instance: " + _instanceName);
synchronized (this) {
@@ -218,7 +294,13 @@ public class ZKHelixManager implements HelixManager {
return true;
}
- private void addListener(Object listener, PropertyKey propertyKey, ChangeType changeType,
+ void checkConnected() {
+ if (!isConnected()) {
+ throw new HelixException("HelixManager is not connected. Call HelixManager#connect()");
+ }
+ }
+
+ void addListener(Object listener, PropertyKey propertyKey, ChangeType changeType,
EventType[] eventType) {
checkConnected();
@@ -229,16 +311,18 @@ public class ZKHelixManager implements HelixManager {
// compare property-key path and listener reference
if (handler.getPath().equals(propertyKey.getPath())
&& handler.getListener().equals(listener)) {
- logger.info("Listener: " + listener + " on path: " + propertyKey.getPath()
- + " already exists. skip adding it");
+ LOG.info("Listener: " + listener + " on path: " + propertyKey.getPath()
+ + " already exists. skip add");
+
return;
}
}
CallbackHandler newHandler =
- createCallBackHandler(propertyKey, listener, eventType, changeType);
+ new CallbackHandler(this, _zkclient, propertyKey, listener, eventType, changeType);
+
_handlers.add(newHandler);
- logger.info("Add listener: " + listener + " for type: " + type + " to path: "
+ LOG.info("Added listener: " + listener + " for type: " + type + " to path: "
+ newHandler.getPath());
}
}
@@ -261,7 +345,7 @@ public class ZKHelixManager implements HelixManager {
}
@Override
- public void addConfigChangeListener(ConfigChangeListener listener) {
+ public void addConfigChangeListener(ConfigChangeListener listener) throws Exception {
addListener(listener, new Builder(_clusterName).instanceConfigs(), ChangeType.INSTANCE_CONFIG,
new EventType[] {
EventType.NodeChildrenChanged
@@ -269,7 +353,8 @@ public class ZKHelixManager implements HelixManager {
}
@Override
- public void addInstanceConfigChangeListener(InstanceConfigChangeListener listener) {
+ public void addInstanceConfigChangeListener(InstanceConfigChangeListener listener)
+ throws Exception {
addListener(listener, new Builder(_clusterName).instanceConfigs(), ChangeType.INSTANCE_CONFIG,
new EventType[] {
EventType.NodeChildrenChanged
@@ -277,7 +362,8 @@ public class ZKHelixManager implements HelixManager {
}
@Override
- public void addConfigChangeListener(ScopedConfigChangeListener listener, ConfigScopeProperty scope) {
+ public void addConfigChangeListener(ScopedConfigChangeListener listener, ConfigScopeProperty scope)
+ throws Exception {
Builder keyBuilder = new Builder(_clusterName);
PropertyKey propertyKey = null;
@@ -300,7 +386,7 @@ public class ZKHelixManager implements HelixManager {
EventType.NodeChildrenChanged
});
} else {
- logger.error("Can't add listener to config scope: " + scope);
+ LOG.error("Can't add listener to config scope: " + scope);
}
}
@@ -314,7 +400,8 @@ public class ZKHelixManager implements HelixManager {
});
}
- void addControllerMessageListener(MessageListener listener) {
+ @Override
+ public void addControllerMessageListener(MessageListener listener) {
addListener(listener, new Builder(_clusterName).controllerMessages(),
ChangeType.MESSAGES_CONTROLLER, new EventType[] {
EventType.NodeChildrenChanged, EventType.NodeDeleted, EventType.NodeCreated
@@ -323,7 +410,7 @@ public class ZKHelixManager implements HelixManager {
@Override
public void addCurrentStateChangeListener(CurrentStateChangeListener listener,
- String instanceName, String sessionId) {
+ String instanceName, String sessionId) throws Exception {
addListener(listener, new Builder(_clusterName).currentStates(instanceName, sessionId),
ChangeType.CURRENT_STATE, new EventType[] {
EventType.NodeChildrenChanged, EventType.NodeDeleted, EventType.NodeCreated
@@ -331,7 +418,8 @@ public class ZKHelixManager implements HelixManager {
}
@Override
- public void addHealthStateChangeListener(HealthStateChangeListener listener, String instanceName) {
+ public void addHealthStateChangeListener(HealthStateChangeListener listener, String instanceName)
+ throws Exception {
addListener(listener, new Builder(_clusterName).healthReports(instanceName), ChangeType.HEALTH,
new EventType[] {
EventType.NodeChildrenChanged, EventType.NodeDeleted, EventType.NodeCreated
@@ -339,7 +427,7 @@ public class ZKHelixManager implements HelixManager {
}
@Override
- public void addExternalViewChangeListener(ExternalViewChangeListener listener) {
+ public void addExternalViewChangeListener(ExternalViewChangeListener listener) throws Exception {
addListener(listener, new Builder(_clusterName).externalViews(), ChangeType.EXTERNAL_VIEW,
new EventType[] {
EventType.NodeChildrenChanged, EventType.NodeDeleted, EventType.NodeCreated
@@ -357,7 +445,7 @@ public class ZKHelixManager implements HelixManager {
@Override
public HelixDataAccessor getHelixDataAccessor() {
checkConnected();
- return _helixAccessor;
+ return _dataAccessor;
}
@Override
@@ -376,484 +464,158 @@ public class ZKHelixManager implements HelixManager {
return _instanceName;
}
- @Override
- public void connect() throws Exception {
- logger.info("ClusterManager.connect()");
- if (_zkStateChangeListener.isConnected()) {
- logger.warn("Cluster manager " + _clusterName + " " + _instanceName + " already connected");
- return;
- }
-
- try {
- createClient(_zkConnectString);
- _messagingService.onConnected();
- } catch (Exception e) {
- logger.error(e);
- disconnect();
- throw e;
- }
- }
-
- @Override
- public void disconnect() {
- if (!isConnected()) {
- logger.error("ClusterManager " + _instanceName + " already disconnected");
- return;
- }
- disconnectInternal();
- }
-
- void disconnectInternal() {
- // This function can be called when the connection are in bad state(e.g. flapping),
- // in which isConnected() could be false and we want to disconnect from cluster.
- logger.info("disconnect " + _instanceName + "(" + _instanceType + ") from " + _clusterName);
-
- /**
- * shutdown thread pool first to avoid reset() being invoked in the middle of state
- * transition
- */
- _messagingService.getExecutor().shutdown();
- resetHandlers();
-
- _helixAccessor.shutdown();
-
- if (_leaderElectionHandler != null) {
- _leaderElectionHandler.reset();
- }
-
- if (_participantHealthCheckInfoCollector != null) {
- _participantHealthReportTask.stop();
- }
-
- if (_timer != null) {
- _timer.cancel();
- _timer = null;
- }
-
- if (_instanceType == InstanceType.CONTROLLER) {
- stopTimerTasks();
- }
-
- // unsubscribe accessor from controllerChange
- _zkClient.unsubscribeAll();
-
- _zkClient.close();
-
- // HACK seems that zkClient is not sending DISCONNECT event
- _zkStateChangeListener.disconnect();
- logger.info("Cluster manager: " + _instanceName + " disconnected");
-
- }
-
- @Override
- public String getSessionId() {
- checkConnected();
- return _sessionId;
- }
-
- @Override
- public boolean isConnected() {
- return _zkStateChangeListener.isConnected();
- }
-
- @Override
- public long getLastNotificationTime() {
- return -1;
- }
-
- private void addLiveInstance() {
- LiveInstance liveInstance = new LiveInstance(_instanceName);
- liveInstance.setSessionId(_sessionId);
- liveInstance.setHelixVersion(_version);
- liveInstance.setLiveInstance(ManagementFactory.getRuntimeMXBean().getName());
-
- if (_liveInstanceInfoProvider != null) {
- logger.info("invoking _liveInstanceInfoProvider");
- ZNRecord additionalLiveInstanceInfo =
- _liveInstanceInfoProvider.getAdditionalLiveInstanceInfo();
- if (additionalLiveInstanceInfo != null) {
- additionalLiveInstanceInfo.merge(liveInstance.getRecord());
- ZNRecord mergedLiveInstance = new ZNRecord(additionalLiveInstanceInfo, _instanceName);
- liveInstance = new LiveInstance(mergedLiveInstance);
- logger.info("liveInstance content :" + _instanceName + " " + liveInstance.toString());
- }
- }
-
- logger.info("Add live instance: InstanceName: " + _instanceName + " Session id:" + _sessionId);
- Builder keyBuilder = _helixAccessor.keyBuilder();
- if (!_helixAccessor.createProperty(keyBuilder.liveInstance(_instanceName), liveInstance)) {
- String errorMsg =
- "Fail to create live instance node after waiting, so quit. instance:" + _instanceName;
- logger.warn(errorMsg);
- throw new HelixException(errorMsg);
-
- }
- String currentStatePathParent =
- PropertyPathConfig.getPath(PropertyType.CURRENTSTATES, _clusterName, _instanceName,
- getSessionId());
-
- if (!_zkClient.exists(currentStatePathParent)) {
- _zkClient.createPersistent(currentStatePathParent);
- logger.info("Creating current state path " + currentStatePathParent);
- }
- }
-
- private void startStatusUpdatedumpTask() {
- long initialDelay = 30 * 60 * 1000;
- long period = 120 * 60 * 1000;
- int timeThresholdNoChange = 180 * 60 * 1000;
+ BaseDataAccessor<ZNRecord> createBaseDataAccessor() {
+ ZkBaseDataAccessor<ZNRecord> baseDataAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkclient);
- if (_timer == null) {
- _timer = new Timer(true);
- _timer.scheduleAtFixedRate(new ZKPathDataDumpTask(this, _zkClient, timeThresholdNoChange),
- initialDelay, period);
- }
+ return baseDataAccessor;
}
- private void createClient(String zkServers) throws Exception {
- // by default use ZNRecordStreamingSerializer except for paths within the property
- // store which expects raw byte[] serialization/deserialization
+ void createClient() throws Exception {
PathBasedZkSerializer zkSerializer =
ChainedPathZkSerializer.builder(new ZNRecordStreamingSerializer()).build();
- _zkClient = new ZkClient(zkServers, _sessionTimeout, CONNECTIONTIMEOUT, zkSerializer);
+ _zkclient =
+ new ZkClient(_zkAddress, _sessionTimeout, ZkClient.DEFAULT_CONNECTION_TIMEOUT, zkSerializer);
- ZkBaseDataAccessor<ZNRecord> baseDataAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkClient);
- if (_instanceType == InstanceType.PARTICIPANT) {
- String curStatePath =
- PropertyPathConfig.getPath(PropertyType.CURRENTSTATES, _clusterName, _instanceName);
- _baseDataAccessor =
- new ZkCacheBaseDataAccessor<ZNRecord>(baseDataAccessor, Arrays.asList(curStatePath));
- } else if (_instanceType == InstanceType.CONTROLLER) {
- String extViewPath = PropertyPathConfig.getPath(PropertyType.EXTERNALVIEW,
+ _baseDataAccessor = createBaseDataAccessor();
- _clusterName);
- _baseDataAccessor =
- new ZkCacheBaseDataAccessor<ZNRecord>(baseDataAccessor, Arrays.asList(extViewPath));
+ _dataAccessor = new ZKHelixDataAccessor(_clusterName, _instanceType, _baseDataAccessor);
+ _configAccessor = new ConfigAccessor(_zkclient);
- } else {
- _baseDataAccessor = baseDataAccessor;
- }
-
- _helixAccessor = new ZKHelixDataAccessor(_clusterName, _instanceType, _baseDataAccessor);
- _configAccessor = new ConfigAccessor(_zkClient);
int retryCount = 0;
- _zkClient.subscribeStateChanges(_zkStateChangeListener);
- while (retryCount < RETRY_LIMIT) {
+ _zkclient.subscribeStateChanges(this);
+ while (retryCount < 3) {
try {
- _zkClient.waitUntilConnected(_sessionTimeout, TimeUnit.MILLISECONDS);
- _zkStateChangeListener.handleStateChanged(KeeperState.SyncConnected);
- _zkStateChangeListener.handleNewSession();
+ _zkclient.waitUntilConnected(_sessionTimeout, TimeUnit.MILLISECONDS);
+ handleStateChanged(KeeperState.SyncConnected);
+ handleNewSession();
break;
} catch (HelixException e) {
- logger.error("fail to createClient.", e);
+ LOG.error("fail to createClient.", e);
throw e;
} catch (Exception e) {
retryCount++;
- logger.error("fail to createClient. retry " + retryCount, e);
- if (retryCount == RETRY_LIMIT) {
+ LOG.error("fail to createClient. retry " + retryCount, e);
+ if (retryCount == 3) {
throw e;
}
}
}
}
- private CallbackHandler createCallBackHandler(PropertyKey propertyKey, Object listener,
- EventType[] eventTypes, ChangeType changeType) {
- if (listener == null) {
- throw new HelixException("Listener cannot be null");
+ @Override
+ public void connect() throws Exception {
+ LOG.info("ClusterManager.connect()");
+ if (isConnected()) {
+ LOG.warn("Cluster manager: " + _instanceName + " for cluster: " + _clusterName
+ + " already connected. skip connect");
+ return;
}
- return new CallbackHandler(this, _zkClient, propertyKey, listener, eventTypes, changeType);
- }
-
- /**
- * This will be invoked when ever a new session is created<br/>
- * case 1: the cluster manager was a participant carry over current state, add live
- * instance, and invoke message listener; case 2: the cluster manager was controller and
- * was a leader before do leader election, and if it becomes leader again, invoke ideal
- * state listener, current state listener, etc. if it fails to become leader in the new
- * session, then becomes standby; case 3: the cluster manager was controller and was NOT
- * a leader before do leader election, and if it becomes leader, instantiate and invoke
- * ideal state listener, current state listener, etc. if if fails to become leader in
- * the new session, stay as standby
- */
- protected void handleNewSession() {
- boolean isConnected = _zkClient.waitUntilConnected(CONNECTIONTIMEOUT, TimeUnit.MILLISECONDS);
- while (!isConnected) {
- logger.error("Could NOT connect to zk server in " + CONNECTIONTIMEOUT + "ms. zkServer: "
- + _zkConnectString + ", expiredSessionId: " + _sessionId + ", clusterName: "
- + _clusterName);
- isConnected = _zkClient.waitUntilConnected(CONNECTIONTIMEOUT, TimeUnit.MILLISECONDS);
+ try {
+ createClient();
+ _messagingService.onConnected();
+ } catch (Exception e) {
+ LOG.error("fail to connect " + _instanceName, e);
+ disconnect();
+ throw e;
}
+ }
- ZkConnection zkConnection = ((ZkConnection) _zkClient.getConnection());
-
- synchronized (this) {
- _sessionId = Long.toHexString(zkConnection.getZookeeper().getSessionId());
+ @Override
+ public void disconnect() {
+ if (_zkclient == null) {
+ LOG.info("instanceName: " + _instanceName + " already disconnected");
+ return;
}
- _baseDataAccessor.reset();
-
- // reset all handlers so they have a chance to unsubscribe zk changes from zkclient
- // abandon all callback-handlers added in expired session
- resetHandlers();
- logger.info("Handling new session, session id:" + _sessionId + ", instance:" + _instanceName
- + ", instanceTye: " + _instanceType + ", cluster: " + _clusterName);
+ LOG.info("disconnect " + _instanceName + "(" + _instanceType + ") from " + _clusterName);
- logger.info(zkConnection.getZookeeper());
-
- if (!ZKUtil.isClusterSetup(_clusterName, _zkClient)) {
- throw new HelixException("Initial cluster structure is not set up for cluster:"
- + _clusterName);
- }
- // Read cluster config and see if instance can auto join the cluster
- boolean autoJoin = false;
try {
- HelixConfigScope scope =
- new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(getClusterName())
- .build();
- autoJoin = Boolean.parseBoolean(getConfigAccessor().get(scope, ALLOW_PARTICIPANT_AUTO_JOIN));
- logger.info("Auto joining " + _clusterName + " is true");
- } catch (Exception e) {
- }
- if (!ZKUtil.isInstanceSetup(_zkClient, _clusterName, _instanceName, _instanceType)) {
- if (!autoJoin) {
- throw new HelixException("Initial cluster structure is not set up for instance:"
- + _instanceName + " instanceType:" + _instanceType);
- } else {
- logger.info("Auto joining instance " + _instanceName);
- InstanceConfig instanceConfig = new InstanceConfig(_instanceName);
- String hostName = _instanceName;
- String port = "";
- int lastPos = _instanceName.lastIndexOf("_");
- if (lastPos > 0) {
- hostName = _instanceName.substring(0, lastPos);
- port = _instanceName.substring(lastPos + 1);
- }
- instanceConfig.setHostName(hostName);
- instanceConfig.setPort(port);
- instanceConfig.setInstanceEnabled(true);
- getClusterManagmentTool().addInstance(_clusterName, instanceConfig);
- }
- }
+ /**
+ * stop all timer tasks
+ */
+ stopTimerTasks();
- if (_instanceType == InstanceType.PARTICIPANT
- || _instanceType == InstanceType.CONTROLLER_PARTICIPANT) {
- handleNewSessionAsParticipant();
- }
+ /**
+ * shutdown thread pool first to avoid reset() being invoked in the middle of state
+ * transition
+ */
+ _messagingService.getExecutor().shutdown();
+
+ // TODO reset user defined handlers only
+ resetHandlers();
- if (_instanceType == InstanceType.CONTROLLER
- || _instanceType == InstanceType.CONTROLLER_PARTICIPANT) {
- addControllerMessageListener(_messagingService.getExecutor());
- MessageHandlerFactory defaultControllerMsgHandlerFactory =
- new DefaultControllerMessageHandlerFactory();
- _messagingService.getExecutor().registerMessageHandlerFactory(
- defaultControllerMsgHandlerFactory.getMessageType(), defaultControllerMsgHandlerFactory);
- MessageHandlerFactory defaultSchedulerMsgHandlerFactory =
- new DefaultSchedulerMessageHandlerFactory(this);
- _messagingService.getExecutor().registerMessageHandlerFactory(
- defaultSchedulerMsgHandlerFactory.getMessageType(), defaultSchedulerMsgHandlerFactory);
- MessageHandlerFactory defaultParticipantErrorMessageHandlerFactory =
- new DefaultParticipantErrorMessageHandlerFactory(this);
- _messagingService.getExecutor().registerMessageHandlerFactory(
- defaultParticipantErrorMessageHandlerFactory.getMessageType(),
- defaultParticipantErrorMessageHandlerFactory);
+ _dataAccessor.shutdown();
if (_leaderElectionHandler != null) {
_leaderElectionHandler.reset();
- _leaderElectionHandler.init();
- } else {
- _leaderElectionHandler =
- createCallBackHandler(new Builder(_clusterName).controller(),
- new DistClusterControllerElection(_zkConnectString), new EventType[] {
- EventType.NodeChildrenChanged, EventType.NodeDeleted, EventType.NodeCreated
- }, ChangeType.CONTROLLER);
}
- }
- if (_instanceType == InstanceType.PARTICIPANT
- || _instanceType == InstanceType.CONTROLLER_PARTICIPANT
- || (_instanceType == InstanceType.CONTROLLER && isLeader())) {
- initHandlers();
+ } finally {
+ _zkclient.close();
+ _zkclient = null;
+ LOG.info("Cluster manager: " + _instanceName + " disconnected");
}
}
- private void handleNewSessionAsParticipant() {
- // In case there is a live instance record on zookeeper
- Builder keyBuilder = _helixAccessor.keyBuilder();
-
- if (_helixAccessor.getProperty(keyBuilder.liveInstance(_instanceName)) != null) {
- logger.warn("Found another instance with same instanceName: " + _instanceName
- + " in cluster " + _clusterName);
- // Wait for a while, in case previous storage node exits unexpectedly
- // and its liveinstance
- // still hangs around until session timeout happens
- try {
- Thread.sleep(_sessionTimeout + 5000);
- } catch (InterruptedException e) {
- logger.warn("Sleep interrupted while waiting for previous liveinstance to go away.", e);
- }
+ @Override
+ public String getSessionId() {
+ checkConnected();
+ return _sessionId;
+ }
- if (_helixAccessor.getProperty(keyBuilder.liveInstance(_instanceName)) != null) {
- String errorMessage =
- "instance " + _instanceName + " already has a liveinstance in cluster " + _clusterName;
- logger.error(errorMessage);
- throw new HelixException(errorMessage);
- }
+ @Override
+ public boolean isConnected() {
+ if (_zkclient == null) {
+ return false;
}
- // Invoke the PreConnectCallbacks
- for (PreConnectCallback callback : _preConnectCallbacks) {
- callback.onPreConnect();
+ ZkConnection zkconnection = (ZkConnection) _zkclient.getConnection();
+ if (zkconnection != null) {
+ States state = zkconnection.getZookeeperState();
+ return state == States.CONNECTED;
}
- addLiveInstance();
- carryOverPreviousCurrentState();
-
- // In case the cluster manager is running as a participant, setup message
- // listener
- _messagingService.registerMessageHandlerFactory(MessageType.STATE_TRANSITION.toString(),
- _stateMachEngine);
- addMessageListener(_messagingService.getExecutor(), _instanceName);
- addControllerListener(_helixAccessor);
-
- ScheduledTaskStateModelFactory stStateModelFactory =
- new ScheduledTaskStateModelFactory(_messagingService.getExecutor());
- _stateMachEngine.registerStateModelFactory(
- DefaultSchedulerMessageHandlerFactory.SCHEDULER_TASK_QUEUE, stStateModelFactory);
+ return false;
+ }
- if (_participantHealthCheckInfoCollector == null) {
- _participantHealthCheckInfoCollector =
- new ParticipantHealthReportCollectorImpl(this, _instanceName);
- _participantHealthReportTask =
- new ParticipantHealthReportTask(_participantHealthCheckInfoCollector);
- _participantHealthReportTask.start();
- }
- // start the participant health check timer, also create zk path for health
- // check info
- String healthCheckInfoPath = _helixAccessor.keyBuilder().healthReports(_instanceName).getPath();
- if (!_zkClient.exists(healthCheckInfoPath)) {
- _zkClient.createPersistent(healthCheckInfoPath, true);
- logger.info("Creating healthcheck info path " + healthCheckInfoPath);
- }
+ @Override
+ public long getLastNotificationTime() {
+ return 0;
}
@Override
public void addPreConnectCallback(PreConnectCallback callback) {
- logger.info("Adding preconnect callback");
+ LOG.info("Adding preconnect callback: " + callback);
_preConnectCallbacks.add(callback);
}
- private void resetHandlers() {
- synchronized (this) {
- if (_handlers != null) {
- // get a copy of the list and iterate over the copy list
- // in case handler.reset() will modify the original handler list
- List<CallbackHandler> tmpHandlers = new ArrayList<CallbackHandler>();
- tmpHandlers.addAll(_handlers);
-
- for (CallbackHandler handler : tmpHandlers) {
- handler.reset();
- logger.info("reset handler: " + handler.getPath() + ", " + handler.getListener());
- }
- }
- }
- }
-
- private void initHandlers() {
- synchronized (this) {
- if (_handlers != null) {
- // may add new currentState and message listeners during init()
- // so make a copy and iterate over the copy
- List<CallbackHandler> tmpHandlers = new ArrayList<CallbackHandler>();
- tmpHandlers.addAll(_handlers);
- for (CallbackHandler handler : tmpHandlers) {
- handler.init();
- logger.info("init handler: " + handler.getPath() + ", " + handler.getListener());
- }
- }
- }
- }
-
@Override
public boolean isLeader() {
- if (!isConnected()) {
+ if (_instanceType != InstanceType.CONTROLLER
+ && _instanceType != InstanceType.CONTROLLER_PARTICIPANT) {
return false;
}
- if (_instanceType != InstanceType.CONTROLLER) {
- return false;
- }
-
- Builder keyBuilder = _helixAccessor.keyBuilder();
- LiveInstance leader = _helixAccessor.getProperty(keyBuilder.controllerLeader());
- if (leader == null) {
+ if (!isConnected()) {
return false;
- } else {
- String leaderName = leader.getInstanceName();
- // TODO need check sessionId also, but in distributed mode, leader's
- // sessionId is
- // not equal to
- // the leader znode's sessionId field which is the sessionId of the
- // controller_participant that
- // successfully creates the leader node
- if (leaderName == null || !leaderName.equals(_instanceName)) {
- return false;
- }
}
- return true;
- }
-
- /**
- * carry over current-states from last sessions
- * set to initial state for current session only when the state doesn't exist in current session
- */
- private void carryOverPreviousCurrentState() {
- Builder keyBuilder = _helixAccessor.keyBuilder();
- List<String> sessions = _helixAccessor.getChildNames(keyBuilder.sessions(_instanceName));
- // carry-over
- for (String session : sessions) {
- if (session.equals(_sessionId)) {
- continue;
- }
-
- List<CurrentState> lastCurStates =
- _helixAccessor.getChildValues(keyBuilder.currentStates(_instanceName, session));
-
- for (CurrentState lastCurState : lastCurStates) {
- logger.info("Carrying over old session: " + session + ", resource: " + lastCurState.getId()
- + " to current session: " + _sessionId);
- String stateModelDefRef = lastCurState.getStateModelDefRef();
- if (stateModelDefRef == null) {
- logger
- .error("skip carry-over because previous current state doesn't have a state model definition. previous current-state: "
- + lastCurState);
- continue;
+ try {
+ LiveInstance leader = _dataAccessor.getProperty(_keyBuilder.controllerLeader());
+ if (leader != null) {
+ String leaderName = leader.getInstanceName();
+ String sessionId = leader.getSessionId();
+ if (leaderName != null && leaderName.equals(_instanceName) && sessionId != null
+ && sessionId.equals(_sessionId)) {
+ return true;
}
- StateModelDefinition stateModel =
- _helixAccessor.getProperty(keyBuilder.stateModelDef(stateModelDefRef));
-
- String curStatePath =
- keyBuilder.currentState(_instanceName, _sessionId, lastCurState.getResourceName())
- .getPath();
- _helixAccessor.getBaseDataAccessor().update(curStatePath,
- new CurStateCarryOverUpdater(_sessionId, stateModel.getInitialState(), lastCurState),
- AccessOption.PERSISTENT);
- }
- }
-
- // remove previous current states
- for (String session : sessions) {
- if (session.equals(_sessionId)) {
- continue;
}
-
- String path = _helixAccessor.keyBuilder().currentStates(_instanceName, session).getPath();
- logger.info("Removing current states from previous sessions. path: " + path);
- _zkClient.deleteRecursive(path);
+ } catch (Exception e) {
+ // log
}
+ return false;
}
@Override
@@ -864,7 +626,7 @@ public class ZKHelixManager implements HelixManager {
String path = PropertyPathConfig.getPath(PropertyType.PROPERTYSTORE, _clusterName);
_helixPropertyStore =
- new ZkHelixPropertyStore<ZNRecord>(new ZkBaseDataAccessor<ZNRecord>(_zkClient), path,
+ new ZkHelixPropertyStore<ZNRecord>(new ZkBaseDataAccessor<ZNRecord>(_zkclient), path,
null);
}
@@ -874,13 +636,12 @@ public class ZKHelixManager implements HelixManager {
@Override
public synchronized HelixAdmin getClusterManagmentTool() {
checkConnected();
- if (_zkClient != null) {
- _managementTool = new ZKHelixAdmin(_zkClient);
- } else {
- logger.error("Couldn't get ZKClusterManagementTool because zkClient is null");
+ if (_zkclient != null) {
+ return new ZKHelixAdmin(_zkclient);
}
- return _managementTool;
+ LOG.error("Couldn't get ZKClusterManagementTool because zkclient is null");
+ return null;
}
@Override
@@ -893,7 +654,7 @@ public class ZKHelixManager implements HelixManager {
@Override
public ParticipantHealthReportCollector getHealthReportCollector() {
checkConnected();
- return _participantHealthCheckInfoCollector;
+ return _participantHealthInfoCollector;
}
@Override
@@ -901,12 +662,6 @@ public class ZKHelixManager implements HelixManager {
return _instanceType;
}
- private void checkConnected() {
- if (!isConnected()) {
- throw new HelixException("ClusterManager not connected. Call clusterManager.connect()");
- }
- }
-
@Override
public String getVersion() {
return _version;
@@ -919,21 +674,20 @@ public class ZKHelixManager implements HelixManager {
@Override
public StateMachineEngine getStateMachineEngine() {
- return _stateMachEngine;
+ return _stateMachineEngine;
}
// TODO: rename this and not expose this function as part of interface
@Override
public void startTimerTasks() {
- for (HelixTimerTask task : _controllerTimerTasks) {
+ for (HelixTimerTask task : _timerTasks) {
task.start();
}
- startStatusUpdatedumpTask();
}
@Override
public void stopTimerTasks() {
- for (HelixTimerTask task : _controllerTimerTasks) {
+ for (HelixTimerTask task : _timerTasks) {
task.stop();
}
}
@@ -942,4 +696,209 @@ public class ZKHelixManager implements HelixManager {
public void setLiveInstanceInfoProvider(LiveInstanceInfoProvider liveInstanceInfoProvider) {
_liveInstanceInfoProvider = liveInstanceInfoProvider;
}
+
+ /**
+ * wait until we get a non-zero session-id. note that we might lose zkconnection
+ * right after we read session-id. but it's ok to get stale session-id and we will have
+ * another handle-new-session callback to correct this.
+ */
+ void waitUntilConnected() {
+ boolean isConnected;
+ do {
+ isConnected =
+ _zkclient.waitUntilConnected(ZkClient.DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
+ if (!isConnected) {
+ LOG.error("fail to connect zkserver: " + _zkAddress + " in "
+ + ZkClient.DEFAULT_CONNECTION_TIMEOUT + "ms. expiredSessionId: " + _sessionId
+ + ", clusterName: " + _clusterName);
+ continue;
+ }
+
+ ZkConnection zkConnection = ((ZkConnection) _zkclient.getConnection());
+ _sessionId = Long.toHexString(zkConnection.getZookeeper().getSessionId());
+
+ /**
+ * at the time we read session-id, zkconnection might be lost again
+ * wait until we get a non-zero session-id
+ */
+ } while ("0".equals(_sessionId));
+
+ LOG.info("Handling new session, session id: " + _sessionId + ", instance: " + _instanceName
+ + ", instanceTye: " + _instanceType + ", cluster: " + _clusterName + ", zkconnection: "
+ + ((ZkConnection) _zkclient.getConnection()).getZookeeper());
+ }
+
+ void initHandlers(List<CallbackHandler> handlers) {
+ synchronized (this) {
+ if (handlers != null) {
+ for (CallbackHandler handler : handlers) {
+ handler.init();
+ LOG.info("init handler: " + handler.getPath() + ", " + handler.getListener());
+ }
+ }
+ }
+ }
+
+ void resetHandlers() {
+ synchronized (this) {
+ if (_handlers != null) {
+ // get a copy of the list and iterate over the copy list
+ // in case handler.reset() modify the original handler list
+ List<CallbackHandler> tmpHandlers = new ArrayList<CallbackHandler>();
+ tmpHandlers.addAll(_handlers);
+
+ for (CallbackHandler handler : tmpHandlers) {
+ handler.reset();
+ LOG.info("reset handler: " + handler.getPath() + ", " + handler.getListener());
+ }
+ }
+ }
+ }
+
+ /**
+ * If zk state has changed into Disconnected for _maxDisconnectThreshold times during previous
+ * _timeWindowLengthMs Ms
+ * time window, we think that there are something wrong going on and disconnect the zkHelixManager
+ * from zk.
+ */
+ boolean isFlapping() {
+ if (_disconnectTimeHistory.size() == 0) {
+ return false;
+ }
+ long mostRecentTimestamp = _disconnectTimeHistory.get(_disconnectTimeHistory.size() - 1);
+
+ // Remove disconnect history timestamp that are older than _flappingTimeWindowMs ago
+ while ((_disconnectTimeHistory.get(0) + _flappingTimeWindowMs) < mostRecentTimestamp) {
+ _disconnectTimeHistory.remove(0);
+ }
+ return _disconnectTimeHistory.size() > _maxDisconnectThreshold;
+ }
+
+ @Override
+ public void handleStateChanged(KeeperState state) throws Exception {
+ switch (state) {
+ case SyncConnected:
+ ZkConnection zkConnection = (ZkConnection) _zkclient.getConnection();
+ LOG.info("KeeperState: " + state + ", zookeeper:" + zkConnection.getZookeeper());
+ break;
+ case Disconnected:
+ LOG.info("KeeperState:" + state + ", disconnectedSessionId: " + _sessionId + ", instance: "
+ + _instanceName + ", type: " + _instanceType);
+
+ /**
+ * Track the time stamp that the disconnected happens, then check history and see if
+ * we should disconnect the helix-manager
+ */
+ _disconnectTimeHistory.add(System.currentTimeMillis());
+ if (isFlapping()) {
+ LOG.error("instanceName: " + _instanceName + " is flapping. diconnect it. "
+ + " maxDisconnectThreshold: " + _maxDisconnectThreshold + " disconnects in "
+ + _flappingTimeWindowMs + "ms.");
+ disconnect();
+ }
+ break;
+ case Expired:
+ LOG.info("KeeperState:" + state + ", expiredSessionId: " + _sessionId + ", instance: "
+ + _instanceName + ", type: " + _instanceType);
+ break;
+ default:
+ break;
+ }
+ }
+
+ @Override
+ public void handleNewSession() throws Exception {
+ waitUntilConnected();
+
+ /**
+ * stop all timer tasks, reset all handlers, make sure cleanup completed for previous session
+ * disconnect if fail to cleanup
+ */
+ stopTimerTasks();
+ if (_leaderElectionHandler != null) {
+ _leaderElectionHandler.reset();
+ }
+ resetHandlers();
+
+ /**
+ * clean up write-through cache
+ */
+ _baseDataAccessor.reset();
+
+ /**
+ * from here on, we are dealing with new session
+ */
+ if (!ZKUtil.isClusterSetup(_clusterName, _zkclient)) {
+ throw new HelixException("Cluster structure is not set up for cluster: " + _clusterName);
+ }
+
+ switch (_instanceType) {
+ case PARTICIPANT:
+ handleNewSessionAsParticipant();
+ break;
+ case CONTROLLER:
+ handleNewSessionAsController();
+ break;
+ case CONTROLLER_PARTICIPANT:
+ handleNewSessionAsParticipant();
+ handleNewSessionAsController();
+ break;
+ case ADMINISTRATOR:
+ case SPECTATOR:
+ default:
+ break;
+ }
+
+ startTimerTasks();
+
+ /**
+ * init handlers
+ * ok to init message handler and data-accessor twice
+ * the second init will be skipped (see CallbackHandler)
+ */
+ initHandlers(_handlers);
+ }
+
+ void handleNewSessionAsParticipant() throws Exception {
+ /**
+ * auto-join
+ */
+ ParticipantManagerHelper participantHelper =
+ new ParticipantManagerHelper(this, _zkclient, _sessionTimeout, _liveInstanceInfoProvider);
+ participantHelper.joinCluster();
+
+ /**
+ * Invoke PreConnectCallbacks
+ */
+ for (PreConnectCallback callback : _preConnectCallbacks) {
+ callback.onPreConnect();
+ }
+
+ participantHelper.createLiveInstance();
+ participantHelper.carryOverPreviousCurrentState();
+
+ /**
+ * setup message listener
+ */
+ participantHelper.setupMsgHandler();
+
+ /**
+ * start health check timer task
+ */
+ participantHelper.createHealthCheckPath();
+ }
+
+ void handleNewSessionAsController() {
+ if (_leaderElectionHandler != null) {
+ _leaderElectionHandler.init();
+ } else {
+ _leaderElectionHandler =
+ new CallbackHandler(this, _zkclient, _keyBuilder.controller(),
+ new DistributedLeaderElection(this, _controller, _controllerTimerTasks),
+ new EventType[] {
+ EventType.NodeChildrenChanged, EventType.NodeDeleted, EventType.NodeCreated
+ }, ChangeType.CONTROLLER);
+ }
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/main/java/org/apache/helix/manager/zk/ZkAsyncCallbacks.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZkAsyncCallbacks.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ZkAsyncCallbacks.java
index 5865863..755ca52 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZkAsyncCallbacks.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZkAsyncCallbacks.java
@@ -143,8 +143,7 @@ public class ZkAsyncCallbacks {
}
}
} catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.error("Interrupted waiting for success", e);
}
return true;
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/main/java/org/apache/helix/manager/zk/ZkStateChangeListener.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZkStateChangeListener.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ZkStateChangeListener.java
deleted file mode 100644
index e11444b..0000000
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZkStateChangeListener.java
+++ /dev/null
@@ -1,127 +0,0 @@
-package org.apache.helix.manager.zk;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.LinkedList;
-import java.util.List;
-
-import org.I0Itec.zkclient.IZkStateListener;
-import org.I0Itec.zkclient.ZkConnection;
-import org.apache.log4j.Logger;
-import org.apache.zookeeper.Watcher.Event.KeeperState;
-
-public class ZkStateChangeListener implements IZkStateListener {
- private volatile boolean _isConnected;
- private volatile boolean _hasSessionExpired;
- private final ZKHelixManager _zkHelixManager;
-
- // Keep track of timestamps that zk State has become Disconnected
- // If in a _timeWindowLengthMs window zk State has become Disconnected
- // for more than_maxDisconnectThreshold times disconnect the zkHelixManager
- List<Long> _disconnectTimeHistory = new LinkedList<Long>();
- int _timeWindowLengthMs;
- int _maxDisconnectThreshold;
-
- private static Logger logger = Logger.getLogger(ZkStateChangeListener.class);
-
- public ZkStateChangeListener(ZKHelixManager zkHelixManager, int timeWindowLengthMs,
- int maxDisconnectThreshold) {
- this._zkHelixManager = zkHelixManager;
- _timeWindowLengthMs = timeWindowLengthMs;
- // _maxDisconnectThreshold min value is 1.
- // We don't want to disconnect from zk for the first time zkState become Disconnected
- _maxDisconnectThreshold = maxDisconnectThreshold > 0 ? maxDisconnectThreshold : 1;
- }
-
- @Override
- public void handleNewSession() {
- // TODO:bug in zkclient .
- // zkclient does not invoke handleStateChanged when a session expires but
- // directly invokes handleNewSession
- _isConnected = true;
- _hasSessionExpired = false;
- _zkHelixManager.handleNewSession();
- }
-
- @Override
- public void handleStateChanged(KeeperState keeperState) throws Exception {
- switch (keeperState) {
- case SyncConnected:
- ZkConnection zkConnection = ((ZkConnection) _zkHelixManager._zkClient.getConnection());
- logger.info("KeeperState: " + keeperState + ", zookeeper:" + zkConnection.getZookeeper());
- _isConnected = true;
- break;
- case Disconnected:
- logger.info("KeeperState:" + keeperState + ", disconnectedSessionId: "
- + _zkHelixManager._sessionId + ", instance: " + _zkHelixManager.getInstanceName()
- + ", type: " + _zkHelixManager.getInstanceType());
-
- _isConnected = false;
- // Track the time stamp that the disconnected happens, then check history and see if
- // we should disconnect the _zkHelixManager
- _disconnectTimeHistory.add(System.currentTimeMillis());
- if (isFlapping()) {
- logger.error("isFlapping() returns true, so disconnect the helix manager. "
- + _zkHelixManager.getInstanceName() + " " + _maxDisconnectThreshold
- + " disconnects in " + _timeWindowLengthMs + " Ms.");
- _zkHelixManager.disconnectInternal();
- }
- break;
- case Expired:
- logger.info("KeeperState:" + keeperState + ", expiredSessionId: "
- + _zkHelixManager._sessionId + ", instance: " + _zkHelixManager.getInstanceName()
- + ", type: " + _zkHelixManager.getInstanceType());
-
- _isConnected = false;
- _hasSessionExpired = true;
- break;
- }
- }
-
- boolean isConnected() {
- return _isConnected;
- }
-
- void disconnect() {
- _isConnected = false;
- }
-
- boolean hasSessionExpired() {
- return _hasSessionExpired;
- }
-
- /**
- * If zk state has changed into Disconnected for _maxDisconnectThreshold times during previous
- * _timeWindowLengthMs Ms
- * time window, we think that there are something wrong going on and disconnect the zkHelixManager
- * from zk.
- */
- boolean isFlapping() {
- if (_disconnectTimeHistory.size() == 0) {
- return false;
- }
- long mostRecentTimestamp = _disconnectTimeHistory.get(_disconnectTimeHistory.size() - 1);
- // Remove disconnect history timestamp that are older than _timeWindowLengthMs ago
- while ((_disconnectTimeHistory.get(0) + _timeWindowLengthMs) < mostRecentTimestamp) {
- _disconnectTimeHistory.remove(0);
- }
- return _disconnectTimeHistory.size() > _maxDisconnectThreshold;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/Mocks.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/Mocks.java b/helix-core/src/test/java/org/apache/helix/Mocks.java
index 7bafe1b..df893bb 100644
--- a/helix-core/src/test/java/org/apache/helix/Mocks.java
+++ b/helix-core/src/test/java/org/apache/helix/Mocks.java
@@ -473,6 +473,12 @@ public class Mocks {
return _properties;
}
+ @Override
+ public void addControllerMessageListener(MessageListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
}
public static class MockAccessor implements HelixDataAccessor // DataAccessor
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/TestHelper.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/TestHelper.java b/helix-core/src/test/java/org/apache/helix/TestHelper.java
index 5c4749e..50530a5 100644
--- a/helix-core/src/test/java/org/apache/helix/TestHelper.java
+++ b/helix-core/src/test/java/org/apache/helix/TestHelper.java
@@ -45,7 +45,6 @@ import org.I0Itec.zkclient.ZkServer;
import org.I0Itec.zkclient.exception.ZkNoNodeException;
import org.apache.commons.io.FileUtils;
import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.controller.HelixControllerMain;
import org.apache.helix.integration.manager.ZkTestManager;
import org.apache.helix.manager.zk.CallbackHandler;
import org.apache.helix.manager.zk.ZKHelixAdmin;
@@ -60,8 +59,6 @@ import org.apache.helix.model.Message;
import org.apache.helix.model.Message.MessageType;
import org.apache.helix.model.StateModelDefinition;
import org.apache.helix.model.StateModelDefinition.StateModelDefinitionProperty;
-import org.apache.helix.participant.DistClusterControllerStateModelFactory;
-import org.apache.helix.participant.StateMachineEngine;
import org.apache.helix.store.zk.ZNode;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.util.ZKClientPool;
@@ -126,7 +123,7 @@ public class TestHelper {
try {
zkClient.deleteRecursive(rootNamespace);
} catch (Exception e) {
- LOG.error("fail to deleteRecursive path:" + rootNamespace + "\nexception:" + e);
+ LOG.error("fail to deleteRecursive path:" + rootNamespace, e);
}
}
}
@@ -147,90 +144,6 @@ public class TestHelper {
}
}
- public static StartCMResult startDummyProcess(final String zkAddr, final String clusterName,
- final String instanceName) throws Exception {
- StartCMResult result = new StartCMResult();
- ZkHelixTestManager manager = null;
- manager = new ZkHelixTestManager(clusterName, instanceName, InstanceType.PARTICIPANT, zkAddr);
- result._manager = manager;
- Thread thread = new Thread(new DummyProcessThread(manager, instanceName));
- result._thread = thread;
- thread.start();
-
- return result;
- }
-
- private static ZkHelixTestManager startHelixController(final String zkConnectString,
- final String clusterName, final String controllerName, final String controllerMode) {
- ZkHelixTestManager manager = null;
- try {
- if (controllerMode.equalsIgnoreCase(HelixControllerMain.STANDALONE)) {
- manager =
- new ZkHelixTestManager(clusterName, controllerName, InstanceType.CONTROLLER,
- zkConnectString);
- manager.connect();
- } else if (controllerMode.equalsIgnoreCase(HelixControllerMain.DISTRIBUTED)) {
- manager =
- new ZkHelixTestManager(clusterName, controllerName,
- InstanceType.CONTROLLER_PARTICIPANT, zkConnectString);
-
- DistClusterControllerStateModelFactory stateModelFactory =
- new DistClusterControllerStateModelFactory(zkConnectString);
-
- StateMachineEngine stateMach = manager.getStateMachineEngine();
- stateMach.registerStateModelFactory("LeaderStandby", stateModelFactory);
- manager.connect();
- } else {
- LOG.error("cluster controller mode:" + controllerMode + " NOT supported");
- }
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- return manager;
- }
-
- // TODO refactor this
- public static StartCMResult startController(final String clusterName,
- final String controllerName, final String zkConnectString, final String controllerMode)
- throws Exception {
- final StartCMResult result = new StartCMResult();
- final ZkHelixTestManager manager =
- startHelixController(zkConnectString, clusterName, controllerName, controllerMode);
- result._manager = manager;
-
- Thread thread = new Thread(new Runnable() {
- @Override
- public void run() {
- // ClusterManager manager = null;
-
- try {
-
- Thread.currentThread().join();
- } catch (InterruptedException e) {
- String msg =
- "controller:" + controllerName + ", " + Thread.currentThread().getName()
- + " interrupted";
- LOG.info(msg);
- // System.err.println(msg);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
-
- thread.start();
- result._thread = thread;
- return result;
- }
-
- public static class StartCMResult {
- public Thread _thread;
- public ZkHelixTestManager _manager;
-
- }
-
public static void setupEmptyCluster(ZkClient zkClient, String clusterName) {
ZKHelixAdmin admin = new ZKHelixAdmin(zkClient);
admin.addCluster(clusterName, true);
@@ -246,11 +159,6 @@ public class TestHelper {
return set;
}
- // public static void verifyWithTimeout(String verifierName, Object... args)
- // {
- // verifyWithTimeout(verifierName, 30 * 1000, args);
- // }
-
/**
* generic method for verification with a timeout
* @param verifierName
@@ -287,8 +195,7 @@ public class TestHelper {
Assert.assertTrue(result);
} catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.error("Exception in verify: " + verifierName, e);
}
}
@@ -309,7 +216,7 @@ public class TestHelper {
try {
ZKHelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(zkClient));
+ new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(zkClient));
Builder keyBuilder = accessor.keyBuilder();
for (String instanceName : instanceNames) {
@@ -392,7 +299,7 @@ public class TestHelper {
try {
ZKHelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(zkClient));
+ new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(zkClient));
Builder keyBuilder = accessor.keyBuilder();
for (String resGroupPartitionKey : stateMap.keySet()) {
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/TestShuffledIdealState.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/TestShuffledIdealState.java b/helix-core/src/test/java/org/apache/helix/TestShuffledIdealState.java
index 5c158f8..b56f98e 100644
--- a/helix-core/src/test/java/org/apache/helix/TestShuffledIdealState.java
+++ b/helix-core/src/test/java/org/apache/helix/TestShuffledIdealState.java
@@ -19,7 +19,6 @@ package org.apache.helix;
* under the License.
*/
-import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
@@ -32,8 +31,6 @@ import org.apache.helix.ZNRecord;
import org.apache.helix.tools.IdealCalculatorByConsistentHashing;
import org.apache.helix.tools.IdealStateCalculatorByRush;
import org.apache.helix.tools.IdealStateCalculatorByShuffling;
-import org.codehaus.jackson.JsonGenerationException;
-import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.testng.Assert;
import org.testng.AssertJUnit;
@@ -73,44 +70,33 @@ public class TestShuffledIdealState {
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
StringWriter sw = new StringWriter();
- try {
- mapper.writeValue(sw, result);
- // System.out.println(sw.toString());
-
- ZNRecord zn = mapper.readValue(new StringReader(sw.toString()), ZNRecord.class);
- System.out.println(result.toString());
- System.out.println(zn.toString());
- AssertJUnit.assertTrue(zn.toString().equalsIgnoreCase(result.toString()));
- System.out.println();
-
- sw = new StringWriter();
- mapper.writeValue(sw, result2);
-
- ZNRecord zn2 = mapper.readValue(new StringReader(sw.toString()), ZNRecord.class);
- System.out.println(result2.toString());
- System.out.println(zn2.toString());
- AssertJUnit.assertTrue(zn2.toString().equalsIgnoreCase(result2.toString()));
-
- sw = new StringWriter();
- mapper.writeValue(sw, result3);
- System.out.println();
-
- ZNRecord zn3 = mapper.readValue(new StringReader(sw.toString()), ZNRecord.class);
- System.out.println(result3.toString());
- System.out.println(zn3.toString());
- AssertJUnit.assertTrue(zn3.toString().equalsIgnoreCase(result3.toString()));
- System.out.println();
-
- } catch (JsonGenerationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (JsonMappingException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ mapper.writeValue(sw, result);
+ // System.out.println(sw.toString());
+
+ ZNRecord zn = mapper.readValue(new StringReader(sw.toString()), ZNRecord.class);
+ System.out.println(result.toString());
+ System.out.println(zn.toString());
+ AssertJUnit.assertTrue(zn.toString().equalsIgnoreCase(result.toString()));
+ System.out.println();
+
+ sw = new StringWriter();
+ mapper.writeValue(sw, result2);
+
+ ZNRecord zn2 = mapper.readValue(new StringReader(sw.toString()), ZNRecord.class);
+ System.out.println(result2.toString());
+ System.out.println(zn2.toString());
+ AssertJUnit.assertTrue(zn2.toString().equalsIgnoreCase(result2.toString()));
+
+ sw = new StringWriter();
+ mapper.writeValue(sw, result3);
+ System.out.println();
+
+ ZNRecord zn3 = mapper.readValue(new StringReader(sw.toString()), ZNRecord.class);
+ System.out.println(result3.toString());
+ System.out.println(zn3.toString());
+ AssertJUnit.assertTrue(zn3.toString().equalsIgnoreCase(result3.toString()));
+ System.out.println();
+
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/TestZkClientWrapper.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/TestZkClientWrapper.java b/helix-core/src/test/java/org/apache/helix/TestZkClientWrapper.java
index f3b0ac9..0bbfd7f 100644
--- a/helix-core/src/test/java/org/apache/helix/TestZkClientWrapper.java
+++ b/helix-core/src/test/java/org/apache/helix/TestZkClientWrapper.java
@@ -24,6 +24,7 @@ import org.I0Itec.zkclient.ZkConnection;
import org.apache.helix.ZNRecord;
import org.apache.helix.manager.zk.ZNRecordSerializer;
import org.apache.helix.manager.zk.ZkClient;
+import org.apache.log4j.Logger;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.Watcher.Event.KeeperState;
@@ -35,6 +36,8 @@ import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class TestZkClientWrapper extends ZkUnitTestBase {
+ private static Logger LOG = Logger.getLogger(TestZkClientWrapper.class);
+
ZkClient _zkClient;
@BeforeClass
@@ -70,7 +73,7 @@ public class TestZkClientWrapper extends ZkUnitTestBase {
}
@Test()
- void testSessioExpire() {
+ void testSessioExpire() throws Exception {
IZkStateListener listener = new IZkStateListener() {
@Override
@@ -83,31 +86,27 @@ public class TestZkClientWrapper extends ZkUnitTestBase {
System.out.println("In Old connection New session");
}
};
+
_zkClient.subscribeStateChanges(listener);
ZkConnection connection = ((ZkConnection) _zkClient.getConnection());
ZooKeeper zookeeper = connection.getZookeeper();
System.out.println("old sessionId= " + zookeeper.getSessionId());
- try {
- Watcher watcher = new Watcher() {
- @Override
- public void process(WatchedEvent event) {
- System.out.println("In New connection In process event:" + event);
- }
- };
- ZooKeeper newZookeeper =
- new ZooKeeper(connection.getServers(), zookeeper.getSessionTimeout(), watcher,
- zookeeper.getSessionId(), zookeeper.getSessionPasswd());
- Thread.sleep(3000);
- System.out.println("New sessionId= " + newZookeeper.getSessionId());
- Thread.sleep(3000);
- newZookeeper.close();
- Thread.sleep(10000);
- connection = ((ZkConnection) _zkClient.getConnection());
- zookeeper = connection.getZookeeper();
- System.out.println("After session expiry sessionId= " + zookeeper.getSessionId());
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ Watcher watcher = new Watcher() {
+ @Override
+ public void process(WatchedEvent event) {
+ System.out.println("In New connection In process event:" + event);
+ }
+ };
+ ZooKeeper newZookeeper =
+ new ZooKeeper(connection.getServers(), zookeeper.getSessionTimeout(), watcher,
+ zookeeper.getSessionId(), zookeeper.getSessionPasswd());
+ Thread.sleep(3000);
+ System.out.println("New sessionId= " + newZookeeper.getSessionId());
+ Thread.sleep(3000);
+ newZookeeper.close();
+ Thread.sleep(10000);
+ connection = ((ZkConnection) _zkClient.getConnection());
+ zookeeper = connection.getZookeeper();
+ System.out.println("After session expiry sessionId= " + zookeeper.getSessionId());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/TestZnodeModify.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/TestZnodeModify.java b/helix-core/src/test/java/org/apache/helix/TestZnodeModify.java
index 7d66ebd..5b4b165 100644
--- a/helix-core/src/test/java/org/apache/helix/TestZnodeModify.java
+++ b/helix-core/src/test/java/org/apache/helix/TestZnodeModify.java
@@ -216,8 +216,7 @@ public class TestZnodeModify extends ZkUnitTestBase {
zkClient.createPersistent(pathChild1, true);
zkClient.writeData(pathChild1, record);
} catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ logger.error("Interrupted sleep", e);
}
}
}.start();
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/ZkHelixTestManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/ZkHelixTestManager.java b/helix-core/src/test/java/org/apache/helix/ZkHelixTestManager.java
deleted file mode 100644
index b660a1d..0000000
--- a/helix-core/src/test/java/org/apache/helix/ZkHelixTestManager.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package org.apache.helix;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.List;
-
-import org.apache.helix.manager.zk.CallbackHandler;
-import org.apache.helix.manager.zk.ZKHelixManager;
-import org.apache.helix.manager.zk.ZkClient;
-
-// ZkHelixManager used for test only. expose more class members
-public class ZkHelixTestManager extends ZKHelixManager {
-
- public ZkHelixTestManager(String clusterName, String instanceName, InstanceType instanceType,
- String zkConnectString) throws Exception {
- super(clusterName, instanceName, instanceType, zkConnectString);
- // TODO Auto-generated constructor stub
- }
-
- public ZkClient getZkClient() {
- return _zkClient;
- }
-
- public List<CallbackHandler> getHandlers() {
- return _handlers;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/controller/stages/DummyClusterManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/controller/stages/DummyClusterManager.java b/helix-core/src/test/java/org/apache/helix/controller/stages/DummyClusterManager.java
index 26da8ee..fc9b7d5 100644
--- a/helix-core/src/test/java/org/apache/helix/controller/stages/DummyClusterManager.java
+++ b/helix-core/src/test/java/org/apache/helix/controller/stages/DummyClusterManager.java
@@ -254,4 +254,10 @@ public class DummyClusterManager implements HelixManager {
// TODO Auto-generated method stub
return null;
}
+
+ @Override
+ public void addControllerMessageListener(MessageListener listener) {
+ // TODO Auto-generated method stub
+
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/controller/stages/TestParseInfoFromAlert.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/controller/stages/TestParseInfoFromAlert.java b/helix-core/src/test/java/org/apache/helix/controller/stages/TestParseInfoFromAlert.java
index d191345..eb2f6fe 100644
--- a/helix-core/src/test/java/org/apache/helix/controller/stages/TestParseInfoFromAlert.java
+++ b/helix-core/src/test/java/org/apache/helix/controller/stages/TestParseInfoFromAlert.java
@@ -28,26 +28,28 @@ import org.testng.annotations.Test;
public class TestParseInfoFromAlert extends ZkStandAloneCMTestBase {
@Test
public void TestParse() {
- StatsAggregationStage stage = new StatsAggregationStage();
- String controllerName = CONTROLLER_PREFIX + "_0";
- HelixManager manager = _startCMResultMap.get(controllerName)._manager;
+ HelixManager manager = _controller;
String instanceName =
- stage.parseInstanceName("localhost_12918.TestStat@DB=123.latency", manager);
+ StatsAggregationStage.parseInstanceName("localhost_12918.TestStat@DB=123.latency", manager);
Assert.assertTrue(instanceName.equals("localhost_12918"));
- instanceName = stage.parseInstanceName("localhost_12955.TestStat@DB=123.latency", manager);
+ instanceName =
+ StatsAggregationStage.parseInstanceName("localhost_12955.TestStat@DB=123.latency", manager);
Assert.assertTrue(instanceName == null);
- instanceName = stage.parseInstanceName("localhost_12922.TestStat@DB=123.latency", manager);
+ instanceName =
+ StatsAggregationStage.parseInstanceName("localhost_12922.TestStat@DB=123.latency", manager);
Assert.assertTrue(instanceName.equals("localhost_12922"));
String resourceName =
- stage.parseResourceName("localhost_12918.TestStat@DB=TestDB.latency", manager);
+ StatsAggregationStage.parseResourceName("localhost_12918.TestStat@DB=TestDB.latency",
+ manager);
Assert.assertTrue(resourceName.equals("TestDB"));
String partitionName =
- stage.parsePartitionName("localhost_12918.TestStat@DB=TestDB;Partition=TestDB_22.latency",
+ StatsAggregationStage.parsePartitionName(
+ "localhost_12918.TestStat@DB=TestDB;Partition=TestDB_22.latency",
manager);
Assert.assertTrue(partitionName.equals("TestDB_22"));
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/controller/stages/TestRebalancePipeline.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/controller/stages/TestRebalancePipeline.java b/helix-core/src/test/java/org/apache/helix/controller/stages/TestRebalancePipeline.java
index fccd0c7..1a11be3 100644
--- a/helix-core/src/test/java/org/apache/helix/controller/stages/TestRebalancePipeline.java
+++ b/helix-core/src/test/java/org/apache/helix/controller/stages/TestRebalancePipeline.java
@@ -29,7 +29,6 @@ import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.ZkUnitTestBase;
import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.controller.HelixControllerMain;
import org.apache.helix.controller.pipeline.Pipeline;
import org.apache.helix.controller.stages.AttributeName;
import org.apache.helix.controller.stages.BestPossibleStateCalcStage;
@@ -42,6 +41,7 @@ import org.apache.helix.controller.stages.MessageThrottleStage;
import org.apache.helix.controller.stages.ReadClusterDataStage;
import org.apache.helix.controller.stages.ResourceComputationStage;
import org.apache.helix.controller.stages.TaskAssignmentStage;
+import org.apache.helix.integration.manager.ClusterControllerManager;
import org.apache.helix.manager.zk.ZKHelixAdmin;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
@@ -63,7 +63,7 @@ public class TestRebalancePipeline extends ZkUnitTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
HelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_gZkClient));
+ new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
HelixManager manager = new DummyClusterManager(clusterName, accessor);
ClusterEvent event = new ClusterEvent("testEvent");
@@ -136,7 +136,7 @@ public class TestRebalancePipeline extends ZkUnitTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
HelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_gZkClient));
+ new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
HelixManager manager = new DummyClusterManager(clusterName, accessor);
ClusterEvent event = new ClusterEvent("testEvent");
@@ -160,8 +160,9 @@ public class TestRebalancePipeline extends ZkUnitTestBase {
0, 1
});
- TestHelper
- .startController(clusterName, "controller_0", ZK_ADDR, HelixControllerMain.STANDALONE);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+ controller.syncStart();
// round1: controller sends O->S to both node0 and node1
Thread.sleep(1000);
@@ -211,7 +212,7 @@ public class TestRebalancePipeline extends ZkUnitTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
HelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_gZkClient));
+ new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
HelixManager manager = new DummyClusterManager(clusterName, accessor);
ClusterEvent event = new ClusterEvent("testEvent");
event.addAttribute("helixmanager", manager);
@@ -306,7 +307,7 @@ public class TestRebalancePipeline extends ZkUnitTestBase {
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
HelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_gZkClient));
+ new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
HelixManager manager = new DummyClusterManager(clusterName, accessor);
ClusterEvent event = new ClusterEvent("testEvent");
event.addAttribute("helixmanager", manager);
@@ -376,7 +377,7 @@ public class TestRebalancePipeline extends ZkUnitTestBase {
protected void setCurrentState(String clusterName, String instance, String resourceGroupName,
String resourceKey, String sessionId, String state) {
ZKHelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_gZkClient));
+ new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
CurrentState curState = new CurrentState(resourceGroupName);
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/579baa5b/helix-core/src/test/java/org/apache/helix/healthcheck/TestAddDropAlert.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/healthcheck/TestAddDropAlert.java b/helix-core/src/test/java/org/apache/helix/healthcheck/TestAddDropAlert.java
index d5a1b08..8e0b04f 100644
--- a/helix-core/src/test/java/org/apache/helix/healthcheck/TestAddDropAlert.java
+++ b/helix-core/src/test/java/org/apache/helix/healthcheck/TestAddDropAlert.java
@@ -29,17 +29,13 @@ import org.apache.helix.NotificationContext;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.TestHelper.StartCMResult;
-import org.apache.helix.controller.HelixControllerMain;
-import org.apache.helix.healthcheck.HealthStatsAggregationTask;
import org.apache.helix.healthcheck.ParticipantHealthReportCollectorImpl;
import org.apache.helix.integration.ZkIntegrationTestBase;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
-import org.apache.helix.manager.zk.ZNRecordSerializer;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
-import org.apache.helix.manager.zk.ZkClient;
import org.apache.helix.mock.participant.MockEspressoHealthReportProvider;
-import org.apache.helix.mock.participant.MockParticipant;
import org.apache.helix.mock.participant.MockTransition;
import org.apache.helix.model.Message;
import org.apache.helix.tools.ClusterSetup;
@@ -50,7 +46,6 @@ import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class TestAddDropAlert extends ZkIntegrationTestBase {
- ZkClient _zkClient;
protected ClusterSetup _setupTool = null;
protected final String _alertStr =
"EXP(accumulate()(localhost_12918.RestQueryStats@DBName=TestDB0.latency))CMP(GREATER)CON(10)";
@@ -59,15 +54,11 @@ public class TestAddDropAlert extends ZkIntegrationTestBase {
@BeforeClass()
public void beforeClass() throws Exception {
- _zkClient = new ZkClient(ZK_ADDR);
- _zkClient.setZkSerializer(new ZNRecordSerializer());
-
- _setupTool = new ClusterSetup(ZK_ADDR);
+ _setupTool = new ClusterSetup(_gZkClient);
}
@AfterClass
public void afterClass() {
- _zkClient.close();
}
public class AddDropAlertTransition extends MockTransition {
@@ -115,7 +106,7 @@ public class TestAddDropAlert extends ZkIntegrationTestBase {
@Test()
public void testAddDropAlert() throws Exception {
String clusterName = getShortClassName();
- MockParticipant[] participants = new MockParticipant[5];
+ MockParticipantManager[] participants = new MockParticipantManager[5];
System.out.println("START TestAddDropAlert at " + new Date(System.currentTimeMillis()));
@@ -131,18 +122,18 @@ public class TestAddDropAlert extends ZkIntegrationTestBase {
_setupTool.getClusterManagementTool().addAlert(clusterName, _alertStr);
- StartCMResult cmResult =
- TestHelper.startController(clusterName, "controller_0", ZK_ADDR,
- HelixControllerMain.STANDALONE);
+ ClusterControllerManager controller =
+ new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+ controller.syncStart();
+
// start participants
for (int i = 0; i < 5; i++) // !!!change back to 5
{
String instanceName = "localhost_" + (12918 + i);
- participants[i] =
- new MockParticipant(clusterName, instanceName, ZK_ADDR, new AddDropAlertTransition());
+ participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
+ participants[i].setTransition(new AddDropAlertTransition());
participants[i].syncStart();
- // new Thread(participants[i]).start();
}
boolean result =
@@ -153,10 +144,10 @@ public class TestAddDropAlert extends ZkIntegrationTestBase {
// drop alert soon after adding, but leave enough time for alert to fire once
// Thread.sleep(3000);
ZKHelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_zkClient));
+ new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
- new HealthStatsAggregator(cmResult._manager).aggregate();
+ new HealthStatsAggregator(controller).aggregate();
String instance = "localhost_12918";
ZNRecord record = accessor.getProperty(keyBuilder.alertStatus()).getRecord();
Map<String, Map<String, String>> recMap = record.getMapFields();
@@ -164,7 +155,7 @@ public class TestAddDropAlert extends ZkIntegrationTestBase {
Assert.assertTrue(keySet.size() > 0);
_setupTool.getClusterManagementTool().dropAlert(clusterName, _alertStr);
- new HealthStatsAggregator(cmResult._manager).aggregate();
+ new HealthStatsAggregator(controller).aggregate();
// other verifications go here
// for (int i = 0; i < 1; i++) //change 1 back to 5
// {