use of javax.cache.integration.CompletionListenerFuture in project cache2k by cache2k.
the class CacheLoaderWithoutReadThroughTest method shouldPropagateExceptionUsingLoadAll.
/**
* Ensure that {@link Cache#loadAll(java.util.Set, boolean, javax.cache.integration.CompletionListener)} )}
* will propagate an exception from a {@link javax.cache.integration.CacheLoader}.
*/
@Test
public void shouldPropagateExceptionUsingLoadAll() throws Exception {
FailingCacheLoader<String, String> cacheLoader = new FailingCacheLoader<>();
cacheLoaderServer.setCacheLoader(cacheLoader);
HashSet<String> keys = new HashSet<>();
keys.add("gudday");
keys.add("hello");
keys.add("howdy");
keys.add("bonjour");
CompletionListenerFuture future = new CompletionListenerFuture();
cache.loadAll(keys, false, future);
// wait for the load to complete
try {
future.get();
// new since TCK 1.1
fail();
} catch (ExecutionException e) {
assertThat(e.getCause(), instanceOf(CacheLoaderException.class));
}
}
use of javax.cache.integration.CompletionListenerFuture in project cache2k by cache2k.
the class CacheLoaderWithoutReadThroughTest method shouldNotLoadMultipleNullEntriesUsingLoadAll.
/**
* Ensure that {@link Cache#loadAll(java.util.Set, boolean, javax.cache.integration.CompletionListener)}
* won't load <code>null</code> entries.
*/
@Test
public void shouldNotLoadMultipleNullEntriesUsingLoadAll() throws Exception {
NullValueCacheLoader<String, String> cacheLoader = new NullValueCacheLoader<>();
cacheLoaderServer.setCacheLoader(cacheLoader);
HashSet<String> keys = new HashSet<>();
keys.add("gudday");
keys.add("hello");
keys.add("howdy");
keys.add("bonjour");
CompletionListenerFuture future = new CompletionListenerFuture();
cache.loadAll(keys, false, future);
// wait for the load to complete
future.get();
assertThat(future.isDone(), is(true));
for (String key : keys) {
assertThat(cache.containsKey(key), is(false));
}
}
use of javax.cache.integration.CompletionListenerFuture in project cache2k by cache2k.
the class CacheLoaderWithoutReadThroughTest method shouldLoadMultipleExistingEntryUsingLoadAll.
/**
* Ensure that {@link Cache#loadAll(java.util.Set, boolean, javax.cache.integration.CompletionListener)}
* for multiple existing entries will be reloaded.
*/
@Test
public void shouldLoadMultipleExistingEntryUsingLoadAll() throws Exception {
RecordingCacheLoader<String> cacheLoader = new RecordingCacheLoader<String>();
cacheLoaderServer.setCacheLoader(cacheLoader);
HashSet<String> keys = new HashSet<>();
keys.add("gudday");
keys.add("hello");
keys.add("howdy");
keys.add("bonjour");
String value = "other";
for (String key : keys) {
assertThat(cache.containsKey(key), is(false));
cache.put(key, value);
assertThat(cache.containsKey(key), is(true));
}
CompletionListenerFuture future = new CompletionListenerFuture();
cache.loadAll(keys, true, future);
// wait for the load to complete
future.get();
assertThat(future.isDone(), is(true));
assertThat(cacheLoader.getLoadCount(), is(keys.size()));
for (String key : keys) {
assertThat(cache.get(key), is(equalTo(key)));
assertThat(cacheLoader.hasLoaded(key), is(true));
}
}
use of javax.cache.integration.CompletionListenerFuture in project cache2k by cache2k.
the class CacheLoaderWriterTest method shouldLoadSingleExistingEntryUsingLoadAll.
/**
* Ensure that {@link Cache#loadAll(java.util.Set, boolean, javax.cache.integration.CompletionListener)}
* for an existing single entry will cause it to be reloaded or written.
*/
@Test
public void shouldLoadSingleExistingEntryUsingLoadAll() throws Exception {
String key = "message";
HashSet<String> keys = new HashSet<>();
keys.add(key);
assertThat(cache.containsKey(key), is(false));
String value = "other";
cache.put(key, value);
assertThat(cache.containsKey(key), is(true));
assertThat(cache.get(key), is(value));
CompletionListenerFuture future = new CompletionListenerFuture();
cache.loadAll(keys, true, future);
// wait for the load to complete
future.get();
assertThat(future.isDone(), is(true));
assertThat(cache.get(key), is(equalTo(key)));
assertThat(recordingCacheLoader.getLoadCount(), is(1));
assertThat(recordingCacheLoader.hasLoaded(key), is(true));
// ensure nothing has been written
assertThat(recordingCacheWriter.getWriteCount(), is(1L));
assertThat(recordingCacheWriter.getDeleteCount(), is(0L));
}
use of javax.cache.integration.CompletionListenerFuture in project ignite by apache.
the class IgniteCacheExpiryStoreLoadSelfTest method testLoadAllWithExpiry.
/**
* @throws Exception If failed.
*/
@Test
public void testLoadAllWithExpiry() throws Exception {
IgniteCache<Integer, Integer> cache = ignite(0).<Integer, Integer>cache(DEFAULT_CACHE_NAME).withExpiryPolicy(new CreatedExpiryPolicy(new Duration(MILLISECONDS, TIME_TO_LIVE)));
Set<Integer> keys = new HashSet<>();
keys.add(primaryKey(jcache(0)));
keys.add(primaryKey(jcache(1)));
keys.add(primaryKey(jcache(2)));
CompletionListenerFuture fut = new CompletionListenerFuture();
cache.loadAll(keys, false, fut);
fut.get();
assertEquals(3, cache.size(CachePeekMode.PRIMARY));
Thread.sleep(TIME_TO_LIVE + WAIT_TIME);
assertEquals(0, cache.size());
}
Aggregations