Search in sources :

Example 6 with IndexTrackingQueryObserver

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);
}
Also used : IndexTrackingQueryObserver(org.apache.geode.cache.query.internal.IndexTrackingQueryObserver) QueryObserver(org.apache.geode.cache.query.internal.QueryObserver) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) IndexTrackingQueryObserver(org.apache.geode.cache.query.internal.IndexTrackingQueryObserver)

Example 7 with IndexTrackingQueryObserver

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);
}
Also used : IndexTrackingQueryObserver(org.apache.geode.cache.query.internal.IndexTrackingQueryObserver) QueryObserver(org.apache.geode.cache.query.internal.QueryObserver) QueryService(org.apache.geode.cache.query.QueryService) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Index(org.apache.geode.cache.query.Index) IndexTrackingQueryObserver(org.apache.geode.cache.query.internal.IndexTrackingQueryObserver)

Example 8 with IndexTrackingQueryObserver

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;
}
Also used : IndexTrackingQueryObserver(org.apache.geode.cache.query.internal.IndexTrackingQueryObserver) QueryObserver(org.apache.geode.cache.query.internal.QueryObserver) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) IndexInfo(org.apache.geode.cache.query.internal.IndexTrackingQueryObserver.IndexInfo) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation)

Aggregations

IndexTrackingQueryObserver (org.apache.geode.cache.query.internal.IndexTrackingQueryObserver)8 QueryObserver (org.apache.geode.cache.query.internal.QueryObserver)7 AttributesFactory (org.apache.geode.cache.AttributesFactory)3 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)3 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)3 Iterator (java.util.Iterator)2 Map (java.util.Map)2 Region (org.apache.geode.cache.Region)2 Portfolio (org.apache.geode.cache.query.data.Portfolio)2 IndexTrackingTestHook (org.apache.geode.cache.query.internal.index.IndexTrackingQueryObserverDUnitTest.IndexTrackingTestHook)2 LocalRegion (org.apache.geode.internal.cache.LocalRegion)2 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Index (org.apache.geode.cache.query.Index)1 QueryExecutionLowMemoryException (org.apache.geode.cache.query.QueryExecutionLowMemoryException)1 QueryService (org.apache.geode.cache.query.QueryService)1 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)1