Search in sources :

Example 81 with Protocol

use of org.jgroups.stack.Protocol in project JGroups by belaban.

the class UNICAST_ConnectionTests method testMultipleConcurrentResets.

/**
 * Tests concurrent reception of multiple messages with a different conn_id (https://issues.jboss.org/browse/JGRP-1347)
 */
@Test(dataProvider = "configProvider")
public void testMultipleConcurrentResets(Class<? extends UNICAST3> unicast) throws Exception {
    setup(unicast);
    sendAndCheck(a, b_addr, 1, r2);
    // now close connection on A unilaterally
    System.out.println("==== Closing the connection on A");
    removeConnection(u1, b_addr);
    r2.clear();
    final Protocol ucast = b.getProtocolStack().findProtocol(Util.getUnicastProtocols());
    int NUM = 10;
    final List<Message> msgs = new ArrayList<>(NUM);
    for (int i = 1; i <= NUM; i++) {
        Message msg = new BytesMessage(b_addr, i).setSrc(a_addr);
        Header hdr = createDataHeader(ucast, 1, (short) 2, true);
        msg.putHeader(ucast.getId(), hdr);
        msgs.add(msg);
    }
    Thread[] threads = new Thread[NUM];
    final CyclicBarrier barrier = new CyclicBarrier(NUM + 1);
    for (int i = 0; i < NUM; i++) {
        final int index = i;
        threads[i] = new Thread(() -> {
            try {
                barrier.await();
                ucast.up(msgs.get(index));
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        threads[i].start();
    }
    barrier.await();
    for (Thread thread : threads) thread.join();
    List<Integer> list = r2.getMessages();
    System.out.println("list = " + print(list));
    assert list.size() == 1 : "list must have 1 element but has " + list.size() + ": " + print(list);
}
Also used : ArrayList(java.util.ArrayList) CyclicBarrier(java.util.concurrent.CyclicBarrier) Protocol(org.jgroups.stack.Protocol) Test(org.testng.annotations.Test)

Example 82 with Protocol

use of org.jgroups.stack.Protocol in project JGroups by belaban.

the class UNICAST_DropFirstAndLastTest method testFirstMessageDropped.

/**
 * A sends unicast message 1 to B, but we drop message 1. The code in
 * https://issues.jboss.org/browse/JGRP-1563 now needs to make sure message 1 is retransmitted to B
 * within a short time period, and we don't have to rely on the stable task to kick in.
 */
@Test(dataProvider = "configProvider")
public void testFirstMessageDropped(Class<? extends UNICAST3> unicast_class) throws Exception {
    setup(unicast_class);
    System.out.println("**** closing all connections ****");
    // close all connections, so we can start from scratch and send message A1 to B
    for (JChannel ch : Arrays.asList(a, b)) {
        Protocol unicast = ch.getProtocolStack().findProtocol(Util.getUnicastProtocols());
        removeAllConnections(unicast);
    }
    setLevel("trace", a, b);
    System.out.println("--> A sending first message to B (dropped before it reaches B)");
    // drops the next unicast
    discard.dropDownUnicasts(1);
    a.send(new BytesMessage(b.getAddress(), 1));
    List<Integer> msgs = rb.list();
    try {
        Util.waitUntilListHasSize(msgs, 1, 500000, 500);
    } catch (AssertionError err) {
        printConnectionTables(a, b);
        throw err;
    }
    System.out.println("list=" + msgs);
    printConnectionTables(a, b);
// assert ((UNICAST2)a.getProtocolStack().findProtocol(UNICAST2.class)).connectionEstablished(b.getAddress());
}
Also used : Protocol(org.jgroups.stack.Protocol) Test(org.testng.annotations.Test)

Example 83 with Protocol

use of org.jgroups.stack.Protocol in project JGroups by belaban.

the class UNICAST_RetransmitTest method setLevel.

protected static void setLevel(String level, JChannel... channels) {
    for (JChannel ch : channels) {
        Protocol prot = ch.getProtocolStack().findProtocol(UNICAST3.class);
        prot.level(level);
    }
}
Also used : Protocol(org.jgroups.stack.Protocol)

Example 84 with Protocol

use of org.jgroups.stack.Protocol 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 85 with Protocol

use of org.jgroups.stack.Protocol in project JGroups by belaban.

the class ConfiguratorTest method testRemovalOfBottom.

public void testRemovalOfBottom() throws Exception {
    Protocol prot = stack.removeProtocol("UDP");
    assert prot != null;
    List<Protocol> protocols = stack.getProtocols();
    Assert.assertEquals(5, protocols.size());
    assert protocols.get(protocols.size() - 1).getName().endsWith("PING");
}
Also used : Protocol(org.jgroups.stack.Protocol)

Aggregations

Protocol (org.jgroups.stack.Protocol)87 NAKACK2 (org.jgroups.protocols.pbcast.NAKACK2)18 JChannel (org.jgroups.JChannel)17 GMS (org.jgroups.protocols.pbcast.GMS)17 STABLE (org.jgroups.protocols.pbcast.STABLE)13 ProtocolStack (org.jgroups.stack.ProtocolStack)12 ArrayList (java.util.ArrayList)9 Test (org.testng.annotations.Test)9 Property (org.jgroups.annotations.Property)6 HashMap (java.util.HashMap)5 ForkProtocol (org.jgroups.fork.ForkProtocol)5 ForkProtocolStack (org.jgroups.fork.ForkProtocolStack)5 InetAddress (java.net.InetAddress)4 ProtocolConfiguration (org.jgroups.conf.ProtocolConfiguration)4 OperationFailedException (org.jboss.as.controller.OperationFailedException)3 Message (org.jgroups.Message)3 FORK (org.jgroups.protocols.FORK)3 UNICAST3 (org.jgroups.protocols.UNICAST3)3 BeforeMethod (org.testng.annotations.BeforeMethod)3 Method (java.lang.reflect.Method)2