コード例 #1
0
ファイル: LongRefTest.java プロジェクト: codehaus/multiverse
  @Test
  public void awaitTest() {
    final LongRef ref = new LongRef();

    TestThread t =
        new TestThread() {
          @Override
          public void doRun() throws Exception {
            ref.await(2);
          }
        };

    t.start();
    sleepMs(500);

    assertAlive(t);

    ref.set(1);
    sleepMs(500);

    assertAlive(t);

    ref.set(2);
    joinAll(t);
  }
コード例 #2
0
  @Test
  public void whenTimeout() throws InterruptedException {
    barrier = new VetoCommitBarrier();

    TestThread thread =
        new TestThread() {
          @Override
          public void doRun() throws Exception {
            boolean result = barrier.tryAwaitOpen(1, TimeUnit.SECONDS);
            assertFalse(result);
          }
        };

    thread.setPrintStackTrace(false);
    thread.start();
    joinAll(thread);
  }
コード例 #3
0
  @Test
  public void whenAbortedWhileWaiting() throws InterruptedException {
    barrier = new VetoCommitBarrier();

    TestThread thread =
        new TestThread() {
          @Override
          public void doRun() throws Exception {
            boolean result = barrier.tryAwaitOpen(1, TimeUnit.DAYS);
            assertTrue(result);
          }
        };

    thread.setPrintStackTrace(false);
    thread.start();
    sleepMs(500);
    barrier.abort();

    joinAll(thread);
  }
コード例 #4
0
  @Test
  public void whenCommittedWhileWaiting() {
    barrier = new VetoCommitBarrier();

    TestThread thread =
        new TestThread() {
          @Override
          public void doRun() throws Exception {
            barrier.tryAwaitOpen(1, TimeUnit.DAYS);
          }
        };

    thread.setPrintStackTrace(false);
    thread.start();
    sleepMs(500);
    thread.interrupt();

    // thread.join();
    // thread.assertFailedWithException(InterruptedException.class);
  }