Search in sources :

Example 6 with ClusterControllerManager

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()));
}
Also used : Verifier(org.apache.helix.TestHelper.Verifier) Date(java.util.Date) ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) HelixDataAccessor(org.apache.helix.HelixDataAccessor) LiveInstance(org.apache.helix.model.LiveInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ZNRecord(org.apache.helix.ZNRecord) PropertyKey(org.apache.helix.PropertyKey) Test(org.testng.annotations.Test)

Example 7 with ClusterControllerManager

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());
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager)

Example 8 with ClusterControllerManager

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()));
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) ClusterSetup(org.apache.helix.tools.ClusterSetup) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 9 with ClusterControllerManager

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()));
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) ClusterStateVerifier(org.apache.helix.tools.ClusterStateVerifier) Test(org.testng.annotations.Test)

Example 10 with ClusterControllerManager

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();
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)125 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)101 Date (java.util.Date)88 Test (org.testng.annotations.Test)78 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)38 BeforeClass (org.testng.annotations.BeforeClass)37 ZNRecord (org.apache.helix.ZNRecord)33 ClusterSetup (org.apache.helix.tools.ClusterSetup)33 ClusterStateVerifier (org.apache.helix.tools.ClusterStateVerifier)30 BestPossAndExtViewZkVerifier (org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier)28 HashMap (java.util.HashMap)26 IdealState (org.apache.helix.model.IdealState)24 HelixDataAccessor (org.apache.helix.HelixDataAccessor)19 PropertyKey (org.apache.helix.PropertyKey)19 Map (java.util.Map)18 HelixClusterVerifier (org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier)17 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)15 BestPossibleExternalViewVerifier (org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier)15 Set (java.util.Set)14 ConfigAccessor (org.apache.helix.ConfigAccessor)14