Search in sources :

Example 1 with SerializableBiFunction

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

the class BaseClusteredExtendedStatisticTest method testComputeIfPresent.

public void testComputeIfPresent(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);
    SerializableBiFunction computeFunction = (k, v) -> VALUE_2 + k + v;
    computeIfPresent(0, key1, computeFunction);
    assertCacheValue(key1, VALUE_2 + key1 + VALUE_1);
    // failed operation is not added to the transaction
    cache(1).computeIfPresent(key2, computeFunction);
    assertEmpty(key2);
    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) SerializableBiFunction(org.infinispan.util.function.SerializableBiFunction)

Example 2 with SerializableBiFunction

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

the class BaseClusteredExtendedStatisticTest method testCompute.

public void testCompute(Method method) throws InterruptedException {
    final String key1 = k(method, 1);
    final String key2 = k(method, 2);
    assertEmpty(key1);
    put(1, key1, VALUE_1);
    assertCacheValue(key1, VALUE_1);
    SerializableBiFunction computeFunction = (k, v) -> VALUE_2 + k + v;
    compute(0, key1, computeFunction);
    assertCacheValue(key1, VALUE_2 + key1 + VALUE_1);
    compute(1, key2, computeFunction);
    assertCacheValue(key2, VALUE_2 + key2 + "null");
    SerializableBiFunction computeFunctionToNull = (k, v) -> null;
    compute(0, key1, computeFunctionToNull);
    assertEmpty(key1);
    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) SerializableBiFunction(org.infinispan.util.function.SerializableBiFunction)

Aggregations

Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Map (java.util.Map)2 Queue (java.util.Queue)2 Set (java.util.Set)2 TimeUnit (java.util.concurrent.TimeUnit)2 BiFunction (java.util.function.BiFunction)2 Function (java.util.function.Function)2 Cache (org.infinispan.Cache)2 ReplicableCommand (org.infinispan.commands.ReplicableCommand)2 CacheRpcCommand (org.infinispan.commands.remote.CacheRpcCommand)2 SingleRpcCommand (org.infinispan.commands.remote.SingleRpcCommand)2 PrepareCommand (org.infinispan.commands.tx.PrepareCommand)2 VersionedPrepareCommand (org.infinispan.commands.tx.VersionedPrepareCommand)2 ClearCommand (org.infinispan.commands.write.ClearCommand)2