Search in sources :

Example 1 with PartitionOfflineException

use of org.apache.geode.cache.persistence.PartitionOfflineException in project geode by apache.

the class PutAllCSDUnitTest method testPartialKeyInPR.

/**
   * Tests partial key putAll to 2 PR servers, because putting data at server side is different
   * between PR and LR. PR does it in postPutAll. It's not running in singleHop putAll
   */
@Test
public void testPartialKeyInPR() throws CacheException, InterruptedException {
    final String title = "testPartialKeyInPR:";
    final Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    final VM server2 = host.getVM(1);
    VM client1 = host.getVM(2);
    VM client2 = host.getVM(3);
    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, true, 0, "ds1");
    final int serverPort2 = createBridgeServer(server2, regionName, 0, true, 0, "ds1");
    createClient(client1, regionName, serverHost, new int[] { serverPort1, serverPort2 }, -1, -1, false, false, true);
    createClient(client2, regionName, serverHost, new int[] { serverPort1, serverPort2 }, -1, -1, false, false, true);
    server1.invoke(addExceptionTag1(expectedExceptions));
    server2.invoke(addExceptionTag1(expectedExceptions));
    client1.invoke(addExceptionTag1(expectedExceptions));
    client2.invoke(addExceptionTag1(expectedExceptions));
    server1.invoke(new CacheSerializableRunnable(title + "server1 add slow listener") {

        @Override
        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regionName);
            region.getAttributesMutator().addCacheListener(new MyListener(true));
        }
    });
    final SharedCounter sc_server2 = new SharedCounter("server2");
    server2.invoke(new CacheSerializableRunnable(title + "server2 add slow listener") {

        @Override
        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regionName);
            region.getAttributesMutator().addCacheListener(new MyListener(server2, true, sc_server2, 10));
        }
    });
    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());
        }
    });
    AsyncInvocation async1 = client1.invokeAsync(new CacheSerializableRunnable(title + "client1 add listener and putAll") {

        @Override
        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regionName);
            region.getAttributesMutator().addCacheListener(new MyListener(false));
            region.registerInterest("ALL_KEYS");
            // create keys
            try {
                doPutAll(regionName, title, numberOfEntries);
                fail("Expect ServerOperationException caused by PutAllParitialResultException");
            } catch (ServerOperationException soe) {
                if (!(soe.getCause() instanceof PartitionOfflineException)) {
                    throw soe;
                }
                if (!soe.getMessage().contains(LocalizedStrings.Region_PutAll_Applied_PartialKeys_At_Server_0.toLocalizedString(region.getFullPath()))) {
                    throw soe;
                }
            }
        }
    });
    // server2 will closeCache after created 10 keys
    ThreadUtils.join(async1, 30 * 1000);
    if (async1.exceptionOccurred()) {
        Assert.fail("Aync1 get exceptions:", async1.getException());
    }
    int client1Size = getRegionSize(client1, regionName);
    // client2Size maybe more than client1Size
    int client2Size = getRegionSize(client2, regionName);
    int server1Size = getRegionSize(server1, regionName);
    LogWriterUtils.getLogWriter().info("region sizes: " + client1Size + "," + client2Size + "," + server1Size);
    // restart server2
    createBridgeServer(server2, regionName, serverPort2, true, 0, "ds1");
    server1Size = getRegionSize(server1, regionName);
    int server2Size = getRegionSize(server2, regionName);
    LogWriterUtils.getLogWriter().info("region sizes after server2 restarted: " + client1Size + "," + client2Size + "," + server1Size + ":" + server2Size);
    assertEquals(client2Size, server1Size);
    assertEquals(client2Size, server2Size);
    // close a server to re-run the test
    closeCache(server2);
    server1Size = getRegionSize(server1, regionName);
    client1.invoke(new CacheSerializableRunnable(title + "client1 does putAll again") {

        @Override
        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regionName);
            // create keys
            try {
                doPutAll(regionName, title + "again:", 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 PartitionOfflineException);
            }
        }
    });
    int new_server1Size = getRegionSize(server1, regionName);
    int new_client1Size = getRegionSize(client1, regionName);
    int new_client2Size = getRegionSize(client2, regionName);
    LogWriterUtils.getLogWriter().info("region sizes after re-run the putAll: " + new_client1Size + "," + new_client2Size + "," + new_server1Size);
    assertEquals(server1Size + numberOfEntries / 2, new_server1Size);
    assertEquals(client1Size + numberOfEntries / 2, new_client1Size);
    assertEquals(client2Size + numberOfEntries / 2, new_client2Size);
    // restart server2
    createBridgeServer(server2, regionName, serverPort2, true, 0, "ds1");
    server1Size = getRegionSize(server1, regionName);
    server2Size = getRegionSize(server2, regionName);
    LogWriterUtils.getLogWriter().info("region sizes after restart server2: " + server1Size + "," + server2Size);
    assertEquals(server1Size, server2Size);
    // add a cacheWriter for server to stop after created 15 keys
    server1.invoke(new CacheSerializableRunnable(title + "server1 execute P2P putAll") {

        @Override
        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regionName);
            // let the server to trigger exception after created 15 keys
            region.getAttributesMutator().setCacheWriter(new MyWriter(15));
        }
    });
    // p2p putAll on PR and expect exception
    server2.invoke(new CacheSerializableRunnable(title + "server2 add listener and putAll") {

        @Override
        public void run2() throws CacheException {
            // create keys
            try {
                doPutAll(regionName, title + "once again:", numberOfEntries);
                fail("Expected a CacheWriterException to be thrown by test");
            } catch (CacheWriterException rte) {
                assertTrue(rte.getMessage().contains("Triggered exception as planned, created 15 keys"));
            }
        }
    });
    new_server1Size = getRegionSize(server1, regionName);
    int new_server2Size = getRegionSize(server2, regionName);
    LogWriterUtils.getLogWriter().info("region sizes after restart server2: " + new_server1Size + "," + new_server2Size);
    assertEquals(server1Size + 15, new_server1Size);
    assertEquals(server2Size + 15, new_server2Size);
    server1.invoke(removeExceptionTag1(expectedExceptions));
    server2.invoke(removeExceptionTag1(expectedExceptions));
    client1.invoke(removeExceptionTag1(expectedExceptions));
    client2.invoke(removeExceptionTag1(expectedExceptions));
    // Stop server
    stopBridgeServers(getCache());
}
Also used : CacheException(org.apache.geode.cache.CacheException) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) 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)

Example 2 with PartitionOfflineException

use of org.apache.geode.cache.persistence.PartitionOfflineException in project geode by apache.

the class PersistentPartitionedRegionDUnitTest method testRevokedMemberRedundancy0.

/**
   * Test to make sure that we recreate a bucket if a member is revoked
   */
@Test
public void testRevokedMemberRedundancy0() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    createPR(vm0, 0);
    createPR(vm1, 0);
    createData(vm0, 0, NUM_BUCKETS, "a");
    Set<Integer> vm0Buckets = getBucketList(vm0);
    Set<Integer> vm1Buckets = getBucketList(vm1);
    int aVM0Bucket = vm0Buckets.iterator().next();
    int aVM1Bucket = vm1Buckets.iterator().next();
    closeCache(vm1);
    // This should work, because this bucket is still available.
    checkData(vm0, aVM0Bucket, aVM0Bucket + 1, "a");
    IgnoredException expect = IgnoredException.addIgnoredException("PartitionOfflineException", vm0);
    try {
        checkData(vm0, aVM1Bucket, aVM1Bucket + 1, "a");
        fail("Should not have been able to read from missing buckets!");
    } catch (RMIException e) {
        if (!(e.getCause() instanceof PartitionOfflineException)) {
            throw e;
        }
    }
    try {
        createData(vm0, aVM1Bucket, aVM1Bucket + 1, "b");
        fail("Should not have been able to write to missing buckets!");
    } catch (RMIException e) {
        // We expect to see a partition offline exception here.
        if (!(e.getCause() instanceof PartitionOfflineException)) {
            throw e;
        }
    }
    expect.remove();
    // This should work, because these are new buckets
    createData(vm0, NUM_BUCKETS, 113, "a");
    revokeKnownMissingMembers(vm2, 1);
    createPR(vm2, 0);
    // We should be able to use that missing bucket now
    checkData(vm2, aVM1Bucket, aVM1Bucket + 1, null);
    createData(vm2, aVM1Bucket, aVM1Bucket + 1, "a");
    checkData(vm2, aVM1Bucket, aVM1Bucket + 1, "a");
    IgnoredException ex = IgnoredException.addIgnoredException(RevokedPersistentDataException.class.getName(), vm1);
    try {
        createPR(vm1, 0);
        fail("Should have recieved a RevokedPersistentDataException");
    } catch (RMIException e) {
        // We revoked this member.
        if (!(e.getCause() instanceof RevokedPersistentDataException)) {
            throw e;
        }
    }
    ex.remove();
}
Also used : RevokedPersistentDataException(org.apache.geode.cache.persistence.RevokedPersistentDataException) RMIException(org.apache.geode.test.dunit.RMIException) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) VM(org.apache.geode.test.dunit.VM) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Host(org.apache.geode.test.dunit.Host) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 3 with PartitionOfflineException

use of org.apache.geode.cache.persistence.PartitionOfflineException in project geode by apache.

the class PersistentColocatedPartitionedRegionDUnitTest method testRecoverySystemWithConcurrentPutter.

/**
   * Test what happens when we restart persistent members while there is an accessor concurrently
   * performing puts. This is for bug 43899
   */
@Test
public void testRecoverySystemWithConcurrentPutter() throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    VM vm3 = host.getVM(3);
    // Define all of the runnables used in this test
    // runnable to create accessors
    SerializableRunnable createAccessor = new SerializableRunnable("createAccessor") {

        public void run() {
            Cache cache = getCache();
            AttributesFactory af = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setRedundantCopies(1);
            paf.setLocalMaxMemory(0);
            af.setPartitionAttributes(paf.create());
            af.setDataPolicy(DataPolicy.PARTITION);
            cache.createRegion(PR_REGION_NAME, af.create());
            paf.setColocatedWith(PR_REGION_NAME);
            af.setPartitionAttributes(paf.create());
            cache.createRegion("region2", af.create());
        }
    };
    // runnable to create PRs
    SerializableRunnable createPRs = new SerializableRunnable("createPRs") {

        public void run() {
            Cache cache = getCache();
            DiskStore ds = cache.findDiskStore("disk");
            if (ds == null) {
                ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
            }
            AttributesFactory af = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setRedundantCopies(1);
            af.setPartitionAttributes(paf.create());
            af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
            af.setDiskStoreName("disk");
            cache.createRegion(PR_REGION_NAME, af.create());
            paf.setColocatedWith(PR_REGION_NAME);
            af.setPartitionAttributes(paf.create());
            cache.createRegion("region2", af.create());
        }
    };
    // runnable to close the cache.
    SerializableRunnable closeCache = new SerializableRunnable("closeCache") {

        public void run() {
            closeCache();
        }
    };
    // Runnable to do a bunch of puts handle exceptions
    // due to the fact that member is offline.
    SerializableRunnable doABunchOfPuts = new SerializableRunnable("doABunchOfPuts") {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion(PR_REGION_NAME);
            try {
                for (int i = 0; ; i++) {
                    try {
                        region.get(i % NUM_BUCKETS);
                    } catch (PartitionOfflineException expected) {
                    // do nothing.
                    } catch (PartitionedRegionStorageException expected) {
                    // do nothing.
                    }
                    Thread.yield();
                }
            } catch (CacheClosedException expected) {
            // ok, we're done.
            }
        }
    };
    // Runnable to clean up disk dirs on a members
    SerializableRunnable cleanDiskDirs = new SerializableRunnable("Clean disk dirs") {

        public void run() {
            try {
                cleanDiskDirs();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    };
    // Create the PR two members
    vm1.invoke(createPRs);
    vm2.invoke(createPRs);
    // create the accessor.
    vm0.invoke(createAccessor);
    // Create some buckets.
    createData(vm0, 0, NUM_BUCKETS, "a");
    createData(vm0, 0, NUM_BUCKETS, "a", "region2");
    // backup the system. We use this to get a snapshot of vm1 and vm2
    // when they both are online. Recovering from this backup simulates
    // a simulataneous kill and recovery.
    backup(vm3);
    // close vm1 and vm2.
    vm1.invoke(closeCache);
    vm2.invoke(closeCache);
    // restore the backup
    vm1.invoke(cleanDiskDirs);
    vm2.invoke(cleanDiskDirs);
    restoreBackup(2);
    // in vm0, start doing a bunch of concurrent puts.
    AsyncInvocation async0 = vm0.invokeAsync(doABunchOfPuts);
    // This recovery should not hang (that's what we're testing for
    // here.
    AsyncInvocation async1 = vm1.invokeAsync(createPRs);
    AsyncInvocation async2 = vm2.invokeAsync(createPRs);
    async1.getResult(MAX_WAIT);
    async2.getResult(MAX_WAIT);
    // close the cache in vm0 to stop the async puts.
    vm0.invoke(closeCache);
    // make sure we didn't get an exception
    async0.getResult(MAX_WAIT);
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) CacheClosedException(org.apache.geode.cache.CacheClosedException) IOException(java.io.IOException) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) DiskStore(org.apache.geode.cache.DiskStore) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) PartitionedRegionStorageException(org.apache.geode.cache.PartitionedRegionStorageException) VM(org.apache.geode.test.dunit.VM) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 4 with PartitionOfflineException

use of org.apache.geode.cache.persistence.PartitionOfflineException in project geode by apache.

the class PersistentColocatedPartitionedRegionDUnitTest method replaceOfflineMemberAndRestart.

/**
   * Test for support issue 7870. 1. Run three members with redundancy 1 and recovery delay 0 2.
   * Kill one of the members, to trigger replacement of buckets 3. Shutdown all members and restart.
   * 
   * What was happening is that in the parent PR, we discarded our offline data in one member, but
   * in the child PR the other members ended up waiting for the child bucket to be created in the
   * member that discarded it's offline data.
   * 
   * @throws Throwable
   */
public void replaceOfflineMemberAndRestart(SerializableRunnable createPRs) throws Throwable {
    disconnectAllFromDS();
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    // Create the PR on three members
    vm0.invoke(createPRs);
    vm1.invoke(createPRs);
    vm2.invoke(createPRs);
    // Create some buckets.
    createData(vm0, 0, NUM_BUCKETS, "a");
    createData(vm0, 0, NUM_BUCKETS, "a", "region2");
    // Close one of the members to trigger redundancy recovery.
    closeCache(vm2);
    // Wait until redundancy is recovered.
    waitForRedundancyRecovery(vm0, 1, PR_REGION_NAME);
    waitForRedundancyRecovery(vm0, 1, "region2");
    createData(vm0, 0, NUM_BUCKETS, "b");
    createData(vm0, 0, NUM_BUCKETS, "b", "region2");
    IgnoredException expected = IgnoredException.addIgnoredException("PartitionOfflineException");
    try {
        // Close the remaining members.
        vm0.invoke(new SerializableCallable() {

            public Object call() throws Exception {
                InternalDistributedSystem ds = (InternalDistributedSystem) getCache().getDistributedSystem();
                AdminDistributedSystemImpl.shutDownAllMembers(ds.getDistributionManager(), 600000);
                return null;
            }
        });
        // Make sure that vm-1 is completely disconnected
        // The shutdown all asynchronously finishes the disconnect after
        // replying to the admin member.
        vm1.invoke(new SerializableRunnable() {

            public void run() {
                basicGetSystem().disconnect();
            }
        });
        // Recreate the members. Try to make sure that
        // the member with the latest copy of the buckets
        // is the one that decides to throw away it's copy
        // by starting it last.
        AsyncInvocation async0 = vm0.invokeAsync(createPRs);
        AsyncInvocation async1 = vm1.invokeAsync(createPRs);
        Wait.pause(2000);
        AsyncInvocation async2 = vm2.invokeAsync(createPRs);
        async0.getResult(MAX_WAIT);
        async1.getResult(MAX_WAIT);
        async2.getResult(MAX_WAIT);
        checkData(vm0, 0, NUM_BUCKETS, "b");
        checkData(vm0, 0, NUM_BUCKETS, "b", "region2");
        waitForRedundancyRecovery(vm0, 1, PR_REGION_NAME);
        waitForRedundancyRecovery(vm0, 1, "region2");
        waitForRedundancyRecovery(vm1, 1, PR_REGION_NAME);
        waitForRedundancyRecovery(vm1, 1, "region2");
        waitForRedundancyRecovery(vm2, 1, PR_REGION_NAME);
        waitForRedundancyRecovery(vm2, 1, "region2");
        // Make sure we don't have any extra buckets after the restart
        int totalBucketCount = getBucketList(vm0).size();
        totalBucketCount += getBucketList(vm1).size();
        totalBucketCount += getBucketList(vm2).size();
        assertEquals(2 * NUM_BUCKETS, totalBucketCount);
        totalBucketCount = getBucketList(vm0, "region2").size();
        totalBucketCount += getBucketList(vm1, "region2").size();
        totalBucketCount += getBucketList(vm2, "region2").size();
        assertEquals(2 * NUM_BUCKETS, totalBucketCount);
    } finally {
        expected.remove();
    }
}
Also used : VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Host(org.apache.geode.test.dunit.Host) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) IgnoredException(org.apache.geode.test.dunit.IgnoredException) PartitionedRegionStorageException(org.apache.geode.cache.PartitionedRegionStorageException) RMIException(org.apache.geode.test.dunit.RMIException) CacheClosedException(org.apache.geode.cache.CacheClosedException) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) IOException(java.io.IOException)

Example 5 with PartitionOfflineException

use of org.apache.geode.cache.persistence.PartitionOfflineException in project geode by apache.

the class PersistentColocatedPartitionedRegionDUnitTest method testCrashDuringRedundancySatisfaction.

/**
   * Test what happens when we crash in the middle of satisfying redundancy for a colocated bucket.
   * 
   * @throws Throwable
   */
// This test method is disabled because it is failing
// periodically and causing cruise control failures
// See bug #46748
@Test
public void testCrashDuringRedundancySatisfaction() throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    SerializableRunnable createPRs = new SerializableRunnable("region1") {

        public void run() {
            Cache cache = getCache();
            DiskStore ds = cache.findDiskStore("disk");
            if (ds == null) {
                ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
            }
            AttributesFactory af = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setRedundantCopies(1);
            // Workaround for 44414 - disable recovery delay so we shutdown
            // vm1 at a predictable point.
            paf.setRecoveryDelay(-1);
            paf.setStartupRecoveryDelay(-1);
            af.setPartitionAttributes(paf.create());
            af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
            af.setDiskStoreName("disk");
            cache.createRegion(PR_REGION_NAME, af.create());
            paf.setColocatedWith(PR_REGION_NAME);
            af.setPartitionAttributes(paf.create());
            cache.createRegion("region2", af.create());
        }
    };
    // Create the PR on vm0
    vm0.invoke(createPRs);
    // Create some buckets.
    createData(vm0, 0, NUM_BUCKETS, "a");
    createData(vm0, 0, NUM_BUCKETS, "a", "region2");
    vm1.invoke(createPRs);
    // We shouldn't have created any buckets in vm1 yet.
    assertEquals(Collections.emptySet(), getBucketList(vm1));
    // Add an observer that will disconnect before allowing the peer to
    // GII a colocated bucket. This should leave the peer with only the parent
    // bucket
    vm0.invoke(new SerializableRunnable() {

        public void run() {
            DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

                @Override
                public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof RequestImageMessage) {
                        if (((RequestImageMessage) message).regionPath.contains("region2")) {
                            DistributionMessageObserver.setInstance(null);
                            disconnectFromDS();
                        }
                    }
                }
            });
        }
    });
    IgnoredException ex = IgnoredException.addIgnoredException("PartitionOfflineException", vm1);
    try {
        // as we satisfy redundancy with vm1.
        try {
            RebalanceResults rr = rebalance(vm1);
        } catch (Exception expected) {
            // disconnect
            if (!(expected.getCause() instanceof PartitionOfflineException)) {
                throw expected;
            }
        }
        // Wait for vm0 to be closed by the callback
        vm0.invoke(new SerializableCallable() {

            public Object call() throws Exception {
                Wait.waitForCriterion(new WaitCriterion() {

                    public boolean done() {
                        InternalDistributedSystem ds = basicGetSystem();
                        return ds == null || !ds.isConnected();
                    }

                    public String description() {
                        return "DS did not disconnect";
                    }
                }, MAX_WAIT, 100, true);
                return null;
            }
        });
        // close the cache in vm1
        SerializableCallable disconnectFromDS = new SerializableCallable() {

            public Object call() throws Exception {
                disconnectFromDS();
                return null;
            }
        };
        vm1.invoke(disconnectFromDS);
        // Make sure vm0 is disconnected. This avoids a race where we
        // may still in the process of disconnecting even though the our async listener
        // found the system was disconnected
        vm0.invoke(disconnectFromDS);
    } finally {
        ex.remove();
    }
    // Create the cache and PRs on both members
    AsyncInvocation async0 = vm0.invokeAsync(createPRs);
    AsyncInvocation async1 = vm1.invokeAsync(createPRs);
    async0.getResult(MAX_WAIT);
    async1.getResult(MAX_WAIT);
    // Make sure the data was recovered correctly
    checkData(vm0, 0, NUM_BUCKETS, "a");
    // Workaround for bug 46748.
    checkData(vm0, 0, NUM_BUCKETS, "a", "region2");
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) RequestImageMessage(org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) IgnoredException(org.apache.geode.test.dunit.IgnoredException) PartitionedRegionStorageException(org.apache.geode.cache.PartitionedRegionStorageException) RMIException(org.apache.geode.test.dunit.RMIException) CacheClosedException(org.apache.geode.cache.CacheClosedException) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) IOException(java.io.IOException) DiskStore(org.apache.geode.cache.DiskStore) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) IgnoredException(org.apache.geode.test.dunit.IgnoredException) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) RebalanceResults(org.apache.geode.cache.control.RebalanceResults) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Aggregations

PartitionOfflineException (org.apache.geode.cache.persistence.PartitionOfflineException)19 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)12 Test (org.junit.Test)12 Host (org.apache.geode.test.dunit.Host)10 IgnoredException (org.apache.geode.test.dunit.IgnoredException)10 RMIException (org.apache.geode.test.dunit.RMIException)10 VM (org.apache.geode.test.dunit.VM)10 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)10 IOException (java.io.IOException)9 CacheClosedException (org.apache.geode.cache.CacheClosedException)9 PartitionedRegionStorageException (org.apache.geode.cache.PartitionedRegionStorageException)9 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)9 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)7 AttributesFactory (org.apache.geode.cache.AttributesFactory)6 Cache (org.apache.geode.cache.Cache)6 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)6 DiskStore (org.apache.geode.cache.DiskStore)5 Region (org.apache.geode.cache.Region)4 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)3 CancelException (org.apache.geode.CancelException)2