use of org.apache.geode.cache.query.internal.IndexTrackingQueryObserver in project geode by apache.
the class IndexTrackingQueryObserverDUnitTest method createPR.
/**
* CReates a PR on a VM with NUM_BKTS buckets.
*
* @param vm
*/
private void createPR(VM vm) {
SerializableRunnable createDS = new SerializableRunnable("Creating PR Datastore") {
public void run() {
QueryObserver observer = QueryObserverHolder.setInstance(new IndexTrackingQueryObserver());
// Create Partition Region
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setTotalNumBuckets(NUM_BKTS);
AttributesFactory af = new AttributesFactory();
af.setPartitionAttributes(paf.create());
Region region = getCache().createRegion("portfolio", af.create());
}
};
vm.invoke(createDS);
}
use of org.apache.geode.cache.query.internal.IndexTrackingQueryObserver in project geode by apache.
the class IndexTrackingQueryObserverDUnitTest method createQueryIndex.
private void createQueryIndex(VM vm, final boolean create) {
SerializableRunnable createIndex = new SerializableRunnable("Create index on PR") {
public void run() {
// Query VERBOSE has to be true for the test
assertTrue(DefaultQuery.QUERY_VERBOSE);
QueryService qs = getCache().getQueryService();
Index keyIndex1 = null;
try {
if (create) {
keyIndex1 = (IndexProtocol) qs.createIndex(INDEX_NAME, IndexType.FUNCTIONAL, "ID", "/portfolio ");
assertNotNull(keyIndex1);
assertTrue(keyIndex1 instanceof PartitionedIndex);
}
} catch (Exception e) {
Assert.fail("While creating Index on PR", e);
}
Region region = getCache().getRegion("portfolio");
// Inject TestHook in QueryObserver before running query.
IndexTrackingTestHook th = new IndexTrackingTestHook(region, NUM_BKTS / 2);
QueryObserver observer = QueryObserverHolder.getInstance();
assertTrue(QueryObserverHolder.hasObserver());
((IndexTrackingQueryObserver) observer).setTestHook(th);
}
};
vm.invoke(createIndex);
}
use of org.apache.geode.cache.query.internal.IndexTrackingQueryObserver in project geode by apache.
the class IndexTrackingQueryObserverDUnitTest method verifyQueryVerboseData.
private AsyncInvocation verifyQueryVerboseData(VM vm, final int results) {
SerializableRunnable testQueryVerbose = new SerializableRunnable("Test Query Verbose Data") {
public void run() {
// Query VERBOSE has to be true for the test
assertTrue(DefaultQuery.QUERY_VERBOSE);
// Get TestHook from observer.
QueryObserver observer = QueryObserverHolder.getInstance();
assertTrue(QueryObserverHolder.hasObserver());
final IndexTrackingTestHook th = (IndexTrackingTestHook) ((IndexTrackingQueryObserver) observer).getTestHook();
Wait.waitForCriterion(new WaitCriterion() {
public boolean done() {
if (th.getRegionMap() != null) {
return th.getRegionMap().getResults() != null;
}
return false;
}
public String description() {
return null;
}
}, 60 * 1000, 200, true);
IndexInfo regionMap = th.getRegionMap();
Collection<Integer> rslts = regionMap.getResults().values();
int totalResults = 0;
for (Integer i : rslts) {
totalResults += i.intValue();
}
LogWriterUtils.getLogWriter().fine("Index Info result size is " + totalResults);
assertEquals(results, totalResults);
}
};
AsyncInvocation asyncInv = vm.invokeAsync(testQueryVerbose);
return asyncInv;
}
Aggregations