surahman commented on a change in pull request #3725:
URL: https://github.com/apache/incubator-heron/pull/3725#discussion_r749782858



##########
File path: 
heron/schedulers/tests/java/org/apache/heron/scheduler/kubernetes/V1ControllerTest.java
##########
@@ -737,4 +746,284 @@ public void testConfigureTolerations() {
         CollectionUtils.containsAll(podSpecWithTolerations.getTolerations(),
             expectedTolerationsOverriding));
   }
+
+  @Test
+  public void testCreatePersistentVolumeClaims() {
+    final String topologyName = "topology-name";
+    final String volumeNameOne = "volume-name-one";
+    final String volumeNameTwo = "volume-name-two";
+    final String volumeNameStatic = "volume-name-static";
+    final String claimNameOne = "OnDemand";
+    final String claimNameTwo = "claim-name-two";
+    final String claimNameStatic = "OnDEmaND";
+    final String storageClassName = "storage-class-name";
+    final String sizeLimit = "555Gi";
+    final String accessModesList = "ReadWriteOnce,ReadOnlyMany,ReadWriteMany";
+    final String accessModes = "ReadOnlyMany";
+    final String volumeMode = "VolumeMode";
+    final String path = "/path/to/mount/";
+    final String subPath = "/sub/path/to/mount/";
+    final Map<String, Map<VolumeClaimTemplateConfigKeys, String>> mapPVCOpts =
+        ImmutableMap.of(
+            volumeNameOne, new HashMap<VolumeClaimTemplateConfigKeys, 
String>() {
+              {
+                put(VolumeClaimTemplateConfigKeys.claimName, claimNameOne);
+                put(VolumeClaimTemplateConfigKeys.storageClassName, 
storageClassName);
+                put(VolumeClaimTemplateConfigKeys.sizeLimit, sizeLimit);
+                put(VolumeClaimTemplateConfigKeys.accessModes, 
accessModesList);
+                put(VolumeClaimTemplateConfigKeys.volumeMode, volumeMode);
+                put(VolumeClaimTemplateConfigKeys.path, path);
+              }
+            },
+            volumeNameTwo, new HashMap<VolumeClaimTemplateConfigKeys, 
String>() {
+              {
+                put(VolumeClaimTemplateConfigKeys.claimName, claimNameTwo);
+                put(VolumeClaimTemplateConfigKeys.storageClassName, 
storageClassName);
+                put(VolumeClaimTemplateConfigKeys.sizeLimit, sizeLimit);
+                put(VolumeClaimTemplateConfigKeys.accessModes, accessModes);
+                put(VolumeClaimTemplateConfigKeys.volumeMode, volumeMode);
+                put(VolumeClaimTemplateConfigKeys.path, path);
+                put(VolumeClaimTemplateConfigKeys.subPath, subPath);
+              }
+            },
+            volumeNameStatic, new HashMap<VolumeClaimTemplateConfigKeys, 
String>() {
+              {
+                put(VolumeClaimTemplateConfigKeys.claimName, claimNameStatic);
+                put(VolumeClaimTemplateConfigKeys.sizeLimit, sizeLimit);
+                put(VolumeClaimTemplateConfigKeys.accessModes, accessModes);
+                put(VolumeClaimTemplateConfigKeys.volumeMode, volumeMode);
+                put(VolumeClaimTemplateConfigKeys.path, path);
+                put(VolumeClaimTemplateConfigKeys.subPath, subPath);
+              }
+            }
+        );
+
+    final V1PersistentVolumeClaim claimOne = new 
V1PersistentVolumeClaimBuilder()
+        .withNewMetadata()
+          .withName(volumeNameOne)
+          
.withLabels(V1Controller.getPersistentVolumeClaimLabels(topologyName))
+        .endMetadata()
+        .withNewSpec()
+          .withStorageClassName(storageClassName)
+          .withAccessModes(Arrays.asList(accessModesList.split(",")))
+          .withVolumeMode(volumeMode)
+          .withNewResources()
+            .addToRequests("storage", new Quantity(sizeLimit))
+          .endResources()
+        .endSpec()
+        .build();
+
+    final V1PersistentVolumeClaim claimStatic = new 
V1PersistentVolumeClaimBuilder()
+        .withNewMetadata()
+          .withName(volumeNameStatic)
+          
.withLabels(V1Controller.getPersistentVolumeClaimLabels(topologyName))
+        .endMetadata()
+        .withNewSpec()
+          .withAccessModes(Collections.singletonList(accessModes))
+          .withVolumeMode(volumeMode)
+          .withNewResources()
+            .addToRequests("storage", new Quantity(sizeLimit))
+          .endResources()
+        .endSpec()
+        .build();
+
+    final List<V1PersistentVolumeClaim> expectedClaims =
+        new LinkedList<>(Arrays.asList(claimOne, claimStatic));
+
+    final List<V1PersistentVolumeClaim> actualClaims =
+        v1ControllerWithPodTemplate.createPersistentVolumeClaims(mapPVCOpts);
+
+    Assert.assertTrue(expectedClaims.containsAll(actualClaims));
+  }
+
+  @Test
+  public void testCreatePersistentVolumeClaimVolumesAndMounts() {
+    final String volumeNameOne = "VolumeNameONE";
+    final String volumeNameTwo = "VolumeNameTWO";
+    final String claimNameOne = "claim-name-one";
+    final String claimNameTwo = "OnDemand";
+    final String mountPathOne = "/mount/path/ONE";
+    final String mountPathTwo = "/mount/path/TWO";
+    final String mountSubPathTwo = "/mount/sub/path/TWO";
+    Map<String, Map<VolumeClaimTemplateConfigKeys, String>> mapOfOpts =
+        ImmutableMap.of(
+            volumeNameOne, ImmutableMap.of(
+                VolumeClaimTemplateConfigKeys.claimName, claimNameOne,
+                VolumeClaimTemplateConfigKeys.path, mountPathOne),
+            volumeNameTwo, ImmutableMap.of(
+                VolumeClaimTemplateConfigKeys.claimName, claimNameTwo,
+                VolumeClaimTemplateConfigKeys.path, mountPathTwo,
+                VolumeClaimTemplateConfigKeys.subPath, mountSubPathTwo)
+        );
+    final V1Volume volumeOne = new V1VolumeBuilder()
+        .withName(volumeNameOne)
+        .withNewPersistentVolumeClaim()
+          .withClaimName(claimNameOne)
+        .endPersistentVolumeClaim()
+        .build();
+    final V1Volume volumeTwo = new V1VolumeBuilder()
+        .withName(volumeNameTwo)
+        .withNewPersistentVolumeClaim()
+          .withClaimName(claimNameTwo)
+        .endPersistentVolumeClaim()
+        .build();
+    final V1VolumeMount volumeMountOne = new V1VolumeMountBuilder()
+        .withName(volumeNameOne)
+        .withMountPath(mountPathOne)
+        .build();
+    final V1VolumeMount volumeMountTwo = new V1VolumeMountBuilder()
+        .withName(volumeNameTwo)
+        .withMountPath(mountPathTwo)
+        .withSubPath(mountSubPathTwo)
+        .build();
+
+    // Test case container.
+    final List<TestTuple<Pair<List<V1Volume>, List<V1VolumeMount>>,
+        Pair<List<V1Volume>, List<V1VolumeMount>>>> testCases = new 
LinkedList<>();
+
+    // Default case: No PVC provided.
+    final Pair<List<V1Volume>, List<V1VolumeMount>> actualEmpty =
+        
v1ControllerPodTemplate.createPersistentVolumeClaimVolumesAndMounts(new 
HashMap<>());
+    testCases.add(new TestTuple<>("Generated an empty list of Volumes", 
actualEmpty,
+        new Pair<>(new LinkedList<>(), new LinkedList<>())));
+
+    // PVC Provided.
+    final Pair<List<V1Volume>, List<V1VolumeMount>> expectedFull =
+        new Pair<>(
+            new LinkedList<>(Arrays.asList(volumeOne, volumeTwo)),
+            new LinkedList<>(Arrays.asList(volumeMountOne, volumeMountTwo)));
+    final Pair<List<V1Volume>, List<V1VolumeMount>> actualFull =
+        
v1ControllerPodTemplate.createPersistentVolumeClaimVolumesAndMounts(mapOfOpts);
+    testCases.add(new TestTuple<>("Generated a list of Volumes", actualFull,
+        new Pair<>(expectedFull.first, expectedFull.second)));
+
+    // Testing loop.
+    for (TestTuple<Pair<List<V1Volume>, List<V1VolumeMount>>,
+            Pair<List<V1Volume>, List<V1VolumeMount>>> testCase : testCases) {

Review comment:
       Strange CI error because this line is indented 13.
   
   ```bash
   [ERROR] 
/home/travis/.cache/bazel/_bazel_travis/be6dac4936703c7eedcb4f5cf38cdd65/execroot/org_apache_heron/heron/schedulers/tests/java/org/apache/heron/scheduler/kubernetes/V1ControllerTest.java:902:
 'Pair' have incorrect indentation level 12, expected level should be 13. 
[Indentation]
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to