28
28
import static org .mockito .ArgumentMatchers .any ;
29
29
import static org .mockito .ArgumentMatchers .anyInt ;
30
30
import static org .mockito .ArgumentMatchers .isA ;
31
+ import static org .mockito .Mockito .atLeast ;
31
32
import static org .mockito .Mockito .doThrow ;
32
33
import static org .mockito .Mockito .mock ;
33
34
import static org .mockito .Mockito .spy ;
@@ -203,7 +204,9 @@ public void testGetApplicationReport() throws Exception {
203
204
String appReportStr = baos .toString ("UTF-8" );
204
205
assertEquals (appReportStr , sysOutStream .toString ());
205
206
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 ));
207
210
}
208
211
}
209
212
@@ -238,7 +241,7 @@ public void testGetApplicationAttemptReport() throws Exception {
238
241
pw .close ();
239
242
String appReportStr = baos .toString ("UTF-8" );
240
243
assertEquals (appReportStr , sysOutStream .toString ());
241
- verify (sysOut , times (1 )).println (isA (String .class ));
244
+ verify (sysOut , atLeast (1 )).println (isA (String .class ));
242
245
}
243
246
244
247
@ Test
@@ -327,7 +330,7 @@ public void testGetContainerReport() throws Exception {
327
330
String appReportStr = baos .toString ("UTF-8" );
328
331
329
332
assertEquals (appReportStr , sysOutStream .toString ());
330
- verify (sysOut , times (1 )).println (isA (String .class ));
333
+ verify (sysOut , atLeast (1 )).println (isA (String .class ));
331
334
}
332
335
333
336
@ Test
@@ -521,7 +524,7 @@ public void testGetApplications() throws Exception {
521
524
pw .close ();
522
525
String appsReportStr = baos .toString ("UTF-8" );
523
526
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 ());
525
528
526
529
//Test command yarn application -list --appTypes apptype1,apptype2
527
530
//the output should be the same as
@@ -562,7 +565,7 @@ public void testGetApplications() throws Exception {
562
565
pw .close ();
563
566
appsReportStr = baos .toString ("UTF-8" );
564
567
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 ());
566
569
567
570
//Test command yarn application -list --appStates appState1,appState2
568
571
sysOutStream .reset ();
@@ -603,7 +606,7 @@ public void testGetApplications() throws Exception {
603
606
pw .close ();
604
607
appsReportStr = baos .toString ("UTF-8" );
605
608
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 ());
607
610
608
611
// Test command yarn application -list --appTypes apptype1,apptype2
609
612
// --appStates appstate1,appstate2
@@ -642,7 +645,7 @@ public void testGetApplications() throws Exception {
642
645
pw .close ();
643
646
appsReportStr = baos .toString ("UTF-8" );
644
647
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 ());
646
649
647
650
//Test command yarn application -list --appStates with invalid appStates
648
651
sysOutStream .reset ();
@@ -664,7 +667,7 @@ public void testGetApplications() throws Exception {
664
667
pw .close ();
665
668
appsReportStr = baos .toString ("UTF-8" );
666
669
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 ());
668
671
669
672
//Test command yarn application -list --appStates all
670
673
sysOutStream .reset ();
@@ -723,7 +726,7 @@ public void testGetApplications() throws Exception {
723
726
pw .close ();
724
727
appsReportStr = baos .toString ("UTF-8" );
725
728
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 ());
727
730
728
731
// Test command yarn application user case insensitive
729
732
sysOutStream .reset ();
@@ -759,7 +762,7 @@ public void testGetApplications() throws Exception {
759
762
pw .close ();
760
763
appsReportStr = baos .toString ("UTF-8" );
761
764
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 ());
763
766
764
767
// Test command yarn application with tags.
765
768
sysOutStream .reset ();
@@ -793,7 +796,7 @@ public void testGetApplications() throws Exception {
793
796
pw .close ();
794
797
appsReportStr = baos .toString ("UTF-8" );
795
798
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 ());
797
800
798
801
sysOutStream .reset ();
799
802
EnumSet <YarnApplicationState > appState7 =
@@ -833,7 +836,7 @@ public void testGetApplications() throws Exception {
833
836
pw .close ();
834
837
appsReportStr = baos .toString ("UTF-8" );
835
838
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 ());
837
840
838
841
sysOutStream .reset ();
839
842
Set <String > appType9 = Sets .newHashSet ("YARN" );
@@ -862,7 +865,7 @@ public void testGetApplications() throws Exception {
862
865
pw .close ();
863
866
appsReportStr = baos .toString ("UTF-8" );
864
867
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 ());
866
869
867
870
sysOutStream .reset ();
868
871
Set <String > appType10 = Sets .newHashSet ("HIVE" );
@@ -893,7 +896,7 @@ public void testGetApplications() throws Exception {
893
896
pw .close ();
894
897
appsReportStr = baos .toString ("UTF-8" );
895
898
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 ());
897
900
}
898
901
899
902
private List <ApplicationReport > getApplicationReports (
@@ -1340,7 +1343,7 @@ public void testListClusterNodes() throws Exception {
1340
1343
pw .close ();
1341
1344
String nodesReportStr = baos .toString ("UTF-8" );
1342
1345
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 ());
1344
1347
1345
1348
sysOutStream .reset ();
1346
1349
nodeStates .clear ();
@@ -1363,13 +1366,13 @@ public void testListClusterNodes() throws Exception {
1363
1366
pw .close ();
1364
1367
nodesReportStr = baos .toString ("UTF-8" );
1365
1368
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 ());
1367
1370
1368
1371
sysOutStream .reset ();
1369
1372
result = cli .run (new String [] {"-list" });
1370
1373
assertEquals (0 , result );
1371
1374
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 ());
1373
1376
1374
1377
sysOutStream .reset ();
1375
1378
result = cli .run (new String [] {"-list" , "-showDetails" });
@@ -1398,7 +1401,7 @@ public void testListClusterNodes() throws Exception {
1398
1401
pw .close ();
1399
1402
nodesReportStr = baos .toString ("UTF-8" );
1400
1403
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 ());
1402
1405
1403
1406
sysOutStream .reset ();
1404
1407
nodeStates .clear ();
@@ -1419,7 +1422,7 @@ public void testListClusterNodes() throws Exception {
1419
1422
pw .close ();
1420
1423
nodesReportStr = baos .toString ("UTF-8" );
1421
1424
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 ());
1423
1426
1424
1427
sysOutStream .reset ();
1425
1428
nodeStates .clear ();
@@ -1440,7 +1443,7 @@ public void testListClusterNodes() throws Exception {
1440
1443
pw .close ();
1441
1444
nodesReportStr = baos .toString ("UTF-8" );
1442
1445
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 ());
1444
1447
1445
1448
sysOutStream .reset ();
1446
1449
nodeStates .clear ();
@@ -1461,7 +1464,7 @@ public void testListClusterNodes() throws Exception {
1461
1464
pw .close ();
1462
1465
nodesReportStr = baos .toString ("UTF-8" );
1463
1466
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 ());
1465
1468
1466
1469
sysOutStream .reset ();
1467
1470
nodeStates .clear ();
@@ -1482,7 +1485,7 @@ public void testListClusterNodes() throws Exception {
1482
1485
pw .close ();
1483
1486
nodesReportStr = baos .toString ("UTF-8" );
1484
1487
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 ());
1486
1489
1487
1490
sysOutStream .reset ();
1488
1491
nodeStates .clear ();
@@ -1515,7 +1518,7 @@ public void testListClusterNodes() throws Exception {
1515
1518
pw .close ();
1516
1519
nodesReportStr = baos .toString ("UTF-8" );
1517
1520
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 ());
1519
1522
1520
1523
sysOutStream .reset ();
1521
1524
nodeStates .clear ();
@@ -1550,7 +1553,7 @@ public void testListClusterNodes() throws Exception {
1550
1553
pw .close ();
1551
1554
nodesReportStr = baos .toString ("UTF-8" );
1552
1555
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 ());
1554
1557
1555
1558
sysOutStream .reset ();
1556
1559
result = cli .run (new String [] { "-list" , "-states" , "InvalidState" });
@@ -1601,7 +1604,7 @@ public void testNodeStatus() throws Exception {
1601
1604
pw .println ("\t Resource Utilization by Containers : PMem:1024 MB, VMem:2048 MB, VCores:4.0" );
1602
1605
pw .close ();
1603
1606
String nodeStatusStr = baos .toString ("UTF-8" );
1604
- verify (sysOut , times (1 )).println (isA (String .class ));
1607
+ verify (sysOut , atLeast (1 )).println (isA (String .class ));
1605
1608
verify (sysOut ).println (nodeStatusStr );
1606
1609
}
1607
1610
@@ -1635,7 +1638,7 @@ public void testNodeStatusWithEmptyNodeLabels() throws Exception {
1635
1638
pw .println ("\t Resource Utilization by Containers : PMem:1024 MB, VMem:2048 MB, VCores:4.0" );
1636
1639
pw .close ();
1637
1640
String nodeStatusStr = baos .toString ("UTF-8" );
1638
- verify (sysOut , times (1 )).println (isA (String .class ));
1641
+ verify (sysOut , atLeast (1 )).println (isA (String .class ));
1639
1642
verify (sysOut ).println (nodeStatusStr );
1640
1643
}
1641
1644
@@ -1669,7 +1672,7 @@ public void testNodeStatusWithEmptyResourceUtilization() throws Exception {
1669
1672
pw .println ("\t Resource Utilization by Containers : " );
1670
1673
pw .close ();
1671
1674
String nodeStatusStr = baos .toString ("UTF-8" );
1672
- verify (sysOut , times (1 )).println (isA (String .class ));
1675
+ verify (sysOut , atLeast (1 )).println (isA (String .class ));
1673
1676
verify (sysOut ).println (nodeStatusStr );
1674
1677
}
1675
1678
@@ -1683,7 +1686,7 @@ public void testAbsentNodeStatus() throws Exception {
1683
1686
int result = cli .run (new String [] { "-status" , nodeId .toString () });
1684
1687
assertEquals (0 , result );
1685
1688
verify (client ).getNodeReports ();
1686
- verify (sysOut , times (1 )).println (isA (String .class ));
1689
+ verify (sysOut , atLeast (1 )).println (isA (String .class ));
1687
1690
verify (sysOut ).println (
1688
1691
"Could not find the node report for node id : " + nodeId .toString ());
1689
1692
}
0 commit comments