@Test(timeout=600000)
public void testInvalidContainerReleaseRequest() throws Exception {

  MockRM rm = new MockRM(conf);
  
  try {
    rm.start();
    // Register node1
    MockNM nm1 = rm.registerNode("127.0.0.1:1234", 6 * GB);
    // Submit an application
    RMApp app1 = rm.submitApp(1024);
    // kick the scheduling
    nm1.nodeHeartbeat(true);
    RMAppAttempt attempt1 = app1.getCurrentAppAttempt();
    MockAM am1 = rm.sendAMLaunched(attempt1.getAppAttemptId());
    am1.registerAppAttempt();
    
    am1.addRequests(new String[] { "127.0.0.1" }, GB, 1, 1);
    AllocateResponse alloc1Response = am1.schedule(); // send the request
    // kick the scheduler
    nm1.nodeHeartbeat(true);
    while (alloc1Response.getAllocatedContainers().size() < 1) {
      LOG.info("Waiting for containers to be created for app 1...");
      sleep(1000);
      alloc1Response = am1.schedule();
    }
    
    Assert.assertTrue(alloc1Response.getAllocatedContainers().size() > 0);
    
    RMApp app2 = rm.submitApp(1024);
    
    nm1.nodeHeartbeat(true);
    RMAppAttempt attempt2 = app2.getCurrentAppAttempt();
    MockAM am2 = rm.sendAMLaunched(attempt2.getAppAttemptId());
    am2.registerAppAttempt();
    
    // Now trying to release container allocated for app1 -> appAttempt1.
    ContainerId cId = alloc1Response.getAllocatedContainers().get(0).getId();
    am2.addContainerToBeReleased(cId);
    try {
      am2.schedule();
      Assert.fail("Exception was expected!!");
    } catch (InvalidContainerReleaseException e) {
      StringBuilder sb = new StringBuilder("Cannot release container : ");
      sb.append(cId.toString());
      sb.append(" not belonging to this application attempt : ");
      sb.append(attempt2.getAppAttemptId().toString());
      Assert.assertTrue(e.getMessage().contains(sb.toString()));
    }
  } finally {
    if (rm != null) {
      rm.stop();
    }
  }
}