use of org.apache.geode.cache.query.internal.index.PartitionedIndex in project geode by apache.
the class PRIndexStatisticsJUnitTest 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;
createRegion();
assertEquals(0, region.size());
keyIndex3 = (IndexProtocol) qs.createIndex("multiKeyIndex6", IndexType.FUNCTIONAL, "positions['DELL', 'YHOO']", "/portfolio");
// 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 PartitionedIndex);
IndexStatistics keyIndexStats = keyIndex3.getStatistics();
assertTrue(keyIndexStats instanceof IndexStatistics);
assertEquals(89, keyIndexStats.getNumberOfBucketIndexes());
assertEquals(2, keyIndexStats.getNumberOfMapIndexKeys());
assertEquals(100, keyIndexStats.getNumberOfKeys());
assertEquals(100, keyIndexStats.getNumberOfValues());
assertEquals(100, keyIndexStats.getNumUpdates());
Position.cnt = 0;
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();
}
// Both RangeIndex should be used
assertEquals(100, /* Execution time */
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(300, 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(300, keyIndexStats.getNumUpdates());
for (int i = 50; i < 100; i++) {
region.destroy(Integer.toString(i));
}
assertEquals(2, keyIndexStats.getNumberOfMapIndexKeys());
assertEquals(400, keyIndexStats.getNumUpdates());
assertEquals(0, keyIndexStats.getNumberOfKeys());
qs.removeIndex(keyIndex3);
region.destroyRegion();
}
use of org.apache.geode.cache.query.internal.index.PartitionedIndex in project geode by apache.
the class PRIndexStatisticsJUnitTest method testStatsForMapRangeIndex.
/**
* Test MapRenageIndex IndexStatistics for keys, values, updates and uses.
*
* @throws Exception
*/
@Test
public void testStatsForMapRangeIndex() throws Exception {
IndexManager.TEST_RANGEINDEX_ONLY = true;
createAndPopulateRegion();
keyIndex3 = (IndexProtocol) qs.createIndex("multiKeyIndex3", IndexType.FUNCTIONAL, "positions['DELL', 'YHOO']", "/portfolio");
assertTrue(keyIndex3 instanceof PartitionedIndex);
IndexStatistics keyIndexStats = keyIndex3.getStatistics();
assertTrue(keyIndexStats instanceof IndexStatistics);
assertEquals(89, keyIndexStats.getNumberOfBucketIndexes());
assertEquals(89, keyIndexStats.getNumberOfBucketIndexes());
assertEquals(2, keyIndexStats.getNumberOfMapIndexKeys());
assertEquals(100, keyIndexStats.getNumberOfKeys());
assertEquals(100, keyIndexStats.getNumberOfValues());
assertEquals(100, keyIndexStats.getNumUpdates());
Position.cnt = 0;
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();
}
// Both RangeIndex should be used
assertEquals(100, /* Execution time */
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(300, 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(300, keyIndexStats.getNumUpdates());
for (int i = 50; i < 100; i++) {
region.destroy(Integer.toString(i));
}
assertEquals(400, keyIndexStats.getNumUpdates());
assertEquals(0, keyIndexStats.getNumberOfKeys());
assertEquals(2, keyIndexStats.getNumberOfMapIndexKeys());
qs.removeIndex(keyIndex3);
region.destroyRegion();
}
Aggregations