use of org.apache.helix.integration.manager.ClusterControllerManager in project helix by apache.
the class TestZkFlapping method testControllerFlapping.
@Test
public void testControllerFlapping() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
final HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
final PropertyKey.Builder keyBuilder = accessor.keyBuilder();
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
// participant port
TestHelper.setupCluster(// participant port
clusterName, // participant port
ZK_ADDR, // participant port
12918, // participant name prefix
"localhost", // resource name prefix
"TestDB", // resources
1, // partitions per resource
32, // number of nodes
1, // replicas
1, "MasterSlave", false);
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller");
controller.syncStart();
final ZkClient client = controller.getZkClient();
final ZkStateCountListener listener = new ZkStateCountListener();
client.subscribeStateChanges(listener);
final AtomicInteger expectDisconnectCnt = new AtomicInteger(0);
final int n = ZKHelixManager.MAX_DISCONNECT_THRESHOLD;
for (int i = 0; i < n; i++) {
String oldSessionId = ZkTestHelper.getSessionId(client);
ZkTestHelper.simulateZkStateDisconnected(client);
expectDisconnectCnt.incrementAndGet();
// wait until we get invoked by zk state change to disconnected
TestHelper.verify(new Verifier() {
@Override
public boolean verify() throws Exception {
return listener.count == expectDisconnectCnt.get();
}
}, 30 * 1000);
String newSessionId = ZkTestHelper.getSessionId(client);
Assert.assertEquals(newSessionId, oldSessionId);
}
// make sure controller is NOT disconnected
LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
Assert.assertNotNull(leader, "Leader should exist after " + n + " disconnects");
// trigger flapping
ZkTestHelper.simulateZkStateDisconnected(client);
// wait until we get invoked by zk state change to disconnected
boolean success = TestHelper.verify(new Verifier() {
@Override
public boolean verify() throws Exception {
return client.getShutdownTrigger();
}
}, 30 * 1000);
Assert.assertTrue(success, "The " + (n + 1) + "th disconnect event should trigger ZkHelixManager#disonnect");
// make sure controller is disconnected
success = TestHelper.verify(new TestHelper.Verifier() {
@Override
public boolean verify() throws Exception {
LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
return leader == null;
}
}, 5 * 1000);
Assert.assertTrue(success, "Leader should be gone after " + (n + 1) + " disconnects");
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.integration.manager.ClusterControllerManager in project helix by apache.
the class TestZkManagerFlappingDetection method testDisconnectFlappingWindowController.
// 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 {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
final String clusterName = className + "_" + methodName;
// participant port
TestHelper.setupCluster(// participant port
clusterName, // participant port
ZK_ADDR, // participant port
12918, // participant name prefix
"localhost", // resource name prefix
"TestDB", // resources
1, // partitions per resource
10, // number of nodes
5, // replicas
3, "MasterSlave", // do rebalance
true);
// flapping time window to 5 sec
System.setProperty("helixmanager.flappingTimeWindow", "5000");
System.setProperty("helixmanager.maxDisconnectThreshold", "3");
ClusterControllerManager manager2 = new ClusterControllerManager(ZK_ADDR, clusterName, null);
manager2.connect();
Thread.sleep(100);
ZkClient zkClient = manager2.getZkClient();
for (int i = 0; i < 2; i++) {
ZkTestHelper.expireSession(zkClient);
Thread.sleep(500);
Assert.assertTrue(manager2.isConnected());
}
Thread.sleep(5000);
// Old entries should be cleaned up
for (int i = 0; i < 3; i++) {
ZkTestHelper.expireSession(zkClient);
Thread.sleep(500);
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());
}
use of org.apache.helix.integration.manager.ClusterControllerManager in project helix by apache.
the class TestDropResourceMetricsReset method testBasic.
@Test
public void testBasic() throws Exception {
final int NUM_PARTICIPANTS = 4;
final int NUM_PARTITIONS = 64;
final int NUM_REPLICAS = 1;
final String RESOURCE_NAME = "TestDB0";
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
ParticipantMonitorListener listener = new ParticipantMonitorListener("ClusterStatus", clusterName, RESOURCE_NAME);
// Set up cluster
// participant port
TestHelper.setupCluster(// participant port
clusterName, // participant port
ZK_ADDR, // participant port
12918, // participant name prefix
"localhost", // resource name prefix
"TestDB", // resources
1, // partitions per resource
NUM_PARTITIONS, // number of nodes
NUM_PARTICIPANTS, // replicas
NUM_REPLICAS, // use FULL_AUTO mode to test node tagging
"MasterSlave", // use FULL_AUTO mode to test node tagging
RebalanceMode.FULL_AUTO, // do rebalance
true);
// Start participants and controller
ClusterSetup setupTool = new ClusterSetup(_gZkClient);
MockParticipantManager[] participants = new MockParticipantManager[NUM_PARTICIPANTS];
for (int i = 0; i < NUM_PARTICIPANTS; i++) {
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, "localhost_" + (12918 + i));
participants[i].syncStart();
}
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// Verify that the bean was created
boolean noTimeout = _registerLatch.await(30000, TimeUnit.MILLISECONDS);
Assert.assertTrue(noTimeout);
// Drop the resource
setupTool.dropResourceFromCluster(clusterName, RESOURCE_NAME);
// Verify that the bean was removed
noTimeout = _unregisterLatch.await(30000, TimeUnit.MILLISECONDS);
Assert.assertTrue(noTimeout);
// Clean up
listener.disconnect();
controller.syncStop();
for (MockParticipantManager participant : participants) {
participant.syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.integration.manager.ClusterControllerManager in project helix by apache.
the class TestResetClusterMetrics method testControllerDisconnect.
/**
* Ensure cluster status lifecycle is tied to controller leader status
*/
@Test
public void testControllerDisconnect() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
// Set up a cluster with one of everything
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, "localhost", "Resource", 1, 1, 1, 1, "OnlineOffline", RebalanceMode.FULL_AUTO, true);
// Add a participant
MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, clusterName, "localhost_12918");
participant.syncStart();
// Add a controller
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// Make sure everything gets assigned
Thread.sleep(1000);
boolean result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
// Check the metrics
Assert.assertTrue(metricsExist(clusterName, participant.getInstanceName()));
// Stop the controller
controller.syncStop();
// Check the metrics
Thread.sleep(1000);
Assert.assertFalse(metricsExist(clusterName, participant.getInstanceName()));
}
use of org.apache.helix.integration.manager.ClusterControllerManager in project helix by apache.
the class TestCorrectnessOnConnectivityLoss method beforeMethod.
@BeforeMethod
public void beforeMethod() throws Exception {
_zkServer = TestHelper.startZkServer(ZK_ADDR);
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
_clusterName = className + "_" + methodName;
// participant start port
TestHelper.setupCluster(// participant start port
_clusterName, // participant start port
ZK_ADDR, // participant start port
12918, // participant host
"localhost", // resource name prefix
"resource", // number of resources
1, // number of partitions
1, // number of participants
1, // number of replicas
1, // state model
"OnlineOffline", // automatic assignment
RebalanceMode.FULL_AUTO, // rebalance
true);
_controller = new ClusterControllerManager(ZK_ADDR, _clusterName, "controller0");
_controller.connect();
}
Aggregations