use of java.util.concurrent.TimeoutException in project flink by apache.
the class RpcConnectionTest method testConnectFailure.
@Test
public void testConnectFailure() {
ActorSystem actorSystem = null;
RpcService rpcService = null;
try {
actorSystem = AkkaUtils.createActorSystem(new Configuration(), Option.apply(new Tuple2<String, Object>("localhost", 0)));
// we start the RPC service with a very long timeout to ensure that the test
// can only pass if the connection problem is not recognized merely via a timeout
rpcService = new AkkaRpcService(actorSystem, Time.of(10000000, TimeUnit.SECONDS));
Future<TaskExecutorGateway> future = rpcService.connect("foo.bar.com.test.invalid", TaskExecutorGateway.class);
future.get(10000000, TimeUnit.SECONDS);
fail("should never complete normally");
} catch (TimeoutException e) {
fail("should not fail with a generic timeout exception");
} catch (ExecutionException e) {
// that is what we want
assertTrue(e.getCause() instanceof RpcConnectionException);
assertTrue("wrong error message", e.getCause().getMessage().contains("foo.bar.com.test.invalid"));
} catch (Throwable t) {
fail("wrong exception: " + t);
} finally {
if (rpcService != null) {
rpcService.stopService();
}
if (actorSystem != null) {
actorSystem.shutdown();
}
}
}
use of java.util.concurrent.TimeoutException in project flink by apache.
the class AkkaRpcServiceTest method testExecuteCallable.
/**
* Tests that the {@link AkkaRpcService} can execute callables and returns their result as
* a {@link Future}.
*/
@Test
public void testExecuteCallable() throws InterruptedException, ExecutionException, TimeoutException {
final OneShotLatch latch = new OneShotLatch();
final int expected = 42;
Future<Integer> result = akkaRpcService.execute(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
latch.trigger();
return expected;
}
});
int actual = result.get(30L, TimeUnit.SECONDS);
assertEquals(expected, actual);
assertTrue(latch.isTriggered());
}
use of java.util.concurrent.TimeoutException in project flink by apache.
the class AbstractTaskManagerProcessFailureRecoveryTest method waitUntilNumTaskManagersAreRegistered.
protected void waitUntilNumTaskManagersAreRegistered(ActorRef jobManager, int numExpected, long maxDelayMillis) throws Exception {
// 10 ms = 10,000,000 nanos
final long pollInterval = 10_000_000;
final long deadline = System.nanoTime() + maxDelayMillis * 1_000_000;
long time;
while ((time = System.nanoTime()) < deadline) {
FiniteDuration timeout = new FiniteDuration(pollInterval, TimeUnit.NANOSECONDS);
try {
Future<?> result = Patterns.ask(jobManager, JobManagerMessages.getRequestNumberRegisteredTaskManager(), new Timeout(timeout));
int numTMs = (Integer) Await.result(result, timeout);
if (numTMs == numExpected) {
return;
}
} catch (TimeoutException e) {
// ignore and retry
} catch (ClassCastException e) {
fail("Wrong response: " + e.getMessage());
}
long timePassed = System.nanoTime() - time;
long remainingMillis = (pollInterval - timePassed) / 1_000_000;
if (remainingMillis > 0) {
Thread.sleep(remainingMillis);
}
}
fail("The TaskManagers did not register within the expected time (" + maxDelayMillis + "msecs)");
}
use of java.util.concurrent.TimeoutException in project flink by apache.
the class DirectExecutorService method invokeAny.
@Override
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
long end = System.currentTimeMillis() + unit.toMillis(timeout);
Exception exception = null;
Iterator<? extends Callable<T>> iterator = tasks.iterator();
while (end > System.currentTimeMillis() && iterator.hasNext()) {
Callable<T> callable = iterator.next();
try {
return callable.call();
} catch (Exception e) {
// ignore exception and try next
exception = e;
}
}
if (iterator.hasNext()) {
throw new TimeoutException("Could not finish execution of tasks within time.");
} else {
throw new ExecutionException("No tasks finished successfully.", exception);
}
}
use of java.util.concurrent.TimeoutException in project flink by apache.
the class TaskTest method testTriggerPartitionStateUpdate.
/**
* Tests the trigger partition state update future completions.
*/
@Test
public void testTriggerPartitionStateUpdate() throws Exception {
IntermediateDataSetID resultId = new IntermediateDataSetID();
ResultPartitionID partitionId = new ResultPartitionID();
LibraryCacheManager libCache = mock(LibraryCacheManager.class);
when(libCache.getClassLoader(any(JobID.class))).thenReturn(getClass().getClassLoader());
PartitionProducerStateChecker partitionChecker = mock(PartitionProducerStateChecker.class);
ResultPartitionConsumableNotifier consumableNotifier = mock(ResultPartitionConsumableNotifier.class);
NetworkEnvironment network = mock(NetworkEnvironment.class);
when(network.getResultPartitionManager()).thenReturn(mock(ResultPartitionManager.class));
when(network.getDefaultIOMode()).thenReturn(IOManager.IOMode.SYNC);
when(network.createKvStateTaskRegistry(any(JobID.class), any(JobVertexID.class))).thenReturn(mock(TaskKvStateRegistry.class));
createTask(InvokableBlockingInInvoke.class, libCache, network, consumableNotifier, partitionChecker, Executors.directExecutor());
// Test all branches of trigger partition state check
{
// Reset latches
createQueuesAndActors();
// PartitionProducerDisposedException
Task task = createTask(InvokableBlockingInInvoke.class, libCache, network, consumableNotifier, partitionChecker, Executors.directExecutor());
FlinkCompletableFuture<ExecutionState> promise = new FlinkCompletableFuture<>();
when(partitionChecker.requestPartitionProducerState(eq(task.getJobID()), eq(resultId), eq(partitionId))).thenReturn(promise);
task.triggerPartitionProducerStateCheck(task.getJobID(), resultId, partitionId);
promise.completeExceptionally(new PartitionProducerDisposedException(partitionId));
assertEquals(ExecutionState.CANCELING, task.getExecutionState());
}
{
// Reset latches
createQueuesAndActors();
// Any other exception
Task task = createTask(InvokableBlockingInInvoke.class, libCache, network, consumableNotifier, partitionChecker, Executors.directExecutor());
FlinkCompletableFuture<ExecutionState> promise = new FlinkCompletableFuture<>();
when(partitionChecker.requestPartitionProducerState(eq(task.getJobID()), eq(resultId), eq(partitionId))).thenReturn(promise);
task.triggerPartitionProducerStateCheck(task.getJobID(), resultId, partitionId);
promise.completeExceptionally(new RuntimeException("Any other exception"));
assertEquals(ExecutionState.FAILED, task.getExecutionState());
}
{
// Reset latches
createQueuesAndActors();
// TimeoutException handled special => retry
Task task = createTask(InvokableBlockingInInvoke.class, libCache, network, consumableNotifier, partitionChecker, Executors.directExecutor());
SingleInputGate inputGate = mock(SingleInputGate.class);
when(inputGate.getConsumedResultId()).thenReturn(resultId);
try {
task.startTaskThread();
awaitLatch.await();
setInputGate(task, inputGate);
FlinkCompletableFuture<ExecutionState> promise = new FlinkCompletableFuture<>();
when(partitionChecker.requestPartitionProducerState(eq(task.getJobID()), eq(resultId), eq(partitionId))).thenReturn(promise);
task.triggerPartitionProducerStateCheck(task.getJobID(), resultId, partitionId);
promise.completeExceptionally(new TimeoutException());
assertEquals(ExecutionState.RUNNING, task.getExecutionState());
verify(inputGate, times(1)).retriggerPartitionRequest(eq(partitionId.getPartitionId()));
} finally {
task.getExecutingThread().interrupt();
task.getExecutingThread().join();
}
}
{
// Reset latches
createQueuesAndActors();
// Success
Task task = createTask(InvokableBlockingInInvoke.class, libCache, network, consumableNotifier, partitionChecker, Executors.directExecutor());
SingleInputGate inputGate = mock(SingleInputGate.class);
when(inputGate.getConsumedResultId()).thenReturn(resultId);
try {
task.startTaskThread();
awaitLatch.await();
setInputGate(task, inputGate);
FlinkCompletableFuture<ExecutionState> promise = new FlinkCompletableFuture<>();
when(partitionChecker.requestPartitionProducerState(eq(task.getJobID()), eq(resultId), eq(partitionId))).thenReturn(promise);
task.triggerPartitionProducerStateCheck(task.getJobID(), resultId, partitionId);
promise.complete(ExecutionState.RUNNING);
assertEquals(ExecutionState.RUNNING, task.getExecutionState());
verify(inputGate, times(1)).retriggerPartitionRequest(eq(partitionId.getPartitionId()));
} finally {
task.getExecutingThread().interrupt();
task.getExecutingThread().join();
}
}
}
Aggregations