Search in sources :

Example 91 with CacheException

use of org.apache.geode.cache.CacheException 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 92 with CacheException

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

the class DurableClientSimpleDUnitTest method testCloseAllCqsAndDrainEvents.

/**
   * Test functionality to close the cq and drain all events from the ha queue from the server This
   * draining should not affect events that still have register interest
   * 
   * @throws Exception
   */
@Test
public void testCloseAllCqsAndDrainEvents() throws Exception {
    String greaterThan5Query = "select * from /" + regionName + " p where p.ID > 5";
    String allQuery = "select * from /" + regionName + " p where p.ID > -1";
    String lessThan5Query = "select * from /" + regionName + " p where p.ID < 5";
    // Start server 1
    Integer[] ports = ((Integer[]) this.server1VM.invoke(() -> CacheServerTestUtil.createCacheServerReturnPorts(regionName, new Boolean(true))));
    final int serverPort = ports[0].intValue();
    final String durableClientId = getName() + "_client";
    startDurableClient(durableClientVM, durableClientId, serverPort, regionName);
    // register durable cqs
    registerInterest(durableClientVM, regionName, true);
    createCq(durableClientVM, "GreaterThan5", greaterThan5Query, true);
    createCq(durableClientVM, "All", allQuery, true);
    createCq(durableClientVM, "LessThan5", lessThan5Query, true);
    // send client ready
    sendClientReady(durableClientVM);
    // Verify durable client on server
    verifyDurableClientOnServer(server1VM, durableClientId);
    // Stop the durable client
    this.disconnectDurableClient(true);
    // Start normal publisher client
    startClient(publisherClientVM, serverPort, regionName);
    // Publish some entries
    publishEntries(publisherClientVM, regionName, 10);
    this.server1VM.invoke(new CacheSerializableRunnable("Close cq for durable client") {

        @Override
        public void run2() throws CacheException {
            final CacheClientNotifier ccnInstance = CacheClientNotifier.getInstance();
            final CacheClientProxy clientProxy = ccnInstance.getClientProxy(durableClientId);
            ClientProxyMembershipID proxyId = clientProxy.getProxyID();
            try {
                ccnInstance.closeClientCq(durableClientId, "All");
                ccnInstance.closeClientCq(durableClientId, "GreaterThan5");
                ccnInstance.closeClientCq(durableClientId, "LessThan5");
            } catch (CqException e) {
                fail("failed", e);
            }
        }
    });
    // Restart the durable client
    startDurableClient(durableClientVM, durableClientId, serverPort, regionName);
    // Reregister durable cqs
    registerInterest(durableClientVM, regionName, true);
    createCq(durableClientVM, "GreaterThan5", "select * from /" + regionName + " p where p.ID > 5", true);
    createCq(durableClientVM, "All", "select * from /" + regionName + " p where p.ID > -1", true);
    createCq(durableClientVM, "LessThan5", "select * from /" + regionName + " p where p.ID < 5", true);
    // send client ready
    sendClientReady(durableClientVM);
    checkCqListenerEvents(durableClientVM, "GreaterThan5", 0, /* numEventsExpected */
    1, /* numEventsToWaitFor */
    5);
    checkCqListenerEvents(durableClientVM, "LessThan5", 0, /* numEventsExpected */
    1, /* numEventsToWaitFor */
    5);
    checkCqListenerEvents(durableClientVM, "All", 0, /* numEventsExpected */
    1, /* numEventsToWaitFor */
    5);
    checkInterestEvents(durableClientVM, regionName, 10);
    // Stop the durable client
    this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache());
    // Stop the publisher client
    this.publisherClientVM.invoke(() -> CacheServerTestUtil.closeCache());
    // Stop the server
    this.server1VM.invoke(() -> CacheServerTestUtil.closeCache());
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) CqException(org.apache.geode.cache.query.CqException) 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 93 with CacheException

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

the class DurableClientSimpleDUnitTest method testMultipleVMsWithSameDurableId.

/**
   * Test that a second VM with the same durable id cannot connect to the server while the first VM
   * is connected. Also, verify that the first client is not affected by the second one attempting
   * to connect.
   */
@Ignore("TODO: test is disabled")
@Test
public void testMultipleVMsWithSameDurableId() {
    // Start a server
    final int serverPort = ((Integer) this.server1VM.invoke(() -> CacheServerTestUtil.createCacheServer(regionName, new Boolean(true)))).intValue();
    // Start a durable client that is not kept alive on the server when it
    // stops normally
    final String durableClientId = getName() + "_client";
    this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(getClientPool(getServerHostName(durableClientVM.getHost()), serverPort, true), regionName, getClientDistributedSystemProperties(durableClientId), Boolean.TRUE));
    // Send clientReady message
    this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {

        @Override
        public void run2() throws CacheException {
            CacheServerTestUtil.getCache().readyForEvents();
        }
    });
    // Have the durable client register interest in all keys
    this.durableClientVM.invoke(new CacheSerializableRunnable("Register interest") {

        @Override
        public void run2() throws CacheException {
            // Get the region
            Region region = CacheServerTestUtil.getCache().getRegion(regionName);
            assertNotNull(region);
            // Register interest in all keys
            region.registerInterestRegex(".*", InterestResultPolicy.NONE);
        }
    });
    // Attempt to start another durable client VM with the same id.
    this.publisherClientVM.invoke(new CacheSerializableRunnable("Create another durable client") {

        @Override
        public void run2() throws CacheException {
            getSystem(getClientDistributedSystemProperties(durableClientId));
            PoolFactoryImpl pf = (PoolFactoryImpl) PoolManager.createFactory();
            pf.init(getClientPool(getServerHostName(publisherClientVM.getHost()), serverPort, true));
            try {
                pf.create("uncreatablePool");
                fail("Should not have been able to create the pool");
            } catch (ServerRefusedConnectionException expected) {
                // expected exception
                disconnectFromDS();
            } catch (Exception e) {
                Assert.fail("Should not have gotten here", e);
            }
        }
    });
    // 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());
            assertEquals(DistributionConfig.DEFAULT_DURABLE_CLIENT_TIMEOUT, proxy.getDurableTimeout());
        }
    });
    // 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
    verifyDurableClientEvents(this.durableClientVM, numberOfEntries);
    // Stop the publisher client
    this.publisherClientVM.invoke(() -> CacheServerTestUtil.closeCache());
    // Stop the durable client
    this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache());
    // Stop the server
    this.server1VM.invoke(() -> CacheServerTestUtil.closeCache());
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) ServerRefusedConnectionException(org.apache.geode.cache.client.ServerRefusedConnectionException) Region(org.apache.geode.cache.Region) ServerRefusedConnectionException(org.apache.geode.cache.client.ServerRefusedConnectionException) 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) PoolFactoryImpl(org.apache.geode.internal.cache.PoolFactoryImpl) Ignore(org.junit.Ignore) 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 94 with CacheException

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

the class DurableClientSimpleDUnitTest method testCloseCacheProxy.

/**
   * Test functionality to close the durable client and drain all events from the ha queue from the
   * server
   */
@Test
public void testCloseCacheProxy() throws Exception {
    String greaterThan5Query = "select * from /" + regionName + " p where p.ID > 5";
    String allQuery = "select * from /" + regionName + " p where p.ID > -1";
    String lessThan5Query = "select * from /" + regionName + " p where p.ID < 5";
    // Start a server
    int serverPort = ((Integer) this.server1VM.invoke(() -> CacheServerTestUtil.createCacheServer(regionName, new Boolean(true)))).intValue();
    // Start a durable client that is kept alive on the server when it stops
    // normally
    final String durableClientId = getName() + "_client";
    startDurableClient(durableClientVM, durableClientId, serverPort, regionName);
    // register durable cqs
    createCq(durableClientVM, "GreaterThan5", greaterThan5Query, true);
    createCq(durableClientVM, "All", allQuery, true);
    createCq(durableClientVM, "LessThan5", lessThan5Query, true);
    // send client ready
    sendClientReady(durableClientVM);
    // Verify durable client on server
    verifyDurableClientOnServer(server1VM, durableClientId);
    // Stop the durable client
    this.disconnectDurableClient(true);
    // Start normal publisher client
    startClient(publisherClientVM, serverPort, regionName);
    // Publish some entries
    publishEntries(publisherClientVM, regionName, 10);
    // verify cq stats are correct
    checkNumDurableCqs(server1VM, durableClientId, 3);
    checkCqStatOnServer(server1VM, durableClientId, "All", 10);
    checkCqStatOnServer(server1VM, durableClientId, "GreaterThan5", 4);
    checkCqStatOnServer(server1VM, durableClientId, "LessThan5", 5);
    // drop client proxy
    this.server1VM.invoke(new CacheSerializableRunnable("Close client proxy on server for client" + durableClientId) {

        @Override
        public void run2() throws CacheException {
            final CacheClientNotifier ccnInstance = CacheClientNotifier.getInstance();
            final CacheClientProxy clientProxy = ccnInstance.getClientProxy(durableClientId);
            ClientProxyMembershipID proxyId = clientProxy.getProxyID();
            ccnInstance.closeDurableClientProxy(durableClientId);
        }
    });
    // Restart the durable client
    startDurableClient(durableClientVM, durableClientId, serverPort, regionName);
    // check that cqs are no longer registered
    checkNumDurableCqs(server1VM, durableClientId, 0);
    // Reregister durable cqs
    createCq(durableClientVM, "GreaterThan5", "select * from /" + regionName + " p where p.ID > 5", true);
    createCq(durableClientVM, "All", "select * from /" + regionName + " p where p.ID > -1", true);
    createCq(durableClientVM, "LessThan5", "select * from /" + regionName + " p where p.ID < 5", true);
    // Before sending client ready, lets make sure the stats already reflect 0 queued events
    checkCqStatOnServer(server1VM, durableClientId, "LessThan5", 0);
    checkCqStatOnServer(server1VM, durableClientId, "GreaterThan5", 0);
    checkCqStatOnServer(server1VM, durableClientId, "All", 0);
    // send client ready
    sendClientReady(durableClientVM);
    // verify cq events for all 3 cqs are 0 events
    checkCqListenerEvents(durableClientVM, "GreaterThan5", 0, /* numEventsExpected */
    1, /* numEventsToWaitFor */
    5);
    checkCqListenerEvents(durableClientVM, "LessThan5", 0, /* numEventsExpected */
    1, /* numEventsToWaitFor */
    5);
    checkCqListenerEvents(durableClientVM, "All", 0, /* numEventsExpected */
    1, /* numEventsToWaitFor */
    5);
    // Stop the durable client
    this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache());
    // Stop the publisher client
    this.publisherClientVM.invoke(() -> CacheServerTestUtil.closeCache());
    // Stop the server
    this.server1VM.invoke(() -> CacheServerTestUtil.closeCache());
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) 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 95 with CacheException

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

the class DurableClientCrashDUnitTest method verifySimpleDurableClientMultipleServers.

@Override
public void verifySimpleDurableClientMultipleServers() {
    // Verify the durable client is no longer on server1
    this.server1VM.invoke(new CacheSerializableRunnable("Verify durable client") {

        public void run2() throws CacheException {
            // Find the proxy
            checkNumberOfClientProxies(1);
            CacheClientProxy proxy = getClientProxy();
            assertNotNull(proxy);
        }
    });
    // Verify the durable client is no longer on server2
    this.server2VM.invoke(new CacheSerializableRunnable("Verify durable client") {

        public void run2() throws CacheException {
            // Find the proxy
            checkNumberOfClientProxies(1);
            CacheClientProxy proxy = getClientProxy();
            assertNotNull(proxy);
        }
    });
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) 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