use of org.apache.flink.runtime.concurrent.impl.FlinkCompletableFuture in project flink by apache.
the class AkkaRpcService method startServer.
@Override
public <C extends RpcGateway, S extends RpcEndpoint<C>> C startServer(S rpcEndpoint) {
checkNotNull(rpcEndpoint, "rpc endpoint");
CompletableFuture<Void> terminationFuture = new FlinkCompletableFuture<>();
Props akkaRpcActorProps = Props.create(AkkaRpcActor.class, rpcEndpoint, terminationFuture);
ActorRef actorRef;
synchronized (lock) {
checkState(!stopped, "RpcService is stopped");
actorRef = actorSystem.actorOf(akkaRpcActorProps);
actors.add(actorRef);
}
LOG.info("Starting RPC endpoint for {} at {} .", rpcEndpoint.getClass().getName(), actorRef.path());
final String address = AkkaUtils.getAkkaURL(actorSystem, actorRef);
final String hostname;
Option<String> host = actorRef.path().address().host();
if (host.isEmpty()) {
hostname = "localhost";
} else {
hostname = host.get();
}
InvocationHandler akkaInvocationHandler = new AkkaInvocationHandler(address, hostname, actorRef, timeout, maximumFramesize, terminationFuture);
// Rather than using the System ClassLoader directly, we derive the ClassLoader
// from this class . That works better in cases where Flink runs embedded and all Flink
// code is loaded dynamically (for example from an OSGI bundle) through a custom ClassLoader
ClassLoader classLoader = getClass().getClassLoader();
@SuppressWarnings("unchecked") C self = (C) Proxy.newProxyInstance(classLoader, new Class<?>[] { rpcEndpoint.getSelfGatewayType(), SelfGateway.class, MainThreadExecutable.class, StartStoppable.class, AkkaGateway.class }, akkaInvocationHandler);
return self;
}
use of org.apache.flink.runtime.concurrent.impl.FlinkCompletableFuture in project flink by apache.
the class ExecutionGraphSchedulingTest method testTimeoutForSlotAllocation.
/**
* This test verifies that the slot allocations times out after a certain time, and that
* all slots are released in that case.
*/
@Test
public void testTimeoutForSlotAllocation() throws Exception {
// we construct a simple graph: (task)
final int parallelism = 3;
final JobVertex vertex = new JobVertex("task");
vertex.setParallelism(parallelism);
vertex.setInvokableClass(NoOpInvokable.class);
final JobID jobId = new JobID();
final JobGraph jobGraph = new JobGraph(jobId, "test", vertex);
final SlotOwner slotOwner = mock(SlotOwner.class);
final TaskManagerGateway taskManager = mock(TaskManagerGateway.class);
final SimpleSlot[] slots = new SimpleSlot[parallelism];
@SuppressWarnings({ "unchecked", "rawtypes" }) final FlinkCompletableFuture<SimpleSlot>[] slotFutures = new FlinkCompletableFuture[parallelism];
for (int i = 0; i < parallelism; i++) {
slots[i] = createSlot(taskManager, jobId, slotOwner);
slotFutures[i] = new FlinkCompletableFuture<>();
}
ProgrammedSlotProvider slotProvider = new ProgrammedSlotProvider(parallelism);
slotProvider.addSlots(vertex.getID(), slotFutures);
final ExecutionGraph eg = createExecutionGraph(jobGraph, slotProvider, Time.milliseconds(20));
final TerminalJobStatusListener statusListener = new TerminalJobStatusListener();
eg.registerJobStatusListener(statusListener);
// we complete one future
slotFutures[1].complete(slots[1]);
// kick off the scheduling
eg.setScheduleMode(ScheduleMode.EAGER);
eg.setQueuedSchedulingAllowed(true);
eg.scheduleForExecution();
// we complete another future
slotFutures[2].complete(slots[2]);
// since future[0] is still missing the while operation must time out
// we have no restarts allowed, so the job will go terminal
statusListener.waitForTerminalState(2000);
// wait until all slots are back
verify(slotOwner, new Timeout(2000, times(2))).returnAllocatedSlot(any(Slot.class));
// verify that no deployments have happened
verify(taskManager, times(0)).submitTask(any(TaskDeploymentDescriptor.class), any(Time.class));
for (Future<SimpleSlot> future : slotFutures) {
if (future.isDone()) {
assertTrue(future.get().isCanceled());
}
}
}
use of org.apache.flink.runtime.concurrent.impl.FlinkCompletableFuture in project flink by apache.
the class FlinkFutureTest method testGetNow.
@Test
public void testGetNow() throws ExecutionException {
CompletableFuture<Integer> initialFuture = new FlinkCompletableFuture<>();
final int absentValue = 41;
assertEquals(new Integer(absentValue), initialFuture.getNow(absentValue));
}
use of org.apache.flink.runtime.concurrent.impl.FlinkCompletableFuture in project flink by apache.
the class FutureUtilsTest method testConjunctFutureCompletion.
@Test
public void testConjunctFutureCompletion() throws Exception {
// some futures that we combine
CompletableFuture<Object> future1 = new FlinkCompletableFuture<>();
CompletableFuture<Object> future2 = new FlinkCompletableFuture<>();
CompletableFuture<Object> future3 = new FlinkCompletableFuture<>();
CompletableFuture<Object> future4 = new FlinkCompletableFuture<>();
// some future is initially completed
future2.complete(new Object());
// build the conjunct future
ConjunctFuture result = FutureUtils.combineAll(Arrays.asList(future1, future2, future3, future4));
Future<Void> resultMapped = result.thenAccept(new AcceptFunction<Void>() {
@Override
public void accept(Void value) {
}
});
assertEquals(4, result.getNumFuturesTotal());
assertEquals(1, result.getNumFuturesCompleted());
assertFalse(result.isDone());
assertFalse(resultMapped.isDone());
// complete two more futures
future4.complete(new Object());
assertEquals(2, result.getNumFuturesCompleted());
assertFalse(result.isDone());
assertFalse(resultMapped.isDone());
future1.complete(new Object());
assertEquals(3, result.getNumFuturesCompleted());
assertFalse(result.isDone());
assertFalse(resultMapped.isDone());
// complete one future again
future1.complete(new Object());
assertEquals(3, result.getNumFuturesCompleted());
assertFalse(result.isDone());
assertFalse(resultMapped.isDone());
// complete the final future
future3.complete(new Object());
assertEquals(4, result.getNumFuturesCompleted());
assertTrue(result.isDone());
assertTrue(resultMapped.isDone());
}
use of org.apache.flink.runtime.concurrent.impl.FlinkCompletableFuture in project flink by apache.
the class FutureUtilsTest method testConjunctFutureFailureOnSuccessive.
@Test
public void testConjunctFutureFailureOnSuccessive() throws Exception {
CompletableFuture<Object> future1 = new FlinkCompletableFuture<>();
CompletableFuture<Object> future2 = new FlinkCompletableFuture<>();
CompletableFuture<Object> future3 = new FlinkCompletableFuture<>();
CompletableFuture<Object> future4 = new FlinkCompletableFuture<>();
// build the conjunct future
ConjunctFuture result = FutureUtils.combineAll(Arrays.asList(future1, future2, future3, future4));
assertEquals(4, result.getNumFuturesTotal());
Future<Void> resultMapped = result.thenAccept(new AcceptFunction<Void>() {
@Override
public void accept(Void value) {
}
});
future1.complete(new Object());
future3.complete(new Object());
future4.complete(new Object());
future2.completeExceptionally(new IOException());
assertEquals(3, result.getNumFuturesCompleted());
assertTrue(result.isDone());
assertTrue(resultMapped.isDone());
try {
result.get();
fail();
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof IOException);
}
try {
resultMapped.get();
fail();
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof IOException);
}
}
Aggregations