예제 #1
0
  @Test
  public void testAbort() {
    TestPipe consumer = new TestPipe();
    TestDaemon daemon = new TestDaemon(LOG, consumer, Integer.MAX_VALUE, 10);
    DaemonThread thread = new DaemonThread(daemon, ID);

    // Must keep ID and name
    assertEquals(ID, thread.getPID());
    assertEquals(daemon.getDaemonName(), thread.getDaemonName());

    // Must not have started yet
    assertEquals(0, daemon.getTicksDone());
    assertEquals(WAITING, thread.getDaemonState());
    assertTrue(thread.isRunning());

    // Start and abort soon after
    thread.start();
    sleepFor(10);
    thread.cancel();
    thread.waitForJoin();

    // Must record aborted state
    assertEquals(ABORTED, thread.getDaemonState());
    assertFalse(thread.isRunning());
  }
예제 #2
0
  @Test
  public void testExit() {
    TestPipe consumer = new TestPipe();
    TestDaemon daemon = new TestDaemon(LOG, consumer, TICKS, 1);
    DaemonThread thread = new DaemonThread(daemon, ID);

    // Must keep ID and name
    assertEquals(ID, thread.getPID());
    assertEquals(daemon.getDaemonName(), thread.getDaemonName());

    // Must not have started yet
    assertEquals(0, daemon.getTicksDone());
    assertEquals(WAITING, thread.getDaemonState());
    assertTrue(thread.isRunning());

    // Start and wait for completion
    thread.start();
    thread.waitForJoin();

    // Must have completed all loops
    assertEquals(TICKS, daemon.getTicksDone());
    assertEquals(TICKS, consumer.count());
    assertEquals(COMPLETED, thread.getDaemonState());
    assertFalse(thread.isRunning());
  }