adoroszlai commented on code in PR #5543:
URL: https://github.com/apache/ozone/pull/5543#discussion_r1385307714
##########
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/replication/TestPushReplicator.java:
##########
@@ -126,6 +148,99 @@ void packFailsWithException() throws IOException {
output.assertClosedExactlyOnce();
}
+ @Test
+ void importSameContainerWhenAlreadyImport() throws Exception {
+ long containerId = 1;
+ // 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);
+ // create containerImporter object
+ ContainerSet containerSet = new ContainerSet(0);
+ containerSet.addContainer(container);
+ MutableVolumeSet volumeSet = new MutableVolumeSet("test", conf, null,
+ StorageVolume.VolumeType.DATA_VOLUME, null);
+ ContainerImporter containerImporter = new ContainerImporter(conf,
+ containerSet, controllerMock, volumeSet);
+ File tarFile = new File("dummy.tar");
+ // second import should fail immediately
+ try {
+ containerImporter.importContainer(containerId, tarFile.toPath(),
+ null, NO_COMPRESSION);
+ assertFalse(true, "exception should occur");
+ } catch (StorageContainerException ex) {
+ assertTrue(ex.getResult().equals(
+ ContainerProtos.Result.CONTAINER_EXISTS));
+ }
+ }
+
+ @Test
+ void importSameContainerWhenFirstInProgress() throws Exception {
+ long containerId = 1;
+ // create container
+ KeyValueContainerData containerData = new
KeyValueContainerData(containerId,
+ ContainerLayoutVersion.FILE_PER_BLOCK, 100, "test", "test");
+ KeyValueContainer container = new KeyValueContainer(containerData, conf);
+ // mock controller for return container data with delay
+ ContainerController controllerMock = mock(ContainerController.class);
+ when(controllerMock.importContainer(any(), any(), any()))
+ .thenAnswer((invocation) -> {
+ Thread.sleep(5000);
Review Comment:
Instead of `sleep`, please try to implement the same multithreaded test with
semaphore (or similar), to avoid unnecessary delays and possible timing issues.
--
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]