Search in sources :

Example 11 with CacheException

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

the class CqQueryOptimizedExecuteDUnitTest method testCqExecuteWithoutQueryExecution.

@Test
public void testCqExecuteWithoutQueryExecution() throws Exception {
    final Host host = Host.getHost(0);
    final VM server = host.getVM(0);
    final VM client = host.getVM(1);
    final int numOfEntries = 10;
    final String cqName = "testCqExecuteWithoutQueryExecution_1";
    createServer(server);
    // Create values.
    createValues(server, regions[0], numOfEntries);
    final int thePort = server.invoke(() -> CqQueryDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(server.getHost());
    // Create client.
    createClient(client, thePort, host0);
    /* Create CQs. */
    createCQ(client, cqName, cqs[0]);
    validateCQCount(client, 1);
    executeCQ(client, cqName, false, null);
    server.invoke(new CacheSerializableRunnable("execute cq") {

        public void run2() throws CacheException {
            assertFalse("CqServiceImpl.EXECUTE_QUERY_DURING_INIT flag should be false ", CqServiceImpl.EXECUTE_QUERY_DURING_INIT);
            int numOfQueryExecutions = (Integer) ((GemFireCacheImpl) getCache()).getCachePerfStats().getStats().get("queryExecutions");
            assertEquals("Number of query executions for cq.execute should be 0 ", 0, numOfQueryExecutions);
        }
    });
    // Create more values.
    server.invoke(new CacheSerializableRunnable("Create values") {

        public void run2() throws CacheException {
            Region region1 = getRootRegion().getSubregion(regions[0]);
            for (int i = numOfEntries + 1; i <= numOfEntries * 2; i++) {
                region1.put(KEY + i, new Portfolio(i));
            }
            LogWriterUtils.getLogWriter().info("### Number of Entries in Region :" + region1.keySet().size());
        }
    });
    waitForCreated(client, cqName, KEY + numOfEntries * 2);
    validateCQ(client, cqName, /* resultSize: */
    noTest, /* creates: */
    numOfEntries, /* updates: */
    0, /* deletes; */
    0, /* queryInserts: */
    numOfEntries, /* queryUpdates: */
    0, /* queryDeletes: */
    0, /* totalEvents: */
    numOfEntries);
    // Update values.
    createValues(server, regions[0], 5);
    createValues(server, regions[0], 10);
    waitForUpdated(client, cqName, KEY + numOfEntries);
    // validate Update events.
    validateCQ(client, cqName, /* resultSize: */
    noTest, /* creates: */
    numOfEntries, /* updates: */
    15, /* deletes; */
    0, /* queryInserts: */
    numOfEntries, /* queryUpdates: */
    15, /* queryDeletes: */
    0, /* totalEvents: */
    numOfEntries + 15);
    // Validate delete events.
    deleteValues(server, regions[0], 5);
    waitForDestroyed(client, cqName, KEY + 5);
    validateCQ(client, cqName, /* resultSize: */
    noTest, /* creates: */
    numOfEntries, /* updates: */
    15, /* deletes; */
    5, /* queryInserts: */
    numOfEntries, /* queryUpdates: */
    15, /* queryDeletes: */
    5, /* totalEvents: */
    numOfEntries + 15 + 5);
    closeClient(client);
    closeServer(server);
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) Portfolio(org.apache.geode.cache.query.data.Portfolio) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Region(org.apache.geode.cache.Region) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 12 with CacheException

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

the class CqQueryUsingPoolDUnitTest method testWithoutCQs.

/**
   * Test without CQs. This was added after an exception encountered with CQService, when there was
   * no CQService initiated.
   */
@Test
public void testWithoutCQs() throws Exception {
    final Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM server2 = host.getVM(1);
    VM client = host.getVM(2);
    createServer(server1);
    createServer(server2);
    final int port1 = server1.invoke(() -> CqQueryUsingPoolDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(server1.getHost());
    final int thePort2 = server2.invoke(() -> CqQueryUsingPoolDUnitTest.getCacheServerPort());
    SerializableRunnable createConnectionPool = new CacheSerializableRunnable("Create region") {

        @Override
        public void run2() throws CacheException {
            getCache();
            IgnoredException.addIgnoredException("java.net.ConnectException||java.net.SocketException");
            AttributesFactory regionFactory = new AttributesFactory();
            regionFactory.setScope(Scope.LOCAL);
            ClientServerTestCase.configureConnectionPool(regionFactory, host0, port1, thePort2, true, -1, -1, null);
            createRegion(regions[0], regionFactory.createRegionAttributes());
        }
    };
    // Create client.
    client.invoke(createConnectionPool);
    server1.invoke(new CacheSerializableRunnable("Create values") {

        @Override
        public void run2() throws CacheException {
            Region region1 = getRootRegion().getSubregion(regions[0]);
            for (int i = 0; i < 20; i++) {
                region1.put("key-string-" + i, "value-" + i);
            }
        }
    });
    // Put some values on the client.
    client.invoke(new CacheSerializableRunnable("Put values client") {

        @Override
        public void run2() throws CacheException {
            Region region1 = getRootRegion().getSubregion(regions[0]);
            for (int i = 0; i < 10; i++) {
                region1.put("key-string-" + i, "client-value-" + i);
            }
        }
    });
    Wait.pause(2 * 1000);
    closeServer(server1);
    closeServer(server2);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 13 with CacheException

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

the class CqQueryUsingPoolDUnitTest method createServer.

public void createServer(VM server, final int thePort, final boolean eviction, final MirrorType mirrorType) {
    SerializableRunnable createServer = new CacheSerializableRunnable("Create Cache Server") {

        @Override
        public void run2() throws CacheException {
            LogWriterUtils.getLogWriter().info("### Create Cache Server. ###");
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.DISTRIBUTED_ACK);
            factory.setMirrorType(mirrorType);
            // setting the eviction attributes.
            if (eviction) {
                EvictionAttributes evictAttrs = EvictionAttributes.createLRUEntryAttributes(100000, EvictionAction.OVERFLOW_TO_DISK);
                factory.setEvictionAttributes(evictAttrs);
            }
            for (int i = 0; i < regions.length; i++) {
                createRegion(regions[i], factory.createRegionAttributes());
            }
            try {
                startBridgeServer(thePort, true);
            } catch (Exception ex) {
                Assert.fail("While starting CacheServer", ex);
            }
        }
    };
    server.invoke(createServer);
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) AttributesFactory(org.apache.geode.cache.AttributesFactory) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CqExistsException(org.apache.geode.cache.query.CqExistsException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) RMIException(org.apache.geode.test.dunit.RMIException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Example 14 with CacheException

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

the class CqQueryDUnitTest method testWithoutCQs.

/**
   * Test without CQs. This was added after an exception encountered with CQService, when there was
   * no CQService intiated.
   * 
   * @throws Exception
   */
@Test
public void testWithoutCQs() throws Exception {
    final Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM server2 = host.getVM(1);
    VM client = host.getVM(2);
    createServer(server1);
    createServer(server2);
    final int port1 = server1.invoke(() -> CqQueryDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(server1.getHost());
    final int thePort2 = server2.invoke(() -> CqQueryDUnitTest.getCacheServerPort());
    SerializableRunnable createConnectionPool = new CacheSerializableRunnable("Create region") {

        public void run2() throws CacheException {
            getCache();
            AttributesFactory regionFactory = new AttributesFactory();
            regionFactory.setScope(Scope.LOCAL);
            ClientServerTestCase.configureConnectionPool(regionFactory, host0, port1, thePort2, true, -1, -1, null);
            createRegion(regions[0], regionFactory.createRegionAttributes());
        }
    };
    // Create client.
    client.invoke(createConnectionPool);
    server1.invoke(new CacheSerializableRunnable("Create values") {

        public void run2() throws CacheException {
            Region region1 = getRootRegion().getSubregion(regions[0]);
            for (int i = 0; i < 20; i++) {
                region1.put("key-string-" + i, "value-" + i);
            }
        }
    });
    // Put some values on the client.
    client.invoke(new CacheSerializableRunnable("Put values client") {

        public void run2() throws CacheException {
            Region region1 = getRootRegion().getSubregion(regions[0]);
            for (int i = 0; i < 10; i++) {
                region1.put("key-string-" + i, "client-value-" + i);
            }
        }
    });
    Wait.pause(2 * 1000);
    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) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 15 with CacheException

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

the class CqQueryDUnitTest method executeAndCloseAndExecuteIRMultipleTimes.

// helps test case where executeIR is called multiple times as well as after close
public void executeAndCloseAndExecuteIRMultipleTimes(VM vm, final String cqName, final String queryStr) {
    vm.invoke(new CacheSerializableRunnable("Create CQ :" + cqName) {

        public void run2() throws CacheException {
            LogWriterUtils.getLogWriter().info("### Create CQ. ###" + cqName);
            // Get CQ Service.
            QueryService cqService = null;
            try {
                cqService = getCache().getQueryService();
            } catch (Exception cqe) {
                cqe.printStackTrace();
                fail("Failed to getCQService.");
            }
            // Create CQ Attributes.
            CqAttributesFactory cqf = new CqAttributesFactory();
            CqListener[] cqListeners = { new CqQueryTestListener(LogWriterUtils.getLogWriter()) };
            cqf.initCqListeners(cqListeners);
            CqAttributes cqa = cqf.create();
            CqQuery cq1;
            // Create CQ.
            try {
                cq1 = cqService.newCq(cqName, queryStr, cqa);
                assertTrue("newCq() state mismatch", cq1.getState().isStopped());
            } catch (Exception ex) {
                AssertionError err = new AssertionError("Failed to create CQ " + cqName + " . ");
                err.initCause(ex);
                LogWriterUtils.getLogWriter().info("CqService is :" + cqService, err);
                throw err;
            }
            try {
                cq1.executeWithInitialResults();
                try {
                    cq1.executeWithInitialResults();
                } catch (IllegalStateException e) {
                // expected
                }
                cq1.close();
                try {
                    cq1.executeWithInitialResults();
                } catch (CqClosedException e) {
                    // expected
                    return;
                }
                fail("should have received cqClosedException");
            } catch (Exception e) {
                fail("exception not expected here " + e);
            }
        }
    });
}
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) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) CqClosedException(org.apache.geode.cache.query.CqClosedException) 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)

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