/**
   * Executes batch but finalizer is failed.
   *
   * @throws Exception if failed
   */
  @Test
  public void executeBatch_failed_finalize() throws Exception {
    ProfileBuilder prf = new ProfileBuilder(folder.getRoot());
    prf.setTracker(FinalizerFailed.class);
    ExecutionTask task = prf.task();
    try {
      task.executeBatch("batch");
      fail();
    } catch (IOException e) {
      // ok.
    }

    List<Record> results = SerialExecutionTracker.get(prf.trackingId);
    verifyPhaseOrder(results);

    assertThat(phase(results, "testing", ExecutionPhase.SETUP).size(), is(2));
    assertThat(phase(results, "testing", ExecutionPhase.INITIALIZE).size(), is(1));
    assertThat(phase(results, "testing", ExecutionPhase.IMPORT).size(), is(2));
    assertThat(phase(results, "testing", ExecutionPhase.PROLOGUE).size(), is(1));
    assertThat(phase(results, "testing", ExecutionPhase.MAIN).size(), is(4));
    assertThat(phase(results, "testing", ExecutionPhase.EPILOGUE).size(), is(1));
    assertThat(phase(results, "testing", ExecutionPhase.EXPORT).size(), is(2));
    assertThat(phase(results, "testing", ExecutionPhase.FINALIZE).size(), is(1));
    assertThat(phase(results, "testing", ExecutionPhase.CLEANUP).size(), is(0));

    assertThat(flow(results, "left").size(), is(0));
    assertThat(flow(results, "right").size(), is(0));
    assertThat(flow(results, "last").size(), is(0));
  }
  /**
   * Executes batch but some flows are skipped.
   *
   * @throws Exception if failed
   */
  @Test
  public void executeBatch_seriaize() throws Exception {
    ProfileBuilder prf = new ProfileBuilder(folder.getRoot());
    prf.setTracker(FlowSerialized.class);
    ExecutionTask task = prf.task();
    task.setSerializeFlows(true);
    task.executeBatch("batch");

    List<Record> results = SerialExecutionTracker.get(prf.trackingId);
    checkFlowHappensBefore(results, "testing", "left");
    checkFlowHappensBefore(results, "testing", "right");
    checkFlowHappensBefore(results, "left", "last");
    checkFlowHappensBefore(results, "right", "last");
    verifyPhaseOrder(results);
  }
  /**
   * Executes flow but cleanup is failed.
   *
   * @throws Exception if failed
   */
  @Test
  public void executeFlow_failed_cleanup() throws Exception {
    ProfileBuilder prf = new ProfileBuilder(folder.getRoot());
    prf.setTracker(CleanerFailed.class);
    ExecutionTask task = prf.task();
    task.executeFlow("batch", "testing", "flow");

    List<Record> results = SerialExecutionTracker.get(prf.trackingId);
    verifyPhaseOrder(results);

    assertThat(phase(results, "testing", ExecutionPhase.SETUP).size(), is(2));
    assertThat(phase(results, "testing", ExecutionPhase.INITIALIZE).size(), is(1));
    assertThat(phase(results, "testing", ExecutionPhase.IMPORT).size(), is(2));
    assertThat(phase(results, "testing", ExecutionPhase.PROLOGUE).size(), is(1));
    assertThat(phase(results, "testing", ExecutionPhase.MAIN).size(), is(4));
    assertThat(phase(results, "testing", ExecutionPhase.EPILOGUE).size(), is(1));
    assertThat(phase(results, "testing", ExecutionPhase.EXPORT).size(), is(2));
    assertThat(phase(results, "testing", ExecutionPhase.FINALIZE).size(), is(2));
    assertThat(phase(results, "testing", ExecutionPhase.CLEANUP).size(), is(1));
  }