TriggerInstance { public Status getStatus() { if (this.depInstances.isEmpty()) { return Status.SUCCEEDED; } final Set<Status> statusSet = new HashSet<>(); for (final DependencyInstance depInst : this.depInstances) { statusSet.add(depInst.getStatus()); } if (isRunning(statusSet)) { return Status.RUNNING; } else if (isSucceed(statusSet)) { return Status.SUCCEEDED; } else if (isCancelled(statusSet)) { return Status.CANCELLED; } else { return Status.CANCELLING; } } TriggerInstance(final String id, final FlowTrigger flowTrigger, final String flowId,
      final int flowVersion, final String submitUser, final List<DependencyInstance>
      depInstances, final int flowExecId, final Project project); @Override String toString(); Project getProject(); String getProjectName(); List<String> getFailureEmails(); String getFlowId(); int getFlowVersion(); int getFlowExecId(); void setFlowExecId(final int flowExecId); final FlowTrigger getFlowTrigger(); void setFlowTrigger(final FlowTrigger flowTrigger); String getSubmitUser(); void addDependencyInstance(final DependencyInstance depInst); List<DependencyInstance> getDepInstances(); String getId(); Status getStatus(); long getStartTime(); long getEndTime();  }
@Test public void testTriggerInstanceRunningStatus() throws Exception { final List<DependencyInstance> dependencyInstanceList = new ArrayList<>(); TriggerInstance ti = null; dependencyInstanceList .add(createTestDependencyInstance(Status.RUNNING, CancellationCause.MANUAL)); dependencyInstanceList .add(createTestDependencyInstance(Status.SUCCEEDED, CancellationCause.NONE)); dependencyInstanceList .add(createTestDependencyInstance(Status.SUCCEEDED, CancellationCause.NONE)); ti = new TriggerInstance("1", null, "1", 1, "test", dependencyInstanceList, -1, null); assertThat(ti.getStatus()).isEqualTo(Status.RUNNING); dependencyInstanceList.clear(); dependencyInstanceList .add(createTestDependencyInstance(Status.RUNNING, CancellationCause.MANUAL)); ti = new TriggerInstance("1", null, "1", 1, "test", dependencyInstanceList, -1, null); assertThat(ti.getStatus()).isEqualTo(Status.RUNNING); dependencyInstanceList.clear(); }
@Test public void testTriggerInstanceSucceededStatus() throws Exception { final List<DependencyInstance> dependencyInstanceList = new ArrayList<>(); TriggerInstance ti = null; dependencyInstanceList .add(createTestDependencyInstance(Status.SUCCEEDED, CancellationCause.NONE)); dependencyInstanceList .add(createTestDependencyInstance(Status.SUCCEEDED, CancellationCause.NONE)); dependencyInstanceList .add(createTestDependencyInstance(Status.SUCCEEDED, CancellationCause.NONE)); ti = new TriggerInstance("1", null, "1", 1, "test", dependencyInstanceList, -1, null); assertThat(ti.getStatus()).isEqualTo(Status.SUCCEEDED); dependencyInstanceList.clear(); ti = new TriggerInstance("1", null, "1", 1, "test", dependencyInstanceList, -1, null); assertThat(ti.getStatus()).isEqualTo(Status.SUCCEEDED); dependencyInstanceList.clear(); }
@Test public void testTriggerInstanceCancellingStatus() throws Exception { final List<DependencyInstance> dependencyInstanceList = new ArrayList<>(); TriggerInstance ti = null; dependencyInstanceList .add(createTestDependencyInstance(Status.CANCELLING, CancellationCause.MANUAL)); dependencyInstanceList .add(createTestDependencyInstance(Status.CANCELLED, CancellationCause.MANUAL)); dependencyInstanceList .add(createTestDependencyInstance(Status.SUCCEEDED, CancellationCause.NONE)); dependencyInstanceList .add(createTestDependencyInstance(Status.SUCCEEDED, CancellationCause.NONE)); dependencyInstanceList .add(createTestDependencyInstance(Status.SUCCEEDED, CancellationCause.NONE)); ti = new TriggerInstance("1", null, "1", 1, "test", dependencyInstanceList, -1, null); assertThat(ti.getStatus()).isEqualTo(Status.CANCELLING); dependencyInstanceList.clear(); dependencyInstanceList .add(createTestDependencyInstance(Status.RUNNING, CancellationCause.MANUAL)); dependencyInstanceList .add(createTestDependencyInstance(Status.CANCELLED, CancellationCause.MANUAL)); dependencyInstanceList .add(createTestDependencyInstance(Status.SUCCEEDED, CancellationCause.NONE)); dependencyInstanceList .add(createTestDependencyInstance(Status.SUCCEEDED, CancellationCause.NONE)); dependencyInstanceList .add(createTestDependencyInstance(Status.SUCCEEDED, CancellationCause.NONE)); ti = new TriggerInstance("1", null, "1", 1, "test", dependencyInstanceList, -1, null); assertThat(ti.getStatus()).isEqualTo(Status.CANCELLING); dependencyInstanceList.clear(); dependencyInstanceList .add(createTestDependencyInstance(Status.CANCELLED, CancellationCause.MANUAL)); dependencyInstanceList .add(createTestDependencyInstance(Status.CANCELLING, CancellationCause.NONE)); dependencyInstanceList .add(createTestDependencyInstance(Status.RUNNING, CancellationCause.NONE)); ti = new TriggerInstance("1", null, "1", 1, "test", dependencyInstanceList, -1, null); assertThat(ti.getStatus()).isEqualTo(Status.CANCELLING); dependencyInstanceList.clear(); dependencyInstanceList .add(createTestDependencyInstance(Status.RUNNING, CancellationCause.MANUAL)); dependencyInstanceList .add(createTestDependencyInstance(Status.CANCELLING, CancellationCause.MANUAL)); dependencyInstanceList .add(createTestDependencyInstance(Status.SUCCEEDED, CancellationCause.NONE)); ti = new TriggerInstance("1", null, "1", 1, "test", dependencyInstanceList, -1, null); assertThat(ti.getStatus()).isEqualTo(Status.CANCELLING); dependencyInstanceList.clear(); dependencyInstanceList .add(createTestDependencyInstance(Status.CANCELLED, CancellationCause.MANUAL)); dependencyInstanceList .add(createTestDependencyInstance(Status.RUNNING, CancellationCause.NONE)); ti = new TriggerInstance("1", null, "1", 1, "test", dependencyInstanceList, -1, null); assertThat(ti.getStatus()).isEqualTo(Status.CANCELLING); dependencyInstanceList.clear(); }
@Test public void testTriggerInstanceCancelledStatus() throws Exception { final List<DependencyInstance> dependencyInstanceList = new ArrayList<>(); TriggerInstance ti = null; dependencyInstanceList .add(createTestDependencyInstance(Status.CANCELLED, CancellationCause.MANUAL)); dependencyInstanceList .add(createTestDependencyInstance(Status.CANCELLED, CancellationCause.MANUAL)); dependencyInstanceList .add(createTestDependencyInstance(Status.SUCCEEDED, CancellationCause.NONE)); dependencyInstanceList .add(createTestDependencyInstance(Status.SUCCEEDED, CancellationCause.NONE)); dependencyInstanceList .add(createTestDependencyInstance(Status.SUCCEEDED, CancellationCause.NONE)); ti = new TriggerInstance("1", null, "1", 1, "test", dependencyInstanceList, -1, null); assertThat(ti.getStatus()).isEqualTo(Status.CANCELLED); dependencyInstanceList.clear(); dependencyInstanceList .add(createTestDependencyInstance(Status.CANCELLED, CancellationCause.MANUAL)); dependencyInstanceList .add(createTestDependencyInstance(Status.CANCELLED, CancellationCause.MANUAL)); ti = new TriggerInstance("1", null, "1", 1, "test", dependencyInstanceList, -1, null); assertThat(ti.getStatus()).isEqualTo(Status.CANCELLED); dependencyInstanceList.clear(); }