Search in sources :

Example 26 with DistributionMessageObserver

use of org.apache.geode.distributed.internal.DistributionMessageObserver in project geode by apache.

the class NetSearchMessagingDUnitTest method testNetSearchFailoverFromOneReplicateToAnother.

@Test
public void testNetSearchFailoverFromOneReplicateToAnother() {
    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);
    // Install a listener to kill this member
    // when we get the netsearch request
    vm0.invoke(new SerializableRunnable("Install listener") {

        public void run() {
            DistributionMessageObserver ob = new DistributionMessageObserver() {

                public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof NetSearchRequestMessage) {
                        disconnectFromDS();
                    }
                }
            };
            DistributionMessageObserver.setInstance(ob);
        }
    });
    createReplicate(vm0);
    createReplicate(vm1);
    createEmpty(vm3);
    // Test with a real value value
    {
        put(vm3, "a", "b");
        boolean disconnected = false;
        while (!disconnected) {
            assertEquals("b", get(vm3, "a"));
            // Make sure we were disconnected in vm0
            disconnected = (Boolean) vm0.invoke(new SerializableCallable("check disconnected") {

                public Object call() {
                    return GemFireCacheImpl.getInstance() == null;
                }
            });
        }
    }
}
Also used : DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) NetSearchRequestMessage(org.apache.geode.internal.cache.SearchLoadAndWriteProcessor.NetSearchRequestMessage) 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)

Example 27 with DistributionMessageObserver

use of org.apache.geode.distributed.internal.DistributionMessageObserver in project geode by apache.

the class ClientsWithVersioningRetryDUnitTest method testRetryPutAll.

/**
   * Test that we can successfully retry a distributed put all and get the version information. bug
   * #45059
   */
@Test
public void testRetryPutAll() {
    Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    final VM vm1 = host.getVM(1);
    final VM vm2 = host.getVM(2);
    final VM vm3 = host.getVM(3);
    createServerRegion(vm0, RegionShortcut.PARTITION_REDUNDANT_PERSISTENT);
    vm0.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            // Make sure the bucket 0 is primary in this member.
            Region region = getCache().getRegion("region");
            region.put(0, "value");
            // Add a listener to close vm1 when we send a distributed put all operation
            // this will cause a retry after we have applied the original put all to
            // the cache, causing a retry
            DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

                @Override
                public void beforeSendMessage(DistributionManager dm, DistributionMessage msg) {
                    if (msg instanceof DistributedPutAllOperation.PutAllMessage) {
                        DistributionMessageObserver.setInstance(null);
                        disconnectFromDS(vm1);
                    }
                }
            });
        }
    });
    int port1 = createServerRegion(vm1, RegionShortcut.PARTITION_REDUNDANT_PERSISTENT);
    int port2 = createServerRegion(vm2, RegionShortcut.PARTITION_REDUNDANT_PERSISTENT);
    createClientRegion(vm3, port1, port2);
    // This will be a put all to bucket 0
    // Here's the expected sequence
    // client->vm1 (accessor0)
    // vm1->vm0
    // vm0 will kill vm1
    // vm0->vm2
    // client will retry the putall
    vm3.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region region = getCache().getRegion("region");
            Map map = new HashMap();
            map.put(0, "a");
            map.put(113, "b");
            region.putAll(map);
            RegionEntry entry = ((LocalRegion) region).getRegionEntry(0);
            assertNotNull(entry);
            assertNotNull(entry.getVersionStamp());
            assertEquals(2, entry.getVersionStamp().getEntryVersion());
            return null;
        }
    });
    // Verify the observer was triggered
    vm0.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            // if the observer was triggered, it would have cleared itself
            assertNull(DistributionMessageObserver.getInstance());
        }
    });
    // Make sure vm1 did in fact shut down
    vm1.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
            assertTrue(cache == null || cache.isClosed());
        }
    });
}
Also used : HashMap(java.util.HashMap) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) IgnoredException(org.apache.geode.test.dunit.IgnoredException) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Region(org.apache.geode.cache.Region) RegionEntry(org.apache.geode.internal.cache.RegionEntry) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Map(java.util.Map) HashMap(java.util.HashMap) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 28 with DistributionMessageObserver

use of org.apache.geode.distributed.internal.DistributionMessageObserver in project geode by apache.

the class ClientsWithVersioningRetryDUnitTest method testRetryPutAllInAccessor.

/**
   * Test that we can successfully retry a distributed putAll on an accessor and get the version
   * information. bug #48205
   */
@Test
public void testRetryPutAllInAccessor() {
    Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    final VM vm1 = host.getVM(1);
    final VM vm2 = host.getVM(2);
    final VM vm3 = host.getVM(3);
    LogWriterUtils.getLogWriter().info("creating region in vm0");
    createRegionInPeer(vm0, RegionShortcut.PARTITION_REDUNDANT_PERSISTENT);
    vm0.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            // Make sure the bucket 0 is primary in this member.
            Region region = getCache().getRegion("region");
            region.put(0, "value");
        }
    });
    LogWriterUtils.getLogWriter().info("creating region in vm1");
    createRegionInPeer(vm1, RegionShortcut.PARTITION_REDUNDANT_PERSISTENT);
    LogWriterUtils.getLogWriter().info("creating region in vm2");
    createRegionInPeer(vm2, RegionShortcut.PARTITION_REDUNDANT_PERSISTENT);
    LogWriterUtils.getLogWriter().info("creating region in vm3");
    createRegionInPeer(vm3, RegionShortcut.PARTITION_PROXY);
    expectedExceptions.add(IgnoredException.addIgnoredException("RuntimeException", vm2));
    vm2.invoke(new SerializableRunnable("install message listener to ignore update") {

        public void run() {
            // Add a listener to close vm2 when we send a distributed put all operation
            // this will cause a retry after we have applied the original put all to
            // the cache, causing a retry
            DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

                @Override
                public void beforeProcessMessage(DistributionManager dm, DistributionMessage msg) {
                    if (msg instanceof DistributedPutAllOperation.PutAllMessage) {
                        DistributionMessageObserver.setInstance(null);
                        // give vm1 time to process the message that we're ignoring
                        Wait.pause(5000);
                        disconnectFromDS(vm0);
                        // because vm0 has been shut down
                        throw new RuntimeException("test code is ignoring message: " + msg);
                    }
                }
            });
        }
    });
    // This will be a put all to bucket 0
    // Here's the expected sequence
    // accessor->vm0 (primary)
    // vm0->vm1, vm2
    // vm2 will ignore the message & kill vm0
    // accessor->vm2 or vm1
    // version tag is recovered and put in the event & cache
    vm3.invoke(new SerializableCallable("perform putAll in accessor") {

        public Object call() throws Exception {
            Region region = getCache().getRegion("region");
            Map map = new HashMap();
            map.put(0, "a");
            map.put(113, "b");
            region.putAll(map);
            return null;
        }
    });
    // verify that the version is correct
    vm1.invoke(new SerializableRunnable("verify vm1") {

        @Override
        public void run() {
            // if the observer was triggered, it would have cleared itself
            assertNull(DistributionMessageObserver.getInstance());
            Region region = getCache().getRegion("region");
            VersionTag tag = ((LocalRegion) region).getVersionTag(0);
            assertEquals(2, tag.getEntryVersion());
        }
    });
    // Verify the observer was triggered and the version is correct
    vm2.invoke(new SerializableRunnable("verify vm2") {

        @Override
        public void run() {
            // if the observer was triggered, it would have cleared itself
            assertNull(DistributionMessageObserver.getInstance());
            Region region = getCache().getRegion("region");
            VersionTag tag = ((LocalRegion) region).getVersionTag(0);
            assertEquals(2, tag.getEntryVersion());
        }
    });
    // Make sure vm1 did in fact shut down
    vm0.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
            assertTrue(cache == null || cache.isClosed());
        }
    });
}
Also used : HashMap(java.util.HashMap) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) IgnoredException(org.apache.geode.test.dunit.IgnoredException) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) VMVersionTag(org.apache.geode.internal.cache.versions.VMVersionTag) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Region(org.apache.geode.cache.Region) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Map(java.util.Map) HashMap(java.util.HashMap) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 29 with DistributionMessageObserver

use of org.apache.geode.distributed.internal.DistributionMessageObserver in project geode by apache.

the class PartitionedRegionQueryDUnitTest method testRebalanceDuringQueryEvaluation.

/**
   * Test of bug 43102. 1. Buckets are created on several nodes 2. A query is started 3. While the
   * query is executing, several buckets are moved.
   */
@Test
public void testRebalanceDuringQueryEvaluation() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    createAccessor(vm0);
    createPR(vm1);
    createBuckets(vm1);
    createPR(vm2);
    // Add a listener that will trigger a rebalance
    // as soon as the query arrives on this node.
    vm1.invoke(new SerializableRunnable("add listener") {

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

                @Override
                public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof QueryMessage) {
                        RebalanceOperation rebalance = getCache().getResourceManager().createRebalanceFactory().start();
                        // wait for the rebalance
                        try {
                            rebalanceResults.compareAndSet(null, rebalance.getResults());
                        } catch (CancellationException e) {
                        // ignore
                        } catch (InterruptedException e) {
                        // ignore
                        }
                    }
                }
            });
        }
    });
    executeQuery(vm0);
    vm1.invoke(new SerializableRunnable("check rebalance happened") {

        public void run() {
            assertNotNull(rebalanceResults.get());
            assertEquals(5, rebalanceResults.get().getTotalBucketTransfersCompleted());
        }
    });
}
Also used : QueryMessage(org.apache.geode.internal.cache.partitioned.QueryMessage) RebalanceOperation(org.apache.geode.cache.control.RebalanceOperation) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) CancellationException(java.util.concurrent.CancellationException) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Host(org.apache.geode.test.dunit.Host) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Aggregations

DistributionManager (org.apache.geode.distributed.internal.DistributionManager)29 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)29 DistributionMessageObserver (org.apache.geode.distributed.internal.DistributionMessageObserver)29 VM (org.apache.geode.test.dunit.VM)28 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)28 Test (org.junit.Test)28 Host (org.apache.geode.test.dunit.Host)27 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)22 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)11 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)11 Cache (org.apache.geode.cache.Cache)9 IgnoredException (org.apache.geode.test.dunit.IgnoredException)9 Region (org.apache.geode.cache.Region)7 RequestImageMessage (org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage)7 LocalRegion (org.apache.geode.internal.cache.LocalRegion)6 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)6 IOException (java.io.IOException)5 DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)5 CacheClosedException (org.apache.geode.cache.CacheClosedException)4 DiskRegion (org.apache.geode.internal.cache.DiskRegion)4