Ejemplo n.º 1
0
  /** Tests a merge between ViewIds of the same coord, e.g. A|6, A|7, A|8, A|9 */
  public void testViewsBySameCoord() {
    View v1 =
        View.create(
            a.getAddress(),
            6,
            a.getAddress(),
            b.getAddress(),
            c.getAddress(),
            d.getAddress()); // {A,B,C,D}
    View v2 =
        View.create(a.getAddress(), 7, a.getAddress(), b.getAddress(), c.getAddress()); // {A,B,C}
    View v3 = View.create(a.getAddress(), 8, a.getAddress(), b.getAddress()); // {A,B}
    View v4 = View.create(a.getAddress(), 9, a.getAddress()); // {A}

    Util.close(b, c, d); // not interested in those...

    MERGE3 merge = (MERGE3) a.getProtocolStack().findProtocol(MERGE3.class);
    for (View view : Arrays.asList(v1, v2, v4, v3)) {
      MERGE3.MergeHeader hdr = MERGE3.MergeHeader.createInfo(view.getViewId(), null, null);
      Message msg = new Message(null, a.getAddress(), null).putHeader(merge.getId(), hdr);
      merge.up(new Event(Event.MSG, msg));
    }

    merge.checkInconsistencies(); // no merge will happen

    Util.waitUntilAllChannelsHaveSameSize(10000, 500, a);
    System.out.println("A's view: " + a.getView());
    assert a.getView().size() == 1;
    assert a.getView().containsMember(a.getAddress());
  }
Ejemplo n.º 2
0
  /**
   * Tests a simple split: {A,B} and {C,D} need to merge back into one subgroup. Checks how many
   * MergeViews are installed
   */
  public void testSplitInTheMiddle2() throws Exception {
    View v1 = View.create(a.getAddress(), 10, a.getAddress(), b.getAddress());
    View v2 = View.create(c.getAddress(), 10, c.getAddress(), d.getAddress());
    injectView(v1, a, b);
    injectView(v2, c, d);
    enableInfoSender(false, a, b, c, d);
    Util.waitUntilAllChannelsHaveSameSize(10000, 500, a, b);
    Util.waitUntilAllChannelsHaveSameSize(10000, 500, c, d);
    enableInfoSender(false, a, b, c, d);
    for (JChannel ch : Arrays.asList(a, b, c, d))
      System.out.println(ch.getName() + ": " + ch.getView());
    System.out.println("\nEnabling INFO sending in merge protocols to merge subclusters");
    enableInfoSender(true, a, b, c, d);

    Util.waitUntilAllChannelsHaveSameSize(30000, 1000, a, b, c, d);
    System.out.println("\nResulting views:");
    for (JChannel ch : Arrays.asList(a, b, c, d)) {
      GMS gms = (GMS) ch.getProtocolStack().findProtocol(GMS.class);
      View mv = gms.view();
      System.out.println(mv);
    }
    for (JChannel ch : Arrays.asList(a, b, c, d)) {
      GMS gms = (GMS) ch.getProtocolStack().findProtocol(GMS.class);
      View mv = gms.view();
      assert mv instanceof MergeView;
      assert mv.size() == 4;
      assert ((MergeView) mv).getSubgroups().size() == 2;
    }
    for (JChannel ch : Arrays.asList(a, b, c, d)) {
      View view = ch.getView();
      assert view.size() == 4 : "view should have 4 members: " + view;
    }
  }
Ejemplo n.º 3
0
  public static void testDetermineMergeParticipantsAndMergeCoords4() {
    Address a = Util.createRandomAddress(),
        b = Util.createRandomAddress(),
        c = Util.createRandomAddress(),
        d = Util.createRandomAddress();
    org.jgroups.util.UUID.add(a, "A");
    org.jgroups.util.UUID.add(b, "B");
    org.jgroups.util.UUID.add(c, "C");
    org.jgroups.util.UUID.add(d, "D");

    View v1 = View.create(a, 1, a, b);
    View v2 = View.create(c, 1, c, d);

    Map<Address, View> map = new HashMap<>();
    map.put(a, v1);
    map.put(b, v1);
    map.put(d, v2);

    StringBuilder sb = new StringBuilder("map:\n");
    for (Map.Entry<Address, View> entry : map.entrySet())
      sb.append(entry.getKey() + ": " + entry.getValue() + "\n");
    System.out.println(sb);

    Collection<Address> merge_participants = Util.determineMergeParticipants(map);
    System.out.println("merge_participants = " + merge_participants);
    assert merge_participants.size() == 3;
    assert merge_participants.contains(a)
        && merge_participants.contains(c)
        && merge_participants.contains(d);

    Collection<Address> merge_coords = Util.determineMergeCoords(map);
    System.out.println("merge_coords = " + merge_coords);
    assert merge_coords.size() == 2;
    assert merge_coords.contains(a) && merge_coords.contains(c);
  }
Ejemplo n.º 4
0
  public static void testAllEqual() {
    Address[] mbrs = Util.createRandomAddresses(5);
    View[] views = {
      View.create(mbrs[0], 1, mbrs), View.create(mbrs[0], 1, mbrs), View.create(mbrs[0], 1, mbrs)
    };

    boolean same = Util.allEqual(Arrays.asList(views));
    System.out.println("views=" + Arrays.toString(views) + ", same = " + same);
    assert same;

    views =
        new View[] {
          View.create(mbrs[0], 1, mbrs),
          View.create(mbrs[0], 2, mbrs),
          View.create(mbrs[0], 1, mbrs)
        };
    same = Util.allEqual(Arrays.asList(views));
    System.out.println("views=" + Arrays.toString(views) + ", same = " + same);
    assert !same;

    views =
        new View[] {
          View.create(mbrs[1], 1, mbrs),
          View.create(mbrs[0], 1, mbrs),
          View.create(mbrs[0], 1, mbrs)
        };
    same = Util.allEqual(Arrays.asList(views));
    System.out.println("views=" + Arrays.toString(views) + ", same = " + same);
    assert !same;
  }
Ejemplo n.º 5
0
  /** Tests the scenario described by Dan in https://issues.jboss.org/browse/JGRP-1876 */
  public void testJGRP_1876_Dan() throws Exception {
    Util.close(d, c, b, a);
    s = createChannel("S", true);
    t = createChannel("T", true);
    u = createChannel("U", true);
    v = createChannel("V", true);
    Util.waitUntilAllChannelsHaveSameSize(10000, 500, s, t, u, v);
    enableInfoSender(false, s, t, u, v); // stops INFO sending in MERGE3
    for (JChannel ch : Arrays.asList(s, t, u, v))
      System.out.println(ch.getName() + ": " + ch.getView());
    View v1 = View.create(s.getAddress(), 10, s.getAddress());
    View v2 = View.create(t.getAddress(), 10, t.getAddress());
    View v3 = View.create(u.getAddress(), 11, u.getAddress(), v.getAddress());

    injectView(v1, s);
    injectView(v2, t);
    injectView(v3, u, v);
    enableInfoSender(false, s, t, u, v); // stops INFO sending in MERGE3
    Util.waitUntilAllChannelsHaveSameSize(10000, 500, s);
    Util.waitUntilAllChannelsHaveSameSize(10000, 500, t);
    Util.waitUntilAllChannelsHaveSameSize(10000, 500, u, v);

    System.out.printf("\nPartitions:\n");
    for (JChannel ch : Arrays.asList(s, t, u, v))
      System.out.println(ch.getName() + ": " + ch.getView());

    enableInfoSender(true, s, t, u, v);
    System.out.println("\nEnabling INFO sending in merge protocols to merge subclusters");

    Util.waitUntilAllChannelsHaveSameSize(30000, 1000, s, t, u, v);
    System.out.println("\nResulting views:");
    for (JChannel ch : Arrays.asList(s, t, u, v)) {
      GMS gms = (GMS) ch.getProtocolStack().findProtocol(GMS.class);
      View mv = gms.view();
      System.out.println(mv);
    }
    for (JChannel ch : Arrays.asList(s, t, u, v)) {
      GMS gms = (GMS) ch.getProtocolStack().findProtocol(GMS.class);
      View mv = gms.view();
      assert mv instanceof MergeView;
      assert mv.size() == 4;
      assert ((MergeView) mv).getSubgroups().size() == 3;
    }
    for (JChannel ch : Arrays.asList(s, t, u, v)) {
      View view = ch.getView();
      assert view.size() == 4 : "view should have 4 members: " + view;
    }
  }
Ejemplo n.º 6
0
  /**
   * Tests A|6, A|7, A|8 and B|7, B|8, B|9 -> we should have a subviews in MergeView consisting of
   * only 2 elements: A|5 and B|5
   */
  public void testMultipleViewsBySameMembers() throws Exception {
    View a1 =
        View.create(
            a.getAddress(),
            6,
            a.getAddress(),
            b.getAddress(),
            c.getAddress(),
            d.getAddress()); // {A,B,C,D}
    View a2 =
        View.create(a.getAddress(), 7, a.getAddress(), b.getAddress(), c.getAddress()); // {A,B,C}
    View a3 = View.create(a.getAddress(), 8, a.getAddress(), b.getAddress()); // {A,B}
    View a4 = View.create(a.getAddress(), 9, a.getAddress()); // {A}

    View b1 = View.create(b.getAddress(), 7, b.getAddress(), c.getAddress(), d.getAddress());
    View b2 = View.create(b.getAddress(), 8, b.getAddress(), c.getAddress());
    View b3 = View.create(b.getAddress(), 9, b.getAddress());

    Util.close(c, d); // not interested in those...

    // A and B cannot communicate:
    discard(true, a, b);

    // inject view A|6={A} into A and B|5={B} into B
    injectView(a4, a);
    injectView(b3, b);

    assert a.getView().equals(a4);
    assert b.getView().equals(b3);

    List<Event> merge_events = new ArrayList<>();
    for (View view : Arrays.asList(a3, a4, a2, a1)) {
      MERGE3.MergeHeader hdr = MERGE3.MergeHeader.createInfo(view.getViewId(), null, null);
      Message msg = new Message(null, a.getAddress(), null).putHeader(merge_id, hdr);
      merge_events.add(new Event(Event.MSG, msg));
    }
    for (View view : Arrays.asList(b2, b3, b1)) {
      MERGE3.MergeHeader hdr = MERGE3.MergeHeader.createInfo(view.getViewId(), null, null);
      Message msg = new Message(null, b.getAddress(), null).putHeader(merge_id, hdr);
      merge_events.add(new Event(Event.MSG, msg));
    }

    // A and B can communicate again
    discard(false, a, b);

    injectMergeEvents(merge_events, a, b);
    checkInconsistencies(a, b); // merge will happen between A and B
    Util.waitUntilAllChannelsHaveSameSize(10000, 500, a, b);
    System.out.println("A's view: " + a.getView() + "\nB's view: " + b.getView());
    assert a.getView().size() == 2;
    assert a.getView().containsMember(a.getAddress());
    assert a.getView().containsMember(b.getAddress());
    assert a.getView().equals(b.getView());
    for (View merge_view : Arrays.asList(getViewFromGMS(a), getViewFromGMS(b))) {
      System.out.println(merge_view);
      assert merge_view instanceof MergeView;
      List<View> subviews = ((MergeView) merge_view).getSubgroups();
      assert subviews.size() == 2;
    }
  }
Ejemplo n.º 7
0
  /** A: {A,B} B: {A,B} C: {C} C receives INFO from B only */
  public void testMergeWithIncompleteInfos() throws Exception {
    Util.close(d);
    enableInfoSender(false, a, b, c);
    View one = View.create(a.getAddress(), 10, a.getAddress(), b.getAddress());
    View two = View.create(c.getAddress(), 10, c.getAddress());
    injectView(one, a, b);
    injectView(two, c);
    enableInfoSender(false, a, b, c);

    Util.waitUntilAllChannelsHaveSameSize(10000, 500, a, b);
    Util.waitUntilAllChannelsHaveSameSize(10000, 500, c);
    System.out.printf("\nPartitions:\n");
    for (JChannel ch : Arrays.asList(a, b, c))
      System.out.println(ch.getName() + ": " + ch.getView());

    MERGE3.MergeHeader hdr = MERGE3.MergeHeader.createInfo(one.getViewId(), null, null);
    Message msg =
        new Message(null, b.getAddress(), null)
            .putHeader(merge_id, hdr); // B sends the INFO message to C
    Event merge_event = new Event(Event.MSG, msg);
    MERGE3 merge = (MERGE3) c.getProtocolStack().findProtocol(MERGE3.class);
    merge.up(merge_event);
    enableInfoSender(true, a, b, c);
    System.out.println("\nEnabling INFO sending in merge protocols to merge subclusters");

    Util.waitUntilAllChannelsHaveSameSize(30000, 1000, a, b, c);
    System.out.println("\nResulting views:");
    for (JChannel ch : Arrays.asList(a, b, c)) {
      GMS gms = (GMS) ch.getProtocolStack().findProtocol(GMS.class);
      View mv = gms.view();
      System.out.println(mv);
    }
    for (JChannel ch : Arrays.asList(a, b, c)) {
      GMS gms = (GMS) ch.getProtocolStack().findProtocol(GMS.class);
      View mv = gms.view();
      assert mv instanceof MergeView;
      assert mv.size() == 3;
      assert ((MergeView) mv).getSubgroups().size() == 2;
    }
    for (JChannel ch : Arrays.asList(a, b, c)) {
      View view = ch.getView();
      assert view.size() == 3 : "view should have 3 members: " + view;
    }
  }
Ejemplo n.º 8
0
  /**
   * Tests a simple split: {A,B} and {C,D} need to merge back into one subgroup. Checks how many
   * MergeViews are installed
   */
  public void testSplitInTheMiddle() {
    View v1 = View.create(a.getAddress(), 10, a.getAddress(), b.getAddress());
    View v2 = View.create(c.getAddress(), 10, c.getAddress(), d.getAddress());

    injectView(v1, a, b);
    injectView(v2, c, d);
    Util.waitUntilAllChannelsHaveSameSize(10000, 500, a, b);
    Util.waitUntilAllChannelsHaveSameSize(10000, 500, c, d);
    for (JChannel ch : Arrays.asList(a, b, c, d))
      System.out.println(ch.getName() + ": " + ch.getView());
    Address merge_leader_one =
        new Membership().add(a.getAddress(), b.getAddress()).sort().elementAt(0);
    Address merge_leader_two =
        new Membership().add(c.getAddress(), d.getAddress()).sort().elementAt(0);

    for (int x = 0; x < 20; x++) {
      if (a.getView().size() == 4
          && b.getView().size() == 4
          && c.getView().size() == 4
          && d.getView().size() == 4) break;

      for (JChannel ch : Arrays.asList(a, b, c, d)) {
        MERGE3 merge = (MERGE3) ch.getProtocolStack().findProtocol(MERGE3.class);
        merge.sendInfo(); // multicasts an INFO msg to everybody else
      }

      for (JChannel ch :
          Arrays.asList(findChannel(merge_leader_one), findChannel(merge_leader_two))) {
        MERGE3 merge = (MERGE3) ch.getProtocolStack().findProtocol(MERGE3.class);
        merge.checkInconsistencies();
      }
      Util.sleep(1000);
    }

    for (JChannel ch : Arrays.asList(a, b, c, d))
      System.out.println(ch.getName() + ": " + ch.getView());
    for (JChannel ch : Arrays.asList(a, b, c, d))
      assert ch.getView().size() == 4 : "view of " + ch.getName() + ": " + ch.getView();
  }
Ejemplo n.º 9
0
  /**
   * Tests the scenario described by Dan in https://issues.jboss.org/browse/JGRP-1876; INFO messages
   * are injected
   */
  public void testJGRP_1876_Dan2() throws Exception {
    Util.close(d, c, b, a);
    s = createChannel("S", false);
    t = createChannel("T", false);
    u = createChannel("U", false);
    v = createChannel("V", false);
    for (JChannel ch : Arrays.asList(s, t, u, v))
      ch.getProtocolStack().removeProtocol(MERGE3.class);
    s.connect("MergeTest4");
    t.connect("MergeTest4");
    u.connect("MergeTest4");
    v.connect("MergeTest4");
    Util.waitUntilAllChannelsHaveSameSize(10000, 500, s, t, u, v);

    for (JChannel ch : Arrays.asList(s, t, u, v))
      System.out.println(ch.getName() + ": " + ch.getView());
    View v1 = View.create(s.getAddress(), 10, s.getAddress());
    View v2 = View.create(t.getAddress(), 10, t.getAddress());
    View v3 = View.create(u.getAddress(), 11, u.getAddress(), v.getAddress());
    injectView(v1, s);
    injectView(v2, t);
    injectView(v3, u, v);
    Util.waitUntilAllChannelsHaveSameSize(10000, 500, s);
    Util.waitUntilAllChannelsHaveSameSize(10000, 500, t);
    Util.waitUntilAllChannelsHaveSameSize(10000, 500, u, v);

    System.out.printf("\nPartitions:\n");
    for (JChannel ch : Arrays.asList(s, t, u, v))
      System.out.println(ch.getName() + ": " + ch.getView());

    System.out.println("\nInjecting MERGE events into GMS to merge subclusters");
    Map<Address, View> different_views = new HashMap<>();
    different_views.put(s.getAddress(), v1);
    different_views.put(t.getAddress(), v2);
    different_views.put(v.getAddress(), v3);

    Collection<Address> coords = Util.determineActualMergeCoords(different_views);
    Address merge_leader = new Membership().add(coords).sort().elementAt(0);
    System.out.printf("--> coords=%s, merge_leader=%s\n", coords, merge_leader);
    GMS gms = (GMS) findChannel(merge_leader).getProtocolStack().findProtocol(GMS.class);
    gms.up(new Event(Event.MERGE, different_views));

    Util.waitUntilAllChannelsHaveSameSize(30000, 1000, s, t, u, v);
    System.out.println("\nResulting views:");
    for (JChannel ch : Arrays.asList(s, t, u, v)) {
      gms = (GMS) ch.getProtocolStack().findProtocol(GMS.class);
      View mv = gms.view();
      System.out.println(mv);
    }
    for (JChannel ch : Arrays.asList(s, t, u, v)) {
      gms = (GMS) ch.getProtocolStack().findProtocol(GMS.class);
      View mv = gms.view();
      assert mv instanceof MergeView;
      assert mv.size() == 4;
      assert ((MergeView) mv).getSubgroups().size() == 3;
    }
    for (JChannel ch : Arrays.asList(s, t, u, v)) {
      View view = ch.getView();
      assert view.size() == 4 : "view should have 4 members: " + view;
    }
  }
Ejemplo n.º 10
0
  /** Tests the scenario described by Karim in https://issues.jboss.org/browse/JGRP-1876 */
  public void testJGRP_1876() throws Exception {
    e = createChannel("E", true);
    f = createChannel("F", true);
    g = createChannel("G", true);
    h = createChannel("H", true);
    Util.waitUntilAllChannelsHaveSameSize(10000, 500, a, b, c, d, e, f, g, h);
    enableInfoSender(false, a, b, c, d, e, f, g, h); // stops INFO sending in MERGE3
    for (JChannel ch : Arrays.asList(a, b, c, d, e, f, g, h))
      System.out.println(ch.getName() + ": " + ch.getView());
    View v1 =
        View.create(
            a.getAddress(), 10, a.getAddress(), b.getAddress(), c.getAddress(), d.getAddress());
    View v2 =
        View.create(
            a.getAddress(),
            9,
            a.getAddress(),
            b.getAddress(),
            c.getAddress(),
            d.getAddress(),
            e.getAddress(),
            f.getAddress());
    View v3 = View.create(g.getAddress(), 8, g.getAddress(), h.getAddress());

    injectView(v1, a, b, c, d);
    injectView(v2, e, f);
    injectView(v3, g, h);
    enableInfoSender(false, a, b, c, d, e, f, g, h); // stops INFO sending in MERGE3
    Util.waitUntilAllChannelsHaveSameSize(10000, 500, a, b, c, d);
    for (int x = 0;
        x < 10;
        x++) { // can't use waitUntilAllChannelsHaveSameSize() as the channel list's length != view
      // !
      if (e.getView().size() == v2.size() && f.getView().size() == v2.size()) break;
      Util.sleep(500);
    }
    assert e.getView().size() == v2.size() : "E's view: " + e.getView();
    assert f.getView().size() == v2.size() : "F's view: " + f.getView();
    Util.waitUntilAllChannelsHaveSameSize(10000, 500, g, h);

    System.out.printf("\nPartitions:\n");
    for (JChannel ch : Arrays.asList(a, b, c, d, e, f, g, h))
      System.out.println(ch.getName() + ": " + ch.getView());

    enableInfoSender(true, a, b, c, d, e, f, g, h);
    System.out.println("\nEnabling INFO sending in merge protocols to merge subclusters");

    Util.waitUntilAllChannelsHaveSameSize(30000, 1000, a, b, c, d, e, f, g, h);
    System.out.println("\nResulting views:");
    for (JChannel ch : Arrays.asList(a, b, c, d, e, f, g, h)) {
      GMS gms = (GMS) ch.getProtocolStack().findProtocol(GMS.class);
      View mv = gms.view();
      System.out.println(mv);
    }
    for (JChannel ch : Arrays.asList(a, b, c, d, e, f, g, h)) {
      GMS gms = (GMS) ch.getProtocolStack().findProtocol(GMS.class);
      View mv = gms.view();
      assert mv instanceof MergeView;
      assert mv.size() == 8;
      assert ((MergeView) mv).getSubgroups().size() == 3;
    }
    for (JChannel ch : Arrays.asList(a, b, c, d, e, f, g, h)) {
      View view = ch.getView();
      assert view.size() == 8 : "view should have 8 members: " + view;
    }
  }