use of org.infinispan.interceptors.InvocationSuccessFunction in project infinispan by infinispan.
the class AsyncInterceptorChainInvocationTest method testAsyncStageComposeAsyncStage.
public void testAsyncStageComposeAsyncStage() throws Exception {
CompletableFuture<Object> f1 = new CompletableFuture<>();
CompletableFuture<Object> f2 = new CompletableFuture<>();
CompletableFuture<Object> f3 = new CompletableFuture<>();
AsyncInterceptorChain chain = newInterceptorChain(new BaseAsyncInterceptor() {
@Override
public Object visitCommand(InvocationContext ctx, VisitableCommand command) throws Throwable {
return invokeNextAndHandle(ctx, command, (rCtx, rCommand, rv, t) -> {
InvocationSuccessFunction function = (rCtx1, rCommand1, rv1) -> asyncValue(f3);
return asyncValue(f2).addCallback(rCtx, rCommand, function);
});
}
}, new BaseAsyncInterceptor() {
@Override
public Object visitCommand(InvocationContext ctx, VisitableCommand command) throws Throwable {
return asyncValue(f1);
}
});
InvocationContext context = newInvocationContext();
CompletableFuture<Object> invokeFuture = chain.invokeAsync(context, testCommand);
assertFalse(invokeFuture.isDone());
f1.complete("v1");
assertFalse(invokeFuture.isDone());
f2.complete("v2");
assertFalse(invokeFuture.isDone());
f3.complete("v3");
assertEquals("v3", invokeFuture.get(10, SECONDS));
}
use of org.infinispan.interceptors.InvocationSuccessFunction in project infinispan by infinispan.
the class AsyncInterceptorChainInvocationTest method testDeadlockWithAsyncStage.
public void testDeadlockWithAsyncStage() throws Exception {
CompletableFuture<Object> f1 = new CompletableFuture<>();
CompletableFuture<Object> f2 = new CompletableFuture<>();
AsyncInterceptorChain chain = newInterceptorChain(new BaseAsyncInterceptor() {
@Override
public Object visitCommand(InvocationContext ctx, VisitableCommand command) throws Throwable {
return invokeNextThenApply(ctx, command, (rCtx, rCommand, rv) -> rv + " " + awaitFuture(f2));
}
}, new BaseAsyncInterceptor() {
@Override
public Object visitCommand(InvocationContext ctx, VisitableCommand command) throws Throwable {
// Add a handler to force the return value to be a full AsyncInvocationStage
InvocationSuccessFunction function = (rCtx, rCommand, rv) -> rv;
return asyncValue(f1).addCallback(ctx, command, function);
}
});
InvocationContext context = newInvocationContext();
CompletableFuture<Object> invokeFuture = chain.invokeAsync(context, testCommand);
assertFalse(invokeFuture.isDone());
Future<Boolean> fork = fork(() -> f1.complete("v1"));
Thread.sleep(100);
assertFalse(fork.isDone());
assertFalse(invokeFuture.isDone());
f2.complete("v2");
fork.get(10, SECONDS);
assertEquals("v1 v2", invokeFuture.getNow(null));
}
Aggregations