Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
efonsell committed Feb 17, 2021
1 parent f20c4a9 commit 439f0c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.nflow.tests.demo.workflow;

import static io.nflow.engine.workflow.curated.CronWorkflow.State.schedule;
import static io.nflow.engine.workflow.definition.NextAction.moveToState;
import static io.nflow.engine.workflow.curated.CronWorkflow.State.waitForWorkToFinish;
import static io.nflow.engine.workflow.definition.NextAction.moveToStateAfter;
import static io.nflow.tests.demo.workflow.DemoWorkflow.DEMO_WORKFLOW_TYPE;
import static org.joda.time.DateTime.now;
import static org.joda.time.Period.hours;

import org.joda.time.DateTime;
Expand All @@ -11,6 +13,7 @@
import io.nflow.engine.workflow.definition.NextAction;
import io.nflow.engine.workflow.definition.StateExecution;
import io.nflow.engine.workflow.definition.WorkflowSettings.Builder;
import io.nflow.engine.workflow.instance.WorkflowInstance;

@Component
public class TestCronWorkflow extends CronWorkflow {
Expand All @@ -20,8 +23,10 @@ protected TestCronWorkflow() {
super(TYPE, new Builder().setHistoryDeletableAfter(hours(1)).setDeleteHistoryCondition(() -> true).build());
}

public NextAction doWork(@SuppressWarnings("unused") StateExecution execution) {
return moveToState(schedule, "ok");
public NextAction doWork(StateExecution execution) {
WorkflowInstance childWorkflow = new WorkflowInstance.Builder().setType(DEMO_WORKFLOW_TYPE).build();
execution.addChildWorkflows(childWorkflow);
return moveToStateAfter(waitForWorkToFinish, now().plusMinutes(1), "Work delegated to child workflow");
}

@Override
Expand All @@ -33,4 +38,9 @@ protected DateTime getNextActivationTime(StateExecution execution, String cron)
protected boolean handleFailureImpl(StateExecution execution) {
return super.handleFailureImpl(execution);
}

@Override
protected DateTime waitForWorkToFinishImpl(StateExecution execution) {
return super.waitForWorkToFinishImpl(execution);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ public void letItRunFor5Seconds() throws InterruptedException {
public void verifyItHasRunPeriodically() {
List<Action> actions = getWorkflowInstance(resp.id).actions;
long scheduleActions = actions.stream().filter(a -> CronWorkflow.State.schedule.name().equals(a.state)).count();
long waitActions = actions.stream().filter(a -> CronWorkflow.State.waitForWorkToFinish.name().equals(a.state)).count();
long doWorkActions = actions.stream().filter(a -> CronWorkflow.State.doWork.name().equals(a.state)).count();
assertThat(scheduleActions, is(greaterThanOrEqualTo(1L)));
assertThat(waitActions, is(greaterThanOrEqualTo(1L)));
assertThat(doWorkActions, is(greaterThanOrEqualTo(1L)));
}

Expand Down

0 comments on commit 439f0c7

Please sign in to comment.