Search in sources :

Example 6 with PartitionedIndex

use of org.apache.geode.cache.query.internal.index.PartitionedIndex in project geode by apache.

the class PRQueryDUnitHelper method getCacheSerializableRunnableForPRIndexCreate.

/**
   * This function creates a appropriate index on a PR given the name and other parameters.
   */
public CacheSerializableRunnable getCacheSerializableRunnableForPRIndexCreate(final String prRegionName, final String indexName, final String indexedExpression, final String fromClause, final String alias) {
    SerializableRunnable prIndexCreator = new CacheSerializableRunnable("PartitionedIndexCreator") {

        @Override
        public void run2() {
            try {
                Cache cache = getCache();
                QueryService qs = cache.getQueryService();
                Region region = cache.getRegion(prRegionName);
                LogWriter logger = cache.getLogger();
                if (null != fromClause) {
                    logger.info("Test Creating index with Name : [ " + indexName + " ] " + "IndexedExpression : [ " + indexedExpression + " ] Alias : [ " + alias + " ] FromClause : [ " + fromClause + " " + alias + " ] ");
                    Index parIndex = qs.createIndex(indexName, IndexType.FUNCTIONAL, indexedExpression, fromClause);
                    logger.info("Index creted on partitioned region : " + parIndex);
                } else {
                    logger.info("Test Creating index with Name : [ " + indexName + " ] " + "IndexedExpression : [ " + indexedExpression + " ] Alias : [ " + alias + " ] FromClause : [ " + region.getFullPath() + " " + alias + " ] ");
                    Index parIndex = qs.createIndex(indexName, IndexType.FUNCTIONAL, indexedExpression, region.getFullPath() + " " + alias);
                    logger.info("Index creted on partitioned region : " + parIndex);
                    logger.info("Number of buckets indexed in the partitioned region locally : " + "" + ((PartitionedIndex) parIndex).getNumberOfIndexedBuckets() + " and remote buckets indexed : " + ((PartitionedIndex) parIndex).getNumRemoteBucketsIndexed());
                }
            /*
           * assertIndexDetailsEquals("Max num of buckets in the partiotion regions and the
           * " + "buckets indexed should be equal",
           * ((PartitionedRegion)region).getTotalNumberOfBuckets(),
           * (((PartionedIndex)parIndex).getNumberOfIndexedBucket()+((PartionedIndex)parIndex).
           * getNumRemtoeBucketsIndexed())); should put all the assetion in a seperate function.
           */
            } catch (Exception ex) {
                Assert.fail("Creating Index in this vm failed : ", ex);
            }
        }
    };
    return (CacheSerializableRunnable) prIndexCreator;
}
Also used : PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryService(org.apache.geode.cache.query.QueryService) LogWriter(org.apache.geode.LogWriter) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) Index(org.apache.geode.cache.query.Index) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryExistsException(org.apache.geode.cache.EntryExistsException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) CancelException(org.apache.geode.CancelException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) TestException(util.TestException) CacheException(org.apache.geode.cache.CacheException) ReplyException(org.apache.geode.distributed.internal.ReplyException) QueryException(org.apache.geode.cache.query.QueryException) IndexNameConflictException(org.apache.geode.cache.query.IndexNameConflictException) IndexExistsException(org.apache.geode.cache.query.IndexExistsException) Cache(org.apache.geode.cache.Cache)

Example 7 with PartitionedIndex

use of org.apache.geode.cache.query.internal.index.PartitionedIndex in project geode by apache.

the class PdxOrderByJUnitTest method testPartitionRangeIndex.

@Test
public void testPartitionRangeIndex() throws Exception {
    final int numberOfEntries = 10;
    Region pr = this.configurePR();
    // create a local query service
    QueryService localQueryService = null;
    try {
        localQueryService = CacheUtils.getQueryService();
    } catch (Exception e) {
        fail(e.toString());
    }
    for (int i = 0; i < numberOfEntries; i++) {
        pr.put("key-" + i, new PortfolioPdx(i));
    }
    localQueryService = CacheUtils.getCache().getQueryService();
    SelectResults[][] rs = new SelectResults[queryString.length][2];
    for (int i = 0; i < queryString.length; i++) {
        try {
            Query query = localQueryService.newQuery(queryString[i]);
            rs[i][0] = (SelectResults) query.execute();
            checkForPdxString(rs[i][0].asList(), queryString[i]);
        } catch (Exception e) {
            fail("Failed executing " + queryString[i]);
        }
    }
    Index index = null;
    try {
        index = localQueryService.createIndex("secIdIndex", "pos.secId", regName + " p, p.positions.values pos");
        if (index instanceof PartitionedIndex) {
            for (Object o : ((PartitionedIndex) index).getBucketIndexes()) {
                if (!(o instanceof RangeIndex)) {
                    fail("Range Index should have been created instead of " + index.getClass());
                }
            }
        } else {
            fail("Partitioned index expected");
        }
    } catch (Exception ex) {
        fail("Failed to create index." + ex.getMessage());
    }
    for (int i = 0; i < queryString.length; i++) {
        try {
            Query query = localQueryService.newQuery(queryString[i]);
            rs[i][1] = (SelectResults) query.execute();
            checkForPdxString(rs[i][1].asList(), queryString[i]);
        } catch (Exception e) {
            fail("Failed executing " + queryString[i]);
        }
    }
    for (int i = 0; i < queryString.length; i++) {
        try {
            if (i < 7) {
                // Compare local and remote query results.
                if (!compareResultsOfWithAndWithoutIndex(rs[i])) {
                    fail("Local and Remote Query Results are not matching for query :" + queryString[i]);
                }
            } else {
                // compare the order of results returned
                compareResultsOrder(rs[i], true);
            }
        } catch (Exception e) {
            fail("Failed executing " + queryString[i]);
        }
    }
}
Also used : PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) SelectResults(org.apache.geode.cache.query.SelectResults) Query(org.apache.geode.cache.query.Query) QueryService(org.apache.geode.cache.query.QueryService) Region(org.apache.geode.cache.Region) PortfolioPdx(org.apache.geode.cache.query.data.PortfolioPdx) Index(org.apache.geode.cache.query.Index) RangeIndex(org.apache.geode.cache.query.internal.index.RangeIndex) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) RangeIndex(org.apache.geode.cache.query.internal.index.RangeIndex) RegionExistsException(org.apache.geode.cache.RegionExistsException) TimeoutException(org.apache.geode.cache.TimeoutException) CacheException(org.apache.geode.cache.CacheException) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 8 with PartitionedIndex

use of org.apache.geode.cache.query.internal.index.PartitionedIndex in project geode by apache.

the class PdxStringQueryDUnitTest method testPartitionRegionCompactRangeIndex.

@Test
public void testPartitionRegionCompactRangeIndex() throws CacheException {
    final Host host = Host.getHost(0);
    VM server0 = host.getVM(0);
    VM server1 = host.getVM(1);
    VM server2 = host.getVM(2);
    VM client = host.getVM(3);
    final int numberOfEntries = 10;
    final boolean isPr = true;
    // Start server1 and create index
    server0.invoke(new CacheSerializableRunnable("Create Server1") {

        public void run2() throws CacheException {
            configAndStartBridgeServer(isPr, false, false);
            // create a local query service
            QueryService localQueryService = null;
            try {
                localQueryService = getCache().getQueryService();
            } catch (Exception e) {
                Assert.fail("Failed to get QueryService.", e);
            }
            // Verify the type of index created
            Index index = null;
            try {
                index = localQueryService.createIndex("statusIndex", "status", regName);
                if (index instanceof PartitionedIndex) {
                    for (Object o : ((PartitionedIndex) index).getBucketIndexes()) {
                        if (!(o instanceof CompactRangeIndex)) {
                            fail("CompactRangeIndex Index should have been created instead of " + index.getClass());
                        }
                    }
                } else {
                    fail("Partitioned index expected");
                }
            } catch (Exception ex) {
                fail("Failed to create index." + ex.getMessage());
            }
        }
    });
    // Start server2
    server1.invoke(new CacheSerializableRunnable("Create Server2") {

        public void run2() throws CacheException {
            configAndStartBridgeServer(isPr, false, false);
            Region region = getRootRegion().getSubregion(regionName);
        }
    });
    // Start server3
    server2.invoke(new CacheSerializableRunnable("Create Server3") {

        public void run2() throws CacheException {
            configAndStartBridgeServer(isPr, false, false);
            Region region = getRootRegion().getSubregion(regionName);
        }
    });
    // Client pool.
    final int port0 = server0.invoke(() -> PdxStringQueryDUnitTest.getCacheServerPort());
    final int port1 = server1.invoke(() -> PdxStringQueryDUnitTest.getCacheServerPort());
    final int port2 = server2.invoke(() -> PdxStringQueryDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(server0.getHost());
    // Create client pool.
    final String poolName = "testClientServerQueryPool";
    createPool(client, poolName, new String[] { host0 }, new int[] { port0, port1, port2 }, true);
    // Create client region and put PortfolioPdx objects (PdxInstances)
    client.invoke(new CacheSerializableRunnable("Create client") {

        public void run2() throws CacheException {
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.LOCAL);
            ClientServerTestCase.configureConnectionPool(factory, host0, port1, -1, true, -1, -1, null);
            Region region = createRegion(regionName, rootRegionName, factory.create());
            LogWriterUtils.getLogWriter().info("Put PortfolioPdx");
            for (int i = 0; i < numberOfEntries; i++) {
                region.put("key-" + i, new PortfolioPdx(i));
            }
        }
    });
    // Verify if all the index keys are PdxStrings
    server0.invoke(new CacheSerializableRunnable("Create Server") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regionName);
            QueryService localQueryService = getCache().getQueryService();
            Index index = localQueryService.getIndex(region, "statusIndex");
            if (index instanceof PartitionedIndex) {
                for (Object o : ((PartitionedIndex) index).getBucketIndexes()) {
                    CloseableIterator<IndexStoreEntry> iter = ((CompactRangeIndex) o).getIndexStorage().iterator(null);
                    while (iter.hasNext()) {
                        Object key = iter.next().getDeserializedKey();
                        if (!(key instanceof PdxString)) {
                            fail("All keys of the CompactRangeIndex in the Partitioned index should be PdxStrings and not " + key.getClass());
                        }
                    }
                }
            } else {
                fail("Partitioned index expected");
            }
        }
    });
    // Execute queries from client to server and locally on client
    SerializableRunnable executeQueries = new CacheSerializableRunnable("Execute queries") {

        public void run2() throws CacheException {
            QueryService remoteQueryService = null;
            QueryService localQueryService = null;
            SelectResults[][] rs = new SelectResults[1][2];
            try {
                remoteQueryService = (PoolManager.find(poolName)).getQueryService();
                localQueryService = getCache().getQueryService();
            } catch (Exception e) {
                Assert.fail("Failed to get QueryService.", e);
            }
            for (int i = 0; i < queryString.length; i++) {
                try {
                    LogWriterUtils.getLogWriter().info("### Executing Query on remote server:" + queryString[i]);
                    Query query = remoteQueryService.newQuery(queryString[i]);
                    rs[0][0] = (SelectResults) query.execute();
                    LogWriterUtils.getLogWriter().info("RR remote indexType:CompactRange size of resultset: " + rs[0][0].size() + " for query: " + queryString[i]);
                    ;
                    checkForPdxString(rs[0][0].asList(), queryString[i]);
                    LogWriterUtils.getLogWriter().info("### Executing Query locally on client:" + queryString[i]);
                    query = localQueryService.newQuery(queryString[i]);
                    rs[0][1] = (SelectResults) query.execute();
                    LogWriterUtils.getLogWriter().info("isPR: " + isPr + "  client local indexType:CompactRange size of resultset: " + rs[0][1].size() + " for query: " + queryString[i]);
                    ;
                    checkForPdxString(rs[0][1].asList(), queryString[i]);
                    if (i < orderByQueryIndex) {
                        // Compare local and remote query results.
                        if (!compareResultsOfWithAndWithoutIndex(rs)) {
                            fail("Local and Remote Query Results are not matching for query :" + queryString[i]);
                        }
                    } else {
                        // compare the order of results returned
                        compareResultsOrder(rs, isPr);
                    }
                } catch (Exception e) {
                    Assert.fail("Failed executing " + queryString[i], e);
                }
            }
        }
    };
    client.invoke(executeQueries);
    // Put Non Pdx objects on server execute queries locally
    server0.invoke(new CacheSerializableRunnable("Create Bridge Server") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regionName);
            LogWriterUtils.getLogWriter().info("Put Objects locally on server");
            for (int i = numberOfEntries; i < numberOfEntries * 2; i++) {
                region.put("key-" + i, new Portfolio(i));
            }
            QueryService localQueryService = getCache().getQueryService();
            // Query server1 locally to check if PdxString is not being returned
            for (int i = 0; i < queryString.length; i++) {
                try {
                    LogWriterUtils.getLogWriter().info("### Executing Query locally on server:" + queryString[i]);
                    SelectResults rs = (SelectResults) localQueryService.newQuery(queryString[i]).execute();
                    LogWriterUtils.getLogWriter().info("RR server local indexType:Range  size of resultset: " + rs.size() + " for query: " + queryString[i]);
                    // The results should not be PdxString
                    checkForPdxString(rs.asList(), queryString[i]);
                } catch (Exception e) {
                    Assert.fail("Failed executing " + queryString[i], e);
                }
            }
        }
    });
    // test for readSerialized flag
    server0.invoke(new CacheSerializableRunnable("Create Bridge Server") {

        public void run2() throws CacheException {
            GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
            cache.setReadSerialized(true);
            QueryService localQueryService = getCache().getQueryService();
            // Query server1 locally to check if PdxString is not being returned
            for (int i = 0; i < queryString.length; i++) {
                try {
                    LogWriterUtils.getLogWriter().info("### Executing Query locally on server:" + queryString[i]);
                    SelectResults rs = (SelectResults) localQueryService.newQuery(queryString[i]).execute();
                    LogWriterUtils.getLogWriter().info("isPR: " + isPr + " server local readSerializedTrue: indexType:CompactRange size of resultset: " + rs.size() + " for query: " + queryString[i]);
                    // The results should not be PdxString
                    checkForPdxString(rs.asList(), queryString[i]);
                } catch (Exception e) {
                    Assert.fail("Failed executing " + queryString[i], e);
                }
            }
        }
    });
    // test for readSerialized flag on client
    client.invoke(new CacheSerializableRunnable("Create client") {

        public void run2() throws CacheException {
            GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
            cache.setReadSerialized(true);
            QueryService remoteQueryService = (PoolManager.find(poolName)).getQueryService();
            // Query server1 remotely to check if PdxString is not being returned
            for (int i = 0; i < queryString.length; i++) {
                try {
                    LogWriterUtils.getLogWriter().info("### Executing Query locally on server:" + queryString[i]);
                    SelectResults rs = (SelectResults) remoteQueryService.newQuery(queryString[i]).execute();
                    LogWriterUtils.getLogWriter().info("RR server remote readSerializedTrue: indexType: indexType:CompactRange size of resultset: " + rs.size() + " for query: " + queryString[i]);
                    // The results should not be PdxString
                    checkForPdxString(rs.asList(), queryString[i]);
                } catch (Exception e) {
                    Assert.fail("Failed executing " + queryString[i], e);
                }
            }
        }
    });
    closeClient(server2);
    closeClient(client);
    closeClient(server1);
    closeClient(server0);
}
Also used : CloseableIterator(org.apache.geode.internal.cache.persistence.query.CloseableIterator) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) Query(org.apache.geode.cache.query.Query) CacheException(org.apache.geode.cache.CacheException) Portfolio(org.apache.geode.cache.query.data.Portfolio) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Host(org.apache.geode.test.dunit.Host) RangeIndex(org.apache.geode.cache.query.internal.index.RangeIndex) Index(org.apache.geode.cache.query.Index) CompactRangeIndex(org.apache.geode.cache.query.internal.index.CompactRangeIndex) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) PortfolioPdx(org.apache.geode.cache.query.data.PortfolioPdx) PdxString(org.apache.geode.pdx.internal.PdxString) PdxString(org.apache.geode.pdx.internal.PdxString) IgnoredException(org.apache.geode.test.dunit.IgnoredException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) CompactRangeIndex(org.apache.geode.cache.query.internal.index.CompactRangeIndex) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) SelectResults(org.apache.geode.cache.query.SelectResults) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryService(org.apache.geode.cache.query.QueryService) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 9 with PartitionedIndex

use of org.apache.geode.cache.query.internal.index.PartitionedIndex in project geode by apache.

the class PdxStringQueryDUnitTest method testPartitionRegionNoIndex.

@Test
public void testPartitionRegionNoIndex() throws CacheException {
    final Host host = Host.getHost(0);
    VM server0 = host.getVM(0);
    VM server1 = host.getVM(1);
    VM server2 = host.getVM(2);
    VM client = host.getVM(3);
    final int numberOfEntries = 10;
    final boolean isPr = true;
    // Start server1 and create index
    server0.invoke(new CacheSerializableRunnable("Create Server1") {

        public void run2() throws CacheException {
            configAndStartBridgeServer(isPr, false, false);
            // create a local query service
            QueryService localQueryService = null;
            try {
                localQueryService = getCache().getQueryService();
            } catch (Exception e) {
                Assert.fail("Failed to get QueryService.", e);
            }
            Index index = null;
            // created
            try {
                index = localQueryService.createIndex("secIdIndex", "pos.secIdIndexed", regName + " p, p.positions.values pos");
                if (index instanceof PartitionedIndex) {
                    for (Object o : ((PartitionedIndex) index).getBucketIndexes()) {
                        if (!(o instanceof RangeIndex)) {
                            fail("RangeIndex Index should have been created instead of " + index.getClass());
                        }
                    }
                } else {
                    fail("Partitioned index expected");
                }
            } catch (Exception ex) {
                fail("Failed to create index." + ex.getMessage());
            }
        }
    });
    // Start server2
    server1.invoke(new CacheSerializableRunnable("Create Server2") {

        public void run2() throws CacheException {
            configAndStartBridgeServer(isPr, false, false);
            Region region = getRootRegion().getSubregion(regionName);
        }
    });
    // Start server3
    server2.invoke(new CacheSerializableRunnable("Create Server3") {

        public void run2() throws CacheException {
            configAndStartBridgeServer(isPr, false, false);
            Region region = getRootRegion().getSubregion(regionName);
        }
    });
    // Client pool.
    final int port0 = server0.invoke(() -> PdxStringQueryDUnitTest.getCacheServerPort());
    final int port1 = server1.invoke(() -> PdxStringQueryDUnitTest.getCacheServerPort());
    final int port2 = server2.invoke(() -> PdxStringQueryDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(server0.getHost());
    // Create client pool.
    final String poolName = "testClientServerQueryPool";
    createPool(client, poolName, new String[] { host0 }, new int[] { port0, port1, port2 }, true);
    // Create client region and put PortfolioPdx objects (PdxInstances)
    client.invoke(new CacheSerializableRunnable("Create client") {

        public void run2() throws CacheException {
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.LOCAL);
            ClientServerTestCase.configureConnectionPool(factory, host0, port1, -1, true, -1, -1, null);
            Region region = createRegion(regionName, rootRegionName, factory.create());
            LogWriterUtils.getLogWriter().info("Put PortfolioPdx");
            for (int i = 0; i < numberOfEntries; i++) {
                region.put("key-" + i, new PortfolioPdx(i));
            }
        }
    });
    // Execute queries from client to server and locally on client
    SerializableRunnable executeQueries = new CacheSerializableRunnable("Execute queries") {

        public void run2() throws CacheException {
            QueryService remoteQueryService = null;
            QueryService localQueryService = null;
            SelectResults[][] rs = new SelectResults[1][2];
            SelectResults[] resWithoutIndexRemote = new SelectResults[queryString.length];
            SelectResults[] resWithIndexRemote = new SelectResults[queryString.length];
            SelectResults[] resWithoutIndexLocal = new SelectResults[queryString.length];
            SelectResults[] resWithIndexLocal = new SelectResults[queryString.length];
            try {
                remoteQueryService = (PoolManager.find(poolName)).getQueryService();
                localQueryService = getCache().getQueryService();
            } catch (Exception e) {
                Assert.fail("Failed to get QueryService.", e);
            }
            for (int i = 0; i < queryString.length; i++) {
                try {
                    LogWriterUtils.getLogWriter().info("### Executing Query on remote server:" + queryString[i]);
                    Query query = remoteQueryService.newQuery(queryString[i]);
                    rs[0][0] = (SelectResults) query.execute();
                    resWithoutIndexRemote[i] = rs[0][0];
                    LogWriterUtils.getLogWriter().info("RR remote no index size of resultset: " + rs[0][0].size() + " for query: " + queryString[i]);
                    ;
                    checkForPdxString(rs[0][0].asList(), queryString[i]);
                    LogWriterUtils.getLogWriter().info("### Executing Query locally on client:" + queryString[i]);
                    query = localQueryService.newQuery(queryString[i]);
                    rs[0][1] = (SelectResults) query.execute();
                    resWithoutIndexLocal[i] = rs[0][1];
                    LogWriterUtils.getLogWriter().info("isPR: " + isPr + "  client local indexType:no index size of resultset: " + rs[0][1].size() + " for query: " + queryString[i]);
                    ;
                    checkForPdxString(rs[0][1].asList(), queryString[i]);
                } catch (Exception e) {
                    Assert.fail("Failed executing " + queryString[i], e);
                }
                try {
                    // to compare remote query results with and without index
                    LogWriterUtils.getLogWriter().info("### Executing Query on remote server for region2:" + queryString2[i]);
                    Query query = remoteQueryService.newQuery(queryString2[i]);
                    resWithIndexRemote[i] = (SelectResults) query.execute();
                    LogWriterUtils.getLogWriter().info("isPR: " + isPr + "  remote region2 size of resultset: " + resWithIndexRemote[i].size() + " for query: " + queryString2[i]);
                    ;
                    checkForPdxString(resWithIndexRemote[i].asList(), queryString2[i]);
                    // to compare local query results with and without index
                    LogWriterUtils.getLogWriter().info("### Executing Query on local for region2:" + queryString2[i]);
                    query = localQueryService.newQuery(queryString2[i]);
                    resWithIndexLocal[i] = (SelectResults) query.execute();
                    LogWriterUtils.getLogWriter().info("isPR: " + isPr + "  local region2 size of resultset: " + resWithIndexLocal[i].size() + " for query: " + queryString2[i]);
                    ;
                    checkForPdxString(resWithIndexLocal[i].asList(), queryString2[i]);
                } catch (Exception e) {
                    Assert.fail("Failed executing " + queryString2[i], e);
                }
                if (i < orderByQueryIndex) {
                    // Compare local and remote query results.
                    if (!compareResultsOfWithAndWithoutIndex(rs)) {
                        LogWriterUtils.getLogWriter().info("result0=" + rs[0][0].asList());
                        LogWriterUtils.getLogWriter().info("result1=" + rs[0][1].asList());
                        fail("Local and Remote Query Results are not matching for query :" + queryString[i]);
                    }
                } else {
                    // compare the order of results returned
                    compareResultsOrder(rs, isPr);
                }
            }
            for (int i = 0; i < queryString.length; i++) {
                rs[0][0] = resWithoutIndexRemote[i];
                rs[0][1] = resWithIndexRemote[i];
                if (i < orderByQueryIndex) {
                    // Compare local and remote query results.
                    if (!compareResultsOfWithAndWithoutIndex(rs)) {
                        fail("Results with and without index are not matching for query :" + queryString2[i]);
                    }
                } else {
                    // compare the order of results returned
                    compareResultsOrder(rs, isPr);
                }
            }
            for (int i = 0; i < queryString.length; i++) {
                rs[0][0] = resWithoutIndexLocal[i];
                rs[0][1] = resWithIndexLocal[i];
                if (i < orderByQueryIndex) {
                    // Compare local and remote query results.
                    if (!compareResultsOfWithAndWithoutIndex(rs)) {
                        fail("Results with and without index are not matching for query :" + queryString2[i]);
                    }
                } else {
                    // compare the order of results returned
                    compareResultsOrder(rs, isPr);
                }
            }
        }
    };
    client.invoke(executeQueries);
    // Put Non Pdx objects on server execute queries locally
    server0.invoke(new CacheSerializableRunnable("Create Bridge Server") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regionName);
            LogWriterUtils.getLogWriter().info("Put Objects locally on server");
            for (int i = numberOfEntries; i < numberOfEntries * 2; i++) {
                region.put("key-" + i, new Portfolio(i));
            }
            QueryService localQueryService = getCache().getQueryService();
            // Query server1 locally to check if PdxString is not being returned
            for (int i = 0; i < queryString.length; i++) {
                try {
                    LogWriterUtils.getLogWriter().info("### Executing Query locally on server:" + queryString[i]);
                    SelectResults rs = (SelectResults) localQueryService.newQuery(queryString[i]).execute();
                    LogWriterUtils.getLogWriter().info("PR server local indexType:no  size of resultset: " + rs.size() + " for query: " + queryString[i]);
                    // The results should not be PdxString
                    checkForPdxString(rs.asList(), queryString[i]);
                } catch (Exception e) {
                    Assert.fail("Failed executing " + queryString[i], e);
                }
                try {
                    SelectResults rs = (SelectResults) localQueryService.newQuery(queryString2[i]).execute();
                    LogWriterUtils.getLogWriter().info("PR server local indexType: no size of resultset: " + rs.size() + " for query: " + queryString2[i]);
                    // The results should not be PdxString
                    checkForPdxString(rs.asList(), queryString2[i]);
                } catch (Exception e) {
                    Assert.fail("Failed executing " + queryString2[i], e);
                }
            }
        }
    });
    // test for readSerialized flag
    server0.invoke(new CacheSerializableRunnable("Create Bridge Server") {

        public void run2() throws CacheException {
            GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
            cache.setReadSerialized(true);
            QueryService localQueryService = getCache().getQueryService();
            // Query server1 locally to check if PdxString is not being returned
            for (int i = 0; i < queryString.length; i++) {
                try {
                    LogWriterUtils.getLogWriter().info("### Executing Query locally on server:" + queryString[i]);
                    SelectResults rs = (SelectResults) localQueryService.newQuery(queryString[i]).execute();
                    LogWriterUtils.getLogWriter().info("isPR: " + isPr + " server local readSerializedTrue: indexType: no index size of resultset: " + rs.size() + " for query: " + queryString[i]);
                    // The results should not be PdxString
                    checkForPdxString(rs.asList(), queryString[i]);
                } catch (Exception e) {
                    Assert.fail("Failed executing " + queryString[i], e);
                }
            }
        }
    });
    // test for readSerialized flag on client
    client.invoke(new CacheSerializableRunnable("Create client") {

        public void run2() throws CacheException {
            GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
            cache.setReadSerialized(true);
            QueryService remoteQueryService = (PoolManager.find(poolName)).getQueryService();
            // Query server1 remotely to check if PdxString is not being returned
            for (int i = 0; i < queryString.length; i++) {
                try {
                    LogWriterUtils.getLogWriter().info("### Executing Query locally on server:" + queryString[i]);
                    SelectResults rs = (SelectResults) remoteQueryService.newQuery(queryString[i]).execute();
                    LogWriterUtils.getLogWriter().info("RR server remote readSerializedTrue: indexType:no index size of resultset: " + rs.size() + " for query: " + queryString[i]);
                    // The results should not be PdxString
                    checkForPdxString(rs.asList(), queryString[i]);
                } catch (Exception e) {
                    Assert.fail("Failed executing " + queryString[i], e);
                }
            }
        }
    });
    closeClient(server2);
    closeClient(client);
    closeClient(server1);
    closeClient(server0);
}
Also used : DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) Query(org.apache.geode.cache.query.Query) CacheException(org.apache.geode.cache.CacheException) Portfolio(org.apache.geode.cache.query.data.Portfolio) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Host(org.apache.geode.test.dunit.Host) RangeIndex(org.apache.geode.cache.query.internal.index.RangeIndex) Index(org.apache.geode.cache.query.Index) CompactRangeIndex(org.apache.geode.cache.query.internal.index.CompactRangeIndex) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) PortfolioPdx(org.apache.geode.cache.query.data.PortfolioPdx) PdxString(org.apache.geode.pdx.internal.PdxString) IgnoredException(org.apache.geode.test.dunit.IgnoredException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) SelectResults(org.apache.geode.cache.query.SelectResults) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryService(org.apache.geode.cache.query.QueryService) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) RangeIndex(org.apache.geode.cache.query.internal.index.RangeIndex) CompactRangeIndex(org.apache.geode.cache.query.internal.index.CompactRangeIndex) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 10 with PartitionedIndex

use of org.apache.geode.cache.query.internal.index.PartitionedIndex in project geode by apache.

the class QueryTraceJUnitTest method testTraceOnPartitionedRegionWithTracePrefix.

/**
   * Tests tracing on queries with <TRACE> or <trace> tag.
   * 
   * @throws Exception
   */
@Test
public void testTraceOnPartitionedRegionWithTracePrefix() throws Exception {
    String slComment = "-- single line comment with TRACE \n";
    String mlComment = " /* Multi-line comments here" + "* ends here " + "* with TRACE too" + "*/ <TRACE> ";
    String prefix = slComment + mlComment;
    // 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(prefix + queryStr);
    assertTrue(((DefaultQuery) query).isTraced());
    SelectResults results = (SelectResults) query.execute();
    assertTrue(QueryObserverHolder.getInstance() instanceof IndexTrackingQueryObserver);
    // The query should return all elements in region.
    assertEquals(region.size(), results.size());
    QueryObserverHolder.reset();
}
Also used : PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) SelectResults(org.apache.geode.cache.query.SelectResults) Query(org.apache.geode.cache.query.Query) Portfolio(org.apache.geode.cache.query.data.Portfolio) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

PartitionedIndex (org.apache.geode.cache.query.internal.index.PartitionedIndex)32 Index (org.apache.geode.cache.query.Index)17 Query (org.apache.geode.cache.query.Query)17 Test (org.junit.Test)17 Portfolio (org.apache.geode.cache.query.data.Portfolio)15 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)13 SelectResults (org.apache.geode.cache.query.SelectResults)9 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)9 AttributesFactory (org.apache.geode.cache.AttributesFactory)8 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)8 IndexStatistics (org.apache.geode.cache.query.IndexStatistics)8 AbstractIndex (org.apache.geode.cache.query.internal.index.AbstractIndex)8 CacheException (org.apache.geode.cache.CacheException)7 QueryService (org.apache.geode.cache.query.QueryService)7 IOException (java.io.IOException)6 Region (org.apache.geode.cache.Region)6 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)6 Iterator (java.util.Iterator)5 LogWriter (org.apache.geode.LogWriter)5 Cache (org.apache.geode.cache.Cache)5