use of org.apache.helix.model.Resource in project helix by apache.
the class TestResourceValidationStage method testNoSpec.
@Test
public void testNoSpec() throws Exception {
MockAccessor accessor = new MockAccessor();
accessor.setProperty(accessor.keyBuilder().clusterConfig(), new ClusterConfig("TestCluster"));
// create an ideal state and no spec
String masterSlaveCustomResource = "masterSlaveCustomResource";
createIS(accessor, masterSlaveCustomResource, "MasterSlave", RebalanceMode.CUSTOMIZED);
// add some state models
addStateModels(accessor);
// refresh the cache
ClusterEvent event = new ClusterEvent(ClusterEventType.Unknown);
ClusterDataCache cache = new ClusterDataCache();
cache.refresh(accessor);
event.addAttribute(AttributeName.ClusterDataCache.name(), cache);
// run resource computation
new ResourceComputationStage().process(event);
Map<String, Resource> resourceMap = event.getAttribute(AttributeName.RESOURCES.name());
Assert.assertTrue(resourceMap.containsKey(masterSlaveCustomResource));
// run resource validation
new ResourceValidationStage().process(event);
Map<String, Resource> finalResourceMap = event.getAttribute(AttributeName.RESOURCES.name());
Assert.assertTrue(finalResourceMap.containsKey(masterSlaveCustomResource));
}
use of org.apache.helix.model.Resource in project helix by apache.
the class BaseStageTest method getResourceMap.
protected Map<String, Resource> getResourceMap(String[] resources, int partitions, String stateModel) {
Map<String, Resource> resourceMap = new HashMap<String, Resource>();
for (String r : resources) {
Resource testResource = new Resource(r);
testResource.setStateModelDefRef(stateModel);
for (int i = 0; i < partitions; i++) {
testResource.addPartition(r + "_" + i);
}
resourceMap.put(r, testResource);
}
return resourceMap;
}
use of org.apache.helix.model.Resource in project helix by apache.
the class TestBestPossibleCalcStageCompatibility method testSemiAutoModeCompatibility.
@Test
public void testSemiAutoModeCompatibility() {
System.out.println("START TestBestPossibleStateCalcStage at " + new Date(System.currentTimeMillis()));
String[] resources = new String[] { "testResourceName" };
setupIdealStateDeprecated(5, resources, 10, 1, IdealStateModeProperty.AUTO);
setupLiveInstances(5);
setupStateModel();
Map<String, Resource> resourceMap = getResourceMap();
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);
ReadClusterDataStage stage1 = new ReadClusterDataStage();
runStage(event, stage1);
BestPossibleStateCalcStage stage2 = new BestPossibleStateCalcStage();
runStage(event, stage2);
BestPossibleStateOutput output = event.getAttribute(AttributeName.BEST_POSSIBLE_STATE.name());
for (int p = 0; p < 5; p++) {
Partition resource = new Partition("testResourceName_" + p);
AssertJUnit.assertEquals("MASTER", output.getInstanceStateMap("testResourceName", resource).get("localhost_" + (p + 1) % 5));
}
System.out.println("END TestBestPossibleStateCalcStage at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.model.Resource in project helix by apache.
the class TestBestPossibleCalcStageCompatibility method testCustomModeCompatibility.
@Test
public void testCustomModeCompatibility() {
System.out.println("START TestBestPossibleStateCalcStage at " + new Date(System.currentTimeMillis()));
String[] resources = new String[] { "testResourceName" };
setupIdealStateDeprecated(5, resources, 10, 1, IdealStateModeProperty.CUSTOMIZED);
setupLiveInstances(5);
setupStateModel();
Map<String, Resource> resourceMap = getResourceMap();
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);
ReadClusterDataStage stage1 = new ReadClusterDataStage();
runStage(event, stage1);
BestPossibleStateCalcStage stage2 = new BestPossibleStateCalcStage();
runStage(event, stage2);
BestPossibleStateOutput output = event.getAttribute(AttributeName.BEST_POSSIBLE_STATE.name());
for (int p = 0; p < 5; p++) {
Partition resource = new Partition("testResourceName_" + p);
AssertJUnit.assertNull(output.getInstanceStateMap("testResourceName", resource).get("localhost_" + (p + 1) % 5));
}
System.out.println("END TestBestPossibleStateCalcStage at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.model.Resource in project helix by apache.
the class TestBestPossibleStateCalcStage method testSimple.
@Test
public void testSimple() {
System.out.println("START TestBestPossibleStateCalcStage at " + new Date(System.currentTimeMillis()));
// List<IdealState> idealStates = new ArrayList<IdealState>();
String[] resources = new String[] { "testResourceName" };
int numPartition = 5;
int numReplica = 1;
setupIdealState(5, resources, numPartition, numReplica, RebalanceMode.SEMI_AUTO, BuiltInStateModelDefinitions.MasterSlave.name());
setupLiveInstances(5);
setupStateModel();
Map<String, Resource> resourceMap = getResourceMap(resources, 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);
ReadClusterDataStage stage1 = new ReadClusterDataStage();
runStage(event, stage1);
BestPossibleStateCalcStage stage2 = new BestPossibleStateCalcStage();
runStage(event, stage2);
BestPossibleStateOutput output = event.getAttribute(AttributeName.BEST_POSSIBLE_STATE.name());
for (int p = 0; p < 5; p++) {
Partition resource = new Partition("testResourceName_" + p);
AssertJUnit.assertEquals("MASTER", output.getInstanceStateMap("testResourceName", resource).get("localhost_" + (p + 1) % 5));
}
System.out.println("END TestBestPossibleStateCalcStage at " + new Date(System.currentTimeMillis()));
}
Aggregations