@Test
public void testReportHeartbeat() {

	try {
		InstanceManager cm = new InstanceManager();
		
		final int dataPort = 20000;
		HardwareDescription hardwareDescription = HardwareDescription.extractFromSystem(4096);
		InetAddress address = InetAddress.getByName("127.0.0.1");
		
		// register three instances
		InstanceConnectionInfo ici1 = new InstanceConnectionInfo(address, dataPort);
		InstanceConnectionInfo ici2 = new InstanceConnectionInfo(address, dataPort + 1);
		InstanceConnectionInfo ici3 = new InstanceConnectionInfo(address, dataPort + 2);
		JavaTestKit probe1 = new JavaTestKit(system);
		JavaTestKit probe2 = new JavaTestKit(system);
		JavaTestKit probe3 = new JavaTestKit(system);
		
		InstanceID i1 = cm.registerTaskManager(probe1.getRef(), ici1, hardwareDescription, 1, leaderSessionID);
		InstanceID i2 = cm.registerTaskManager(probe2.getRef(), ici2, hardwareDescription, 1, leaderSessionID);
		InstanceID i3 = cm.registerTaskManager(probe3.getRef(), ici3, hardwareDescription, 1, leaderSessionID);
		// report some immediate heart beats
		assertTrue(cm.reportHeartBeat(i1, new byte[] {}));
		assertTrue(cm.reportHeartBeat(i2, new byte[] {}));
		assertTrue(cm.reportHeartBeat(i3, new byte[] {}));
		
		// report heart beat for non-existing instance
		assertFalse(cm.reportHeartBeat(new InstanceID(), new byte[] {}));
		
		final long WAIT = 200;
		CommonTestUtils.sleepUninterruptibly(WAIT);
		Iterator<Instance> it = cm.getAllRegisteredInstances().iterator();
		Instance instance1 = it.next();
		long h1 = instance1.getLastHeartBeat();
		long h2 = it.next().getLastHeartBeat();
		long h3 = it.next().getLastHeartBeat();
		// send one heart beat again and verify that the
		assertTrue(cm.reportHeartBeat(instance1.getId(), new byte[] {}));
		long newH1 = instance1.getLastHeartBeat();
		
		long now = System.currentTimeMillis();
		
		assertTrue(now - h1 >= WAIT);
		assertTrue(now - h2 >= WAIT);
		assertTrue(now - h3 >= WAIT);
		assertTrue(now - newH1 <= WAIT);
		
		cm.shutdown();
	}
	catch (Exception e) {
		System.err.println(e.getMessage());
		e.printStackTrace();
		Assert.fail("Test erroneous: " + e.getMessage());
	}
}