@JsonIgnore
  public void updateForRestart(
      long iterationId,
      WorkflowInstance.Status newStatus,
      WorkflowInstance.Status oldStatus,
      WorkflowRollupOverview oldOverview) {
    Checks.checkTrue(
        isForeachIterationRestartable(iterationId) && stats != null && stats.get(oldStatus) > 0,
        "Invalid: pending action tries to restart a non-restartable iteration: " + iterationId);
    long cnt = stats.get(oldStatus);
    if (cnt > 1) {
      stats.put(oldStatus, stats.get(oldStatus) - 1);
    } else {
      stats.remove(oldStatus);
    }
    addRunningOne(newStatus, null);
    rollup.segregate(oldOverview);
    details.resetIterationDetail(iterationId, newStatus, oldStatus);
    if (restartInfo == null) {
      restartInfo = new HashSet<>();
    }
    restartInfo.add(iterationId);
  }
@Test
  public void testUpdateForRestart() throws Exception {
    ForeachStepOverview overview =
        loadObject(
            "fixtures/instances/sample-foreach-step-overview.json", ForeachStepOverview.class);

    AssertHelper.assertThrows(
        "should throw exception for invalid restart",
        IllegalArgumentException.class,
        "Invalid: pending action tries to restart a non-restartable iteration",
        () ->
            overview.updateForRestart(
                123L, WorkflowInstance.Status.CREATED, WorkflowInstance.Status.FAILED, null));

    overview.addOne(123L, WorkflowInstance.Status.FAILED, null);
    overview.refreshDetail();
    assertEquals(1L, overview.getStats().get(WorkflowInstance.Status.FAILED).longValue());
    assertFalse(overview.getStats().containsKey(WorkflowInstance.Status.CREATED));
    assertEquals(
        Collections.singletonList(new ForeachDetails.Interval(123L, 123L)),
        overview.getDetails().getInfo().get(WorkflowInstance.Status.FAILED));
    assertFalse(overview.getDetails().getInfo().containsKey(WorkflowInstance.Status.CREATED));

    WorkflowRollupOverview rollup = new WorkflowRollupOverview();
    rollup.setTotalLeafCount(1);
    overview.updateForRestart(
        123L, WorkflowInstance.Status.CREATED, WorkflowInstance.Status.FAILED, rollup);

    assertFalse(overview.isForeachIterationRestartable(123L));
    assertFalse(overview.getStats().containsKey(WorkflowInstance.Status.FAILED));
    assertEquals(127L, overview.getRunningStats().get(WorkflowInstance.Status.CREATED).longValue());
    assertEquals(
        Collections.singletonList(new ForeachDetails.Interval(123L, 123L)),
        overview.getDetails().getPendingInfo().get(WorkflowInstance.Status.CREATED));
    assertFalse(overview.getDetails().getInfo().containsKey(WorkflowInstance.Status.FAILED));
    assertEquals(Collections.singleton(123L), overview.getRestartInfo());
    assertEquals(160305, overview.getRollup().getTotalLeafCount());
  }