Пример #1
0
  private void send(Address dest) throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    final BlockingReceiver receiver = new BlockingReceiver(latch);
    final int NUM = 10;
    b.setReceiver(receiver);

    a.send(dest, 1); // the only regular message
    for (int i = 2; i <= NUM; i++) a.send(new Message(dest, i).setFlag(Message.Flag.OOB));

    sendStableMessages(a, b);
    List<Integer> list = receiver.getMsgs();
    for (int i = 0; i < 20; i++) {
      if (list.size() == NUM - 1) break;
      sendStableMessages(a, b);
      Util.sleep(500); // give the asynchronous msgs some time to be received
    }

    System.out.println("list = " + list);
    assert list.size() == NUM - 1 : "list is " + list;
    assert list.contains(2) && list.contains(10);

    System.out.println("[" + Thread.currentThread().getName() + "]: releasing latch");
    latch.countDown();

    for (int i = 0; i < 20; i++) {
      if (list.size() == NUM) break;
      sendStableMessages(a, b);
      Util.sleep(1000); // give the asynchronous msgs some time to be received
    }

    System.out.println("list = " + list);
    assert list.size() == NUM : "list is " + list;
    for (int i = 1; i <= NUM; i++) assert list.contains(i);
  }
Пример #2
0
  private void send(Address dest) throws ChannelNotConnectedException, ChannelClosedException {
    final ReentrantLock lock = new ReentrantLock();
    final BlockingReceiver receiver = new BlockingReceiver(lock);
    final int NUM = 10;
    c2.setReceiver(receiver);

    System.out.println("[" + Thread.currentThread().getName() + "]: locking lock");
    lock.lock();
    c1.send(new Message(dest, null, 1));
    for (int i = 2; i <= NUM; i++) {
      Message msg = new Message(dest, null, i);
      msg.setFlag(Message.OOB);
      c1.send(msg);
    }
    sendStableMessages(c1, c2);
    Util.sleep(500);

    List<Integer> list = receiver.getMsgs();
    for (int i = 0; i < 20; i++) {
      if (list.size() == NUM - 1) break;
      System.out.println("list = " + list);
      Util.sleep(1000); // give the asynchronous msgs some time to be received
    }

    System.out.println("list = " + list);

    assert list.size() == NUM - 1 : "list is " + list;
    assert list.contains(2) && list.contains(10);

    System.out.println("[" + Thread.currentThread().getName() + "]: unlocking lock");
    lock.unlock();

    for (int i = 0; i < 20; i++) {
      if (list.size() == NUM) break;
      System.out.println("list = " + list);
      Util.sleep(1000); // give the asynchronous msgs some time to be received
    }

    System.out.println("list = " + list);
    assert list.size() == NUM : "list is " + list;
    for (int i = 1; i <= NUM; i++) assert list.contains(i);
  }