Ejemplo n.º 1
0
 public void testSizeCalc() throws Exception {
   SimpleBinarySemaphore sem = new SimpleBinarySemaphore();
   mgr.setSem(sem);
   RepositoryNode node1 = new RepositoryNodeImpl("url1", "testDir", null);
   RepositoryNode node2 = new RepositoryNodeImpl("url2", "testDir", null);
   RepositoryNode node3 = new RepositoryNodeImpl("url3", "testDir", null);
   mgr.queueSizeCalc(node1);
   assertTrue(sem.take(TIMEOUT_SHOULDNT));
   assertEquals(ListUtil.list(node1), mgr.getNodes());
   mgr.queueSizeCalc(node2);
   mgr.queueSizeCalc(node3);
   assertTrue(sem.take(TIMEOUT_SHOULDNT));
   if (mgr.getNodes().size() < 3) {
     assertTrue(sem.take(TIMEOUT_SHOULDNT));
   }
   assertSameElements(ListUtil.list(node1, node2, node3), mgr.getNodes());
 }
Ejemplo n.º 2
0
  public void testNotifyThread() {
    final List rec = new ArrayList();
    final SimpleBinarySemaphore sem = new SimpleBinarySemaphore();
    tr.setImmediateNotify(false);

    TaskCallback cb =
        new TaskCallback() {
          public void taskEvent(SchedulableTask task, Schedule.EventType event) {
            rec.add(new BERec(Deadline.in(0), (BackgroundTask) task, event));
            sem.give();
          }
        };
    BackgroundTask t1 = btask(100, 200, .1, cb);
    BackgroundTask t2 = btask(100, 300, .2, cb);

    tr.notify(t1, Schedule.EventType.START);
    tr.notify(t1, Schedule.EventType.FINISH);
    // 2nd finish event should not cause another callback
    tr.notify(t1, Schedule.EventType.FINISH);
    tr.notify(t2, Schedule.EventType.START);

    Interrupter intr = null;
    try {
      intr = interruptMeIn(TIMEOUT_SHOULDNT, true);
      while (rec.size() < 3) {
        sem.take();
      }
      assertEquals(
          ListUtil.list(
              new BERec(0, t1, Schedule.EventType.START),
              new BERec(0, t1, Schedule.EventType.FINISH),
              new BERec(0, t2, Schedule.EventType.START)),
          rec);
      intr.cancel();
    } finally {
      if (intr.did()) {
        fail("Notifier didn't run callbacks");
      }
    }
  }