Search in sources :

Example 46 with DistributionMessage

use of org.apache.geode.distributed.internal.DistributionMessage 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 47 with DistributionMessage

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

the class InterruptClientServerDUnitTest method testClientPutWithInterrupt.

/**
   * A simple test case that we are actually persisting with a PR.
   * 
   * @throws Throwable
   */
@Test
public void testClientPutWithInterrupt() throws Throwable {
    IgnoredException.addIgnoredException("InterruptedException");
    Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    final VM vm2 = host.getVM(2);
    int port = AvailablePortHelper.getRandomAvailableTCPPort();
    createRegionAndServer(vm0, port);
    // put some data in vm0
    createData(vm0, 0, 10, "a");
    final SerializableCallable interruptTask = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            puttingThread.interrupt();
            return null;
        }
    };
    vm1.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            disconnectFromDS();
            DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

                @Override
                public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof UpdateMessage && ((UpdateMessage) message).regionPath.contains("region") && doInterrupt.compareAndSet(true, false)) {
                        vm2.invoke(interruptTask);
                        DistributionMessageObserver.setInstance(null);
                    }
                }
            });
            return null;
        }
    });
    createRegion(vm1);
    createClientRegion(vm2, port);
    SerializableCallable doPuts = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            puttingThread = Thread.currentThread();
            Region<Object, Object> region = getCache().getRegion("region");
            long value = 0;
            long end = System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(MAX_WAIT);
            while (!Thread.currentThread().isInterrupted()) {
                region.put(0, value);
                if (System.nanoTime() > end) {
                    fail("Did not get interrupted in 60 seconds");
                }
            }
            return null;
        }
    };
    AsyncInvocation async0 = vm2.invokeAsync(doPuts);
    vm1.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            doInterrupt.set(true);
            return null;
        }
    });
    // vm0.invoke(new SerializableCallable() {
    //
    // @Override
    // public Object call() throws Exception {
    // long end = System.nanoTime() + TimeUnit.SECONDS.toNanos(MAX_WAIT);
    // while(puttingThread == null) {
    // Thread.sleep(50);
    // if(System.nanoTime() > end) {
    // fail("Putting thread not set in 60 seconds");
    // }
    // }
    //
    // puttingThread.interrupt();
    // return null;
    // }
    // });
    async0.getResult();
    Object value0 = checkCacheAndGetValue(vm0);
    Object value1 = checkCacheAndGetValue(vm1);
    assertEquals(value0, value1);
}
Also used : UpdateMessage(org.apache.geode.internal.cache.UpdateOperation.UpdateMessage) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) 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) 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 48 with DistributionMessage

use of org.apache.geode.distributed.internal.DistributionMessage 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 49 with DistributionMessage

use of org.apache.geode.distributed.internal.DistributionMessage 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 50 with DistributionMessage

use of org.apache.geode.distributed.internal.DistributionMessage 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)

Aggregations

DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)51 Test (org.junit.Test)34 DistributionManager (org.apache.geode.distributed.internal.DistributionManager)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 Host (org.apache.geode.test.dunit.Host)27 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)22 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)13 IOException (java.io.IOException)11 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 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)8 DataInputStream (java.io.DataInputStream)7 RequestImageMessage (org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage)7 Properties (java.util.Properties)6 CacheClosedException (org.apache.geode.cache.CacheClosedException)6 Region (org.apache.geode.cache.Region)6