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);
}
}
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);
}
}
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));
}
}
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));
}
}
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));
}
}
Aggregations