sokui commented on code in PR #3186:
URL: https://github.com/apache/ozone/pull/3186#discussion_r876154823
##########
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/pipeline/TestPipelineManagerImpl.java:
##########
@@ -772,6 +776,77 @@ public void testPipelineCloseFlow() throws IOException {
}
@Test
+ public void testGetStalePipelines() throws IOException {
+ SCMHADBTransactionBuffer buffer = new
SCMHADBTransactionBufferStub(dbStore);
+ PipelineManagerImpl pipelineManager =
+ spy(createPipelineManager(true, buffer));
+
+ // For existing pipelines
+ List<Pipeline> pipelines = new ArrayList<>();
+ UUID[] uuids = new UUID[3];
+ String[] ipAddresses = new String[3];
+ String[] hostNames = new String[3];
+ for (int i = 0; i < 3; i++) {
+ uuids[i] = UUID.randomUUID();
+ ipAddresses[i] = "1.2.3." + (i + 1);
+ hostNames[i] = "host" + i;
+
+ Pipeline pipeline = mock(Pipeline.class);
+ DatanodeDetails datanodeDetails = mock(DatanodeDetails.class);
+ when(datanodeDetails.getUuid()).thenReturn(uuids[i]);
+ when(datanodeDetails.getIpAddress()).thenReturn(ipAddresses[i]);
+ when(datanodeDetails.getHostName()).thenReturn(hostNames[i]);
+ List<DatanodeDetails> nodes = new ArrayList<>();
+ nodes.add(datanodeDetails);
+ when(pipeline.getNodes()).thenReturn(nodes);
+ pipelines.add(pipeline);
+ }
+
+ List<DatanodeDetails> nodes = new ArrayList<>();
+ nodes.add(pipelines.get(0).getNodes().get(0));
+ nodes.add(pipelines.get(1).getNodes().get(0));
+ nodes.add(pipelines.get(2).getNodes().get(0));
+ Pipeline pipeline = mock(Pipeline.class);
+ when(pipeline.getNodes()).thenReturn(nodes);
+ pipelines.add(pipeline);
+
+ doReturn(pipelines).when(pipelineManager).getPipelines();
+
+ // node with changed uuid
+ DatanodeDetails node0 = mock(DatanodeDetails.class);
+ UUID changedUUID = UUID.randomUUID();
+ when(node0.getUuid()).thenReturn(changedUUID);
+ when(node0.getIpAddress()).thenReturn(ipAddresses[0]);
+ when(node0.getHostName()).thenReturn(hostNames[0]);
+
+ // test uuid change
+ assertTrue(pipelineManager.getStalePipelines(node0).isEmpty());
+
+ // node with changed IP
+ DatanodeDetails node1 = mock(DatanodeDetails.class);
+ when(node1.getUuid()).thenReturn(uuids[0]);
+ when(node1.getIpAddress()).thenReturn("1.2.3.100");
+ when(node1.getHostName()).thenReturn(hostNames[0]);
+
+ // test IP change
+ List<Pipeline> pipelineList1 = pipelineManager.getStalePipelines(node1);
+ Assertions.assertEquals(2, pipelineList1.size());
+ Assertions.assertEquals(pipelines.get(0), pipelineList1.get(0));
+ Assertions.assertEquals(pipelines.get(3), pipelineList1.get(1));
+
+ // node with changed host name
+ DatanodeDetails node2 = mock(DatanodeDetails.class);
+ when(node2.getUuid()).thenReturn(uuids[0]);
+ when(node2.getIpAddress()).thenReturn(ipAddresses[0]);
+ when(node2.getHostName()).thenReturn("host100");
+
+ // test IP change
+ List<Pipeline> pipelineList2 = pipelineManager.getStalePipelines(node2);
+ Assertions.assertEquals(2, pipelineList1.size());
+ Assertions.assertEquals(pipelines.get(0), pipelineList2.get(0));
+ Assertions.assertEquals(pipelines.get(3), pipelineList2.get(1));
Review Comment:
good catch
--
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]