Search in sources :

Example 11 with DistributionMessage

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

the class PersistentRecoveryOrderDUnitTest method testCrashDuringPreparePersistentId.

// GEODE-1703: fails assertion: Region not created within30000
@Category(FlakyTest.class)
@Test
public void testCrashDuringPreparePersistentId() 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 PrepareNewPersistentMemberMessage) {
                        DistributionMessageObserver.setInstance(null);
                        disconnectFromDS();
                    }
                }

                @Override
                public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
                }
            });
        }
    });
    createPersistentRegion(vm0);
    putAnEntry(vm0);
    updateTheEntry(vm0);
    AsyncInvocation async1 = createPersistentRegionAsync(vm1);
    // Wait for vm 1 to get stuck waiting for vm0, because vm0 has crashed
    waitForBlockedInitialization(vm1);
    // closeCache(vm0);
    closeCache(vm1);
    try {
        async1.getResult();
        fail("Should have seen a CacheClosedException");
    } catch (AssertionError e) {
        if (!CacheClosedException.class.isInstance(getRootCause(e))) {
            throw e;
        }
    }
    createPersistentRegion(vm0);
    createPersistentRegion(vm1);
    ;
    checkForEntry(vm0);
    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) Host(org.apache.geode.test.dunit.Host) 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)

Example 12 with DistributionMessage

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

the class BackupDUnitTest method testBackupWhileBucketIsMovedBackupAfterSendDestroy.

@Test
public void testBackupWhileBucketIsMovedBackupAfterSendDestroy() throws Throwable {
    Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    final VM vm2 = host.getVM(2);
    DistributionMessageObserver observer = new SerializableDistributionMessageObserver() {

        private volatile boolean done;

        private AtomicInteger count = new AtomicInteger();

        private volatile int replyId = -0xBAD;

        @Override
        public void beforeSendMessage(DistributionManager dm, DistributionMessage msg) {
            // The bucket move will send a destroy region message.
            if (msg instanceof DestroyRegionOperation.DestroyRegionMessage && !done) {
                this.replyId = msg.getProcessorId();
            }
        }

        @Override
        public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
            if (message instanceof ReplyMessage && replyId != -0xBAD && replyId == message.getProcessorId() && !done && // we need two replies
            count.incrementAndGet() == 2) {
                backup(vm2);
                done = true;
            }
        }
    };
    backupWhileBucketIsMoved(observer);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) ReplyMessage(org.apache.geode.distributed.internal.ReplyMessage) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 13 with DistributionMessage

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

the class BackupDUnitTest method testBackupWhileBucketIsMovedBackupBeforeSendDestroy.

@Test
public void testBackupWhileBucketIsMovedBackupBeforeSendDestroy() throws Throwable {
    Host host = Host.getHost(0);
    final VM vm2 = host.getVM(2);
    DistributionMessageObserver observer = new SerializableDistributionMessageObserver() {

        private volatile boolean done;

        private AtomicInteger count = new AtomicInteger();

        private volatile int replyId = -0xBAD;

        @Override
        public void beforeSendMessage(DistributionManager dm, DistributionMessage msg) {
            // The bucket move will send a destroy region message.
            if (msg instanceof DestroyRegionOperation.DestroyRegionMessage && !done) {
                backup(vm2);
                done = true;
            }
        }
    };
    backupWhileBucketIsMoved(observer);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) 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)

Example 14 with DistributionMessage

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

the class InterruptsDUnitTest method testDRPutWithInterrupt.

/**
   * A simple test case that we are actually persisting with a PR.
   * 
   * @throws Throwable
   */
@Test
public void testDRPutWithInterrupt() throws Throwable {
    Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    createRegion(vm0);
    // 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)) {
                        vm0.invoke(interruptTask);
                        DistributionMessageObserver.setInstance(null);
                    }
                }
            });
            return null;
        }
    });
    createRegion(vm1);
    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 = vm0.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) 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 15 with DistributionMessage

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

the class NetSearchMessagingDUnitTest method testNetSearchFailoverFromReplicate.

/**
   * Make sure that even if we start out by net searching replicates, we'll fall back to net
   * searching normal members.
   */
@Test
public void testNetSearchFailoverFromReplicate() {
    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);
    createNormal(vm1);
    createNormal(vm2);
    createEmpty(vm3);
    // Test with a real value value
    {
        put(vm3, "a", "b");
        long vm0Count = getReceivedMessages(vm0);
        long vm1Count = getReceivedMessages(vm1);
        long vm2Count = getReceivedMessages(vm2);
        long vm3Count = getReceivedMessages(vm3);
        assertEquals("b", get(vm3, "a"));
        // Make sure we were disconnected in vm0
        vm0.invoke(new SerializableRunnable("check disconnected") {

            public void run() {
                assertNull(GemFireCacheImpl.getInstance());
            }
        });
    }
}
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) 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)

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