Search in sources :

Example 16 with IndexStatistics

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();
}
Also used : IndexStatistics(org.apache.geode.cache.query.IndexStatistics) 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 17 with IndexStatistics

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

Example 18 with IndexStatistics

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());
}
Also used : IndexStatistics(org.apache.geode.cache.query.IndexStatistics) SelectResults(org.apache.geode.cache.query.SelectResults) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 19 with IndexStatistics

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);
}
Also used : IndexStatistics(org.apache.geode.cache.query.IndexStatistics) 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 20 with IndexStatistics

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

Aggregations

IndexStatistics (org.apache.geode.cache.query.IndexStatistics)31 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)24 Test (org.junit.Test)24 Portfolio (org.apache.geode.cache.query.data.Portfolio)23 Query (org.apache.geode.cache.query.Query)19 PartitionedIndex (org.apache.geode.cache.query.internal.index.PartitionedIndex)8 SelectResults (org.apache.geode.cache.query.SelectResults)6 BucketRegion (org.apache.geode.internal.cache.BucketRegion)4 Region (org.apache.geode.cache.Region)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Cache (org.apache.geode.cache.Cache)2 Index (org.apache.geode.cache.query.Index)2 InternalIndexStatistics (org.apache.geode.cache.query.internal.index.AbstractIndex.InternalIndexStatistics)2 File (java.io.File)1 Properties (java.util.Properties)1 QueryService (org.apache.geode.cache.query.QueryService)1 Numbers (org.apache.geode.cache.query.data.Numbers)1 DefaultQueryService (org.apache.geode.cache.query.internal.DefaultQueryService)1 DistributedSystem (org.apache.geode.distributed.DistributedSystem)1