Search in sources :

Example 31 with EntryProcessor

use of javax.cache.processor.EntryProcessor in project hazelcast by hazelcast.

the class CacheEntryProcessorMessageTask method prepareOperation.

@Override
protected Operation prepareOperation() {
    CacheService service = getService(getServiceName());
    CacheOperationProvider operationProvider = getOperationProvider(parameters.name);
    EntryProcessor entryProcessor = (EntryProcessor) service.toObject(parameters.entryProcessor);
    ArrayList argumentsList = new ArrayList(parameters.arguments.size());
    for (Data data : parameters.arguments) {
        argumentsList.add(service.toObject(data));
    }
    return operationProvider.createEntryProcessorOperation(parameters.key, parameters.completionId, entryProcessor, argumentsList.toArray());
}
Also used : EntryProcessor(javax.cache.processor.EntryProcessor) CacheOperationProvider(com.hazelcast.cache.impl.CacheOperationProvider) ArrayList(java.util.ArrayList) Data(com.hazelcast.internal.serialization.Data) CacheService(com.hazelcast.cache.impl.CacheService)

Example 32 with EntryProcessor

use of javax.cache.processor.EntryProcessor in project cache2k by cache2k.

the class CacheExpiryTest method invokeMultiSetValueShouldCallGetExpiry.

@Test
public void invokeMultiSetValueShouldCallGetExpiry() {
    CountingExpiryPolicy expiryPolicy = new CountingExpiryPolicy();
    expiryPolicyServer.setExpiryPolicy(expiryPolicy);
    MutableConfiguration<Integer, Integer> config = new MutableConfiguration<>();
    config.setExpiryPolicyFactory(FactoryBuilder.factoryOf(expiryPolicyClient));
    Cache<Integer, Integer> cache = getCacheManager().createCache(getTestCacheName(), config);
    final Integer key = 123;
    final Integer setValue = 456;
    final Integer modifySetValue = 789;
    // verify create
    EntryProcessor[] processors = new EntryProcessor[] { new AssertNotPresentEntryProcessor(null), new SetEntryProcessor<Integer, Integer>(111), new SetEntryProcessor<Integer, Integer>(setValue), new GetEntryProcessor<Integer, Integer>() };
    Object[] result = (Object[]) cache.invoke(key, new CombineEntryProcessor(processors));
    assertEquals(result[1], 111);
    assertEquals(result[2], setValue);
    assertEquals(result[3], setValue);
    // expiry called should be for create, not for the get or modify.
    // Operations get combined in entry processor and only net result should be expiryPolicy method called.
    assertThat(expiryPolicy.getCreationCount(), greaterThanOrEqualTo(1));
    assertThat(expiryPolicy.getAccessCount(), greaterThanOrEqualTo(0));
    assertThat(expiryPolicy.getUpdatedCount(), greaterThanOrEqualTo(0));
}
Also used : AssertNotPresentEntryProcessor(org.jsr107.tck.processor.AssertNotPresentEntryProcessor) CombineEntryProcessor(org.jsr107.tck.processor.CombineEntryProcessor) MutableConfiguration(javax.cache.configuration.MutableConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GetEntryProcessor(org.jsr107.tck.processor.GetEntryProcessor) SetEntryProcessor(org.jsr107.tck.processor.SetEntryProcessor) EntryProcessor(javax.cache.processor.EntryProcessor) CombineEntryProcessor(org.jsr107.tck.processor.CombineEntryProcessor) GetEntryProcessor(org.jsr107.tck.processor.GetEntryProcessor) AssertNotPresentEntryProcessor(org.jsr107.tck.processor.AssertNotPresentEntryProcessor) SetEntryProcessor(org.jsr107.tck.processor.SetEntryProcessor) Test(org.junit.Test)

Example 33 with EntryProcessor

use of javax.cache.processor.EntryProcessor in project cache2k by cache2k.

the class CacheExpiryTest method invokeSetValueShouldCallGetExpiry.

// skipping test for removeAll and removeAll specified keys for now. negative test of remove seems enough.
@Test
public void invokeSetValueShouldCallGetExpiry() {
    CountingExpiryPolicy expiryPolicy = new CountingExpiryPolicy();
    expiryPolicyServer.setExpiryPolicy(expiryPolicy);
    MutableConfiguration<Integer, Integer> config = new MutableConfiguration<>();
    config.setExpiryPolicyFactory(FactoryBuilder.factoryOf(expiryPolicyClient));
    Cache<Integer, Integer> cache = getCacheManager().createCache(getTestCacheName(), config);
    final Integer key = 123;
    final Integer setValue = 456;
    final Integer modifySetValue = 789;
    // verify create
    EntryProcessor[] processors = new EntryProcessor[] { new AssertNotPresentEntryProcessor(null), new SetEntryProcessor<Integer, Integer>(setValue), new GetEntryProcessor<Integer, Integer>() };
    Object[] result = (Object[]) cache.invoke(key, new CombineEntryProcessor(processors));
    assertEquals(result[1], setValue);
    assertEquals(result[2], setValue);
    // expiry called should be for create, not for the get or modify.
    // Operations get combined in entry processor and only net result should be expiryPolicy method called.
    assertThat(expiryPolicy.getCreationCount(), greaterThanOrEqualTo(1));
    assertThat(expiryPolicy.getAccessCount(), is(0));
    assertThat(expiryPolicy.getUpdatedCount(), is(0));
    expiryPolicy.resetCount();
    // verify modify
    Integer resultValue = cache.invoke(key, new SetEntryProcessor<Integer, Integer>(modifySetValue));
    assertEquals(modifySetValue, resultValue);
    assertThat(expiryPolicy.getCreationCount(), is(0));
    assertThat(expiryPolicy.getAccessCount(), is(0));
    assertThat(expiryPolicy.getUpdatedCount(), greaterThanOrEqualTo(1));
}
Also used : AssertNotPresentEntryProcessor(org.jsr107.tck.processor.AssertNotPresentEntryProcessor) CombineEntryProcessor(org.jsr107.tck.processor.CombineEntryProcessor) MutableConfiguration(javax.cache.configuration.MutableConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GetEntryProcessor(org.jsr107.tck.processor.GetEntryProcessor) SetEntryProcessor(org.jsr107.tck.processor.SetEntryProcessor) EntryProcessor(javax.cache.processor.EntryProcessor) CombineEntryProcessor(org.jsr107.tck.processor.CombineEntryProcessor) GetEntryProcessor(org.jsr107.tck.processor.GetEntryProcessor) AssertNotPresentEntryProcessor(org.jsr107.tck.processor.AssertNotPresentEntryProcessor) SetEntryProcessor(org.jsr107.tck.processor.SetEntryProcessor) Test(org.junit.Test)

Aggregations

EntryProcessor (javax.cache.processor.EntryProcessor)33 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)15 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)14 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)14 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)12 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)10 LinkedHashMap (java.util.LinkedHashMap)9 CacheInvokeEntry (org.apache.ignite.internal.processors.cache.CacheInvokeEntry)8 IgniteException (org.apache.ignite.IgniteException)7 Map (java.util.Map)6 EntryProcessorResult (javax.cache.processor.EntryProcessorResult)6 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)6 Test (org.junit.Test)6 MutableEntry (javax.cache.processor.MutableEntry)5 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)5 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)5 GridCacheReturn (org.apache.ignite.internal.processors.cache.GridCacheReturn)5 GridTimeoutObject (org.apache.ignite.internal.processors.timeout.GridTimeoutObject)5 IgniteBiTuple (org.apache.ignite.lang.IgniteBiTuple)5