Search in sources :

Example 1 with SerializableFunction

use of org.infinispan.util.function.SerializableFunction 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)

Example 2 with SerializableFunction

use of org.infinispan.util.function.SerializableFunction in project infinispan by infinispan.

the class BaseClusteredExtendedStatisticTest method testComputeIfAbsent.

public void testComputeIfAbsent(Method method) throws InterruptedException {
    final String key1 = k(method, 1);
    final String key2 = k(method, 2);
    assertEmpty(key1);
    assertEmpty(key2);
    put(1, key1, VALUE_1);
    assertCacheValue(key1, VALUE_1);
    SerializableFunction computeFunction = v -> VALUE_3 + v;
    // failed operation is not added to the transaction
    cache(0).computeIfAbsent(key1, computeFunction);
    assertCacheValue(key1, VALUE_1);
    SerializableFunction computeFunction2 = v -> VALUE_2;
    computeIfAbsent(1, key2, computeFunction2);
    assertCacheValue(key2, VALUE_2);
    assertNoTransactions();
    assertNoTxStats();
}
Also used : WriteCommand(org.infinispan.commands.write.WriteCommand) SingleRpcCommand(org.infinispan.commands.remote.SingleRpcCommand) SerializableFunction(org.infinispan.util.function.SerializableFunction) AssertJUnit(org.testng.AssertJUnit) ComputeCommand(org.infinispan.commands.write.ComputeCommand) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) BiFunction(java.util.function.BiFunction) ReplaceCommand(org.infinispan.commands.write.ReplaceCommand) Reply(org.infinispan.remoting.inboundhandler.Reply) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) Cache(org.infinispan.Cache) Function(java.util.function.Function) ArrayList(java.util.ArrayList) AbstractDelegatingHandler(org.infinispan.remoting.inboundhandler.AbstractDelegatingHandler) HashSet(java.util.HashSet) TestingUtil.k(org.infinispan.test.TestingUtil.k) AssertJUnit.assertNull(org.testng.AssertJUnit.assertNull) Map(java.util.Map) SerializableBiFunction(org.infinispan.util.function.SerializableBiFunction) LinkedList(java.util.LinkedList) Method(java.lang.reflect.Method) ClearCommand(org.infinispan.commands.write.ClearCommand) Address(org.infinispan.remoting.transport.Address) PrepareCommand(org.infinispan.commands.tx.PrepareCommand) RemoveCommand(org.infinispan.commands.write.RemoveCommand) ReplicableCommand(org.infinispan.commands.ReplicableCommand) MultipleCacheManagersTest(org.infinispan.test.MultipleCacheManagersTest) Collection(java.util.Collection) BeforeMethod(org.testng.annotations.BeforeMethod) Set(java.util.Set) PutMapCommand(org.infinispan.commands.write.PutMapCommand) VersionedPrepareCommand(org.infinispan.commands.tx.VersionedPrepareCommand) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) CacheRpcCommand(org.infinispan.commands.remote.CacheRpcCommand) CacheMode(org.infinispan.configuration.cache.CacheMode) InterceptorConfiguration(org.infinispan.configuration.cache.InterceptorConfiguration) IsolationLevel(org.infinispan.util.concurrent.IsolationLevel) PerCacheInboundInvocationHandler(org.infinispan.remoting.inboundhandler.PerCacheInboundInvocationHandler) TestingUtil.wrapInboundInvocationHandler(org.infinispan.test.TestingUtil.wrapInboundInvocationHandler) ComputeIfAbsentCommand(org.infinispan.commands.write.ComputeIfAbsentCommand) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand) ExtendedStatisticInterceptor(org.infinispan.extendedstats.wrappers.ExtendedStatisticInterceptor) Queue(java.util.Queue) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) DeliverOrder(org.infinispan.remoting.inboundhandler.DeliverOrder) SerializableFunction(org.infinispan.util.function.SerializableFunction)

Aggregations

ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 CacheMode (org.infinispan.configuration.cache.CacheMode)2 Address (org.infinispan.remoting.transport.Address)2 SerializableFunction (org.infinispan.util.function.SerializableFunction)2 Test (org.testng.annotations.Test)2 Method (java.lang.reflect.Method)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Queue (java.util.Queue)1 Set (java.util.Set)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