Search in sources :

Example 11 with CompactRangeIndex

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

the class IndexCreationJUnitTest method testIndexCreationWithFunctionsinFromClause.

@Test
public void testIndexCreationWithFunctionsinFromClause() throws Exception {
    // Task ID: ICM13
    QueryService qs;
    qs = CacheUtils.getQueryService();
    // BUG #32586 : FIXED
    Index i1 = qs.createIndex("Index11", IndexType.FUNCTIONAL, "status", "/portfolios.values.toArray()");
    Index i2 = qs.createIndex("Index12", IndexType.FUNCTIONAL, "ID", "/portfolios.values.asSet");
    Index i3 = qs.createIndex("Index13", IndexType.FUNCTIONAL, "ID", "/portfolios.values.asList");
    qs.createIndex("Index14", IndexType.FUNCTIONAL, "value.ID", "/portfolios.entries.toArray()");
    qs.createIndex("Index15", IndexType.FUNCTIONAL, "value.ID", "/portfolios.entries.asSet");
    qs.createIndex("Index16", IndexType.FUNCTIONAL, "value.ID", "/portfolios.entries.asList");
    // BUG #32586 : FIXED
    qs.createIndex("Index17", IndexType.FUNCTIONAL, "kIter", "/portfolios.keys.toArray() kIter");
    qs.createIndex("Index18", IndexType.FUNCTIONAL, "kIter", "/portfolios.keys.asSet kIter");
    qs.createIndex("Index19", IndexType.FUNCTIONAL, "kIter", "/portfolios.keys.asList kIter");
    CacheUtils.log(((CompactRangeIndex) i1).dump());
    CacheUtils.log(((CompactRangeIndex) i2).dump());
    CacheUtils.log(((CompactRangeIndex) i3).dump());
}
Also used : DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) QueryService(org.apache.geode.cache.query.QueryService) RangeIndex(org.apache.geode.cache.query.internal.index.RangeIndex) CompactMapRangeIndex(org.apache.geode.cache.query.internal.index.CompactMapRangeIndex) Index(org.apache.geode.cache.query.Index) CompactRangeIndex(org.apache.geode.cache.query.internal.index.CompactRangeIndex) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 12 with CompactRangeIndex

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

the class MultiIndexCreationJUnitTest method testBasicMultiIndexCreationDifferentTypes.

@Test
public void testBasicMultiIndexCreationDifferentTypes() throws Exception {
    Region r = CacheUtils.getRegion(regionName);
    for (int i = 0; i < 10; i++) {
        r.put("" + i, new Portfolio(i));
    }
    QueryService qs = CacheUtils.getQueryService();
    qs.defineIndex("statusIndex", "status", r.getFullPath());
    qs.defineHashIndex("IDIndex", "ID", r.getFullPath());
    qs.defineKeyIndex("keyIDIndex", "ID", r.getFullPath());
    List<Index> indexes = qs.createDefinedIndexes();
    assertEquals("Only 3 indexes should have been created. ", 3, indexes.size());
    Index ind = qs.getIndex(r, "statusIndex");
    assertTrue(ind instanceof CompactRangeIndex);
    assertEquals(2, ind.getStatistics().getNumberOfKeys());
    assertEquals(10, ind.getStatistics().getNumberOfValues());
    ind = qs.getIndex(r, "IDIndex");
    assertTrue(ind instanceof HashIndex);
    assertEquals(10, ind.getStatistics().getNumberOfValues());
    ind = qs.getIndex(r, "keyIDIndex");
    assertTrue(ind instanceof PrimaryKeyIndex);
    assertEquals(10, ind.getStatistics().getNumberOfKeys());
    assertEquals(10, ind.getStatistics().getNumberOfValues());
    QueryObserver old = QueryObserverHolder.setInstance(new QueryObserverAdapter() {

        private boolean indexCalled = false;

        public void afterIndexLookup(Collection results) {
            indexCalled = true;
        }

        public void endQuery() {
            assertTrue(indexCalled);
        }
    });
    String[] queries = { "select * from " + r.getFullPath() + " where status = 'active'", "select * from " + r.getFullPath() + " where ID > 4" };
    for (int i = 0; i < queries.length; i++) {
        SelectResults sr = (SelectResults) qs.newQuery(queries[i]).execute();
        assertEquals(5, sr.size());
    }
    QueryObserverHolder.setInstance(old);
}
Also used : Portfolio(org.apache.geode.cache.query.data.Portfolio) Index(org.apache.geode.cache.query.Index) CompactRangeIndex(org.apache.geode.cache.query.internal.index.CompactRangeIndex) HashIndex(org.apache.geode.cache.query.internal.index.HashIndex) PrimaryKeyIndex(org.apache.geode.cache.query.internal.index.PrimaryKeyIndex) HashIndex(org.apache.geode.cache.query.internal.index.HashIndex) QueryObserver(org.apache.geode.cache.query.internal.QueryObserver) CompactRangeIndex(org.apache.geode.cache.query.internal.index.CompactRangeIndex) SelectResults(org.apache.geode.cache.query.SelectResults) QueryService(org.apache.geode.cache.query.QueryService) QueryObserverAdapter(org.apache.geode.cache.query.internal.QueryObserverAdapter) Region(org.apache.geode.cache.Region) Collection(java.util.Collection) PrimaryKeyIndex(org.apache.geode.cache.query.internal.index.PrimaryKeyIndex) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 13 with CompactRangeIndex

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

the class PdxStringQueryDUnitTest method testRepliacatedRegionCompactRangeIndex.

@Test
public void testRepliacatedRegionCompactRangeIndex() 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;
    // Start server1 and create index
    server0.invoke(new CacheSerializableRunnable("Create Server1") {

        public void run2() throws CacheException {
            configAndStartBridgeServer(false, 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 CompactRangeIndex)) {
                    fail("CompactRange Index should have been created instead of " + index.getClass());
                }
            } catch (Exception ex) {
                fail("Failed to create index." + ex.getMessage());
            }
        }
    });
    // Start server2
    server1.invoke(new CacheSerializableRunnable("Create Server2") {

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

        public void run2() throws CacheException {
            configAndStartBridgeServer(false, 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");
            CloseableIterator<IndexStoreEntry> iter = ((CompactRangeIndex) index).getIndexStorage().iterator(null);
            while (iter.hasNext()) {
                Object key = iter.next().getDeserializedKey();
                if (!(key instanceof PdxString)) {
                    fail("All keys of the CompactRangeIndex should be PdxStrings and not " + key.getClass());
                }
            }
        }
    });
    // 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("RR  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, false);
                    }
                } 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("RR 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: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) 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 14 with CompactRangeIndex

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

the class PdxStringQueryDUnitTest method testNullPdxString.

@Test
public void testNullPdxString() 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");
            // Put some PortfolioPdx objects with null Status and secIds
            for (int i = 0; i < numberOfEntries * 2; i++) {
                PortfolioPdx portfolioPdx = new PortfolioPdx(i);
                // this will create NULL PdxStrings
                portfolioPdx.status = null;
                portfolioPdx.positions = new HashMap();
                portfolioPdx.positions.put(null, new PositionPdx(null, PositionPdx.cnt * 1000));
                region.put("key-" + i, portfolioPdx);
            }
            // Put some PortfolioPdx with non null status to reproduce bug#45351
            for (int i = 0; i < numberOfEntries; i++) {
                PortfolioPdx portfolioPdx = new PortfolioPdx(i);
                region.put("key-" + i, portfolioPdx);
            }
        }
    });
    // 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) && !(key == IndexManager.NULL)) {
                            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
    client.invoke(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);
            }
            // Querying the fields with null values
            String[] qs = { "SELECT pos.secId FROM " + regName + "  p, p.positions.values pos where p.status = null", "SELECT p.pkid FROM " + regName + "  p, p.positions.values pos where pos.secId = null" };
            for (int i = 0; i < 2; i++) {
                try {
                    Query query = remoteQueryService.newQuery(qs[i]);
                    SelectResults res = (SelectResults) query.execute();
                    LogWriterUtils.getLogWriter().info("PR NULL Pdxstring test size of resultset: " + res.size() + " for query: " + qs[i]);
                    ;
                    if (i == 0) {
                        for (Object o : res) {
                            if (o != null) {
                                fail("Query : " + qs[i] + " should have returned null and not " + o);
                            }
                        }
                    } else {
                        checkForPdxString(res.asList(), qs[i]);
                    }
                } catch (Exception e) {
                    Assert.fail("Failed executing " + qs[i], e);
                }
            }
        }
    });
    closeClient(server2);
    closeClient(client);
    closeClient(server1);
    closeClient(server0);
}
Also used : CloseableIterator(org.apache.geode.internal.cache.persistence.query.CloseableIterator) PositionPdx(org.apache.geode.cache.query.data.PositionPdx) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) Query(org.apache.geode.cache.query.Query) CacheException(org.apache.geode.cache.CacheException) HashMap(java.util.HashMap) 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) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 15 with CompactRangeIndex

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

the class QueryTraceJUnitTest method testTraceOnLocalRegionWithTracePrefix.

@Test
public void testTraceOnLocalRegionWithTracePrefix() 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
    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(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 : AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CompactRangeIndex(org.apache.geode.cache.query.internal.index.CompactRangeIndex) 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

CompactRangeIndex (org.apache.geode.cache.query.internal.index.CompactRangeIndex)18 Test (org.junit.Test)18 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)15 Query (org.apache.geode.cache.query.Query)12 SelectResults (org.apache.geode.cache.query.SelectResults)11 Portfolio (org.apache.geode.cache.query.data.Portfolio)11 RangeIndex (org.apache.geode.cache.query.internal.index.RangeIndex)11 Index (org.apache.geode.cache.query.Index)10 QueryService (org.apache.geode.cache.query.QueryService)10 AttributesFactory (org.apache.geode.cache.AttributesFactory)9 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)9 Region (org.apache.geode.cache.Region)6 DefaultQueryService (org.apache.geode.cache.query.internal.DefaultQueryService)6 CompactMapRangeIndex (org.apache.geode.cache.query.internal.index.CompactMapRangeIndex)6 PdxString (org.apache.geode.pdx.internal.PdxString)5 IOException (java.io.IOException)3 CacheException (org.apache.geode.cache.CacheException)3 PortfolioPdx (org.apache.geode.cache.query.data.PortfolioPdx)3 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)3 PartitionedIndex (org.apache.geode.cache.query.internal.index.PartitionedIndex)3