Search in sources :

Example 71 with Portfolio

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

the class QRegionInterfaceJUnitTest method setUp.

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

Example 72 with Portfolio

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

the class QRegionInterfaceJUnitTest method testUnsupportedExceptionInSubregionsMethod.

@Test
public void testUnsupportedExceptionInSubregionsMethod() {
    Region region1 = null;
    Region region2 = null;
    try {
        region1 = CacheUtils.getRegion("/Portfolios").createSubregion("region1", CacheUtils.getRegion("/Portfolios").getAttributes());
        region2 = CacheUtils.getRegion("/Portfolios").createSubregion("region2", CacheUtils.getRegion("/Portfolios").getAttributes());
    } catch (RegionExistsException ree) {
        fail("Test failed because of Exception= " + ree);
    }
    region1.put("5", new Portfolio(0));
    region1.put("5", new Portfolio(1));
    region2.put("6", new Portfolio(2));
    region2.put("6", new Portfolio(3));
    Query query = CacheUtils.getQueryService().newQuery("select distinct * from /Portfolios.subregions(false) where remove('5')!= null");
    try {
        query.execute();
        assertTrue(!region1.containsKey("5"));
        assertTrue(!region2.containsKey("5"));
        fail("The test should have thrown TypeMismatchException exception");
    } catch (TypeMismatchException tme) {
    // Test has passed successfuly as this exception is expected
    } catch (Exception e) {
        fail("Test failed because of Exception= " + e);
    }
}
Also used : Query(org.apache.geode.cache.query.Query) Portfolio(org.apache.geode.cache.query.data.Portfolio) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) Region(org.apache.geode.cache.Region) RegionExistsException(org.apache.geode.cache.RegionExistsException) RegionExistsException(org.apache.geode.cache.RegionExistsException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 73 with Portfolio

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

the class QRegionInterfaceJUnitTest method testGetEntries.

@Test
public void testGetEntries() throws Exception {
    Query query = CacheUtils.getQueryService().newQuery("select distinct * from /Portfolios.entries where value.ID = 1 and key = '1'");
    Collection result = (Collection) query.execute();
    Region.Entry entry = (Region.Entry) result.iterator().next();
    if (!entry.getKey().equals("1") || ((Portfolio) entry.getValue()).getID() != 1)
        fail(query.getQueryString());
}
Also used : Query(org.apache.geode.cache.query.Query) Portfolio(org.apache.geode.cache.query.data.Portfolio) Collection(java.util.Collection) Region(org.apache.geode.cache.Region) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 74 with Portfolio

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

the class TestNewFunctionSSorRSIntegrationTest method testNewFunc.

@Test
public void testNewFunc() throws Exception {
    Region region = CacheUtils.createRegion("portfolios", Portfolio.class);
    for (int i = 0; i < 4; i++) {
        region.put("" + i, new Portfolio(i));
    // CacheUtils.log(new Portfolio(i));
    }
    Object[][] r = new Object[2][2];
    QueryService qs;
    qs = CacheUtils.getQueryService();
    String[] queries = { "SELECT DISTINCT * from /portfolios pf , pf.positions.values pos where status = 'inactive'", "select distinct * from /portfolios where ID > 1 " };
    for (int i = 0; i < queries.length; i++) {
        Query q = null;
        q = CacheUtils.getQueryService().newQuery(queries[i]);
        QueryObserverImpl observer1 = new QueryObserverImpl();
        QueryObserverHolder.setInstance(observer1);
        r[i][0] = q.execute();
    }
    qs.createIndex("sIndex", IndexType.FUNCTIONAL, "status", "/portfolios");
    qs.createIndex("iIndex", IndexType.FUNCTIONAL, "ID", "/portfolios");
    for (int i = 0; i < queries.length; i++) {
        Query q = null;
        q = CacheUtils.getQueryService().newQuery(queries[i]);
        QueryObserverImpl observer2 = new QueryObserverImpl();
        QueryObserverHolder.setInstance(observer2);
        r[i][1] = q.execute();
        if (!observer2.isIndexesUsed) {
            fail("Index NOT Used");
        }
    }
    StructSetOrResultsSet ssORrs = new StructSetOrResultsSet();
    ssORrs.CompareQueryResultsWithoutAndWithIndexes(r, queries.length, queries);
}
Also used : Query(org.apache.geode.cache.query.Query) QueryService(org.apache.geode.cache.query.QueryService) Portfolio(org.apache.geode.cache.query.data.Portfolio) Region(org.apache.geode.cache.Region) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 75 with Portfolio

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

the class OrderByTestImplementation method testMultiColOrderByWithMultiIndexResultDefaultProjection.

@Test
public void testMultiColOrderByWithMultiIndexResultDefaultProjection() throws Exception {
    String[] queries = { // Test case No. IUMR021
    "SELECT  distinct * FROM /portfolio1 pf1 where pkid = '12' and ID > 10 order by ID desc, pkid asc ", "SELECT  distinct * FROM /portfolio1 pf1 where pkid > '1' and ID > 10 order by ID asc, pkid desc ", "SELECT  distinct * FROM /portfolio1 pf1 where pkid = '13'and  ID > 10 and ID < 20 order by ID asc, pkid asc ", "SELECT  distinct * FROM /portfolio1 pf1 where pkid <'9' and ID > 10 and ID < 20 order by ID desc , pkid desc", "SELECT  distinct * FROM /portfolio1 pf1 where pkid = '15' and ID >= 10 and ID <= 20 order by ID desc, pkid desc ", "SELECT  distinct * FROM /portfolio1 pf1 where pkid > '1' and pkid <='9' and ID >= 10 and ID <= 20 order by ID asc, pkid asc", "SELECT  distinct * FROM /portfolio1 pf1 where pkid > '1' and ID != 10 order by ID asc, pkid asc ", "SELECT  distinct * FROM /portfolio1 pf1 where pkid > '1' and ID != 10 order by ID desc, pkid desc ", "SELECT  distinct * FROM /portfolio1 pf1 where pkid = '17' and ID > 10 order by ID desc, pkid asc limit 5", "SELECT  distinct * FROM /portfolio1 pf1 where pkid > '17' and ID > 10 order by ID asc, pkid desc limit 5", "SELECT  distinct * FROM /portfolio1 pf1 where pkid < '7' and ID > 10 and ID < 20 order by ID asc, pkid asc limit 5 ", "SELECT  distinct * FROM /portfolio1 pf1 where pkid = '18' and ID > 10 and ID < 20 order by ID desc, pkid desc limit 5", "SELECT  distinct * FROM /portfolio1 pf1 where pkid > '1' and ID >= 10 and ID <= 20 order by ID desc, pkid asc limit 5", "SELECT  distinct * FROM /portfolio1 pf1 where pkid != '17' and ID >= 10 and ID <= 20 order by ID asc, pkid desc limit 5", "SELECT  distinct * FROM /portfolio1 pf1 where pkid > '0' and ID != 10 order by ID asc, pkid asc limit 10", "SELECT  distinct * FROM /portfolio1 pf1 where pkid > '1' and ID != 10 order by ID desc, pkid 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");
    this.createIndex("PKIDIndexPf1", IndexType.FUNCTIONAL, "pkid", "/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);
            assertEquals("Ordered", rcw.getCollectionType().getSimpleClassName());
            if (assertIndexUsedOnQueryNode() && !observer.isIndexesUsed) {
                fail("Index is NOT uesd");
            }
            Iterator itr = observer.indexesUsed.iterator();
            while (itr.hasNext()) {
                String indexUsed = itr.next().toString();
                if (!(indexUsed).equals("IDIndexPf1")) {
                    fail("<IDIndexPf1> was expected but found " + indexUsed);
                }
            // 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)

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