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


##########
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/server/TestSCMDatanodeHeartbeatDispatcher.java:
##########
@@ -166,6 +170,74 @@ public void testVersionReportProcessedOnlyWhenPresent() 
throws IOException {
     verify(mockNodeManager, times(1)).processVersionReport(any(), any());
   }
 
+  @Test
+  public void testStaleNodeWithIncompatibleVersionGetsReregisterCommand() 
throws Exception {
+    NodeManager mockNodeManager = mock(NodeManager.class);
+    when(mockNodeManager.isNodeRegistered(any())).thenReturn(true);
+    
when(mockNodeManager.getNodeStatus(any())).thenReturn(NodeStatus.inServiceStale());
+    when(mockNodeManager.shouldFenceDatanode(any(), any())).thenReturn(true);
+
+    SCMDatanodeHeartbeatDispatcher dispatcher =
+        new SCMDatanodeHeartbeatDispatcher(mockNodeManager, 
mock(EventPublisher.class));
+
+    DatanodeVersionProto version = DatanodeVersionProto.newBuilder()
+        .setApparentVersion(1).setSoftwareVersion(1).build();
+    SCMHeartbeatRequestProto heartbeat = SCMHeartbeatRequestProto.newBuilder()
+        .setDatanodeDetails(randomDatanodeDetails().getProtoBufMessage())
+        .setDatanodeVersion(version)
+        .build();
+
+    dispatcher.dispatch(heartbeat);
+
+    verify(mockNodeManager, 
times(1)).addDatanodeCommand(any(DatanodeID.class), 
any(ReregisterCommand.class));
+    verify(mockNodeManager, never()).processHeartbeat(any(), any());
+  }
+
+  @Test
+  public void testDeadNodeWithIncompatibleVersionGetsReregisterCommand() 
throws Exception {
+    NodeManager mockNodeManager = mock(NodeManager.class);
+    when(mockNodeManager.isNodeRegistered(any())).thenReturn(true);
+    
when(mockNodeManager.getNodeStatus(any())).thenReturn(NodeStatus.inServiceDead());
+    when(mockNodeManager.shouldFenceDatanode(any(), any())).thenReturn(true);
+
+    SCMDatanodeHeartbeatDispatcher dispatcher =
+        new SCMDatanodeHeartbeatDispatcher(mockNodeManager, 
mock(EventPublisher.class));
+
+    DatanodeVersionProto version = DatanodeVersionProto.newBuilder()
+        .setApparentVersion(1).setSoftwareVersion(1).build();
+    SCMHeartbeatRequestProto heartbeat = SCMHeartbeatRequestProto.newBuilder()
+        .setDatanodeDetails(randomDatanodeDetails().getProtoBufMessage())
+        .setDatanodeVersion(version)
+        .build();
+
+    dispatcher.dispatch(heartbeat);
+
+    verify(mockNodeManager, 
times(1)).addDatanodeCommand(any(DatanodeID.class), 
any(ReregisterCommand.class));
+    verify(mockNodeManager, never()).processHeartbeat(any(), any());
+  }
+
+  @Test
+  public void testUnhealthyNodeWithoutVersionReportIsNotFenced() throws 
Exception {
+    // A stale or dead node that omits datanodeVersion (e.g. an older binary) 
must not be

Review Comment:
   Yea I only add this from the copilot review, so I will remove it again .



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