2828import static org .mockito .ArgumentMatchers .any ;
2929import static org .mockito .ArgumentMatchers .anyInt ;
3030import static org .mockito .ArgumentMatchers .isA ;
31+ import static org .mockito .Mockito .atLeast ;
3132import static org .mockito .Mockito .doThrow ;
3233import static org .mockito .Mockito .mock ;
3334import static org .mockito .Mockito .spy ;
@@ -203,7 +204,9 @@ public void testGetApplicationReport() throws Exception {
203204 String appReportStr = baos .toString ("UTF-8" );
204205 assertEquals (appReportStr , sysOutStream .toString ());
205206 sysOutStream .reset ();
206- verify (sysOut , times (1 + i )).println (isA (String .class ));
207+ // TODO does checking the exact number test anything apart from JDK's
208+ // StreamEncoder implementation details ?
209+ verify (sysOut , atLeast (1 + i )).println (isA (String .class ));
207210 }
208211 }
209212
@@ -238,7 +241,7 @@ public void testGetApplicationAttemptReport() throws Exception {
238241 pw .close ();
239242 String appReportStr = baos .toString ("UTF-8" );
240243 assertEquals (appReportStr , sysOutStream .toString ());
241- verify (sysOut , times (1 )).println (isA (String .class ));
244+ verify (sysOut , atLeast (1 )).println (isA (String .class ));
242245 }
243246
244247 @ Test
@@ -327,7 +330,7 @@ public void testGetContainerReport() throws Exception {
327330 String appReportStr = baos .toString ("UTF-8" );
328331
329332 assertEquals (appReportStr , sysOutStream .toString ());
330- verify (sysOut , times (1 )).println (isA (String .class ));
333+ verify (sysOut , atLeast (1 )).println (isA (String .class ));
331334 }
332335
333336 @ Test
@@ -521,7 +524,7 @@ public void testGetApplications() throws Exception {
521524 pw .close ();
522525 String appsReportStr = baos .toString ("UTF-8" );
523526 assertEquals (appsReportStr , sysOutStream .toString ());
524- verify (sysOut , times (1 )).write (any (byte [].class ), anyInt (), anyInt ());
527+ verify (sysOut , atLeast (1 )).write (any (byte [].class ), anyInt (), anyInt ());
525528
526529 //Test command yarn application -list --appTypes apptype1,apptype2
527530 //the output should be the same as
@@ -562,7 +565,7 @@ public void testGetApplications() throws Exception {
562565 pw .close ();
563566 appsReportStr = baos .toString ("UTF-8" );
564567 assertEquals (appsReportStr , sysOutStream .toString ());
565- verify (sysOut , times (2 )).write (any (byte [].class ), anyInt (), anyInt ());
568+ verify (sysOut , atLeast (2 )).write (any (byte [].class ), anyInt (), anyInt ());
566569
567570 //Test command yarn application -list --appStates appState1,appState2
568571 sysOutStream .reset ();
@@ -603,7 +606,7 @@ public void testGetApplications() throws Exception {
603606 pw .close ();
604607 appsReportStr = baos .toString ("UTF-8" );
605608 assertEquals (appsReportStr , sysOutStream .toString ());
606- verify (sysOut , times (3 )).write (any (byte [].class ), anyInt (), anyInt ());
609+ verify (sysOut , atLeast (3 )).write (any (byte [].class ), anyInt (), anyInt ());
607610
608611 // Test command yarn application -list --appTypes apptype1,apptype2
609612 // --appStates appstate1,appstate2
@@ -642,7 +645,7 @@ public void testGetApplications() throws Exception {
642645 pw .close ();
643646 appsReportStr = baos .toString ("UTF-8" );
644647 assertEquals (appsReportStr , sysOutStream .toString ());
645- verify (sysOut , times (4 )).write (any (byte [].class ), anyInt (), anyInt ());
648+ verify (sysOut , atLeast (4 )).write (any (byte [].class ), anyInt (), anyInt ());
646649
647650 //Test command yarn application -list --appStates with invalid appStates
648651 sysOutStream .reset ();
@@ -664,7 +667,7 @@ public void testGetApplications() throws Exception {
664667 pw .close ();
665668 appsReportStr = baos .toString ("UTF-8" );
666669 assertEquals (appsReportStr , sysOutStream .toString ());
667- verify (sysOut , times (4 )).write (any (byte [].class ), anyInt (), anyInt ());
670+ verify (sysOut , atLeast (4 )).write (any (byte [].class ), anyInt (), anyInt ());
668671
669672 //Test command yarn application -list --appStates all
670673 sysOutStream .reset ();
@@ -723,7 +726,7 @@ public void testGetApplications() throws Exception {
723726 pw .close ();
724727 appsReportStr = baos .toString ("UTF-8" );
725728 assertEquals (appsReportStr , sysOutStream .toString ());
726- verify (sysOut , times (5 )).write (any (byte [].class ), anyInt (), anyInt ());
729+ verify (sysOut , atLeast (5 )).write (any (byte [].class ), anyInt (), anyInt ());
727730
728731 // Test command yarn application user case insensitive
729732 sysOutStream .reset ();
@@ -759,7 +762,7 @@ public void testGetApplications() throws Exception {
759762 pw .close ();
760763 appsReportStr = baos .toString ("UTF-8" );
761764 assertEquals (appsReportStr , sysOutStream .toString ());
762- verify (sysOut , times (6 )).write (any (byte [].class ), anyInt (), anyInt ());
765+ verify (sysOut , atLeast (6 )).write (any (byte [].class ), anyInt (), anyInt ());
763766
764767 // Test command yarn application with tags.
765768 sysOutStream .reset ();
@@ -793,7 +796,7 @@ public void testGetApplications() throws Exception {
793796 pw .close ();
794797 appsReportStr = baos .toString ("UTF-8" );
795798 assertEquals (appsReportStr , sysOutStream .toString ());
796- verify (sysOut , times (7 )).write (any (byte [].class ), anyInt (), anyInt ());
799+ verify (sysOut , atLeast (7 )).write (any (byte [].class ), anyInt (), anyInt ());
797800
798801 sysOutStream .reset ();
799802 EnumSet <YarnApplicationState > appState7 =
@@ -833,7 +836,7 @@ public void testGetApplications() throws Exception {
833836 pw .close ();
834837 appsReportStr = baos .toString ("UTF-8" );
835838 assertEquals (appsReportStr , sysOutStream .toString ());
836- verify (sysOut , times (8 )).write (any (byte [].class ), anyInt (), anyInt ());
839+ verify (sysOut , atLeast (8 )).write (any (byte [].class ), anyInt (), anyInt ());
837840
838841 sysOutStream .reset ();
839842 Set <String > appType9 = Sets .newHashSet ("YARN" );
@@ -862,7 +865,7 @@ public void testGetApplications() throws Exception {
862865 pw .close ();
863866 appsReportStr = baos .toString ("UTF-8" );
864867 assertEquals (appsReportStr , sysOutStream .toString ());
865- verify (sysOut , times (9 )).write (any (byte [].class ), anyInt (), anyInt ());
868+ verify (sysOut , atLeast (9 )).write (any (byte [].class ), anyInt (), anyInt ());
866869
867870 sysOutStream .reset ();
868871 Set <String > appType10 = Sets .newHashSet ("HIVE" );
@@ -893,7 +896,7 @@ public void testGetApplications() throws Exception {
893896 pw .close ();
894897 appsReportStr = baos .toString ("UTF-8" );
895898 assertEquals (appsReportStr , sysOutStream .toString ());
896- verify (sysOut , times (10 )).write (any (byte [].class ), anyInt (), anyInt ());
899+ verify (sysOut , atLeast (10 )).write (any (byte [].class ), anyInt (), anyInt ());
897900 }
898901
899902 private List <ApplicationReport > getApplicationReports (
@@ -1340,7 +1343,7 @@ public void testListClusterNodes() throws Exception {
13401343 pw .close ();
13411344 String nodesReportStr = baos .toString ("UTF-8" );
13421345 assertEquals (nodesReportStr , sysOutStream .toString ());
1343- verify (sysOut , times (1 )).write (any (byte [].class ), anyInt (), anyInt ());
1346+ verify (sysOut , atLeast (1 )).write (any (byte [].class ), anyInt (), anyInt ());
13441347
13451348 sysOutStream .reset ();
13461349 nodeStates .clear ();
@@ -1363,13 +1366,13 @@ public void testListClusterNodes() throws Exception {
13631366 pw .close ();
13641367 nodesReportStr = baos .toString ("UTF-8" );
13651368 assertEquals (nodesReportStr , sysOutStream .toString ());
1366- verify (sysOut , times (2 )).write (any (byte [].class ), anyInt (), anyInt ());
1369+ verify (sysOut , atLeast (2 )).write (any (byte [].class ), anyInt (), anyInt ());
13671370
13681371 sysOutStream .reset ();
13691372 result = cli .run (new String [] {"-list" });
13701373 assertEquals (0 , result );
13711374 assertEquals (nodesReportStr , sysOutStream .toString ());
1372- verify (sysOut , times (3 )).write (any (byte [].class ), anyInt (), anyInt ());
1375+ verify (sysOut , atLeast (3 )).write (any (byte [].class ), anyInt (), anyInt ());
13731376
13741377 sysOutStream .reset ();
13751378 result = cli .run (new String [] {"-list" , "-showDetails" });
@@ -1398,7 +1401,7 @@ public void testListClusterNodes() throws Exception {
13981401 pw .close ();
13991402 nodesReportStr = baos .toString ("UTF-8" );
14001403 assertEquals (nodesReportStr , sysOutStream .toString ());
1401- verify (sysOut , times (4 )).write (any (byte [].class ), anyInt (), anyInt ());
1404+ verify (sysOut , atLeast (4 )).write (any (byte [].class ), anyInt (), anyInt ());
14021405
14031406 sysOutStream .reset ();
14041407 nodeStates .clear ();
@@ -1419,7 +1422,7 @@ public void testListClusterNodes() throws Exception {
14191422 pw .close ();
14201423 nodesReportStr = baos .toString ("UTF-8" );
14211424 assertEquals (nodesReportStr , sysOutStream .toString ());
1422- verify (sysOut , times (5 )).write (any (byte [].class ), anyInt (), anyInt ());
1425+ verify (sysOut , atLeast (5 )).write (any (byte [].class ), anyInt (), anyInt ());
14231426
14241427 sysOutStream .reset ();
14251428 nodeStates .clear ();
@@ -1440,7 +1443,7 @@ public void testListClusterNodes() throws Exception {
14401443 pw .close ();
14411444 nodesReportStr = baos .toString ("UTF-8" );
14421445 assertEquals (nodesReportStr , sysOutStream .toString ());
1443- verify (sysOut , times (6 )).write (any (byte [].class ), anyInt (), anyInt ());
1446+ verify (sysOut , atLeast (6 )).write (any (byte [].class ), anyInt (), anyInt ());
14441447
14451448 sysOutStream .reset ();
14461449 nodeStates .clear ();
@@ -1461,7 +1464,7 @@ public void testListClusterNodes() throws Exception {
14611464 pw .close ();
14621465 nodesReportStr = baos .toString ("UTF-8" );
14631466 assertEquals (nodesReportStr , sysOutStream .toString ());
1464- verify (sysOut , times (7 )).write (any (byte [].class ), anyInt (), anyInt ());
1467+ verify (sysOut , atLeast (7 )).write (any (byte [].class ), anyInt (), anyInt ());
14651468
14661469 sysOutStream .reset ();
14671470 nodeStates .clear ();
@@ -1482,7 +1485,7 @@ public void testListClusterNodes() throws Exception {
14821485 pw .close ();
14831486 nodesReportStr = baos .toString ("UTF-8" );
14841487 assertEquals (nodesReportStr , sysOutStream .toString ());
1485- verify (sysOut , times (8 )).write (any (byte [].class ), anyInt (), anyInt ());
1488+ verify (sysOut , atLeast (8 )).write (any (byte [].class ), anyInt (), anyInt ());
14861489
14871490 sysOutStream .reset ();
14881491 nodeStates .clear ();
@@ -1515,7 +1518,7 @@ public void testListClusterNodes() throws Exception {
15151518 pw .close ();
15161519 nodesReportStr = baos .toString ("UTF-8" );
15171520 assertEquals (nodesReportStr , sysOutStream .toString ());
1518- verify (sysOut , times (9 )).write (any (byte [].class ), anyInt (), anyInt ());
1521+ verify (sysOut , atLeast (9 )).write (any (byte [].class ), anyInt (), anyInt ());
15191522
15201523 sysOutStream .reset ();
15211524 nodeStates .clear ();
@@ -1550,7 +1553,7 @@ public void testListClusterNodes() throws Exception {
15501553 pw .close ();
15511554 nodesReportStr = baos .toString ("UTF-8" );
15521555 assertEquals (nodesReportStr , sysOutStream .toString ());
1553- verify (sysOut , times (10 )).write (any (byte [].class ), anyInt (), anyInt ());
1556+ verify (sysOut , atLeast (10 )).write (any (byte [].class ), anyInt (), anyInt ());
15541557
15551558 sysOutStream .reset ();
15561559 result = cli .run (new String [] { "-list" , "-states" , "InvalidState" });
@@ -1601,7 +1604,7 @@ public void testNodeStatus() throws Exception {
16011604 pw .println ("\t Resource Utilization by Containers : PMem:1024 MB, VMem:2048 MB, VCores:4.0" );
16021605 pw .close ();
16031606 String nodeStatusStr = baos .toString ("UTF-8" );
1604- verify (sysOut , times (1 )).println (isA (String .class ));
1607+ verify (sysOut , atLeast (1 )).println (isA (String .class ));
16051608 verify (sysOut ).println (nodeStatusStr );
16061609 }
16071610
@@ -1635,7 +1638,7 @@ public void testNodeStatusWithEmptyNodeLabels() throws Exception {
16351638 pw .println ("\t Resource Utilization by Containers : PMem:1024 MB, VMem:2048 MB, VCores:4.0" );
16361639 pw .close ();
16371640 String nodeStatusStr = baos .toString ("UTF-8" );
1638- verify (sysOut , times (1 )).println (isA (String .class ));
1641+ verify (sysOut , atLeast (1 )).println (isA (String .class ));
16391642 verify (sysOut ).println (nodeStatusStr );
16401643 }
16411644
@@ -1669,7 +1672,7 @@ public void testNodeStatusWithEmptyResourceUtilization() throws Exception {
16691672 pw .println ("\t Resource Utilization by Containers : " );
16701673 pw .close ();
16711674 String nodeStatusStr = baos .toString ("UTF-8" );
1672- verify (sysOut , times (1 )).println (isA (String .class ));
1675+ verify (sysOut , atLeast (1 )).println (isA (String .class ));
16731676 verify (sysOut ).println (nodeStatusStr );
16741677 }
16751678
@@ -1683,7 +1686,7 @@ public void testAbsentNodeStatus() throws Exception {
16831686 int result = cli .run (new String [] { "-status" , nodeId .toString () });
16841687 assertEquals (0 , result );
16851688 verify (client ).getNodeReports ();
1686- verify (sysOut , times (1 )).println (isA (String .class ));
1689+ verify (sysOut , atLeast (1 )).println (isA (String .class ));
16871690 verify (sysOut ).println (
16881691 "Could not find the node report for node id : " + nodeId .toString ());
16891692 }
0 commit comments