Search in sources :

Example 6 with RequestImageMessage

use of org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage in project geode by apache.

the class PersistentRecoveryOrderDUnitTest method testMissingEntryOnDisk.

@Test
public void testMissingEntryOnDisk() throws Exception {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    // Add a hook which will perform some updates while the region is initializing
    vm0.invoke(new SerializableRunnable() {

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

                @Override
                public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof RequestImageMessage) {
                        Cache cache = getCache();
                        Region region = cache.getRegion(REGION_NAME);
                        if (region == null) {
                            LogWriterUtils.getLogWriter().severe("removing listener for PersistentRecoveryOrderDUnitTest because region was not found: " + REGION_NAME);
                            Object old = DistributionMessageObserver.setInstance(null);
                            if (old != this) {
                                LogWriterUtils.getLogWriter().severe("removed listener was not the invoked listener", new Exception("stack trace"));
                            }
                            return;
                        }
                        region.put("A", "B");
                        region.destroy("A");
                        region.put("A", "C");
                    }
                }

                @Override
                public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
                }
            });
        }
    });
    createPersistentRegion(vm0);
    createPersistentRegion(vm1);
    checkForEntry(vm1);
    closeRegion(vm0);
    closeRegion(vm1);
    // This should work
    createPersistentRegion(vm1);
    checkForEntry(vm1);
}
Also used : DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) DiskRegion(org.apache.geode.internal.cache.DiskRegion) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) RequestImageMessage(org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) RevokedPersistentDataException(org.apache.geode.cache.persistence.RevokedPersistentDataException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) AdminException(org.apache.geode.admin.AdminException) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) LockServiceDestroyedException(org.apache.geode.distributed.LockServiceDestroyedException) CacheClosedException(org.apache.geode.cache.CacheClosedException) PersistentReplicatesOfflineException(org.apache.geode.cache.persistence.PersistentReplicatesOfflineException) IOException(java.io.IOException) 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 7 with RequestImageMessage

use of org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage in project geode by apache.

the class PersistentRecoveryOrderDUnitTest method testCrashDuringGII.

/**
   * Test to make sure that if if a member crashes while a GII is in progress, we wait for the
   * member to come back for starting.
   */
@Test
public void testCrashDuringGII() throws Exception {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    LogWriterUtils.getLogWriter().info("Creating region in VM0");
    createPersistentRegion(vm0);
    LogWriterUtils.getLogWriter().info("Creating region in VM1");
    createPersistentRegion(vm1);
    putAnEntry(vm0);
    LogWriterUtils.getLogWriter().info("closing region in vm0");
    closeRegion(vm0);
    updateTheEntry(vm1);
    LogWriterUtils.getLogWriter().info("closing region in vm1");
    closeRegion(vm1);
    // This ought to wait for VM1 to come back
    LogWriterUtils.getLogWriter().info("Creating region in VM0");
    AsyncInvocation future = createPersistentRegionAsync(vm0);
    waitForBlockedInitialization(vm0);
    assertTrue(future.isAlive());
    // Add a hook which will disconnect from the distributed
    // system when the initial image message shows up.
    vm1.invoke(new SerializableRunnable() {

        public void run() {
            sawRequestImageMessage.set(false);
            DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

                @Override
                public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof RequestImageMessage) {
                        DistributionMessageObserver.setInstance(null);
                        disconnectFromDS();
                        synchronized (sawRequestImageMessage) {
                            sawRequestImageMessage.set(true);
                            sawRequestImageMessage.notifyAll();
                        }
                    }
                }

                @Override
                public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
                }
            });
        }
    });
    createPersistentRegion(vm1);
    vm1.invoke(new SerializableRunnable() {

        public void run() {
            synchronized (sawRequestImageMessage) {
                try {
                    while (!sawRequestImageMessage.get()) {
                        sawRequestImageMessage.wait();
                    }
                } catch (InterruptedException ex) {
                }
            }
        }
    });
    waitForBlockedInitialization(vm0);
    assertTrue(future.isAlive());
    // Now create the region again. The initialization should
    // work (the observer was cleared when we disconnected from the DS.
    createPersistentRegion(vm1);
    ;
    future.join(MAX_WAIT);
    if (future.isAlive()) {
        fail("Region not created within" + MAX_WAIT);
    }
    if (future.exceptionOccurred()) {
        throw new Exception(future.getException());
    }
    checkForEntry(vm0);
    checkForEntry(vm1);
    checkForRecoveryStat(vm1, true);
    checkForRecoveryStat(vm0, false);
}
Also used : DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) RequestImageMessage(org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) RevokedPersistentDataException(org.apache.geode.cache.persistence.RevokedPersistentDataException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) AdminException(org.apache.geode.admin.AdminException) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) LockServiceDestroyedException(org.apache.geode.distributed.LockServiceDestroyedException) CacheClosedException(org.apache.geode.cache.CacheClosedException) PersistentReplicatesOfflineException(org.apache.geode.cache.persistence.PersistentReplicatesOfflineException) IOException(java.io.IOException) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 8 with RequestImageMessage

use of org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage in project geode by apache.

the class PersistentPartitionedRegionDUnitTest method testCrashDuringBucketGII2.

/**
   * Another test for bug 41436. If the GII source crashes before the GII is complete, we need to
   * make sure that later we can recover redundancy.
   * 
   * In this test case, we bring the GII down before we bring the source back up, to make sure the
   * source still discovers that the GII target is no longer hosting the bucket.
   * 
   * @throws InterruptedException
   */
@Test
public void testCrashDuringBucketGII2() throws InterruptedException {
    IgnoredException.addIgnoredException("PartitionOfflineException");
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    final VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    createPR(vm0, 1);
    createData(vm0, 0, 1, "value");
    // Add an observer which will close the cache when the GII starts
    vm0.invoke(new SerializableRunnable("Set crashing observer") {

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

                @Override
                public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof RequestImageMessage) {
                        RequestImageMessage rim = (RequestImageMessage) message;
                        if (rim.regionPath.contains("_0")) {
                            DistributionMessageObserver.setInstance(null);
                            getCache().close();
                        }
                    }
                }
            });
        }
    });
    createPR(vm1, 1);
    // Make sure vm1 didn't create the bucket
    assertEquals(Collections.emptySet(), getBucketList(vm1));
    closeCache(vm1);
    AsyncInvocation async0 = createPRAsync(vm0, 1, 0, 113);
    async0.join(500);
    // vm0 should get stuck waiting for vm1 to recover from disk,
    // because vm0 thinks vm1 has the bucket
    assertTrue(async0.isAlive());
    createPR(vm1, 1, 0);
    // Make sure vm0 recovers the bucket
    assertEquals(Collections.singleton(0), getBucketList(vm0));
    // vm1 should satisfy redundancy for the bucket as well
    WaitCriterion ev = new WaitCriterion() {

        public boolean done() {
            return (Collections.singleton(0).equals(getBucketList(vm1)));
        }

        public String description() {
            return null;
        }
    };
    Wait.waitForCriterion(ev, 30 * 1000, 200, true);
    assertEquals(Collections.singleton(0), getBucketList(vm1));
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) 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) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 9 with RequestImageMessage

use of org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage in project geode by apache.

the class PersistentPartitionedRegionDUnitTest method testBug42226.

/**
   * Test for bug 4226. 1. Member A has the bucket 2. Member B starts creating the bucket. It tells
   * member A that it hosts the bucket 3. Member A crashes 4. Member B destroys the bucket and
   * throws a partition offline exception, because it wasn't able to complete initialization. 5.
   * Member A recovers, and gets stuck waiting for member B.
   * 
   * @throws Throwable
   */
// GEODE-1208: time sensitive, multiple non-thread-safe test hooks,
@Category(FlakyTest.class)
// async actions
@Test
public void testBug42226() throws Exception {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    // Add a hook which will disconnect from the distributed
    // system when the initial image message shows up.
    vm0.invoke(new SerializableRunnable() {

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

                @Override
                public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof RequestImageMessage) {
                        RequestImageMessage rim = (RequestImageMessage) message;
                        // Don't disconnect until we see a bucket
                        if (rim.regionPath.contains("_B_")) {
                            DistributionMessageObserver.setInstance(null);
                            disconnectFromDS();
                        }
                    }
                }

                @Override
                public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
                }
            });
        }
    });
    LogWriterUtils.getLogWriter().info("Creating region in VM0");
    createPR(vm0, 1, 0, 1);
    // Make sure we create a bucket
    createData(vm0, 0, 1, "a");
    // This should recover redundancy, which should cause vm0 to disconnect
    IgnoredException ex = IgnoredException.addIgnoredException("PartitionOfflineException");
    try {
        LogWriterUtils.getLogWriter().info("Creating region in VM1");
        createPR(vm1, 1, 0, 1);
        // Make sure get a partition offline exception
        try {
            createData(vm1, 0, 1, "a");
        } catch (RMIException e) {
            // We expect a PartitionOfflineException
            if (!(e.getCause() instanceof PartitionOfflineException)) {
                throw e;
            }
        }
    } finally {
        ex.remove();
    }
    // Make sure vm0 is really disconnected (avoids a race with the observer).
    vm0.invoke(new SerializableRunnable() {

        public void run() {
            disconnectFromDS();
        }
    });
    // This should recreate the bucket
    AsyncInvocation async1 = createPRAsync(vm0, 1, 0, 1);
    async1.getResult(MAX_WAIT);
    checkData(vm1, 0, 1, "a");
}
Also used : RMIException(org.apache.geode.test.dunit.RMIException) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Host(org.apache.geode.test.dunit.Host) RequestImageMessage(org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) 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)

Aggregations

RequestImageMessage (org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage)9 Test (org.junit.Test)8 DistributionManager (org.apache.geode.distributed.internal.DistributionManager)7 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)7 DistributionMessageObserver (org.apache.geode.distributed.internal.DistributionMessageObserver)7 Host (org.apache.geode.test.dunit.Host)7 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)7 VM (org.apache.geode.test.dunit.VM)7 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)7 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)6 IOException (java.io.IOException)4 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)4 IgnoredException (org.apache.geode.test.dunit.IgnoredException)4 Cache (org.apache.geode.cache.Cache)3 CacheClosedException (org.apache.geode.cache.CacheClosedException)3 AdminException (org.apache.geode.admin.AdminException)2 AttributesFactory (org.apache.geode.cache.AttributesFactory)2 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)2 Region (org.apache.geode.cache.Region)2 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)2