Пример #1
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;
    }
  }
  public void testNullMessageToAll() throws Exception {
    d1.setRequestHandler(new MyHandler(null));

    c2 = createChannel(c1);
    c2.setName("B");
    disableBundling(c2);
    long stop, start = System.currentTimeMillis();
    d2 = new MessageDispatcher(c2, null, null, new MyHandler(null));
    stop = System.currentTimeMillis();
    c2.connect("MessageDispatcherUnitTest");
    Assert.assertEquals(2, c2.getView().size());
    System.out.println("view: " + c2.getView());

    System.out.println("casting message");
    start = System.currentTimeMillis();
    RspList rsps = d1.castMessage(null, new Message(), new RequestOptions(ResponseMode.GET_ALL, 0));
    stop = System.currentTimeMillis();
    System.out.println("rsps:\n" + rsps);
    System.out.println("call took " + (stop - start) + " ms");
    assertNotNull(rsps);
    Assert.assertEquals(2, rsps.size());
    Rsp rsp = rsps.get(c1.getAddress());
    assertNotNull(rsp);
    Object ret = rsp.getValue();
    assert ret == null;

    rsp = rsps.get(c2.getAddress());
    assertNotNull(rsp);
    ret = rsp.getValue();
    assert ret == null;

    Util.close(c2);
  }
Пример #3
0
  public static void main(String[] args) throws Exception {

    JChannel channel = new JChannel();

    channel.setReceiver(
        new ReceiverAdapter() {

          public void receive(Message msg) {
            Address sender = msg.getSrc();
            System.out.println(msg.getObject() + " [" + sender + "]");
          }

          public void viewAccepted(View view) {
            System.out.println("view: " + view);
          }
        });

    channel.connect("ChatCluster");

    System.out.println(
        channel.getView().getCreator().equals(channel.getView().getMembers().get(0)));

    for (; ; ) {
      String line = Util.readStringFromStdin(": ");
      channel.send(null, line);
    }
  }
Пример #4
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());
  }
Пример #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;
    }
  }
  private void sendMessageToBothChannels(int size) throws Exception {
    long start, stop;
    d1.setRequestHandler(new MyHandler(new byte[size]));

    c2 = createChannel(c1);
    c2.setName("B");
    disableBundling(c2);
    d2 = new MessageDispatcher(c2, null, null, new MyHandler(new byte[size]));
    c2.connect("MessageDispatcherUnitTest");
    Assert.assertEquals(2, c2.getView().size());

    System.out.println("casting message");
    start = System.currentTimeMillis();
    RspList rsps = d1.castMessage(null, new Message(), new RequestOptions(ResponseMode.GET_ALL, 0));
    stop = System.currentTimeMillis();
    System.out.println("rsps:\n" + rsps);
    System.out.println("call took " + (stop - start) + " ms");
    assertNotNull(rsps);
    Assert.assertEquals(2, rsps.size());
    Rsp rsp = rsps.get(c1.getAddress());
    assertNotNull(rsp);
    byte[] ret = (byte[]) rsp.getValue();
    Assert.assertEquals(size, ret.length);

    rsp = rsps.get(c2.getAddress());
    assertNotNull(rsp);
    ret = (byte[]) rsp.getValue();
    Assert.assertEquals(size, ret.length);

    Util.close(c2);
  }
Пример #7
0
  public void testFlushWithCrashedParticipants() throws Exception {
    JChannel c1 = null;
    JChannel c2 = null;
    JChannel c3 = null;

    try {
      c1 = createChannel(true, 3, "C1");
      changeProps(c1);
      c1.connect("testFlushWithCrashedFlushCoordinator");

      c2 = createChannel(c1, "C2");
      changeProps(c2);
      c2.connect("testFlushWithCrashedFlushCoordinator");

      c3 = createChannel(c1, "C3");
      changeProps(c3);
      c3.connect("testFlushWithCrashedFlushCoordinator");

      // and then kill members other than flush coordinator
      Util.shutdown(c3);
      Util.shutdown(c1);

      // start flush
      Util.startFlush(c2);

      c2.stopFlush();
      Util.waitUntilAllChannelsHaveSameSize(10000, 500, c2);

      // cluster should not hang and one remaining member should have a correct view
      assertTrue("correct view size", c2.getView().size() == 1);
    } finally {
      Util.close(c3, c2, c1);
    }
  }
Пример #8
0
 void printView() {
   System.out.println("\n-- view: " + channel.getView() + '\n');
   try {
     System.in.skip(System.in.available());
   } catch (Exception e) {
   }
 }
Пример #9
0
 private boolean checkViewSize(int expectedSize, JChannel... channels) {
   boolean b = true;
   for (JChannel ch : channels) {
     b = b && ch.getView().size() == expectedSize;
   }
   return b;
 }
Пример #10
0
  /**
   * Takes a membership of 10, e.g. {A,B,C,D,E,F,G,H,I,J}, creates multiple partitions (e.g.
   * {A,B,C}, {D}, {E,F,G,H}, {I,J}), and merges them back into one cluster. Asserts that there's
   * only 1 MergeView
   */
  public void testMultipleSplits() throws Exception {
    e = createChannel("E", true);
    f = createChannel("F", true);
    g = createChannel("G", true);
    h = createChannel("H", true);
    i = createChannel("I", true);
    j = createChannel("J", true);
    Util.waitUntilAllChannelsHaveSameSize(10000, 500, a, b, c, d, e, f, g, h, i, j);
    enableInfoSender(false, a, b, c, d, e, f, g, h, i, j); // stops INFO sending in MERGE3
    for (JChannel ch : Arrays.asList(a, b, c, d, e, f, g, h, i, j))
      System.out.println(ch.getName() + ": " + ch.getView());
    List<View> partitions = createPartitions(4, a, b, c, d, e, f, g, h, i, j);

    // Install views
    for (View partition : partitions) {
      for (Address mbr : partition.getMembersRaw()) {
        JChannel ch = findChannel(mbr);
        injectView(partition, ch);
      }
    }

    System.out.printf("\n%d partitions:\n", partitions.size());
    for (JChannel ch : Arrays.asList(a, b, c, d, e, f, g, h, i, j))
      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, e, f, g, h, i, j);

    Util.waitUntilAllChannelsHaveSameSize(30000, 1000, a, b, c, d, e, f, g, h, i, j);
    System.out.println("\nResulting views:");
    for (JChannel ch : Arrays.asList(a, b, c, d, e, f, g, h, i, j)) {
      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, i, j)) {
      GMS gms = (GMS) ch.getProtocolStack().findProtocol(GMS.class);
      View mv = gms.view();
      assert mv instanceof MergeView;
      assert mv.size() == 10;
      assert ((MergeView) mv).getSubgroups().size() == partitions.size();
    }
    for (JChannel ch : Arrays.asList(a, b, c, d, e, f, g, h, i, j)) {
      View view = ch.getView();
      assert view.size() == 10 : "view should have 10 members: " + view;
    }
  }
Пример #11
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;
    }
  }
 private Address getAddress(String nodeName) {
   for (Address member : channel.getView()) {
     if (channel.getName(member).equals(nodeName)) {
       return member;
     }
   }
   throw new IllegalArgumentException(
       "Given node doesn't seem to be a member of the DistributedCommandBus");
 }
Пример #13
0
 public void testSASLDigestMD5Merge() throws Exception {
   a = createChannel("A", "DIGEST-MD5", "jack");
   b = createChannel("B", "DIGEST-MD5", "jack");
   a.connect("SaslTest");
   b.connect("SaslTest");
   assertTrue(b.isConnected());
   print(a, b);
   createPartitions(a, b);
   print(a, b);
   assertTrue(checkViewSize(1, a, b));
   dropDiscard(a, b);
   mergePartitions(a, b);
   for (int i = 0; i < 10 && !checkViewSize(2, a, b); i++) {
     Util.sleep(500);
   }
   assertTrue(viewContains(a.getView(), a, b));
   assertTrue(viewContains(b.getView(), a, b));
 }
Пример #14
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;
    }
  }
 private static void injectView(View view, JChannel... channels) {
   for (JChannel ch : channels) {
     ch.down(new Event(Event.VIEW_CHANGE, view));
     ch.up(new Event(Event.VIEW_CHANGE, view));
   }
   for (JChannel ch : channels) {
     MyReceiver receiver = (MyReceiver) ch.getReceiver();
     System.out.println("[" + receiver.name + "] view=" + ch.getView());
   }
 }
Пример #16
0
 void setAnycastCount() throws Exception {
   int tmp = Util.readIntFromStdin("Anycast count: ");
   View view = channel.getView();
   if (tmp > view.size()) {
     System.err.println(
         "anycast count must be smaller or equal to the view size (" + view + ")\n");
     return;
   }
   disp.callRemoteMethods(null, new MethodCall(SET_ANYCAST_COUNT, tmp), RequestOptions.SYNC());
 }
Пример #17
0
 /** Picks the next member in the view */
 private Address getReceiver() {
   try {
     List<Address> mbrs = channel.getView().getMembers();
     int index = mbrs.indexOf(local_addr);
     int new_index = index + 1 % mbrs.size();
     return mbrs.get(new_index);
   } catch (Exception e) {
     System.err.println("UPerf.getReceiver(): " + e);
     return null;
   }
 }
Пример #18
0
  public void testMergeWithAsymetricViewsCoordIsolated() {
    // Isolate the coord
    Address coord = a.getView().getCreator();
    System.out.println("Isolating coord: " + coord);
    List<Address> members = new ArrayList<>();
    members.add(coord);
    View coord_view = new View(coord, 4, members);
    System.out.println("coord_view: " + coord_view);
    Channel coord_channel = findChannel(coord);
    System.out.println("coord_channel: " + coord_channel.getAddress());

    MutableDigest digest = new MutableDigest(coord_view.getMembersRaw());
    NAKACK2 nakack = (NAKACK2) coord_channel.getProtocolStack().findProtocol(NAKACK2.class);
    digest.merge(nakack.getDigest(coord));

    GMS gms = (GMS) coord_channel.getProtocolStack().findProtocol(GMS.class);
    gms.installView(coord_view, digest);
    System.out.println("gms.getView() " + gms.getView());

    System.out.println("Views are:");
    for (JChannel ch : Arrays.asList(a, b, c, d))
      System.out.println(ch.getAddress() + ": " + ch.getView());

    JChannel merge_leader = findChannel(coord);
    MyReceiver receiver = new MyReceiver();
    merge_leader.setReceiver(receiver);

    System.out.println("merge_leader: " + merge_leader.getAddressAsString());

    System.out.println("Injecting MERGE event into merge leader " + merge_leader.getAddress());
    Map<Address, View> merge_views = new HashMap<>(4);
    merge_views.put(a.getAddress(), a.getView());
    merge_views.put(b.getAddress(), b.getView());
    merge_views.put(c.getAddress(), c.getView());
    merge_views.put(d.getAddress(), d.getView());

    gms = (GMS) merge_leader.getProtocolStack().findProtocol(GMS.class);
    gms.up(new Event(Event.MERGE, merge_views));

    Util.waitUntilAllChannelsHaveSameSize(10000, 1000, a, b, c, d);

    System.out.println("Views are:");
    for (JChannel ch : Arrays.asList(a, b, c, d)) {
      View view = ch.getView();
      System.out.println(ch.getAddress() + ": " + view);
      assert view.size() == 4;
    }
    MergeView merge_view = receiver.getView();
    System.out.println("merge_view = " + merge_view);
    assert merge_view.size() == 4;
    assert merge_view.getSubgroups().size() == 2;

    for (View view : merge_view.getSubgroups())
      assert contains(view, a.getAddress())
          || contains(view, b.getAddress(), c.getAddress(), d.getAddress());
  }
Пример #19
0
  public void testFlushWithCrashedFlushCoordinator() throws Exception {
    JChannel a = null, b = null, c = null;
    try {
      a = createChannel(true, 3, "A");
      changeProps(a);
      a.connect("testFlushWithCrashedFlushCoordinator");

      b = createChannel(a, "B");
      changeProps(b);
      b.connect("testFlushWithCrashedFlushCoordinator");

      c = createChannel(a, "C");
      changeProps(c);
      c.connect("testFlushWithCrashedFlushCoordinator");

      System.out.println("shutting down flush coordinator B");
      b.down(new Event(Event.SUSPEND_BUT_FAIL)); // send out START_FLUSH and then return

      // now shut down B. This means, after failure detection kicks in and the new coordinator takes
      // over
      // (either A or C), that the current flush started by B will be cancelled and a new flush (by
      // A or C)
      // will be started
      Util.shutdown(b);

      a.getProtocolStack().findProtocol(FLUSH.class).setLevel("debug");
      c.getProtocolStack().findProtocol(FLUSH.class).setLevel("debug");

      Util.waitUntilAllChannelsHaveSameSize(10000, 500, a, c);

      // cluster should not hang and two remaining members should have a correct view
      assertTrue("correct view size", a.getView().size() == 2);
      assertTrue("correct view size", c.getView().size() == 2);

      a.getProtocolStack().findProtocol(FLUSH.class).setLevel("warn");
      c.getProtocolStack().findProtocol(FLUSH.class).setLevel("warn");

    } finally {
      Util.close(c, b, a);
    }
  }
Пример #20
0
  public void testFlushWithCrashedParticipant() throws Exception {
    JChannel c1 = null;
    JChannel c2 = null;
    JChannel c3 = null;

    try {
      c1 = createChannel(true, 3, "C1");
      changeProps(c1);
      c1.connect("testFlushWithCrashedParticipant");

      c2 = createChannel(c1, "C2");
      changeProps(c2);
      c2.connect("testFlushWithCrashedParticipant");

      c3 = createChannel(c1, "C3");
      changeProps(c3);
      c3.connect("testFlushWithCrashedParticipant");

      System.out.println("shutting down C3");
      Util.shutdown(c3); // kill a flush participant

      System.out.println("C2: starting flush");
      boolean rc = Util.startFlush(c2);
      System.out.println("flush " + (rc ? " was successful" : "failed"));
      assert rc;

      System.out.println("stopping flush");
      c2.stopFlush();

      System.out.println("waiting for view to contain C1 and C2");
      Util.waitUntilAllChannelsHaveSameSize(10000, 500, c1, c2);

      // cluster should not hang and two remaining members should have a correct view
      System.out.println("C1: view=" + c1.getView() + "\nC2: view=" + c2.getView());
      assertTrue("correct view size", c1.getView().size() == 2);
      assertTrue("correct view size", c2.getView().size() == 2);
    } finally {
      Util.close(c3, c2, c1);
    }
  }
Пример #21
0
  /**
   * When we flush the server queue and one or more of the delivered messages triggers a response
   * (in the same thread), we need to make sure the channel is connected, or else the JOIN will fail
   * as the exception happens on the same thread. Note that the suggested fix on JGRP-1522 will
   * solve this. Issue: https://issues.jboss.org/browse/JGRP-1522
   */
  @BMScript(dir = "scripts/BecomeServerTest", value = "testSendingOfMsgsOnUnconnectedChannel")
  public void testSendingOfMsgsOnUnconnectedChannel() throws Exception {
    a = createChannel("A");
    a.setReceiver(
        new ReceiverAdapter() {
          public void receive(Message msg) {
            System.out.println("A: received message from " + msg.getSrc() + ": " + msg.getObject());
          }
        });
    a.connect("BecomeServerTest");

    new Thread("MsgSender-A") {
      public void run() {
        sendMessage(a, "hello from A"); // will be blocked by byteman rendezvous
      }
    }.start();

    b = createChannel("B");
    b.setReceiver(
        new ReceiverAdapter() {
          public void receive(Message msg) {
            System.out.println("B: received message from " + msg.getSrc() + ": " + msg.getObject());
            if (msg.getSrc().equals(a.getAddress())) {
              try {
                b.send(
                    null,
                    "This message would trigger an exception if the channel was not yet connected");
              } catch (Exception e) {
                throw new RuntimeException(e);
              }
            }
          }
        });

    b.connect("BecomeServerTest");

    Util.waitUntilAllChannelsHaveSameSize(20000, 1000, a, b);

    System.out.println("\nA: " + a.getView() + "\nB: " + b.getView());
  }
  /**
   * Verifies that unicasts are received correctly by all participants after an overlapping merge.
   * The following steps are executed:
   *
   * <ol>
   *   <li/>Group is {A,B,C}, A is the coordinator
   *   <li/>MERGE2 is removed from all members
   *   <li/>VERIFY_SUSPECT is removed from all members
   *   <li/>Everyone sends 5 unicast messages to everyone else
   *   <li/>A VIEW(B,C) is injected into B and C
   *   <li/>B and C install {B,C}
   *   <li/>B and C trash the connection table for A in UNICAST
   *   <li/>A still has view {A,B,C} and all connection tables intact in UNICAST
   *   <li/>We now send N unicasts from everyone to everyone else, all the unicasts should be
   *       received.
   * </ol>
   */
  public void testWithViewBC() throws Exception {

    System.out.println("A's view: " + a.getView());

    // Inject view {B,C} into B and C:
    View new_view = Util.createView(b.getAddress(), 10, b.getAddress(), c.getAddress());
    injectView(new_view, b, c);
    assertEquals("A's view is " + a.getView(), 3, a.getView().size());
    assertEquals("B's view is " + b.getView(), 2, b.getView().size());
    assertEquals("C's view is " + c.getView(), 2, c.getView().size());
    sendAndCheckMessages(5, a, b, c);
  }
Пример #23
0
  public int numLocalInstances() {
    java.util.List<Address> members = channel.getView().getMembers();
    int instances = 0;

    java.util.Iterator<Address> it = members.iterator();
    while (it.hasNext()) {
      Address addr = it.next();
      UUID uuid = (UUID) addr;
      if (uuid.toString().startsWith(hostName)) {
        instances++;
      }
    }
    return instances;
  }
Пример #24
0
 @BeforeMethod
 void init() throws Exception {
   a = createChannel(true, 2);
   a.setName("A");
   b = createChannel(a);
   b.setName("B");
   setOOBPoolSize(a, b);
   setStableGossip(a, b);
   a.connect("OOBTest");
   b.connect("OOBTest");
   View view = b.getView();
   System.out.println("view = " + view);
   Util.waitUntilAllChannelsHaveSameSize(20000, 1000, a, b);
 }
Пример #25
0
 @BeforeMethod
 public void init() throws Exception {
   c1 = createChannel(true, 2);
   c1.setName("C1");
   c2 = createChannel(c1);
   c2.setName("C2");
   setOOBPoolSize(c1, c2);
   setStableGossip(c1, c2);
   c1.connect("OOBTest");
   c2.connect("OOBTest");
   View view = c2.getView();
   log.info("view = " + view);
   Util.waitUntilAllChannelsHaveSameSize(20000, 1000, c1, c2);
 }
Пример #26
0
 @BeforeMethod
 public void init() throws Exception {
   c1 = createChannel(true, 2);
   c1.setName("C1");
   c2 = createChannel(c1);
   c2.setName("C2");
   setOOBPoolSize(c1, c2);
   setStableGossip(c1, c2);
   c1.connect("OOBTest");
   c2.connect("OOBTest");
   View view = c2.getView();
   log.info("view = " + view);
   assert view.size() == 2 : "view is " + view;
 }
Пример #27
0
  /**
   * Creates a list of randomly generated partitions, each having a max size of max_partition_size
   */
  protected List<View> createPartitions(int max_partition_size, JChannel... channels) {
    long view_id = 1;
    for (JChannel ch : channels) view_id = Math.max(view_id, ch.getView().getViewId().getId());
    List<View> partitions = new ArrayList<>();
    List<Address> tmp = new ArrayList<>();
    for (JChannel ch : channels) tmp.add(ch.getAddress());

    while (!tmp.isEmpty()) {
      int num_to_remove = (int) Util.random(max_partition_size);
      List<Address> part = new ArrayList<>(max_partition_size);
      for (int x = 0; x < num_to_remove && !tmp.isEmpty(); x++) part.add(tmp.remove(0));
      partitions.add(new View(part.get(0), view_id + 1, part));
    }
    return partitions;
  }
Пример #28
0
  @BeforeMethod
  void setUp() throws Exception {
    System.out.print("Connecting channels: ");
    a = createChannel("A");
    disp_a = new MessageDispatcher(a, null, null);
    a.connect(RpcLockingTest.class.getSimpleName());
    lock_a = new LockService(a).getLock("lock");

    b = createChannel("B");
    disp_b = new MessageDispatcher(b, null, null);
    b.connect(RpcLockingTest.class.getSimpleName());
    lock_b = new LockService(b).getLock("lock");

    Util.waitUntilAllChannelsHaveSameSize(30000, 1000, a, b);
    System.out.println("");

    disp_a.setRequestHandler(
        new RequestHandler() {
          @Override
          public Object handle(Message arg0) throws Exception {
            System.out.println("A received a message, will now try to lock the lock");
            if (lock_a.tryLock()) {
              Assert.fail("Should not be able to lock the lock here");
              System.out.println("A aquired the lock, this shouldn't be possible");
            } else System.out.println("The lock was already locked, as it should be");
            return "Hello";
          }
        });

    disp_b.setRequestHandler(
        new RequestHandler() {
          @Override
          public Object handle(Message arg0) throws Exception {
            System.out.println("B received a message, will now try to lock the lock");
            if (lock_b.tryLock()) {
              Assert.fail("Should not be able to lock the lock here");
              System.out.println("B aquired the lock, this shouldn't be possible");
            } else System.out.println("The lock already was locked, as it should be");
            return "Hello";
          }
        });

    // Print who is the coordinator
    if (b.getView().getMembers().get(0).equals(b.getAddress()))
      System.out.println("B is the coordinator");
    else System.out.println("A is the coordinator");
    System.out.println("");
  }
Пример #29
0
 private static void mergePartitions(JChannel... channels) throws Exception {
   Membership membership = new Membership();
   for (JChannel ch : channels) {
     membership.add(ch.getAddress());
   }
   membership.sort();
   Address leaderAddress = membership.elementAt(0);
   JChannel leader = findChannelByAddress(leaderAddress, channels);
   GMS gms = (GMS) leader.getProtocolStack().findProtocol(GMS.class);
   gms.setLevel("trace");
   Map<Address, View> views = new HashMap<>();
   for (JChannel ch : channels) {
     views.put(ch.getAddress(), ch.getView());
   }
   gms.up(new Event(Event.MERGE, views));
 }
Пример #30
0
  public void testLifecycle() throws Exception {
    fc1 = new ForkChannel(ch, "stack", "fc1");
    assert fc1.isOpen() && !fc1.isConnected() && !fc1.isClosed() : "state=" + fc1.getState();

    ch.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 ch.getAddress().equals(fc1.getAddress());
    assert ch.getClusterName().equals(fc1.getClusterName());
    assert ch.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(ch);
    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);
    }
  }