Search in sources :

Example 36 with DistributedRegion

use of org.apache.geode.internal.cache.DistributedRegion 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

DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)36 Region (org.apache.geode.cache.Region)25 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)16 LocalRegion (org.apache.geode.internal.cache.LocalRegion)14 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)9 VM (org.apache.geode.test.dunit.VM)9 Test (org.junit.Test)9 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)8 Cache (org.apache.geode.cache.Cache)7 Host (org.apache.geode.test.dunit.Host)7 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)7 FunctionException (org.apache.geode.cache.execute.FunctionException)6 IOException (java.io.IOException)5 AttributesFactory (org.apache.geode.cache.AttributesFactory)5 CacheException (org.apache.geode.cache.CacheException)5 IgnoredException (org.apache.geode.test.dunit.IgnoredException)5 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)5 Set (java.util.Set)4 CancelException (org.apache.geode.CancelException)4 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)4