Search in sources :

Example 6 with V1ConfigMapBuilder

use of io.kubernetes.client.openapi.models.V1ConfigMapBuilder 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 7 with V1ConfigMapBuilder

use of io.kubernetes.client.openapi.models.V1ConfigMapBuilder 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

V1ConfigMapBuilder (io.kubernetes.client.openapi.models.V1ConfigMapBuilder)7 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)6 Test (org.junit.Test)5 Matchers.anyString (org.mockito.Matchers.anyString)5 LinkedList (java.util.LinkedList)4 TopologySubmissionException (org.apache.heron.scheduler.TopologySubmissionException)4 TestTuple (org.apache.heron.scheduler.kubernetes.KubernetesUtils.TestTuple)4 Pair (org.apache.heron.common.basics.Pair)3 HashMap (java.util.HashMap)2 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)1 V1PodTemplateSpec (io.kubernetes.client.openapi.models.V1PodTemplateSpec)1