@Test public void testBasicProperties() throws Exception { FlowExecution execution = new FlowExecution("foo", new FlowExecutionStatus("BAR")); assertEquals("foo",execution.getName()); assertEquals("BAR",execution.getStatus().getName()); }
@Test public void testEnumOrdering() throws Exception { FlowExecution first = new FlowExecution("foo", FlowExecutionStatus.COMPLETED); FlowExecution second = new FlowExecution("foo", FlowExecutionStatus.FAILED); assertTrue("Should be negative",first.compareTo(second)<0); assertTrue("Should be positive",second.compareTo(first)>0); }
@Test public void testOneStep() throws Exception { flow.setStateTransitions(Collections.singletonList(StateTransition.createEndStateTransition(new StubState( "step1")))); flow.afterPropertiesSet(); FlowExecution execution = flow.start(executor); assertEquals(FlowExecutionStatus.COMPLETED, execution.getStatus()); assertEquals("step1", execution.getName()); }
/** * Aggregate all of the {@link FlowExecutionStatus}es of the * {@link FlowExecution}s into one status. The aggregate status will be the * status with the highest precedence. * * @see FlowExecutionAggregator#aggregate(Collection) */ @Override public FlowExecutionStatus aggregate(Collection<FlowExecution> executions) { if (executions == null || executions.size() == 0) { return FlowExecutionStatus.UNKNOWN; } return Collections.max(executions).getStatus(); }
executor.close(new FlowExecution(stateName, status)); throw e; executor.close(new FlowExecution(stateName, status)); throw new FlowExecutionException(String.format("Ended flow=%s at state=%s with exception", name, stateName), e); FlowExecution result = new FlowExecution(stateName, status); executor.close(result); return result;
@Override public FlowExecutionStatus handle(FlowExecutor executor) throws Exception { return flow.start(executor).getStatus(); }
@Test public void testOneStepWithListenerCallsClose() throws Exception { flow.setStateTransitions(Collections.singletonList(StateTransition.createEndStateTransition(new StubState( "step1")))); flow.afterPropertiesSet(); final List<FlowExecution> list = new ArrayList<>(); executor = new JobFlowExecutorSupport() { @Override public void close(FlowExecution result) { list.add(result); } }; FlowExecution execution = flow.start(executor); assertEquals(1, list.size()); assertEquals(FlowExecutionStatus.COMPLETED, execution.getStatus()); assertEquals("step1", execution.getName()); }
@Test public void testBasicHandling() throws Exception { Collection<Flow> flows = new ArrayList<>(); Flow flow1 = mock(Flow.class); Flow flow2 = mock(Flow.class); flows.add(flow1); flows.add(flow2); SplitState state = new SplitState(flows, "foo"); when(flow1.start(executor)).thenReturn(new FlowExecution("step1", FlowExecutionStatus.COMPLETED)); when(flow2.start(executor)).thenReturn(new FlowExecution("step1", FlowExecutionStatus.COMPLETED)); FlowExecutionStatus result = state.handle(executor); assertEquals(FlowExecutionStatus.COMPLETED, result); }
/** * Create an ordering on {@link FlowExecution} instances by comparing their * statuses. * * @see Comparable#compareTo(Object) * * @param other the {@link FlowExecution} instance to compare with this instance. * @return negative, zero or positive as per the contract */ @Override public int compareTo(FlowExecution other) { return this.status.compareTo(other.getStatus()); }
@Test public void testUnconnectedSteps() throws Exception { flow.setStateTransitions(collect(StateTransition.createEndStateTransition(new StubState("step1")), StateTransition.createEndStateTransition(new StubState("step2")))); flow.afterPropertiesSet(); FlowExecution execution = flow.start(executor); assertEquals(FlowExecutionStatus.COMPLETED, execution.getStatus()); assertEquals("step1", execution.getName()); }
@Test public void testFailed() throws Exception { FlowExecution first = new FlowExecution("foo", FlowExecutionStatus.COMPLETED); FlowExecution second = new FlowExecution("foo", FlowExecutionStatus.FAILED); assertTrue("Should be negative", first.compareTo(second)<0); assertTrue("Should be positive", second.compareTo(first)>0); assertEquals(FlowExecutionStatus.FAILED, aggregator.aggregate(Arrays.asList(first, second))); }
@Test public void testConcurrentHandling() throws Exception { Flow flow1 = mock(Flow.class); Flow flow2 = mock(Flow.class); SplitState state = new SplitState(Arrays.asList(flow1, flow2), "foo"); state.setTaskExecutor(new SimpleAsyncTaskExecutor()); when(flow1.start(executor)).thenReturn(new FlowExecution("step1", FlowExecutionStatus.COMPLETED)); when(flow2.start(executor)).thenReturn(new FlowExecution("step1", FlowExecutionStatus.COMPLETED)); FlowExecutionStatus result = state.handle(executor); assertEquals(FlowExecutionStatus.COMPLETED, result); }
/** * @see AbstractJob#doExecute(JobExecution) */ @Override protected void doExecute(final JobExecution execution) throws JobExecutionException { try { JobFlowExecutor executor = new JobFlowExecutor(getJobRepository(), new SimpleStepHandler(getJobRepository()), execution); executor.updateJobExecutionStatus(flow.start(executor).getStatus()); } catch (FlowExecutionException e) { if (e.getCause() instanceof JobExecutionException) { throw (JobExecutionException) e.getCause(); } throw new JobExecutionException("Flow execution ended unexpectedly", e); } }
@Test public void testResume() throws Exception { flow.setStateTransitions(collect(StateTransition.createStateTransition(new StubState("step1"), "step2"), StateTransition.createEndStateTransition(new StubState("step2")))); flow.afterPropertiesSet(); FlowExecution execution = flow.resume("step2", executor); assertEquals(FlowExecutionStatus.COMPLETED, execution.getStatus()); assertEquals("step2", execution.getName()); }
@Test public void testEnumStartsWithOrdering() throws Exception { FlowExecution first = new FlowExecution("foo", new FlowExecutionStatus("COMPLETED.BAR")); FlowExecution second = new FlowExecution("foo", new FlowExecutionStatus("FAILED.FOO")); assertTrue("Should be negative",first.compareTo(second)<0); assertTrue("Should be positive",second.compareTo(first)>0); }
executor.close(new FlowExecution(stateName, status)); throw e; executor.close(new FlowExecution(stateName, status)); throw new FlowExecutionException(String.format("Ended flow=%s at state=%s with exception", name, stateName), e); FlowExecution result = new FlowExecution(stateName, status); executor.close(result); return result;
/** * Delegate to the flow provided for the execution of the step. * * @see AbstractStep#doExecute(StepExecution) */ @Override protected void doExecute(StepExecution stepExecution) throws Exception { try { stepExecution.getExecutionContext().put(STEP_TYPE_KEY, this.getClass().getName()); StepHandler stepHandler = new SimpleStepHandler(getJobRepository(), stepExecution.getExecutionContext()); FlowExecutor executor = new JobFlowExecutor(getJobRepository(), stepHandler, stepExecution.getJobExecution()); executor.updateJobExecutionStatus(flow.start(executor).getStatus()); stepExecution.upgradeStatus(executor.getJobExecution().getStatus()); stepExecution.setExitStatus(executor.getJobExecution().getExitStatus()); } catch (FlowExecutionException e) { if (e.getCause() instanceof JobExecutionException) { throw (JobExecutionException) e.getCause(); } throw new JobExecutionException("Flow execution ended unexpectedly", e); } }
@Test public void testTwoSteps() throws Exception { flow.setStateTransitions(collect(StateTransition.createStateTransition(new StubState("step1"), "step2"), StateTransition.createEndStateTransition(new StubState("step2")))); flow.afterPropertiesSet(); FlowExecution execution = flow.start(executor); assertEquals(FlowExecutionStatus.COMPLETED, execution.getStatus()); assertEquals("step2", execution.getName()); }
@Test public void testEnumAndAlpha() throws Exception { FlowExecution first = new FlowExecution("foo", new FlowExecutionStatus("ZZZZZ")); FlowExecution second = new FlowExecution("foo", new FlowExecutionStatus("FAILED.FOO")); assertTrue("Should be negative",first.compareTo(second)<0); assertTrue("Should be positive",second.compareTo(first)>0); }
executor.close(new FlowExecution(stateName, status)); throw e; executor.close(new FlowExecution(stateName, status)); throw new FlowExecutionException(String.format("Ended flow=%s at state=%s with exception", name, stateName), e); FlowExecution result = new FlowExecution(stateName, status); executor.close(result); return result;