Пример #1
0
  @Ignore
  @Test
  public void whenReceiveNotCalledFromOwnerThenThrowException4() throws Exception {
    assumeTrue(Debug.isAssertionsEnabled());
    final Channel<String> ch = newChannel();

    Thread thread =
        new Thread(
            new Runnable() {
              @Override
              public void run() {
                try {
                  ch.receive();
                } catch (InterruptedException ex) {
                  throw new AssertionError(ex);
                } catch (SuspendExecution e) {
                  throw new AssertionError(e);
                }
              }
            });
    thread.start();

    Thread.sleep(100);
    ch.send("a message");

    boolean thrown = false;
    try {
      ch.receive();
    } catch (Throwable e) {
      thrown = true;
    }
    assertTrue(thrown);

    thread.join();
  }
Пример #2
0
  @Ignore
  @Test
  public void whenReceiveNotCalledFromOwnerThenThrowException3() throws Exception {
    assumeTrue(Debug.isAssertionsEnabled());
    final Channel<String> ch = newChannel();

    Fiber fib =
        new Fiber(
                "fiber",
                fjPool,
                new SuspendableRunnable() {
                  @Override
                  public void run() throws SuspendExecution, InterruptedException {
                    Fiber.sleep(100);

                    ch.send("a message");

                    boolean thrown = false;
                    try {
                      ch.receive();
                    } catch (Throwable e) {
                      thrown = true;
                    }
                    assertTrue(thrown);
                  }
                })
            .start();

    String m = ch.receive();

    assertThat(m, equalTo("a message"));

    fib.join();
  }