Search in sources :

Example 6 with DistributionManager

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

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

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

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

Example 10 with DistributionManager

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

the class PersistentRecoveryOrderDUnitTest method testFinishIncompleteInitializationNoSend.

@Test
public void testFinishIncompleteInitializationNoSend() throws Exception {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    // Add a hook which will disconnect the DS before sending a prepare message
    vm1.invoke(new SerializableRunnable() {

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

                @Override
                public void beforeSendMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof PrepareNewPersistentMemberMessage) {
                        DistributionMessageObserver.setInstance(null);
                        getSystem().disconnect();
                    }
                }

                @Override
                public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
                }
            });
        }
    });
    createPersistentRegion(vm0);
    putAnEntry(vm0);
    updateTheEntry(vm0);
    try {
        createPersistentRegion(vm1);
    } catch (Exception e) {
        if (!(e.getCause() instanceof DistributedSystemDisconnectedException)) {
            throw e;
        }
    }
    closeRegion(vm0);
    // This wait for VM0 to come back
    AsyncInvocation async1 = createPersistentRegionAsync(vm1);
    waitForBlockedInitialization(vm1);
    createPersistentRegion(vm0);
    async1.getResult();
    checkForEntry(vm1);
    vm0.invoke(new SerializableRunnable("check for offline members") {

        public void run() {
            Cache cache = getCache();
            DistributedRegion region = (DistributedRegion) cache.getRegion(REGION_NAME);
            PersistentMembershipView view = region.getPersistenceAdvisor().getMembershipView();
            DiskRegion dr = region.getDiskRegion();
            assertEquals(Collections.emptySet(), dr.getOfflineMembers());
            assertEquals(1, dr.getOnlineMembers().size());
        }
    });
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) 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) DiskRegion(org.apache.geode.internal.cache.DiskRegion) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) 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

DistributionManager (org.apache.geode.distributed.internal.DistributionManager)60 Test (org.junit.Test)44 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)36 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)29 DistributionMessageObserver (org.apache.geode.distributed.internal.DistributionMessageObserver)29 VM (org.apache.geode.test.dunit.VM)29 Host (org.apache.geode.test.dunit.Host)28 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)25 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)15 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)12 Cache (org.apache.geode.cache.Cache)11 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)11 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)11 IOException (java.io.IOException)9 IgnoredException (org.apache.geode.test.dunit.IgnoredException)9 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)9 Properties (java.util.Properties)8 UnitTest (org.apache.geode.test.junit.categories.UnitTest)8 RequestImageMessage (org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage)7 Region (org.apache.geode.cache.Region)6