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());
}
}
});
}
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);
}
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);
}
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);
}
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);
}
Aggregations