use of com.twitter.heron.spi.packing.InstanceId in project heron by twitter.
the class PackingPlanBuilderTest method testGetContainers.
/**
* Tests the getContainers method.
*/
@Test
public void testGetContainers() throws ResourceExceededException {
int paddingPercentage = 10;
Map<Integer, List<InstanceId>> packing = new HashMap<>();
packing.put(7, Arrays.asList(new InstanceId("spout", 1, 0), new InstanceId("bolt", 2, 0)));
packing.put(3, Arrays.asList(new InstanceId("spout", 3, 0), new InstanceId("bolt", 4, 0)));
PackingPlan packingPlan = generatePacking(packing);
Map<Integer, Container> containers = PackingPlanBuilder.getContainers(packingPlan, paddingPercentage, new HashMap<String, TreeSet<Integer>>(), new TreeSet<Integer>());
assertEquals(packing.size(), containers.size());
for (Integer containerId : packing.keySet()) {
Container foundContainer = containers.get(containerId);
assertEquals(paddingPercentage, foundContainer.getPaddingPercentage());
assertEquals(packingPlan.getMaxContainerResources(), foundContainer.getCapacity());
assertEquals(2, foundContainer.getInstances().size());
}
}
use of com.twitter.heron.spi.packing.InstanceId in project heron by twitter.
the class PackingPlanBuilderTest method testExceededCapacityAddingToPackingPlan.
@Test(expected = ResourceExceededException.class)
public void testExceededCapacityAddingToPackingPlan() throws ResourceExceededException {
PackingPlan plan = doCreatePackingPlanTest(testContainerInstances);
@SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, InstanceId>[] added = new Pair[] { new Pair<>(3, new InstanceId("componentB", 4, 1)) };
PackingTestHelper.addToTestPackingPlan(TOPOLOGY_ID, plan, PackingTestHelper.toContainerIdComponentNames(added), 0);
}
use of com.twitter.heron.spi.packing.InstanceId in project heron by twitter.
the class PackingPlanBuilderTest method testAddToPackingPlan.
@Test
public void testAddToPackingPlan() throws ResourceExceededException {
PackingPlan plan = doCreatePackingPlanTest(testContainerInstances);
@SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, InstanceId>[] added = new Pair[] { new Pair<>(1, new InstanceId("componentB", 4, 1)), new Pair<>(4, new InstanceId("componentA", 5, 2)) };
PackingPlan updatedPlan = PackingTestHelper.addToTestPackingPlan(TOPOLOGY_ID, plan, PackingTestHelper.toContainerIdComponentNames(added), 0);
Pair<Integer, InstanceId>[] expected = concat(testContainerInstances, added);
AssertPacking.assertPackingPlan(TOPOLOGY_ID, expected, updatedPlan);
}
use of com.twitter.heron.spi.packing.InstanceId in project heron by twitter.
the class CommonPackingTests method testScaleDownTwoComponentsRemoveContainer.
@Test
public void testScaleDownTwoComponentsRemoveContainer() throws Exception {
@SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, InstanceId>[] initialComponentInstances = new Pair[] { new Pair<>(1, new InstanceId(A, 1, 0)), new Pair<>(1, new InstanceId(A, 2, 1)), new Pair<>(1, new InstanceId(B, 3, 0)), new Pair<>(1, new InstanceId(B, 4, 1)), new Pair<>(3, new InstanceId(A, 5, 2)), new Pair<>(3, new InstanceId(A, 6, 3)), new Pair<>(3, new InstanceId(B, 7, 2)), new Pair<>(3, new InstanceId(B, 8, 3)) };
Map<String, Integer> componentChanges = new HashMap<>();
componentChanges.put(A, -2);
componentChanges.put(B, -2);
@SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, InstanceId>[] expectedComponentInstances = new Pair[] { new Pair<>(1, new InstanceId(A, 1, 0)), new Pair<>(1, new InstanceId(A, 2, 1)), new Pair<>(1, new InstanceId(B, 3, 0)), new Pair<>(1, new InstanceId(B, 4, 1)) };
doScaleDownTest(initialComponentInstances, componentChanges, expectedComponentInstances);
}
Aggregations