Search in sources :

Example 56 with Protocol

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

the class ForkChannelTest method testRefcount2.

public void testRefcount2() throws Exception {
    Prot p1 = new Prot("P1"), p2 = new Prot("P2");
    fc1 = new ForkChannel(a, "stack", "fc1", p1, p2);
    // uses p1 and p2 from fc1
    fc2 = new ForkChannel(a, "stack", "fc2");
    // uses p1 and p2 from fc1
    fc3 = new ForkChannel(a, "stack", "fc3");
    assert p1.inits == 1 && p2.inits == 1;
    FORK fork = a.getProtocolStack().findProtocol(FORK.class);
    Protocol prot = fork.get("stack");
    ForkProtocolStack fork_stack = (ForkProtocolStack) getProtStack(prot);
    int inits = fork_stack.getInits();
    assert inits == 3;
    a.connect(CLUSTER);
    fc1.connect(CLUSTER);
    int connects = fork_stack.getConnects();
    assert connects == 1;
    assert p1.starts == 1 && p2.starts == 1;
    fc2.connect(CLUSTER);
    fc3.connect(CLUSTER);
    connects = fork_stack.getConnects();
    assert connects == 3;
    assert p1.starts == 1 && p2.starts == 1;
    fc3.disconnect();
    fc2.disconnect();
    assert p1.starts == 1 && p2.starts == 1;
    assert p1.stops == 0 && p2.stops == 0;
    fc1.disconnect();
    assert p1.starts == 1 && p2.starts == 1;
    assert p1.stops == 1 && p2.stops == 1;
    Util.close(fc3, fc2);
    assert p1.destroys == 0 && p2.destroys == 0;
    Util.close(fc1);
    assert p1.destroys == 1 && p2.destroys == 1;
}
Also used : FORK(org.jgroups.protocols.FORK) Protocol(org.jgroups.stack.Protocol) ForkChannel(org.jgroups.fork.ForkChannel) ForkProtocolStack(org.jgroups.fork.ForkProtocolStack)

Example 57 with Protocol

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

the class FrozenCoordinatorTest method create.

protected JChannel create(String name) throws Exception {
    FILE_PING ping = new FILE_PING().setLocation(root_dir.toString()).removeAllDataOnViewChange(true);
    Protocol[] protocols = { new SHARED_LOOPBACK(), ping, new NAKACK2(), new UNICAST3(), new STABLE(), new GMS().setJoinTimeout(1000).setMaxJoinAttempts(5) };
    return new JChannel(protocols).name(name);
}
Also used : SHARED_LOOPBACK(org.jgroups.protocols.SHARED_LOOPBACK) FILE_PING(org.jgroups.protocols.FILE_PING) NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) JChannel(org.jgroups.JChannel) STABLE(org.jgroups.protocols.pbcast.STABLE) Protocol(org.jgroups.stack.Protocol) GMS(org.jgroups.protocols.pbcast.GMS) UNICAST3(org.jgroups.protocols.UNICAST3)

Example 58 with Protocol

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

the class InetAddressChecksTest method testIPVersionCheckingConsistentVersion.

/*
	 * Checks IP version mechanism for consistent version processing
	 */
public void testIPVersionCheckingConsistentVersion() throws Exception {
    List<ProtocolConfiguration> protocol_configs = new ArrayList<>();
    List<Protocol> protocols = new ArrayList<>();
    // create the layer described by IPCHECK
    protocol = Configurator.createProtocol(ipCheckConsistentProps, stack);
    // process the defaults
    protocol_configs.add(new ProtocolConfiguration(ipCheckConsistentProps));
    protocols.add(protocol);
    Map<String, Map<String, InetAddressInfo>> inetAddressMap = null;
    inetAddressMap = Configurator.createInetAddressMap(protocol_configs, protocols);
    Collection<InetAddress> addrs = Configurator.getAddresses(inetAddressMap);
    determineIpVersionFromAddresses(addrs);
    // get the value which should have been assigned a default
    InetAddress a = ((IPCHECK) protocol).getInetAddress1();
    System.out.println("value of inetAddress1 = " + a);
    InetAddress b = ((IPCHECK) protocol).getInetAddress2();
    System.out.println("value of inetAddress2 = " + b);
    InetAddress c = ((IPCHECK) protocol).getInetAddress3();
    System.out.println("value of inetAddress3 = " + c);
}
Also used : ProtocolConfiguration(org.jgroups.conf.ProtocolConfiguration) Protocol(org.jgroups.stack.Protocol) InetAddress(java.net.InetAddress)

Example 59 with Protocol

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

the class MergeTest6 method testViewInconsistency.

/**
 * Tests whether the following scenario is successfully healed by {@link MERGE3}:
 * <pre>
 *     - (2 left)
 *     - 3: 3|6 -> {3,4,5,6,7}
 *     - 4: 3|6 -> {3,4,5,6,7}
 *     - 5: 3|6 -> {3,4,5,6,7}
 *     - 6: 3|6 -> {3,4,5,6,7}
 *     - 7: 2|5 -> {2,3,4,5,6,7}
 * </pre>
 * In this case, 7 and 3 should become merge coordinators and establish a MergeView
 */
public void testViewInconsistency() throws Exception {
    System.out.println("Initial view:\n");
    for (JChannel ch : Arrays.asList(two, three, four, five, six, seven)) System.out.printf("%s: %s\n", ch.getAddress(), ch.getView());
    ProtocolStack stack = seven.getProtocolStack();
    Protocol drop_view = new DropView().setAddress(seven.getAddress());
    // GMS.class);
    stack.insertProtocol(drop_view, ProtocolStack.Position.BELOW, NAKACK2.class);
    Util.close(two);
    for (int i = 0; i < 10; i++) {
        View view_3 = three.getView();
        boolean same = true;
        for (JChannel ch : Arrays.asList(four, five, six)) {
            if (!ch.getView().equals(view_3)) {
                same = false;
                break;
            }
        }
        if (same)
            break;
        Util.sleep(500);
    }
    View view_3 = three.getView();
    assert Stream.of(four, five, six).allMatch(ch -> ch.getView().equals(view_3)) : Stream.of(four, five, six).map(JChannel::getView).collect(Collectors.toList());
    assert !view_3.equals(seven.getView());
    System.out.println("Views after member 7 dropped view");
    Stream.of(three, four, five, six, seven).forEach(ch -> System.out.printf("%s: %s\n", ch.getAddress(), ch.getView()));
    stack.removeProtocol(drop_view);
    System.out.println("-- waiting for merge to heal partition");
    Util.waitUntilAllChannelsHaveSameView(1500000, 1000, three, four, five, six, seven);
    Stream.of(three, four, five, six, seven).forEach(ch -> System.out.printf("%s: %s\n", ch.getAddress(), ch.getView()));
}
Also used : ProtocolStack(org.jgroups.stack.ProtocolStack) Protocol(org.jgroups.stack.Protocol)

Example 60 with Protocol

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

the class VERIFY_SUSPECT_Test method testUnsuspect.

public void testUnsuspect() throws TimeoutException {
    VERIFY_SUSPECT ver = new VERIFY_SUSPECT().setTimeout(1000);
    ProtImpl impl = new ProtImpl();
    ver.setUpProtocol(impl);
    ver.setDownProtocol(new Protocol() {

        public Object down(Event evt) {
            return null;
        }

        public Object down(Message msg) {
            return null;
        }

        public ThreadFactory getThreadFactory() {
            return new DefaultThreadFactory("foo", false, true);
        }
    });
    Map<Address, Long> map = impl.getMap();
    start = System.currentTimeMillis();
    ver.up(new Event(Event.SUSPECT, Collections.singletonList(a)));
    ver.up(new Event(Event.SUSPECT, Collections.singletonList(b)));
    Util.waitUntil(10000, 500, () -> map.size() == 2);
    ver.up(new Event(Event.SUSPECT, Collections.singletonList(a)));
    ver.up(new Event(Event.SUSPECT, Collections.singletonList(b)));
    ver.unsuspect(a);
    Util.waitUntilTrue(10000, 500, () -> map.size() == 1);
    assert map.size() == 1 && map.containsKey(b);
}
Also used : DefaultThreadFactory(org.jgroups.util.DefaultThreadFactory) ThreadFactory(org.jgroups.util.ThreadFactory) DefaultThreadFactory(org.jgroups.util.DefaultThreadFactory) 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