use of org.apache.geode.cache.query.internal.index.IndexTrackingQueryObserverDUnitTest.IndexTrackingTestHook in project geode by apache.
the class IndexTrackingQueryObserverJUnitTest method testIndexInfoOnPartitionedRegion.
@Test
public void testIndexInfoOnPartitionedRegion() throws Exception {
// Query VERBOSE has to be true for the test
assertEquals("true", System.getProperty(DistributionConfig.GEMFIRE_PREFIX + "Query.VERBOSE"));
// Create Partition Region
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setTotalNumBuckets(NUM_BKTS);
AttributesFactory af = new AttributesFactory();
af.setPartitionAttributes(paf.create());
region = CacheUtils.createRegion("portfolio", af.create(), false);
if (region.size() == 0) {
for (int i = 1; i <= 100; i++) {
region.put(Integer.toString(i), new Portfolio(i, i));
}
}
assertEquals(100, region.size());
qs = CacheUtils.getQueryService();
keyIndex1 = (IndexProtocol) qs.createIndex(INDEX_NAME, IndexType.FUNCTIONAL, "ID", "/portfolio ");
assertTrue(keyIndex1 instanceof PartitionedIndex);
Query query = qs.newQuery(queryStr);
// Inject TestHook in QueryObserver before running query.
IndexTrackingTestHook th = new IndexTrackingTestHook(region, NUM_BKTS);
QueryObserver observer = QueryObserverHolder.getInstance();
assertTrue(QueryObserverHolder.hasObserver());
((IndexTrackingQueryObserver) observer).setTestHook(th);
SelectResults results = (SelectResults) query.execute();
// The query should return all elements in region.
assertEquals(region.size(), results.size());
// Check results size of Map.
regionMap = ((IndexTrackingTestHook) th).getRegionMap();
Collection<Integer> rslts = regionMap.getResults().values();
int totalResults = 0;
for (Integer i : rslts) {
totalResults += i.intValue();
}
assertEquals(results.size(), totalResults);
QueryObserverHolder.reset();
}
use of org.apache.geode.cache.query.internal.index.IndexTrackingQueryObserverDUnitTest.IndexTrackingTestHook in project geode by apache.
the class IndexTrackingQueryObserverJUnitTest method testIndexInfoOnLocalRegion.
@Test
public void testIndexInfoOnLocalRegion() throws Exception {
// Query VERBOSE has to be true for the test
assertEquals("true", System.getProperty(DistributionConfig.GEMFIRE_PREFIX + "Query.VERBOSE"));
// Create Partition Region
AttributesFactory af = new AttributesFactory();
af.setScope(Scope.LOCAL);
region = CacheUtils.createRegion("portfolio", af.create(), false);
if (region.size() == 0) {
for (int i = 1; i <= 100; i++) {
region.put(Integer.toString(i), new Portfolio(i, i));
}
}
assertEquals(100, region.size());
qs = CacheUtils.getQueryService();
keyIndex1 = (IndexProtocol) qs.createIndex(INDEX_NAME, IndexType.FUNCTIONAL, "ID", "/portfolio ");
assertTrue(keyIndex1 instanceof CompactRangeIndex);
Query query = qs.newQuery(queryStr);
// Inject TestHook in QueryObserver before running query.
IndexTrackingTestHook th = new IndexTrackingTestHook(region, 0);
QueryObserver observer = QueryObserverHolder.getInstance();
assertTrue(QueryObserverHolder.hasObserver());
((IndexTrackingQueryObserver) observer).setTestHook(th);
SelectResults results = (SelectResults) query.execute();
// The query should return all elements in region.
assertEquals(region.size(), results.size());
regionMap = ((IndexTrackingTestHook) th).getRegionMap();
Object rslts = regionMap.getResults().get(region.getFullPath());
assertTrue(rslts instanceof Integer);
assertEquals(results.size(), ((Integer) rslts).intValue());
}
Aggregations