Search in sources :

Example 16 with RegionNotFoundException

use of org.apache.geode.cache.query.RegionNotFoundException in project geode by apache.

the class CqDataUsingPoolDUnitTest method testGetDurableCQsFromPoolOnly.

@Test
public void testGetDurableCQsFromPoolOnly() throws Exception {
    final String regionName = "regionA";
    final Host host = Host.getHost(0);
    VM server = host.getVM(0);
    VM client1 = host.getVM(1);
    VM client2 = host.getVM(2);
    /* Create Server and Client */
    cqDUnitTest.createServer(server);
    final int port = server.invoke(() -> CqQueryUsingPoolDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(server.getHost());
    final String poolName1 = "pool1";
    final String poolName2 = "pool2";
    cqDUnitTest.createPool(client1, poolName1, host0, port);
    cqDUnitTest.createPool(client2, poolName2, host0, port);
    client1.invoke(new CacheSerializableRunnable("Register cq for client 1") {

        @Override
        public void run2() throws CacheException {
            QueryService queryService = null;
            try {
                queryService = (PoolManager.find(poolName1)).getQueryService();
            } catch (Exception cqe) {
                Assert.fail("Failed to getCQService.", cqe);
            }
            try {
                CqAttributesFactory cqAf = new CqAttributesFactory();
                CqAttributes attributes = cqAf.create();
                queryService.newCq("client1DCQ1", "Select * From /root/" + regionName + " where id = 1", attributes, true).execute();
                queryService.newCq("client1DCQ2", "Select * From /root/" + regionName + " where id = 10", attributes, true).execute();
                queryService.newCq("client1NoDC1", "Select * From /root/" + regionName, attributes, false).execute();
                queryService.newCq("client1NoDC2", "Select * From /root/" + regionName + " where id = 3", attributes, false).execute();
            } catch (CqException e) {
                fail("failed", e);
            } catch (CqExistsException e) {
                fail("failed", e);
            } catch (RegionNotFoundException e) {
                fail("failed", e);
            }
        }
    });
    client2.invoke(new CacheSerializableRunnable("Register cq for client 2") {

        @Override
        public void run2() throws CacheException {
            QueryService queryService = null;
            try {
                queryService = (PoolManager.find(poolName2)).getQueryService();
            } catch (Exception cqe) {
                Assert.fail("Failed to getCQService.", cqe);
            }
            try {
                CqAttributesFactory cqAf = new CqAttributesFactory();
                CqAttributes attributes = cqAf.create();
                queryService.newCq("client2DCQ1", "Select * From /root/" + regionName + " where id = 1", attributes, true).execute();
                queryService.newCq("client2DCQ2", "Select * From /root/" + regionName + " where id = 10", attributes, true).execute();
                queryService.newCq("client2DCQ3", "Select * From /root/" + regionName, attributes, true).execute();
                queryService.newCq("client2DCQ4", "Select * From /root/" + regionName + " where id = 3", attributes, true).execute();
            } catch (CqException e) {
                fail("failed", e);
            } catch (CqExistsException e) {
                fail("failed", e);
            } catch (RegionNotFoundException e) {
                fail("failed", e);
            }
        }
    });
    client2.invoke(new CacheSerializableRunnable("test getDurableCQsFromServer for client2") {

        @Override
        public void run2() throws CacheException {
            QueryService queryService = null;
            try {
                queryService = (PoolManager.find(poolName2)).getQueryService();
            } catch (Exception cqe) {
                Assert.fail("Failed to getCQService.", cqe);
            }
            List<String> list = null;
            try {
                list = queryService.getAllDurableCqsFromServer();
            } catch (CqException e) {
                fail("failed", e);
            }
            assertEquals(4, list.size());
            assertTrue(list.contains("client2DCQ1"));
            assertTrue(list.contains("client2DCQ2"));
            assertTrue(list.contains("client2DCQ3"));
            assertTrue(list.contains("client2DCQ4"));
        }
    });
    client1.invoke(new CacheSerializableRunnable("test getDurableCQsFromServer for client1") {

        @Override
        public void run2() throws CacheException {
            QueryService queryService = null;
            try {
                queryService = (PoolManager.find(poolName1)).getQueryService();
            } catch (Exception cqe) {
                Assert.fail("Failed to getCQService.", cqe);
            }
            List<String> list = null;
            try {
                list = queryService.getAllDurableCqsFromServer();
            } catch (CqException e) {
                fail("failed", e);
            }
            assertEquals(2, list.size());
            assertTrue(list.contains("client1DCQ1"));
            assertTrue(list.contains("client1DCQ2"));
        }
    });
    cqDUnitTest.closeClient(client2);
    cqDUnitTest.closeClient(client1);
    cqDUnitTest.closeServer(server);
}
Also used : CacheException(org.apache.geode.cache.CacheException) CqException(org.apache.geode.cache.query.CqException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) Host(org.apache.geode.test.dunit.Host) CqExistsException(org.apache.geode.cache.query.CqExistsException) CqException(org.apache.geode.cache.query.CqException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CacheException(org.apache.geode.cache.CacheException) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryService(org.apache.geode.cache.query.QueryService) CqAttributes(org.apache.geode.cache.query.CqAttributes) VM(org.apache.geode.test.dunit.VM) CqExistsException(org.apache.geode.cache.query.CqExistsException) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) List(java.util.List) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 17 with RegionNotFoundException

use of org.apache.geode.cache.query.RegionNotFoundException in project geode by apache.

the class CqDataUsingPoolDUnitTest method createCq.

private CqQuery createCq(String regionName, String cqName) {
    // Create CQ Attributes.
    CqAttributesFactory cqAf = new CqAttributesFactory();
    // Initialize and set CqListener.
    CqListener[] cqListeners = { new CqListener() {

        @Override
        public void close() {
        }

        @Override
        public void onEvent(CqEvent aCqEvent) {
        }

        @Override
        public void onError(CqEvent aCqEvent) {
        }
    } };
    cqAf.initCqListeners(cqListeners);
    CqAttributes cqa = cqAf.create();
    // Create cq's
    // Get the query service for the Pool
    QueryService queryService = CacheServerTestUtil.getCache().getQueryService();
    CqQuery query = null;
    try {
        query = queryService.newCq(cqName, "Select * from /" + regionName, cqa);
        query.execute();
    } catch (CqExistsException e) {
        fail("Could not find specified region:" + regionName + ":", e);
    } catch (CqException e) {
        fail("Could not find specified region:" + regionName + ":", e);
    } catch (RegionNotFoundException e) {
        fail("Could not find specified region:" + regionName + ":", e);
    }
    return query;
}
Also used : CqEvent(org.apache.geode.cache.query.CqEvent) CqAttributes(org.apache.geode.cache.query.CqAttributes) QueryService(org.apache.geode.cache.query.QueryService) CqListener(org.apache.geode.cache.query.CqListener) CqException(org.apache.geode.cache.query.CqException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CqExistsException(org.apache.geode.cache.query.CqExistsException) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) CqQuery(org.apache.geode.cache.query.CqQuery)

Example 18 with RegionNotFoundException

use of org.apache.geode.cache.query.RegionNotFoundException in project geode by apache.

the class DurableClientSimpleDUnitTest method testReadyForEventsNotCalledImplicitlyWithCacheXML.

/**
   * This test method is disabled because it is failing periodically and causing cruise control
   * failures See bug #47060 (test seems to be enabled now!)
   */
@Test
public void testReadyForEventsNotCalledImplicitlyWithCacheXML() {
    try {
        setPeriodicACKObserver(durableClientVM);
        final String cqName = "cqTest";
        // Start a server
        int serverPort = (Integer) this.server1VM.invoke(() -> CacheServerTestUtil.createCacheServerFromXml(DurableClientTestCase.class.getResource("durablecq-server-cache.xml")));
        // Start a durable client that is not kept alive on the server when it
        // stops normally
        final String durableClientId = getName() + "_client";
        // create client cache from xml
        this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClientFromXml(DurableClientTestCase.class.getResource("durablecq-client-cache.xml"), "client", durableClientId, 45, Boolean.FALSE));
        // verify that readyForEvents has not yet been called on all the client's pools
        this.durableClientVM.invoke(new CacheSerializableRunnable("check readyForEvents not called") {

            @Override
            public void run2() throws CacheException {
                for (Pool p : PoolManager.getAll().values()) {
                    assertEquals(false, ((PoolImpl) p).getReadyForEventsCalled());
                }
            }
        });
        // Send clientReady message
        this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {

            @Override
            public void run2() throws CacheException {
                CacheServerTestUtil.getCache().readyForEvents();
            }
        });
        registerDurableCq(cqName);
        // Verify durable client on server1
        this.server1VM.invoke(new CacheSerializableRunnable("Verify durable client") {

            @Override
            public void run2() throws CacheException {
                // Find the proxy
                checkNumberOfClientProxies(1);
                CacheClientProxy proxy = getClientProxy();
                assertNotNull(proxy);
                // Verify that it is durable
                assertTrue(proxy.isDurable());
                assertEquals(durableClientId, proxy.getDurableId());
            }
        });
        // Start normal publisher client
        this.publisherClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(getClientPool(getServerHostName(publisherClientVM.getHost()), serverPort, false), regionName));
        // Publish some entries
        final int numberOfEntries = 10;
        publishEntries(numberOfEntries);
        // Verify the durable client received the updates
        this.durableClientVM.invoke(new CacheSerializableRunnable("Verify updates") {

            @Override
            public void run2() throws CacheException {
                // Get the region
                Region region = CacheServerTestUtil.getCache().getRegion(regionName);
                assertNotNull(region);
                // Get the listener and wait for the appropriate number of events
                QueryService queryService = CacheServerTestUtil.getPool().getQueryService();
                CqQuery cqQuery = queryService.getCq(cqName);
                CacheServerTestUtil.ControlCqListener cqlistener = (CacheServerTestUtil.ControlCqListener) cqQuery.getCqAttributes().getCqListener();
                cqlistener.waitWhileNotEnoughEvents(30000, numberOfEntries);
                assertEquals(numberOfEntries, cqlistener.events.size());
            }
        });
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            fail("interrupted", e);
        }
        // Stop the durable client
        this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache(new Boolean(true)));
        // Verify the durable client still exists on the server
        this.server1VM.invoke(new CacheSerializableRunnable("Verify durable client") {

            @Override
            public void run2() throws CacheException {
                // Find the proxy
                CacheClientProxy proxy = getClientProxy();
                assertNotNull(proxy);
            }
        });
        // Publish some more entries
        publishEntries(numberOfEntries);
        this.publisherClientVM.invoke(() -> CacheServerTestUtil.closeCache());
        // Re-start the durable client
        this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClientFromXml(DurableClientTestCase.class.getResource("durablecq-client-cache.xml"), "client", durableClientId, 45, Boolean.FALSE));
        // Durable client registers durable cq on server
        this.durableClientVM.invoke(new CacheSerializableRunnable("Register cq") {

            @Override
            public void run2() throws CacheException {
                // Get the region
                Region region = CacheServerTestUtil.getCache().getRegion(regionName);
                assertNotNull(region);
                // Create CQ Attributes.
                CqAttributesFactory cqAf = new CqAttributesFactory();
                // Initialize and set CqListener.
                CqListener[] cqListeners = { new CacheServerTestUtil.ControlCqListener() };
                cqAf.initCqListeners(cqListeners);
                CqAttributes cqa = cqAf.create();
                // Create cq's
                // Get the query service for the Pool
                QueryService queryService = CacheServerTestUtil.getPool().getQueryService();
                try {
                    CqQuery query = queryService.newCq(cqName, "Select * from /" + regionName, cqa, true);
                    query.execute();
                } catch (CqExistsException e) {
                    fail("Failed due to ", e);
                } catch (CqException e) {
                    fail("Failed due to ", e);
                } catch (RegionNotFoundException e) {
                    fail("Could not find specified region:" + regionName + ":", e);
                }
            }
        });
        // Send clientReady message
        this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {

            @Override
            public void run2() throws CacheException {
                CacheServerTestUtil.getCache().readyForEvents();
            }
        });
        // Verify durable client on server
        this.server1VM.invoke(new CacheSerializableRunnable("Verify durable client") {

            @Override
            public void run2() throws CacheException {
                // Find the proxy
                checkNumberOfClientProxies(1);
                CacheClientProxy proxy = getClientProxy();
                assertNotNull(proxy);
                // Verify that it is durable and its properties are correct
                assertTrue(proxy.isDurable());
                assertEquals(durableClientId, proxy.getDurableId());
            }
        });
        // Verify the durable client received the updates held for it on the server
        this.durableClientVM.invoke(new CacheSerializableRunnable("Verify updates") {

            @Override
            public void run2() throws CacheException {
                // Get the region
                Region region = CacheServerTestUtil.getCache().getRegion(regionName);
                assertNotNull(region);
                QueryService queryService = CacheServerTestUtil.getPool().getQueryService();
                CqQuery cqQuery = queryService.getCq(cqName);
                CacheServerTestUtil.ControlCqListener cqlistener = (CacheServerTestUtil.ControlCqListener) cqQuery.getCqAttributes().getCqListener();
                cqlistener.waitWhileNotEnoughEvents(30000, numberOfEntries);
                assertEquals(numberOfEntries, cqlistener.events.size());
            }
        });
        // Stop the durable client
        this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache());
        // Stop the server
        this.server1VM.invoke(() -> CacheServerTestUtil.closeCache());
    } finally {
        unsetPeriodicACKObserver(durableClientVM);
    }
}
Also used : CacheException(org.apache.geode.cache.CacheException) CqException(org.apache.geode.cache.query.CqException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryService(org.apache.geode.cache.query.QueryService) CqAttributes(org.apache.geode.cache.query.CqAttributes) CqExistsException(org.apache.geode.cache.query.CqExistsException) Region(org.apache.geode.cache.Region) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) Pool(org.apache.geode.cache.client.Pool) CqQuery(org.apache.geode.cache.query.CqQuery) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 19 with RegionNotFoundException

use of org.apache.geode.cache.query.RegionNotFoundException in project geode by apache.

the class EquiJoinIntegrationTest method testSingleFilterWithSingleEquijoinMultipleFiltersOnSameRegionOnSameIteratorMapping.

@Test
public void testSingleFilterWithSingleEquijoinMultipleFiltersOnSameRegionOnSameIteratorMapping() throws Exception {
    createRegions();
    String[] queries = new String[] { "select * from /region1 c, /region2 s where c.pkid=1 and c.pkid = s.pkid and c.id = 1", "select * from /region1 c, /region2 s where c.id = 1 and c.pkid=1 and s.pkid = c.pkid" };
    for (int i = 0; i < 1000; i++) {
        region1.put(i, new Customer(i, i % 10));
        region2.put(i, new Customer(i, i));
    }
    executeQueriesWithIndexCombinations(queries, new DefaultIndexCreatorCallback(qs) {

        Index secondaryIndex;

        @Override
        public void createIndexForRegion1(int indexTypeId) throws RegionNotFoundException, IndexExistsException, IndexNameConflictException {
            secondaryIndex = qs.createIndex("region1 id", "p.id", "/region1 p");
            super.createIndexForRegion1(indexTypeId);
        }

        @Override
        public void destroyIndexForRegion1(int indexTypeId) {
            qs.removeIndex(secondaryIndex);
            super.destroyIndexForRegion1(indexTypeId);
        }
    }, false);
}
Also used : IndexExistsException(org.apache.geode.cache.query.IndexExistsException) IndexNameConflictException(org.apache.geode.cache.query.IndexNameConflictException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) Index(org.apache.geode.cache.query.Index) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 20 with RegionNotFoundException

use of org.apache.geode.cache.query.RegionNotFoundException in project geode by apache.

the class EquiJoinIntegrationTest method testSingleFilterWithSingleEquijoinLimit.

@Test
public void testSingleFilterWithSingleEquijoinLimit() throws Exception {
    // In this test we are hoping the index being used will properly use the limit while taking into
    // consideration the filters of c.id and c.pkid
    // This test is set up so that if the pkid index is used and limit applied, if id is not taken
    // into consideration until later stages, it will lead to incorrect results (0)
    createRegions();
    String[] queries = new String[] { "select * from /region1 c, /region2 s where c.id = 3 and c.pkid > 2  and c.pkid = s.pkid limit 1" };
    for (int i = 0; i < 1000; i++) {
        region1.put(i, new Customer(i, i % 10));
        region2.put(i, new Customer(i, i));
    }
    executeQueriesWithIndexCombinations(queries, new DefaultIndexCreatorCallback(qs) {

        Index secondaryIndex;

        @Override
        public void createIndexForRegion1(int indexTypeId) throws RegionNotFoundException, IndexExistsException, IndexNameConflictException {
            secondaryIndex = qs.createIndex("region1 id", "p.id", "/region1 p");
            super.createIndexForRegion1(indexTypeId);
        }

        @Override
        public void destroyIndexForRegion1(int indexTypeId) {
            qs.removeIndex(secondaryIndex);
            super.destroyIndexForRegion1(indexTypeId);
        }
    }, true);
}
Also used : IndexExistsException(org.apache.geode.cache.query.IndexExistsException) IndexNameConflictException(org.apache.geode.cache.query.IndexNameConflictException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) Index(org.apache.geode.cache.query.Index) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

RegionNotFoundException (org.apache.geode.cache.query.RegionNotFoundException)26 Test (org.junit.Test)11 Region (org.apache.geode.cache.Region)9 CqException (org.apache.geode.cache.query.CqException)9 QueryService (org.apache.geode.cache.query.QueryService)9 CqExistsException (org.apache.geode.cache.query.CqExistsException)7 IndexExistsException (org.apache.geode.cache.query.IndexExistsException)7 IndexNameConflictException (org.apache.geode.cache.query.IndexNameConflictException)7 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)7 Cache (org.apache.geode.cache.Cache)6 CacheClosedException (org.apache.geode.cache.CacheClosedException)6 CacheException (org.apache.geode.cache.CacheException)6 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)6 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 CancelException (org.apache.geode.CancelException)5 CqAttributes (org.apache.geode.cache.query.CqAttributes)5 CqAttributesFactory (org.apache.geode.cache.query.CqAttributesFactory)5 CqClosedException (org.apache.geode.cache.query.CqClosedException)5 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)5 Host (org.apache.geode.test.dunit.Host)5