Search in sources :

Example 56 with Portfolio

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

the class ComparisonOperatorsJUnitTest method testCompareWithNULL.

@Test
public void testCompareWithNULL() throws Exception {
    String var = "P2";
    Object value = null;
    QueryService qs = CacheUtils.getQueryService();
    for (int i = 0; i < operators.length; i++) {
        Query query = qs.newQuery("SELECT DISTINCT * FROM /Portfolios where " + var + operators[i] + value);
        Object result = query.execute();
        if (result instanceof Collection) {
            Iterator iter = ((Collection) result).iterator();
            while (iter.hasNext()) {
                boolean isPassed = false;
                Portfolio p = (Portfolio) iter.next();
                switch(i) {
                    case 0:
                        isPassed = (p.getP2() == value);
                        break;
                    default:
                        isPassed = (p.getP2() != value);
                        break;
                }
                if (!isPassed)
                    fail(this.getName() + " failed for operator " + operators[i]);
            }
        } else {
            fail(this.getName() + " failed for operator " + operators[i]);
        }
    }
}
Also used : Query(org.apache.geode.cache.query.Query) QueryService(org.apache.geode.cache.query.QueryService) Portfolio(org.apache.geode.cache.query.data.Portfolio) Iterator(java.util.Iterator) Collection(java.util.Collection) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 57 with Portfolio

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

the class ComparisonOperatorsJUnitTest 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 58 with Portfolio

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

the class QueryParamsAuthorizationDUnitTest method testQueryParamsInAuthCallback.

@Ignore("Bug 51079")
@Test
public void testQueryParamsInAuthCallback() throws Exception {
    final Host host = Host.getHost(0);
    final VM server1 = host.getVM(0);
    final VM client = host.getVM(1);
    // create servers and regions
    final int port = (Integer) server1.invoke(new SerializableCallable("Create Server1") {

        @Override
        public Object call() throws Exception {
            CacheFactory cf = new CacheFactory().set(MCAST_PORT, "0").set(SECURITY_CLIENT_ACCESSOR, "org.apache.geode.cache.query.dunit.QueryAuthorization.create").set(SECURITY_CLIENT_AUTHENTICATOR, DummyAuthenticator.class.getName() + ".create");
            Cache cache = getCache(cf);
            cache.createRegionFactory(RegionShortcut.REPLICATE).create(regName);
            CacheServer server = cache.addCacheServer();
            int port = AvailablePortHelper.getRandomAvailablePortForDUnitSite();
            server.setPort(port);
            server.start();
            return port;
        }
    });
    // create client
    client.invoke(new SerializableCallable("Create client") {

        @Override
        public Object call() throws Exception {
            ClientCacheFactory ccf = new ClientCacheFactory().addPoolServer(NetworkUtils.getServerHostName(server1.getHost()), port).set(SECURITY_CLIENT_AUTH_INIT, UserPasswordAuthInit.class.getName() + ".create").set(SECURITY_PREFIX + "username", "root").set(SECURITY_PREFIX + "password", "root");
            ClientCache cache = getClientCache(ccf);
            Region r1 = cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create(regName);
            for (int i = 0; i < 20; i++) {
                r1.put("key-" + i, new Portfolio(i));
            }
            QueryService qs = cache.getQueryService();
            Object[] params = new Object[] { "active", 0 };
            SelectResults sr = (SelectResults) qs.newQuery("select * from " + r1.getFullPath() + " where status = $1 and ID > $2 ").execute(params);
            assertTrue("Result size should be greater than 0 ", sr.size() > 0);
            return null;
        }
    });
}
Also used : Portfolio(org.apache.geode.cache.query.data.Portfolio) Host(org.apache.geode.test.dunit.Host) ClientCache(org.apache.geode.cache.client.ClientCache) UserPasswordAuthInit(org.apache.geode.security.templates.UserPasswordAuthInit) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) SelectResults(org.apache.geode.cache.query.SelectResults) QueryService(org.apache.geode.cache.query.QueryService) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) CacheServer(org.apache.geode.cache.server.CacheServer) Region(org.apache.geode.cache.Region) CacheFactory(org.apache.geode.cache.CacheFactory) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Ignore(org.junit.Ignore) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 59 with Portfolio

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

the class CustomerOptimizationsJUnitTest method testUnionDuringIndexEvaluationWithMultipleFilters.

@Test
public void testUnionDuringIndexEvaluationWithMultipleFilters() throws QueryException {
    QueryService qs = CacheUtils.getQueryService();
    Region rgn = CacheUtils.getRegion("/pos");
    for (int i = 100; i < 200; ++i) {
        Portfolio pf = new Portfolio(i);
        pf.setCreateTime(10l);
        rgn.put("" + i, pf);
    }
    String[] queries = new String[] { "select  p.status as sts, p as pos from /pos p  where  p.ID IN  SET( 0,1,2,3,4,5,101,102,103,104,105) AND p.createTime > 9l" };
    SelectResults[][] sr = new SelectResults[queries.length][2];
    for (int i = 0; i < queries.length; ++i) {
        Query q = qs.newQuery(queries[i]);
        sr[i][0] = (SelectResults) q.execute();
    }
    qs.createIndex("PortFolioID", IndexType.FUNCTIONAL, "ID", "/pos");
    qs.createIndex("CreateTime", IndexType.FUNCTIONAL, "createTime", "/pos");
    final boolean[] expectedIndexUsed = new boolean[] { true };
    final boolean[] actualIndexUsed = new boolean[] { false };
    final boolean[] expectedProjectionCallabck = new boolean[] { false };
    final boolean[] actualProjectionCallback = new boolean[] { false };
    final boolean[] expectedUnionCallback = { false };
    final boolean[] actualUnionCallback = new boolean[queries.length];
    final boolean[] expectedIntersectionCallback = { false };
    final boolean[] actualIntersectionCallback = new boolean[queries.length];
    ObjectType[] expectedTypes = new ObjectType[] { new StructTypeImpl(new String[] { "sts", "pos" }, new ObjectType[] { new ObjectTypeImpl(String.class), new ObjectTypeImpl(Portfolio.class) }) };
    QueryObserverHolder.setInstance(new QueryObserverAdapter() {

        private int i = 0;

        public void invokedQueryUtilsUnion(SelectResults r1, SelectResults r2) {
            actualUnionCallback[i] = true;
        }

        public void invokedQueryUtilsIntersection(SelectResults r1, SelectResults r2) {
            actualIntersectionCallback[i] = true;
        }

        public void beforeIndexLookup(Index index, int oper, Object key) {
            actualIndexUsed[i] = true;
        }

        public void beforeApplyingProjectionOnFilterEvaluatedResults(Object preProjectionApplied) {
            actualProjectionCallback[i] = true;
        }

        public void afterQueryEvaluation(Object result) {
            ++i;
        }
    });
    for (int i = 0; i < queries.length; ++i) {
        Query q = qs.newQuery(queries[i]);
        sr[i][1] = (SelectResults) q.execute();
        assertEquals(expectedUnionCallback[i], actualUnionCallback[i]);
        assertEquals(expectedTypes[i], sr[i][1].getCollectionType().getElementType());
        assertEquals(expectedIndexUsed[i], actualIndexUsed[i]);
        assertEquals(expectedProjectionCallabck[i], actualProjectionCallback[i]);
        assertEquals(expectedIntersectionCallback[i], actualIntersectionCallback[i]);
    }
    CacheUtils.compareResultsOfWithAndWithoutIndex(sr, this);
}
Also used : Query(org.apache.geode.cache.query.Query) Portfolio(org.apache.geode.cache.query.data.Portfolio) ObjectTypeImpl(org.apache.geode.cache.query.internal.types.ObjectTypeImpl) Index(org.apache.geode.cache.query.Index) ObjectType(org.apache.geode.cache.query.types.ObjectType) SelectResults(org.apache.geode.cache.query.SelectResults) QueryService(org.apache.geode.cache.query.QueryService) QueryObserverAdapter(org.apache.geode.cache.query.internal.QueryObserverAdapter) StructTypeImpl(org.apache.geode.cache.query.internal.types.StructTypeImpl) Region(org.apache.geode.cache.Region) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 60 with Portfolio

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

the class CustomerOptimizationsJUnitTest method setUp.

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

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