Search in sources :

Example 1 with TestHook

use of org.apache.geode.cache.query.internal.index.IndexManager.TestHook in project geode by apache.

the class ConcurrentIndexInitOnOverflowRegionDUnitTest method testIndexUpdateWithRegionClear.

/**
   * This tests if index updates are blocked while region.clear() is called and indexes are being
   * reinitialized.
   */
@Test
public void testIndexUpdateWithRegionClear() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    final String regionName = "portfolio";
    hooked = false;
    // Create region and an index on it
    vm0.invoke(new CacheSerializableRunnable("Create region and index") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            Region region = cache.createRegionFactory(RegionShortcut.LOCAL).create(regionName);
            QueryService qService = cache.getQueryService();
            try {
                qService.createIndex("idIndex", "ID", "/" + regionName);
                qService.createIndex("secIdIndex", "pos.secId", "/" + regionName + " p, p.positions.values pos");
            } catch (Exception e) {
                fail("Index creation failed." + e);
            }
        }
    });
    class LocalTestHook implements TestHook {

        @Override
        public void hook(int spot) throws RuntimeException {
            switch(spot) {
                case // processAction in IndexManager
                6:
                    hooked = true;
                    // wait untill some thread unhooks.
                    while (hooked) {
                        Wait.pause(20);
                    }
                    break;
                default:
                    break;
            }
        }
    }
    // Asynch invocation for continuous index updates
    AsyncInvocation indexUpdateAsysnch = vm0.invokeAsync(new CacheSerializableRunnable("index updates") {

        @Override
        public void run2() throws CacheException {
            Region region = getCache().getRegion(regionName);
            for (int i = 0; i < 100; i++) {
                if (i == 50)
                    IndexManager.testHook = new LocalTestHook();
                region.put(i, new Portfolio(i));
                if (i == 50)
                    Wait.pause(20);
            }
        }
    });
    // Region.clear() which should block other region updates.
    vm0.invoke(new CacheSerializableRunnable("Clear the region") {

        @Override
        public void run2() throws CacheException {
            Region region = getCache().getRegion(regionName);
            while (!hooked) {
                Wait.pause(100);
            }
            if (hooked) {
                hooked = false;
                IndexManager.testHook = null;
                region.clear();
            }
            try {
                QueryService qservice = getCache().getQueryService();
                Index index = qservice.getIndex(region, "idIndex");
                if (((CompactRangeIndex) index).getIndexStorage().size() > 1) {
                    fail("After clear region size is supposed to be zero as all index updates are blocked. Current region size is: " + region.size());
                }
            } finally {
                IndexManager.testHook = null;
            }
        }
    });
    // Kill asynch thread
    ThreadUtils.join(indexUpdateAsysnch, 20000);
    // Verify region size which must be 50
    vm0.invoke(new CacheSerializableRunnable("Check region size") {

        @Override
        public void run2() throws CacheException {
            Region region = getCache().getRegion(regionName);
            if (region.size() > 50) {
                fail("After clear region size is supposed to be 50 as all index updates are blocked " + region.size());
            }
        }
    });
}
Also used : CacheException(org.apache.geode.cache.CacheException) Portfolio(org.apache.geode.cache.query.data.Portfolio) Host(org.apache.geode.test.dunit.Host) Index(org.apache.geode.cache.query.Index) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) TestHook(org.apache.geode.cache.query.internal.index.IndexManager.TestHook) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryService(org.apache.geode.cache.query.QueryService) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 2 with TestHook

use of org.apache.geode.cache.query.internal.index.IndexManager.TestHook in project geode by apache.

the class IndexUseJUnitTest method testSizeEstimateLTInCompactRangeIndexForNullMap.

@Test
public void testSizeEstimateLTInCompactRangeIndexForNullMap() 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 2", ((RangeIndexTestHook) hook).isHooked(2));
    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 3 with TestHook

use of org.apache.geode.cache.query.internal.index.IndexManager.TestHook 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 4 with TestHook

use of org.apache.geode.cache.query.internal.index.IndexManager.TestHook 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 5 with TestHook

use of org.apache.geode.cache.query.internal.index.IndexManager.TestHook in project geode by apache.

the class IndexUseJUnitTest method testSizeEstimateLTInRangeIndexForNullMap.

@Test
public void testSizeEstimateLTInRangeIndexForNullMap() 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 2", ((RangeIndexTestHook) hook).isHooked(2));
    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)

Aggregations

Index (org.apache.geode.cache.query.Index)5 QueryService (org.apache.geode.cache.query.QueryService)5 Portfolio (org.apache.geode.cache.query.data.Portfolio)5 TestHook (org.apache.geode.cache.query.internal.index.IndexManager.TestHook)5 Test (org.junit.Test)5 Query (org.apache.geode.cache.query.Query)4 SelectResults (org.apache.geode.cache.query.SelectResults)4 LocalRegion (org.apache.geode.internal.cache.LocalRegion)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 IOException (java.io.IOException)1 Cache (org.apache.geode.cache.Cache)1 CacheException (org.apache.geode.cache.CacheException)1 Region (org.apache.geode.cache.Region)1 ClientCache (org.apache.geode.cache.client.ClientCache)1 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)1 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)1 Host (org.apache.geode.test.dunit.Host)1 IgnoredException (org.apache.geode.test.dunit.IgnoredException)1 VM (org.apache.geode.test.dunit.VM)1 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)1