Search in sources :

Example 1 with TestException

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);
}
Also used : TestException(org.infinispan.test.TestException) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain)

Example 2 with TestException

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());
}
Also used : InvocationStage(org.infinispan.interceptors.InvocationStage) TestException(org.infinispan.test.TestException) ReplaceCommand(org.infinispan.commands.write.ReplaceCommand)

Example 3 with TestException

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());
}
Also used : RemoveCommand(org.infinispan.commands.write.RemoveCommand) InvocationStage(org.infinispan.interceptors.InvocationStage) TestException(org.infinispan.test.TestException)

Example 4 with TestException

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());
    });
}
Also used : NoJtaPlatform(org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform) ByRef(org.infinispan.commons.util.ByRef) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue) List(java.util.List) CacheMode(org.infinispan.configuration.cache.CacheMode) TestException(org.infinispan.test.TestException) INFINISPAN_CONFIG_LOCAL_RESOURCE(org.infinispan.hibernate.cache.spi.InfinispanProperties.INFINISPAN_CONFIG_LOCAL_RESOURCE) JdbcResourceLocalTransactionCoordinatorBuilderImpl(org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl) Exceptions(org.infinispan.commons.test.Exceptions) Map(java.util.Map) INFINISPAN_CONFIG_RESOURCE_PROP(org.infinispan.hibernate.cache.spi.InfinispanProperties.INFINISPAN_CONFIG_RESOURCE_PROP) AccessType(org.hibernate.cache.spi.access.AccessType) Customer(org.infinispan.test.hibernate.cache.commons.functional.entities.Customer) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) TestException(org.infinispan.test.TestException) Customer(org.infinispan.test.hibernate.cache.commons.functional.entities.Customer) ByRef(org.infinispan.commons.util.ByRef) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 5 with TestException

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);
}
Also used : Address(org.infinispan.remoting.transport.Address) TestException(org.infinispan.test.TestException) SingleRpcCommand(org.infinispan.commands.remote.SingleRpcCommand) TimeoutException(org.infinispan.util.concurrent.TimeoutException) TestException(org.infinispan.test.TestException) TimeoutException(org.infinispan.util.concurrent.TimeoutException)

Aggregations

TestException (org.infinispan.test.TestException)18 InvocationStage (org.infinispan.interceptors.InvocationStage)7 Address (org.infinispan.remoting.transport.Address)6 CheckPoint (org.infinispan.test.fwk.CheckPoint)4 CompletableFuture (java.util.concurrent.CompletableFuture)3 TimeoutException (java.util.concurrent.TimeoutException)3 Collections (java.util.Collections)2 List (java.util.List)2 CompletionStage (java.util.concurrent.CompletionStage)2 TransactionManager (javax.transaction.TransactionManager)2 Exceptions (org.infinispan.commons.test.Exceptions)2 CacheMode (org.infinispan.configuration.cache.CacheMode)2 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)2 InternalDataContainer (org.infinispan.container.impl.InternalDataContainer)2 DistributionManager (org.infinispan.distribution.DistributionManager)2 AsyncInterceptorChain (org.infinispan.interceptors.AsyncInterceptorChain)2 AbstractInfinispanTest (org.infinispan.test.AbstractInfinispanTest)2 TransactionTable (org.infinispan.transaction.impl.TransactionTable)2 Test (org.testng.annotations.Test)2 ArrayList (java.util.ArrayList)1