Search in sources :

Example 6 with ForkChannel

use of org.jgroups.fork.ForkChannel in project JGroups by belaban.

the class ForkChannelTest method testLifecycle.

public void testLifecycle() throws Exception {
    fc1 = new ForkChannel(a, "stack", "fc1");
    assert fc1.isOpen() && !fc1.isConnected() && !fc1.isClosed() : "state=" + fc1.getState();
    a.connect(CLUSTER);
    assert fc1.isOpen() && !fc1.isConnected() && !fc1.isClosed() : "state=" + fc1.getState();
    fc1.connect("bla");
    assert fc1.isOpen() && fc1.isConnected() && !fc1.isClosed() : "state=" + fc1.getState();
    assert a.getAddress().equals(fc1.getAddress());
    assert a.getClusterName().equals(fc1.getClusterName());
    assert a.getView().equals(fc1.getView());
    fc1.disconnect();
    assert fc1.isOpen() && !fc1.isConnected() && !fc1.isClosed() : "state=" + fc1.getState();
    fc1.connect("foobar");
    assert fc1.isOpen() && fc1.isConnected() && !fc1.isClosed() : "state=" + fc1.getState();
    Util.close(fc1);
    assert !fc1.isOpen() && !fc1.isConnected() && fc1.isClosed() : "state=" + fc1.getState();
    try {
        fc1.connect("whocares");
        assert false : "a closed fork channel cannot be reconnected";
    } catch (Exception ex) {
        assert ex instanceof IllegalStateException;
    }
    assert !fc1.isOpen() && !fc1.isConnected() && fc1.isClosed() : "state=" + fc1.getState();
    Util.close(a);
    assert !fc1.isOpen() && !fc1.isConnected() && fc1.isClosed() : "state=" + fc1.getState();
    try {
        fc1.send(null, "hello");
        assert false : "sending on a fork-channel with a disconnected main-channel should throw an exception";
    } catch (Throwable t) {
        System.out.println("got an exception (as expected) sending on a fork-channel where the main-channel is disconnected: " + t);
    }
}
Also used : ForkChannel(org.jgroups.fork.ForkChannel)

Example 7 with ForkChannel

use of org.jgroups.fork.ForkChannel in project JGroups by belaban.

the class ForkChannelTest method createForkChannel.

protected ForkChannel createForkChannel(JChannel main, String stack_name, String ch_name) throws Exception {
    ForkChannel fork_ch = new ForkChannel(main, stack_name, ch_name);
    fork_ch.connect(ch_name);
    return fork_ch;
}
Also used : ForkChannel(org.jgroups.fork.ForkChannel)

Example 8 with ForkChannel

use of org.jgroups.fork.ForkChannel in project JGroups by belaban.

the class ForkChannelTest method testCreateForkIfAbsent.

@Test
public void testCreateForkIfAbsent() throws Exception {
    JChannel c = new JChannel(Util.getTestStack(new STATE())).name("C");
    ForkChannel fc = new ForkChannel(c, "hijack-stack", "lead-hijacker", true, ProtocolStack.Position.ABOVE, FRAG2.class);
    assert fc.isOpen() && !fc.isConnected() && !fc.isClosed() : "state=" + fc.getState();
    Util.close(fc, c);
}
Also used : JChannel(org.jgroups.JChannel) STATE(org.jgroups.protocols.pbcast.STATE) ForkChannel(org.jgroups.fork.ForkChannel) Test(org.testng.annotations.Test)

Aggregations

ForkChannel (org.jgroups.fork.ForkChannel)8 FORK (org.jgroups.protocols.FORK)3 ForkProtocolStack (org.jgroups.fork.ForkProtocolStack)2 Protocol (org.jgroups.stack.Protocol)2 JChannel (org.jgroups.JChannel)1 Counter (org.jgroups.blocks.atomic.Counter)1 CounterService (org.jgroups.blocks.atomic.CounterService)1 COUNTER (org.jgroups.protocols.COUNTER)1 STATE (org.jgroups.protocols.pbcast.STATE)1 MyReceiver (org.jgroups.util.MyReceiver)1 Test (org.testng.annotations.Test)1