Search in sources :

Example 26 with DistributionMessage

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

the class PersistentPartitionedRegionDUnitTest method testBug42226.

/**
   * Test for bug 4226. 1. Member A has the bucket 2. Member B starts creating the bucket. It tells
   * member A that it hosts the bucket 3. Member A crashes 4. Member B destroys the bucket and
   * throws a partition offline exception, because it wasn't able to complete initialization. 5.
   * Member A recovers, and gets stuck waiting for member B.
   * 
   * @throws Throwable
   */
// GEODE-1208: time sensitive, multiple non-thread-safe test hooks,
@Category(FlakyTest.class)
// async actions
@Test
public void testBug42226() 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 RequestImageMessage) {
                        RequestImageMessage rim = (RequestImageMessage) message;
                        // Don't disconnect until we see a bucket
                        if (rim.regionPath.contains("_B_")) {
                            DistributionMessageObserver.setInstance(null);
                            disconnectFromDS();
                        }
                    }
                }

                @Override
                public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
                }
            });
        }
    });
    LogWriterUtils.getLogWriter().info("Creating region in VM0");
    createPR(vm0, 1, 0, 1);
    // Make sure we create a bucket
    createData(vm0, 0, 1, "a");
    // This should recover redundancy, which should cause vm0 to disconnect
    IgnoredException ex = IgnoredException.addIgnoredException("PartitionOfflineException");
    try {
        LogWriterUtils.getLogWriter().info("Creating region in VM1");
        createPR(vm1, 1, 0, 1);
        // Make sure get a partition offline exception
        try {
            createData(vm1, 0, 1, "a");
        } catch (RMIException e) {
            // We expect a PartitionOfflineException
            if (!(e.getCause() instanceof PartitionOfflineException)) {
                throw e;
            }
        }
    } finally {
        ex.remove();
    }
    // Make sure vm0 is really disconnected (avoids a race with the observer).
    vm0.invoke(new SerializableRunnable() {

        public void run() {
            disconnectFromDS();
        }
    });
    // This should recreate the bucket
    AsyncInvocation async1 = createPRAsync(vm0, 1, 0, 1);
    async1.getResult(MAX_WAIT);
    checkData(vm1, 0, 1, "a");
}
Also used : RMIException(org.apache.geode.test.dunit.RMIException) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Host(org.apache.geode.test.dunit.Host) RequestImageMessage(org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage) 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 27 with DistributionMessage

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

the class ConnectionTest method shouldBeMockable.

@Test
public void shouldBeMockable() throws Exception {
    Connection mockConnection = mock(Connection.class);
    SocketChannel channel = null;
    ByteBuffer buffer = null;
    boolean forceAsync = true;
    DistributionMessage mockDistributionMessage = mock(DistributionMessage.class);
    mockConnection.nioWriteFully(channel, buffer, forceAsync, mockDistributionMessage);
    verify(mockConnection, times(1)).nioWriteFully(channel, buffer, forceAsync, mockDistributionMessage);
}
Also used : SocketChannel(java.nio.channels.SocketChannel) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) ByteBuffer(java.nio.ByteBuffer) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 28 with DistributionMessage

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

the class Bug41733DUnitTest method testCrashAfterBucketCreation.

/**
   * Test the we can handle a member departing after creating a bucket on the remote node but before
   * we choose a primary
   */
@Test
public void testCrashAfterBucketCreation() throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    vm0.invoke(new SerializableRunnable("Install observer") {

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

                @Override
                public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof ManageBucketReplyMessage) {
                        disconnectFromDS();
                    }
                }
            });
        }
    });
    createPR(vm0, 0);
    // Create a couple of buckets in VM0. This will make sure
    // the next bucket we create will be created in VM 1.
    putData(vm0, 0, 2, "a");
    createPR(vm1, 0);
    // Trigger a bucket creation in VM1, which should cause vm0 to close it's cache.
    try {
        putData(vm0, 3, 4, "a");
        fail("should have received a cache closed exception");
    } catch (RMIException e) {
        if (!(e.getCause() instanceof DistributedSystemDisconnectedException)) {
            throw e;
        }
    }
    assertEquals(Collections.singleton(3), getBucketList(vm1));
    // This shouldn't hang, because the bucket creation should finish,.
    putData(vm1, 3, 4, "a");
}
Also used : RMIException(org.apache.geode.test.dunit.RMIException) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) ManageBucketReplyMessage(org.apache.geode.internal.cache.partitioned.ManageBucketMessage.ManageBucketReplyMessage) Host(org.apache.geode.test.dunit.Host) 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 29 with DistributionMessage

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

the class PdxSerializableDUnitTest method testVmWaitsForPdxType.

@Test
public void testVmWaitsForPdxType() throws Throwable {
    VM vm0 = Host.getHost(0).getVM(0);
    VM vm1 = Host.getHost(0).getVM(1);
    getBlackboard().initBlackboard();
    final Properties properties = getDistributedSystemProperties();
    properties.put("conserve-sockets", "false");
    // steps:
    // 1 create two caches and define a PdxType
    // 2 install a block in VM1 that delays receipt of new PDX types
    // 3 update the value of the PdxInstance in VM0 using a new Enum type
    // 4 get the value in VM0
    // The result should be that step 4 hangs unless the bug is fixed
    vm0.invoke("create cache", () -> {
        Cache cache = getCache(properties);
        Region region = cache.createRegionFactory(RegionShortcut.REPLICATE).create("testRegion");
        region.put("TestObject", new TestPdxObject("aString", 1, 1.0, TestPdxObject.AnEnum.ONE));
    });
    vm1.invoke("create cache and region", () -> {
        Cache cache = getCache(properties);
        // note that initial image transfer in testRegion will cause the object to be serialized in
        // vm0
        // and populate the PdxRegion in this vm
        cache.createRegionFactory(RegionShortcut.REPLICATE).create("testRegion");
        // this message observer will ensure that a new PDX registration doesn't occur
        final DUnitBlackboard bb = getBlackboard();
        DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

            @Override
            public void beforeProcessMessage(DistributionManager dm, DistributionMessage msg) {
                if (msg instanceof DistributedCacheOperation.CacheOperationMessage) {
                    try {
                        DistributedCacheOperation.CacheOperationMessage cmsg = (DistributedCacheOperation.CacheOperationMessage) msg;
                        String path = cmsg.getRegionPath();
                        if (path.equals(PeerTypeRegistration.REGION_FULL_PATH)) {
                            System.out.println("message observer found a PDX update message and is stalling: " + msg);
                            try {
                                bb.signalGate("listenerWasInvoked");
                                bb.waitForGate("pdxObjectGetStarting", 3, TimeUnit.SECONDS);
                                // let the get() commence and block
                                Thread.sleep(30000);
                                System.out.println("message observer after sleep ");
                            } catch (InterruptedException e) {
                                System.out.println("message observer is done stalling1 ");
                                bb.setMailbox("listenerProblem", e);
                            } catch (TimeoutException e) {
                                System.out.println("message observer is done stalling2");
                                bb.setMailbox("listenerProblem", e);
                            } finally {
                                System.out.println("message observer is done stalling");
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        });
    });
    AsyncInvocation async0 = vm0.invokeAsync("propagate value with new pdx enum type", () -> {
        Cache cache = getCache(properties);
        final Region pdxRegion = cache.getRegion(PeerTypeRegistration.REGION_FULL_PATH);
        final DUnitBlackboard bb = getBlackboard();
        // now we register a new Id for our enum in a different thread. This will
        // block in vm1 due to its message observer
        Thread t = new Thread("PdxSerializableDUnitTest async thread") {

            public void run() {
                bb.signalGate("asyncThreadReady");
                // pdxRegion.put(new EnumId(0x3010101), new EnumInfo(TestPdxObject.AnEnum.TWO));
                ((GemFireCacheImpl) cache).getPdxRegistry().addRemoteEnum(0x3010101, new EnumInfo(TestPdxObject.AnEnum.TWO));
            }
        };
        t.setDaemon(true);
        t.start();
        try {
            bb.waitForGate("asyncThreadReady", 20, TimeUnit.SECONDS);
        } catch (TimeoutException e) {
            fail("timed out");
        }
        // reserialization will use the new Enumeration PDX type
        Region region = cache.getRegion("testRegion");
        bb.waitForGate("listenerWasInvoked", 20, TimeUnit.SECONDS);
        region.put("TestObject", new TestPdxObject("TestObject'", 2, 2.0, TestPdxObject.AnEnum.TWO));
        System.out.println("TestObject added put");
        bb.signalGate("pdxObjectPut");
    });
    // vm0 has sent a new TestObject but vm1 does not have the enum type needed to
    // deserialize it.
    AsyncInvocation async1 = vm1.invokeAsync("try to read object w/o enum type", () -> {
        DUnitBlackboard bb = getBlackboard();
        bb.waitForGate("pdxObjectPut", 10, TimeUnit.SECONDS);
        Region region = getCache(properties).getRegion("testRegion");
        bb.signalGate("pdxObjectGetStarting");
        Object testObject = region.get("TestObject");
        System.out.println("found " + testObject);
    });
    DUnitBlackboard bb = getBlackboard();
    try {
        async0.join(20000);
        async1.join(10000);
        if (async0.exceptionOccurred()) {
            throw async0.getException();
        }
        if (async1.exceptionOccurred()) {
            throw async1.getException();
        }
        assertTrue(bb.isGateSignaled("listenerWasInvoked"));
    /*
       * Throwable throwable = (Throwable)bb.getMailbox("listenerProblem"); if (throwable != null) {
       * RuntimeException rte = new RuntimeException("message observer had a problem", throwable);
       * throw rte; }
       */
    } finally {
        bb.signalGate("pdxObjectGetStarting");
        bb.signalGate("pdxObjectPut");
        bb.initBlackboard();
    }
}
Also used : DUnitBlackboard(org.apache.geode.test.dunit.DUnitBlackboard) DistributedCacheOperation(org.apache.geode.internal.cache.DistributedCacheOperation) EnumInfo(org.apache.geode.pdx.internal.EnumInfo) Properties(java.util.Properties) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) TimeoutException(java.util.concurrent.TimeoutException) TransactionWriterException(org.apache.geode.cache.TransactionWriterException) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Cache(org.apache.geode.cache.Cache) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 30 with DistributionMessage

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

the class StreamingFunctionOperation method getFunctionResultFrom.

public ResultCollector getFunctionResultFrom(Set recipients, Function function, AbstractExecution execution) {
    if (recipients.isEmpty())
        return rc;
    FunctionStreamingResultCollector processor = new FunctionStreamingResultCollector(this, this.sys, recipients, rc, function, execution);
    this.reply = processor;
    for (InternalDistributedMember recip : this.memberArgs.keySet()) {
        DistributionMessage m = null;
        if (execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) {
            m = createRequestMessage(Collections.singleton(recip), processor, execution.isReExecute(), execution.isFnSerializationReqd());
        } else {
            m = createRequestMessage(Collections.singleton(recip), processor, false, execution.isFnSerializationReqd());
        }
        this.sys.getDistributionManager().putOutgoing(m);
    }
    return processor;
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage)

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