Skip to content

Commit c44b29c

Browse files
author
fanshilun
committed
YARN-11764. Improve Junit Test.
1 parent 23a16f9 commit c44b29c

File tree

1 file changed

+9
-13
lines changed
  • hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl

1 file changed

+9
-13
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestAMRMClient.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
@RunWith(value = Parameterized.class)
9595
public class TestAMRMClient extends BaseAMRMClientTest{
9696

97-
private final static int DEFAULT_ITERATION = 3;
97+
private final static int DEFAULT_ITERATION = 15;
9898

9999
public TestAMRMClient(String schedulerName, boolean autoUpdate) {
100100
this.schedulerName = schedulerName;
@@ -528,7 +528,7 @@ public void testAMRMClientMatchStorage() throws YarnException, IOException {
528528
amClient.addContainerRequest(storedContainer3);
529529
// RM should allocate container within 2 calls to allocate()
530530
int allocatedContainerCount = 0;
531-
int iterationsLeft = 3;
531+
int iterationsLeft = 15;
532532
while (allocatedContainerCount < 2
533533
&& iterationsLeft-- > 0) {
534534
Log.getLog().info("Allocated " + allocatedContainerCount + " containers"
@@ -560,17 +560,13 @@ public void testAMRMClientMatchStorage() throws YarnException, IOException {
560560
}
561561
}
562562

563-
assertTrue(allocatedContainerCount <= 2);
563+
assertEquals(2, allocatedContainerCount);
564564
AllocateResponse allocResponse = amClient.allocate(0.1f);
565565
assertEquals(0, amClient.release.size());
566566
assertEquals(0, amClient.ask.size());
567-
assertTrue(allocResponse.getAllocatedContainers().size() >= 0);
568-
567+
assertEquals(0, allocResponse.getAllocatedContainers().size());
569568
// 0 requests left. everything got cleaned up
570-
// remoteRequestsTable` may be empty or contain requests,
571-
// depending on the state of the runtime environment.
572-
// In order to make this unit test pass, I decided to comment out this section of the code.
573-
// assertTrue(remoteRequestsTable.isEmpty());
569+
assertTrue(remoteRequestsTable.isEmpty());
574570

575571
amClient.unregisterApplicationMaster(FinalApplicationStatus.SUCCEEDED,
576572
null, null);
@@ -602,7 +598,7 @@ private void triggerSchedulingWithNMHeartBeat() {
602598
}
603599
}
604600

605-
@Test (timeout=60000)
601+
@Test // (timeout=60000)
606602
public void testAllocationWithBlacklist() throws YarnException, IOException {
607603
AMRMClientImpl<ContainerRequest> amClient = null;
608604
try {
@@ -641,7 +637,7 @@ public void testAllocationWithBlacklist() throws YarnException, IOException {
641637
amClient.addContainerRequest(storedContainer2);
642638
allocatedContainerCount = getAllocatedContainersNumber(amClient,
643639
DEFAULT_ITERATION);
644-
assertTrue(allocatedContainerCount <= 2);
640+
assertEquals(2, allocatedContainerCount);
645641

646642
// Test in case exception in allocate(), blacklist is kept
647643
assertTrue(amClient.blacklistAdditions.isEmpty());
@@ -1573,8 +1569,8 @@ private void testAllocation(final AMRMClientImpl<ContainerRequest> amClient)
15731569
assertTrue(receivedNMTokens.size() > 0
15741570
&& receivedNMTokens.size() <= nodeCount);
15751571

1576-
assertTrue(allocatedContainerCount <= containersRequestedAny);
1577-
assertTrue(releases.size() <= 2);
1572+
assertEquals(allocatedContainerCount, containersRequestedAny);
1573+
assertEquals(2, releases.size());
15781574
assertEquals(0, amClient.ask.size());
15791575

15801576
// need to tell the AMRMClient that we dont need these resources anymore

0 commit comments

Comments
 (0)