示例#1
0
  @Test
  public void testPrimitiveChannelClose() throws Exception {
    assumeThat(mailboxSize, not(equalTo(0)));

    final IntChannel ch = Channels.newIntChannel(mailboxSize, policy);

    Fiber fib =
        new Fiber(
                "fiber",
                fjPool,
                new SuspendableRunnable() {
                  @Override
                  public void run() throws SuspendExecution, InterruptedException {
                    for (int i = 1; i <= 5; i++) {
                      int m = ch.receiveInt();

                      assertThat(m, is(i));
                    }

                    try {
                      int m = ch.receiveInt();
                      fail("m = " + m);
                    } catch (QueueChannel.EOFException e) {
                    }

                    assertTrue(ch.isClosed());
                  }
                })
            .start();

    Thread.sleep(50);
    ch.send(1);
    ch.send(2);
    ch.send(3);
    ch.send(4);
    ch.send(5);

    ch.close();

    ch.send(6);
    ch.send(7);

    fib.join();
  }
示例#2
0
 private <Message> Channel<Message> newChannel() {
   return Channels.newChannel(mailboxSize, policy, singleProducer, singleConsumer);
 }