Search in sources :

Example 56 with JChannel

use of org.jgroups.JChannel in project camel by apache.

the class JGroupsConsumerTest method doPreSetup.

// Fixture setup
@Override
protected void doPreSetup() throws Exception {
    super.doPreSetup();
    channel = new JChannel();
    channel.connect(clusterName);
}
Also used : JChannel(org.jgroups.JChannel)

Example 57 with JChannel

use of org.jgroups.JChannel in project camel by apache.

the class JGroupsProducerTest method doPreSetup.

// Fixture setup
@Override
protected void doPreSetup() throws Exception {
    super.doPreSetup();
    channel = new JChannel();
    channel.setReceiver(new ReceiverAdapter() {

        @Override
        public void receive(Message msg) {
            messageReceived = msg.getObject();
        }
    });
    channel.connect(CLUSTER_NAME);
}
Also used : JChannel(org.jgroups.JChannel) Message(org.jgroups.Message) ReceiverAdapter(org.jgroups.ReceiverAdapter)

Example 58 with JChannel

use of org.jgroups.JChannel in project geode by apache.

the class JGroupsMessengerJUnitTest method testUseOldJChannel.

@Test
public void testUseOldJChannel() throws Exception {
    initMocks(false);
    JChannel channel = messenger.myChannel;
    services.getConfig().getTransport().setOldDSMembershipInfo(channel);
    JGroupsMessenger newMessenger = new JGroupsMessenger();
    newMessenger.init(services);
    newMessenger.start();
    newMessenger.started();
    newMessenger.stop();
    assertTrue(newMessenger.myChannel == messenger.myChannel);
}
Also used : JChannel(org.jgroups.JChannel) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 59 with JChannel

use of org.jgroups.JChannel in project geode by apache.

the class JGroupsMessengerJUnitTest method testSendWhenChannelIsClosed.

@Test
public void testSendWhenChannelIsClosed() throws Exception {
    for (int i = 0; i < 2; i++) {
        initMocks(false);
        JChannel mockChannel = mock(JChannel.class);
        when(mockChannel.isConnected()).thenReturn(false);
        doThrow(new RuntimeException()).when(mockChannel).send(any(Message.class));
        JChannel realChannel = messenger.myChannel;
        messenger.myChannel = mockChannel;
        try {
            InternalDistributedMember mbr = createAddress(8888);
            DistributedCacheOperation.CacheOperationMessage msg = mock(DistributedCacheOperation.CacheOperationMessage.class);
            when(msg.getRecipients()).thenReturn(new InternalDistributedMember[] { mbr });
            when(msg.getMulticast()).thenReturn(false);
            when(msg.getProcessorId()).thenReturn(1234);
            try {
                messenger.send(msg);
                fail("expected a failure");
            } catch (DistributedSystemDisconnectedException e) {
            // success
            }
            verify(mockChannel, never()).send(isA(Message.class));
        } finally {
            messenger.myChannel = realChannel;
        }
    }
}
Also used : JChannel(org.jgroups.JChannel) DistributedCacheOperation(org.apache.geode.internal.cache.DistributedCacheOperation) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage) LeaveRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage) InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) SerialAckedMessage(org.apache.geode.distributed.internal.SerialAckedMessage) Message(org.jgroups.Message) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 60 with JChannel

use of org.jgroups.JChannel in project geode by apache.

the class JGroupsMessengerJUnitTest method testJChannelErrorDuringDisconnect.

@Test
public void testJChannelErrorDuringDisconnect() throws Exception {
    for (int i = 0; i < 4; i++) {
        System.out.println("loop #" + i);
        boolean enableMcast = (i % 2 == 1);
        initMocks(enableMcast);
        JChannel mockChannel = mock(JChannel.class);
        when(mockChannel.isConnected()).thenReturn(true);
        Exception ex, shutdownCause;
        if (i < 2) {
            ex = new RuntimeException("");
            shutdownCause = new RuntimeException("shutdownCause");
        } else {
            shutdownCause = new ForcedDisconnectException("");
            ex = new RuntimeException("", shutdownCause);
        }
        doThrow(ex).when(mockChannel).send(any(Message.class));
        JChannel realChannel = messenger.myChannel;
        messenger.myChannel = mockChannel;
        when(services.getShutdownCause()).thenReturn(shutdownCause);
        try {
            InternalDistributedMember mbr = createAddress(8888);
            DistributedCacheOperation.CacheOperationMessage msg = mock(DistributedCacheOperation.CacheOperationMessage.class);
            when(msg.getRecipients()).thenReturn(new InternalDistributedMember[] { mbr });
            when(msg.getMulticast()).thenReturn(enableMcast);
            when(msg.getProcessorId()).thenReturn(1234);
            when(msg.getDSFID()).thenReturn((int) DataSerializableFixedID.PUT_ALL_MESSAGE);
            try {
                messenger.send(msg);
                fail("expected a failure");
            } catch (DistributedSystemDisconnectedException e) {
                // the ultimate cause should be the shutdownCause returned
                // by Services.getShutdownCause()
                Throwable cause = e;
                while (cause.getCause() != null) {
                    cause = cause.getCause();
                }
                assertTrue(cause != e);
                assertTrue(cause == shutdownCause);
            }
            verify(mockChannel).send(isA(Message.class));
        } finally {
            messenger.myChannel = realChannel;
        }
    }
}
Also used : JChannel(org.jgroups.JChannel) DistributedCacheOperation(org.apache.geode.internal.cache.DistributedCacheOperation) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage) LeaveRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage) InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) SerialAckedMessage(org.apache.geode.distributed.internal.SerialAckedMessage) Message(org.jgroups.Message) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) SerializationException(org.apache.commons.lang.SerializationException) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) GemFireIOException(org.apache.geode.GemFireIOException) IOException(java.io.IOException) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

JChannel (org.jgroups.JChannel)119 GMS (org.jgroups.protocols.pbcast.GMS)22 NAKACK2 (org.jgroups.protocols.pbcast.NAKACK2)21 Protocol (org.jgroups.stack.Protocol)18 STABLE (org.jgroups.protocols.pbcast.STABLE)15 View (org.jgroups.View)14 Message (org.jgroups.Message)10 ArrayList (java.util.ArrayList)9 Address (org.jgroups.Address)7 IOException (java.io.IOException)6 Test (org.testng.annotations.Test)5 InetSocketAddress (java.net.InetSocketAddress)4 HashMap (java.util.HashMap)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)4 LockService (org.jgroups.blocks.locking.LockService)4 Test (org.junit.Test)4 BeforeMethod (org.testng.annotations.BeforeMethod)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 ChannelBroadcastEndpointFactory (org.apache.activemq.artemis.api.core.ChannelBroadcastEndpointFactory)3