Search in sources :

Example 96 with JChannel

use of org.jgroups.JChannel in project JGroups by belaban.

the class DNSDiscoveryTester method runTestAndCheckIfViewWasReceived.

public boolean runTestAndCheckIfViewWasReceived(String dnsQuery, String recordType) throws Exception {
    List<JChannel> channels = new ArrayList<>();
    CountDownLatch waitForViewToForm = new CountDownLatch(1);
    for (int i = 0; i < numberOfTestedInstances; ++i) {
        DNS_PING ping = new DNS_PING();
        ping.dns_resolver = dnsResolverBuilder.build();
        ping.dns_query = dnsQuery;
        ping.dns_record_type = recordType;
        ping.dns_address = "fake.com";
        Protocol[] protocols = { new TCP().setBindAddress(InetAddress.getLoopbackAddress()).setBindPort(portStart).setPortRange(1), ping, new NAKACK2(), new UNICAST3(), new STABLE(), new GMS().setJoinTimeout(timeout) };
        JChannel c = new JChannel(protocols).name(String.valueOf(i + 1));
        channels.add(c);
        c.setReceiver(new Receiver() {

            @Override
            public void viewAccepted(View view) {
                if (view.getMembers().size() == numberOfTestedInstances) {
                    waitForViewToForm.countDown();
                }
            }
        });
        c.connect("TEST");
    }
    boolean viewReceived = waitForViewToForm.await(timeout, unit);
    channels.forEach(JChannel::close);
    return viewReceived;
}
Also used : TCP(org.jgroups.protocols.TCP) JChannel(org.jgroups.JChannel) ArrayList(java.util.ArrayList) Receiver(org.jgroups.Receiver) CountDownLatch(java.util.concurrent.CountDownLatch) GMS(org.jgroups.protocols.pbcast.GMS) View(org.jgroups.View) UNICAST3(org.jgroups.protocols.UNICAST3) NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) STABLE(org.jgroups.protocols.pbcast.STABLE) Protocol(org.jgroups.stack.Protocol)

Example 97 with JChannel

use of org.jgroups.JChannel in project JGroups by belaban.

the class STABLE_Test method testStableWithDontLoopback.

public void testStableWithDontLoopback() throws Exception {
    byte[] payload = new byte[5000];
    for (int i = 0; i < 10; i++) {
        Message msg = new BytesMessage(null, payload).setFlag(Message.TransientFlag.DONT_LOOPBACK);
        b.send(msg);
        // prevents batches, which trigger STABLE msgs in non-10000 increments
        Util.sleep(200);
    }
    Util.waitUntil(5000, 500, () -> Stream.of(r1, r3).allMatch(r -> r.size() == 10));
    assert r2.size() == 0;
    Util.waitUntilTrue(5000, 500, () -> Stream.of(a, b, c).map(c -> ((NAKACK2) c.getProtocolStack().findProtocol(NAKACK2.class)).getWindow(b.getAddress())).allMatch(t -> t.getHighestReceived() == 10 && t.getHighestDelivered() == 10 && t.getLow() == 10));
    for (JChannel ch : List.of(a, b, c)) {
        NAKACK2 n = ch.getProtocolStack().findProtocol(NAKACK2.class);
        Table<Message> t = n.getWindow(b.getAddress());
        assert t.getHighestReceived() == 10 && t.getHighestDelivered() == 10 && t.getLow() == 10 : String.format("table for %s is %s (low is probably 0)", ch.getName(), t);
    }
}
Also used : Table(org.jgroups.util.Table) Util(org.jgroups.util.Util) BeforeMethod(org.testng.annotations.BeforeMethod) Test(org.testng.annotations.Test) AfterMethod(org.testng.annotations.AfterMethod) BytesMessage(org.jgroups.BytesMessage) MyReceiver(org.jgroups.util.MyReceiver) List(java.util.List) Stream(java.util.stream.Stream) Message(org.jgroups.Message) NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) Global(org.jgroups.Global) STABLE(org.jgroups.protocols.pbcast.STABLE) JChannel(org.jgroups.JChannel) NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) JChannel(org.jgroups.JChannel) BytesMessage(org.jgroups.BytesMessage) Message(org.jgroups.Message) BytesMessage(org.jgroups.BytesMessage)

Example 98 with JChannel

use of org.jgroups.JChannel in project JGroups by belaban.

the class STABLE_Test method create.

protected static JChannel create(String name) throws Exception {
    JChannel ch = new JChannel(Util.getTestStack()).name(name);
    STABLE stable = ch.getProtocolStack().findProtocol(STABLE.class);
    // disabled periodical stable
    stable.setDesiredAverageGossip(0).setMaxBytes(10000);
    ch.getProtocolStack().getTransport().getDiagnosticsHandler().setEnabled(true);
    return ch;
}
Also used : JChannel(org.jgroups.JChannel) STABLE(org.jgroups.protocols.pbcast.STABLE)

Example 99 with JChannel

use of org.jgroups.JChannel in project JGroups by belaban.

the class TLSTest method create.

private JChannel create(String name) throws Exception {
    TCP transport = new TCP();
    transport.setBindAddress(InetAddress.getLoopbackAddress());
    transport.setBindPort(9600);
    transport.setSocketFactory(sslContexts.containsKey(name) ? new DefaultSocketFactory(sslContexts.get(name)) : new DefaultSocketFactory());
    TCPPING ping = new TCPPING();
    ping.setInitialHosts2(Collections.singletonList(new IpAddress(transport.getBindAddress(), transport.getBindPort())));
    return new JChannel(transport, ping, new NAKACK2(), new UNICAST3(), new STABLE(), new GMS()).name(name);
}
Also used : NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) JChannel(org.jgroups.JChannel) DefaultSocketFactory(org.jgroups.util.DefaultSocketFactory) IpAddress(org.jgroups.stack.IpAddress) STABLE(org.jgroups.protocols.pbcast.STABLE) GMS(org.jgroups.protocols.pbcast.GMS)

Example 100 with JChannel

use of org.jgroups.JChannel in project JGroups by belaban.

the class NAKACK_RetransmitTest method startRetransmission.

protected static void startRetransmission(JChannel... channels) throws Exception {
    for (JChannel ch : channels) {
        NAKACK2 nak = ch.getProtocolStack().findProtocol(NAKACK2.class);
        START_RETRANSMISSION.invoke(nak);
    }
}
Also used : NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) JChannel(org.jgroups.JChannel)

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