Search in sources :

Example 16 with HelixClusterVerifier

use of org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier in project helix by apache.

the class TestCrushAutoRebalance method testLackEnoughLiveRacks.

@Test(dependsOnMethods = { "testZoneIsolation", "testZoneIsolationWithInstanceTag" })
public void testLackEnoughLiveRacks() throws Exception {
    System.out.println("TestLackEnoughInstances");
    enablePersistBestPossibleAssignment(_gZkClient, CLUSTER_NAME, true);
    // shutdown participants within one zone
    String zone = _nodeToZoneMap.values().iterator().next();
    for (int i = 0; i < _participants.size(); i++) {
        MockParticipantManager p = _participants.get(i);
        if (_nodeToZoneMap.get(p.getInstanceName()).equals(zone)) {
            p.syncStop();
        }
    }
    int i = 0;
    for (String stateModel : _testModels) {
        String db = "Test-DB-CrushRebalanceStrategy-" + i++;
        _setupTool.addResourceToCluster(CLUSTER_NAME, db, _PARTITIONS, stateModel, RebalanceMode.FULL_AUTO + "", CrushRebalanceStrategy.class.getName());
        _setupTool.rebalanceStorageCluster(CLUSTER_NAME, db, _replica);
        _allDBs.add(db);
    }
    Thread.sleep(300);
    HelixClusterVerifier _clusterVerifier = new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).setResources(_allDBs).build();
    Assert.assertTrue(_clusterVerifier.verify());
    for (String db : _allDBs) {
        IdealState is = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, db);
        ExternalView ev = _setupTool.getClusterManagementTool().getResourceExternalView(CLUSTER_NAME, db);
        validateZoneAndTagIsolation(is, ev, 2);
    }
}
Also used : ExternalView(org.apache.helix.model.ExternalView) HelixClusterVerifier(org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) BestPossibleExternalViewVerifier(org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier) IdealState(org.apache.helix.model.IdealState) Test(org.testng.annotations.Test)

Example 17 with HelixClusterVerifier

use of org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier in project helix by apache.

the class TestCrushAutoRebalanceNonRack method testLackEnoughInstances.

@Test(dataProvider = "rebalanceStrategies", enabled = true, dependsOnMethods = { "testLackEnoughLiveInstances" })
public void testLackEnoughInstances(String rebalanceStrategyName, String rebalanceStrategyClass) throws Exception {
    System.out.println("TestLackEnoughInstances " + rebalanceStrategyName);
    enablePersistBestPossibleAssignment(_gZkClient, CLUSTER_NAME, true);
    // shutdown participants, keep only two left
    for (int i = 2; i < _participants.size(); i++) {
        MockParticipantManager p = _participants.get(i);
        p.syncStop();
        _setupTool.getClusterManagementTool().enableInstance(CLUSTER_NAME, p.getInstanceName(), false);
        Thread.sleep(50);
        _setupTool.dropInstanceFromCluster(CLUSTER_NAME, p.getInstanceName());
    }
    int j = 0;
    for (String stateModel : _testModels) {
        String db = "Test-DB-" + rebalanceStrategyName + "-" + j++;
        _setupTool.addResourceToCluster(CLUSTER_NAME, db, _PARTITIONS, stateModel, RebalanceMode.FULL_AUTO + "", rebalanceStrategyClass);
        _setupTool.rebalanceStorageCluster(CLUSTER_NAME, db, _replica);
        _allDBs.add(db);
    }
    Thread.sleep(300);
    HelixClusterVerifier _clusterVerifier = new StrictMatchExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).setResources(_allDBs).build();
    Assert.assertTrue(_clusterVerifier.verify());
    for (String db : _allDBs) {
        IdealState is = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, db);
        ExternalView ev = _setupTool.getClusterManagementTool().getResourceExternalView(CLUSTER_NAME, db);
        validateIsolation(is, ev, 2);
    }
    // recover test environment
    ConfigAccessor configAccessor = new ConfigAccessor(_gZkClient);
    for (int i = 2; i < _participants.size(); i++) {
        String storageNodeName = _participants.get(i).getInstanceName();
        _setupTool.addInstanceToCluster(CLUSTER_NAME, storageNodeName);
        InstanceConfig instanceConfig = configAccessor.getInstanceConfig(CLUSTER_NAME, storageNodeName);
        instanceConfig.setDomain("instance=" + storageNodeName);
        configAccessor.setInstanceConfig(CLUSTER_NAME, storageNodeName, instanceConfig);
        MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, CLUSTER_NAME, storageNodeName);
        participant.syncStart();
        _participants.set(i, participant);
    }
}
Also used : StrictMatchExternalViewVerifier(org.apache.helix.tools.ClusterVerifiers.StrictMatchExternalViewVerifier) HelixClusterVerifier(org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) ConfigAccessor(org.apache.helix.ConfigAccessor) Test(org.testng.annotations.Test)

Example 18 with HelixClusterVerifier

use of org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier in project helix by apache.

the class TestCrushAutoRebalanceNonRack method testLackEnoughLiveInstances.

@Test(dataProvider = "rebalanceStrategies", enabled = true, dependsOnMethods = { "testWithInstanceTag" })
public void testLackEnoughLiveInstances(String rebalanceStrategyName, String rebalanceStrategyClass) throws Exception {
    System.out.println("TestLackEnoughLiveInstances " + rebalanceStrategyName);
    enablePersistBestPossibleAssignment(_gZkClient, CLUSTER_NAME, true);
    // shutdown participants, keep only two left
    for (int i = 2; i < _participants.size(); i++) {
        _participants.get(i).syncStop();
    }
    int j = 0;
    for (String stateModel : _testModels) {
        String db = "Test-DB-" + rebalanceStrategyName + "-" + j++;
        _setupTool.addResourceToCluster(CLUSTER_NAME, db, _PARTITIONS, stateModel, RebalanceMode.FULL_AUTO + "", rebalanceStrategyClass);
        _setupTool.rebalanceStorageCluster(CLUSTER_NAME, db, _replica);
        _allDBs.add(db);
    }
    Thread.sleep(300);
    HelixClusterVerifier _clusterVerifier = new StrictMatchExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).setResources(_allDBs).build();
    Assert.assertTrue(_clusterVerifier.verify(5000));
    for (String db : _allDBs) {
        IdealState is = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, db);
        ExternalView ev = _setupTool.getClusterManagementTool().getResourceExternalView(CLUSTER_NAME, db);
        validateIsolation(is, ev, 2);
    }
    for (int i = 2; i < _participants.size(); i++) {
        _participants.get(i).syncStart();
    }
}
Also used : StrictMatchExternalViewVerifier(org.apache.helix.tools.ClusterVerifiers.StrictMatchExternalViewVerifier) HelixClusterVerifier(org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier) Test(org.testng.annotations.Test)

Example 19 with HelixClusterVerifier

use of org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier in project helix by apache.

the class TestZkConnectionLost method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    _participants = new MockParticipantManager[_numNodes];
    String namespace = "/" + CLUSTER_NAME;
    if (_gZkClient.exists(namespace)) {
        _gZkClient.deleteRecursively(namespace);
    }
    _setupTool = new ClusterSetup(ZK_ADDR);
    _setupTool.addCluster(CLUSTER_NAME, true);
    setupParticipants();
    setupDBs();
    createManagers();
    // start controller
    String controllerName = CONTROLLER_PREFIX + "_0";
    _controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, controllerName);
    _controller.syncStart();
    HelixClusterVerifier clusterVerifier = new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).build();
    Assert.assertTrue(clusterVerifier.verify());
    _zkServerRef.set(_zkServer);
}
Also used : ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) HelixClusterVerifier(org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier) ClusterSetup(org.apache.helix.tools.ClusterSetup) BeforeClass(org.testng.annotations.BeforeClass)

Example 20 with HelixClusterVerifier

use of org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier in project helix by apache.

the class TestClusterDataCacheSelectiveUpdate method testSelectiveUpdates.

@Test(dependsOnMethods = { "testUpdateOnNotification" })
public void testSelectiveUpdates() throws Exception {
    MockZkHelixDataAccessor accessor = new MockZkHelixDataAccessor(CLUSTER_NAME, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
    ClusterDataCache cache = new ClusterDataCache("CLUSTER_" + TestHelper.getTestClassName());
    cache.refresh(accessor);
    Assert.assertEquals(accessor.getReadCount(PropertyType.IDEALSTATES), 1);
    Assert.assertEquals(accessor.getReadCount(PropertyType.LIVEINSTANCES), NODE_NR);
    Assert.assertEquals(accessor.getReadCount(PropertyType.CURRENTSTATES), NODE_NR);
    Assert.assertEquals(accessor.getReadCount(PropertyType.CONFIGS), NODE_NR + 1);
    accessor.clearReadCounters();
    // refresh again should read nothing
    cache.refresh(accessor);
    Assert.assertEquals(accessor.getReadCount(PropertyType.IDEALSTATES), 0);
    Assert.assertEquals(accessor.getReadCount(PropertyType.LIVEINSTANCES), 0);
    Assert.assertEquals(accessor.getReadCount(PropertyType.CURRENTSTATES), 0);
    Assert.assertEquals(accessor.getReadCount(PropertyType.CONFIGS), 1);
    // add a new resource
    _setupTool.addResourceToCluster(CLUSTER_NAME, "TestDB_1", _PARTITIONS, STATE_MODEL);
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, "TestDB_1", _replica);
    Thread.sleep(100);
    HelixClusterVerifier _clusterVerifier = new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).build();
    Assert.assertTrue(_clusterVerifier.verify());
    accessor.clearReadCounters();
    // refresh again should read only new current states and new idealstate
    cache.notifyDataChange(HelixConstants.ChangeType.IDEAL_STATE);
    cache.refresh(accessor);
    Assert.assertEquals(accessor.getReadCount(PropertyType.CURRENTSTATES), NODE_NR);
    Assert.assertEquals(accessor.getReadCount(PropertyType.IDEALSTATES), 1);
    // Add more resources
    accessor.clearReadCounters();
    _setupTool.addResourceToCluster(CLUSTER_NAME, "TestDB_2", _PARTITIONS, STATE_MODEL);
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, "TestDB_2", _replica);
    _setupTool.addResourceToCluster(CLUSTER_NAME, "TestDB_3", _PARTITIONS, STATE_MODEL);
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, "TestDB_3", _replica);
    // Totally four resources. Two of them are newly added.
    cache.notifyDataChange(HelixConstants.ChangeType.IDEAL_STATE);
    cache.refresh(accessor);
    Assert.assertEquals(accessor.getReadCount(PropertyType.IDEALSTATES), 2);
}
Also used : HelixClusterVerifier(org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier) ClusterDataCache(org.apache.helix.controller.stages.ClusterDataCache) ZNRecord(org.apache.helix.ZNRecord) Test(org.testng.annotations.Test)

Aggregations

HelixClusterVerifier (org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier)43 Test (org.testng.annotations.Test)38 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)19 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)17 Date (java.util.Date)15 BestPossibleExternalViewVerifier (org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier)14 IdealState (org.apache.helix.model.IdealState)13 Set (java.util.Set)7 ZNRecord (org.apache.helix.ZNRecord)7 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)7 ExternalView (org.apache.helix.model.ExternalView)7 Map (java.util.Map)6 PropertyKey (org.apache.helix.PropertyKey)6 StrictMatchExternalViewVerifier (org.apache.helix.tools.ClusterVerifiers.StrictMatchExternalViewVerifier)5 HashMap (java.util.HashMap)4 ConfigAccessor (org.apache.helix.ConfigAccessor)4 HashSet (java.util.HashSet)3 ErrTransition (org.apache.helix.mock.participant.ErrTransition)3 ClusterConfig (org.apache.helix.model.ClusterConfig)3 CurrentState (org.apache.helix.model.CurrentState)3