use of org.apache.ignite.internal.processors.cache.GridCacheLocalConcurrentMap in project ignite by apache.
the class IgniteCacheClientNearCacheExpiryTest method testExpirationOnClient.
/**
* @throws Exception If failed.
*/
public void testExpirationOnClient() throws Exception {
Ignite ignite = grid(NODES - 1);
// Check size of near entries via reflection because entries is filtered for size() API call.
IgniteEx igniteEx = (IgniteEx) ignite;
GridCacheAdapter internalCache = igniteEx.context().cache().internalCache(DEFAULT_CACHE_NAME);
GridCacheLocalConcurrentMap map = GridTestUtils.getFieldValue(internalCache, GridCacheAdapter.class, "map");
assertTrue(ignite.configuration().isClientMode());
IgniteCache<Object, Object> cache = ignite.cache(DEFAULT_CACHE_NAME);
assertTrue(((IgniteCacheProxy) cache).context().isNear());
for (int i = 0; i < KEYS_COUNT; i++) cache.put(i, i);
CreatedExpiryPolicy plc = new CreatedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, 500));
IgniteCache<Object, Object> cacheWithExpiry = cache.withExpiryPolicy(plc);
for (int i = KEYS_COUNT; i < KEYS_COUNT * 2; i++) {
cacheWithExpiry.put(i, i);
assertEquals(i, cacheWithExpiry.localPeek(i));
}
assertEquals(KEYS_COUNT * 2, map.publicSize(internalCache.context().cacheId()));
U.sleep(1000);
assertEquals(KEYS_COUNT, map.publicSize(internalCache.context().cacheId()));
assertEquals(KEYS_COUNT, cache.size());
for (int i = 0; i < KEYS_COUNT; i++) assertEquals(i, cacheWithExpiry.localPeek(i));
for (int i = KEYS_COUNT; i < KEYS_COUNT * 2; i++) assertNull(cache.localPeek(i));
}
Aggregations