Search in sources :

Example 1 with DestroyRegionMessage

use of org.apache.geode.internal.cache.DestroyRegionOperation.DestroyRegionMessage in project geode by apache.

the class PersistentRecoveryOrderDUnitTest method testGIIDuringDestroy.

/**
   * Test to make sure we don't leak any persistent ids if a member does GII while a distributed
   * destroy is in progress
   */
@Test
public void testGIIDuringDestroy() throws Exception {
    Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    final VM vm1 = host.getVM(1);
    final VM vm2 = host.getVM(2);
    LogWriterUtils.getLogWriter().info("Creating region in VM0");
    createPersistentRegion(vm0);
    // Add a hook which will disconnect from the distributed
    // system when the initial image message shows up.
    vm1.invoke(new SerializableRunnable() {

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

                @Override
                public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof DestroyRegionMessage) {
                        createPersistentRegionAsync(vm2);
                        try {
                            Thread.sleep(10000);
                        } catch (InterruptedException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } finally {
                            DistributionMessageObserver.setInstance(null);
                        }
                    }
                }

                @Override
                public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
                }

                @Override
                public void beforeSendMessage(DistributionManager dm, DistributionMessage msg) {
                }
            });
        }
    });
    createPersistentRegion(vm1);
    vm0.invoke(new SerializableRunnable("Destroy region") {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion(REGION_NAME);
            region.destroyRegion();
        }
    });
    vm1.invoke(new SerializableRunnable("check destroyed") {

        public void run() {
            Cache cache = getCache();
            assertNull(cache.getRegion(REGION_NAME));
        }
    });
    vm2.invoke(new SerializableRunnable("Wait for region creation") {

        public void run() {
            final Cache cache = getCache();
            Wait.waitForCriterion(new WaitCriterion() {

                public String description() {
                    return "Waiting for creation of region " + REGION_NAME;
                }

                public boolean done() {
                    Region region = cache.getRegion(REGION_NAME);
                    return region != null;
                }
            }, MAX_WAIT, 100, true);
        }
    });
    vm2.invoke(new SerializableRunnable("Check offline members") {

        public void run() {
            final Cache cache = getCache();
            DistributedRegion region = (DistributedRegion) cache.getRegion(REGION_NAME);
            PersistenceAdvisor persistAdvisor = region.getPersistenceAdvisor();
            assertEquals(Collections.emptySet(), persistAdvisor.getMembershipView().getOfflineMembers());
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) 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) DestroyRegionMessage(org.apache.geode.internal.cache.DestroyRegionOperation.DestroyRegionMessage) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) 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

Cache (org.apache.geode.cache.Cache)1 Region (org.apache.geode.cache.Region)1 DistributionManager (org.apache.geode.distributed.internal.DistributionManager)1 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)1 DistributionMessageObserver (org.apache.geode.distributed.internal.DistributionMessageObserver)1 DestroyRegionMessage (org.apache.geode.internal.cache.DestroyRegionOperation.DestroyRegionMessage)1 DiskRegion (org.apache.geode.internal.cache.DiskRegion)1 DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)1 LocalRegion (org.apache.geode.internal.cache.LocalRegion)1 Host (org.apache.geode.test.dunit.Host)1 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)1 VM (org.apache.geode.test.dunit.VM)1 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)1 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)1 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)1 Test (org.junit.Test)1