Esempio n. 1
0
 @Override
 protected void starting(Description desc) {
   if (Debug.isDebug()) {
     System.out.println("STARTING TEST " + desc.getMethodName());
     Debug.record(0, "STARTING TEST " + desc.getMethodName());
   }
 }
Esempio n. 2
0
 @Override
 public void failed(Throwable e, Description desc) {
   System.out.println("FAILED TEST " + desc.getMethodName() + ": " + e.getMessage());
   e.printStackTrace(System.err);
   if (Debug.isDebug() && !(e instanceof OutOfMemoryError)) {
     Debug.record(
         0,
         "EXCEPTION IN THREAD "
             + Thread.currentThread().getName()
             + ": "
             + e
             + " - "
             + Arrays.toString(e.getStackTrace()));
     Debug.dumpRecorder("~/quasar.dump");
   }
 }
Esempio n. 3
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();
  }
Esempio n. 4
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();
  }
Esempio n. 5
0
  @Test
  public void testBlockingChannelSendingFiber() throws Exception {
    assumeThat(policy, is(OverflowPolicy.BLOCK));
    final Channel<Integer> ch = newChannel();

    Fiber<Integer> receiver =
        new Fiber<Integer>(
                fjPool,
                new SuspendableCallable<Integer>() {
                  @Override
                  public Integer run() throws SuspendExecution, InterruptedException {
                    int i = 0;
                    while (ch.receive() != null) {
                      i++;
                      Fiber.sleep(50);
                    }
                    return i;
                  }
                })
            .start();

    Fiber<Void> sender =
        new Fiber<Void>(
                fjPool,
                new SuspendableRunnable() {
                  @Override
                  public void run() throws SuspendExecution, InterruptedException {
                    for (int i = 0; i < 10; i++) ch.send(i);
                    ch.close();
                  }
                })
            .start();

    try {
      assertThat(receiver.get(), is(10));
      sender.join();
    } catch (Throwable t) {
      Debug.dumpRecorder("channels.log");
      throw t;
    }
  }
Esempio n. 6
0
 @Override
 protected void succeeded(Description desc) {
   Debug.record(0, "DONE TEST " + desc.getMethodName());
 }