Search in sources :

Example 31 with PartitionedIndex

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();
}
Also used : IndexStatistics(org.apache.geode.cache.query.IndexStatistics) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) Query(org.apache.geode.cache.query.Query) Portfolio(org.apache.geode.cache.query.data.Portfolio) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 32 with PartitionedIndex

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();
}
Also used : IndexStatistics(org.apache.geode.cache.query.IndexStatistics) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) Query(org.apache.geode.cache.query.Query) Portfolio(org.apache.geode.cache.query.data.Portfolio) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

PartitionedIndex (org.apache.geode.cache.query.internal.index.PartitionedIndex)32 Index (org.apache.geode.cache.query.Index)17 Query (org.apache.geode.cache.query.Query)17 Test (org.junit.Test)17 Portfolio (org.apache.geode.cache.query.data.Portfolio)15 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)13 SelectResults (org.apache.geode.cache.query.SelectResults)9 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)9 AttributesFactory (org.apache.geode.cache.AttributesFactory)8 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)8 IndexStatistics (org.apache.geode.cache.query.IndexStatistics)8 AbstractIndex (org.apache.geode.cache.query.internal.index.AbstractIndex)8 CacheException (org.apache.geode.cache.CacheException)7 QueryService (org.apache.geode.cache.query.QueryService)7 IOException (java.io.IOException)6 Region (org.apache.geode.cache.Region)6 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)6 Iterator (java.util.Iterator)5 LogWriter (org.apache.geode.LogWriter)5 Cache (org.apache.geode.cache.Cache)5