Search in sources :

Example 81 with Portfolio

use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.

the class OrderByTestImplementation method testOrderByWithIndexResultWithProjection.

@Test
public void testOrderByWithIndexResultWithProjection() throws Exception {
    String[] queries = { // Test case No. IUMR021
    "SELECT  distinct ID, description, createTime FROM /portfolio1 pf1 where ID > 10 order by ID desc ", "SELECT  distinct ID, description, createTime FROM /portfolio1 pf1 where ID > 10 order by ID asc ", "SELECT  distinct ID, description, createTime FROM /portfolio1 pf1 where ID > 10 and ID < 20 order by ID asc ", "SELECT  distinct ID, description, createTime FROM /portfolio1 pf1 where ID > 10 and ID < 20 order by ID desc ", "SELECT  distinct ID, description, createTime FROM /portfolio1 pf1 where ID >= 10 and ID <= 20 order by ID desc ", "SELECT  distinct ID, description, createTime FROM /portfolio1 pf1 where ID >= 10 and ID <= 20 order by ID asc", "SELECT  distinct ID, description, createTime FROM /portfolio1 pf1 where ID != 10 order by ID asc ", "SELECT  distinct ID, description, createTime FROM /portfolio1 pf1 where ID != 10 order by ID desc ", "SELECT  distinct ID, description, createTime FROM /portfolio1 pf1 where ID > 10 order by ID desc limit 5", "SELECT  distinct ID, description, createTime FROM /portfolio1 pf1 where ID > 10 order by ID asc limit 5", "SELECT  distinct ID, description, createTime FROM /portfolio1 pf1 where ID > 10 and ID < 20 order by ID asc limit 5 ", "SELECT  distinct ID, description, createTime FROM /portfolio1 pf1 where ID > 10 and ID < 20 order by ID desc limit 5", "SELECT  distinct ID, description, createTime FROM /portfolio1 pf1 where ID >= 10 and ID <= 20 order by ID desc limit 5", "SELECT  distinct ID, description, createTime FROM /portfolio1 pf1 where ID >= 10 and ID <= 20 order by ID asc limit 5", "SELECT  distinct ID, description, createTime FROM /portfolio1 pf1 where ID != 10 order by ID asc limit 10", "SELECT  distinct ID, description, createTime FROM /portfolio1 pf1 where ID != 10 order by ID desc limit 10" };
    Object[][] r = new Object[queries.length][2];
    QueryService qs;
    qs = CacheUtils.getQueryService();
    Position.resetCounter();
    // Create Regions
    Region r1 = createRegion("portfolio1", Portfolio.class);
    for (int i = 0; i < 50; i++) {
        r1.put(i + "", new Portfolio(i));
    }
    // Execute Queries without Indexes
    for (int i = 0; i < queries.length; i++) {
        Query q = null;
        try {
            q = CacheUtils.getQueryService().newQuery(queries[i]);
            CacheUtils.getLogger().info("Executing query: " + queries[i]);
            r[i][0] = q.execute();
        } catch (Exception e) {
            e.printStackTrace();
            fail(q.getQueryString());
        }
    }
    // Create Indexes
    this.createIndex("IDIndexPf1", IndexType.FUNCTIONAL, "ID", "/portfolio1");
    // Execute Queries with Indexes
    for (int i = 0; i < queries.length; i++) {
        Query q = null;
        try {
            q = CacheUtils.getQueryService().newQuery(queries[i]);
            CacheUtils.getLogger().info("Executing query: " + queries[i]);
            QueryObserverImpl observer = new QueryObserverImpl();
            QueryObserverHolder.setInstance(observer);
            r[i][1] = q.execute();
            SelectResults rcw = (SelectResults) r[i][1];
            int indexLimit = queries[i].indexOf("limit");
            int limit = -1;
            boolean limitQuery = indexLimit != -1;
            if (limitQuery) {
                limit = Integer.parseInt(queries[i].substring(indexLimit + 5).trim());
            }
            assertTrue(!limitQuery || rcw.size() <= limit);
            // assertIndexDetailsEquals("Set",rcw.getCollectionType().getSimpleClassName());
            String colType = rcw.getCollectionType().getSimpleClassName();
            if (!(colType.equals("Ordered") || colType.equals("LinkedHashSet"))) {
                fail("The collection type " + colType + " is not expexted");
            }
            if (assertIndexUsedOnQueryNode() && !observer.isIndexesUsed) {
                fail("Index is NOT uesd");
            }
            Iterator itr = observer.indexesUsed.iterator();
            while (itr.hasNext()) {
                if (!(itr.next().toString()).equals("IDIndexPf1")) {
                    fail("<IDIndexPf1> was expected but found " + itr.next().toString());
                }
            // assertIndexDetailsEquals("statusIndexPf1",itr.next().toString());
            }
            int indxs = observer.indexesUsed.size();
            System.out.println("**************************************************Indexes Used :::::: " + indxs + " Index Name: " + observer.indexName);
        } catch (Exception e) {
            e.printStackTrace();
            fail(q.getQueryString());
        }
    }
    StructSetOrResultsSet ssOrrs = new StructSetOrResultsSet();
    ssOrrs.CompareQueryResultsWithoutAndWithIndexes(r, queries.length, true, queries);
    ssOrrs.compareExternallySortedQueriesWithOrderBy(queries, r);
}
Also used : Query(org.apache.geode.cache.query.Query) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) Portfolio(org.apache.geode.cache.query.data.Portfolio) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) IndexInvalidException(org.apache.geode.cache.query.IndexInvalidException) IndexNameConflictException(org.apache.geode.cache.query.IndexNameConflictException) IndexExistsException(org.apache.geode.cache.query.IndexExistsException) SelectResults(org.apache.geode.cache.query.SelectResults) QueryService(org.apache.geode.cache.query.QueryService) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region) Test(org.junit.Test)

Example 82 with Portfolio

use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.

the class StructMemberAccessJUnitTest method setUp.

@Before
public void setUp() throws java.lang.Exception {
    CacheUtils.startCache();
    Region region = CacheUtils.createRegion("Portfolios", Portfolio.class);
    for (int i = 0; i < 4; i++) {
        region.put("" + i, new Portfolio(i));
    }
}
Also used : Portfolio(org.apache.geode.cache.query.data.Portfolio) Region(org.apache.geode.cache.Region) Before(org.junit.Before)

Example 83 with Portfolio

use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.

the class ResultsDataSerializabilityJUnitTest method testDataSerializability.

// For locally executed queries, ResultsCollectionPdxDeserializerWrapper is
// returned which is not required to be DSFID as it is not sent over the
// network. Hence a dunit test is required for testing this functionality.
/* test DataSerializability of a simple query result */
@Ignore
@Test
public void testDataSerializability() throws Exception {
    Region region = CacheUtils.createRegion("Portfolios", Portfolio.class);
    for (int i = 0; i < 10000; i++) {
        region.put(i + "", new Portfolio(i));
    }
    String queryStr = "SELECT DISTINCT * FROM /Portfolios";
    Query q = CacheUtils.getQueryService().newQuery(queryStr);
    SelectResults res1 = (SelectResults) q.execute();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(baos);
    // false prevents Java serialization
    DataSerializer.writeObject(res1, out, false);
    out.close();
    DataInputStream in = new DataInputStream(new ByteArrayInputStream(baos.toByteArray()));
    SelectResults res2 = (SelectResults) DataSerializer.readObject(in);
    in.close();
    assertEquals(res2.size(), res1.size());
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) Query(org.apache.geode.cache.query.Query) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) Portfolio(org.apache.geode.cache.query.data.Portfolio) Region(org.apache.geode.cache.Region) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) Ignore(org.junit.Ignore) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 84 with Portfolio

use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.

the class IndexMaintainceJUnitTest method test004DestroyEntry.

@Test
public void test004DestroyEntry() throws Exception {
    IndexStatistics stats = index.getStatistics();
    region.put("4", new Portfolio(4));
    region.destroy("4");
    assertEquals(4, stats.getNumberOfValues());
    // Set results = new HashSet();
    // index.query("active", OQLLexerTokenTypes.TOK_EQ, results,new ExecutionContext(null,
    // CacheUtils.getCache()));
    SelectResults results = region.query("status = 'active'");
    assertEquals(2, results.size());
}
Also used : IndexStatistics(org.apache.geode.cache.query.IndexStatistics) SelectResults(org.apache.geode.cache.query.SelectResults) Portfolio(org.apache.geode.cache.query.data.Portfolio) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 85 with Portfolio

use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.

the class HashIndexSetJUnitTest method testGetByKeyLocatesAfterMultipleColiisionsAndRemoveToken.

@Test
public void testGetByKeyLocatesAfterMultipleColiisionsAndRemoveToken() throws Exception {
    int numEntries = 20;
    int keyToLookup = 1;
    his = createHashIndexSet();
    Map<Integer, Portfolio> collectionOfPorts1 = this.createPortfolioObjects(numEntries, 0);
    Map<Integer, Portfolio> collectionOfPorts2 = this.createPortfolioObjects(numEntries, numEntries);
    Map<Integer, Portfolio> collectionOfPorts3 = this.createPortfolioObjects(numEntries, numEntries * 2);
    addPortfoliosToHashIndexSet(collectionOfPorts1, his);
    addPortfoliosToHashIndexSet(collectionOfPorts2, his);
    addPortfoliosToHashIndexSet(collectionOfPorts3, his);
    assertEquals(numEntries * 3, his.size());
    Iterator iterator = his.get(keyToLookup);
    int numIterated = 0;
    while (iterator.hasNext()) {
        numIterated++;
        // verify that the returned values match what we lookedup
        assertEquals(keyToLookup, ((Portfolio) iterator.next()).indexKey);
    }
    assertEquals(3, numIterated);
    // let's remove the second collision
    his.remove(keyToLookup, collectionOfPorts2.get(keyToLookup));
    iterator = his.get(keyToLookup);
    numIterated = 0;
    while (iterator.hasNext()) {
        numIterated++;
        // verify that the returned values match what we lookedup
        assertEquals(keyToLookup, ((Portfolio) iterator.next()).indexKey);
    }
    assertEquals(2, numIterated);
    // Add it back in and make sure we can iterate all 3 again
    his.add(keyToLookup, collectionOfPorts2.get(keyToLookup));
    iterator = his.get(keyToLookup);
    numIterated = 0;
    while (iterator.hasNext()) {
        numIterated++;
        // verify that the returned values match what we lookedup
        assertEquals(keyToLookup, ((Portfolio) iterator.next()).indexKey);
    }
    assertEquals(3, numIterated);
}
Also used : Portfolio(org.apache.geode.cache.query.data.Portfolio) Iterator(java.util.Iterator) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Aggregations

Portfolio (org.apache.geode.cache.query.data.Portfolio)520 Test (org.junit.Test)415 Region (org.apache.geode.cache.Region)302 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)298 SelectResults (org.apache.geode.cache.query.SelectResults)247 Query (org.apache.geode.cache.query.Query)235 QueryService (org.apache.geode.cache.query.QueryService)195 Index (org.apache.geode.cache.query.Index)121 AttributesFactory (org.apache.geode.cache.AttributesFactory)85 Iterator (java.util.Iterator)81 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)72 LocalRegion (org.apache.geode.internal.cache.LocalRegion)69 VM (org.apache.geode.test.dunit.VM)65 Host (org.apache.geode.test.dunit.Host)64 Cache (org.apache.geode.cache.Cache)62 CacheException (org.apache.geode.cache.CacheException)49 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)47 QueryObserverAdapter (org.apache.geode.cache.query.internal.QueryObserverAdapter)47 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)47 IndexExistsException (org.apache.geode.cache.query.IndexExistsException)46