Search in sources :

Example 1 with Route

use of org.jgroups.protocols.relay.Route in project JGroups by belaban.

the class Relay2Test method testMissingRouteAfterMerge.

/**
 * Tests that routes are correctly registered after a partition and a subsequent merge
 * (https://issues.jboss.org/browse/JGRP-1524)
 */
public void testMissingRouteAfterMerge() throws Exception {
    a = createNode(LON, "A", LON_CLUSTER, null);
    b = createNode(LON, "B", LON_CLUSTER, null);
    Util.waitUntilAllChannelsHaveSameView(30000, 1000, a, b);
    x = createNode(SFO, "X", SFO_CLUSTER, null);
    assert x.getView().size() == 1;
    RELAY2 ar = a.getProtocolStack().findProtocol(RELAY2.class), xr = x.getProtocolStack().findProtocol(RELAY2.class);
    assert ar != null && xr != null;
    JChannel a_bridge = null, x_bridge = null;
    for (int i = 0; i < 20; i++) {
        a_bridge = ar.getBridge(SFO);
        x_bridge = xr.getBridge(LON);
        if (a_bridge != null && x_bridge != null && a_bridge.getView().size() == 2 && x_bridge.getView().size() == 2)
            break;
        Util.sleep(500);
    }
    assert a_bridge != null && x_bridge != null;
    System.out.println("A's bridge channel: " + a_bridge.getView());
    System.out.println("X's bridge channel: " + x_bridge.getView());
    assert a_bridge.getView().size() == 2 : "bridge view is " + a_bridge.getView();
    assert x_bridge.getView().size() == 2 : "bridge view is " + x_bridge.getView();
    Route route = getRoute(x, LON);
    System.out.println("Route at sfo to lon: " + route);
    assert route != null;
    // Now inject a partition into site LON
    System.out.println("Creating partition between A and B:");
    createPartition(a, b);
    System.out.println("A's view: " + a.getView() + "\nB's view: " + b.getView());
    assert a.getView().size() == 1 && b.getView().size() == 1;
    route = getRoute(x, LON);
    System.out.println("Route at sfo to lon: " + route);
    assert route != null;
    View bridge_view = xr.getBridgeView(BRIDGE_CLUSTER);
    System.out.println("bridge_view = " + bridge_view);
    // Now make A and B form a cluster again:
    View merge_view = new MergeView(a.getAddress(), 10, Arrays.asList(a.getAddress(), b.getAddress()), Arrays.asList(View.create(a.getAddress(), 5, a.getAddress()), View.create(b.getAddress(), 5, b.getAddress())));
    GMS gms = a.getProtocolStack().findProtocol(GMS.class);
    gms.installView(merge_view, null);
    gms = b.getProtocolStack().findProtocol(GMS.class);
    gms.installView(merge_view, null);
    Util.waitUntilAllChannelsHaveSameView(20000, 500, a, b);
    System.out.println("A's view: " + a.getView() + "\nB's view: " + b.getView());
    for (int i = 0; i < 20; i++) {
        bridge_view = xr.getBridgeView(BRIDGE_CLUSTER);
        if (bridge_view != null && bridge_view.size() == 2)
            break;
        Util.sleep(500);
    }
    route = getRoute(x, LON);
    System.out.println("Route at sfo to lon: " + route);
    assert route != null;
}
Also used : RELAY2(org.jgroups.protocols.relay.RELAY2) GMS(org.jgroups.protocols.pbcast.GMS) Route(org.jgroups.protocols.relay.Route)

Example 2 with Route

use of org.jgroups.protocols.relay.Route in project JGroups by belaban.

the class Relay2Test method testAddRelay2ToAnAlreadyConnectedChannel.

/**
 * Test that RELAY2 can be added to an already connected channel.
 */
public void testAddRelay2ToAnAlreadyConnectedChannel() throws Exception {
    // Create and connect a channel.
    a = new JChannel();
    a.connect(SFO_CLUSTER);
    System.out.println("Channel " + a.getName() + " is connected. View: " + a.getView());
    // Add RELAY2 protocol to the already connected channel.
    RELAY2 relayToInject = createRELAY2(SFO);
    // Util.setField(Util.getField(relayToInject.getClass(), "local_addr"), relayToInject, a.getAddress());
    a.getProtocolStack().insertProtocolAtTop(relayToInject);
    relayToInject.down(new Event(Event.SET_LOCAL_ADDRESS, a.getAddress()));
    relayToInject.setProtocolStack(a.getProtocolStack());
    relayToInject.configure();
    relayToInject.handleView(a.getView());
    // Check for RELAY2 presence
    RELAY2 ar = a.getProtocolStack().findProtocol(RELAY2.class);
    assert ar != null;
    waitUntilRoute(SFO, true, 10000, 500, a);
    assert !ar.printRoutes().equals("n/a (not site master)") : "This member should be site master";
    Route route = getRoute(a, SFO);
    System.out.println("Route at sfo to sfo: " + route);
    assert route != null;
}
Also used : RELAY2(org.jgroups.protocols.relay.RELAY2) Route(org.jgroups.protocols.relay.Route)

Example 3 with Route

use of org.jgroups.protocols.relay.Route in project JGroups by belaban.

the class Relay2RpcDispatcherTest method testNotificationAndRpcRelay2Transit.

/**
 * Tests that notifications are routed to all sites.
 */
public void testNotificationAndRpcRelay2Transit() throws Exception {
    a.connect(LON_CLUSTER);
    b.connect(LON_CLUSTER);
    rpca.start();
    rpcb.start();
    Util.waitUntilAllChannelsHaveSameView(30000, 1000, a, b);
    x.connect(SFO_CLUSTER);
    y.connect(SFO_CLUSTER);
    rpcx.start();
    rpcy.start();
    Util.waitUntilAllChannelsHaveSameView(30000, 1000, x, y);
    assert a.getView().size() == 2;
    assert x.getView().size() == 2;
    RELAY2 ar = a.getProtocolStack().findProtocol(RELAY2.class);
    RELAY2 xr = x.getProtocolStack().findProtocol(RELAY2.class);
    assert ar != null && xr != null;
    JChannel a_bridge = null, x_bridge = null;
    for (int i = 0; i < 20; i++) {
        a_bridge = ar.getBridge(SFO);
        x_bridge = xr.getBridge(LON);
        if (a_bridge != null && x_bridge != null && a_bridge.getView().size() == 2 && x_bridge.getView().size() == 2)
            break;
        Util.sleep(500);
    }
    assert a_bridge != null && x_bridge != null;
    System.out.println("A's bridge channel: " + a_bridge.getView());
    System.out.println("X's bridge channel: " + x_bridge.getView());
    assert a_bridge.getView().size() == 2 : "bridge view is " + a_bridge.getView();
    assert x_bridge.getView().size() == 2 : "bridge view is " + x_bridge.getView();
    Route route = getRoute(x, LON);
    System.out.println("Route at sfo to lon: " + route);
    assert route != null;
    System.out.println("B: sending message 0 to the site master of SFO");
    Address sm_sfo = new SiteMaster(SFO);
    MethodCall call = new MethodCall(ServerObject.class.getMethod("foo"));
    System.out.println("B: call foo method on A");
    Object rsp = rpcb.callRemoteMethod(a.getAddress(), call, new RequestOptions(ResponseMode.GET_ALL, 5000));
    System.out.println("RSP is: " + rsp);
    System.out.println("B: call foo method on SFO master site");
    rsp = rpcb.callRemoteMethod(sm_sfo, call, new RequestOptions(ResponseMode.GET_ALL, 15000));
    System.out.println("RSP is: " + rsp);
    System.out.println("B: call foo method on all members in site LON");
    RspList<Integer> rsps = rpcb.callRemoteMethods(null, call, new RequestOptions(ResponseMode.GET_ALL, 5000));
    System.out.println("RSPs are: \n" + rsps);
    assert rsps.size() == 2;
    assert rsps.containsKey(a.getAddress()) && rsps.containsKey(b.getAddress());
    View bridge_view = xr.getBridgeView(BRIDGE_CLUSTER);
    System.out.println("bridge_view = " + bridge_view);
    route = getRoute(x, LON);
    System.out.println("Route at sfo to lon: " + route);
    assert route != null;
}
Also used : RequestOptions(org.jgroups.blocks.RequestOptions) MethodCall(org.jgroups.blocks.MethodCall) SiteMaster(org.jgroups.protocols.relay.SiteMaster) RELAY2(org.jgroups.protocols.relay.RELAY2) Route(org.jgroups.protocols.relay.Route)

Example 4 with Route

use of org.jgroups.protocols.relay.Route in project JGroups by belaban.

the class Relay2Test method waitUntilRoute.

protected void waitUntilRoute(String site_name, boolean present, long timeout, long interval, JChannel ch) throws Exception {
    RELAY2 relay = ch.getProtocolStack().findProtocol(RELAY2.class);
    if (relay == null)
        throw new IllegalArgumentException("Protocol RELAY2 not found");
    Route route = null;
    long deadline = System.currentTimeMillis() + timeout;
    while (System.currentTimeMillis() < deadline) {
        route = relay.getRoute(site_name);
        if ((route != null && present) || (route == null && !present))
            break;
        Util.sleep(interval);
    }
    assert (route != null && present) || (route == null && !present);
}
Also used : RELAY2(org.jgroups.protocols.relay.RELAY2) Route(org.jgroups.protocols.relay.Route)

Example 5 with Route

use of org.jgroups.protocols.relay.Route in project JGroups by belaban.

the class Relay2Test method testUnknownAndUpStateTransitions.

/**
 * Tests the following scenario:
 * <ul>
 *     <li>Nodes A in LON and B in SFO, both are up</li>
 *     <li>B goes down</li>
 *     <li>The status of site SFO in LON is set to UNKNOWN and a task T is started which will set SFO's status
 *     to DOWN in site_down_timeout ms</li>
 *     <li>Before T kicks in, B in SFO is started again</li>
 *     <li>The status of site SFO in LON is now UP</li>
 *     <li>Make sure T is cancelled when transitioning from UNKNOWN to UP, or else it'll set the status
 *     of SFO to DOWN when it triggers</li>
 * </ul>
 */
public void testUnknownAndUpStateTransitions() throws Exception {
    a = createNode(LON, "A", LON_CLUSTER, null);
    x = createNode(SFO, "X", SFO_CLUSTER, null);
    waitForBridgeView(2, 20000, 500, a, x);
    System.out.println("Disconnecting X");
    x.disconnect();
    System.out.println("A: waiting for site SFO to be UNKNOWN");
    waitUntilRoute(SFO, false, 20000, 500, a);
    System.out.println("Reconnecting X, waiting for 5 seconds to see if the route is marked as DOWN");
    x.connect(SFO_CLUSTER);
    Util.sleep(5000);
    Route route = getRoute(a, SFO);
    assert route != null : "route is " + route + " (expected to be UP)";
    route = getRoute(x, LON);
    assert route != null : "route is " + route + " (expected to be UP)";
}
Also used : Route(org.jgroups.protocols.relay.Route)

Aggregations

Route (org.jgroups.protocols.relay.Route)5 RELAY2 (org.jgroups.protocols.relay.RELAY2)4 MethodCall (org.jgroups.blocks.MethodCall)1 RequestOptions (org.jgroups.blocks.RequestOptions)1 GMS (org.jgroups.protocols.pbcast.GMS)1 SiteMaster (org.jgroups.protocols.relay.SiteMaster)1