Search in sources :

Example 16 with ClusterDataCache

use of org.apache.helix.controller.stages.ClusterDataCache in project helix by apache.

the class TestRebalancerMetrics method testRecoveryRebalanceMetrics.

@Test
public void testRecoveryRebalanceMetrics() {
    System.out.println("START testRecoveryRebalanceMetrics at " + new Date(System.currentTimeMillis()));
    String resource = "testResourceName";
    int numPartition = 100;
    int numReplica = 3;
    int maxPending = 3;
    setupIdealState(5, new String[] { resource }, numPartition, numReplica, IdealState.RebalanceMode.FULL_AUTO, BuiltInStateModelDefinitions.MasterSlave.name());
    setupInstances(5);
    setupLiveInstances(5);
    setupStateModel();
    Map<String, Resource> resourceMap = getResourceMap(new String[] { resource }, numPartition, BuiltInStateModelDefinitions.MasterSlave.name());
    CurrentStateOutput currentStateOutput = new CurrentStateOutput();
    event.addAttribute(AttributeName.RESOURCES.name(), resourceMap);
    event.addAttribute(AttributeName.RESOURCES_TO_REBALANCE.name(), resourceMap);
    event.addAttribute(AttributeName.CURRENT_STATE.name(), currentStateOutput);
    ClusterStatusMonitor monitor = new ClusterStatusMonitor(_clusterName);
    monitor.active();
    event.addAttribute(AttributeName.clusterStatusMonitor.name(), monitor);
    runStage(event, new ReadClusterDataStage());
    ClusterDataCache cache = event.getAttribute(AttributeName.ClusterDataCache.name());
    setupThrottleConfig(cache.getClusterConfig(), StateTransitionThrottleConfig.RebalanceType.RECOVERY_BALANCE, maxPending);
    runStage(event, new BestPossibleStateCalcStage());
    runStage(event, new IntermediateStateCalcStage());
    ClusterStatusMonitor clusterStatusMonitor = event.getAttribute(AttributeName.clusterStatusMonitor.name());
    ResourceMonitor resourceMonitor = clusterStatusMonitor.getResourceMonitor(resource);
    Assert.assertEquals(resourceMonitor.getPendingRecoveryRebalancePartitionGauge(), numPartition);
    Assert.assertEquals(resourceMonitor.getRecoveryRebalanceThrottledPartitionGauge(), numPartition - maxPending);
    System.out.println("END testRecoveryRebalanceMetrics at " + new Date(System.currentTimeMillis()));
}
Also used : ClusterDataCache(org.apache.helix.controller.stages.ClusterDataCache) ReadClusterDataStage(org.apache.helix.controller.stages.ReadClusterDataStage) BestPossibleStateCalcStage(org.apache.helix.controller.stages.BestPossibleStateCalcStage) IntermediateStateCalcStage(org.apache.helix.controller.stages.IntermediateStateCalcStage) Resource(org.apache.helix.model.Resource) Date(java.util.Date) CurrentStateOutput(org.apache.helix.controller.stages.CurrentStateOutput) Test(org.testng.annotations.Test) BaseStageTest(org.apache.helix.controller.stages.BaseStageTest)

Aggregations

ClusterDataCache (org.apache.helix.controller.stages.ClusterDataCache)16 Test (org.testng.annotations.Test)7 HashMap (java.util.HashMap)5 Map (java.util.Map)5 BestPossibleStateOutput (org.apache.helix.controller.stages.BestPossibleStateOutput)5 ArrayList (java.util.ArrayList)4 ZNRecord (org.apache.helix.ZNRecord)4 CurrentStateOutput (org.apache.helix.controller.stages.CurrentStateOutput)4 IdealState (org.apache.helix.model.IdealState)4 Partition (org.apache.helix.model.Partition)4 Resource (org.apache.helix.model.Resource)4 PropertyKey (org.apache.helix.PropertyKey)3 BestPossibleStateCalcStage (org.apache.helix.controller.stages.BestPossibleStateCalcStage)3 ReadClusterDataStage (org.apache.helix.controller.stages.ReadClusterDataStage)3 ExternalView (org.apache.helix.model.ExternalView)3 Date (java.util.Date)2 BaseStageTest (org.apache.helix.controller.stages.BaseStageTest)2 IntermediateStateCalcStage (org.apache.helix.controller.stages.IntermediateStateCalcStage)2 ResourceComputationStage (org.apache.helix.controller.stages.ResourceComputationStage)2 StateModelDefinition (org.apache.helix.model.StateModelDefinition)2