Skip to content

Commit

Permalink
fix TestYarnCLI
Browse files Browse the repository at this point in the history
  • Loading branch information
stoty committed Mar 9, 2025
1 parent 094e350 commit 5eb2535
Showing 1 changed file with 31 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
Expand Down Expand Up @@ -203,7 +204,9 @@ public void testGetApplicationReport() throws Exception {
String appReportStr = baos.toString("UTF-8");
assertEquals(appReportStr, sysOutStream.toString());
sysOutStream.reset();
verify(sysOut, times(1 + i)).println(isA(String.class));
// TODO does checking the exact number test anything apart from JDK's
// StreamEncoder implementation details ?
verify(sysOut, atLeast(1 + i)).println(isA(String.class));
}
}

Expand Down Expand Up @@ -238,7 +241,7 @@ public void testGetApplicationAttemptReport() throws Exception {
pw.close();
String appReportStr = baos.toString("UTF-8");
assertEquals(appReportStr, sysOutStream.toString());
verify(sysOut, times(1)).println(isA(String.class));
verify(sysOut, atLeast(1)).println(isA(String.class));
}

@Test
Expand Down Expand Up @@ -327,7 +330,7 @@ public void testGetContainerReport() throws Exception {
String appReportStr = baos.toString("UTF-8");

assertEquals(appReportStr, sysOutStream.toString());
verify(sysOut, times(1)).println(isA(String.class));
verify(sysOut, atLeast(1)).println(isA(String.class));
}

@Test
Expand Down Expand Up @@ -521,7 +524,7 @@ public void testGetApplications() throws Exception {
pw.close();
String appsReportStr = baos.toString("UTF-8");
assertEquals(appsReportStr, sysOutStream.toString());
verify(sysOut, times(1)).write(any(byte[].class), anyInt(), anyInt());
verify(sysOut, atLeast(1)).write(any(byte[].class), anyInt(), anyInt());

//Test command yarn application -list --appTypes apptype1,apptype2
//the output should be the same as
Expand Down Expand Up @@ -562,7 +565,7 @@ public void testGetApplications() throws Exception {
pw.close();
appsReportStr = baos.toString("UTF-8");
assertEquals(appsReportStr, sysOutStream.toString());
verify(sysOut, times(2)).write(any(byte[].class), anyInt(), anyInt());
verify(sysOut, atLeast(2)).write(any(byte[].class), anyInt(), anyInt());

//Test command yarn application -list --appStates appState1,appState2
sysOutStream.reset();
Expand Down Expand Up @@ -603,7 +606,7 @@ public void testGetApplications() throws Exception {
pw.close();
appsReportStr = baos.toString("UTF-8");
assertEquals(appsReportStr, sysOutStream.toString());
verify(sysOut, times(3)).write(any(byte[].class), anyInt(), anyInt());
verify(sysOut, atLeast(3)).write(any(byte[].class), anyInt(), anyInt());

// Test command yarn application -list --appTypes apptype1,apptype2
// --appStates appstate1,appstate2
Expand Down Expand Up @@ -642,7 +645,7 @@ public void testGetApplications() throws Exception {
pw.close();
appsReportStr = baos.toString("UTF-8");
assertEquals(appsReportStr, sysOutStream.toString());
verify(sysOut, times(4)).write(any(byte[].class), anyInt(), anyInt());
verify(sysOut, atLeast(4)).write(any(byte[].class), anyInt(), anyInt());

//Test command yarn application -list --appStates with invalid appStates
sysOutStream.reset();
Expand All @@ -664,7 +667,7 @@ public void testGetApplications() throws Exception {
pw.close();
appsReportStr = baos.toString("UTF-8");
assertEquals(appsReportStr, sysOutStream.toString());
verify(sysOut, times(4)).write(any(byte[].class), anyInt(), anyInt());
verify(sysOut, atLeast(4)).write(any(byte[].class), anyInt(), anyInt());

//Test command yarn application -list --appStates all
sysOutStream.reset();
Expand Down Expand Up @@ -723,7 +726,7 @@ public void testGetApplications() throws Exception {
pw.close();
appsReportStr = baos.toString("UTF-8");
assertEquals(appsReportStr, sysOutStream.toString());
verify(sysOut, times(5)).write(any(byte[].class), anyInt(), anyInt());
verify(sysOut, atLeast(5)).write(any(byte[].class), anyInt(), anyInt());

// Test command yarn application user case insensitive
sysOutStream.reset();
Expand Down Expand Up @@ -759,7 +762,7 @@ public void testGetApplications() throws Exception {
pw.close();
appsReportStr = baos.toString("UTF-8");
assertEquals(appsReportStr, sysOutStream.toString());
verify(sysOut, times(6)).write(any(byte[].class), anyInt(), anyInt());
verify(sysOut, atLeast(6)).write(any(byte[].class), anyInt(), anyInt());

// Test command yarn application with tags.
sysOutStream.reset();
Expand Down Expand Up @@ -793,7 +796,7 @@ public void testGetApplications() throws Exception {
pw.close();
appsReportStr = baos.toString("UTF-8");
assertEquals(appsReportStr, sysOutStream.toString());
verify(sysOut, times(7)).write(any(byte[].class), anyInt(), anyInt());
verify(sysOut, atLeast(7)).write(any(byte[].class), anyInt(), anyInt());

sysOutStream.reset();
EnumSet<YarnApplicationState> appState7 =
Expand Down Expand Up @@ -833,7 +836,7 @@ public void testGetApplications() throws Exception {
pw.close();
appsReportStr = baos.toString("UTF-8");
assertEquals(appsReportStr, sysOutStream.toString());
verify(sysOut, times(8)).write(any(byte[].class), anyInt(), anyInt());
verify(sysOut, atLeast(8)).write(any(byte[].class), anyInt(), anyInt());

sysOutStream.reset();
Set<String> appType9 = Sets.newHashSet("YARN");
Expand Down Expand Up @@ -862,7 +865,7 @@ public void testGetApplications() throws Exception {
pw.close();
appsReportStr = baos.toString("UTF-8");
assertEquals(appsReportStr, sysOutStream.toString());
verify(sysOut, times(9)).write(any(byte[].class), anyInt(), anyInt());
verify(sysOut, atLeast(9)).write(any(byte[].class), anyInt(), anyInt());

sysOutStream.reset();
Set<String> appType10 = Sets.newHashSet("HIVE");
Expand Down Expand Up @@ -893,7 +896,7 @@ public void testGetApplications() throws Exception {
pw.close();
appsReportStr = baos.toString("UTF-8");
assertEquals(appsReportStr, sysOutStream.toString());
verify(sysOut, times(10)).write(any(byte[].class), anyInt(), anyInt());
verify(sysOut, atLeast(10)).write(any(byte[].class), anyInt(), anyInt());
}

private List<ApplicationReport> getApplicationReports(
Expand Down Expand Up @@ -1340,7 +1343,7 @@ public void testListClusterNodes() throws Exception {
pw.close();
String nodesReportStr = baos.toString("UTF-8");
assertEquals(nodesReportStr, sysOutStream.toString());
verify(sysOut, times(1)).write(any(byte[].class), anyInt(), anyInt());
verify(sysOut, atLeast(1)).write(any(byte[].class), anyInt(), anyInt());

sysOutStream.reset();
nodeStates.clear();
Expand All @@ -1363,13 +1366,13 @@ public void testListClusterNodes() throws Exception {
pw.close();
nodesReportStr = baos.toString("UTF-8");
assertEquals(nodesReportStr, sysOutStream.toString());
verify(sysOut, times(2)).write(any(byte[].class), anyInt(), anyInt());
verify(sysOut, atLeast(2)).write(any(byte[].class), anyInt(), anyInt());

sysOutStream.reset();
result = cli.run(new String[] {"-list"});
assertEquals(0, result);
assertEquals(nodesReportStr, sysOutStream.toString());
verify(sysOut, times(3)).write(any(byte[].class), anyInt(), anyInt());
verify(sysOut, atLeast(3)).write(any(byte[].class), anyInt(), anyInt());

sysOutStream.reset();
result = cli.run(new String[] {"-list", "-showDetails"});
Expand Down Expand Up @@ -1398,7 +1401,7 @@ public void testListClusterNodes() throws Exception {
pw.close();
nodesReportStr = baos.toString("UTF-8");
assertEquals(nodesReportStr, sysOutStream.toString());
verify(sysOut, times(4)).write(any(byte[].class), anyInt(), anyInt());
verify(sysOut, atLeast(4)).write(any(byte[].class), anyInt(), anyInt());

sysOutStream.reset();
nodeStates.clear();
Expand All @@ -1419,7 +1422,7 @@ public void testListClusterNodes() throws Exception {
pw.close();
nodesReportStr = baos.toString("UTF-8");
assertEquals(nodesReportStr, sysOutStream.toString());
verify(sysOut, times(5)).write(any(byte[].class), anyInt(), anyInt());
verify(sysOut, atLeast(5)).write(any(byte[].class), anyInt(), anyInt());

sysOutStream.reset();
nodeStates.clear();
Expand All @@ -1440,7 +1443,7 @@ public void testListClusterNodes() throws Exception {
pw.close();
nodesReportStr = baos.toString("UTF-8");
assertEquals(nodesReportStr, sysOutStream.toString());
verify(sysOut, times(6)).write(any(byte[].class), anyInt(), anyInt());
verify(sysOut, atLeast(6)).write(any(byte[].class), anyInt(), anyInt());

sysOutStream.reset();
nodeStates.clear();
Expand All @@ -1461,7 +1464,7 @@ public void testListClusterNodes() throws Exception {
pw.close();
nodesReportStr = baos.toString("UTF-8");
assertEquals(nodesReportStr, sysOutStream.toString());
verify(sysOut, times(7)).write(any(byte[].class), anyInt(), anyInt());
verify(sysOut, atLeast(7)).write(any(byte[].class), anyInt(), anyInt());

sysOutStream.reset();
nodeStates.clear();
Expand All @@ -1482,7 +1485,7 @@ public void testListClusterNodes() throws Exception {
pw.close();
nodesReportStr = baos.toString("UTF-8");
assertEquals(nodesReportStr, sysOutStream.toString());
verify(sysOut, times(8)).write(any(byte[].class), anyInt(), anyInt());
verify(sysOut, atLeast(8)).write(any(byte[].class), anyInt(), anyInt());

sysOutStream.reset();
nodeStates.clear();
Expand Down Expand Up @@ -1515,7 +1518,7 @@ public void testListClusterNodes() throws Exception {
pw.close();
nodesReportStr = baos.toString("UTF-8");
assertEquals(nodesReportStr, sysOutStream.toString());
verify(sysOut, times(9)).write(any(byte[].class), anyInt(), anyInt());
verify(sysOut, atLeast(9)).write(any(byte[].class), anyInt(), anyInt());

sysOutStream.reset();
nodeStates.clear();
Expand Down Expand Up @@ -1550,7 +1553,7 @@ public void testListClusterNodes() throws Exception {
pw.close();
nodesReportStr = baos.toString("UTF-8");
assertEquals(nodesReportStr, sysOutStream.toString());
verify(sysOut, times(10)).write(any(byte[].class), anyInt(), anyInt());
verify(sysOut, atLeast(10)).write(any(byte[].class), anyInt(), anyInt());

sysOutStream.reset();
result = cli.run(new String[] { "-list", "-states", "InvalidState"});
Expand Down Expand Up @@ -1601,7 +1604,7 @@ public void testNodeStatus() throws Exception {
pw.println("\tResource Utilization by Containers : PMem:1024 MB, VMem:2048 MB, VCores:4.0");
pw.close();
String nodeStatusStr = baos.toString("UTF-8");
verify(sysOut, times(1)).println(isA(String.class));
verify(sysOut, atLeast(1)).println(isA(String.class));
verify(sysOut).println(nodeStatusStr);
}

Expand Down Expand Up @@ -1635,7 +1638,7 @@ public void testNodeStatusWithEmptyNodeLabels() throws Exception {
pw.println("\tResource Utilization by Containers : PMem:1024 MB, VMem:2048 MB, VCores:4.0");
pw.close();
String nodeStatusStr = baos.toString("UTF-8");
verify(sysOut, times(1)).println(isA(String.class));
verify(sysOut, atLeast(1)).println(isA(String.class));
verify(sysOut).println(nodeStatusStr);
}

Expand Down Expand Up @@ -1669,7 +1672,7 @@ public void testNodeStatusWithEmptyResourceUtilization() throws Exception {
pw.println("\tResource Utilization by Containers : ");
pw.close();
String nodeStatusStr = baos.toString("UTF-8");
verify(sysOut, times(1)).println(isA(String.class));
verify(sysOut, atLeast(1)).println(isA(String.class));
verify(sysOut).println(nodeStatusStr);
}

Expand All @@ -1683,7 +1686,7 @@ public void testAbsentNodeStatus() throws Exception {
int result = cli.run(new String[] { "-status", nodeId.toString() });
assertEquals(0, result);
verify(client).getNodeReports();
verify(sysOut, times(1)).println(isA(String.class));
verify(sysOut, atLeast(1)).println(isA(String.class));
verify(sysOut).println(
"Could not find the node report for node id : " + nodeId.toString());
}
Expand Down

0 comments on commit 5eb2535

Please sign in to comment.