Index: ../ggprivate/os/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheClearAllSelfTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- ../ggprivate/os/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheClearAllSelfTest.java (date 1419927043000) +++ ../ggprivate/os/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/GridCacheClearAllSelfTest.java (revision ) @@ -11,19 +11,20 @@ import org.gridgain.grid.*; import org.gridgain.grid.cache.*; -import org.gridgain.grid.cache.affinity.consistenthash.*; import org.gridgain.grid.spi.discovery.tcp.*; import org.gridgain.grid.spi.discovery.tcp.ipfinder.*; import org.gridgain.grid.spi.discovery.tcp.ipfinder.vm.*; import org.gridgain.testframework.junits.common.*; import java.lang.reflect.*; +import java.util.*; import static org.gridgain.grid.cache.GridCacheMode.*; import static org.gridgain.grid.cache.GridCacheDistributionMode.*; import static org.gridgain.grid.cache.GridCacheWriteSynchronizationMode.*; import static org.gridgain.grid.cache.GridCacheAtomicityMode.*; import static org.gridgain.grid.kernal.processors.cache.GridCacheAdapter.*; +import static org.gridgain.grid.cache.GridCacheMemoryMode.*; /** * Test {@link GridCache#clearAll()} operations in multinode environment with nodes having caches with different names. @@ -41,6 +42,9 @@ /** Replicated cache. */ private static final String CACHE_REPLICATED = "cache_replicated"; + /** Partitioned cache. */ + private static final String CACHE_OH_PARTITIONED = "cache_oh_partitioned"; + /** Grid nodes count. */ private static final int GRID_CNT = 3; @@ -59,6 +63,9 @@ /** Replicated caches. */ private GridCache[] cachesReplicated; + /** Offheap caches. */ + private GridCache[] cachesOffheap; + /** {@inheritDoc} */ @Override protected GridConfiguration getConfiguration(String gridName) throws Exception { GridConfiguration cfg = super.getConfiguration(gridName); @@ -80,6 +87,16 @@ gridName.equals(getTestGridName(1)) ? NEAR_ONLY : CLIENT_ONLY); ccfgPartitioned.setAtomicityMode(TRANSACTIONAL); + GridCacheConfiguration ccfgOhPartitioned = new GridCacheConfiguration(); + + ccfgOhPartitioned.setName(CACHE_OH_PARTITIONED); + ccfgOhPartitioned.setCacheMode(PARTITIONED); + ccfgOhPartitioned.setBackups(0); + ccfgOhPartitioned.setWriteSynchronizationMode(PRIMARY_SYNC); + ccfgOhPartitioned.setDistributionMode(PARTITIONED_ONLY); + ccfgOhPartitioned.setAtomicityMode(ATOMIC); + ccfgOhPartitioned.setMemoryMode(OFFHEAP_TIERED); + GridCacheConfiguration ccfgColocated = new GridCacheConfiguration(); ccfgColocated.setName(CACHE_COLOCATED); @@ -96,7 +113,7 @@ ccfgReplicated.setWriteSynchronizationMode(FULL_SYNC); ccfgReplicated.setAtomicityMode(TRANSACTIONAL); - cfg.setCacheConfiguration(ccfgLoc, ccfgPartitioned, ccfgColocated, ccfgReplicated); + cfg.setCacheConfiguration(ccfgLoc, ccfgPartitioned, ccfgOhPartitioned, ccfgColocated, ccfgReplicated); GridTcpDiscoverySpi discoSpi = new GridTcpDiscoverySpi(); @@ -127,6 +144,7 @@ cachesPartitioned = (GridCache[])Array.newInstance(GridCache.class, GRID_CNT); cachesColocated = (GridCache[])Array.newInstance(GridCache.class, GRID_CNT); cachesReplicated = (GridCache[])Array.newInstance(GridCache.class, GRID_CNT); + cachesOffheap = (GridCache[])Array.newInstance(GridCache.class, GRID_CNT); for (int i = 0; i < GRID_CNT; i++) { Grid grid = startGrid(i); @@ -135,6 +153,7 @@ cachesPartitioned[i] = grid.cache(CACHE_PARTITIONED); cachesColocated[i] = grid.cache(CACHE_COLOCATED); cachesReplicated[i] = grid.cache(CACHE_REPLICATED); + cachesOffheap[i] = grid.cache(CACHE_OH_PARTITIONED); } } @@ -208,6 +227,55 @@ */ public void testReplicatedSplit() throws Exception { test(Mode.TEST_REPLICATED, CLEAR_ALL_SPLIT_THRESHOLD + 1); + } + + /** + * Test {@link GridCache#clear(Object)} on PARTITIONED OFFHEAP cache with. + * + * @throws Exception If failed. + */ + public void testClearOffHeap() throws Exception { + startUp(); + + for (int i = 0; i < 1000; i++) { + cachesOffheap[0].put(i, i); + cachesOffheap[1].put(i + 10000, i + 10000); + cachesOffheap[2].put(i + 20000, i + 20000); + } + + Iterator> it = cachesOffheap[0].offHeapIterator(); + + info("Offheap entries before: " + cachesOffheap[0].offHeapEntriesCount()); + + while (it.hasNext()) + cachesOffheap[0].clear(it.next().getKey()); + + info("Offheap entries after: " + cachesOffheap[0].offHeapEntriesCount()); + + assert cachesOffheap[0].offHeapEntriesCount() == 0; + } + + /** + * Test {@link GridCache#clearAll()} on PARTITIONED OFFHEAP cache with. + * + * @throws Exception If failed. + */ + public void testClearAllOffHeap() throws Exception { + startUp(); + + for (int i = 0; i < 1000; i++) { + cachesOffheap[0].put(i, i); + cachesOffheap[1].put(i + 10000, i + 10000); + cachesOffheap[2].put(i + 20000, i + 20000); + } + + info("Offheap entries before clear: " + cachesOffheap[0].offHeapEntriesCount()); + + cachesOffheap[0].clearAll(); + + info("Offheap entries after clear: " + cachesOffheap[0].offHeapEntriesCount()); + + assert cachesOffheap[0].offHeapEntriesCount() == 0; } /**