Search in sources :

Example 56 with ClientCache

use of org.apache.geode.cache.client.ClientCache in project geode by apache.

the class SelectStarQueryDUnitTest method testSelectStarQueryForPartitionedRegion.

@Test
public void testSelectStarQueryForPartitionedRegion() throws Exception {
    final Host host = Host.getHost(0);
    final VM server1 = host.getVM(0);
    final VM server2 = host.getVM(1);
    final VM server3 = host.getVM(2);
    final VM client = host.getVM(3);
    PortfolioPdx[] portfolios = new PortfolioPdx[10];
    for (int i = 0; i < portfolios.length; i++) {
        portfolios[i] = new PortfolioPdx(i);
    }
    // create servers and regions
    final int port1 = startPartitionedCacheServer(server1, portfolios);
    final int port2 = startPartitionedCacheServer(server2, portfolios);
    final int port3 = startPartitionedCacheServer(server3, portfolios);
    server1.invoke(new SerializableCallable("Set observer") {

        @Override
        public Object call() throws Exception {
            oldObserver = QueryObserverHolder.setInstance(new QueryResultTrackingObserver());
            return null;
        }
    });
    // create client
    client.invoke(new SerializableCallable("Create client") {

        @Override
        public Object call() throws Exception {
            ClientCacheFactory cf = new ClientCacheFactory();
            cf.addPoolServer(getServerHostName(server1.getHost()), port1);
            cf.addPoolServer(getServerHostName(server2.getHost()), port2);
            cf.addPoolServer(getServerHostName(server3.getHost()), port3);
            ClientCache cache = getClientCache(cf);
            cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create(regName);
            return null;
        }
    });
    // put serialized PortfolioPdx objects
    client.invoke(new SerializableCallable("Put objects") {

        @Override
        public Object call() throws Exception {
            Region r1 = getRootRegion(regName);
            for (int i = 10; i < 20; i++) {
                r1.put("key-" + i, new PortfolioPdx(i));
            }
            return null;
        }
    });
    // query remotely from client
    client.invoke(new SerializableCallable("Query") {

        @Override
        public Object call() throws Exception {
            getLogWriter().info("Querying remotely from client");
            QueryService localQS = null;
            QueryService remoteQS = null;
            try {
                localQS = ((ClientCache) getCache()).getLocalQueryService();
                remoteQS = ((ClientCache) getCache()).getQueryService();
            } catch (Exception e) {
                fail("Exception getting query service ", e);
            }
            SelectResults[][] sr = new SelectResults[1][2];
            SelectResults res = null;
            for (int i = 0; i < queries.length; i++) {
                try {
                    res = (SelectResults) localQS.newQuery(queries[i]).execute();
                    sr[0][0] = res;
                    res = (SelectResults) remoteQS.newQuery(queries[i]).execute();
                    sr[0][1] = res;
                    CacheUtils.compareResultsOfWithAndWithoutIndex(sr);
                } catch (Exception e) {
                    fail("Error executing query: " + queries[i], e);
                }
                assertEquals(resultSize[i], res.size());
                if (i == 3) {
                    int cnt = ((Integer) res.iterator().next());
                    assertEquals(20, cnt);
                } else {
                    for (Object rs : res) {
                        if (rs instanceof StructImpl) {
                            for (Object obj : ((StructImpl) rs).getFieldValues()) {
                                if (obj instanceof PortfolioPdx || obj instanceof PositionPdx) {
                                } else {
                                    fail("Result objects for remote client query: " + queries[i] + " should be instance of PortfolioPdx and not " + obj.getClass());
                                }
                            }
                        } else if (rs instanceof PortfolioPdx) {
                        } else {
                            fail("Result objects for remote client query: " + queries[i] + " should be instance of PortfolioPdx and not " + rs.getClass());
                        }
                    }
                }
            }
            return null;
        }
    });
    // verify if objects iterated by query are serialized
    server1.invoke(new SerializableCallable("Get observer") {

        @Override
        public Object call() throws Exception {
            QueryObserver observer = QueryObserverHolder.getInstance();
            assertTrue(QueryObserverHolder.hasObserver());
            assertTrue(observer instanceof QueryResultTrackingObserver);
            QueryResultTrackingObserver resultObserver = (QueryResultTrackingObserver) observer;
            assertTrue(resultObserver.isObjectSerialized());
            return null;
        }
    });
    // verify if objects returned by local server query are not serialized
    server1.invoke(new SerializableCallable("Query") {

        @Override
        public Object call() throws Exception {
            QueryObserver observer = QueryObserverHolder.setInstance(new QueryResultTrackingObserver());
            QueryService qs = null;
            try {
                qs = getCache().getQueryService();
            } catch (Exception e) {
                fail("Exception getting query service ", e);
            }
            SelectResults res = null;
            for (int i = 0; i < queries.length; i++) {
                try {
                    res = (SelectResults) qs.newQuery(queries[i]).execute();
                } catch (Exception e) {
                    fail("Error executing query: " + queries[i], e);
                }
                assertEquals(resultSize[i], res.size());
                if (i == 3) {
                    int cnt = ((Integer) res.iterator().next());
                    assertEquals(20, cnt);
                } else {
                    for (Object rs : res) {
                        if (rs instanceof StructImpl) {
                            for (Object obj : ((StructImpl) rs).getFieldValues()) {
                                if (obj instanceof PortfolioPdx || obj instanceof PositionPdx) {
                                } else {
                                    fail("Result objects for remote client query: " + queries[i] + " should be instance of PortfolioPdx and not " + obj.getClass());
                                }
                            }
                        } else if (rs instanceof PortfolioPdx) {
                        } else {
                            fail("Result objects for remote client query: " + queries[i] + " should be instance of PortfolioPdx and not " + rs.getClass());
                        }
                    }
                }
            }
            observer = QueryObserverHolder.getInstance();
            assertTrue(QueryObserverHolder.hasObserver());
            assertTrue(observer instanceof QueryResultTrackingObserver);
            QueryResultTrackingObserver resultObserver = (QueryResultTrackingObserver) observer;
            assertFalse(resultObserver.isObjectSerialized());
            // reset observer
            QueryObserverHolder.setInstance(oldObserver);
            return null;
        }
    });
    closeCache(client);
    closeCache(server1);
    closeCache(server2);
    closeCache(server3);
}
Also used : PositionPdx(org.apache.geode.cache.query.data.PositionPdx) Host(org.apache.geode.test.dunit.Host) PortfolioPdx(org.apache.geode.cache.query.data.PortfolioPdx) ClientCache(org.apache.geode.cache.client.ClientCache) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) QueryObserver(org.apache.geode.cache.query.internal.QueryObserver) SelectResults(org.apache.geode.cache.query.SelectResults) StructImpl(org.apache.geode.cache.query.internal.StructImpl) QueryService(org.apache.geode.cache.query.QueryService) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 57 with ClientCache

use of org.apache.geode.cache.client.ClientCache in project geode by apache.

the class SelectStarQueryDUnitTest method testSelectStarQueryForReplicatedRegion.

@Test
public void testSelectStarQueryForReplicatedRegion() throws Exception {
    final Host host = Host.getHost(0);
    final VM server1 = host.getVM(1);
    final VM client = host.getVM(3);
    // create servers and regions
    final int port1 = startReplicatedCacheServer(server1);
    server1.invoke(new SerializableCallable("Set observer") {

        @Override
        public Object call() throws Exception {
            oldObserver = QueryObserverHolder.setInstance(new QueryResultTrackingObserver());
            return null;
        }
    });
    // create client
    client.invoke(new SerializableCallable("Create client") {

        @Override
        public Object call() throws Exception {
            ClientCacheFactory cf = new ClientCacheFactory();
            cf.addPoolServer(getServerHostName(server1.getHost()), port1);
            ClientCache cache = getClientCache(cf);
            cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create(regName);
            cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create(regName2);
            return null;
        }
    });
    // put serialized PortfolioPdx objects
    client.invoke(new SerializableCallable("Put objects") {

        @Override
        public Object call() throws Exception {
            Region r1 = getRootRegion(regName);
            Region r2 = getRootRegion(regName2);
            for (int i = 10; i < 20; i++) {
                r1.put("key-" + i, new PortfolioPdx(i));
                r2.put("key-" + i, new PortfolioPdx(i));
            }
            return null;
        }
    });
    // query remotely from client
    client.invoke(new SerializableCallable("Query") {

        @Override
        public Object call() throws Exception {
            getLogWriter().info("Querying remotely from client");
            QueryService localQS = null;
            QueryService remoteQS = null;
            try {
                localQS = ((ClientCache) getCache()).getLocalQueryService();
                remoteQS = ((ClientCache) getCache()).getQueryService();
            } catch (Exception e) {
                fail("Exception getting query service ", e);
            }
            SelectResults res = null;
            SelectResults[][] sr = new SelectResults[1][2];
            for (int i = 0; i < multipleRegionQueries.length; i++) {
                try {
                    res = (SelectResults) localQS.newQuery(multipleRegionQueries[i]).execute();
                    sr[0][0] = res;
                    res = (SelectResults) remoteQS.newQuery(multipleRegionQueries[i]).execute();
                    sr[0][1] = res;
                    CacheUtils.compareResultsOfWithAndWithoutIndex(sr);
                } catch (Exception e) {
                    fail("Error executing query: " + multipleRegionQueries[i], e);
                }
                assertEquals(resultSize2[i], res.size());
                if (i == 4) {
                    int cnt = ((Integer) res.iterator().next());
                    assertEquals(400, cnt);
                } else {
                    for (Object rs : res) {
                        if (rs instanceof StructImpl) {
                            for (Object obj : ((StructImpl) rs).getFieldValues()) {
                                if (obj instanceof PortfolioPdx || obj instanceof PositionPdx) {
                                } else {
                                    fail("Result objects for remote client query: " + multipleRegionQueries[i] + " should be instance of PortfolioPdx and not " + obj.getClass());
                                }
                            }
                        } else if (rs instanceof PortfolioPdx) {
                        } else {
                            fail("Result objects for remote client query: " + multipleRegionQueries[i] + " should be instance of PortfolioPdx and not " + rs.getClass());
                        }
                    }
                }
            }
            return null;
        }
    });
    // verify if objects iterated by query are serialized
    server1.invoke(new SerializableCallable("Get observer") {

        @Override
        public Object call() throws Exception {
            QueryObserver observer = QueryObserverHolder.getInstance();
            assertTrue(QueryObserverHolder.hasObserver());
            assertTrue(observer instanceof QueryResultTrackingObserver);
            QueryResultTrackingObserver resultObserver = (QueryResultTrackingObserver) observer;
            assertTrue(resultObserver.isObjectSerialized());
            return null;
        }
    });
    // verify if objects returned by local server query are not serialized
    server1.invoke(new SerializableCallable("Query") {

        @Override
        public Object call() throws Exception {
            QueryObserver observer = QueryObserverHolder.setInstance(new QueryResultTrackingObserver());
            QueryService qs = null;
            try {
                qs = getCache().getQueryService();
            } catch (Exception e) {
                fail("Exception getting query service ", e);
            }
            SelectResults res = null;
            for (int i = 0; i < multipleRegionQueries.length; i++) {
                try {
                    res = (SelectResults) qs.newQuery(multipleRegionQueries[i]).execute();
                } catch (Exception e) {
                    fail("Error executing query: " + multipleRegionQueries[i], e);
                }
                assertEquals(resultSize2[i], res.size());
                if (i == 4) {
                    int cnt = ((Integer) res.iterator().next());
                    assertEquals(400, cnt);
                } else {
                    for (Object rs : res) {
                        if (rs instanceof StructImpl) {
                            for (Object obj : ((StructImpl) rs).getFieldValues()) {
                                if (obj instanceof PortfolioPdx || obj instanceof PositionPdx) {
                                } else {
                                    fail("Result objects for remote client query: " + multipleRegionQueries[i] + " should be instance of PortfolioPdx and not " + obj.getClass());
                                }
                            }
                        } else if (rs instanceof PortfolioPdx) {
                        } else {
                            fail("Result objects for remote client query: " + multipleRegionQueries[i] + " should be instance of PortfolioPdx and not " + rs.getClass());
                        }
                    }
                }
            }
            observer = QueryObserverHolder.getInstance();
            assertTrue(QueryObserverHolder.hasObserver());
            assertTrue(observer instanceof QueryResultTrackingObserver);
            QueryResultTrackingObserver resultObserver = (QueryResultTrackingObserver) observer;
            assertFalse(resultObserver.isObjectSerialized());
            // reset observer
            QueryObserverHolder.setInstance(oldObserver);
            return null;
        }
    });
    closeCache(client);
    closeCache(server1);
}
Also used : PositionPdx(org.apache.geode.cache.query.data.PositionPdx) Host(org.apache.geode.test.dunit.Host) PortfolioPdx(org.apache.geode.cache.query.data.PortfolioPdx) ClientCache(org.apache.geode.cache.client.ClientCache) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) QueryObserver(org.apache.geode.cache.query.internal.QueryObserver) SelectResults(org.apache.geode.cache.query.SelectResults) StructImpl(org.apache.geode.cache.query.internal.StructImpl) QueryService(org.apache.geode.cache.query.QueryService) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 58 with ClientCache

use of org.apache.geode.cache.client.ClientCache in project geode by apache.

the class SelectStarQueryDUnitTest method testSelectStarQueryForIndexes.

@Test
public void testSelectStarQueryForIndexes() throws Exception {
    final Host host = Host.getHost(0);
    final VM server1 = host.getVM(0);
    final VM client = host.getVM(3);
    // create servers and regions
    final int port1 = startReplicatedCacheServer(server1);
    // create client
    client.invoke(new SerializableCallable("Create client") {

        @Override
        public Object call() throws Exception {
            ClientCacheFactory cf = new ClientCacheFactory();
            cf.addPoolServer(getServerHostName(server1.getHost()), port1);
            ClientCache cache = getClientCache(cf);
            cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create(regName);
            cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create(regName2);
            return null;
        }
    });
    // put serialized PortfolioPdx objects
    client.invoke(new SerializableCallable("Put objects") {

        @Override
        public Object call() throws Exception {
            Region r1 = getRootRegion(regName);
            Region r2 = getRootRegion(regName2);
            for (int i = 10; i < 20; i++) {
                r1.put("key-" + i, new PortfolioPdx(i));
                r2.put("key-" + i, new PortfolioPdx(i));
            }
            return null;
        }
    });
    // create index on exampleRegion1
    server1.invoke(new SerializableCallable("Query") {

        @Override
        public Object call() throws Exception {
            QueryService qs = null;
            try {
                qs = getCache().getQueryService();
                qs.createIndex("status", "status", "/" + regName);
            } catch (Exception e) {
                fail("Exception getting query service ", e);
            }
            return null;
        }
    });
    // query remotely from client
    client.invoke(new SerializableCallable("Query") {

        @Override
        public Object call() throws Exception {
            getLogWriter().info("Querying remotely from client");
            QueryService localQS = null;
            QueryService remoteQS = null;
            try {
                localQS = ((ClientCache) getCache()).getLocalQueryService();
                remoteQS = ((ClientCache) getCache()).getQueryService();
            } catch (Exception e) {
                fail("Exception getting query service ", e);
            }
            SelectResults res = null;
            SelectResults[][] sr = new SelectResults[1][2];
            for (int i = 0; i < multipleRegionQueries.length; i++) {
                try {
                    res = (SelectResults) localQS.newQuery(multipleRegionQueries[i]).execute();
                    sr[0][0] = res;
                    res = (SelectResults) remoteQS.newQuery(multipleRegionQueries[i]).execute();
                    sr[0][1] = res;
                    CacheUtils.compareResultsOfWithAndWithoutIndex(sr);
                } catch (Exception e) {
                    fail("Error executing query: " + multipleRegionQueries[i], e);
                }
                assertEquals(resultSize2[i], res.size());
                if (i == 4) {
                    int cnt = ((Integer) res.iterator().next());
                    assertEquals(400, cnt);
                } else {
                    for (Object rs : res) {
                        if (rs instanceof StructImpl) {
                            for (Object obj : ((StructImpl) rs).getFieldValues()) {
                                if (obj instanceof PortfolioPdx || obj instanceof PositionPdx) {
                                } else {
                                    fail("Result objects for remote client query: " + multipleRegionQueries[i] + " should be instance of PortfolioPdx and not " + obj.getClass());
                                }
                            }
                        } else if (rs instanceof PortfolioPdx) {
                        } else {
                            fail("Result objects for remote client query: " + multipleRegionQueries[i] + " should be instance of PortfolioPdx and not " + rs.getClass());
                        }
                    }
                }
            }
            return null;
        }
    });
    // create index on exampleRegion2
    server1.invoke(new SerializableCallable("Query") {

        @Override
        public Object call() throws Exception {
            QueryService qs = null;
            try {
                qs = getCache().getQueryService();
                qs.createIndex("status", "status", "/" + regName2);
            } catch (Exception e) {
                fail("Exception getting query service ", e);
            }
            return null;
        }
    });
    // query remotely from client
    client.invoke(new SerializableCallable("Query") {

        @Override
        public Object call() throws Exception {
            getLogWriter().info("Querying remotely from client");
            QueryService localQS = null;
            QueryService remoteQS = null;
            try {
                localQS = ((ClientCache) getCache()).getLocalQueryService();
                remoteQS = ((ClientCache) getCache()).getQueryService();
            } catch (Exception e) {
                fail("Exception getting query service ", e);
            }
            SelectResults res = null;
            SelectResults[][] sr = new SelectResults[1][2];
            for (int i = 0; i < multipleRegionQueries.length; i++) {
                try {
                    res = (SelectResults) localQS.newQuery(multipleRegionQueries[i]).execute();
                    sr[0][0] = res;
                    res = (SelectResults) remoteQS.newQuery(multipleRegionQueries[i]).execute();
                    sr[0][1] = res;
                    CacheUtils.compareResultsOfWithAndWithoutIndex(sr);
                } catch (Exception e) {
                    fail("Error executing query: " + multipleRegionQueries[i], e);
                }
                assertEquals(resultSize2[i], res.size());
                if (i == 4) {
                    int cnt = ((Integer) res.iterator().next());
                    assertEquals(400, cnt);
                } else {
                    for (Object rs : res) {
                        if (rs instanceof StructImpl) {
                            for (Object obj : ((StructImpl) rs).getFieldValues()) {
                                if (obj instanceof PortfolioPdx || obj instanceof PositionPdx) {
                                } else {
                                    fail("Result objects for remote client query: " + multipleRegionQueries[i] + " should be instance of PortfolioPdx and not " + obj.getClass());
                                }
                            }
                        } else if (rs instanceof PortfolioPdx) {
                        } else {
                            fail("Result objects for remote client query: " + multipleRegionQueries[i] + " should be instance of PortfolioPdx and not " + rs.getClass());
                        }
                    }
                }
            }
            return null;
        }
    });
    closeCache(client);
    closeCache(server1);
}
Also used : PositionPdx(org.apache.geode.cache.query.data.PositionPdx) Host(org.apache.geode.test.dunit.Host) PortfolioPdx(org.apache.geode.cache.query.data.PortfolioPdx) ClientCache(org.apache.geode.cache.client.ClientCache) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) SelectResults(org.apache.geode.cache.query.SelectResults) StructImpl(org.apache.geode.cache.query.internal.StructImpl) QueryService(org.apache.geode.cache.query.QueryService) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 59 with ClientCache

use of org.apache.geode.cache.client.ClientCache in project geode by apache.

the class SelectStarQueryDUnitTest method testSelectStarQueryForPdxObjectsReadSerializedTrue.

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

        @Override
        public Object call() throws Exception {
            ((GemFireCacheImpl) getCache()).setReadSerialized(true);
            Region r1 = getCache().createRegionFactory(RegionShortcut.REPLICATE).create(regName);
            CacheServer server = getCache().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 cf = new ClientCacheFactory();
            cf.addPoolServer(getServerHostName(server1.getHost()), port);
            ClientCache cache = getClientCache(cf);
            cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create(regName);
            Region r1 = getRootRegion(regName);
            for (int i = 0; i < 20; i++) {
                r1.put("key-" + i, new PortfolioPdx(i));
            }
            return null;
        }
    });
    // query remotely from client
    client.invoke(new SerializableCallable("Query") {

        @Override
        public Object call() throws Exception {
            getLogWriter().info("Querying remotely from client");
            QueryService localQS = null;
            QueryService remoteQS = null;
            try {
                localQS = ((ClientCache) getCache()).getLocalQueryService();
                remoteQS = ((ClientCache) getCache()).getQueryService();
            } catch (Exception e) {
                fail("Exception getting query service ", e);
            }
            SelectResults res = null;
            SelectResults[][] sr = new SelectResults[1][2];
            for (int i = 0; i < queries.length; i++) {
                try {
                    res = (SelectResults) localQS.newQuery(queries[i]).execute();
                    sr[0][0] = res;
                    res = (SelectResults) remoteQS.newQuery(queries[i]).execute();
                    sr[0][1] = res;
                    CacheUtils.compareResultsOfWithAndWithoutIndex(sr);
                } catch (Exception e) {
                    fail("Error executing query: " + queries[i], e);
                }
                assertEquals(resultSize[i], res.size());
                if (i == 3) {
                    int cnt = ((Integer) res.iterator().next());
                    assertEquals(20, cnt);
                } else {
                    for (Object rs : res) {
                        if (rs instanceof StructImpl) {
                            for (Object obj : ((StructImpl) rs).getFieldValues()) {
                                if (obj instanceof PortfolioPdx || obj instanceof PositionPdx) {
                                } else {
                                    fail("Result objects for remote client query: " + queries[i] + " should be instance of PortfolioPdx and not " + obj.getClass());
                                }
                            }
                        } else if (rs instanceof PortfolioPdx) {
                        } else {
                            fail("Result objects for remote client query: " + queries[i] + " should be instance of PortfolioPdx and not " + rs.getClass());
                        }
                    }
                }
            }
            return null;
        }
    });
    closeCache(client);
    closeCache(server1);
}
Also used : PositionPdx(org.apache.geode.cache.query.data.PositionPdx) Host(org.apache.geode.test.dunit.Host) PortfolioPdx(org.apache.geode.cache.query.data.PortfolioPdx) ClientCache(org.apache.geode.cache.client.ClientCache) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) SelectResults(org.apache.geode.cache.query.SelectResults) StructImpl(org.apache.geode.cache.query.internal.StructImpl) QueryService(org.apache.geode.cache.query.QueryService) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Region(org.apache.geode.cache.Region) CacheServer(org.apache.geode.cache.server.CacheServer) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 60 with ClientCache

use of org.apache.geode.cache.client.ClientCache in project geode by apache.

the class SelectStarQueryDUnitTest method functionWithStructTypeInInnerQueryShouldNotThrowException.

@Test
public void functionWithStructTypeInInnerQueryShouldNotThrowException() throws Exception {
    final Host host = Host.getHost(0);
    final VM server1 = host.getVM(0);
    final VM client = host.getVM(3);
    PortfolioPdx[] portfolios = new PortfolioPdx[10];
    for (int i = 0; i < portfolios.length; i++) {
        portfolios[i] = new PortfolioPdx(i);
    }
    // create servers and regions
    final int port1 = startPartitionedCacheServer(server1, portfolios);
    // create client
    client.invoke(new SerializableCallable("Create client") {

        @Override
        public Object call() throws Exception {
            ClientCacheFactory cf = new ClientCacheFactory();
            cf.addPoolServer(getServerHostName(server1.getHost()), port1);
            ClientCache cache = getClientCache(cf);
            cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(regName);
            return null;
        }
    });
    // put serialized PortfolioPdx objects
    client.invoke(new SerializableCallable("Put objects") {

        @Override
        public Object call() throws Exception {
            Region r1 = getRootRegion(regName);
            for (int i = 10; i < 100; i++) {
                r1.put("key-" + i, new PortfolioPdx(i));
            }
            return null;
        }
    });
    // query remotely from client
    client.invoke(new SerializableCallable("Query") {

        @Override
        public Object call() throws Exception {
            getLogWriter().info("Querying remotely from client");
            QueryService remoteQS = null;
            try {
                remoteQS = ((ClientCache) getCache()).getQueryService();
                SelectResults sr = (SelectResults) remoteQS.newQuery("select distinct oP.ID, oP.status, oP.getType from /" + regName + " oP where element(select distinct p.ID, p.status, p.getType from /" + regName + " p where p.ID = oP.ID).status = 'inactive'").execute();
                assertEquals(50, sr.size());
            } catch (Exception e) {
                fail("Exception getting query service ", e);
            }
            return null;
        }
    });
    closeCache(client);
    closeCache(server1);
}
Also used : Host(org.apache.geode.test.dunit.Host) PortfolioPdx(org.apache.geode.cache.query.data.PortfolioPdx) ClientCache(org.apache.geode.cache.client.ClientCache) 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) Region(org.apache.geode.cache.Region) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

ClientCache (org.apache.geode.cache.client.ClientCache)112 Test (org.junit.Test)74 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)73 ClientCacheFactory (org.apache.geode.cache.client.ClientCacheFactory)65 Region (org.apache.geode.cache.Region)64 VM (org.apache.geode.test.dunit.VM)43 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)42 Host (org.apache.geode.test.dunit.Host)40 SecurityTest (org.apache.geode.test.junit.categories.SecurityTest)31 QueryService (org.apache.geode.cache.query.QueryService)26 SelectResults (org.apache.geode.cache.query.SelectResults)25 SecurityTestUtil.createClientCache (org.apache.geode.security.SecurityTestUtil.createClientCache)25 SecurityTestUtil.createProxyRegion (org.apache.geode.security.SecurityTestUtil.createProxyRegion)23 CacheServer (org.apache.geode.cache.server.CacheServer)22 Cache (org.apache.geode.cache.Cache)20 CacheException (org.apache.geode.cache.CacheException)15 PortfolioPdx (org.apache.geode.cache.query.data.PortfolioPdx)13 IOException (java.io.IOException)12 Properties (java.util.Properties)12 IgnoredException (org.apache.geode.test.dunit.IgnoredException)12