Search in sources :

Example 6 with DirectExecutorService

use of org.apache.flink.runtime.util.DirectExecutorService in project flink by apache.

the class HeartbeatManagerTest method testHeartbeatTimeout.

/**
	 * Tests that a heartbeat timeout is signaled if the heartbeat is not reported in time.
	 *
	 * @throws Exception
	 */
@Test
public void testHeartbeatTimeout() throws Exception {
    long heartbeatTimeout = 100L;
    int numHeartbeats = 10;
    long heartbeatInterval = 20L;
    Object payload = new Object();
    ResourceID ownResourceID = new ResourceID("foobar");
    ResourceID targetResourceID = new ResourceID("barfoo");
    TestingHeartbeatListener heartbeatListener = new TestingHeartbeatListener(payload);
    ScheduledExecutorService scheduledExecutorService = mock(ScheduledExecutorService.class);
    ScheduledFuture<?> scheduledFuture = mock(ScheduledFuture.class);
    doReturn(scheduledFuture).when(scheduledExecutorService).schedule(any(Runnable.class), anyLong(), any(TimeUnit.class));
    Object expectedObject = new Object();
    HeartbeatManagerImpl<Object, Object> heartbeatManager = new HeartbeatManagerImpl<>(heartbeatTimeout, ownResourceID, heartbeatListener, new DirectExecutorService(), new ScheduledExecutorServiceAdapter(new ScheduledThreadPoolExecutor(1)), LOG);
    HeartbeatTarget<Object> heartbeatTarget = mock(HeartbeatTarget.class);
    Future<ResourceID> timeoutFuture = heartbeatListener.getTimeoutFuture();
    heartbeatManager.monitorTarget(targetResourceID, heartbeatTarget);
    for (int i = 0; i < numHeartbeats; i++) {
        heartbeatManager.receiveHeartbeat(targetResourceID, expectedObject);
        Thread.sleep(heartbeatInterval);
    }
    assertFalse(timeoutFuture.isDone());
    ResourceID timeoutResourceID = timeoutFuture.get(2 * heartbeatTimeout, TimeUnit.MILLISECONDS);
    assertEquals(targetResourceID, timeoutResourceID);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) DirectExecutorService(org.apache.flink.runtime.util.DirectExecutorService) ScheduledExecutorServiceAdapter(org.apache.flink.runtime.concurrent.ScheduledExecutorServiceAdapter) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.Test)

Aggregations

DirectExecutorService (org.apache.flink.runtime.util.DirectExecutorService)6 Test (org.junit.Test)6 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)5 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)3 ScheduledExecutorServiceAdapter (org.apache.flink.runtime.concurrent.ScheduledExecutorServiceAdapter)3 TimeUnit (java.util.concurrent.TimeUnit)2 ScheduledExecutor (org.apache.flink.runtime.concurrent.ScheduledExecutor)2 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 TimeoutException (java.util.concurrent.TimeoutException)1 TaskInfo (org.apache.flink.api.common.TaskInfo)1 Configuration (org.apache.flink.configuration.Configuration)1 CloseableRegistry (org.apache.flink.core.fs.CloseableRegistry)1 CheckpointMetaData (org.apache.flink.runtime.checkpoint.CheckpointMetaData)1 CheckpointOptions (org.apache.flink.runtime.checkpoint.CheckpointOptions)1 Environment (org.apache.flink.runtime.execution.Environment)1 NetworkEnvironment (org.apache.flink.runtime.io.network.NetworkEnvironment)1 OperatorStateHandle (org.apache.flink.runtime.state.OperatorStateHandle)1 StreamStateHandle (org.apache.flink.runtime.state.StreamStateHandle)1