Search in sources :

Example 1 with TestClassLocal

use of org.infinispan.test.fwk.TestClassLocal in project infinispan by infinispan.

the class AllClusterExecutorTest method testExecutorTriConsumerTimeoutException.

public void testExecutorTriConsumerTimeoutException() {
    withCacheManagers(new MultiCacheManagerCallable(TestCacheManagerFactory.createCacheManager(CacheMode.DIST_SYNC, false), TestCacheManagerFactory.createCacheManager(CacheMode.DIST_SYNC, false)) {

        @Override
        public void call() throws InterruptedException, ExecutionException, TimeoutException {
            EmbeddedCacheManager cm1 = cms[0];
            TestClassLocal<CheckPoint> checkPoint = AllClusterExecutorTest.this.checkPoint;
            SerializableFunction<EmbeddedCacheManager, Object> blockingFunction = m -> {
                try {
                    checkPoint.get().trigger("block_execution");
                    checkPoint.get().awaitStrict("resume_execution", 10, TimeUnit.SECONDS);
                    checkPoint.get().trigger("complete");
                } catch (InterruptedException | TimeoutException e) {
                    throw new TestException(e);
                }
                return null;
            };
            CompletableFuture<Void> futureRemote = executor(cm1).filterTargets(a -> !a.equals(cm1.getAddress())).timeout(1, TimeUnit.MILLISECONDS).submitConsumer(blockingFunction, (a, i, t) -> {
                log.tracef("Consumer invoked with %s, %s, %s", a, i, t);
            });
            Exceptions.expectExecutionException(org.infinispan.util.concurrent.TimeoutException.class, futureRemote);
            checkPoint.get().awaitStrict("block_execution", 10, TimeUnit.SECONDS);
            checkPoint.get().trigger("resume_execution");
            // Have to wait for callback to complete - otherwise a different thread could find the "resume_execution"
            // checkpoint reached incorrectly
            checkPoint.get().awaitStrict("complete", 10, TimeUnit.SECONDS);
            CompletableFuture<Void> futureLocal = executor(cm1).filterTargets(a -> a.equals(cm1.getAddress())).timeout(1, TimeUnit.MILLISECONDS).submitConsumer(blockingFunction, (a, i, t) -> {
                log.tracef("Consumer invoked with %s, %s, %s", a, i, t);
            });
            Exceptions.expectExecutionException(org.infinispan.util.concurrent.TimeoutException.class, futureLocal);
            checkPoint.get().awaitStrict("block_execution", 10, TimeUnit.SECONDS);
            checkPoint.get().trigger("resume_execution");
            checkPoint.get().awaitStrict("complete", 10, TimeUnit.SECONDS);
        }
    });
}
Also used : SerializableFunction(org.infinispan.util.function.SerializableFunction) CheckPoint(org.infinispan.test.fwk.CheckPoint) TestingUtil.withCacheManagers(org.infinispan.test.TestingUtil.withCacheManagers) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) KnownComponentNames(org.infinispan.factories.KnownComponentNames) Test(org.testng.annotations.Test) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) AbstractInfinispanTest(org.infinispan.test.AbstractInfinispanTest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestingUtil(org.infinispan.test.TestingUtil) ExecutorService(java.util.concurrent.ExecutorService) Address(org.infinispan.remoting.transport.Address) MultiCacheManagerCallable(org.infinispan.test.MultiCacheManagerCallable) Collection(java.util.Collection) TestBlocking(org.infinispan.test.TestBlocking) SerializableSupplier(org.infinispan.util.function.SerializableSupplier) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) TestClassLocal(org.infinispan.test.fwk.TestClassLocal) List(java.util.List) CacheMode(org.infinispan.configuration.cache.CacheMode) TestException(org.infinispan.test.TestException) Exceptions(org.infinispan.commons.test.Exceptions) TestCacheManagerFactory(org.infinispan.test.fwk.TestCacheManagerFactory) AssertJUnit.assertNotNull(org.testng.AssertJUnit.assertNotNull) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) Collections(java.util.Collections) Exchanger(java.util.concurrent.Exchanger) SerializableFunction(org.infinispan.util.function.SerializableFunction) TestException(org.infinispan.test.TestException) MultiCacheManagerCallable(org.infinispan.test.MultiCacheManagerCallable) CompletableFuture(java.util.concurrent.CompletableFuture) TestClassLocal(org.infinispan.test.fwk.TestClassLocal) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Exchanger (java.util.concurrent.Exchanger)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Supplier (java.util.function.Supplier)1 Exceptions (org.infinispan.commons.test.Exceptions)1 CacheMode (org.infinispan.configuration.cache.CacheMode)1 KnownComponentNames (org.infinispan.factories.KnownComponentNames)1 Address (org.infinispan.remoting.transport.Address)1 AbstractInfinispanTest (org.infinispan.test.AbstractInfinispanTest)1 MultiCacheManagerCallable (org.infinispan.test.MultiCacheManagerCallable)1 TestBlocking (org.infinispan.test.TestBlocking)1