Exemple #1
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);
  }
Exemple #2
0
 public DISCARD localAddress(Address addr) {
   setLocalAddress(addr);
   return this;
 }