sodonnel commented on code in PR #9024:
URL: https://github.com/apache/ozone/pull/9024#discussion_r2348508435


##########
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/statemachine/commandhandler/TestClosePipelineCommandHandler.java:
##########
@@ -132,6 +139,50 @@ void testCommandIdempotency() throws IOException {
         .remove(any(), anyBoolean(), anyBoolean());
   }
 
+  @Test
+  void testPendingPipelineClose() throws IOException, InterruptedException {
+    final List<DatanodeDetails> datanodes = getDatanodes();
+    final DatanodeDetails currentDatanode = datanodes.get(0);
+    final PipelineID pipelineID = PipelineID.randomId();
+    final UUID pipelineUUID = pipelineID.getId();
+    final SCMCommand<ClosePipelineCommandProto> command1 = new 
ClosePipelineCommand(pipelineID);
+    final SCMCommand<ClosePipelineCommandProto> command2 = new 
ClosePipelineCommand(pipelineID);
+    StateContext stateContext = 
ContainerTestUtils.getMockContext(currentDatanode, conf);
+
+    final boolean shouldDeleteRatisLogDirectory = true;
+    XceiverServerRatis writeChannel = mock(XceiverServerRatis.class);
+    when(ozoneContainer.getWriteChannel()).thenReturn(writeChannel);
+    
when(writeChannel.getShouldDeleteRatisLogDirectory()).thenReturn(shouldDeleteRatisLogDirectory);
+    when(writeChannel.isExist(pipelineID.getProtobuf())).thenReturn(true);
+    Collection<RaftPeer> raftPeers = datanodes.stream()
+        .map(RatisHelper::toRaftPeer)
+        .collect(Collectors.toList());
+    when(writeChannel.getServer()).thenReturn(mock(RaftServer.class));
+    
when(writeChannel.getServer().getId()).thenReturn(RatisHelper.toRaftPeerId(currentDatanode));
+    
when(writeChannel.getRaftPeersInPipeline(pipelineID)).thenReturn(raftPeers);
+
+    lenient().doAnswer(invocation -> {
+      Thread.sleep(200);

Review Comment:
   We should avoid sleep() calls in tests, as it can result in flaky tests and 
also this test will run at best in 50 seconds, which is a very slow test and 
affects the runtime of the builds negatively.
   
   If I understand correctly, this thread basically blocks for 200 seconds to 
give time to attempt to schedule call while its blocking, and prove it has not 
been processed.
   
   You can use something like a pair of countdown latches for this:
   
   
https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CountDownLatch.html
   
   You want to use one latch in the thread to prevent the second command from 
being scheduled until you know for sure the first is running. Then in the main 
thread, use the second latch to tell the thread the second command has been 
scheduled and the thread can exit.
   
   Using that technique you should be able to get a very reliable and fast test 
without sleeps.



-- 
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: issues-unsubscr...@ozone.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org
For additional commands, e-mail: issues-h...@ozone.apache.org

Reply via email to