use of org.apache.geode.cache.query.IndexStatistics in project geode by apache.
the class IndexStatisticsJUnitTest method testStatsForCompactMapRangeIndex.
/**
* Test CompactMapRenageIndex IndexStatistics for keys, values, updates and uses.
*
* @throws Exception
*/
@Test
public void testStatsForCompactMapRangeIndex() throws Exception {
keyIndex3 = (IndexProtocol) qs.createIndex("multiKeyIndex3", IndexType.FUNCTIONAL, "positions['DELL', 'YHOO']", "/portfolio p");
assertTrue(keyIndex3 instanceof CompactMapRangeIndex);
Object[] indexes = ((CompactMapRangeIndex) keyIndex3).getRangeIndexHolderForTesting().values().toArray();
assertTrue(indexes[0] instanceof CompactRangeIndex);
assertTrue(indexes[1] instanceof CompactRangeIndex);
IndexStatistics keyIndexStats = keyIndex3.getStatistics();
assertEquals(2, keyIndexStats.getNumberOfMapIndexKeys());
assertEquals(100, keyIndexStats.getNumberOfKeys());
assertEquals(100, keyIndexStats.getNumberOfKeys());
assertEquals(100, keyIndexStats.getNumberOfValues());
assertEquals(100, keyIndexStats.getNumUpdates());
for (int i = 0; i < 100; i++) {
region.put(Integer.toString(i), new Portfolio(i, i));
}
assertEquals(2, keyIndexStats.getNumberOfMapIndexKeys());
assertEquals(100, keyIndexStats.getNumberOfKeys());
assertEquals(100, keyIndexStats.getNumberOfValues());
assertEquals(200, keyIndexStats.getNumUpdates());
String queryStr = "select * from /portfolio where positions['DELL'] != NULL OR positions['YHOO'] != NULL";
Query query = qs.newQuery(queryStr);
for (int i = 0; i < 50; i++) {
query.execute();
}
assertEquals(0, keyIndexStats.getReadLockCount());
assertEquals(100, keyIndexStats.getTotalUses());
for (int i = 0; i < 50; i++) {
region.invalidate(Integer.toString(i));
}
assertEquals(2, keyIndexStats.getNumberOfMapIndexKeys());
assertEquals(50, keyIndexStats.getNumberOfKeys());
assertEquals(50, keyIndexStats.getNumberOfValues());
assertEquals(250, keyIndexStats.getNumUpdates());
for (int i = 0; i < 50; i++) {
region.destroy(Integer.toString(i));
}
assertEquals(2, keyIndexStats.getNumberOfMapIndexKeys());
assertEquals(50, keyIndexStats.getNumberOfKeys());
assertEquals(50, keyIndexStats.getNumberOfValues());
assertEquals(250, keyIndexStats.getNumUpdates());
for (int i = 50; i < 100; i++) {
region.destroy(Integer.toString(i));
}
assertEquals(300, keyIndexStats.getNumUpdates());
assertEquals(2, keyIndexStats.getNumberOfMapIndexKeys());
assertEquals(0, keyIndexStats.getNumberOfKeys());
qs.removeIndex(keyIndex3);
region.destroyRegion();
}
use of org.apache.geode.cache.query.IndexStatistics in project geode by apache.
the class IndexMaintainceJUnitTest method test001AddEntry.
@Test
public void test001AddEntry() throws Exception {
CacheUtils.log(((CompactRangeIndex) index).dump());
IndexStatistics stats = index.getStatistics();
assertEquals(4, stats.getNumberOfValues());
// org.apache.geode.internal.util.
// DebuggerSupport.waitForJavaDebugger(region.getCache().getLogger());
region.put("4", new Portfolio(4));
CacheUtils.log(((CompactRangeIndex) index).dump());
stats = index.getStatistics();
assertEquals(5, stats.getNumberOfValues());
// Set results = new HashSet();
// index.query("active", OQLLexerTokenTypes.TOK_EQ, results, new ExecutionContext(null,
// CacheUtils.getCache()));
SelectResults results = region.query("status = 'active'");
assertEquals(3, results.size());
}
use of org.apache.geode.cache.query.IndexStatistics in project geode by apache.
the class IndexMaintainceJUnitTest method test003InvalidateEntry.
@Test
public void test003InvalidateEntry() throws Exception {
IndexStatistics stats = index.getStatistics();
region.invalidate("4");
assertEquals(4, stats.getNumberOfValues());
// Set results = new HashSet();
// index.query("active", OQLLexerTokenTypes.TOK_EQ, results,new ExecutionContext(null,
// CacheUtils.getCache()));
SelectResults results = region.query("status = 'active'");
assertEquals(2, results.size());
}
use of org.apache.geode.cache.query.IndexStatistics in project geode by apache.
the class IndexStatisticsJUnitTest method testStatsForRangeIndexAfterRecreate.
@Test
public void testStatsForRangeIndexAfterRecreate() throws Exception {
keyIndex2 = (IndexProtocol) qs.createIndex("multiKeyIndex2", IndexType.FUNCTIONAL, "pos.secId", "/portfolio p, p.positions.values pos");
assertTrue(keyIndex2 instanceof RangeIndex);
IndexStatistics keyIndex1Stats = keyIndex2.getStatistics();
// Initial stats test (keys, values & updates)
assertEquals(4, keyIndex1Stats.getNumberOfKeys());
assertEquals(200, keyIndex1Stats.getNumberOfValues());
assertEquals(200, keyIndex1Stats.getNumUpdates());
for (int i = 0; i < 100; i++) {
region.put(Integer.toString(i), new Portfolio(i, i));
}
String queryStr = "select * from /portfolio p, p.positions.values pos where pos.secId = 'YHOO'";
Query query = qs.newQuery(queryStr);
for (int i = 0; i < 50; i++) {
query.execute();
}
assertEquals(4, keyIndex1Stats.getNumberOfKeys());
assertEquals(200, keyIndex1Stats.getNumberOfValues());
assertEquals(400, keyIndex1Stats.getNumUpdates());
assertEquals(50, keyIndex1Stats.getTotalUses());
region.clear();
assertEquals(0, keyIndex1Stats.getNumberOfKeys());
assertEquals(0, keyIndex1Stats.getNumberOfValues());
assertEquals(800, keyIndex1Stats.getNumUpdates());
assertEquals(50, keyIndex1Stats.getTotalUses());
for (int i = 0; i < 100; i++) {
region.put(Integer.toString(i), new Portfolio(i, i));
}
assertEquals(4, keyIndex1Stats.getNumberOfKeys());
assertEquals(200, keyIndex1Stats.getNumberOfValues());
assertEquals(1000, keyIndex1Stats.getNumUpdates());
for (int i = 0; i < 50; i++) {
query.execute();
}
assertEquals(100, keyIndex1Stats.getTotalUses());
qs.removeIndex(keyIndex2);
}
use of org.apache.geode.cache.query.IndexStatistics in project geode by apache.
the class IndexMaintainceJUnitTest method test002UpdateEntry.
// !!!:ezoerner:20081030 disabled because modifying an object in place
// and then putting it back into the cache breaks a CompactRangeIndex.
// @todo file a ticket on this issue
@Ignore
@Test
public void test002UpdateEntry() throws Exception {
IndexStatistics stats = index.getStatistics();
CacheUtils.log(((CompactRangeIndex) index).dump());
Portfolio p = (Portfolio) region.get("4");
p.status = "inactive";
region.put("4", p);
assertEquals(5, stats.getNumberOfValues());
// Set results = new HashSet();
// index.query("active", OQLLexerTokenTypes.TOK_EQ, results,new ExecutionContext(null,
// CacheUtils.getCache()));
SelectResults results = region.query("status = 'active'");
assertEquals(2, results.size());
}
Aggregations