flink-instrumentation/workspace/flink-1.4.1-instrumented/flink-1.4.1/flink-runtime/src/test/java/org/apache/flink/runtime/heartbeat/HeartbeatManagerTest.java
/**
	 * Tests that we can correctly retrieve the last heartbeat for registered targets.
	 */
Tests that we can correctly retrieve the last heartbeat for registered targets.
Tests that we can correctly retrieve the last heartbeat for registered targets .
@Test
	public void testLastHeartbeatFrom() {
		final long heartbeatTimeout = 100L;
		final ResourceID resourceId = ResourceID.generate();
		@SuppressWarnings("unchecked")
		final HeartbeatListener<Object, Object> heartbeatListener = mock(HeartbeatListener.class);
		@SuppressWarnings("unchecked")
		final HeartbeatTarget<Object> heartbeatTarget = mock(HeartbeatTarget.class);
		final ResourceID target = ResourceID.generate();
		HeartbeatManager<Object, Object> heartbeatManager = new HeartbeatManagerImpl<>(
			heartbeatTimeout,
			resourceId,
			heartbeatListener,
			Executors.directExecutor(),
			mock(ScheduledExecutor.class),
			LOG);
		try {
			heartbeatManager.monitorTarget(target, heartbeatTarget);
			assertEquals(0L, heartbeatManager.getLastHeartbeatFrom(target));
			final long currentTime = System.currentTimeMillis();
			heartbeatManager.receiveHeartbeat(target, null);
			assertTrue(heartbeatManager.getLastHeartbeatFrom(target) >= currentTime);
		} finally {
			heartbeatManager.stop();
		}
	}
@ Test public void testLastHeartbeatFrom ( ) { final long heartbeatTimeout = 100L ; final ResourceID resourceId = ResourceID . generate ( ) ; @ SuppressWarnings ( "unchecked" ) final HeartbeatListener < Object , Object > heartbeatListener = mock ( HeartbeatListener . class ) ; @ SuppressWarnings ( "unchecked" ) final HeartbeatTarget < Object > heartbeatTarget = mock ( HeartbeatTarget . class ) ; final ResourceID target = ResourceID . generate ( ) ; HeartbeatManager < Object , Object > heartbeatManager = new HeartbeatManagerImpl < > ( heartbeatTimeout , resourceId , heartbeatListener , Executors . directExecutor ( ) , mock ( ScheduledExecutor . class ) , LOG ) ; try { heartbeatManager . monitorTarget ( target , heartbeatTarget ) ; assertEquals ( 0L , heartbeatManager . getLastHeartbeatFrom ( target ) ) ; final long currentTime = System . currentTimeMillis ( ) ; heartbeatManager . receiveHeartbeat ( target , null ) ; assertTrue ( heartbeatManager . getLastHeartbeatFrom ( target ) >= currentTime ) ; } finally { heartbeatManager . stop ( ) ; } }
Tests that we can correctly retrieve the last heartbeat for registered targets.
Tests that we can correctly retrieve the last heartbeat for registered targets .