YARN-1332. In TestAMRMClient, replace assertTrue with assertEquals where possible (Sebastian Wong via Sandy Ryza)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1547642 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sanford Ryza 2013-12-03 23:23:49 +00:00
parent faf8b3ff53
commit cf465c26a8
2 changed files with 64 additions and 61 deletions

View File

@ -114,6 +114,9 @@ Release 2.4.0 - UNRELEASED
YARN-1318. Promoted AdminService to an Always-On service and merged it into YARN-1318. Promoted AdminService to an Always-On service and merged it into
RMHAProtocolService. (Karthik Kambatla via vinodkv) RMHAProtocolService. (Karthik Kambatla via vinodkv)
YARN-1332. In TestAMRMClient, replace assertTrue with assertEquals where
possible (Sebastian Wong via Sandy Ryza)
OPTIMIZATIONS OPTIMIZATIONS
BUG FIXES BUG FIXES

View File

@ -248,7 +248,7 @@ public class TestAMRMClient {
matches = amClient.getMatchingRequests(priority, node, testCapability1); matches = amClient.getMatchingRequests(priority, node, testCapability1);
verifyMatches(matches, 1); verifyMatches(matches, 1);
storedRequest = matches.get(0).iterator().next(); storedRequest = matches.get(0).iterator().next();
assertTrue(storedContainer1 == storedRequest); assertEquals(storedContainer1, storedRequest);
amClient.removeContainerRequest(storedContainer1); amClient.removeContainerRequest(storedContainer1);
// exact matching with order maintained // exact matching with order maintained
@ -259,9 +259,9 @@ public class TestAMRMClient {
int i = 0; int i = 0;
for(ContainerRequest storedRequest1 : matches.get(0)) { for(ContainerRequest storedRequest1 : matches.get(0)) {
if(i++ == 0) { if(i++ == 0) {
assertTrue(storedContainer4 == storedRequest1); assertEquals(storedContainer4, storedRequest1);
} else { } else {
assertTrue(storedContainer6 == storedRequest1); assertEquals(storedContainer6, storedRequest1);
} }
} }
amClient.removeContainerRequest(storedContainer6); amClient.removeContainerRequest(storedContainer6);
@ -276,7 +276,7 @@ public class TestAMRMClient {
assert(matches.size() == 2); assert(matches.size() == 2);
// verify non-fitting containers are not returned and fitting ones are // verify non-fitting containers are not returned and fitting ones are
for(Collection<ContainerRequest> testSet : matches) { for(Collection<ContainerRequest> testSet : matches) {
assertTrue(testSet.size() == 1); assertEquals(1, testSet.size());
ContainerRequest testRequest = testSet.iterator().next(); ContainerRequest testRequest = testSet.iterator().next();
assertTrue(testRequest != storedContainer4); assertTrue(testRequest != storedContainer4);
assertTrue(testRequest != storedContainer5); assertTrue(testRequest != storedContainer5);
@ -310,8 +310,8 @@ public class TestAMRMClient {
private void verifyMatches( private void verifyMatches(
List<? extends Collection<ContainerRequest>> matches, List<? extends Collection<ContainerRequest>> matches,
int matchSize) { int matchSize) {
assertTrue(matches.size() == 1); assertEquals(1, matches.size());
assertTrue(matches.get(0).size() == matchSize); assertEquals(matches.get(0).size(), matchSize);
} }
@Test (timeout=60000) @Test (timeout=60000)
@ -337,12 +337,12 @@ public class TestAMRMClient {
matches = amClient.getMatchingRequests(priority, node, capability); matches = amClient.getMatchingRequests(priority, node, capability);
verifyMatches(matches, 1); verifyMatches(matches, 1);
storedRequest = matches.get(0).iterator().next(); storedRequest = matches.get(0).iterator().next();
assertTrue(storedContainer1 == storedRequest); assertEquals(storedContainer1, storedRequest);
// inferred match rack // inferred match rack
matches = amClient.getMatchingRequests(priority, rack, capability); matches = amClient.getMatchingRequests(priority, rack, capability);
verifyMatches(matches, 1); verifyMatches(matches, 1);
storedRequest = matches.get(0).iterator().next(); storedRequest = matches.get(0).iterator().next();
assertTrue(storedContainer1 == storedRequest); assertEquals(storedContainer1, storedRequest);
// inferred rack match no longer valid after request is removed // inferred rack match no longer valid after request is removed
amClient.removeContainerRequest(storedContainer1); amClient.removeContainerRequest(storedContainer1);
@ -387,10 +387,10 @@ public class TestAMRMClient {
// test addition and storage // test addition and storage
int containersRequestedAny = amClient.remoteRequestsTable.get(priority) int containersRequestedAny = amClient.remoteRequestsTable.get(priority)
.get(ResourceRequest.ANY).get(capability).remoteRequest.getNumContainers(); .get(ResourceRequest.ANY).get(capability).remoteRequest.getNumContainers();
assertTrue(containersRequestedAny == 2); assertEquals(2, containersRequestedAny);
containersRequestedAny = amClient.remoteRequestsTable.get(priority1) containersRequestedAny = amClient.remoteRequestsTable.get(priority1)
.get(ResourceRequest.ANY).get(capability).remoteRequest.getNumContainers(); .get(ResourceRequest.ANY).get(capability).remoteRequest.getNumContainers();
assertTrue(containersRequestedAny == 1); assertEquals(1, containersRequestedAny);
List<? extends Collection<ContainerRequest>> matches = List<? extends Collection<ContainerRequest>> matches =
amClient.getMatchingRequests(priority, node, capability); amClient.getMatchingRequests(priority, node, capability);
verifyMatches(matches, 2); verifyMatches(matches, 2);
@ -417,7 +417,7 @@ public class TestAMRMClient {
// test matching of containers // test matching of containers
ContainerRequest storedRequest = matches.get(0).iterator().next(); ContainerRequest storedRequest = matches.get(0).iterator().next();
assertTrue(storedContainer1 == storedRequest); assertEquals(storedContainer1, storedRequest);
amClient.removeContainerRequest(storedContainer1); amClient.removeContainerRequest(storedContainer1);
matches = matches =
amClient.getMatchingRequests(priority, ResourceRequest.ANY, capability); amClient.getMatchingRequests(priority, ResourceRequest.ANY, capability);
@ -438,10 +438,10 @@ public class TestAMRMClient {
&& iterationsLeft-- > 0) { && iterationsLeft-- > 0) {
Log.info(" == alloc " + allocatedContainerCount + " it left " + iterationsLeft); Log.info(" == alloc " + allocatedContainerCount + " it left " + iterationsLeft);
AllocateResponse allocResponse = amClient.allocate(0.1f); AllocateResponse allocResponse = amClient.allocate(0.1f);
assertTrue(amClient.ask.size() == 0); assertEquals(0, amClient.ask.size());
assertTrue(amClient.release.size() == 0); assertEquals(0, amClient.release.size());
assertTrue(nodeCount == amClient.getClusterNodeCount()); assertEquals(nodeCount, amClient.getClusterNodeCount());
allocatedContainerCount += allocResponse.getAllocatedContainers().size(); allocatedContainerCount += allocResponse.getAllocatedContainers().size();
for(Container container : allocResponse.getAllocatedContainers()) { for(Container container : allocResponse.getAllocatedContainers()) {
ContainerRequest expectedRequest = ContainerRequest expectedRequest =
@ -453,7 +453,7 @@ public class TestAMRMClient {
// test correct matched container is returned // test correct matched container is returned
verifyMatches(matches, 1); verifyMatches(matches, 1);
ContainerRequest matchedRequest = matches.get(0).iterator().next(); ContainerRequest matchedRequest = matches.get(0).iterator().next();
assertTrue(matchedRequest == expectedRequest); assertEquals(matchedRequest, expectedRequest);
amClient.removeContainerRequest(matchedRequest); amClient.removeContainerRequest(matchedRequest);
// assign this container, use it and release it // assign this container, use it and release it
amClient.releaseAssignedContainer(container.getId()); amClient.releaseAssignedContainer(container.getId());
@ -464,11 +464,11 @@ public class TestAMRMClient {
} }
} }
assertTrue(allocatedContainerCount == 2); assertEquals(2, allocatedContainerCount);
AllocateResponse allocResponse = amClient.allocate(0.1f); AllocateResponse allocResponse = amClient.allocate(0.1f);
assertTrue(amClient.release.size() == 0); assertEquals(0, amClient.release.size());
assertTrue(amClient.ask.size() == 0); assertEquals(0, amClient.ask.size());
assertTrue(allocResponse.getAllocatedContainers().size() == 0); assertEquals(0, allocResponse.getAllocatedContainers().size());
// 0 requests left. everything got cleaned up // 0 requests left. everything got cleaned up
assertTrue(amClient.remoteRequestsTable.isEmpty()); assertTrue(amClient.remoteRequestsTable.isEmpty());
@ -494,14 +494,14 @@ public class TestAMRMClient {
amClient.start(); amClient.start();
amClient.registerApplicationMaster("Host", 10000, ""); amClient.registerApplicationMaster("Host", 10000, "");
assertTrue(amClient.ask.size() == 0); assertEquals(0, amClient.ask.size());
assertTrue(amClient.release.size() == 0); assertEquals(0, amClient.release.size());
ContainerRequest storedContainer1 = ContainerRequest storedContainer1 =
new ContainerRequest(capability, nodes, racks, priority); new ContainerRequest(capability, nodes, racks, priority);
amClient.addContainerRequest(storedContainer1); amClient.addContainerRequest(storedContainer1);
assertTrue(amClient.ask.size() == 3); assertEquals(3, amClient.ask.size());
assertTrue(amClient.release.size() == 0); assertEquals(0, amClient.release.size());
List<String> localNodeBlacklist = new ArrayList<String>(); List<String> localNodeBlacklist = new ArrayList<String>();
localNodeBlacklist.add(node); localNodeBlacklist.add(node);
@ -512,7 +512,7 @@ public class TestAMRMClient {
int allocatedContainerCount = getAllocatedContainersNumber(amClient, int allocatedContainerCount = getAllocatedContainersNumber(amClient,
DEFAULT_ITERATION); DEFAULT_ITERATION);
// the only node is in blacklist, so no allocation // the only node is in blacklist, so no allocation
assertTrue(allocatedContainerCount == 0); assertEquals(0, allocatedContainerCount);
// Remove node from blacklist, so get assigned with 2 // Remove node from blacklist, so get assigned with 2
amClient.updateBlacklist(null, localNodeBlacklist); amClient.updateBlacklist(null, localNodeBlacklist);
@ -521,7 +521,7 @@ public class TestAMRMClient {
amClient.addContainerRequest(storedContainer2); amClient.addContainerRequest(storedContainer2);
allocatedContainerCount = getAllocatedContainersNumber(amClient, allocatedContainerCount = getAllocatedContainersNumber(amClient,
DEFAULT_ITERATION); DEFAULT_ITERATION);
assertEquals(allocatedContainerCount, 2); assertEquals(2, allocatedContainerCount);
// Test in case exception in allocate(), blacklist is kept // Test in case exception in allocate(), blacklist is kept
assertTrue(amClient.blacklistAdditions.isEmpty()); assertTrue(amClient.blacklistAdditions.isEmpty());
@ -538,7 +538,7 @@ public class TestAMRMClient {
amClient.allocate(0.1f); amClient.allocate(0.1f);
fail("there should be an exception here."); fail("there should be an exception here.");
} catch (Exception e) { } catch (Exception e) {
assertEquals(amClient.blacklistAdditions.size(), 1); assertEquals(1, amClient.blacklistAdditions.size());
} }
} finally { } finally {
if (amClient != null && amClient.getServiceState() == STATE.STARTED) { if (amClient != null && amClient.getServiceState() == STATE.STARTED) {
@ -565,16 +565,16 @@ public class TestAMRMClient {
nodeList01.add(nodes[0]); nodeList01.add(nodes[0]);
nodeList01.add(nodes[1]); nodeList01.add(nodes[1]);
amClient.updateBlacklist(nodeList01, null); amClient.updateBlacklist(nodeList01, null);
assertEquals(amClient.blacklistAdditions.size(),2); assertEquals(2, amClient.blacklistAdditions.size());
assertEquals(amClient.blacklistRemovals.size(),0); assertEquals(0, amClient.blacklistRemovals.size());
// Add nodes[0] again, verify it is not added duplicated. // Add nodes[0] again, verify it is not added duplicated.
List<String> nodeList02 = new ArrayList<String>(); List<String> nodeList02 = new ArrayList<String>();
nodeList02.add(nodes[0]); nodeList02.add(nodes[0]);
nodeList02.add(nodes[2]); nodeList02.add(nodes[2]);
amClient.updateBlacklist(nodeList02, null); amClient.updateBlacklist(nodeList02, null);
assertEquals(amClient.blacklistAdditions.size(),3); assertEquals(3, amClient.blacklistAdditions.size());
assertEquals(amClient.blacklistRemovals.size(),0); assertEquals(0, amClient.blacklistRemovals.size());
// Add nodes[1] and nodes[2] to removal list, // Add nodes[1] and nodes[2] to removal list,
// Verify addition list remove these two nodes. // Verify addition list remove these two nodes.
@ -582,16 +582,16 @@ public class TestAMRMClient {
nodeList12.add(nodes[1]); nodeList12.add(nodes[1]);
nodeList12.add(nodes[2]); nodeList12.add(nodes[2]);
amClient.updateBlacklist(null, nodeList12); amClient.updateBlacklist(null, nodeList12);
assertEquals(amClient.blacklistAdditions.size(),1); assertEquals(1, amClient.blacklistAdditions.size());
assertEquals(amClient.blacklistRemovals.size(),2); assertEquals(2, amClient.blacklistRemovals.size());
// Add nodes[1] again to addition list, // Add nodes[1] again to addition list,
// Verify removal list will remove this node. // Verify removal list will remove this node.
List<String> nodeList1 = new ArrayList<String>(); List<String> nodeList1 = new ArrayList<String>();
nodeList1.add(nodes[1]); nodeList1.add(nodes[1]);
amClient.updateBlacklist(nodeList1, null); amClient.updateBlacklist(nodeList1, null);
assertEquals(amClient.blacklistAdditions.size(),2); assertEquals(2, amClient.blacklistAdditions.size());
assertEquals(amClient.blacklistRemovals.size(),1); assertEquals(1, amClient.blacklistRemovals.size());
} finally { } finally {
if (amClient != null && amClient.getServiceState() == STATE.STARTED) { if (amClient != null && amClient.getServiceState() == STATE.STARTED) {
amClient.stop(); amClient.stop();
@ -606,10 +606,10 @@ public class TestAMRMClient {
while (iterationsLeft-- > 0) { while (iterationsLeft-- > 0) {
Log.info(" == alloc " + allocatedContainerCount + " it left " + iterationsLeft); Log.info(" == alloc " + allocatedContainerCount + " it left " + iterationsLeft);
AllocateResponse allocResponse = amClient.allocate(0.1f); AllocateResponse allocResponse = amClient.allocate(0.1f);
assertTrue(amClient.ask.size() == 0); assertEquals(0, amClient.ask.size());
assertTrue(amClient.release.size() == 0); assertEquals(0, amClient.release.size());
assertTrue(nodeCount == amClient.getClusterNodeCount()); assertEquals(nodeCount, amClient.getClusterNodeCount());
allocatedContainerCount += allocResponse.getAllocatedContainers().size(); allocatedContainerCount += allocResponse.getAllocatedContainers().size();
if(allocatedContainerCount == 0) { if(allocatedContainerCount == 0) {
@ -654,8 +654,8 @@ public class TestAMRMClient {
throws YarnException, IOException { throws YarnException, IOException {
// setup container request // setup container request
assertTrue(amClient.ask.size() == 0); assertEquals(0, amClient.ask.size());
assertTrue(amClient.release.size() == 0); assertEquals(0, amClient.release.size());
amClient.addContainerRequest( amClient.addContainerRequest(
new ContainerRequest(capability, nodes, racks, priority)); new ContainerRequest(capability, nodes, racks, priority));
@ -677,11 +677,11 @@ public class TestAMRMClient {
int containersRequestedAny = amClient.remoteRequestsTable.get(priority) int containersRequestedAny = amClient.remoteRequestsTable.get(priority)
.get(ResourceRequest.ANY).get(capability).remoteRequest.getNumContainers(); .get(ResourceRequest.ANY).get(capability).remoteRequest.getNumContainers();
assertTrue(containersRequestedNode == 2); assertEquals(2, containersRequestedNode);
assertTrue(containersRequestedRack == 2); assertEquals(2, containersRequestedRack);
assertTrue(containersRequestedAny == 2); assertEquals(2, containersRequestedAny);
assertTrue(amClient.ask.size() == 3); assertEquals(3, amClient.ask.size());
assertTrue(amClient.release.size() == 0); assertEquals(0, amClient.release.size());
// RM should allocate container within 2 calls to allocate() // RM should allocate container within 2 calls to allocate()
int allocatedContainerCount = 0; int allocatedContainerCount = 0;
@ -695,10 +695,10 @@ public class TestAMRMClient {
while (allocatedContainerCount < containersRequestedAny while (allocatedContainerCount < containersRequestedAny
&& iterationsLeft-- > 0) { && iterationsLeft-- > 0) {
AllocateResponse allocResponse = amClient.allocate(0.1f); AllocateResponse allocResponse = amClient.allocate(0.1f);
assertTrue(amClient.ask.size() == 0); assertEquals(0, amClient.ask.size());
assertTrue(amClient.release.size() == 0); assertEquals(0, amClient.release.size());
assertTrue(nodeCount == amClient.getClusterNodeCount()); assertEquals(nodeCount, amClient.getClusterNodeCount());
allocatedContainerCount += allocResponse.getAllocatedContainers().size(); allocatedContainerCount += allocResponse.getAllocatedContainers().size();
for(Container container : allocResponse.getAllocatedContainers()) { for(Container container : allocResponse.getAllocatedContainers()) {
ContainerId rejectContainerId = container.getId(); ContainerId rejectContainerId = container.getId();
@ -724,19 +724,19 @@ public class TestAMRMClient {
Assert.assertTrue(receivedNMTokens.size() > 0 Assert.assertTrue(receivedNMTokens.size() > 0
&& receivedNMTokens.size() <= nodeCount); && receivedNMTokens.size() <= nodeCount);
assertTrue(allocatedContainerCount == containersRequestedAny); assertEquals(allocatedContainerCount, containersRequestedAny);
assertTrue(amClient.release.size() == 2); assertEquals(2, amClient.release.size());
assertTrue(amClient.ask.size() == 0); assertEquals(0, amClient.ask.size());
// need to tell the AMRMClient that we dont need these resources anymore // need to tell the AMRMClient that we dont need these resources anymore
amClient.removeContainerRequest( amClient.removeContainerRequest(
new ContainerRequest(capability, nodes, racks, priority)); new ContainerRequest(capability, nodes, racks, priority));
amClient.removeContainerRequest( amClient.removeContainerRequest(
new ContainerRequest(capability, nodes, racks, priority)); new ContainerRequest(capability, nodes, racks, priority));
assertTrue(amClient.ask.size() == 3); assertEquals(3, amClient.ask.size());
// send 0 container count request for resources that are no longer needed // send 0 container count request for resources that are no longer needed
ResourceRequest snoopRequest = amClient.ask.iterator().next(); ResourceRequest snoopRequest = amClient.ask.iterator().next();
assertTrue(snoopRequest.getNumContainers() == 0); assertEquals(0, snoopRequest.getNumContainers());
// test RPC exception handling // test RPC exception handling
amClient.addContainerRequest(new ContainerRequest(capability, nodes, amClient.addContainerRequest(new ContainerRequest(capability, nodes,
@ -744,7 +744,7 @@ public class TestAMRMClient {
amClient.addContainerRequest(new ContainerRequest(capability, nodes, amClient.addContainerRequest(new ContainerRequest(capability, nodes,
racks, priority)); racks, priority));
snoopRequest = amClient.ask.iterator().next(); snoopRequest = amClient.ask.iterator().next();
assertTrue(snoopRequest.getNumContainers() == 2); assertEquals(2, snoopRequest.getNumContainers());
ApplicationMasterProtocol realRM = amClient.rmClient; ApplicationMasterProtocol realRM = amClient.rmClient;
try { try {
@ -768,12 +768,12 @@ public class TestAMRMClient {
amClient.rmClient = realRM; amClient.rmClient = realRM;
} }
assertTrue(amClient.release.size() == 2); assertEquals(2, amClient.release.size());
assertTrue(amClient.ask.size() == 3); assertEquals(3, amClient.ask.size());
snoopRequest = amClient.ask.iterator().next(); snoopRequest = amClient.ask.iterator().next();
// verify that the remove request made in between makeRequest and allocate // verify that the remove request made in between makeRequest and allocate
// has not been lost // has not been lost
assertTrue(snoopRequest.getNumContainers() == 0); assertEquals(0, snoopRequest.getNumContainers());
iterationsLeft = 3; iterationsLeft = 3;
// do a few iterations to ensure RM is not going send new containers // do a few iterations to ensure RM is not going send new containers
@ -781,13 +781,13 @@ public class TestAMRMClient {
// inform RM of rejection // inform RM of rejection
AllocateResponse allocResponse = amClient.allocate(0.1f); AllocateResponse allocResponse = amClient.allocate(0.1f);
// RM did not send new containers because AM does not need any // RM did not send new containers because AM does not need any
assertTrue(allocResponse.getAllocatedContainers().size() == 0); assertEquals(0, allocResponse.getAllocatedContainers().size());
if(allocResponse.getCompletedContainersStatuses().size() > 0) { if(allocResponse.getCompletedContainersStatuses().size() > 0) {
for(ContainerStatus cStatus :allocResponse for(ContainerStatus cStatus :allocResponse
.getCompletedContainersStatuses()) { .getCompletedContainersStatuses()) {
if(releases.contains(cStatus.getContainerId())) { if(releases.contains(cStatus.getContainerId())) {
assertTrue(cStatus.getState() == ContainerState.COMPLETE); assertEquals(cStatus.getState(), ContainerState.COMPLETE);
assertTrue(cStatus.getExitStatus() == -100); assertEquals(-100, cStatus.getExitStatus());
releases.remove(cStatus.getContainerId()); releases.remove(cStatus.getContainerId());
} }
} }
@ -797,8 +797,8 @@ public class TestAMRMClient {
sleep(100); sleep(100);
} }
} }
assertTrue(amClient.ask.size() == 0); assertEquals(0, amClient.ask.size());
assertTrue(amClient.release.size() == 0); assertEquals(0, amClient.release.size());
} }
private void sleep(int sleepTime) { private void sleep(int sleepTime) {