Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Edvard Fonsell committed Feb 11, 2021
1 parent ef6af47 commit e7806e2
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@

import javax.inject.Inject;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import io.nflow.engine.workflow.definition.TestState;
import io.nflow.engine.workflow.definition.WorkflowDefinitionStatistics;
import io.nflow.engine.workflow.instance.WorkflowInstance;
import io.nflow.engine.workflow.statistics.Statistics;
import io.nflow.engine.workflow.statistics.Statistics.QueueStatistics;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class StatisticsDaoTest extends BaseDaoTest {

Expand Down Expand Up @@ -64,7 +66,7 @@ public void getWorkflowDefinitionStatisticsWorks() {

Map<String, Map<String, WorkflowDefinitionStatistics>> stats = statisticsDao.getWorkflowDefinitionStatistics(i1.type, null,
null, null, null);
Map<String, WorkflowDefinitionStatistics> stateStats = stats.get("CreateLoan");
Map<String, WorkflowDefinitionStatistics> stateStats = stats.get(TestState.BEGIN.name());
assertThat(stateStats.get(executing.name()), is(nullValue()));
assertThat(stateStats.get(inProgress.name()).queuedInstances, is(2L));
assertThat(stateStats.get(inProgress.name()).allInstances, is(2L));
Expand All @@ -75,7 +77,7 @@ public void getWorkflowDefinitionStatisticsWorks() {
instanceDao.updateNotRunningWorkflowInstance(i2);

stats = statisticsDao.getWorkflowDefinitionStatistics(i1.type, null, null, null, null);
stateStats = stats.get("CreateLoan");
stateStats = stats.get(TestState.BEGIN.name());
assertThat(stateStats.get(executing.name()), is(nullValue()));
assertThat(stateStats.get(inProgress.name()).queuedInstances, is(2L));
assertThat(stateStats.get(inProgress.name()).allInstances, is(2L));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import io.nflow.engine.internal.executor.WorkflowInstanceExecutor;
import io.nflow.engine.internal.storage.db.SQLVariants;
import io.nflow.engine.service.WorkflowInstanceInclude;
import io.nflow.engine.workflow.definition.TestState;
import io.nflow.engine.workflow.executor.StateVariableValueTooLongException;
import io.nflow.engine.workflow.instance.QueryWorkflowInstances;
import io.nflow.engine.workflow.instance.WorkflowInstance;
Expand Down Expand Up @@ -763,7 +764,7 @@ public void getWorkflowInstanceStateWorks() {

String state = dao.getWorkflowInstanceState(workflowInstanceId);

assertThat(state, is("CreateLoan"));
assertThat(state, is(TestState.BEGIN.name()));
}

@Test
Expand Down Expand Up @@ -813,7 +814,7 @@ public void wakeUpWorkflowExternallyWorksWithEmptyExpectedStates() {
assertThat(i2.parentWorkflowId, equalTo(parentWorkflowId));
assertThat(i2.parentActionId, equalTo(parentActionId));

dao.wakeUpWorkflowExternally(parentWorkflowId, new ArrayList<String>());
dao.wakeUpWorkflowExternally(parentWorkflowId, emptyList());
WorkflowInstance wakenWorkflow = dao.getWorkflowInstance(parentWorkflowId, emptySet(), null);
assertTrue(wakenWorkflow.nextActivation.isBefore(now.plusMinutes(1)));
}
Expand All @@ -838,7 +839,7 @@ public void wakeUpWorkflowExternallyWorksWithExpectedStates() {
assertThat(i2.parentWorkflowId, equalTo(parentWorkflowId));
assertThat(i2.parentActionId, equalTo(parentActionId));

dao.wakeUpWorkflowExternally(parentWorkflowId, asList("CreateLoan"));
dao.wakeUpWorkflowExternally(parentWorkflowId, asList(TestState.BEGIN.name()));
WorkflowInstance wakenWorkflow = dao.getWorkflowInstance(parentWorkflowId, emptySet(), null);
assertTrue(wakenWorkflow.nextActivation.isBefore(now.plusMinutes(1)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.mockito.junit.jupiter.MockitoExtension;

import io.nflow.engine.service.DummyTestWorkflow;
import io.nflow.engine.workflow.definition.TestState;
import io.nflow.engine.workflow.instance.WorkflowInstance;
import io.nflow.engine.workflow.instance.WorkflowInstance.WorkflowInstanceStatus;
import io.nflow.engine.workflow.instance.WorkflowInstanceAction;
Expand All @@ -24,7 +25,7 @@ protected WorkflowInstance.Builder constructWorkflowInstanceBuilder() {
return new WorkflowInstance.Builder() //
.setStatus(WorkflowInstanceStatus.inProgress) //
.setType(DummyTestWorkflow.DUMMY_TYPE) //
.setState(DummyTestWorkflow.CREATE_LOAN.name()) //
.setState(TestState.BEGIN.name()) //
.setStateText(null) //
.setExternalId(randomUUID().toString()) //
.setBusinessKey(randomUUID().toString()) //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@
import java.util.HashMap;
import java.util.Map;

import io.nflow.engine.workflow.curated.SimpleState;
import io.nflow.engine.workflow.definition.AbstractWorkflowDefinition;
import io.nflow.engine.workflow.definition.NextAction;
import io.nflow.engine.workflow.definition.StateExecution;
import io.nflow.engine.workflow.definition.WorkflowSettings;
import io.nflow.engine.workflow.definition.WorkflowState;
import io.nflow.engine.workflow.definition.WorkflowStateType;

public class DummyTestWorkflow extends AbstractWorkflowDefinition {

public static final String DUMMY_TYPE = "dummy";
private static final WorkflowState ALTERNATIVE_START = new SimpleState("alternativeStart", WorkflowStateType.start);
public static final WorkflowState CREATE_LOAN = new SimpleState("CreateLoan", WorkflowStateType.start);

public DummyTestWorkflow() {
this(new WorkflowSettings.Builder().build());
Expand All @@ -28,17 +23,12 @@ public DummyTestWorkflow() {
public DummyTestWorkflow(WorkflowSettings settings) {
super(DUMMY_TYPE, BEGIN, DONE, settings);
permit(BEGIN, DONE, DONE);
permit(ALTERNATIVE_START, DONE);
registerState(CREATE_LOAN);
}

public NextAction begin(@SuppressWarnings("unused") StateExecution execution) {
return stopInState(DONE, "Finished");
}

public void done(@SuppressWarnings("unused") StateExecution execution) {
}

public NextAction alternativeStart(@SuppressWarnings("unused") StateExecution execution) {
return stopInState(DONE, "Finished");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class WorkflowInstancePreProcessorTest extends BaseNflowTest {
@BeforeEach
public void setup() {
dummyWorkflow = new DummyTestWorkflow(new WorkflowSettings.Builder().setDefaultPriority(DEFAULT_PRIORITY).build());
lenient().doReturn(dummyWorkflow).when(workflowDefinitionService).getWorkflowDefinition("dummy");
lenient().doReturn(dummyWorkflow).when(workflowDefinitionService).getWorkflowDefinition(DummyTestWorkflow.DUMMY_TYPE);
preProcessor = new WorkflowInstancePreProcessor(workflowDefinitionService, workflowInstanceDao);
}

Expand All @@ -64,7 +64,7 @@ public void createsMissingExternalId() {
public void createsMissingState() {
WorkflowInstance i = constructWorkflowInstanceBuilder().build();
WorkflowInstance processed = preProcessor.process(i);
assertThat(processed.state, is("CreateLoan"));
assertThat(processed.state, is(TestState.BEGIN.name()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import static io.nflow.engine.workflow.definition.NextAction.moveToState;
import static io.nflow.engine.workflow.definition.NextAction.moveToStateAfter;
import static io.nflow.engine.workflow.definition.NextAction.stopInState;
import static io.nflow.performance.workflow.TestState.BEGIN;
import static io.nflow.performance.workflow.TestState.DONE;
import static io.nflow.performance.workflow.TestState.ERROR;
import static org.joda.time.DateTime.now;

import org.slf4j.Logger;
Expand All @@ -13,7 +17,6 @@
import io.nflow.engine.workflow.definition.StateExecution;
import io.nflow.engine.workflow.definition.WorkflowSettings;
import io.nflow.engine.workflow.definition.WorkflowState;
import io.nflow.engine.workflow.definition.WorkflowStateType;

/**
* Deterministic workflow that executes quickly.
Expand All @@ -22,23 +25,20 @@ public class ConstantWorkflow extends AbstractWorkflowDefinition {
private static final Logger logger = LoggerFactory.getLogger(ConstantWorkflow.class);
private static final String KEY = "retries";

public static final WorkflowState START = new SimpleState("start", WorkflowStateType.start);
public static final WorkflowState QUICK_STATE = new SimpleState("quickState", "This executes fast then goes to retryTwice");
public static final WorkflowState RETRY_TWICE_STATE = new SimpleState("retryTwiceState",
"Retries twice and goes then goes to scheduleState");
public static final WorkflowState SCHEDULE_STATE = new SimpleState("scheduleState", "Goes to slowState, in 3 sec");
public static final WorkflowState SLOW_STATE = new SimpleState("slowState", "This executes bit slower. Goes to end");
public static final WorkflowState END = new SimpleState("end", WorkflowStateType.end);
public static final WorkflowState ERROR = new SimpleState("error", WorkflowStateType.end, "Error. Should not be used.");

public ConstantWorkflow() {
super(ConstantWorkflow.class.getSimpleName(), START, ERROR,
super(ConstantWorkflow.class.getSimpleName(), BEGIN, ERROR,
new WorkflowSettings.Builder().setMaxErrorTransitionDelay(5000).build());
permit(START, QUICK_STATE);
permit(BEGIN, QUICK_STATE);
permit(QUICK_STATE, RETRY_TWICE_STATE);
permit(RETRY_TWICE_STATE, SCHEDULE_STATE);
permit(SCHEDULE_STATE, SLOW_STATE);
permit(SLOW_STATE, END);
permit(SLOW_STATE, DONE);
}

public NextAction start(StateExecution execution) {
Expand Down Expand Up @@ -79,7 +79,7 @@ public NextAction slowState(@SuppressWarnings("unused") StateExecution execution
} catch (@SuppressWarnings("unused") InterruptedException e) {
// ignore
}
return NextAction.stopInState(END, "Goto end");
return stopInState(DONE, "Goto end");
}

public void error(@SuppressWarnings("unused") StateExecution execution) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package io.nflow.performance.workflow;

import static io.nflow.engine.workflow.definition.NextAction.moveToState;
import static io.nflow.engine.workflow.definition.NextAction.stopInState;
import static io.nflow.performance.workflow.TestState.DONE;

import io.nflow.engine.workflow.curated.SimpleState;
import io.nflow.engine.workflow.definition.AbstractWorkflowDefinition;
import io.nflow.engine.workflow.definition.NextAction;
Expand All @@ -14,34 +18,33 @@ public class NoDelaysWorkflow extends AbstractWorkflowDefinition {
private static final WorkflowState STATE_3 = new SimpleState("state3");
private static final WorkflowState STATE_4 = new SimpleState("state4");
private static final WorkflowState STATE_5 = new SimpleState("state5");
private static final WorkflowState END = new SimpleState("end", WorkflowStateType.end);

public NoDelaysWorkflow() {
super(NoDelaysWorkflow.class.getSimpleName(), STATE_1, END);
super(NoDelaysWorkflow.class.getSimpleName(), STATE_1, DONE);
permit(STATE_1, STATE_2);
permit(STATE_2, STATE_3);
permit(STATE_3, STATE_4);
permit(STATE_4, STATE_5);
permit(STATE_5, END);
permit(STATE_5, DONE);
}

public NextAction state1(@SuppressWarnings("unused") StateExecution execution) {
return NextAction.moveToState(STATE_2, "");
return moveToState(STATE_2, "");
}

public NextAction state2(@SuppressWarnings("unused") StateExecution execution) {
return NextAction.moveToState(STATE_3, "");
return moveToState(STATE_3, "");
}

public NextAction state3(@SuppressWarnings("unused") StateExecution execution) {
return NextAction.moveToState(STATE_4, "");
return moveToState(STATE_4, "");
}

public NextAction state4(@SuppressWarnings("unused") StateExecution execution) {
return NextAction.moveToState(STATE_5, "");
return moveToState(STATE_5, "");
}

public NextAction state5(@SuppressWarnings("unused") StateExecution execution) {
return NextAction.stopInState(END, "");
return stopInState(DONE, "");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.nflow.performance.workflow;

import io.nflow.engine.workflow.curated.SimpleState;
import io.nflow.engine.workflow.definition.WorkflowState;
import io.nflow.engine.workflow.definition.WorkflowStateType;

public class TestState {
public static final WorkflowState BEGIN = new SimpleState("begin", WorkflowStateType.start);
public static final WorkflowState PROCESS = new SimpleState("process");
public static final WorkflowState POLL = new SimpleState("poll", WorkflowStateType.wait);
public static final WorkflowState DONE = new SimpleState("done", WorkflowStateType.end);
public static final WorkflowState ERROR = new SimpleState("error", WorkflowStateType.manual);
}
Original file line number Diff line number Diff line change
@@ -1,42 +1,32 @@
package io.nflow.rest.v1;

import static io.nflow.engine.workflow.definition.NextAction.moveToState;
import static io.nflow.rest.v1.TestState.BEGIN;
import static io.nflow.rest.v1.TestState.DONE;
import static io.nflow.rest.v1.TestState.ERROR;
import static org.joda.time.Period.days;

import java.util.HashMap;
import java.util.Map;

import io.nflow.engine.workflow.curated.SimpleState;
import io.nflow.engine.workflow.definition.AbstractWorkflowDefinition;
import io.nflow.engine.workflow.definition.NextAction;
import io.nflow.engine.workflow.definition.StateExecution;
import io.nflow.engine.workflow.definition.WorkflowSettings;
import io.nflow.engine.workflow.definition.WorkflowState;
import io.nflow.engine.workflow.definition.WorkflowStateType;

public class DummyTestWorkflow extends AbstractWorkflowDefinition {

public static final WorkflowState START = new SimpleState("start", WorkflowStateType.start);
public static final WorkflowState ERROR = new SimpleState("error", WorkflowStateType.manual);
public static final WorkflowState END = new SimpleState("end", WorkflowStateType.end);

public DummyTestWorkflow() {
super("dummy", START, ERROR, new WorkflowSettings.Builder().setMinErrorTransitionDelay(300).setMaxErrorTransitionDelay(1000)
super("dummy", BEGIN, ERROR, new WorkflowSettings.Builder().setMinErrorTransitionDelay(300).setMaxErrorTransitionDelay(1000)
.setShortTransitionDelay(200).setImmediateTransitionDelay(100).setMaxRetries(10).setHistoryDeletableAfter(days(3))
.build());
permit(START, END, ERROR);
permit(START, ERROR);
permit(ERROR, END);
}

public NextAction start(@SuppressWarnings("unused") StateExecution execution) {
return moveToState(END, "Go to end state");
}

public void error(@SuppressWarnings("unused") StateExecution execution) {
permit(BEGIN, DONE, ERROR);
permit(BEGIN, ERROR);
permit(ERROR, DONE);
}

public void end(@SuppressWarnings("unused") StateExecution execution) {
public NextAction begin(@SuppressWarnings("unused") StateExecution execution) {
return moveToState(DONE, "Go to end state");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.nflow.rest.v1;

import io.nflow.engine.workflow.curated.SimpleState;
import io.nflow.engine.workflow.definition.WorkflowState;
import io.nflow.engine.workflow.definition.WorkflowStateType;

public class TestState {
public static final WorkflowState BEGIN = new SimpleState("begin", WorkflowStateType.start);
public static final WorkflowState PROCESS = new SimpleState("process");
public static final WorkflowState POLL = new SimpleState("poll", WorkflowStateType.wait);
public static final WorkflowState DONE = new SimpleState("done", WorkflowStateType.end);
public static final WorkflowState ERROR = new SimpleState("error", WorkflowStateType.manual);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.nflow.rest.v1.converter;

import static com.nitorcreations.Matchers.reflectEquals;
import static io.nflow.rest.v1.DummyTestWorkflow.END;
import static io.nflow.rest.v1.DummyTestWorkflow.ERROR;
import static io.nflow.rest.v1.DummyTestWorkflow.START;
import static io.nflow.rest.v1.TestState.BEGIN;
import static io.nflow.rest.v1.TestState.DONE;
import static io.nflow.rest.v1.TestState.ERROR;
import static java.util.Arrays.asList;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.arrayContainingInAnyOrder;
Expand Down Expand Up @@ -43,9 +43,9 @@ public void convertWorks() {
assertThat(resp.description, is(def.getDescription()));
assertThat(resp.onError, is(def.getErrorState().name()));
assertThat(resp.states, arrayContainingInAnyOrder(
reflectEquals(getResponseState(END, Collections.<String> emptyList(), null)),
reflectEquals(getResponseState(ERROR, asList(END.name()), null)),
reflectEquals(getResponseState(START, asList(END.name(), ERROR.name()), ERROR.name()))));
reflectEquals(getResponseState(DONE, Collections.<String> emptyList(), null)),
reflectEquals(getResponseState(ERROR, asList(DONE.name()), null)),
reflectEquals(getResponseState(BEGIN, asList(DONE.name(), ERROR.name()), ERROR.name()))));
assertThat(resp.supportedSignals, arrayContainingInAnyOrder(
reflectEquals(getSignal(1, "one")),
reflectEquals(getSignal(2, "two"))));
Expand Down

0 comments on commit e7806e2

Please sign in to comment.