Search in sources :

Example 11 with ErrTransition

use of org.apache.helix.mock.participant.ErrTransition in project helix by apache.

the class TestResetInstance method testResetInstance.

@Test
public void testResetInstance() throws Exception {
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    final int n = 5;
    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
    10, // number of nodes
    n, // replicas
    3, "MasterSlave", // do rebalance
    true);
    // start controller
    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
    controller.syncStart();
    Map<String, Set<String>> errPartitions = new HashMap<String, Set<String>>() {

        {
            put("SLAVE-MASTER", TestHelper.setOf("TestDB0_4"));
            put("OFFLINE-SLAVE", TestHelper.setOf("TestDB0_8"));
        }
    };
    // start mock participants
    MockParticipantManager[] participants = new MockParticipantManager[n];
    for (int i = 0; i < n; i++) {
        String instanceName = "localhost_" + (12918 + i);
        if (i == 0) {
            participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
            participants[i].setTransition(new ErrTransition(errPartitions));
        } else {
            participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
        }
        participants[i].syncStart();
    }
    // verify cluster
    Map<String, Map<String, String>> errStateMap = new HashMap<String, Map<String, String>>();
    errStateMap.put("TestDB0", new HashMap<String, String>());
    errStateMap.get("TestDB0").put("TestDB0_4", "localhost_12918");
    errStateMap.get("TestDB0").put("TestDB0_8", "localhost_12918");
    boolean result = ClusterStateVerifier.verifyByZkCallback((new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName, errStateMap)));
    Assert.assertTrue(result, "Cluster verification fails");
    // reset node "localhost_12918"
    participants[0].setTransition(null);
    String command = "--zkSvr " + ZK_ADDR + " --resetInstance " + clusterName + " localhost_12918";
    ClusterSetup.processCommandLineArgs(command.split("\\s+"));
    result = ClusterStateVerifier.verifyByZkCallback((new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName)));
    Assert.assertTrue(result, "Cluster verification fails");
    // clean up
    controller.syncStop();
    for (int i = 0; i < 5; i++) {
        participants[i].syncStop();
    }
    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Also used : Set(java.util.Set) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) HashMap(java.util.HashMap) ClusterStateVerifier(org.apache.helix.tools.ClusterStateVerifier) ErrTransition(org.apache.helix.mock.participant.ErrTransition) Date(java.util.Date) ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 12 with ErrTransition

use of org.apache.helix.mock.participant.ErrTransition in project helix by apache.

the class TestResetResource method testResetNode.

@Test
public void testResetNode() throws Exception {
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    final int n = 5;
    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
    10, // number of nodes
    n, // replicas
    3, "MasterSlave", // do rebalance
    true);
    // start controller
    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
    controller.syncStart();
    Map<String, Set<String>> errPartitions = new HashMap<String, Set<String>>() {

        {
            put("SLAVE-MASTER", TestHelper.setOf("TestDB0_4"));
            put("OFFLINE-SLAVE", TestHelper.setOf("TestDB0_8"));
        }
    };
    // start mock participants
    MockParticipantManager[] participants = new MockParticipantManager[n];
    for (int i = 0; i < n; i++) {
        String instanceName = "localhost_" + (12918 + i);
        if (i == 0) {
            participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
            participants[i].setTransition(new ErrTransition(errPartitions));
        } else {
            participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
        }
        participants[i].syncStart();
    }
    // verify cluster
    Map<String, Map<String, String>> errStateMap = new HashMap<String, Map<String, String>>();
    errStateMap.put("TestDB0", new HashMap<String, String>());
    errStateMap.get("TestDB0").put("TestDB0_4", "localhost_12918");
    errStateMap.get("TestDB0").put("TestDB0_8", "localhost_12918");
    boolean result = ClusterStateVerifier.verifyByZkCallback((new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName, errStateMap)));
    Assert.assertTrue(result, "Cluster verification fails");
    // reset resource "TestDB0"
    participants[0].setTransition(null);
    String command = "--zkSvr " + ZK_ADDR + " --resetResource " + clusterName + " TestDB0";
    ClusterSetup.processCommandLineArgs(command.split("\\s+"));
    result = ClusterStateVerifier.verifyByZkCallback((new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName)));
    Assert.assertTrue(result, "Cluster verification fails");
    // clean up
    controller.syncStop();
    for (int i = 0; i < 5; i++) {
        participants[i].syncStop();
    }
    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Also used : Set(java.util.Set) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) HashMap(java.util.HashMap) ClusterStateVerifier(org.apache.helix.tools.ClusterStateVerifier) ErrTransition(org.apache.helix.mock.participant.ErrTransition) Date(java.util.Date) ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 13 with ErrTransition

use of org.apache.helix.mock.participant.ErrTransition in project helix by apache.

the class TestResetResource method testResetNode.

@Test
public void testResetNode() throws Exception {
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    final int n = 5;
    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
    10, // number of nodes
    n, // replicas
    3, "MasterSlave", // do rebalance
    true);
    // start controller
    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
    controller.syncStart();
    Map<String, Set<String>> errPartitions = new HashMap<String, Set<String>>() {

        {
            put("SLAVE-MASTER", TestHelper.setOf("TestDB0_4"));
            put("OFFLINE-SLAVE", TestHelper.setOf("TestDB0_8"));
        }
    };
    // start mock participants
    MockParticipantManager[] participants = new MockParticipantManager[n];
    for (int i = 0; i < n; i++) {
        String instanceName = "localhost_" + (12918 + i);
        if (i == 0) {
            participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
            participants[i].setTransition(new ErrTransition(errPartitions));
        } else {
            participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
        }
        participants[i].syncStart();
    }
    // verify cluster
    Map<String, Map<String, String>> errStateMap = new HashMap<String, Map<String, String>>();
    errStateMap.put("TestDB0", new HashMap<String, String>());
    errStateMap.get("TestDB0").put("TestDB0_4", "localhost_12918");
    errStateMap.get("TestDB0").put("TestDB0_8", "localhost_12918");
    boolean result = ClusterStateVerifier.verifyByZkCallback((new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName, errStateMap)));
    Assert.assertTrue(result, "Cluster verification fails");
    // reset resource "TestDB0"
    participants[0].setTransition(null);
    String resourceName = "TestDB0";
    String resourceUrl = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/resourceGroups/" + resourceName;
    Map<String, String> paramMap = new HashMap<String, String>();
    paramMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.resetResource);
    TestHelixAdminScenariosRest.assertSuccessPostOperation(resourceUrl, paramMap, false);
    result = ClusterStateVerifier.verifyByZkCallback((new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName)));
    Assert.assertTrue(result, "Cluster verification fails");
    // clean up
    controller.syncStop();
    for (int i = 0; i < 5; i++) {
        participants[i].syncStop();
    }
    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Also used : Set(java.util.Set) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) HashMap(java.util.HashMap) ClusterStateVerifier(org.apache.helix.tools.ClusterStateVerifier) ErrTransition(org.apache.helix.mock.participant.ErrTransition) Date(java.util.Date) ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Aggregations

ErrTransition (org.apache.helix.mock.participant.ErrTransition)13 Test (org.testng.annotations.Test)13 Date (java.util.Date)12 HashMap (java.util.HashMap)12 Map (java.util.Map)12 Set (java.util.Set)12 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)12 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)12 ClusterStateVerifier (org.apache.helix.tools.ClusterStateVerifier)7 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)4 BestPossibleExternalViewVerifier (org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier)4 HelixClusterVerifier (org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier)3 PropertyKey (org.apache.helix.PropertyKey)2 ZNRecord (org.apache.helix.ZNRecord)2 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)2 BestPossAndExtViewZkVerifier (org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier)2 HashSet (java.util.HashSet)1 TreeMap (java.util.TreeMap)1 HelixAdmin (org.apache.helix.HelixAdmin)1 HelixDataAccessor (org.apache.helix.HelixDataAccessor)1