use of org.infinispan.test.TestException in project infinispan by infinispan.
the class AsyncInterceptorChainInvocationTest method testAsyncInvocationManyHandlersSyncException.
public void testAsyncInvocationManyHandlersSyncException() throws Exception {
sideEffects.set("");
CompletableFuture<Object> f = CompletableFutures.completedExceptionFuture(new TestException(""));
AsyncInterceptorChain chain = makeChainWithManyHandlers(f);
CompletableFuture<Object> invokeFuture = chain.invokeAsync(newInvocationContext(), testCommand);
assertExceptionHandlers(invokeFuture);
}
use of org.infinispan.test.TestException in project infinispan by infinispan.
the class CacheMgmtInterceptorTest method testVisitReplaceCommandException.
public void testVisitReplaceCommandException() throws Throwable {
ReplaceCommand command = new ReplaceCommand(KEY, VALUE, false, null, 0, 0, null);
InvocationStage stage = makeStage(interceptor.visitReplaceCommand(ctx, command));
assertFalse(stage.isDone());
timeService.advance(1);
nextInterceptor.completeLastInvocationExceptionally(new TestException());
expectInvocationException(stage);
assertEquals(1, interceptor.getAverageWriteTime());
}
use of org.infinispan.test.TestException in project infinispan by infinispan.
the class CacheMgmtInterceptorTest method testVisitRemoveCommandException.
public void testVisitRemoveCommandException() throws Throwable {
RemoveCommand command = new RemoveCommand(KEY, null, 0, 0, null);
InvocationStage stage = makeStage(interceptor.visitRemoveCommand(ctx, command));
assertFalse(stage.isDone());
timeService.advance(1);
nextInterceptor.completeLastInvocationExceptionally(new TestException());
expectInvocationException(stage);
assertEquals(0, interceptor.getAverageRemoveTime());
}
use of org.infinispan.test.TestException in project infinispan by infinispan.
the class LocalCacheTest method testRollback.
@Test
@TestForIssue(jiraKey = "HHH-12457")
public void testRollback() throws Exception {
ByRef<Integer> idRef = new ByRef<>(0);
withTxSession(s -> {
Customer c = new Customer();
c.setName("Foo");
s.persist(c);
idRef.set(c.getId());
});
Exceptions.expectException(TestException.class, () -> withTxSession(s -> {
Customer c = s.load(Customer.class, idRef.get());
c.setName("Bar");
s.persist(c);
s.flush();
throw new TestException("Roll me back");
}));
withTxSession(s -> {
Customer c = s.load(Customer.class, idRef.get());
assertEquals("Foo", c.getName());
});
}
use of org.infinispan.test.TestException in project infinispan by infinispan.
the class ControlledRpcManager method performRequest.
@Override
protected <T> CompletionStage<T> performRequest(Collection<Address> targets, ReplicableCommand command, ResponseCollector<T> collector, Function<ResponseCollector<T>, CompletionStage<T>> invoker, RpcOptions rpcOptions) {
if (stopped || commandExcluded(command)) {
log.tracef("Not blocking excluded command %s", command);
return invoker.apply(collector);
}
log.debugf("Intercepted command to %s: %s", targets, command);
// Ignore the SingleRpcCommand wrapper
if (command instanceof SingleRpcCommand) {
command = ((SingleRpcCommand) command).getCommand();
}
Address excluded = realOne.getAddress();
ControlledRequest<T> controlledRequest = new ControlledRequest<>(command, targets, collector, invoker, nonBlockingExecutor, excluded);
try {
CompletableFuture<ControlledRequest<?>> waiter = waiters.poll(TIMEOUT_SECONDS, SECONDS);
if (waiter == null) {
TimeoutException t = new TimeoutException("Found no waiters for command " + command);
addGlobalError(t);
throw t;
}
waiter.complete(controlledRequest);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new TestException(e);
} catch (Exception e) {
throw new TestException(e);
}
if (collector != null) {
ScheduledFuture<?> cancelTask = timeoutExecutor.schedule(() -> {
TimeoutException e = new TimeoutException("Timed out waiting for test to unblock command " + controlledRequest.getCommand());
addGlobalError(e);
controlledRequest.fail(e);
}, TIMEOUT_SECONDS * 2, SECONDS);
controlledRequest.resultFuture.whenComplete((ignored, throwable) -> cancelTask.cancel(false));
}
// resultFuture is completed from a test thread, and we don't want to run the interceptor callbacks there
return controlledRequest.resultFuture.whenCompleteAsync((r, t) -> {
}, nonBlockingExecutor);
}
Aggregations