Search in sources :

Example 26 with ServerOperationException

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

the class PutAllCSDUnitTest method doBug51725.

/**
   * One failure found in bug 51725, both for putAll and removeAll: non-singlehop with redundency=1.
   * Do some singlehop putAll to see if retry succeeded after PRE This is a singlehop putAll test.
   */
public void doBug51725(boolean enableSingleHop) throws CacheException, InterruptedException {
    final String title = "doBug51725:";
    int client1Size;
    int client2Size;
    int server1Size;
    int server2Size;
    final Host host = Host.getHost(0);
    final VM server1 = host.getVM(0);
    final VM server2 = host.getVM(1);
    final VM client1 = host.getVM(2);
    final VM client2 = host.getVM(3);
    final String regionName = getUniqueName();
    final String serverHost = NetworkUtils.getServerHostName(server1.getHost());
    final int serverPort1 = createBridgeServer(server1, regionName, 0, true, 0, "ds1");
    final int serverPort2 = createBridgeServer(server2, regionName, 0, true, 0, "ds1");
    createClient(client1, regionName, serverHost, new int[] { serverPort1 }, -1, 59000, false, false, enableSingleHop);
    createClient(client2, regionName, serverHost, new int[] { serverPort1 }, -1, 59000, false, false, enableSingleHop);
    server1.invoke(addExceptionTag1(expectedExceptions));
    server2.invoke(addExceptionTag1(expectedExceptions));
    client1.invoke(addExceptionTag1(expectedExceptions));
    client2.invoke(addExceptionTag1(expectedExceptions));
    client2.invoke(new CacheSerializableRunnable(title + "client2 add listener") {

        @Override
        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regionName);
            region.getAttributesMutator().addCacheListener(new MyListener(false));
            region.registerInterest("ALL_KEYS");
            LogWriterUtils.getLogWriter().info("client2 registerInterest ALL_KEYS at " + region.getFullPath());
        }
    });
    client1.invoke(new CacheSerializableRunnable(title + "put 3 keys then removeAll") {

        @Override
        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regionName);
            region.getAttributesMutator().addCacheListener(new MyListener(false));
            // do putAll to create all buckets
            doPutAll(regionName, "key-", numberOfEntries);
            assertEquals(numberOfEntries, region.size());
        }
    });
    closeCache(server2);
    client1.invoke(new CacheSerializableRunnable(title + "putAll from client again") {

        @Override
        public void run2() throws CacheException {
            LocalRegion region = (LocalRegion) getRootRegion().getSubregion(regionName);
            region.getAttributesMutator().addCacheListener(new MyListener(false));
            try {
                doPutAll(regionName, title, numberOfEntries);
                fail("Expect ServerOperationException caused by PutAllParitialResultException");
            } catch (ServerOperationException soe) {
                assertTrue(soe.getMessage().contains(LocalizedStrings.Region_PutAll_Applied_PartialKeys_At_Server_0.toLocalizedString(region.getFullPath())));
                assertTrue(soe.getCause() instanceof RuntimeException);
            }
            assertEquals(numberOfEntries * 3 / 2, region.size());
            VersionTag tag;
            int cnt = 0;
            for (int i = 0; i < numberOfEntries; i++) {
                tag = region.getVersionTag(title + i);
                if (tag != null && 1 == tag.getEntryVersion()) {
                    cnt++;
                }
            }
            assertEquals(numberOfEntries / 2, cnt);
            try {
                doRemoveAll(regionName, title, numberOfEntries);
            } catch (ServerOperationException soe) {
                assertTrue(soe.getMessage().contains(LocalizedStrings.Region_RemoveAll_Applied_PartialKeys_At_Server_0.toLocalizedString(region.getFullPath())));
                assertTrue(soe.getCause() instanceof RuntimeException);
            }
            Region.Entry re;
            // putAll only created 50 entries, removeAll removed them. So 100 entries are all NULL
            for (int i = 0; i < numberOfEntries; i++) {
                re = region.getEntry(title + i);
                assertNull(re);
            }
        }
    });
    client2.invoke(new CacheSerializableRunnable(title + "verify entries from client2") {

        @Override
        public void run2() throws CacheException {
            Wait.pause(5000);
            Region region = getRootRegion().getSubregion(regionName);
            Region.Entry re;
            for (int i = 0; i < numberOfEntries; i++) {
                re = region.getEntry(title + i);
                assertNull(re);
            }
        }
    });
    // Stop server
    stopBridgeServers(getCache());
}
Also used : CacheException(org.apache.geode.cache.CacheException) Host(org.apache.geode.test.dunit.Host) Entry(org.apache.geode.cache.Region.Entry) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) VM(org.apache.geode.test.dunit.VM) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) Region(org.apache.geode.cache.Region) ServerOperationException(org.apache.geode.cache.client.ServerOperationException)

Example 27 with ServerOperationException

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

the class PutAllCSDUnitTest method testClientDestroyOfUncreatedEntry.

/**
   * Checks to see if a client does a destroy that throws an exception from CacheWriter
   * beforeDestroy that the size of the region is still correct. See bug 51583.
   */
@Test
public void testClientDestroyOfUncreatedEntry() throws CacheException, InterruptedException {
    final String title = "testClientDestroyOfUncreatedEntry:";
    final Host host = Host.getHost(0);
    final VM server1 = host.getVM(0);
    final VM client1 = host.getVM(1);
    final String regionName = getUniqueName();
    final String serverHost = NetworkUtils.getServerHostName(server1.getHost());
    // set <true, false> means <PR=true, notifyBySubscription=false> to test local-invalidates
    final int serverPort1 = createBridgeServer(server1, regionName, 0, false, 0, null);
    createClient(client1, regionName, serverHost, new int[] { serverPort1 }, -1, -1, false, true, true);
    server1.invoke(addExceptionTag1(expectedExceptions));
    client1.invoke(addExceptionTag1(expectedExceptions));
    server1.invoke(new CacheSerializableRunnable(title + "server1 add cacheWriter") {

        @Override
        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regionName);
            // Install cacheWriter that causes the very first destroy to fail
            region.getAttributesMutator().setCacheWriter(new MyWriter(0));
        }
    });
    assertEquals(0, getRegionSize(server1, regionName));
    client1.invoke(new CacheSerializableRunnable(title + "client1 destroy") {

        @Override
        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regionName);
            try {
                region.destroy("bogusKey");
                fail("Expect ServerOperationException caused by CacheWriterException");
            } catch (ServerOperationException expected) {
                assertTrue(expected.getCause() instanceof CacheWriterException);
            }
        }
    });
    assertEquals(0, getRegionSize(server1, regionName));
    server1.invoke(removeExceptionTag1(expectedExceptions));
    client1.invoke(removeExceptionTag1(expectedExceptions));
    stopBridgeServers(getCache());
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) CacheWriterException(org.apache.geode.cache.CacheWriterException) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Aggregations

ServerOperationException (org.apache.geode.cache.client.ServerOperationException)27 ServerConnectivityException (org.apache.geode.cache.client.ServerConnectivityException)11 Region (org.apache.geode.cache.Region)10 CacheException (org.apache.geode.cache.CacheException)9 Host (org.apache.geode.test.dunit.Host)9 VM (org.apache.geode.test.dunit.VM)9 Test (org.junit.Test)7 IOException (java.io.IOException)6 List (java.util.List)6 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)6 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)6 Iterator (java.util.Iterator)5 ExecutionException (java.util.concurrent.ExecutionException)5 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)5 InternalGemFireException (org.apache.geode.InternalGemFireException)5 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)5 VersionedObjectList (org.apache.geode.internal.cache.tier.sockets.VersionedObjectList)5 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)5 ArrayList (java.util.ArrayList)4