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