Search in sources :

Example 1 with ManageBucketReplyMessage

use of org.apache.geode.internal.cache.partitioned.ManageBucketMessage.ManageBucketReplyMessage in project geode by apache.

the class PersistentPartitionedRegionDUnitTest method testCrashDuringBucketCreation.

/**
   * Test for bug 41336
   */
// GEODE-1738
@Category(FlakyTest.class)
@Test
public void testCrashDuringBucketCreation() throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    vm0.invoke(new SerializableRunnable("Install observer") {

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

                @Override
                public void beforeSendMessage(DistributionManager dm, DistributionMessage msg) {
                    if (msg instanceof ManageBucketReplyMessage) {
                        Cache cache = getCache();
                        disconnectFromDS();
                        await().atMost(30, SECONDS).until(() -> {
                            return (cache == null || cache.isClosed());
                        });
                        LogWriterUtils.getLogWriter().info("Cache is confirmed closed");
                    }
                }
            });
        }
    });
    createPR(vm0, 0);
    createPR(vm1, 0);
    createData(vm1, 0, 4, "a");
    Set<Integer> vm1Buckets = getBucketList(vm1);
    // Make sure the test hook ran
    vm0.invoke(new SerializableRunnable("Check for no distributed system") {

        public void run() {
            assertEquals(null, GemFireCacheImpl.getInstance());
        }
    });
    checkData(vm1, 0, 4, "a");
    assertEquals(4, vm1Buckets.size());
    createPR(vm0, 0);
    checkData(vm0, 0, 4, "a");
    assertEquals(vm1Buckets, getBucketList(vm1));
    assertEquals(Collections.emptySet(), getBucketList(vm0));
    closeCache(vm0);
    closeCache(vm1);
    AsyncInvocation async0 = createPRAsync(vm0, 0);
    AsyncInvocation async1 = createPRAsync(vm1, 0);
    async0.getResult();
    async1.getResult();
    checkData(vm0, 0, 4, "a");
    assertEquals(vm1Buckets, getBucketList(vm1));
    assertEquals(Collections.emptySet(), getBucketList(vm0));
}
Also used : DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) ManageBucketReplyMessage(org.apache.geode.internal.cache.partitioned.ManageBucketMessage.ManageBucketReplyMessage) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Cache(org.apache.geode.cache.Cache) Category(org.junit.experimental.categories.Category) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 2 with ManageBucketReplyMessage

use of org.apache.geode.internal.cache.partitioned.ManageBucketMessage.ManageBucketReplyMessage in project geode by apache.

the class Bug41733DUnitTest method testCrashAfterBucketCreation.

/**
   * Test the we can handle a member departing after creating a bucket on the remote node but before
   * we choose a primary
   */
@Test
public void testCrashAfterBucketCreation() throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    vm0.invoke(new SerializableRunnable("Install observer") {

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

                @Override
                public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof ManageBucketReplyMessage) {
                        disconnectFromDS();
                    }
                }
            });
        }
    });
    createPR(vm0, 0);
    // Create a couple of buckets in VM0. This will make sure
    // the next bucket we create will be created in VM 1.
    putData(vm0, 0, 2, "a");
    createPR(vm1, 0);
    // Trigger a bucket creation in VM1, which should cause vm0 to close it's cache.
    try {
        putData(vm0, 3, 4, "a");
        fail("should have received a cache closed exception");
    } catch (RMIException e) {
        if (!(e.getCause() instanceof DistributedSystemDisconnectedException)) {
            throw e;
        }
    }
    assertEquals(Collections.singleton(3), getBucketList(vm1));
    // This shouldn't hang, because the bucket creation should finish,.
    putData(vm1, 3, 4, "a");
}
Also used : RMIException(org.apache.geode.test.dunit.RMIException) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) ManageBucketReplyMessage(org.apache.geode.internal.cache.partitioned.ManageBucketMessage.ManageBucketReplyMessage) Host(org.apache.geode.test.dunit.Host) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

DistributionManager (org.apache.geode.distributed.internal.DistributionManager)2 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)2 DistributionMessageObserver (org.apache.geode.distributed.internal.DistributionMessageObserver)2 ManageBucketReplyMessage (org.apache.geode.internal.cache.partitioned.ManageBucketMessage.ManageBucketReplyMessage)2 Host (org.apache.geode.test.dunit.Host)2 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)2 VM (org.apache.geode.test.dunit.VM)2 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)2 Test (org.junit.Test)2 Cache (org.apache.geode.cache.Cache)1 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)1 RMIException (org.apache.geode.test.dunit.RMIException)1 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)1 Category (org.junit.experimental.categories.Category)1