use of org.apache.ignite.internal.cache.query.index.sorted.IndexRowCache in project ignite by apache.
the class H2RowCacheSelfTest method checkDeleteEntry.
/**
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
private void checkDeleteEntry() throws Exception {
final String cacheName = "cache";
grid().getOrCreateCache(cacheConfiguration(cacheName, true));
int grpId = grid().cachex(cacheName).context().groupId();
assertEquals(grpId, grid().cachex(cacheName).context().groupId());
fillCache(cacheName);
IndexRowCache rowCache = rowCache(grid(), grpId);
fillRowCache(cacheName);
assertNotNull(rowCache);
int key = RND.nextInt(ENTRIES);
grid().cache(cacheName).query(new SqlQuery(Value.class, "_key = " + key)).getAll();
int rowCacheSize = rowCache.size();
long rowLink = getLinkForKey(cacheName, rowCache, key);
assertNotNull(rowCache.get(rowLink));
// Remove
grid().cache(cacheName).remove(key);
assertNull(rowCache.get(rowLink));
int rowCacheSizeAfterUpdate = rowCache.size();
assertEquals(rowCacheSize - 1, rowCacheSizeAfterUpdate);
}
use of org.apache.ignite.internal.cache.query.index.sorted.IndexRowCache in project ignite by apache.
the class H2RowCacheSelfTest method checkDestroyCache.
/**
* @throws IgniteCheckedException If failed.
*/
private void checkDestroyCache() throws IgniteCheckedException {
final String cacheName0 = "cache0";
final String cacheName1 = "cache1";
grid().getOrCreateCache(cacheConfiguration(cacheName0, true));
grid().getOrCreateCache(cacheConfiguration(cacheName1, true));
int grpId = grid().cachex(cacheName0).context().groupId();
assertEquals(grpId, grid().cachex(cacheName1).context().groupId());
try (IgniteDataStreamer<Integer, Value> streamer = grid().dataStreamer(cacheName0)) {
for (int i = 0; i < ENTRIES / 2; ++i) streamer.addData(i, new Value(i));
}
try (IgniteDataStreamer<Integer, Value> streamer = grid().dataStreamer(cacheName1)) {
for (int i = ENTRIES / 2; i < ENTRIES; ++i) streamer.addData(i, new Value(i));
}
IndexRowCache rowCache = rowCache(grid(), grpId);
assertNotNull(rowCache);
Set<Long> linksOfCache0 = new HashSet<>(ENTRIES / 2);
Set<Long> linksOfCache1 = new HashSet<>(ENTRIES / 2);
for (int i = 0; i < ENTRIES / 2; ++i) linksOfCache0.add(getLinkForKey(cacheName0, rowCache(grid(), grpId), i));
for (int i = ENTRIES / 2; i < ENTRIES; ++i) linksOfCache1.add(getLinkForKey(cacheName1, rowCache(grid(), grpId), i));
grid().destroyCache(cacheName0);
assertNotNull(rowCache(grid(), grpId));
for (long link : linksOfCache0) assertNull(rowCache(grid(), grpId).get(link));
grid().destroyCache(cacheName1);
assertNull(rowCache(grid(), grpId));
}
use of org.apache.ignite.internal.cache.query.index.sorted.IndexRowCache in project ignite by apache.
the class H2RowCacheSelfTest method testFixedSize.
/**
* @throws Exception If failed.
*/
@Test
public void testFixedSize() throws Exception {
int maxSize = 100;
String cacheName = "cacheWithLimitedSize";
CacheConfiguration ccfg = cacheConfiguration(cacheName, true).setSqlOnheapCacheMaxSize(maxSize);
IgniteCache cache = grid().getOrCreateCache(ccfg);
int grpId = grid().cachex(cacheName).context().groupId();
// Fill half.
for (int i = 0; i < maxSize / 2; i++) cache.put(i, new Value(1));
IndexRowCache rowCache = rowCache(grid(), grpId);
assertEquals(0, rowCache.size());
// Warmup cache.
cache.query(new SqlFieldsQuery("SELECT * FROM Value")).getAll();
assertEquals(maxSize / 2, rowCache.size());
// Query again - are there any leaks?
cache.query(new SqlFieldsQuery("SELECT * FROM Value")).getAll();
assertEquals(maxSize / 2, rowCache.size());
// Fill up to limit.
for (int i = maxSize / 2; i < maxSize; i++) cache.put(i, new Value(1));
assertEquals(maxSize / 2, rowCache.size());
cache.query(new SqlFieldsQuery("SELECT * FROM Value")).getAll();
assertEquals(maxSize, rowCache.size());
// Out of limit.
for (int i = maxSize; i < maxSize * 2; i++) cache.put(i, new Value(1));
assertEquals(maxSize, rowCache.size());
cache.query(new SqlFieldsQuery("SELECT * FROM Value")).getAll();
assertEquals(maxSize, rowCache.size());
// Delete all.
cache.query(new SqlFieldsQuery("DELETE FROM Value")).getAll();
assertEquals(0, rowCache.size());
cache.query(new SqlFieldsQuery("SELECT * FROM Value")).getAll();
assertEquals(0, rowCache.size());
}
use of org.apache.ignite.internal.cache.query.index.sorted.IndexRowCache in project ignite by apache.
the class H2RowCacheSelfTest method checkUpdateEntry.
/**
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
private void checkUpdateEntry() throws Exception {
final String cacheName = "cache";
grid().getOrCreateCache(cacheConfiguration(cacheName, true));
int grpId = grid().cachex(cacheName).context().groupId();
assertEquals(grpId, grid().cachex(cacheName).context().groupId());
fillCache(cacheName);
IndexRowCache rowCache = rowCache(grid(), grpId);
fillRowCache(cacheName);
assertNotNull(rowCache);
int key = RND.nextInt(ENTRIES);
long rowLink = getLinkForKey(cacheName, rowCache, key);
int rowCacheSize = rowCache.size();
assertNotNull(rowCache.get(rowLink));
// Update row
grid().cache(cacheName).put(key, new Value(key + 1));
assertNull(rowCache.get(rowLink));
int rowCacheSizeAfterUpdate = rowCache.size();
assertEquals(rowCacheSize - 1, rowCacheSizeAfterUpdate);
// Check updated value.
List<Cache.Entry<Integer, Value>> res = grid().<Integer, Value>cache(cacheName).query(new SqlQuery(Value.class, "_key = " + key)).getAll();
assertEquals(1, res.size());
assertEquals(key + 1, (int) res.get(0).getValue().lVal);
}
use of org.apache.ignite.internal.cache.query.index.sorted.IndexRowCache in project ignite by apache.
the class H2RowCachePageEvictionTest method checkRowCacheOnPageEviction.
/**
*/
private void checkRowCacheOnPageEviction() {
grid().getOrCreateCache(cacheConfiguration(CACHE_NAME, true));
int grpId = grid().cachex(CACHE_NAME).context().groupId();
assertEquals(grpId, grid().cachex(CACHE_NAME).context().groupId());
try (IgniteDataStreamer<Integer, Value> stream = grid().dataStreamer(CACHE_NAME)) {
for (int i = 0; i < ENTRIES; ++i) stream.addData(i, new Value(i));
}
IndexRowCache rowCache = rowCache(grid()).forGroup(grpId);
fillRowCache(CACHE_NAME);
assertNotNull(rowCache);
int rowCacheSizeBeforeEvict = rowCache.size();
try (IgniteDataStreamer<Integer, Value> stream = grid().dataStreamer(CACHE_NAME)) {
for (int i = ENTRIES; i < 2 * ENTRIES; ++i) stream.addData(i, new Value(i));
}
assertTrue("rowCache size before evictions: " + rowCacheSizeBeforeEvict + ", after evictions: " + rowCache.size(), rowCacheSizeBeforeEvict > rowCache.size());
}
Aggregations