@Test
  public void testMultipleManualInstances() throws Exception {
    TaskScheduleUtil.waitForAllTasksToStop();
    getEventInspectorsUtil().waitForCalmPeriod();

    createSnapshotTask("Nexus1650Task1");
    createSnapshotTask("Nexus1650Task2");
    createSnapshotTask("Nexus1650Task3");

    List<ScheduledServiceListResource> tasks = TaskScheduleUtil.getTasks();

    assertThat(tasks, hasSize(3));

    long startTimestamp = System.currentTimeMillis();

    for (ScheduledServiceListResource resource : tasks) {
      TaskScheduleUtil.run(resource.getId());
    }

    waitForOneTaskSleeping();

    TaskScheduleUtil.waitForAllTasksToStop();

    assertAllTasksWereRunning(startTimestamp);
  }
  @Override
  public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) {

    listener.getLogger().println("Start to submit Nexus scheduled tasks.");

    // Verify configuration of Nexus is still valid.
    if (selectedNexus == null) {
      listener.getLogger().println("Nexus you choise is invalid.");
      listener.getLogger().println("Please check your Jenkins's configuration.");
      return false;
    }

    // Verify Nexus is running.
    NexusClient client =
        new NexusJerseyClient(
            selectedNexus.getUrl(), selectedNexus.getUser(), selectedNexus.getPassword());
    client.init();
    if (!client.ping()) {
      listener
          .getLogger()
          .println(
              "Fail to connect Nexus. URL: "
                  + selectedNexus.getUrl()
                  + ", User: "******"Please check your Nexus is working.");
      return false;
    }

    TaskUtil taskUtil = new TaskUtil(client);

    // List<TaskStatus> statusList = new ArrayList<TaskStatus>();

    // Build ToDo list
    List<ScheduledServiceListResource> todoList = new ArrayList<ScheduledServiceListResource>();

    for (String taskName : tasks.split(",\\s*")) {
      if (!taskName.matches("\\s*")) {
        List<ScheduledServiceListResource> queryResults = taskUtil.fastFetchTasks(taskName);
        if (queryResults != null) {
          todoList.addAll(queryResults);
        } else {
          listener
              .getLogger()
              .println("WARNING: There is no shceduled task whose name is " + taskName + ".");
        }
      }
    }

    // Execute tasks.
    TaskRunner runner = new TaskRunner(client);
    for (ScheduledServiceListResource task : todoList) {
      TaskStatus status = runner.exec(task.getId());
      listener
          .getLogger()
          .println(
              "Submitting... [id: "
                  + task.getId()
                  + ", name: "
                  + task.getName()
                  + ", type: "
                  + task.getTypeName()
                  + "]");
      if (status.equals(TaskStatus.NG) || status.equals(TaskStatus.NG_UNKNOWN)) {
        listener.getLogger().println(task.getId() + ": Return NG status. Please Check your Nexus.");
        return false;
      } else if (status.equals(TaskStatus.WARNING_STILL_RUNNING)) {
        listener
            .getLogger()
            .println("WARNING: This task is still running. Jenkins skipped queueing.");
      }
    }

    listener.getLogger().println("End to submit Nexus scheduled tasks successfully.");
    return true;
  }