Search in sources :

Example 11 with JChannel

use of org.jgroups.JChannel in project wildfly by wildfly.

the class RelayConfigurationBuilder method accept.

@Override
public void accept(RELAY2 protocol) {
    String localSite = this.siteName;
    List<RemoteSiteConfiguration> remoteSites = this.getRemoteSites();
    List<String> sites = new ArrayList<>(remoteSites.size() + 1);
    sites.add(localSite);
    // Collect bridges, eliminating duplicates
    Map<String, RelayConfig.BridgeConfig> bridges = new HashMap<>();
    for (final RemoteSiteConfiguration remoteSite : remoteSites) {
        String siteName = remoteSite.getName();
        sites.add(siteName);
        String clusterName = remoteSite.getClusterName();
        RelayConfig.BridgeConfig bridge = new RelayConfig.BridgeConfig(clusterName) {

            @Override
            public JChannel createChannel() throws Exception {
                JChannel channel = (JChannel) remoteSite.getChannelFactory().createChannel(siteName);
                // Don't use FORK in bridge stack
                channel.getProtocolStack().removeProtocol(FORK.class);
                return channel;
            }
        };
        bridges.put(clusterName, bridge);
    }
    protocol.site(localSite);
    for (String site : sites) {
        RelayConfig.SiteConfig siteConfig = new RelayConfig.SiteConfig(site);
        protocol.addSite(site, siteConfig);
        if (site.equals(localSite)) {
            for (RelayConfig.BridgeConfig bridge : bridges.values()) {
                siteConfig.addBridge(bridge);
            }
        }
    }
}
Also used : JChannel(org.jgroups.JChannel) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RelayConfig(org.jgroups.protocols.relay.config.RelayConfig) RemoteSiteConfiguration(org.wildfly.clustering.jgroups.spi.RemoteSiteConfiguration)

Example 12 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 13 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)

Example 14 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)

Aggregations

JChannel (org.jgroups.JChannel)14 Message (org.jgroups.Message)5 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)4 Test (org.junit.Test)4 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)3 SerialAckedMessage (org.apache.geode.distributed.internal.SerialAckedMessage)3 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)3 InstallViewMessage (org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage)3 JoinRequestMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage)3 JoinResponseMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage)3 LeaveRequestMessage (org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage)3 DistributedCacheOperation (org.apache.geode.internal.cache.DistributedCacheOperation)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ForcedDisconnectException (org.apache.geode.ForcedDisconnectException)2 GemFireIOException (org.apache.geode.GemFireIOException)2 StartException (org.jboss.msc.service.StartException)2