Search in sources :

Example 11 with InstanceId

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());
    }
}
Also used : HashMap(java.util.HashMap) InstanceId(com.twitter.heron.spi.packing.InstanceId) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 12 with InstanceId

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);
}
Also used : InstanceId(com.twitter.heron.spi.packing.InstanceId) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Pair(com.twitter.heron.common.basics.Pair) Test(org.junit.Test)

Example 13 with InstanceId

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);
}
Also used : InstanceId(com.twitter.heron.spi.packing.InstanceId) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Pair(com.twitter.heron.common.basics.Pair) Test(org.junit.Test)

Example 14 with InstanceId

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);
}
Also used : InstanceId(com.twitter.heron.spi.packing.InstanceId) HashMap(java.util.HashMap) Pair(com.twitter.heron.common.basics.Pair) Test(org.junit.Test)

Aggregations

InstanceId (com.twitter.heron.spi.packing.InstanceId)14 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)9 HashMap (java.util.HashMap)8 Test (org.junit.Test)7 Pair (com.twitter.heron.common.basics.Pair)6 Resource (com.twitter.heron.spi.packing.Resource)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 ByteAmount (com.twitter.heron.common.basics.ByteAmount)3 List (java.util.List)3 Map (java.util.Map)2 ResourceExceededException (com.twitter.heron.packing.ResourceExceededException)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1