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.jetbrains.annotations.*;

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

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

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

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

int cnt = 1;

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

checkLastMethod("loadAllFull");

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

checkLastMethod("loadAllFull");

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

/** @throws Exception If test failed. */
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");

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

assert cache.size() == 10;

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

checkLastMethod("loadAll");

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

checkLastMethod("loadAllFull");

store.resetLastMethod();

assertEquals(5, cache.size());

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

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

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

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

/** @throws Exception If test failed. */
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<>();

for (int i = 1; i <= 10; 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");

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

assert cache.size() == 10;

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

checkLastMethod("loadAll");

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

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

checkLastMethod("loadAll");

Expand All @@ -505,18 +504,18 @@ public void testReloadAll() throws Exception {
/** @throws Exception If test failed. */
@SuppressWarnings("StringEquality")
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<>();

for (int i = 1; i <= 10; 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");

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

assert cache.size() == 10;

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

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

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

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

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

checkLastMethod("load");

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

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

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.