Search in sources :

Example 56 with LocalRegion

use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.

the class IndexUseJUnitTest method testIndexUsageWithOrderBy3.

@Test
public void testIndexUsageWithOrderBy3() throws Exception {
    QueryService qs;
    qs = CacheUtils.getQueryService();
    LocalRegion testRgn = (LocalRegion) CacheUtils.createRegion("testRgn", null);
    int numObjects = 30;
    // and so on
    for (int i = 0; i < numObjects; i++) {
        Portfolio p = new Portfolio(i);
        p.pkid = ("" + (numObjects - i));
        testRgn.put("" + i, p);
    }
    qs = CacheUtils.getQueryService();
    String[] queries = { "SELECT DISTINCT * FROM /testRgn p  WHERE p.ID <= 10 order by ID asc limit 1", "SELECT DISTINCT * FROM /testRgn p  WHERE p.ID <= 10 order by p.ID desc limit 1" };
    Object[][] r = new Object[queries.length][2];
    Index i1 = qs.createIndex("Index1", IndexType.FUNCTIONAL, "p.ID", "/testRgn p");
    // Execute Queries with Indexes
    for (int i = 0; i < queries.length; i++) {
        Query q = null;
        try {
            q = CacheUtils.getQueryService().newQuery(queries[i]);
            CacheUtils.getLogger().info("Executing query: " + queries[i]);
            QueryObserverImpl observer = new QueryObserverImpl();
            QueryObserverHolder.setInstance(observer);
            SelectResults sr = (SelectResults) q.execute();
            List results = sr.asList();
            for (int rows = 0; rows < results.size(); rows++) {
                Portfolio p = (Portfolio) results.get(0);
                CacheUtils.getLogger().info("index p: " + p);
                if (i == 0) {
                    assertEquals(p.getID(), 0);
                } else if (i == 1) {
                    assertEquals(p.getID(), 10);
                }
            }
            r[i][1] = sr;
            // r[i][1] = q.execute();
            CacheUtils.log("Executing query: " + queries[i] + " with index created");
            if (!observer.isIndexesUsed) {
                fail("Index is NOT uesd");
            }
            Iterator itr = observer.indexesUsed.iterator();
            assertTrue(itr.hasNext());
            String temp = itr.next().toString();
            assertEquals(temp, "Index1");
        } catch (Exception e) {
            e.printStackTrace();
            fail(q.getQueryString());
        }
    }
}
Also used : Query(org.apache.geode.cache.query.Query) Portfolio(org.apache.geode.cache.query.data.Portfolio) Index(org.apache.geode.cache.query.Index) LocalRegion(org.apache.geode.internal.cache.LocalRegion) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) SelectResults(org.apache.geode.cache.query.SelectResults) QueryService(org.apache.geode.cache.query.QueryService) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 57 with LocalRegion

use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.

the class IndexUseJUnitTest method testSizeEstimateGTInRangeIndexForNullMap.

@Test
public void testSizeEstimateGTInRangeIndexForNullMap() throws Exception {
    QueryService qs = CacheUtils.getQueryService();
    LocalRegion testRgn = (LocalRegion) CacheUtils.createRegion("testRgn", null);
    // Create indexes
    Index i1 = qs.createIndex("Index1", IndexType.FUNCTIONAL, "p.status", "/testRgn p, p.positions");
    Index i2 = qs.createIndex("Index2", IndexType.FUNCTIONAL, "p.ID", "/testRgn p, p.positions");
    // put values
    testRgn.put(0, new Portfolio(0));
    testRgn.put(1, new Portfolio(1));
    // Set TestHook in RangeIndex
    TestHook hook = new RangeIndexTestHook();
    RangeIndex.setTestHook(hook);
    // Execute Queries without Indexes
    Query q = CacheUtils.getQueryService().newQuery("<trace> SELECT * FROM /testRgn p, p.positions where p.status = 'active' AND p.ID < 0 ");
    // Following should throw NullPointerException.
    SelectResults sr = (SelectResults) q.execute();
    assertTrue("RangeIndexTestHook was not hooked for spot 1", ((RangeIndexTestHook) hook).isHooked(1));
    RangeIndex.setTestHook(null);
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) Query(org.apache.geode.cache.query.Query) QueryService(org.apache.geode.cache.query.QueryService) Portfolio(org.apache.geode.cache.query.data.Portfolio) Index(org.apache.geode.cache.query.Index) LocalRegion(org.apache.geode.internal.cache.LocalRegion) TestHook(org.apache.geode.cache.query.internal.index.IndexManager.TestHook) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 58 with LocalRegion

use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.

the class IndexUseJUnitTest method testMapIndexUsableQueryOnEmptyRegion.

@Test
public void testMapIndexUsableQueryOnEmptyRegion() throws Exception {
    IndexManager.TEST_RANGEINDEX_ONLY = true;
    QueryService qs;
    qs = CacheUtils.getQueryService();
    LocalRegion testRgn = (LocalRegion) CacheUtils.createRegion("testRgn", null);
    Index i1 = qs.createIndex("Index1", IndexType.FUNCTIONAL, "objs.maap['key2','key3']", "/testRgn objs");
    qs = CacheUtils.getQueryService();
    // Execute Queries without Indexes
    Query q = CacheUtils.getQueryService().newQuery("SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.maap['key2'] >= 3 ");
    SelectResults sr = (SelectResults) q.execute();
    assertTrue(sr.isEmpty());
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) Query(org.apache.geode.cache.query.Query) QueryService(org.apache.geode.cache.query.QueryService) Index(org.apache.geode.cache.query.Index) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 59 with LocalRegion

use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.

the class IndexUseJUnitTest method testSizeEstimateGTInCompactRangeIndexForNullMap.

@Test
public void testSizeEstimateGTInCompactRangeIndexForNullMap() throws Exception {
    QueryService qs = CacheUtils.getQueryService();
    LocalRegion testRgn = (LocalRegion) CacheUtils.createRegion("testRgn", null);
    // Create indexes
    Index i1 = qs.createIndex("Index1", IndexType.FUNCTIONAL, "p.status", "/testRgn p");
    Index i2 = qs.createIndex("Index2", IndexType.FUNCTIONAL, "p.ID", "/testRgn p");
    // put values
    testRgn.put(0, new Portfolio(0));
    testRgn.put(1, new Portfolio(1));
    // Set TestHook in RangeIndex
    TestHook hook = new RangeIndexTestHook();
    CompactRangeIndex.setTestHook(hook);
    // Execute Queries without Indexes
    Query q = CacheUtils.getQueryService().newQuery("<trace> SELECT * FROM /testRgn p where p.status = 'active' AND p.ID < 0 ");
    // Following should throw NullPointerException.
    SelectResults sr = (SelectResults) q.execute();
    assertTrue("RangeIndexTestHook was not hooked for spot 1", ((RangeIndexTestHook) hook).isHooked(1));
    CompactRangeIndex.setTestHook(null);
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) Query(org.apache.geode.cache.query.Query) QueryService(org.apache.geode.cache.query.QueryService) Portfolio(org.apache.geode.cache.query.data.Portfolio) Index(org.apache.geode.cache.query.Index) LocalRegion(org.apache.geode.internal.cache.LocalRegion) TestHook(org.apache.geode.cache.query.internal.index.IndexManager.TestHook) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 60 with LocalRegion

use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.

the class MultiVMRegionTestCase method getEntryExpiryTask.

private static EntryExpiryTask getEntryExpiryTask(Region r, Object key) {
    EntryExpiryTask result = null;
    try {
        LocalRegion lr = (LocalRegion) r;
        result = lr.getEntryExpiryTask(key);
    } catch (EntryNotFoundException ignore) {
    }
    return result;
}
Also used : EntryExpiryTask(org.apache.geode.internal.cache.EntryExpiryTask) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) LocalRegion(org.apache.geode.internal.cache.LocalRegion)

Aggregations

LocalRegion (org.apache.geode.internal.cache.LocalRegion)243 Test (org.junit.Test)103 Region (org.apache.geode.cache.Region)70 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)54 IOException (java.io.IOException)50 AttributesFactory (org.apache.geode.cache.AttributesFactory)42 VM (org.apache.geode.test.dunit.VM)39 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)38 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)37 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)34 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)34 Cache (org.apache.geode.cache.Cache)31 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)31 Host (org.apache.geode.test.dunit.Host)31 Iterator (java.util.Iterator)29 QueryService (org.apache.geode.cache.query.QueryService)29 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)27 CancelException (org.apache.geode.CancelException)26 CacheException (org.apache.geode.cache.CacheException)26 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)25