Example #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();
  }
Example #2
0
  @Test
  public void sendMessageFromThreadToThread() throws Exception {
    final Channel<String> ch = newChannel();

    Thread thread =
        new Thread(
            new Runnable() {
              @Override
              public void run() {
                try {
                  Thread.sleep(100);

                  ch.send("a message");
                } catch (InterruptedException | SuspendExecution ex) {
                  throw new AssertionError(ex);
                }
              }
            });
    thread.start();

    String m = ch.receive();

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

    thread.join();
  }
Example #3
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();
  }
Example #4
0
  @Test
  public void sendMessageFromFiberToThread() throws Exception {
    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");
                  }
                })
            .start();

    String m = ch.receive();

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

    fib.join();
  }