use of org.apache.geode.cache.query.IndexStatistics in project geode by apache.
the class IndexStatisticsJUnitTest method testStatsForMapRangeIndexBeforeRegionCreation.
/**
* Test MapRenageIndex IndexStatistics for keys, values, updates and uses.
*
* @throws Exception
*/
@Test
public void testStatsForMapRangeIndexBeforeRegionCreation() throws Exception {
// Destroy region
IndexManager.TEST_RANGEINDEX_ONLY = true;
region.clear();
assertEquals(0, region.size());
Position.cnt = 0;
keyIndex3 = (IndexProtocol) qs.createIndex("multiKeyIndex6", IndexType.FUNCTIONAL, "positions['DELL', 'YHOO']", "/portfolio");
Object[] indexes = ((MapRangeIndex) keyIndex3).getRangeIndexHolderForTesting().values().toArray();
assertEquals(indexes.length, 0);
// Recreate all entries in the region
Position.cnt = 0;
for (int i = 0; i < 100; i++) {
region.put(Integer.toString(i), new Portfolio(i, i));
}
assertTrue(keyIndex3 instanceof MapRangeIndex);
indexes = ((MapRangeIndex) keyIndex3).getRangeIndexHolderForTesting().values().toArray();
assertTrue(indexes[0] instanceof RangeIndex);
assertTrue(indexes[1] instanceof RangeIndex);
IndexStatistics keyIndex1Stats = ((RangeIndex) indexes[0]).getStatistics();
IndexStatistics keyIndex2Stats = ((RangeIndex) indexes[1]).getStatistics();
IndexStatistics mapIndexStats = keyIndex3.getStatistics();
assertEquals(100, mapIndexStats.getNumberOfKeys());
assertEquals(100, mapIndexStats.getNumberOfValues());
assertEquals(100, mapIndexStats.getNumUpdates());
Position.cnt = 0;
for (int i = 0; i < 100; i++) {
region.put(Integer.toString(i), new Portfolio(i, i));
}
assertEquals(100, mapIndexStats.getNumberOfKeys());
assertEquals(100, mapIndexStats.getNumberOfValues());
assertEquals(200, mapIndexStats.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(100, mapIndexStats.getTotalUses());
for (int i = 0; i < 50; i++) {
region.invalidate(Integer.toString(i));
}
assertEquals(50, mapIndexStats.getNumberOfKeys());
assertEquals(50, mapIndexStats.getNumberOfValues());
assertEquals(300, mapIndexStats.getNumUpdates());
for (int i = 0; i < 50; i++) {
region.destroy(Integer.toString(i));
}
assertEquals(50, mapIndexStats.getNumberOfKeys());
assertEquals(50, mapIndexStats.getNumberOfValues());
assertEquals(300, mapIndexStats.getNumUpdates());
for (int i = 50; i < 100; i++) {
region.destroy(Integer.toString(i));
}
assertEquals(400, mapIndexStats.getNumUpdates());
assertEquals(0, mapIndexStats.getNumberOfKeys());
qs.removeIndex(keyIndex3);
}
use of org.apache.geode.cache.query.IndexStatistics in project geode by apache.
the class IndexStatisticsJUnitTest method testStatsForMapRangeIndex.
/**
* Test MapRenageIndex IndexStatistics for keys, values, updates and uses.
*
* @throws Exception
*/
@Test
public void testStatsForMapRangeIndex() throws Exception {
IndexManager.TEST_RANGEINDEX_ONLY = true;
keyIndex3 = (IndexProtocol) qs.createIndex("multiKeyIndex3", IndexType.FUNCTIONAL, "positions['DELL', 'YHOO']", "/portfolio");
assertTrue(keyIndex3 instanceof MapRangeIndex);
Object[] indexes = ((MapRangeIndex) keyIndex3).getRangeIndexHolderForTesting().values().toArray();
assertTrue(indexes[0] instanceof RangeIndex);
assertTrue(indexes[1] instanceof RangeIndex);
IndexStatistics mapIndexStats = keyIndex3.getStatistics();
assertEquals(2, mapIndexStats.getNumberOfMapIndexKeys());
assertEquals(100, mapIndexStats.getNumberOfKeys());
assertEquals(100, mapIndexStats.getNumberOfValues());
assertEquals(100, mapIndexStats.getNumUpdates());
Position.cnt = 0;
for (int i = 0; i < 100; i++) {
region.put(Integer.toString(i), new Portfolio(i, i));
}
assertEquals(2, mapIndexStats.getNumberOfMapIndexKeys());
assertEquals(100, mapIndexStats.getNumberOfKeys());
assertEquals(100, mapIndexStats.getNumberOfValues());
assertEquals(200, mapIndexStats.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, mapIndexStats.getReadLockCount());
assertEquals(100, mapIndexStats.getTotalUses());
for (int i = 0; i < 50; i++) {
region.invalidate(Integer.toString(i));
}
assertEquals(2, mapIndexStats.getNumberOfMapIndexKeys());
assertEquals(50, mapIndexStats.getNumberOfKeys());
assertEquals(50, mapIndexStats.getNumberOfValues());
assertEquals(300, mapIndexStats.getNumUpdates());
for (int i = 0; i < 50; i++) {
region.destroy(Integer.toString(i));
}
assertEquals(2, mapIndexStats.getNumberOfMapIndexKeys());
assertEquals(50, mapIndexStats.getNumberOfKeys());
assertEquals(50, mapIndexStats.getNumberOfValues());
assertEquals(300, mapIndexStats.getNumUpdates());
for (int i = 50; i < 100; i++) {
region.destroy(Integer.toString(i));
}
assertEquals(400, mapIndexStats.getNumUpdates());
assertEquals(2, mapIndexStats.getNumberOfMapIndexKeys());
assertEquals(0, mapIndexStats.getNumberOfKeys());
qs.removeIndex(keyIndex3);
}
use of org.apache.geode.cache.query.IndexStatistics in project geode by apache.
the class IndexStatisticsJUnitTest method testCompactRangeIndexNumKeysStats.
@Test
public void testCompactRangeIndexNumKeysStats() throws Exception {
String regionName = "testCompactRegionIndexNumKeysStats_region";
Region region = CacheUtils.createRegion(regionName, Numbers.class);
Index index = qs.createIndex("idIndexName", "r.max1", "/" + regionName + " r");
IndexStatistics stats = index.getStatistics();
// Add an object and check stats
Numbers obj1 = new Numbers(1);
obj1.max1 = 20;
region.put(1, obj1);
assertEquals(1, stats.getNumberOfValues());
assertEquals(1, stats.getNumberOfKeys());
// assertIndexDetailsEquals(1, stats.getNumberOfValues(20f));
assertEquals(1, stats.getNumUpdates());
// add a second object with the same index key
Numbers obj2 = new Numbers(1);
obj2.max1 = 20;
region.put(2, obj2);
assertEquals(2, stats.getNumberOfValues());
assertEquals(1, stats.getNumberOfKeys());
// assertIndexDetailsEquals(2, stats.getNumberOfValues(20f));
assertEquals(2, stats.getNumUpdates());
// remove the second object and check that keys are 1
region.remove(2);
assertEquals(1, stats.getNumberOfValues());
assertEquals(1, stats.getNumberOfKeys());
// assertIndexDetailsEquals(1, stats.getNumberOfValues(20f));
assertEquals(3, stats.getNumUpdates());
// remove the first object and check that keys are 0
region.remove(1);
assertEquals(0, stats.getNumberOfValues());
assertEquals(0, stats.getNumberOfKeys());
// assertIndexDetailsEquals(0, stats.getNumberOfValues(20f));
assertEquals(4, stats.getNumUpdates());
// add object with a different key and check results
obj2.max1 = 21;
region.put(3, obj2);
assertEquals(1, stats.getNumberOfValues());
assertEquals(1, stats.getNumberOfKeys());
// assertIndexDetailsEquals(0, stats.getNumberOfValues(20f));
assertEquals(5, stats.getNumUpdates());
// add object with original key and check that num keys are 2
obj1.max1 = 20;
region.put(1, obj1);
assertEquals(2, stats.getNumberOfValues());
assertEquals(2, stats.getNumberOfKeys());
// assertIndexDetailsEquals(1, stats.getNumberOfValues(20f));
assertEquals(6, stats.getNumUpdates());
}
use of org.apache.geode.cache.query.IndexStatistics in project geode by apache.
the class IndexStatisticsJUnitTest method testStatsForCompactRangeIndex.
/**
* Test CompactRenageIndex IndexStatistics for keys, values, updates and uses.
*
* @throws Exception
*/
@Test
public void testStatsForCompactRangeIndex() throws Exception {
keyIndex2 = (IndexProtocol) qs.createIndex("multiKeyIndex2", IndexType.FUNCTIONAL, "ID", "/portfolio ");
assertTrue(keyIndex2 instanceof CompactRangeIndex);
IndexStatistics keyIndex1Stats = keyIndex2.getStatistics();
// Initial stats test (keys, values & updates)
assertEquals(100, keyIndex1Stats.getNumberOfKeys());
assertEquals(100, keyIndex1Stats.getNumberOfValues());
assertEquals(100, keyIndex1Stats.getNumUpdates());
for (int i = 0; i < 100; i++) {
region.put(Integer.toString(i), new Portfolio(i, i));
}
assertEquals(100, keyIndex1Stats.getNumberOfKeys());
assertEquals(100, keyIndex1Stats.getNumberOfValues());
assertEquals(200, keyIndex1Stats.getNumUpdates());
// IndexUsed stats test
String queryStr = "select * from /portfolio where ID > 0";
Query query = qs.newQuery(queryStr);
for (int i = 0; i < 50; i++) {
query.execute();
}
assertEquals(0, keyIndex1Stats.getReadLockCount());
assertEquals(50, keyIndex1Stats.getTotalUses());
// NumOfValues should be reduced.
for (int i = 0; i < 50; i++) {
region.invalidate(Integer.toString(i));
}
assertEquals(50, keyIndex1Stats.getNumberOfKeys());
assertEquals(50, keyIndex1Stats.getNumberOfValues());
assertEquals(250, keyIndex1Stats.getNumUpdates());
for (int i = 0; i < 50; i++) {
region.destroy(Integer.toString(i));
}
assertEquals(50, keyIndex1Stats.getNumberOfKeys());
assertEquals(50, keyIndex1Stats.getNumberOfValues());
assertEquals(250, keyIndex1Stats.getNumUpdates());
// NumOfKeys should get zero as all values are destroyed
for (int i = 50; i < 100; i++) {
region.destroy(Integer.toString(i));
}
assertEquals(300, keyIndex1Stats.getNumUpdates());
assertEquals(0, keyIndex1Stats.getNumberOfKeys());
qs.removeIndex(keyIndex2);
}
use of org.apache.geode.cache.query.IndexStatistics in project geode by apache.
the class IndexStatisticsJUnitTest method testStatsForCompactRangeIndexBeforeRegionCreation.
/**
* Test CompactRenageIndex IndexStatistics for keys, values, updates and uses.
*
* @throws Exception
*/
@Test
public void testStatsForCompactRangeIndexBeforeRegionCreation() throws Exception {
// Destroy region
region.clear();
assertEquals(0, region.size());
Position.cnt = 0;
keyIndex2 = (IndexProtocol) qs.createIndex("multiKeyIndex5", IndexType.FUNCTIONAL, "ID", "/portfolio ");
// Recreate all entries in the region
for (int i = 0; i < 100; i++) {
region.put(Integer.toString(i), new Portfolio(i, i));
}
assertTrue(keyIndex2 instanceof CompactRangeIndex);
IndexStatistics keyIndex1Stats = keyIndex2.getStatistics();
// Initial stats test (keys, values & updates)
assertEquals(100, keyIndex1Stats.getNumberOfKeys());
assertEquals(100, keyIndex1Stats.getNumberOfValues());
assertEquals(100, keyIndex1Stats.getNumUpdates());
for (int i = 0; i < 100; i++) {
region.put(Integer.toString(i), new Portfolio(i, i));
}
assertEquals(100, keyIndex1Stats.getNumberOfKeys());
assertEquals(100, keyIndex1Stats.getNumberOfValues());
assertEquals(200, keyIndex1Stats.getNumUpdates());
// IndexUsed stats test
String queryStr = "select * from /portfolio where ID > 0";
Query query = qs.newQuery(queryStr);
for (int i = 0; i < 50; i++) {
query.execute();
}
assertEquals(50, keyIndex1Stats.getTotalUses());
// NumOfValues should be reduced.
for (int i = 0; i < 50; i++) {
region.invalidate(Integer.toString(i));
}
assertEquals(50, keyIndex1Stats.getNumberOfKeys());
assertEquals(50, keyIndex1Stats.getNumberOfValues());
assertEquals(250, keyIndex1Stats.getNumUpdates());
for (int i = 0; i < 50; i++) {
region.destroy(Integer.toString(i));
}
assertEquals(50, keyIndex1Stats.getNumberOfKeys());
assertEquals(50, keyIndex1Stats.getNumberOfValues());
assertEquals(250, keyIndex1Stats.getNumUpdates());
// NumOfKeys should get zero as all values are destroyed
for (int i = 50; i < 100; i++) {
region.destroy(Integer.toString(i));
}
assertEquals(300, keyIndex1Stats.getNumUpdates());
assertEquals(0, keyIndex1Stats.getNumberOfKeys());
qs.removeIndex(keyIndex2);
}
Aggregations