Search in sources :

Example 11 with TopologySubmissionException

use of org.apache.heron.scheduler.TopologySubmissionException in project heron by twitter.

the class V1ControllerTest method testLoadPodFromTemplateNullConfigMap.

@Test
public void testLoadPodFromTemplateNullConfigMap() {
    final List<TestTuple<Boolean, String>> testCases = new LinkedList<>();
    testCases.add(new TestTuple<>("Executor not found", true, "unable to locate"));
    testCases.add(new TestTuple<>("Manager not found", false, "unable to locate"));
    for (TestTuple<Boolean, String> testCase : testCases) {
        doReturn(null).when(v1ControllerWithPodTemplate).getConfigMap(anyString());
        String message = "";
        try {
            v1ControllerWithPodTemplate.loadPodFromTemplate(testCase.input);
        } catch (TopologySubmissionException e) {
            message = e.getMessage();
        }
        Assert.assertTrue(testCase.description, message.contains(testCase.expected));
    }
}
Also used : TopologySubmissionException(org.apache.heron.scheduler.TopologySubmissionException) TestTuple(org.apache.heron.scheduler.kubernetes.KubernetesUtils.TestTuple) Matchers.anyString(org.mockito.Matchers.anyString) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 12 with TopologySubmissionException

use of org.apache.heron.scheduler.TopologySubmissionException 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)

Example 13 with TopologySubmissionException

use of org.apache.heron.scheduler.TopologySubmissionException in project heron by twitter.

the class V1ControllerTest method testLoadPodFromTemplateNoConfigMap.

@Test
public void testLoadPodFromTemplateNoConfigMap() {
    final List<TestTuple<Boolean, String>> testCases = new LinkedList<>();
    testCases.add(new TestTuple<>("Executor no ConfigMap", true, "Failed to locate Pod Template"));
    testCases.add(new TestTuple<>("Manager no ConfigMap", false, "Failed to locate Pod Template"));
    for (TestTuple<Boolean, String> testCase : testCases) {
        doReturn(new V1ConfigMap()).when(v1ControllerWithPodTemplate).getConfigMap(anyString());
        String message = "";
        try {
            v1ControllerWithPodTemplate.loadPodFromTemplate(testCase.input);
        } catch (TopologySubmissionException e) {
            message = e.getMessage();
        }
        Assert.assertTrue(testCase.description, message.contains(testCase.expected));
    }
}
Also used : TopologySubmissionException(org.apache.heron.scheduler.TopologySubmissionException) TestTuple(org.apache.heron.scheduler.kubernetes.KubernetesUtils.TestTuple) Matchers.anyString(org.mockito.Matchers.anyString) LinkedList(java.util.LinkedList) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) Test(org.junit.Test)

Example 14 with TopologySubmissionException

use of org.apache.heron.scheduler.TopologySubmissionException in project heron by twitter.

the class V1ControllerTest method testDisablePodTemplates.

@Test
public void testDisablePodTemplates() {
    // ConfigMap with valid Pod Template.
    V1ConfigMap configMapValidPod = new V1ConfigMapBuilder().withNewMetadata().withName(CONFIGMAP_NAME).endMetadata().addToData(POD_TEMPLATE_NAME, POD_TEMPLATE_VALID).build();
    final String expected = "Pod Templates are disabled";
    String message = "";
    doReturn(configMapValidPod).when(v1ControllerPodTemplate).getConfigMap(anyString());
    try {
        v1ControllerPodTemplate.loadPodFromTemplate(true);
    } catch (TopologySubmissionException e) {
        message = e.getMessage();
    }
    Assert.assertTrue(message.contains(expected));
}
Also used : V1ConfigMapBuilder(io.kubernetes.client.openapi.models.V1ConfigMapBuilder) TopologySubmissionException(org.apache.heron.scheduler.TopologySubmissionException) Matchers.anyString(org.mockito.Matchers.anyString) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) Test(org.junit.Test)

Aggregations

TopologySubmissionException (org.apache.heron.scheduler.TopologySubmissionException)14 Test (org.junit.Test)8 LinkedList (java.util.LinkedList)7 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)6 TestTuple (org.apache.heron.scheduler.kubernetes.KubernetesUtils.TestTuple)6 Matchers.anyString (org.mockito.Matchers.anyString)6 V1ConfigMapBuilder (io.kubernetes.client.openapi.models.V1ConfigMapBuilder)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 Pair (org.apache.heron.common.basics.Pair)3 ApiException (io.kubernetes.client.openapi.ApiException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Matcher (java.util.regex.Matcher)2 V1Container (io.kubernetes.client.openapi.models.V1Container)1 V1EnvVar (io.kubernetes.client.openapi.models.V1EnvVar)1 V1EnvVarSource (io.kubernetes.client.openapi.models.V1EnvVarSource)1 V1ObjectFieldSelector (io.kubernetes.client.openapi.models.V1ObjectFieldSelector)1 V1PodSpec (io.kubernetes.client.openapi.models.V1PodSpec)1 V1PodTemplate (io.kubernetes.client.openapi.models.V1PodTemplate)1 V1PodTemplateSpec (io.kubernetes.client.openapi.models.V1PodTemplateSpec)1