aryangupta1998 commented on code in PR #8550:
URL: https://github.com/apache/ozone/pull/8550#discussion_r2132036472


##########
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/replication/TestContainerImporter.java:
##########
@@ -187,6 +193,36 @@ public void 
testInconsistentChecksumContainerShouldThrowError() throws Exception
         contains("Container checksum error"));
   }
 
+  @Test
+  public void testImportContainerScansContainer() throws Exception {
+    long containerId = 1;
+    try (MockedStatic<OnDemandContainerDataScanner> mockedStatic = 
mockStatic(OnDemandContainerDataScanner.class)) {
+      // create container
+      KeyValueContainerData containerData = new 
KeyValueContainerData(containerId,
+          ContainerLayoutVersion.FILE_PER_BLOCK, 100, "test", "test");
+      KeyValueContainer container = new KeyValueContainer(containerData, conf);
+      ContainerController controllerMock = mock(ContainerController.class);
+      when(controllerMock.importContainer(any(), any(), 
any())).thenReturn(container);
+
+      // create containerImporter object
+      ContainerSet containerSet = newContainerSet(0);
+      MutableVolumeSet volumeSet = new MutableVolumeSet("test", conf, null,
+          StorageVolume.VolumeType.DATA_VOLUME, null);
+      HddsVolume targetVolume = mock(HddsVolume.class);
+      doNothing().when(targetVolume).incrementUsedSpace(anyLong());
+      ContainerImporter containerImporter = new ContainerImporter(conf,
+          containerSet, controllerMock, volumeSet, volumeChoosingPolicy);
+
+      // import the container
+      File tarFile = containerTarFile(containerId, containerData);
+      containerImporter.importContainer(containerId, tarFile.toPath(),
+          targetVolume, NO_COMPRESSION);
+
+      // verify static method was called
+      mockedStatic.verify(() -> 
OnDemandContainerDataScanner.scanContainer(container), times(1));

Review Comment:
   We should also verify in the test that the container actually gets added to 
the containerSet.
   Something like,
   ```suggestion
         mockedStatic.verify(() -> 
OnDemandContainerDataScanner.scanContainer(container), times(1));
         assertNotNull(containerSet.getContainer(containerId));
   ```



##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/replication/ContainerImporter.java:
##########
@@ -120,9 +121,10 @@ public void importContainer(long containerID, Path 
tarFilePath,
       try (InputStream input = Files.newInputStream(tarFilePath)) {
         Container container = controller.importContainer(
             containerData, input, packer);
-        // After container import is successful, increase used space for the 
volume
+        // After container import is successful, increase used space for the 
volume and schedule an OnDemand scan for it
         
targetVolume.incrementUsedSpace(container.getContainerData().getBytesUsed());
         containerSet.addContainerByOverwriteMissingContainer(container);
+        OnDemandContainerDataScanner.scanContainer(container);

Review Comment:
   ```suggestion
           Optional<Future<?>> scanFuture = 
OnDemandContainerDataScanner.scanContainer(container);
           if (scanFuture.isPresent()) {
             LOG.info("Scheduled on-demand scan for imported container {}", 
containerID);
           } else {
             LOG.debug("Skipped on-demand scan for imported container {}", 
containerID);
           }
   ```



##########
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/replication/TestContainerImporter.java:
##########
@@ -187,6 +193,36 @@ public void 
testInconsistentChecksumContainerShouldThrowError() throws Exception
         contains("Container checksum error"));
   }
 
+  @Test
+  public void testImportContainerScansContainer() throws Exception {

Review Comment:
   ```suggestion
     public void testImportContainerTriggersOnDemandScanner() throws Exception {
   ```



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to