use of org.jsr107.tck.processor.SetEntryProcessor in project cache2k by cache2k.
the class CacheExpiryTest method invokeGetValueShouldCallGetExpiry.
@Test
public void invokeGetValueShouldCallGetExpiry() {
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;
// verify non-access to non-existent entry does not call getExpiryForAccessedEntry. no read-through scenario.
Integer resultValue = cache.invoke(key, new GetEntryProcessor<Integer, Integer>());
assertEquals(null, resultValue);
assertThat(expiryPolicy.getCreationCount(), is(0));
assertThat(expiryPolicy.getAccessCount(), is(0));
assertThat(expiryPolicy.getUpdatedCount(), is(0));
// verify access to existing entry.
resultValue = cache.invoke(key, new SetEntryProcessor<Integer, Integer>(setValue));
assertEquals(resultValue, setValue);
assertThat(expiryPolicy.getCreationCount(), greaterThanOrEqualTo(1));
assertThat(expiryPolicy.getAccessCount(), is(0));
assertThat(expiryPolicy.getUpdatedCount(), is(0));
expiryPolicy.resetCount();
resultValue = cache.invoke(key, new GetEntryProcessor<Integer, Integer>());
assertEquals(setValue, resultValue);
assertThat(expiryPolicy.getCreationCount(), is(0));
assertThat(expiryPolicy.getAccessCount(), greaterThanOrEqualTo(1));
assertThat(expiryPolicy.getUpdatedCount(), is(0));
}
use of org.jsr107.tck.processor.SetEntryProcessor in project cache2k by cache2k.
the class CacheWriterTest method shouldWriteThroughUsingInvoke_setValue_UpdateEntry.
@Test
public void shouldWriteThroughUsingInvoke_setValue_UpdateEntry() {
assertEquals(0, cacheWriter.getWriteCount());
assertEquals(0, cacheWriter.getDeleteCount());
cache.put(1, "Gudday World");
cache.invoke(1, new SetEntryProcessor("Hello World"));
assertEquals(2, cacheWriter.getWriteCount());
assertEquals(0, cacheWriter.getDeleteCount());
assertTrue(cacheWriter.hasWritten(1));
assertEquals("Hello World", cacheWriter.get(1));
}
use of org.jsr107.tck.processor.SetEntryProcessor 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));
}
use of org.jsr107.tck.processor.SetEntryProcessor 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));
}
Aggregations