  @Test
  public void testGetJobsInProgress() throws OrbZKFailure,
                                     NodeDoesNotExistException,
                                     ZooKeeperConnectionException,
                                     WatcherException,
                                     InterruptedException,
                                     KeeperException {

    OrbTrackerMemberDataServiceImpl server = new OrbTrackerMemberDataServiceImpl();
    int num_jobs = 10;
    CountDownLatch jobsLatch = new CountDownLatch(1);
    CountDownLatch updateLatch = new CountDownLatch(1);
    CountDownLatch removeLatch = new CountDownLatch(1);
    server.enterTestingMode(jobsLatch, removeLatch, updateLatch);
    for (int i = 0; i < num_jobs; i++) {
      ZookeeperUtils.tryToCreateNode(zk, jobsInProgressPath + "/job", CreateMode.EPHEMERAL_SEQUENTIAL);
    }
    String[] job = server.getJobsInProgress(); // initialize watcher
    jobsLatch.await();
    List<String> nodes = zk.getChildren(jobsInProgressPath, false);
    job = server.getJobsInProgress();
    assertEquals(nodes.size(), job.length);
    jobsLatch = new CountDownLatch(3);
    server.setJobsLatch(jobsLatch);
    for (int i = 0; i < 3; i++) {
      ZookeeperUtils.tryToCreateNode(zk, jobsInProgressPath + "/job", CreateMode.EPHEMERAL_SEQUENTIAL);
      Thread.sleep(5); // Need to make the number of watcher events deterministic
    }
    jobsLatch.await();
    nodes = zk.getChildren(jobsInProgressPath, false);
    job = server.getJobsInProgress();
    assertEquals(nodes.size(), job.length);
    jobsLatch = new CountDownLatch(5);
    server.setJobsLatch(jobsLatch);
    for (int i = 0; i < 5; i++) {
      ZookeeperUtils.deleteNodeIfEmpty(zk, jobsInProgressPath + "/" + nodes.get(i));
      Thread.sleep(5); // Need to make the number of watcher events deterministic
    }
    jobsLatch.await();
    nodes = zk.getChildren(jobsInProgressPath, false);
    job = server.getJobsInProgress();
    assertEquals(nodes.size(), job.length);
  }