Search in sources :

Example 6 with TestTuple

use of org.apache.heron.scheduler.kubernetes.KubernetesUtils.TestTuple in project heron by twitter.

the class V1ControllerTest method testCreateResourcesRequirement.

@Test
public void testCreateResourcesRequirement() {
    final String managerCpuLimit = "3000m";
    final String managerMemLimit = "256Gi";
    final Quantity memory = Quantity.fromString(managerMemLimit);
    final Quantity cpu = Quantity.fromString(managerCpuLimit);
    final List<TestTuple<Map<String, String>, Map<String, Quantity>>> testCases = new LinkedList<>();
    // No input.
    Map<String, String> inputEmpty = new HashMap<>();
    testCases.add(new TestTuple<>("Empty input.", inputEmpty, new HashMap<>()));
    // Only memory.
    Map<String, String> inputMemory = new HashMap<String, String>() {

        {
            put(KubernetesConstants.MEMORY, managerMemLimit);
        }
    };
    Map<String, Quantity> expectedMemory = new HashMap<String, Quantity>() {

        {
            put(KubernetesConstants.MEMORY, memory);
        }
    };
    testCases.add(new TestTuple<>("Only memory input.", inputMemory, expectedMemory));
    // Only CPU.
    Map<String, String> inputCPU = new HashMap<String, String>() {

        {
            put(KubernetesConstants.CPU, managerCpuLimit);
        }
    };
    Map<String, Quantity> expectedCPU = new HashMap<String, Quantity>() {

        {
            put(KubernetesConstants.CPU, cpu);
        }
    };
    testCases.add(new TestTuple<>("Only CPU input.", inputCPU, expectedCPU));
    // CPU and memory.
    Map<String, String> inputMemoryCPU = new HashMap<String, String>() {

        {
            put(KubernetesConstants.MEMORY, managerMemLimit);
            put(KubernetesConstants.CPU, managerCpuLimit);
        }
    };
    Map<String, Quantity> expectedMemoryCPU = new HashMap<String, Quantity>() {

        {
            put(KubernetesConstants.MEMORY, memory);
            put(KubernetesConstants.CPU, cpu);
        }
    };
    testCases.add(new TestTuple<>("Memory and CPU input.", inputMemoryCPU, expectedMemoryCPU));
    // Invalid.
    Map<String, String> inputInvalid = new HashMap<String, String>() {

        {
            put("invalid input", "will not be ignored");
            put(KubernetesConstants.CPU, managerCpuLimit);
        }
    };
    Map<String, Quantity> expectedInvalid = new HashMap<String, Quantity>() {

        {
            put(KubernetesConstants.CPU, cpu);
        }
    };
    testCases.add(new TestTuple<>("Invalid input.", inputInvalid, expectedInvalid));
    // Test loop.
    for (TestTuple<Map<String, String>, Map<String, Quantity>> testCase : testCases) {
        Map<String, Quantity> actual = v1ControllerPodTemplate.createResourcesRequirement(testCase.input);
        Assert.assertEquals(testCase.description, testCase.expected, actual);
    }
}
Also used : HashMap(java.util.HashMap) TestTuple(org.apache.heron.scheduler.kubernetes.KubernetesUtils.TestTuple) Quantity(io.kubernetes.client.custom.Quantity) Matchers.anyString(org.mockito.Matchers.anyString) HashMap(java.util.HashMap) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 7 with TestTuple

use of org.apache.heron.scheduler.kubernetes.KubernetesUtils.TestTuple in project heron by twitter.

the class V1ControllerTest method testCreateVolumeMountsCLI.

@Test
public void testCreateVolumeMountsCLI() {
    final String volumeNamePVC = "volume-name-pvc";
    final String volumeNameHostPath = "volume-name-host-path";
    final String volumeNameEmptyDir = "volume-name-empty-dir";
    final String volumeNameNFS = "volume-name-nfs";
    final String value = "inserted-value";
    // Test case container.
    // Input: [0] volume name, [1] volume options
    // Output: The expected <V1VolumeMount>.
    final List<TestTuple<Pair<String, Map<VolumeConfigKeys, String>>, V1VolumeMount>> testCases = new LinkedList<>();
    // PVC.
    final Map<VolumeConfigKeys, String> configPVC = ImmutableMap.<VolumeConfigKeys, String>builder().put(VolumeConfigKeys.claimName, value).put(VolumeConfigKeys.storageClassName, value).put(VolumeConfigKeys.sizeLimit, value).put(VolumeConfigKeys.accessModes, value).put(VolumeConfigKeys.volumeMode, value).put(VolumeConfigKeys.path, value).put(VolumeConfigKeys.subPath, value).put(VolumeConfigKeys.readOnly, "true").build();
    final V1VolumeMount volumeMountPVC = new V1VolumeMountBuilder().withName(volumeNamePVC).withMountPath(value).withSubPath(value).withReadOnly(true).build();
    testCases.add(new TestTuple<>("PVC volume mount", new Pair<>(volumeNamePVC, configPVC), volumeMountPVC));
    // Host Path.
    final Map<VolumeConfigKeys, String> configHostPath = ImmutableMap.<VolumeConfigKeys, String>builder().put(VolumeConfigKeys.type, "DirectoryOrCreate").put(VolumeConfigKeys.pathOnHost, value).put(VolumeConfigKeys.path, value).put(VolumeConfigKeys.subPath, value).put(VolumeConfigKeys.readOnly, "true").build();
    final V1VolumeMount volumeMountHostPath = new V1VolumeMountBuilder().withName(volumeNameHostPath).withMountPath(value).withSubPath(value).withReadOnly(true).build();
    testCases.add(new TestTuple<>("Host Path volume mount", new Pair<>(volumeNameHostPath, configHostPath), volumeMountHostPath));
    // Empty Dir.
    final Map<VolumeConfigKeys, String> configEmptyDir = ImmutableMap.<VolumeConfigKeys, String>builder().put(VolumeConfigKeys.sizeLimit, value).put(VolumeConfigKeys.medium, "Memory").put(VolumeConfigKeys.path, value).put(VolumeConfigKeys.subPath, value).put(VolumeConfigKeys.readOnly, "true").build();
    final V1VolumeMount volumeMountEmptyDir = new V1VolumeMountBuilder().withName(volumeNameEmptyDir).withMountPath(value).withSubPath(value).withReadOnly(true).build();
    testCases.add(new TestTuple<>("Empty Dir volume mount", new Pair<>(volumeNameEmptyDir, configEmptyDir), volumeMountEmptyDir));
    // NFS.
    final Map<VolumeConfigKeys, String> configNFS = ImmutableMap.<VolumeConfigKeys, String>builder().put(VolumeConfigKeys.server, "nfs.server.address").put(VolumeConfigKeys.readOnly, "true").put(VolumeConfigKeys.pathOnNFS, value).put(VolumeConfigKeys.path, value).put(VolumeConfigKeys.subPath, value).build();
    final V1VolumeMount volumeMountNFS = new V1VolumeMountBuilder().withName(volumeNameNFS).withMountPath(value).withSubPath(value).withReadOnly(true).build();
    testCases.add(new TestTuple<>("NFS volume mount", new Pair<>(volumeNameNFS, configNFS), volumeMountNFS));
    // Test loop.
    for (TestTuple<Pair<String, Map<VolumeConfigKeys, String>>, V1VolumeMount> testCase : testCases) {
        V1VolumeMount actual = v1ControllerPodTemplate.createVolumeMountsCLI(testCase.input.first, testCase.input.second);
        Assert.assertEquals(testCase.description, testCase.expected, actual);
    }
}
Also used : VolumeConfigKeys(org.apache.heron.scheduler.kubernetes.KubernetesConstants.VolumeConfigKeys) TestTuple(org.apache.heron.scheduler.kubernetes.KubernetesUtils.TestTuple) Matchers.anyString(org.mockito.Matchers.anyString) V1VolumeMountBuilder(io.kubernetes.client.openapi.models.V1VolumeMountBuilder) HashMap(java.util.HashMap) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedList(java.util.LinkedList) V1VolumeMount(io.kubernetes.client.openapi.models.V1VolumeMount) Pair(org.apache.heron.common.basics.Pair) Test(org.junit.Test)

Example 8 with TestTuple

use of org.apache.heron.scheduler.kubernetes.KubernetesUtils.TestTuple 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 9 with TestTuple

use of org.apache.heron.scheduler.kubernetes.KubernetesUtils.TestTuple 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 10 with TestTuple

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

Aggregations

LinkedList (java.util.LinkedList)11 TestTuple (org.apache.heron.scheduler.kubernetes.KubernetesUtils.TestTuple)11 Test (org.junit.Test)11 Matchers.anyString (org.mockito.Matchers.anyString)10 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)8 Pair (org.apache.heron.common.basics.Pair)6 TopologySubmissionException (org.apache.heron.scheduler.TopologySubmissionException)6 V1ConfigMapBuilder (io.kubernetes.client.openapi.models.V1ConfigMapBuilder)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 V1VolumeMount (io.kubernetes.client.openapi.models.V1VolumeMount)3 V1VolumeMountBuilder (io.kubernetes.client.openapi.models.V1VolumeMountBuilder)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 V1Volume (io.kubernetes.client.openapi.models.V1Volume)2 V1VolumeBuilder (io.kubernetes.client.openapi.models.V1VolumeBuilder)2 VolumeConfigKeys (org.apache.heron.scheduler.kubernetes.KubernetesConstants.VolumeConfigKeys)2 Quantity (io.kubernetes.client.custom.Quantity)1 V1Container (io.kubernetes.client.openapi.models.V1Container)1 V1ContainerBuilder (io.kubernetes.client.openapi.models.V1ContainerBuilder)1 V1PodSpec (io.kubernetes.client.openapi.models.V1PodSpec)1