Search in sources :

Example 51 with Protocol

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

the class UNICAST_ConnectionTests method setup.

protected void setup(Class<? extends Protocol> unicast_class, Map<String, Object> props) throws Exception {
    r1 = new MyReceiver("A");
    r2 = new MyReceiver("B");
    a = createChannel(unicast_class, "A");
    if (props != null) {
        Protocol prot = a.getProtocolStack().findProtocol(unicast_class);
        for (Map.Entry<String, Object> entry : props.entrySet()) prot.setValue(entry.getKey(), entry.getValue());
    }
    a.connect(CLUSTER);
    a_addr = a.getAddress();
    a.setReceiver(r1);
    u1 = a.getProtocolStack().findProtocol(unicast_class);
    b = createChannel(unicast_class, "B");
    if (props != null) {
        Protocol prot = b.getProtocolStack().findProtocol(unicast_class);
        for (Map.Entry<String, Object> entry : props.entrySet()) prot.setValue(entry.getKey(), entry.getValue());
    }
    b.connect(CLUSTER);
    b_addr = b.getAddress();
    b.setReceiver(r2);
    u2 = b.getProtocolStack().findProtocol(unicast_class);
}
Also used : Protocol(org.jgroups.stack.Protocol) HashMap(java.util.HashMap) Map(java.util.Map)

Example 52 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 Protocol> 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.setDropDownUnicasts(1);
    a.send(new Message(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 : JChannel(org.jgroups.JChannel) Message(org.jgroups.Message) Protocol(org.jgroups.stack.Protocol) Test(org.testng.annotations.Test)

Example 53 with Protocol

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

the class ViewHandlerTest method configureGMS.

protected static void configureGMS(GMS gms) {
    Address local_addr = Util.createRandomAddress("A");
    ThreadFactory fac = new DefaultThreadFactory("test", true);
    set(gms, "local_addr", local_addr);
    set(gms, "timer", new TimeScheduler3(fac, 1, 3, 5000, 100, "run"));
    gms.setDownProtocol(new Protocol() {

        public ThreadFactory getThreadFactory() {
            return fac;
        }
    });
}
Also used : DefaultThreadFactory(org.jgroups.util.DefaultThreadFactory) DefaultThreadFactory(org.jgroups.util.DefaultThreadFactory) ThreadFactory(org.jgroups.util.ThreadFactory) Address(org.jgroups.Address) TimeScheduler3(org.jgroups.util.TimeScheduler3) Protocol(org.jgroups.stack.Protocol)

Example 54 with Protocol

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

the class ProgrammaticApiTest method testChannelCreation.

public void testChannelCreation() throws Exception {
    ch = new JChannel(new SHARED_LOOPBACK(), new MockProtocol1(), new MockProtocol2()).name("A");
    MyReceiver receiver = new MyReceiver();
    ch.setReceiver(receiver);
    ch.connect("demo");
    Protocol transport = ch.getProtocolStack().getTransport();
    transport.up((Message) new BytesMessage(null, "hello world").setSrc(Util.createRandomAddress()));
    assert receiver.num_msgs_received == 1;
}
Also used : Protocol(org.jgroups.stack.Protocol)

Example 55 with Protocol

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

the class ProtocolConfigurationTest method testConfigurableObject.

/*
	 * Checks InetAddress and IpAddress processing 
	 */
public void testConfigurableObject() throws Exception {
    List<ProtocolConfiguration> protocol_configs = new ArrayList<>();
    List<Protocol> protocols = new ArrayList<>();
    // create the layer described by INETADDRESSES
    protocol = Configurator.createProtocol(configurableObjectsProps, stack);
    ProtocolConfiguration cfg = new ProtocolConfiguration(configurableObjectsProps);
    ProtocolStack.initComponents(protocol, cfg);
    // process the defaults (want this eventually)
    protocol_configs.add(new ProtocolConfiguration(configurableObjectsProps));
    protocols.add(protocol);
    // get the value which should have been assigned a default
    List<Object> configObjs = protocol.getComponents();
    assert configObjs.size() == 1;
    Object configObj = configObjs.get(0);
    assert configObj instanceof ConfigurableObject;
    assert ((ConfigurableObject) configObj).getStringProp().equals("test");
}
Also used : ProtocolConfiguration(org.jgroups.conf.ProtocolConfiguration) ArrayList(java.util.ArrayList) 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