Search in sources :

Example 16 with CacheException

use of org.apache.geode.cache.CacheException in project geode by apache.

the class CqQueryDUnitTest method validateServerClientRegionEntries.

// HELPER METHODS....
/* For debug purpose - Compares entries in the region */
private void validateServerClientRegionEntries(VM server, VM client, final String regionName) {
    server.invoke(new CacheSerializableRunnable("Server Region Entries") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regionName);
            LogWriterUtils.getLogWriter().info("### Entries in Server :" + region.keySet().size());
        }
    });
    client.invoke(new CacheSerializableRunnable("Client Region Entries") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regionName);
            LogWriterUtils.getLogWriter().info("### Entries in Client :" + region.keySet().size());
        }
    });
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Region(org.apache.geode.cache.Region)

Example 17 with CacheException

use of org.apache.geode.cache.CacheException in project geode by apache.

the class CqQueryDUnitTest method stopExecCQ.

// Stop and execute CQ repeatedly
/* Stop/pause CQ */
private void stopExecCQ(VM vm, final String cqName, final int count) throws Exception {
    vm.invoke(new CacheSerializableRunnable("Stop CQ :" + cqName) {

        public void run2() throws CacheException {
            CqQuery cq1 = null;
            LogWriterUtils.getLogWriter().info("### Stop and Exec CQ. ###" + cqName);
            // Get CQ Service.
            QueryService cqService = null;
            try {
                cqService = getCache().getQueryService();
            } catch (Exception cqe) {
                cqe.printStackTrace();
                fail("Failed to getCqService.");
            }
            // Get CQ.
            try {
                cq1 = cqService.getCq(cqName);
            } catch (Exception ex) {
                ex.printStackTrace();
                fail("Failed to get CQ " + cqName + " . " + ex.getMessage());
            }
            for (int i = 0; i < count; ++i) {
                // Stop CQ.
                try {
                    cq1.stop();
                } catch (Exception ex) {
                    ex.printStackTrace();
                    fail("Count = " + i + "Failed to stop CQ " + cqName + " . " + ex.getMessage());
                }
                assertTrue("Stop CQ state mismatch, count = " + i, cq1.getState().isStopped());
                LogWriterUtils.getLogWriter().info("After stop in Stop and Execute loop, ran successfully, loop count: " + i);
                LogWriterUtils.getLogWriter().info("CQ state: " + cq1.getState());
                // Re-execute CQ
                try {
                    cq1.execute();
                } catch (Exception ex) {
                    ex.printStackTrace();
                    fail("Count = " + i + "Failed to execute CQ " + cqName + " . " + ex.getMessage());
                }
                assertTrue("Execute CQ state mismatch, count = " + i, cq1.getState().isRunning());
                LogWriterUtils.getLogWriter().info("After execute in Stop and Execute loop, ran successfully, loop count: " + i);
                LogWriterUtils.getLogWriter().info("CQ state: " + cq1.getState());
            }
        }
    });
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) QueryService(org.apache.geode.cache.query.QueryService) CqQuery(org.apache.geode.cache.query.CqQuery) CqExistsException(org.apache.geode.cache.query.CqExistsException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CqClosedException(org.apache.geode.cache.query.CqClosedException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Example 18 with CacheException

use of org.apache.geode.cache.CacheException in project geode by apache.

the class CqQueryDUnitTest method clearCQListenerEvents.

public void clearCQListenerEvents(VM vm, final String cqName) {
    vm.invoke(new CacheSerializableRunnable("validate cq count") {

        public void run2() throws CacheException {
            // Get CQ Service.
            QueryService cqService = null;
            try {
                cqService = getCache().getQueryService();
            } catch (Exception cqe) {
                cqe.printStackTrace();
                fail("Failed to getCQService.");
            }
            CqQuery cQuery = cqService.getCq(cqName);
            if (cQuery == null) {
                fail("Failed to get CqQuery for CQ : " + cqName);
            }
            CqAttributes cqAttr = cQuery.getCqAttributes();
            CqListener cqListener = cqAttr.getCqListener();
            CqQueryTestListener listener = (CqQueryTestListener) cqListener;
            listener.getEventHistory();
        }
    });
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) QueryService(org.apache.geode.cache.query.QueryService) CqAttributes(org.apache.geode.cache.query.CqAttributes) CqListener(org.apache.geode.cache.query.CqListener) CqQuery(org.apache.geode.cache.query.CqQuery) CqExistsException(org.apache.geode.cache.query.CqExistsException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CqClosedException(org.apache.geode.cache.query.CqClosedException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Example 19 with CacheException

use of org.apache.geode.cache.CacheException in project geode by apache.

the class CqQueryDUnitTest method waitForCqState.

/**
   * Waits till the CQ state is same as the expected. Waits for max time, if the CQ state is not
   * same as expected throws exception.
   */
public void waitForCqState(VM vm, final String cqName, final int state) {
    vm.invoke(new CacheSerializableRunnable("Wait For cq State") {

        public void run2() throws CacheException {
            // Get CQ Service.
            QueryService cqService = null;
            try {
                cqService = getCache().getQueryService();
            } catch (Exception cqe) {
                cqe.printStackTrace();
                fail("Failed to getCQService.");
            }
            CqQuery cQuery = cqService.getCq(cqName);
            if (cQuery == null) {
                fail("Failed to get CqQuery for CQ : " + cqName);
            }
            // Get CQ State.
            final CqStateImpl cqState = (CqStateImpl) cQuery.getState();
            // Wait max time, till the CQ state is as expected.
            WaitCriterion ev = new WaitCriterion() {

                public boolean done() {
                    return cqState.getState() == state;
                }

                public String description() {
                    return "cqState never became " + state;
                }
            };
            Wait.waitForCriterion(ev, MAX_TIME, 200, true);
        }
    });
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) QueryService(org.apache.geode.cache.query.QueryService) CqQuery(org.apache.geode.cache.query.CqQuery) CqStateImpl(org.apache.geode.cache.query.internal.CqStateImpl) CqExistsException(org.apache.geode.cache.query.CqExistsException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CqClosedException(org.apache.geode.cache.query.CqClosedException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Example 20 with CacheException

use of org.apache.geode.cache.CacheException in project geode by apache.

the class CqQueryDUnitTest method testForSupportedRegionAttributes.

/**
   * Tests execution of queries with NULL in where clause like where ID = NULL etc.
   * 
   * @throws Exception
   */
@Test
public void testForSupportedRegionAttributes() throws Exception {
    final Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM server2 = host.getVM(1);
    VM client = host.getVM(2);
    // Create server with Global scope.
    SerializableRunnable createServer = new CacheSerializableRunnable("Create Cache Server") {

        public void run2() throws CacheException {
            LogWriterUtils.getLogWriter().info("### Create Cache Server. ###");
            // Create region with Global scope
            AttributesFactory factory1 = new AttributesFactory();
            factory1.setScope(Scope.GLOBAL);
            factory1.setMirrorType(MirrorType.KEYS_VALUES);
            createRegion(regions[0], factory1.createRegionAttributes());
            // Create region with non Global, distributed_ack scope
            AttributesFactory factory2 = new AttributesFactory();
            factory2.setScope(Scope.DISTRIBUTED_NO_ACK);
            factory2.setMirrorType(MirrorType.KEYS_VALUES);
            createRegion(regions[1], factory2.createRegionAttributes());
            Wait.pause(2000);
            try {
                startBridgeServer(port, true);
            } catch (Exception ex) {
                Assert.fail("While starting CacheServer", ex);
            }
            Wait.pause(2000);
        }
    };
    server1.invoke(createServer);
    server2.invoke(createServer);
    final int port1 = server1.invoke(() -> CqQueryDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(server1.getHost());
    final int thePort2 = server2.invoke(() -> CqQueryDUnitTest.getCacheServerPort());
    // Create client.
    createClient(client, new int[] { port1, thePort2 }, host0, "-1");
    // Create CQ on region with GLOBAL SCOPE.
    createCQ(client, "testForSupportedRegionAttributes_0", cqs[0]);
    executeCQ(client, "testForSupportedRegionAttributes_0", false, null);
    int size = 5;
    createValues(server1, regions[0], size);
    for (int i = 1; i <= size; i++) {
        waitForCreated(client, "testForSupportedRegionAttributes_0", KEY + i);
    }
    // Create CQ on region with non GLOBAL, DISTRIBUTED_ACK SCOPE.
    createCQ(client, "testForSupportedRegionAttributes_1", cqs[2]);
    String errMsg = "The replicated region " + " specified in CQ creation does not have scope supported by CQ." + " The CQ supported scopes are DISTRIBUTED_ACK and GLOBAL.";
    final String expectedErr = "Cq not registered on primary";
    client.invoke(new CacheSerializableRunnable("Set expect") {

        public void run2() {
            getCache().getLogger().info("<ExpectedException action=add>" + expectedErr + "</ExpectedException>");
        }
    });
    try {
        executeCQ(client, "testForSupportedRegionAttributes_1", false, "CqException");
        fail("The test should have failed with exception, " + errMsg);
    } catch (Exception ex) {
    // Expected.
    } finally {
        client.invoke(new CacheSerializableRunnable("Remove expect") {

            public void run2() {
                getCache().getLogger().info("<ExpectedException action=remove>" + expectedErr + "</ExpectedException>");
            }
        });
    }
    // Close.
    closeClient(client);
    closeServer(server1);
    closeServer(server2);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Host(org.apache.geode.test.dunit.Host) CqExistsException(org.apache.geode.cache.query.CqExistsException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CqClosedException(org.apache.geode.cache.query.CqClosedException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Aggregations

CacheException (org.apache.geode.cache.CacheException)638 Test (org.junit.Test)445 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)407 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)376 VM (org.apache.geode.test.dunit.VM)375 Region (org.apache.geode.cache.Region)351 Host (org.apache.geode.test.dunit.Host)330 AttributesFactory (org.apache.geode.cache.AttributesFactory)204 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)201 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)191 IOException (java.io.IOException)124 LocalRegion (org.apache.geode.internal.cache.LocalRegion)118 QueryService (org.apache.geode.cache.query.QueryService)107 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)85 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)85 SelectResults (org.apache.geode.cache.query.SelectResults)80 IgnoredException (org.apache.geode.test.dunit.IgnoredException)72 ClientSubscriptionTest (org.apache.geode.test.junit.categories.ClientSubscriptionTest)64 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)61 Cache (org.apache.geode.cache.Cache)59