예제 #1
0
  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);
  }
예제 #2
0
  /**
   * 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
  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);
  }
예제 #4
0
 protected void discard(boolean flag, JChannel... channels) throws Exception {
   for (JChannel ch : channels) {
     ProtocolStack stack = ch.getProtocolStack();
     DISCARD discard = (DISCARD) stack.findProtocol(DISCARD.class);
     if (discard == null)
       stack.insertProtocol(
           discard = new DISCARD(), ProtocolStack.ABOVE, stack.getTransport().getClass());
     discard.setDiscardAll(flag);
   }
 }
예제 #5
0
  private static void createPartitions(JChannel... channels) throws Exception {
    for (JChannel ch : channels) {
      DISCARD discard = new DISCARD();
      discard.setDiscardAll(true);
      ch.getProtocolStack().insertProtocol(discard, ProtocolStack.Position.ABOVE, TP.class);
    }

    for (JChannel ch : channels) {
      View view = View.create(ch.getAddress(), 10, ch.getAddress());
      GMS gms = (GMS) ch.getProtocolStack().findProtocol(GMS.class);
      gms.installView(view);
    }
  }
예제 #6
0
  @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);
  }
예제 #7
0
  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);
  }