# sprint-2 improved test to check all 'load' methods
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/e0012243 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/e0012243 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/e0012243 Branch: refs/heads/ignite-281 Commit: e00122434a8ccc200b6d01ecf9f19ce3e04276e1 Parents: 1944ae3 Author: sboikov <sboi...@gridgain.com> Authored: Thu Feb 19 15:25:14 2015 +0300 Committer: sboikov <sboi...@gridgain.com> Committed: Thu Feb 19 15:25:14 2015 +0300 ---------------------------------------------------------------------- .../IgniteCacheExpiryStoreLoadSelfTest.java | 79 +++++++++++++++++++- 1 file changed, 76 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e0012243/modules/core/src/test/java/org/apache/ignite/cache/store/IgniteCacheExpiryStoreLoadSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/IgniteCacheExpiryStoreLoadSelfTest.java b/modules/core/src/test/java/org/apache/ignite/cache/store/IgniteCacheExpiryStoreLoadSelfTest.java index 64c76a8..9e8ad2b 100644 --- a/modules/core/src/test/java/org/apache/ignite/cache/store/IgniteCacheExpiryStoreLoadSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/cache/store/IgniteCacheExpiryStoreLoadSelfTest.java @@ -31,6 +31,7 @@ import javax.cache.integration.*; import java.util.*; import java.util.concurrent.*; +import static java.util.concurrent.TimeUnit.*; import static org.apache.ignite.cache.CacheMode.*; /** @@ -86,7 +87,7 @@ public class IgniteCacheExpiryStoreLoadSelfTest extends GridCacheAbstractSelfTes */ private void checkLoad(boolean async) throws Exception { IgniteCache<String, Integer> cache = jcache(0) - .withExpiryPolicy(new CreatedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, TIME_TO_LIVE))); + .withExpiryPolicy(new CreatedExpiryPolicy(new Duration(MILLISECONDS, TIME_TO_LIVE))); List<Integer> keys = new ArrayList<>(); @@ -112,6 +113,73 @@ public class IgniteCacheExpiryStoreLoadSelfTest extends GridCacheAbstractSelfTes } /** + * @throws Exception If failed. + */ + public void testLocalLoadCacheWithExpiry() throws Exception { + checkLocalLoad(false); + } + + /** + * @throws Exception If failed. + */ + public void testLocalLoadCacheWithExpiryAsync() throws Exception { + checkLocalLoad(true); + } + + /** + * @param async If {@code true} uses asynchronous method. + * @throws Exception If failed. + */ + private void checkLocalLoad(boolean async) throws Exception { + IgniteCache<String, Integer> cache = jcache(0) + .withExpiryPolicy(new CreatedExpiryPolicy(new Duration(MILLISECONDS, TIME_TO_LIVE))); + + List<Integer> keys = primaryKeys(cache, 3); + + if (async) { + IgniteCache<String, Integer> asyncCache = cache.withAsync(); + + asyncCache.localLoadCache(null, keys.toArray(new Integer[3])); + + asyncCache.future().get(); + } + else + cache.localLoadCache(null, keys.toArray(new Integer[3])); + + assertEquals(3, cache.localSize()); + + Thread.sleep(TIME_TO_LIVE + WAIT_TIME); + + assertEquals(0, cache.localSize(CachePeekMode.PRIMARY)); + } + + /** + * @throws Exception If failed. + */ + public void testLoadAllWithExpiry() throws Exception { + IgniteCache<Integer, Integer> cache = ignite(0).<Integer, Integer>jcache(null) + .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(CachePeekMode.PRIMARY)); + } + + /** * Test cache store. */ private static class TestStore implements CacheStore<Integer, Integer> { @@ -135,12 +203,17 @@ public class IgniteCacheExpiryStoreLoadSelfTest extends GridCacheAbstractSelfTes /** {@inheritDoc} */ @Override public Integer load(Integer key) throws CacheLoaderException { - return null; + return key; } /** {@inheritDoc} */ @Override public Map<Integer, Integer> loadAll(Iterable<? extends Integer> keys) { - return null; + Map<Integer, Integer> map = new HashMap<>(); + + for (Integer key : keys) + map.put(key, key); + + return map; } /** {@inheritDoc} */