Skip to content

Commit

Permalink
#ignite-565: Remove GridCache from tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivasilinets committed Mar 25, 2015
1 parent 1b7fb1d commit 15334cc
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 125 deletions.
Expand Up @@ -19,7 +19,6 @@


import org.apache.ignite.*; import org.apache.ignite.*;
import org.apache.ignite.configuration.*; import org.apache.ignite.configuration.*;
import org.apache.ignite.internal.processors.cache.*;
import org.apache.ignite.spi.discovery.tcp.*; import org.apache.ignite.spi.discovery.tcp.*;
import org.apache.ignite.spi.discovery.tcp.ipfinder.*; import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
Expand Down Expand Up @@ -89,14 +88,6 @@ abstract class AbstractRestProcessorSelfTest extends GridCommonAbstractTest {
return cfg; return cfg;
} }


/**
* @return Cache.
*/
@Deprecated
@Override protected <K, V> GridCache<K, V> cache() {
throw new UnsupportedOperationException();
}

/** /**
* @return Cache. * @return Cache.
*/ */
Expand Down
Expand Up @@ -106,10 +106,10 @@ public void testAffinity() throws Exception {
* Check CacheAffinityProxy methods. * Check CacheAffinityProxy methods.
*/ */
private void checkAffinity() { private void checkAffinity() {
checkAffinity(grid(0).affinity(null), cache(1, null).affinity()); checkAffinity(grid(0).affinity(null), internalCache(1, null).affinity());
checkAffinity(grid(0).affinity(CACHE1), cache(1, CACHE1).affinity()); checkAffinity(grid(0).affinity(CACHE1), internalCache(1, CACHE1).affinity());
checkAffinity(grid(0).affinity(CACHE1), cache(1, CACHE1).affinity()); checkAffinity(grid(0).affinity(CACHE1), internalCache(1, CACHE1).affinity());
checkAffinity(grid(0).affinity(CACHE2), cache(1, CACHE2).affinity()); checkAffinity(grid(0).affinity(CACHE2), internalCache(1, CACHE2).affinity());
} }


/** /**
Expand Down
Expand Up @@ -47,6 +47,7 @@
import java.util.concurrent.locks.*; import java.util.concurrent.locks.*;


import static java.util.concurrent.TimeUnit.*; import static java.util.concurrent.TimeUnit.*;
import static org.apache.ignite.cache.CacheMemoryMode.OFFHEAP_TIERED;
import static org.apache.ignite.cache.CacheMode.*; import static org.apache.ignite.cache.CacheMode.*;
import static org.apache.ignite.events.EventType.*; import static org.apache.ignite.events.EventType.*;
import static org.apache.ignite.testframework.GridTestUtils.*; import static org.apache.ignite.testframework.GridTestUtils.*;
Expand Down Expand Up @@ -3735,7 +3736,7 @@ protected void checkSize(Collection<String> keys) throws Exception {
for (int i = 0; i < gridCount(); i++) { for (int i = 0; i < gridCount(); i++) {
GridCacheContext<String, Integer> ctx = context(i); GridCacheContext<String, Integer> ctx = context(i);


if (offheapTiered(ctx.cache())) if (ctx.cache().configuration().getMemoryMode() == OFFHEAP_TIERED)
continue; continue;


int size = 0; int size = 0;
Expand Down
Expand Up @@ -335,23 +335,6 @@ protected final boolean partitionedMode() {
return cacheMode() == PARTITIONED; return cacheMode() == PARTITIONED;
} }


/**
* @param idx Index of grid.
* @return Cache instance casted to work with string and integer types for convenience.
*/
@SuppressWarnings({"unchecked"})
@Override protected GridCache<String, Integer> cache(int idx) {
return ((IgniteKernal)grid(idx)).getCache(null);
}

/**
* @return Default cache instance casted to work with string and integer types for convenience.
*/
@SuppressWarnings({"unchecked"})
@Override protected GridCache<String, Integer> cache() {
return cache(0);
}

/** /**
* @return Default cache instance. * @return Default cache instance.
*/ */
Expand Down Expand Up @@ -393,14 +376,6 @@ protected boolean belongs(String key, int idx) {
return context(idx).cache().affinity().isPrimaryOrBackup(context(idx).localNode(), key); return context(idx).cache().affinity().isPrimaryOrBackup(context(idx).localNode(), key);
} }


/**
* @param cache Cache.
* @return {@code True} if cache has OFFHEAP_TIERED memory mode.
*/
protected boolean offheapTiered(GridCache cache) {
return cache.configuration().getMemoryMode() == OFFHEAP_TIERED;
}

/** /**
* @param cache Cache. * @param cache Cache.
* @return {@code True} if cache has OFFHEAP_TIERED memory mode. * @return {@code True} if cache has OFFHEAP_TIERED memory mode.
Expand Down Expand Up @@ -433,24 +408,6 @@ protected boolean containsKey(IgniteCache cache, Object key) throws Exception {
return offheapTiered(cache) ? cache.localPeek(key, CachePeekMode.OFFHEAP) != null : cache.containsKey(key); return offheapTiered(cache) ? cache.localPeek(key, CachePeekMode.OFFHEAP) != null : cache.containsKey(key);
} }


/**
* @param cache Cache.
* @param val Value.
* @return {@code True} if offheap contains given value.
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
protected boolean containsOffheapValue(GridCache cache, Object val) throws Exception {
for (Iterator<Map.Entry> it = cache.offHeapIterator(); it.hasNext();) {
Map.Entry e = it.next();

if (val.equals(e.getValue()))
return true;
}

return false;
}

/** /**
* Filters cache entry projections leaving only ones with keys containing 'key'. * Filters cache entry projections leaving only ones with keys containing 'key'.
*/ */
Expand Down
Expand Up @@ -80,7 +80,7 @@ public abstract class GridCacheOnCopyFlagAbstractSelfTest extends GridCacheAbstr
interceptor.delegate(new CacheInterceptorAdapter<TestKey, TestValue>()); interceptor.delegate(new CacheInterceptorAdapter<TestKey, TestValue>());


for (int i = 0; i < gridCount(); i++) for (int i = 0; i < gridCount(); i++)
cache(i, null).clearLocally(); jcache(i, null).localClearAll(keySet(jcache(i, null)));
} }


/** {@inheritDoc} */ /** {@inheritDoc} */
Expand Down
Expand Up @@ -120,14 +120,6 @@ protected GridCacheNodeFailureAbstractTest() {
} }
} }


/**
* @param i Grid index.
* @return Cache.
*/
@Override protected <K, V> GridCache<K, V> cache(int i) {
return ((IgniteKernal)IGNITEs.get(i)).getCache(null);
}

/** /**
* @param i Grid index. * @param i Grid index.
* @return Cache. * @return Cache.
Expand Down
Expand Up @@ -61,14 +61,6 @@ public class IgniteTxTimeoutAbstractTest extends GridCommonAbstractTest {
IGNITEs.clear(); IGNITEs.clear();
} }


/**
* @param i Grid index.
* @return Cache.
*/
@Override protected <K, V> GridCache<K, V> cache(int i) {
throw new UnsupportedOperationException();
}

/** /**
* @param i Grid index. * @param i Grid index.
* @return Cache. * @return Cache.
Expand Down
Expand Up @@ -75,23 +75,23 @@ public void testOneNode() throws Exception {
checkNodes(startGridsMultiThreaded(1)); checkNodes(startGridsMultiThreaded(1));


assertEquals(26, colocated(0, "test").size()); assertEquals(26, colocated(0, "test").size());
assertEquals(26, cache(0, "test").size()); assertEquals(26, jcache(0, "test").localSize());
} }


/** @throws Exception If failed. */ /** @throws Exception If failed. */
public void testTwoNodes() throws Exception { public void testTwoNodes() throws Exception {
checkNodes(startGridsMultiThreaded(2)); checkNodes(startGridsMultiThreaded(2));


assertTrue(colocated(0, "test").size() > 0); assertTrue(colocated(0, "test").size() > 0);
assertTrue(cache(0, "test").size() > 0); assertTrue(jcache(0, "test").localSize() > 0);
} }


/** @throws Exception If failed. */ /** @throws Exception If failed. */
public void testThreeNodes() throws Exception { public void testThreeNodes() throws Exception {
checkNodes(startGridsMultiThreaded(3)); checkNodes(startGridsMultiThreaded(3));


assertTrue(colocated(0, "test").size() > 0); assertTrue(colocated(0, "test").size() > 0);
assertTrue(cache(0, "test").size() > 0); assertTrue(jcache(0, "test").localSize() > 0);
} }


/** /**
Expand Down
Expand Up @@ -131,7 +131,7 @@ public void testNearEnabledTwoNodes() throws Exception {
}); });


for (int i = 0; i < gridCnt; i++) { for (int i = 0; i < gridCnt; i++) {
assertEquals(cnt, grid(i).cache(null).size()); assertEquals(cnt, internalCache(i).size());
assertEquals(0, near(i).nearSize()); assertEquals(0, near(i).nearSize());
} }
} }
Expand Down Expand Up @@ -164,7 +164,7 @@ public void testNearEnabledThreeNodes() throws Exception {
}); });


for (int i = 0; i < gridCnt; i++) { for (int i = 0; i < gridCnt; i++) {
final IgniteCache cache = grid(i).cache(null); final GridCache cache = internalCache(i);


// Repeatedly check cache sizes because of concurrent cache updates. // Repeatedly check cache sizes because of concurrent cache updates.
assertTrue(GridTestUtils.waitForCondition(new PA() { assertTrue(GridTestUtils.waitForCondition(new PA() {
Expand Down
Expand Up @@ -22,6 +22,7 @@
import org.apache.ignite.cluster.*; import org.apache.ignite.cluster.*;
import org.apache.ignite.configuration.*; import org.apache.ignite.configuration.*;
import org.apache.ignite.events.*; import org.apache.ignite.events.*;
import org.apache.ignite.internal.*;
import org.apache.ignite.internal.processors.cache.*; import org.apache.ignite.internal.processors.cache.*;
import org.apache.ignite.internal.util.lang.*; import org.apache.ignite.internal.util.lang.*;
import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.*;
Expand Down Expand Up @@ -127,13 +128,6 @@ protected boolean clientHasNearCache() {
}); });
} }


/**
* @return For the purpose of this test returns the near-only instance.
*/
@Override protected GridCache<String, Integer> cache() {
return cache(nearIdx);
}

/** /**
* @return A not near-only cache. * @return A not near-only cache.
*/ */
Expand Down
Expand Up @@ -449,7 +449,7 @@ public void testMultipleNodes() throws Exception {
grid(0).cache(null).putAll(map); grid(0).cache(null).putAll(map);


for (int gridIdx = 0; gridIdx < gridCnt; gridIdx++) { for (int gridIdx = 0; gridIdx < gridCnt; gridIdx++) {
assert grid(gridIdx).cache(null).size() == cnt : "Actual size: " + grid(gridIdx).cache(null).size(); assert grid(gridIdx).cache(null).localSize() == cnt : "Actual size: " + grid(gridIdx).cache(null).localSize();


info("Cache size is OK for grid index: " + gridIdx); info("Cache size is OK for grid index: " + gridIdx);
} }
Expand Down
Expand Up @@ -68,40 +68,43 @@ protected GridCommonAbstractTest() {
* @param idx Grid index. * @param idx Grid index.
* @return Cache. * @return Cache.
*/ */
protected <K, V> GridCache<K, V> cache(int idx) { protected <K, V> IgniteCache<K, V> jcache(int idx) {
return grid(idx).cachex(); return grid(idx).cache(null);
} }


/** /**
* @param idx Grid index. * @param idx Grid index.
* @param name Cache name.
* @return Cache. * @return Cache.
*/ */
protected <K, V> IgniteCache<K, V> jcache(int idx) { protected <K, V> IgniteCache<K, V> jcache(int idx, String name) {
return grid(idx).cache(null); return grid(idx).cache(name);
} }


/** /**
* @param idx Grid index. * @param idx Grid index.
* @param name Cache name.
* @return Cache. * @return Cache.
*/ */
protected <K, V> GridCache<K, V> cache(int idx, String name) { protected <K, V> GridCacheAdapter<K, V> internalCache(int idx) {
return grid(idx).cachex(name); return ((IgniteKernal)grid(idx)).internalCache(null);
} }


/** /**
* @param idx Grid index.
* @param name Cache name.
* @return Cache. * @return Cache.
*/ */
protected <K, V> GridCache<K, V> cache() { protected <K, V> GridCacheAdapter<K, V> internalCache(int idx, String name) {
return grid().cachex(); return ((IgniteKernal)grid(idx)).internalCache(name);
} }


/** /**
* @param idx Grid index. * @param ignite Grid.
* @param name Cache name.
* @return Cache. * @return Cache.
*/ */
protected <K, V> GridCache<K, V> internalCache(int idx) { protected <K, V> GridCacheAdapter<K, V> internalCache(Ignite ignite, String name) {
return ((IgniteKernal)grid(idx)).getCache(null); return ((IgniteKernal)ignite).internalCache(name);
} }


/** /**
Expand Down Expand Up @@ -142,18 +145,20 @@ protected <K, V> GridLocalCache<K, V> local() {
* @param cache Cache. * @param cache Cache.
* @return DHT cache. * @return DHT cache.
*/ */
protected static <K, V> GridDhtCacheAdapter<K, V> dht(GridCache<K,V> cache) { protected static <K, V> GridDhtCacheAdapter<K, V> dht(IgniteCache<K,V> cache) {
return nearEnabled(cache) ? near(cache).dht() : return nearEnabled(cache) ? near(cache).dht() :
((IgniteKernal)cache.gridProjection().ignite()).<K, V>internalCache(cache.name()).context().dht(); ((IgniteKernal)cache.unwrap(Ignite.class)).<K, V>internalCache(cache.getName()).context().dht();
} }


/** /**
* @param cache Cache. * @param ignite Ignite.
* @param cfg Cache configuration.
* @return DHT cache. * @return DHT cache.
*/ */
protected static <K, V> GridDhtCacheAdapter<K, V> dht(IgniteCache<K,V> cache) { private static <K, V> GridDhtCacheAdapter<K, V> dht(Ignite ignite, CacheConfiguration cfg) {
return nearEnabled(cache) ? near(cache).dht() : GridNearCacheAdapter<K, V> adapter = near(ignite, cfg.getName());
((IgniteKernal)cache.unwrap(Ignite.class)).<K, V>internalCache(cache.getName()).context().dht(); return nearEnabled(cfg) ? adapter.dht() :
((IgniteKernal)ignite).<K, V>internalCache(cfg.getName()).context().dht();
} }


/** /**
Expand Down Expand Up @@ -190,13 +195,9 @@ protected <K, V> GridDhtColocatedCache<K, V> colocated(int idx, String cache) {
} }


/** /**
* @param cache Cache.
* @return {@code True} if near cache is enabled. * @return {@code True} if near cache is enabled.
*/ */
protected static <K, V> boolean nearEnabled(GridCache<K,V> cache) { private static <K, V> boolean nearEnabled(CacheConfiguration cfg) {
CacheConfiguration cfg = ((IgniteKernal)cache.gridProjection().ignite()).
<K, V>internalCache(cache.name()).context().config();

return isNearEnabled(cfg); return isNearEnabled(cfg);
} }


Expand All @@ -215,16 +216,15 @@ protected static <K, V> boolean nearEnabled(IgniteCache<K,V> cache) {
* @param cache Cache. * @param cache Cache.
* @return Near cache. * @return Near cache.
*/ */
protected static <K, V> GridNearCacheAdapter<K, V> near(GridCache<K,V> cache) { protected static <K, V> GridNearCacheAdapter<K, V> near(IgniteCache<K,V> cache) {
return ((IgniteKernal)cache.gridProjection().ignite()).<K, V>internalCache(cache.name()).context().near(); return ((IgniteKernal)cache.unwrap(Ignite.class)).<K, V>internalCache(cache.getName()).context().near();
} }


/** /**
* @param cache Cache.
* @return Near cache. * @return Near cache.
*/ */
protected static <K, V> GridNearCacheAdapter<K, V> near(IgniteCache<K,V> cache) { private static <K, V> GridNearCacheAdapter<K, V> near(Ignite ignite, String cacheName) {
return ((IgniteKernal)cache.unwrap(Ignite.class)).<K, V>internalCache(cache.getName()).context().near(); return ((IgniteKernal)ignite).<K, V>internalCache(cacheName).context().near();
} }


/** /**
Expand Down Expand Up @@ -347,13 +347,11 @@ protected <K, V> GridNearCacheAdapter<K, V> near(int idx, String cache) {
@SuppressWarnings("BusyWait") @SuppressWarnings("BusyWait")
protected void awaitPartitionMapExchange() throws InterruptedException { protected void awaitPartitionMapExchange() throws InterruptedException {
for (Ignite g : G.allGrids()) { for (Ignite g : G.allGrids()) {
for (GridCache<?, ?> c : ((IgniteEx)g).cachesx()) { for (CacheConfiguration cfg : g.configuration().getCacheConfiguration()) {
CacheConfiguration cfg = c.configuration();

if (cfg.getCacheMode() == PARTITIONED && cfg.getRebalanceMode() != NONE && g.cluster().nodes().size() > 1) { if (cfg.getCacheMode() == PARTITIONED && cfg.getRebalanceMode() != NONE && g.cluster().nodes().size() > 1) {
AffinityFunction aff = cfg.getAffinity(); AffinityFunction aff = cfg.getAffinity();


GridDhtCacheAdapter<?, ?> dht = dht(c); GridDhtCacheAdapter<?, ?> dht = dht(g, cfg);


GridDhtPartitionTopology top = dht.topology(); GridDhtPartitionTopology top = dht.topology();


Expand All @@ -362,7 +360,7 @@ protected void awaitPartitionMapExchange() throws InterruptedException {


for (int i = 0; ; i++) { for (int i = 0; ; i++) {
// Must map on updated version of topology. // Must map on updated version of topology.
Collection<ClusterNode> affNodes = c.affinity().mapPartitionToPrimaryAndBackups(p); Collection<ClusterNode> affNodes = g.affinity(cfg.getName()).mapPartitionToPrimaryAndBackups(p);


int exp = affNodes.size(); int exp = affNodes.size();


Expand Down

0 comments on commit 15334cc

Please sign in to comment.