//
  // runs a single task tracker
  // checks that generated events conform to expectedEvents
  // and the mock jobtracker checks that the heartbeats() sent to it are right
  //
  private void runTaskTracker() {
    long runUntil = eventQueue.getLastCheckTime();
    LOG.debug("Running task tracker until simulation time=" + runUntil);

    List<SimulatorEvent> events = taskTracker.init(simulationStartTime);
    eventQueue.addAll(events);
    while (true) {
      // can't be empty as it must go past runUntil for verifiability
      // besides it is never empty because of HeartbeatEvent
      SimulatorEvent currentEvent = eventQueue.get();
      // copy time, make sure TT does not modify it
      long now = currentEvent.getTimeStamp();
      LOG.debug("Number of events to deliver=" + (eventQueue.getSize() + 1) + ", now=" + now);
      if (now > runUntil) {
        break;
      }
      LOG.debug("Calling accept(), event=" + currentEvent + ", now=" + now);
      events = taskTracker.accept(currentEvent);
      LOG.debug("Accept() returned " + events.size() + " new event(s)");
      for (SimulatorEvent newEvent : events) {
        LOG.debug("New event " + newEvent);
      }
      eventQueue.addAll(events);
      LOG.debug("Done checking and enqueuing new events");
    }

    // make sure we have seen all expected events, even for the last
    // time checked
    eventQueue.checkMissingExpected();
    // Mock JT should have consumed all entries from its heartbeat table
    jobTracker.checkMissingHeartbeats();
  }
 private void setUpReduceTask(
     TaskAttemptID reduceTaskId,
     long reduceStart,
     long mapDoneDelay,
     long reduceRuntime,
     long reduceKill) {
   jobTracker.runReduceTask(
       taskTrackerName, reduceTaskId, reduceStart, mapDoneDelay, reduceRuntime, reduceKill);
   long mapDone = jobTracker.nextHeartbeat(reduceStart + mapDoneDelay);
   if (reduceKill < 0 || mapDone < reduceKill) {
     // it generates completion events iff it survives mapDone
     eventQueue.expectReduceTask(
         taskTracker, reduceTaskId,
         mapDone, reduceRuntime);
   }
 }
 private void setUpMapTask(TaskAttemptID mapTaskId, long mapStart, long mapRuntime, long mapKill) {
   jobTracker.runMapTask(taskTrackerName, mapTaskId, mapStart, mapRuntime, mapKill);
   eventQueue.expectMapTask(taskTracker, mapTaskId, mapStart, mapRuntime);
 }
 // numAccepts must be at least 1
 private void setUpHeartbeats(int numAccepts) {
   eventQueue.expectHeartbeats(taskTracker, numAccepts, heartbeatInterval);
   jobTracker.expectEmptyHeartbeats(taskTrackerName, numAccepts);
 }