use of javax.cache.integration.CompletionListenerFuture in project hazelcast-simulator by hazelcast.
the class CacheLoaderTest method timeStep.
@TimeStep
public void timeStep() throws ExecutionException, InterruptedException {
CompletionListenerFuture loaded = new CompletionListenerFuture();
cache.loadAll(keySet, true, loaded);
if (waitForLoadAllFutureCompletion) {
loaded.get();
}
}
use of javax.cache.integration.CompletionListenerFuture in project cache2k by cache2k.
the class CacheLoaderTest method shouldNotLoadWithNullKeyUsingLoadAll.
/**
* Ensure that {@link Cache#loadAll(java.util.Set, boolean, javax.cache.integration.CompletionListener)} )}
* using a <code>null</code> key will raise an exception
*/
@Test
public void shouldNotLoadWithNullKeyUsingLoadAll() throws Exception {
RecordingCacheLoader<String> cacheLoader = new RecordingCacheLoader<String>();
cacheLoaderServer.setCacheLoader(cacheLoader);
HashSet<String> keys = new HashSet<>();
keys.add(null);
try {
CompletionListenerFuture future = new CompletionListenerFuture();
cache.loadAll(keys, false, future);
fail("Expected a NullPointerException");
} catch (NullPointerException e) {
// SKIP: expected
} finally {
assertThat(cacheLoader.getLoadCount(), is(0));
}
}
use of javax.cache.integration.CompletionListenerFuture in project cache2k by cache2k.
the class CacheLoaderTest method shouldLoadSingleMissingEntryUsingLoadAll.
/**
* Ensure that {@link Cache#loadAll(Set, boolean, javax.cache.integration.CompletionListener)}
* for a non-existent single value will cause it to be loaded.
*/
@Test
public void shouldLoadSingleMissingEntryUsingLoadAll() throws Exception {
RecordingCacheLoader<String> cacheLoader = new RecordingCacheLoader<String>();
cacheLoaderServer.setCacheLoader(cacheLoader);
String key = "message";
HashSet<String> keys = new HashSet<>();
keys.add(key);
assertThat(cache.containsKey(key), is(false));
CompletionListenerFuture future = new CompletionListenerFuture();
cache.loadAll(keys, false, future);
// wait for the load to complete
future.get();
assertThat(future.isDone(), is(true));
assertThat(cache.get(key), is(equalTo(key)));
assertThat(cacheLoader.getLoadCount(), is(1));
assertThat(cacheLoader.hasLoaded(key), is(true));
}
use of javax.cache.integration.CompletionListenerFuture in project cache2k by cache2k.
the class CacheLoaderTest method shouldPropagateExceptionUsingLoadAll.
/**
* Ensure that {@link Cache#loadAll(java.util.Set, boolean, javax.cache.integration.CompletionListener)} )}
* will propagate an exception from a {@link 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 CacheLoaderTest method shouldNotLoadMultipleNullValuesUsingLoadAll.
/**
* Ensure that {@link Cache#loadAll(Set, boolean, javax.cache.integration.CompletionListener)}
* won't load <code>null</code> values.
*/
@Test
public void shouldNotLoadMultipleNullValuesUsingLoadAll() 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));
}
}
Aggregations