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 after unmonitoring a target, there won't be a timeout triggered.
	 */
Tests that after unmonitoring a target, there won't be a timeout triggered.
Tests that after unmonitoring a target there won ' t be a timeout triggered .
@Test
	public void testTargetUnmonitoring() throws InterruptedException, ExecutionException {
		long heartbeatTimeout = 100L;
		ResourceID resourceID = new ResourceID("foobar");
		ResourceID targetID = new ResourceID("target");
		Object object = new Object();
		TestingHeartbeatListener heartbeatListener = new TestingHeartbeatListener(object);
		HeartbeatManager<Object, Object> heartbeatManager = new HeartbeatManagerImpl<>(
			heartbeatTimeout,
			resourceID,
			heartbeatListener,
			new DirectExecutorService(),
			new ScheduledExecutorServiceAdapter(new ScheduledThreadPoolExecutor(1)),
			LOG);
		@SuppressWarnings("unchecked")
		final HeartbeatTarget<Object> heartbeatTarget = mock(HeartbeatTarget.class);
		heartbeatManager.monitorTarget(targetID, heartbeatTarget);
		heartbeatManager.unmonitorTarget(targetID);
		CompletableFuture<ResourceID> timeout = heartbeatListener.getTimeoutFuture();
		try {
			timeout.get(2 * heartbeatTimeout, TimeUnit.MILLISECONDS);
			fail("Timeout should time out.");
		} catch (TimeoutException e) {
		}
	}
@ Test public void testTargetUnmonitoring ( ) throws InterruptedException , ExecutionException { long heartbeatTimeout = 100L ; ResourceID resourceID = new ResourceID ( "foobar" ) ; ResourceID targetID = new ResourceID ( "target" ) ; Object object = new Object ( ) ; TestingHeartbeatListener heartbeatListener = new TestingHeartbeatListener ( object ) ; HeartbeatManager < Object , Object > heartbeatManager = new HeartbeatManagerImpl < > ( heartbeatTimeout , resourceID , heartbeatListener , new DirectExecutorService ( ) , new ScheduledExecutorServiceAdapter ( new ScheduledThreadPoolExecutor ( 1 ) ) , LOG ) ; @ SuppressWarnings ( "unchecked" ) final HeartbeatTarget < Object > heartbeatTarget = mock ( HeartbeatTarget . class ) ; heartbeatManager . monitorTarget ( targetID , heartbeatTarget ) ; heartbeatManager . unmonitorTarget ( targetID ) ; CompletableFuture < ResourceID > timeout = heartbeatListener . getTimeoutFuture ( ) ; try { timeout . get ( 2 * heartbeatTimeout , TimeUnit . MILLISECONDS ) ; fail ( "Timeout should time out." ) ; } catch ( TimeoutException e ) { } }
Tests that after unmonitoring a target, there won't be a timeout triggered.
Tests that after unmonitoring a target there won ' t be a timeout triggered .
// this might be too aggresive for Travis, let's see... // the timeout should not be completed since we unmonitored the target