Search in sources :

Example 1 with RoutingTableSnapshot

use of org.apache.helix.spectator.RoutingTableSnapshot in project helix by apache.

the class TestRoutingTableSnapshot method testRoutingTableSnapshot.

@Test
public void testRoutingTableSnapshot() throws InterruptedException {
    RoutingTableProvider routingTableProvider = new RoutingTableProvider(_manager, PropertyType.EXTERNALVIEW);
    String db1 = "TestDB-1";
    _setupTool.addResourceToCluster(CLUSTER_NAME, db1, NUM_PARTITIONS, "MasterSlave", IdealState.RebalanceMode.FULL_AUTO.name());
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, db1, NUM_REPLICAS);
    Thread.sleep(200);
    HelixClusterVerifier clusterVerifier = new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).build();
    Assert.assertTrue(clusterVerifier.verify());
    IdealState idealState1 = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, db1);
    RoutingTableSnapshot routingTableSnapshot = routingTableProvider.getRoutingTableSnapshot();
    validateMapping(idealState1, routingTableSnapshot);
    Assert.assertEquals(routingTableSnapshot.getInstanceConfigs().size(), NUM_NODES);
    Assert.assertEquals(routingTableSnapshot.getResources().size(), 1);
    Assert.assertEquals(routingTableSnapshot.getLiveInstances().size(), NUM_NODES);
    // add new DB and shutdown an instance
    String db2 = "TestDB-2";
    _setupTool.addResourceToCluster(CLUSTER_NAME, db2, NUM_PARTITIONS, "MasterSlave", IdealState.RebalanceMode.FULL_AUTO.name());
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, db2, NUM_REPLICAS);
    // shutdown an instance
    _participants[0].syncStop();
    Thread.sleep(200);
    Assert.assertTrue(clusterVerifier.verify());
    // the original snapshot should not change
    Assert.assertEquals(routingTableSnapshot.getInstanceConfigs().size(), NUM_NODES);
    Assert.assertEquals(routingTableSnapshot.getResources().size(), 1);
    Assert.assertEquals(routingTableSnapshot.getLiveInstances().size(), NUM_NODES);
    RoutingTableSnapshot newRoutingTableSnapshot = routingTableProvider.getRoutingTableSnapshot();
    Assert.assertEquals(newRoutingTableSnapshot.getInstanceConfigs().size(), NUM_NODES);
    Assert.assertEquals(newRoutingTableSnapshot.getResources().size(), 2);
    Assert.assertEquals(newRoutingTableSnapshot.getLiveInstances().size(), NUM_NODES - 1);
}
Also used : HelixClusterVerifier(org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier) RoutingTableSnapshot(org.apache.helix.spectator.RoutingTableSnapshot) RoutingTableProvider(org.apache.helix.spectator.RoutingTableProvider) IdealState(org.apache.helix.model.IdealState) Test(org.testng.annotations.Test)

Aggregations

IdealState (org.apache.helix.model.IdealState)1 RoutingTableProvider (org.apache.helix.spectator.RoutingTableProvider)1 RoutingTableSnapshot (org.apache.helix.spectator.RoutingTableSnapshot)1 HelixClusterVerifier (org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier)1 Test (org.testng.annotations.Test)1