Skip to content

Commit

Permalink
# IGNITE-56 Fix incorrect usage of IgniteCache.loadCache() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
sevdokimov-gg committed Feb 6, 2015
1 parent fe6b766 commit d227081
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 31 deletions.
Expand Up @@ -28,6 +28,7 @@
import org.apache.ignite.transactions.*; import org.apache.ignite.transactions.*;
import org.jetbrains.annotations.*; import org.jetbrains.annotations.*;


import javax.cache.*;
import javax.cache.configuration.*; import javax.cache.configuration.*;
import java.util.*; import java.util.*;


Expand Down Expand Up @@ -62,7 +63,7 @@ protected GridCacheBasicStoreAbstractTest() {


/** {@inheritDoc} */ /** {@inheritDoc} */
@Override protected void afterTest() throws Exception { @Override protected void afterTest() throws Exception {
cache().clear(); jcache().clear();


store.reset(); store.reset();
} }
Expand Down Expand Up @@ -310,7 +311,7 @@ public void testLoadCache() throws Exception {


int cnt = 1; int cnt = 1;


cache.loadCache(null, 0, cnt); cache.loadCache(null, cnt);


checkLastMethod("loadAllFull"); checkLastMethod("loadAllFull");


Expand Down Expand Up @@ -345,7 +346,7 @@ public void testLoadCacheWithPredicate() throws Exception {
// Accept only even numbers. // Accept only even numbers.
return key % 2 == 0; return key % 2 == 0;
} }
}, 0, cnt); }, cnt);


checkLastMethod("loadAllFull"); checkLastMethod("loadAllFull");


Expand Down Expand Up @@ -373,11 +374,11 @@ public void testLoadCacheWithPredicate() throws Exception {


/** @throws Exception If test failed. */ /** @throws Exception If test failed. */
public void testReloadCache() throws Exception { public void testReloadCache() throws Exception {
GridCache<Integer, String> cache = cache(); IgniteCache<Integer, String> cache = jcache();


cache.loadCache(null, 0, 0); cache.loadCache(null, 0);


assert cache.isEmpty(); assert cache.size() == 0;


checkLastMethod("loadAllFull"); checkLastMethod("loadAllFull");


Expand All @@ -389,7 +390,7 @@ public void testReloadCache() throws Exception {


assert cache.size() == 10; assert cache.size() == 10;


cache.reloadAll(); cache.localLoadCache(null);


checkLastMethod("loadAll"); checkLastMethod("loadAll");


Expand All @@ -414,45 +415,43 @@ public void testReloadCache() throws Exception {
// Only accept even numbers. // Only accept even numbers.
return k % 2 == 0; return k % 2 == 0;
} }
}, 0, 10); }, 10);


checkLastMethod("loadAllFull"); checkLastMethod("loadAllFull");


store.resetLastMethod(); store.resetLastMethod();


assertEquals(5, cache.size()); assertEquals(5, cache.size());


cache.forEach(new CIX1<CacheEntry<Integer, String>>() { for (Cache.Entry<Integer, String> entry : cache) {
@Override public void applyx(CacheEntry<Integer, String> entry) throws IgniteCheckedException { String val = entry.getValue();
String val = entry.get();


assert val != null; assert val != null;
assert val.equals(Integer.toString(entry.getKey())); assert val.equals(Integer.toString(entry.getKey()));
assert entry.getKey() % 2 == 0; assert entry.getKey() % 2 == 0;


// Make sure that value is coming from cache, not from store. // Make sure that value is coming from cache, not from store.
checkLastMethod(null); checkLastMethod(null);
} }
});


// Make sure that value is coming from cache, not from store. // Make sure that value is coming from cache, not from store.
checkLastMethod(null); checkLastMethod(null);
} }


/** @throws Exception If test failed. */ /** @throws Exception If test failed. */
public void testReloadAll() throws Exception { public void testReloadAll() throws Exception {
GridCache<Integer, String> cache = cache(); IgniteCache<Integer, String> cache = jcache();


assert cache.isEmpty(); assert cache.size() == 0;


Map<Integer, String> vals = new HashMap<>(); Map<Integer, String> vals = new HashMap<>();


for (int i = 1; i <= 10; i++) for (int i = 1; i <= 10; i++)
vals.put(i, Integer.toString(i)); vals.put(i, Integer.toString(i));


cache.reloadAll(vals.keySet()); loadAll(cache, vals.keySet(), true);


assert cache.isEmpty() : "Cache is not empty: " + cache.values(); assert cache.size() == 0: "Cache is not empty.";


checkLastMethod("loadAll"); checkLastMethod("loadAll");


Expand All @@ -462,7 +461,7 @@ public void testReloadAll() throws Exception {


assert cache.size() == 10; assert cache.size() == 10;


cache.reloadAll(vals.keySet()); loadAll(cache, vals.keySet(), true);


checkLastMethod("loadAll"); checkLastMethod("loadAll");


Expand All @@ -483,7 +482,7 @@ public void testReloadAll() throws Exception {
for (int i = 1; i <= 10; i++) for (int i = 1; i <= 10; i++)
store.write(new CacheEntryImpl<>(i, "reloaded-" + i)); store.write(new CacheEntryImpl<>(i, "reloaded-" + i));


cache.reloadAll(vals.keySet()); loadAll(cache, vals.keySet(), true);


checkLastMethod("loadAll"); checkLastMethod("loadAll");


Expand All @@ -505,18 +504,18 @@ public void testReloadAll() throws Exception {
/** @throws Exception If test failed. */ /** @throws Exception If test failed. */
@SuppressWarnings("StringEquality") @SuppressWarnings("StringEquality")
public void testReload() throws Exception { public void testReload() throws Exception {
GridCache<Integer, String> cache = cache(); IgniteCache<Integer, String> cache = jcache();


assert cache.isEmpty(); assert cache.size() == 0;


Map<Integer, String> vals = new HashMap<>(); Map<Integer, String> vals = new HashMap<>();


for (int i = 1; i <= 10; i++) for (int i = 1; i <= 10; i++)
vals.put(i, Integer.toString(i)); vals.put(i, Integer.toString(i));


cache.reloadAll(vals.keySet()); loadAll(cache, vals.keySet(), true);


assert cache.isEmpty(); assert cache.size() == 0;


checkLastMethod("loadAll"); checkLastMethod("loadAll");


Expand All @@ -526,7 +525,9 @@ public void testReload() throws Exception {


assert cache.size() == 10; assert cache.size() == 10;


String val = cache.reload(1); load(cache, 1, true);

String val = cache.localPeek(1, CachePeekMode.ONHEAP);


assert val != null; assert val != null;
assert "1".equals(val); assert "1".equals(val);
Expand Down Expand Up @@ -555,7 +556,9 @@ public void testReload() throws Exception {
assert cache.size() == 10; assert cache.size() == 10;


for (int i = 1; i <= 10; i++) { for (int i = 1; i <= 10; i++) {
val = cache.reload(i); load(cache, i, true);

val = cache.localPeek(i, CachePeekMode.ONHEAP);


checkLastMethod("load"); checkLastMethod("load");


Expand Down
Expand Up @@ -29,13 +29,14 @@ public class GridTestLifecycleBean implements LifecycleBean {
@IgniteInstanceResource @IgniteInstanceResource
private Ignite g; private Ignite g;


/** {@inheritDoc} */
@Override public void onLifecycleEvent(LifecycleEventType type) { @Override public void onLifecycleEvent(LifecycleEventType type) {
if (type == LifecycleEventType.AFTER_GRID_START) { if (type == LifecycleEventType.AFTER_GRID_START) {
IgniteCache<GridTestKey, Long> cache = g.jcache("partitioned"); IgniteCache<GridTestKey, Long> cache = g.jcache("partitioned");


assert cache != null; assert cache != null;


cache.loadCache(null, 0, GridTestConstants.LOAD_THREADS, GridTestConstants.ENTRY_COUNT); cache.loadCache(null, GridTestConstants.LOAD_THREADS, GridTestConstants.ENTRY_COUNT);
} }
} }
} }

0 comments on commit d227081

Please sign in to comment.