@Test
public void testResponseIdOverflow() throws Exception {

  Configuration conf = new Configuration();
  rm = new MockRM(conf);
  rm.start();
  MockNM nm1 = rm.registerNode("host1:1234", 5120);
  NodeHeartbeatResponse nodeHeartbeat = nm1.nodeHeartbeat(true);
  Assert.assertEquals(NodeAction.NORMAL, nodeHeartbeat.getNodeAction());
  // prepare the responseId that's about to overflow
  RMNode node = rm.getRMContext().getRMNodes().get(nm1.getNodeId());
  node.getLastNodeHeartBeatResponse().setResponseId(Integer.MAX_VALUE);
  nm1.setResponseId(Integer.MAX_VALUE);
  // heartbeat twice and check responseId
  nodeHeartbeat = nm1.nodeHeartbeat(true);
  Assert.assertEquals(NodeAction.NORMAL, nodeHeartbeat.getNodeAction());
  Assert.assertEquals(0, nodeHeartbeat.getResponseId());
  nodeHeartbeat = nm1.nodeHeartbeat(true);
  Assert.assertEquals(NodeAction.NORMAL, nodeHeartbeat.getNodeAction());
  Assert.assertEquals(1, nodeHeartbeat.getResponseId());
}