Search in sources :

Example 31 with Pair

use of org.apache.heron.common.basics.Pair in project heron by twitter.

the class ResourceCompliantRRPackingTest method testScaleDownHomogenousFirst.

@Test
public void testScaleDownHomogenousFirst() throws Exception {
    @SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, InstanceId>[] initialComponentInstances = new Pair[] { new Pair<>(1, new InstanceId(SPOUT_NAME, 1, 0)), new Pair<>(1, new InstanceId(SPOUT_NAME, 2, 1)), new Pair<>(1, new InstanceId(BOLT_NAME, 3, 0)), new Pair<>(3, new InstanceId(BOLT_NAME, 4, 1)), new Pair<>(3, new InstanceId(BOLT_NAME, 5, 2)), new Pair<>(3, new InstanceId(BOLT_NAME, 6, 3)), new Pair<>(3, new InstanceId(BOLT_NAME, 7, 4)) };
    Map<String, Integer> componentChanges = new HashMap<>();
    componentChanges.put(BOLT_NAME, -4);
    @SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, InstanceId>[] expectedComponentInstances = new Pair[] { new Pair<>(1, new InstanceId(SPOUT_NAME, 1, 0)), new Pair<>(1, new InstanceId(SPOUT_NAME, 2, 1)), new Pair<>(1, new InstanceId(BOLT_NAME, 3, 0)) };
    doScaleDownTest(initialComponentInstances, componentChanges, expectedComponentInstances);
}
Also used : InstanceId(org.apache.heron.spi.packing.InstanceId) HashMap(java.util.HashMap) Pair(org.apache.heron.common.basics.Pair) Test(org.junit.Test)

Example 32 with Pair

use of org.apache.heron.common.basics.Pair in project heron by twitter.

the class FirstFitDecreasingPackingTest method testScaleDownHomogenousFirst.

@Test
public void testScaleDownHomogenousFirst() throws Exception {
    @SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, InstanceId>[] initialComponentInstances = new Pair[] { new Pair<>(1, new InstanceId(SPOUT_NAME, 1, 0)), new Pair<>(1, new InstanceId(SPOUT_NAME, 2, 1)), new Pair<>(1, new InstanceId(BOLT_NAME, 3, 0)), new Pair<>(3, new InstanceId(BOLT_NAME, 4, 1)), new Pair<>(3, new InstanceId(BOLT_NAME, 5, 2)), new Pair<>(3, new InstanceId(BOLT_NAME, 6, 3)), new Pair<>(3, new InstanceId(BOLT_NAME, 7, 4)) };
    Map<String, Integer> componentChanges = new HashMap<>();
    componentChanges.put(BOLT_NAME, -4);
    @SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, InstanceId>[] expectedComponentInstances = new Pair[] { new Pair<>(1, new InstanceId(SPOUT_NAME, 1, 0)), new Pair<>(1, new InstanceId(SPOUT_NAME, 2, 1)), new Pair<>(1, new InstanceId(BOLT_NAME, 3, 0)) };
    doScaleDownTest(initialComponentInstances, componentChanges, expectedComponentInstances);
}
Also used : InstanceId(org.apache.heron.spi.packing.InstanceId) HashMap(java.util.HashMap) Pair(org.apache.heron.common.basics.Pair) Test(org.junit.Test)

Example 33 with Pair

use of org.apache.heron.common.basics.Pair in project heron by twitter.

the class FirstFitDecreasingPackingTest method testScaleDownOneComponentRemoveContainer.

/**
 * Test the scenario where scaling down removes instances from containers that are most imbalanced
 * (i.e., tending towards homogeneity) first. If there is a tie (e.g. AABB, AB), chooses from the
 * container with the fewest instances, to favor ultimately removing  containers. If there is
 * still a tie, favor removing from higher numbered containers
 */
@Test
public void testScaleDownOneComponentRemoveContainer() throws Exception {
    @SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, InstanceId>[] initialComponentInstances = new Pair[] { new Pair<>(1, new InstanceId(SPOUT_NAME, 1, 0)), new Pair<>(1, new InstanceId(SPOUT_NAME, 2, 1)), new Pair<>(1, new InstanceId(BOLT_NAME, 3, 0)), new Pair<>(3, new InstanceId(BOLT_NAME, 4, 1)), new Pair<>(3, new InstanceId(BOLT_NAME, 5, 2)), new Pair<>(4, new InstanceId(BOLT_NAME, 6, 3)), new Pair<>(4, new InstanceId(BOLT_NAME, 7, 4)) };
    Map<String, Integer> componentChanges = new HashMap<>();
    componentChanges.put(BOLT_NAME, -2);
    @SuppressWarnings({ "unchecked", "rawtypes" }) Pair<Integer, InstanceId>[] expectedComponentInstances = new Pair[] { new Pair<>(1, new InstanceId(SPOUT_NAME, 1, 0)), new Pair<>(1, new InstanceId(SPOUT_NAME, 2, 1)), new Pair<>(1, new InstanceId(BOLT_NAME, 3, 0)), new Pair<>(3, new InstanceId(BOLT_NAME, 4, 1)), new Pair<>(3, new InstanceId(BOLT_NAME, 5, 2)) };
    doScaleDownTest(initialComponentInstances, componentChanges, expectedComponentInstances);
}
Also used : InstanceId(org.apache.heron.spi.packing.InstanceId) HashMap(java.util.HashMap) Pair(org.apache.heron.common.basics.Pair) Test(org.junit.Test)

Example 34 with Pair

use of org.apache.heron.common.basics.Pair in project heron by twitter.

the class UpdateDryRunRenderTest method setUp.

@Before
public void setUp() throws Exception {
    // set up original packing plan
    final String COMPONENT_A = "exclaim1";
    final String COMPONENT_B = "word";
    ContainerPlan containerPlanA = PackingTestUtils.testContainerPlan(1, new Pair<>(COMPONENT_A, 1), new Pair<>(COMPONENT_A, 3), new Pair<>(COMPONENT_B, 5));
    ContainerPlan containerPlanB = PackingTestUtils.testContainerPlan(2, new Pair<>(COMPONENT_A, 2), new Pair<>(COMPONENT_A, 4), new Pair<>(COMPONENT_B, 6));
    Set<ContainerPlan> containerPlans = new HashSet<>();
    containerPlans.add(containerPlanA);
    containerPlans.add(containerPlanB);
    originalPlan = new PackingPlan("ORIG", containerPlans);
    // setup new packing plan A: word:1, exclaim1:9
    Set<ContainerPlan> containerPlansA = new HashSet<>();
    containerPlansA.add(containerPlanA);
    containerPlansA.add(PackingTestUtils.testContainerPlan(2, new Pair<>(COMPONENT_A, 4), new Pair<>(COMPONENT_A, 2), new Pair<>(COMPONENT_A, 6)));
    containerPlansA.add(PackingTestUtils.testContainerPlan(3, new Pair<>(COMPONENT_A, 7), new Pair<>(COMPONENT_A, 8), new Pair<>(COMPONENT_A, 9)));
    containerPlansA.add(PackingTestUtils.testContainerPlan(4, new Pair<>(COMPONENT_A, 10)));
    newPlanA = new PackingPlan("A", containerPlansA);
    // setup new packing plan B: word:1, exclaim1:1
    Set<ContainerPlan> containerPlansB = new HashSet<>();
    containerPlansB.add(PackingTestUtils.testContainerPlan(1, new Pair<>(COMPONENT_A, 3), new Pair<>(COMPONENT_B, 5)));
    newPlanB = new PackingPlan("B", containerPlansB);
}
Also used : ContainerPlan(org.apache.heron.spi.packing.PackingPlan.ContainerPlan) PackingPlan(org.apache.heron.spi.packing.PackingPlan) HashSet(java.util.HashSet) Pair(org.apache.heron.common.basics.Pair) Before(org.junit.Before)

Example 35 with Pair

use of org.apache.heron.common.basics.Pair in project heron by twitter.

the class V1ControllerTest method testLoadPodFromTemplateBadTargetConfigMap.

@Test
public void testLoadPodFromTemplateBadTargetConfigMap() {
    // ConfigMap with target ConfigMap and an invalid Pod Template.
    final V1ConfigMap configMapInvalidPod = new V1ConfigMapBuilder().withNewMetadata().withName(CONFIGMAP_NAME).endMetadata().addToData(POD_TEMPLATE_NAME, "Dummy Value").build();
    // ConfigMap with target ConfigMaps and an empty Pod Template.
    final V1ConfigMap configMapEmptyPod = new V1ConfigMapBuilder().withNewMetadata().withName(CONFIGMAP_NAME).endMetadata().addToData(POD_TEMPLATE_NAME, "").build();
    // Test case container.
    // Input: ConfigMap to setup mock V1Controller, Boolean flag for executor/manager switch.
    // Output: The expected error message.
    final List<TestTuple<Pair<V1ConfigMap, Boolean>, String>> testCases = new LinkedList<>();
    testCases.add(new TestTuple<>("Executor invalid Pod Template", new Pair<>(configMapInvalidPod, true), "Error parsing"));
    testCases.add(new TestTuple<>("Manager invalid Pod Template", new Pair<>(configMapInvalidPod, false), "Error parsing"));
    testCases.add(new TestTuple<>("Executor empty Pod Template", new Pair<>(configMapEmptyPod, true), "Error parsing"));
    testCases.add(new TestTuple<>("Manager empty Pod Template", new Pair<>(configMapEmptyPod, false), "Error parsing"));
    // Test loop.
    for (TestTuple<Pair<V1ConfigMap, Boolean>, String> testCase : testCases) {
        doReturn(testCase.input.first).when(v1ControllerWithPodTemplate).getConfigMap(anyString());
        String message = "";
        try {
            v1ControllerWithPodTemplate.loadPodFromTemplate(testCase.input.second);
        } catch (TopologySubmissionException e) {
            message = e.getMessage();
        }
        Assert.assertTrue(testCase.description, message.contains(testCase.expected));
    }
}
Also used : V1ConfigMapBuilder(io.kubernetes.client.openapi.models.V1ConfigMapBuilder) TopologySubmissionException(org.apache.heron.scheduler.TopologySubmissionException) TestTuple(org.apache.heron.scheduler.kubernetes.KubernetesUtils.TestTuple) Matchers.anyString(org.mockito.Matchers.anyString) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) LinkedList(java.util.LinkedList) Pair(org.apache.heron.common.basics.Pair) Test(org.junit.Test)

Aggregations

Pair (org.apache.heron.common.basics.Pair)37 Test (org.junit.Test)19 Config (org.apache.heron.spi.common.Config)15 HashMap (java.util.HashMap)13 InstanceId (org.apache.heron.spi.packing.InstanceId)10 LinkedList (java.util.LinkedList)8 Map (java.util.Map)7 VolumeConfigKeys (org.apache.heron.scheduler.kubernetes.KubernetesConstants.VolumeConfigKeys)7 Matchers.anyString (org.mockito.Matchers.anyString)7 ImmutableMap (com.google.common.collect.ImmutableMap)6 TestTuple (org.apache.heron.scheduler.kubernetes.KubernetesUtils.TestTuple)6 PackingPlan (org.apache.heron.spi.packing.PackingPlan)6 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)5 ArrayList (java.util.ArrayList)4 V1ConfigMapBuilder (io.kubernetes.client.openapi.models.V1ConfigMapBuilder)3 V1VolumeMount (io.kubernetes.client.openapi.models.V1VolumeMount)3 V1VolumeMountBuilder (io.kubernetes.client.openapi.models.V1VolumeMountBuilder)3 InetSocketAddress (java.net.InetSocketAddress)3 TopologySubmissionException (org.apache.heron.scheduler.TopologySubmissionException)3 V1Volume (io.kubernetes.client.openapi.models.V1Volume)2