コード例 #1
0
ファイル: OOBTest.java プロジェクト: julia-wei/JGroups
  public void testRegularAndOOBUnicasts2() throws Exception {
    DISCARD discard = new DISCARD();
    ProtocolStack stack = a.getProtocolStack();
    stack.insertProtocol(
        discard, ProtocolStack.BELOW, (Class<? extends Protocol>[]) Util.getUnicastProtocols());

    Address dest = b.getAddress();
    Message m1 = new Message(dest, 1);
    Message m2 = new Message(dest, 2).setFlag(Message.Flag.OOB);
    Message m3 = new Message(dest, 3).setFlag(Message.Flag.OOB);
    Message m4 = new Message(dest, 4);

    MyReceiver receiver = new MyReceiver("B");
    b.setReceiver(receiver);
    a.send(m1);

    discard.setDropDownUnicasts(2);
    a.send(m2); // dropped
    a.send(m3); // dropped
    a.send(m4);

    Collection<Integer> list = receiver.getMsgs();
    int count = 10;
    while (list.size() < 4 && --count > 0) {
      Util.sleep(500); // time for potential retransmission
      sendStableMessages(a, b);
    }
    System.out.println("list = " + list);
    assert list.size() == 4 : "list is " + list;
    assert list.contains(1) && list.contains(2) && list.contains(3) && list.contains(4);
  }
コード例 #2
0
ファイル: OOBTest.java プロジェクト: navssurtani/JGroups
  /**
   * Tests sending 1, 2 (OOB) and 3, where they are received in the order 1, 3, 2. Message 3 should
   * not get delivered until message 4 is received (http://jira.jboss.com/jira/browse/JGRP-780)
   */
  public void testRegularAndOOBUnicasts() throws Exception {
    DISCARD discard = new DISCARD();
    ProtocolStack stack = a.getProtocolStack();
    stack.insertProtocol(discard, ProtocolStack.BELOW, UNICAST.class, UNICAST2.class);

    Address dest = b.getAddress();
    Message m1 = new Message(dest, null, 1);
    Message m2 = new Message(dest, null, 2);
    m2.setFlag(Message.OOB);
    Message m3 = new Message(dest, null, 3);

    MyReceiver receiver = new MyReceiver("C2");
    b.setReceiver(receiver);
    a.send(m1);
    discard.setDropDownUnicasts(1);
    a.send(m2);
    a.send(m3);

    Collection<Integer> list = receiver.getMsgs();
    int count = 10;
    while (list.size() < 3 && --count > 0) {
      Util.sleep(500); // time for potential retransmission
      sendStableMessages(a, b);
    }

    assert list.size() == 3 : "list is " + list;
    assert list.contains(1) && list.contains(2) && list.contains(3);
  }
コード例 #3
0
ファイル: OOBTest.java プロジェクト: navssurtani/JGroups
  public void testRegularAndOOBMulticasts() throws Exception {
    DISCARD discard = new DISCARD();
    ProtocolStack stack = a.getProtocolStack();
    stack.insertProtocol(discard, ProtocolStack.BELOW, NAKACK2.class);
    a.setDiscardOwnMessages(true);

    Address dest = null; // send to all
    Message m1 = new Message(dest, null, 1);
    Message m2 = new Message(dest, null, 2);
    m2.setFlag(Message.OOB);
    Message m3 = new Message(dest, null, 3);

    MyReceiver receiver = new MyReceiver("C2");
    b.setReceiver(receiver);
    a.send(m1);
    discard.setDropDownMulticasts(1);
    a.send(m2);
    a.send(m3);

    Util.sleep(500);
    Collection<Integer> list = receiver.getMsgs();
    for (int i = 0; i < 10; i++) {
      System.out.println("list = " + list);
      if (list.size() == 3) break;
      Util.sleep(1000); // give the asynchronous msgs some time to be received
      sendStableMessages(a, b);
    }
    assert list.size() == 3 : "list is " + list;
    assert list.contains(1) && list.contains(2) && list.contains(3);
  }
コード例 #4
0
ファイル: OOBTest.java プロジェクト: navssurtani/JGroups
  /** Tests https://jira.jboss.org/jira/browse/JGRP-1079 */
  public void testOOBMessageLoss() throws Exception {
    Util.close(b); // we only need 1 channel
    MyReceiver receiver = new MySleepingReceiver("C1", 1000);
    a.setReceiver(receiver);

    TP transport = a.getProtocolStack().getTransport();
    transport.setOOBRejectionPolicy("discard");

    final int NUM = 10;

    for (int i = 1; i <= NUM; i++) {
      Message msg = new Message(null, null, i);
      msg.setFlag(Message.OOB);
      a.send(msg);
    }
    STABLE stable = (STABLE) a.getProtocolStack().findProtocol(STABLE.class);
    if (stable != null) stable.runMessageGarbageCollection();
    Collection<Integer> msgs = receiver.getMsgs();

    for (int i = 0; i < 20; i++) {
      if (msgs.size() == NUM) break;
      Util.sleep(1000);
      sendStableMessages(a, b);
    }

    System.out.println("msgs = " + Util.print(msgs));

    assert msgs.size() == NUM
        : "expected " + NUM + " messages but got " + msgs.size() + ", msgs=" + Util.print(msgs);
    for (int i = 1; i <= NUM; i++) {
      assert msgs.contains(i);
    }
  }
コード例 #5
0
ファイル: OOBTest.java プロジェクト: navssurtani/JGroups
  /** Tests https://jira.jboss.org/jira/browse/JGRP-1079 for unicast messages */
  public void testOOBUnicastMessageLoss() throws Exception {
    MyReceiver receiver = new MySleepingReceiver("C2", 1000);
    b.setReceiver(receiver);

    a.getProtocolStack().getTransport().setOOBRejectionPolicy("discard");

    final int NUM = 10;
    final Address dest = b.getAddress();
    for (int i = 1; i <= NUM; i++) {
      Message msg = new Message(dest, null, i);
      msg.setFlag(Message.OOB);
      a.send(msg);
    }

    Collection<Integer> msgs = receiver.getMsgs();

    for (int i = 0; i < 20; i++) {
      if (msgs.size() == NUM) break;
      Util.sleep(1000);
      // sendStableMessages(c1,c2); // not needed for unicasts !
    }

    assert msgs.size() == NUM
        : "expected " + NUM + " messages but got " + msgs.size() + ", msgs=" + Util.print(msgs);
    for (int i = 1; i <= NUM; i++) {
      assert msgs.contains(i);
    }
  }
コード例 #6
0
ファイル: MergeTest4.java プロジェクト: xiongrl/JGroups
  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());
  }
コード例 #7
0
  /**
   * Multiple threads (NUM_THREADS) send messages (NUM_MSGS)
   *
   * @throws Exception
   */
  @Test(dataProvider = "provider")
  public void testMessageReceptionUnderHighLoad(String props) throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    c1 = new JChannel(props);
    c2 = new JChannel(props);
    MyReceiver r1 = new MyReceiver("c1"), r2 = new MyReceiver("c2");
    c1.setReceiver(r1);
    c2.setReceiver(r2);
    c1.connect("testSimpleMessageReception");
    c2.connect("testSimpleMessageReception");

    Address c1_addr = c1.getAddress(), c2_addr = c2.getAddress();
    MySender[] c1_senders = new MySender[NUM_THREADS];
    for (int i = 0; i < c1_senders.length; i++) {
      c1_senders[i] = new MySender(c1, c2_addr, latch);
      c1_senders[i].start();
    }
    MySender[] c2_senders = new MySender[NUM_THREADS];
    for (int i = 0; i < c2_senders.length; i++) {
      c2_senders[i] = new MySender(c2, c1_addr, latch);
      c2_senders[i].start();
    }

    Util.sleep(500);
    latch.countDown(); // starts all threads

    long NUM_EXPECTED_MSGS = NUM_THREADS * NUM_MSGS;

    for (int i = 0; i < 20; i++) {
      if (r1.getNum() == NUM_EXPECTED_MSGS && r2.getNum() == NUM_EXPECTED_MSGS) break;
      Util.sleep(2000);
      UNICAST2 unicast2 = (UNICAST2) c1.getProtocolStack().findProtocol(UNICAST2.class);
      if (unicast2 != null) unicast2.sendStableMessages();
      unicast2 = (UNICAST2) c2.getProtocolStack().findProtocol(UNICAST2.class);
      if (unicast2 != null) unicast2.sendStableMessages();
    }

    System.out.println(
        "c1 received "
            + r1.getNum()
            + " msgs, "
            + getNumberOfRetransmissions(c1)
            + " retransmissions");
    System.out.println(
        "c2 received "
            + r2.getNum()
            + " msgs, "
            + getNumberOfRetransmissions(c2)
            + " retransmissions");

    assert r1.getNum() == NUM_EXPECTED_MSGS
        : "expected " + NUM_EXPECTED_MSGS + ", but got " + r1.getNum();
    assert r2.getNum() == NUM_EXPECTED_MSGS
        : "expected " + NUM_EXPECTED_MSGS + ", but got " + r2.getNum();
  }
コード例 #8
0
 private static void checkMsgDelivery(MyReceiver... rl) {
   for (MyReceiver r : rl) {
     List<Integer> list = r.getList();
     for (int i = 0; i < 20; i++) {
       if (!list.isEmpty()) break;
       Util.sleep(500);
     }
     System.out.println("list = " + list);
     assert list.size() == 1 && list.get(0) == 0;
     r.clear();
   }
 }
コード例 #9
0
  /** Tests case #3 of UNICAST.new.txt */
  public void testBothChannelsClosing() throws Exception {
    sendToEachOtherAndCheck(10);

    // now close the connections to each other
    System.out.println("==== Closing the connections on both sides");
    removeConnection(u1, b_addr);
    removeConnection(u2, a_addr);
    r1.clear();
    r2.clear();

    // causes new connection establishment
    sendToEachOtherAndCheck(10);
  }
コード例 #10
0
 private static void sendAndCheck(JChannel channel, Address dest, int num, MyReceiver receiver)
     throws Exception {
   receiver.clear();
   for (int i = 1; i <= num; i++) channel.send(dest, "m" + i);
   List<Message> list = receiver.getMessages();
   for (int i = 0; i < 20; i++) {
     if (list.size() == num) break;
     Util.sleep(500);
   }
   System.out.println("list = " + print(list));
   int size = list.size();
   assert size == num : "list has " + size + " elements: " + list;
 }
コード例 #11
0
  /**
   * Tests concurrent reception of multiple messages with a different conn_id
   * (https://issues.jboss.org/browse/JGRP-1347)
   */
  public void testMultipleConcurrentResets() throws Exception {
    sendAndCheck(a, b_addr, 1, r2);

    // now close connection on A unilaterally
    System.out.println("==== Closing the connection on A");
    removeConnection(u1, b_addr);

    r2.clear();

    final UNICAST unicast = (UNICAST) b.getProtocolStack().findProtocol(UNICAST.class);

    int NUM = 10;

    final List<Message> msgs = new ArrayList<Message>(NUM);

    for (int i = 1; i <= NUM; i++) {
      Message msg = new Message(b_addr, a_addr, "m" + i);
      UNICAST.UnicastHeader hdr = UNICAST.UnicastHeader.createDataHeader(1, (short) 2, true);
      msg.putHeader(unicast.getId(), hdr);
      msgs.add(msg);
    }

    Thread[] threads = new Thread[NUM];
    final CyclicBarrier barrier = new CyclicBarrier(NUM + 1);
    for (int i = 0; i < NUM; i++) {
      final int index = i;
      threads[i] =
          new Thread() {
            public void run() {
              try {
                barrier.await();
                unicast.up(new Event(Event.MSG, msgs.get(index)));
              } catch (Exception e) {
                e.printStackTrace();
              }
            }
          };
      threads[i].start();
    }

    barrier.await();
    for (Thread thread : threads) thread.join();

    List<Message> list = r2.getMessages();
    System.out.println("list = " + print(list));

    assert list.size() == 1
        : "list must have 1 element but has " + list.size() + ": " + print(list);
  }
コード例 #12
0
 /**
  * Send num unicasts on both channels and verify the other end received them
  *
  * @param num
  * @throws Exception
  */
 private void sendToEachOtherAndCheck(int num) throws Exception {
   for (int i = 1; i <= num; i++) {
     a.send(b_addr, "m" + i);
     b.send(a_addr, "m" + i);
   }
   List<Message> l1 = r1.getMessages();
   List<Message> l2 = r2.getMessages();
   for (int i = 0; i < 10; i++) {
     if (l1.size() == num && l2.size() == num) break;
     Util.sleep(500);
   }
   System.out.println("l1 = " + print(l1));
   System.out.println("l2 = " + print(l2));
   assert l1.size() == num;
   assert l2.size() == num;
 }
コード例 #13
0
ファイル: OOBTest.java プロジェクト: navssurtani/JGroups
  @Test(invocationCount = 5)
  @SuppressWarnings("unchecked")
  public void testRandomRegularAndOOBMulticasts() throws Exception {
    DISCARD discard = new DISCARD();
    discard.setLocalAddress(a.getAddress());
    discard.setDownDiscardRate(0.5);
    ProtocolStack stack = a.getProtocolStack();
    stack.insertProtocol(discard, ProtocolStack.BELOW, NAKACK2.class);
    MyReceiver r1 = new MyReceiver("C1"), r2 = new MyReceiver("C2");
    a.setReceiver(r1);
    b.setReceiver(r2);
    final int NUM_MSGS = 20;
    final int NUM_THREADS = 10;

    send(null, NUM_MSGS, NUM_THREADS, 0.5); // send on random channel (c1 or c2)

    Collection<Integer> one = r1.getMsgs(), two = r2.getMsgs();
    for (int i = 0; i < 10; i++) {
      if (one.size() == NUM_MSGS && two.size() == NUM_MSGS) break;
      System.out.println("one size " + one.size() + ", two size " + two.size());
      Util.sleep(1000);
      sendStableMessages(a, b);
    }
    System.out.println("one size " + one.size() + ", two size " + two.size());

    stack.removeProtocol("DISCARD");

    for (int i = 0; i < 5; i++) {
      if (one.size() == NUM_MSGS && two.size() == NUM_MSGS) break;
      sendStableMessages(a, b);
      Util.sleep(500);
    }
    System.out.println(
        "C1 received "
            + one.size()
            + " messages ("
            + NUM_MSGS
            + " expected)"
            + "\nC2 received "
            + two.size()
            + " messages ("
            + NUM_MSGS
            + " expected)");

    check(NUM_MSGS, one, two);
  }
コード例 #14
0
  private void sendAndCheckMessages(int num_msgs, JChannel... channels) throws Exception {
    ra.clear();
    rb.clear();
    rc.clear();
    // 1. send unicast messages
    Set<Address> mbrs = new HashSet<Address>(channels.length);
    for (JChannel ch : channels) mbrs.add(ch.getAddress());

    for (JChannel ch : channels) {
      Address addr = ch.getAddress();
      for (Address dest : mbrs) {
        for (int i = 1; i <= num_msgs; i++) {
          ch.send(dest, null, "unicast msg #" + i + " from " + addr);
        }
      }
    }
    int total_msgs = num_msgs * channels.length;
    MyReceiver[] receivers = new MyReceiver[channels.length];
    for (int i = 0; i < channels.length; i++) receivers[i] = (MyReceiver) channels[i].getReceiver();
    checkReceivedMessages(total_msgs, receivers);
  }
コード例 #15
0
 private static void checkReceivedMessages(int num_ucasts, MyReceiver... receivers) {
   for (int i = 0; i < 20; i++) {
     boolean all_received = true;
     for (MyReceiver receiver : receivers) {
       List<Message> ucasts = receiver.getUnicasts();
       int ucasts_received = ucasts.size();
       if (num_ucasts != ucasts_received) {
         all_received = false;
         break;
       }
     }
     if (all_received) break;
     Util.sleep(500);
   }
   for (MyReceiver receiver : receivers) {
     List<Message> ucasts = receiver.getUnicasts();
     int ucasts_received = ucasts.size();
     System.out.println("receiver " + receiver + ": ucasts=" + ucasts_received);
     assertEquals("ucasts for " + receiver + ": " + print(ucasts), num_ucasts, ucasts_received);
   }
 }
コード例 #16
0
  @Test(dataProvider = "provider")
  public void testSimpleMessageReception(String props) throws Exception {
    c1 = new JChannel(props);
    c2 = new JChannel(props);
    MyReceiver r1 = new MyReceiver("c1"), r2 = new MyReceiver("c2");
    c1.setReceiver(r1);
    c2.setReceiver(r2);
    c1.connect("testSimpleMessageReception");
    c2.connect("testSimpleMessageReception");

    int NUM = 100;
    Address c1_addr = c1.getAddress(), c2_addr = c2.getAddress();
    for (int i = 1; i <= NUM; i++) {
      c1.send(c1_addr, "bla");
      c1.send(c2_addr, "bla");
      c2.send(c2_addr, "bla");
      c2.send(c1_addr, "bla");
    }

    for (int i = 0; i < 10; i++) {
      if (r1.getNum() == NUM * 2 && r2.getNum() == NUM * 2) break;
      Util.sleep(500);
    }

    System.out.println(
        "c1 received "
            + r1.getNum()
            + " msgs, "
            + getNumberOfRetransmissions(c1)
            + " retransmissions");
    System.out.println(
        "c2 received "
            + r2.getNum()
            + " msgs, "
            + getNumberOfRetransmissions(c2)
            + " retransmissions");

    assert r1.getNum() == NUM * 2 : "expected " + NUM * 2 + ", but got " + r1.getNum();
    assert r2.getNum() == NUM * 2 : "expected " + NUM * 2 + ", but got " + r2.getNum();
  }
コード例 #17
0
ファイル: DuplicateTest.java プロジェクト: vasilev/JGroups
  private void check(
      MyReceiver receiver, int expected_size, boolean oob, Tuple<Address, Integer>... vals) {
    Map<Address, Collection<Long>> msgs = receiver.getMsgs();

    for (int i = 0; i < 10; i++) {
      if (msgs.size() >= expected_size) break;
      Util.sleep(1000);
    }
    assert msgs.size() == expected_size
        : "expected size=" + expected_size + ", msgs: " + msgs.keySet();

    for (Tuple<Address, Integer> tuple : vals) {
      Address addr = tuple.getVal1();
      Collection<Long> list = msgs.get(addr);
      assert list != null : "no list available for " + addr;

      int expected_values = tuple.getVal2();
      for (int i = 0; i < 20; i++) {
        if (list.size() >= expected_values) break;
        Util.sleep(1000);
        sendStableMessages(c1, c2, c3);
      }

      System.out.println("[" + receiver.getName() + "]: " + addr + ": " + list);
      assert list.size() == expected_values
          : addr
              + "'s list's size is not "
              + tuple.getVal2()
              + ", list: "
              + list
              + " (size="
              + list.size()
              + ")";
      if (!oob) // if OOB messages, ordering is not guaranteed
      check(addr, list);
      else checkPresence(list);
    }
  }
コード例 #18
0
ファイル: OOBTest.java プロジェクト: rocketraman/JGroups
  public void testRegularAndOOBUnicasts2() throws Exception {
    DISCARD discard = new DISCARD();
    ProtocolStack stack = c1.getProtocolStack();
    stack.insertProtocol(discard, ProtocolStack.BELOW, UNICAST.class, UNICAST2.class);

    Address dest = c2.getAddress();
    Message m1 = new Message(dest, null, 1);
    Message m2 = new Message(dest, null, 2);
    m2.setFlag(Message.OOB);
    Message m3 = new Message(dest, null, 3);
    m3.setFlag(Message.OOB);
    Message m4 = new Message(dest, null, 4);

    MyReceiver receiver = new MyReceiver("C2");
    c2.setReceiver(receiver);
    c1.send(m1);

    discard.setDropDownUnicasts(1);
    c1.send(m3);

    discard.setDropDownUnicasts(1);
    c1.send(m2);

    c1.send(m4);
    Util.sleep(1000); // sleep some time to receive all messages

    Collection<Integer> list = receiver.getMsgs();
    int count = 10;
    while (list.size() < 4 && --count > 0) {
      Util.sleep(500); // time for potential retransmission
      sendStableMessages(c1, c2);
    }
    log.info("list = " + list);
    assert list.size() == 4 : "list is " + list;
    assert list.contains(1) && list.contains(2) && list.contains(3) && list.contains(4);
  }
コード例 #19
0
ファイル: OOBTest.java プロジェクト: navssurtani/JGroups
 public void receive(Message msg) {
   super.receive(msg);
   System.out.println("-- received " + msg.getObject());
   Util.sleep(sleep_time);
 }