public TimelineEventList doData(
     StaplerRequest req, @QueryParameter long min, @QueryParameter long max) throws IOException {
   TimelineEventList result = new TimelineEventList();
   for (Run r : builds.byTimestamp(min, max)) {
     Event e = new Event();
     e.start = r.getTime();
     e.end = new Date(r.timestamp + r.getDuration());
     e.title = r.getFullDisplayName();
     // what to put in the description?
     // e.description = "Longish description of event "+r.getFullDisplayName();
     // e.durationEvent = true;
     e.link = req.getContextPath() + '/' + r.getUrl();
     BallColor c = r.getIconColor();
     e.color = String.format("#%06X", c.getBaseColor().darker().getRGB() & 0xFFFFFF);
     e.classname = "event-" + c.noAnime().toString() + " " + (c.isAnimated() ? "animated" : "");
     result.add(e);
   }
   return result;
 }
  public void testMultipleExecutors() throws Exception {

    // Job1 runs for 1 second, no dependencies
    FreeStyleProject theJob1 = createFreeStyleProject("MultipleExecutor_Job1");
    theJob1.getBuildersList().add(new Shell("sleep 1; exit 0"));
    assertTrue(theJob1.getBuilds().isEmpty());

    // Job2 returns immediatly but can't run while Job1 is running.
    FreeStyleProject theJob2 = createFreeStyleProject("MultipleExecutor_Job2");
    {
      BuildBlockerProperty theProperty = new BuildBlockerProperty();
      theProperty.setBlockingJobs("MultipleExecutor_Job1");
      theJob2.addProperty(theProperty);
    }
    assertTrue(theJob1.getBuilds().isEmpty());

    // allow executing two simultanious jobs
    int theOldNumExecutors = Hudson.getInstance().getNumExecutors();
    Hudson.getInstance().setNumExecutors(2);

    Future<FreeStyleBuild> theFuture1 = theJob1.scheduleBuild2(0);
    Future<FreeStyleBuild> theFuture2 = theJob2.scheduleBuild2(0);
    while (!theFuture1.isDone() || !theFuture2.isDone()) {
      // let the jobs process
    }

    // check if job2 was not started before job1 was finished
    Run theRun1 = theJob1.getLastBuild();
    Run theRun2 = theJob2.getLastBuild();
    assertTrue(theRun1.getTimeInMillis() + theRun1.getDuration() <= theRun2.getTimeInMillis());

    // restore changed settings
    Hudson.getInstance().setNumExecutors(theOldNumExecutors);
    theJob2.delete();
    theJob1.delete();
  }