Skip to content

Commit

Permalink
Merge pull request #334 from NitorCreations/mariadb-docker
Browse files Browse the repository at this point in the history
Mariadb docker
  • Loading branch information
Edvard Fonsell committed Jul 23, 2019
2 parents 775424c + 321b645 commit 775c197
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 81 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ env:
- DB=h2
- DB=postgresql
- DB=mysql
- DB=mariadb
- DB=sqlserver
- DB=db2
addons:
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- Remove deprecated `WorkflowInstanceInclude.STARTED` enum value
- Remove deprecated `AbstractWorkflowExecutorListener`, use `WorkflowExecutorListener` instead
- Remove deprecated `WorkflowInstance.setStarted`, use `WorkflowInstance.setStartedIfNotSet` instead
- Add experimental MariaDB support (tests are not run on MariaDB in Travis)
- Add MariaDB support

**Details**
- `nflow-engine`
Expand Down
13 changes: 12 additions & 1 deletion nflow-tests/src/test/java/io/nflow/tests/AbstractNflowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import static org.apache.cxf.jaxrs.client.WebClient.fromClient;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;

import java.time.Duration;
import java.util.List;

import javax.inject.Inject;
Expand Down Expand Up @@ -118,7 +120,16 @@ protected ListWorkflowInstanceResponse getWorkflowInstance(int id, String expect
return wf;
}


protected ListWorkflowInstanceResponse getWorkflowInstanceWithTimeout(int id, String expectedState, Duration timeout) throws InterruptedException {
return assertTimeoutPreemptively(timeout,
() -> {
ListWorkflowInstanceResponse resp;
do {
resp = getWorkflowInstance(id, expectedState);
} while (resp.nextActivation != null);
return resp;
});
}

protected void assertWorkflowInstance(int instanceId, WorkflowInstanceValidator... validators) {
ListWorkflowInstanceResponse instance = getWorkflowInstance(instanceId);
Expand Down
59 changes: 36 additions & 23 deletions nflow-tests/src/test/java/io/nflow/tests/ArchiveTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

import static java.lang.Thread.sleep;
import static java.util.concurrent.TimeUnit.SECONDS;
import static java.time.Duration.ofSeconds;
import static org.apache.cxf.jaxrs.client.WebClient.fromClient;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
import static org.joda.time.DateTime.now;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;

import java.time.Duration;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -36,6 +40,7 @@ public class ArchiveTest extends AbstractNflowTest {
private static final int STEP_1_WORKFLOWS = 4;
private static final int STEP_2_WORKFLOWS = 7;
private static final int STEP_3_WORKFLOWS = 4;
private static final Duration ARCHIVE_TIMEOUT = ofSeconds(15);

public static NflowServerConfig server = new NflowServerConfig.Builder().prop("nflow.dispatcher.sleep.ms", 25)
.springContextClass(ArchiveConfiguration.class).build();
Expand All @@ -47,69 +52,75 @@ public ArchiveTest() {
super(server);
}

@Test // (timeout = ARCHIVE_TIMEOUT)
@Test
@Order(1)
public void cleanupExistingArchivableStuff() {
archiveService.archiveWorkflows(DateTime.now(), 10);
assertTimeoutPreemptively(ARCHIVE_TIMEOUT, () ->
archiveService.archiveWorkflows(now(), 10));
}

@Test // (timeout = CREATE_TIMEOUT)
@Test
@Order(2)
public void createWorkflows() throws InterruptedException {
waitUntilWorkflowsFinished(createWorkflows(STEP_1_WORKFLOWS));
archiveLimit1 = DateTime.now();
archiveLimit1 = now();
// Make sure first batch of workflows is created before the second batch.
// (some databases have 1 second precision in timestamps (e.g. mysql 5.5))
sleep(SECONDS.toMillis(1));
}

@Test // (timeout = CREATE_TIMEOUT)
@Test
@Order(3)
public void createMoreWorkflows() throws InterruptedException {
waitUntilWorkflowsFinished(createWorkflows(STEP_2_WORKFLOWS));
archiveLimit2 = DateTime.now();
archiveLimit2 = now();
sleep(SECONDS.toMillis(1));
}

@Test // (timeout = ARCHIVE_TIMEOUT)
@Test
@Order(4)
public void archiveBeforeTime1ArchiveAllWorkflows() {
int archived = archiveService.archiveWorkflows(archiveLimit1, 3);
int archived = assertTimeoutPreemptively(ARCHIVE_TIMEOUT, () ->
archiveService.archiveWorkflows(archiveLimit1, 3));
// fibonacci(3) workflow creates 1 child workflow
assertEquals(STEP_1_WORKFLOWS * 2, archived);
}

@Test // (timeout = ARCHIVE_TIMEOUT)
@Test
@Order(5)
public void archiveAgainBeforeTime1DoesNotArchivesAnything() {
int archived = archiveService.archiveWorkflows(archiveLimit1, 3);
int archived = assertTimeoutPreemptively(ARCHIVE_TIMEOUT, () ->
archiveService.archiveWorkflows(archiveLimit1, 3));
assertEquals(0, archived);
}

@Test // (timeout = ARCHIVE_TIMEOUT)
@Test
@Order(6)
public void archiveBeforeTime2Archives() {
int archived = archiveService.archiveWorkflows(archiveLimit2, 5);
int archived = assertTimeoutPreemptively(ARCHIVE_TIMEOUT, () ->
archiveService.archiveWorkflows(archiveLimit2, 5));
assertEquals(STEP_2_WORKFLOWS * 2, archived);
}

@Test // (timeout = CREATE_TIMEOUT)
@Test
@Order(7)
public void createMoreWorkflows_again() {
waitUntilWorkflowsFinished(createWorkflows(STEP_3_WORKFLOWS));
}

@Test // (timeout = ARCHIVE_TIMEOUT)
@Test
@Order(8)
public void archiveAgainBeforeTime1DoesNotArchiveAnything() {
int archived = archiveService.archiveWorkflows(archiveLimit1, 3);
int archived = assertTimeoutPreemptively(ARCHIVE_TIMEOUT, () ->
archiveService.archiveWorkflows(archiveLimit1, 3));
assertEquals(0, archived);
}

@Test // (timeout = ARCHIVE_TIMEOUT)
@Test
@Order(9)
public void archiveAgainBeforeTime2DoesNotArchiveAnything() {
int archived = archiveService.archiveWorkflows(archiveLimit2, 3);
int archived = assertTimeoutPreemptively(ARCHIVE_TIMEOUT, () ->
archiveService.archiveWorkflows(archiveLimit2, 3));
assertEquals(0, archived);
}

Expand All @@ -132,13 +143,15 @@ private int createWorkflow() {
}

private void waitUntilWorkflowsFinished(List<Integer> workflowIds) {
for (int workflowId : workflowIds) {
try {
getWorkflowInstance(workflowId, "done");
} catch (@SuppressWarnings("unused") InterruptedException e) {
// ignore
assertTimeoutPreemptively(ofSeconds(15), () -> {
for (int workflowId : workflowIds) {
try {
getWorkflowInstance(workflowId, "done");
} catch (@SuppressWarnings("unused") InterruptedException e) {
// ignore
}
}
}
});
}

// TODO another way would be to modify JettyServerContainer to have reference to Spring's applicationContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static io.nflow.tests.demo.workflow.DemoWorkflow.DEMO_WORKFLOW_TYPE;
import static java.util.Comparator.naturalOrder;
import static java.util.stream.Collectors.toList;
import static java.time.Duration.ofSeconds;
import static org.apache.cxf.jaxrs.client.WebClient.fromClient;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -69,7 +70,7 @@ public void t01_startDemoBulkWorkflow() {
workflowId = resp.id;
}

@Test // (timeout = 30000)
@Test
@Order(2)
public void t02_waitForBulkToFinish() throws InterruptedException {
waitForBulkToFinish();
Expand Down Expand Up @@ -107,14 +108,14 @@ public void t12_startBulkWorkflow() {
}
}

@Test // (timeout = 30000)
@Test
@Order(5)
public void t13_waitForBulkToFinish() throws InterruptedException {
waitForBulkToFinish();
}

private void waitForBulkToFinish() throws InterruptedException {
ListWorkflowInstanceResponse instance = getWorkflowInstance(workflowId, done.name());
ListWorkflowInstanceResponse instance = getWorkflowInstanceWithTimeout(workflowId, done.name(), ofSeconds(30));
assertThat(instance.childWorkflows.size(), equalTo(1));
List<Integer> childWorkflowIds = instance.childWorkflows.values().iterator().next();
assertThat(childWorkflowIds.size(), equalTo(CHILDREN_COUNT));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.nflow.tests;

import static java.time.Duration.ofSeconds;
import static org.apache.cxf.jaxrs.client.WebClient.fromClient;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
Expand Down Expand Up @@ -41,10 +42,10 @@ public void startFibonacciWorkflow() {
workflowId = resp.id;
}

@Test // (timeout = 30000)
@Test
@Order(2)
public void checkFibonacciWorkflowComputesCorrectResult() throws InterruptedException {
ListWorkflowInstanceResponse response = getWorkflowInstance(workflowId, FibonacciWorkflow.State.done.name());
ListWorkflowInstanceResponse response = getWorkflowInstanceWithTimeout(workflowId, FibonacciWorkflow.State.done.name(), ofSeconds(30));
assertTrue(response.stateVariables.containsKey("result"));
assertEquals(8, response.stateVariables.get("result"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static io.nflow.engine.workflow.instance.WorkflowInstanceAction.WorkflowActionType.stateExecution;
import static java.util.Arrays.asList;
import static java.time.Duration.ofSeconds;
import static org.apache.cxf.jaxrs.client.WebClient.fromClient;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
Expand Down Expand Up @@ -53,13 +54,10 @@ public void createCreditApplicationWorkflow() {
assertThat(resp.id, notNullValue());
}

@Test // (timeout = 10000)
@Test
@Order(2)
public void checkAcceptCreditApplicationReached() throws InterruptedException {
ListWorkflowInstanceResponse response;
do {
response = getWorkflowInstance(resp.id, "acceptCreditApplication");
} while (response.nextActivation != null);
getWorkflowInstanceWithTimeout(resp.id, "acceptCreditApplication", ofSeconds(10));
}

@Test
Expand All @@ -71,13 +69,10 @@ public void moveToGrantLoanState() {
fromClient(workflowInstanceIdResource, true).path(resp.id).put(ureq);
}

@Test //(timeout = 5000)
@Test
@Order(4)
public void checkErrorStateReached() throws InterruptedException {
ListWorkflowInstanceResponse response;
do {
response = getWorkflowInstance(resp.id, "error");
} while (response.nextActivation != null);
getWorkflowInstanceWithTimeout(resp.id, "error", ofSeconds(5));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package io.nflow.tests;

import static java.time.Duration.ofSeconds;
import static org.apache.cxf.jaxrs.client.WebClient.fromClient;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;

import io.nflow.tests.extension.NflowServerConfig;
import io.nflow.tests.extension.NflowServerExtension;
Expand Down Expand Up @@ -49,10 +51,10 @@ public void createWorkflowInstance() {
assertThat(resp.id, is(notNullValue()));
}

@Test // (timeout = 5000)
@Test
@Order(2)
public void getProcessedInstance() throws Exception {
instance = getWorkflowInstance(resp.id, DeleteHistoryWorkflow.State.done.name());
instance = getWorkflowInstanceWithTimeout(resp.id, DeleteHistoryWorkflow.State.done.name(), ofSeconds(5));
}

@Test
Expand Down
37 changes: 22 additions & 15 deletions nflow-tests/src/test/java/io/nflow/tests/DemoWorkflowTest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package io.nflow.tests;

import static java.lang.Thread.sleep;
import static java.time.Duration.ofSeconds;
import static org.apache.cxf.jaxrs.client.WebClient.fromClient;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;

import io.nflow.tests.extension.NflowServerConfig;
import io.nflow.tests.extension.NflowServerExtension;
Expand Down Expand Up @@ -50,23 +52,28 @@ public void startDemoWorkflow() {
assertThat(resp.id, notNullValue());
}

@Test // (timeout = 5000)
@Test
@Order(2)
public void queryDemoWorkflowHistory() throws Exception {
ListWorkflowInstanceResponse wf = null;
do {
sleep(200);
ListWorkflowInstanceResponse[] instances = fromClient(workflowInstanceResource, true).query("type", "demo")
.query("include", "actions").get(ListWorkflowInstanceResponse[].class);
assertThat(instances.length, greaterThanOrEqualTo(1));
for (ListWorkflowInstanceResponse instance : instances) {
if (instance.id == resp.id && "done".equals(instance.state) && instance.nextActivation == null) {
wf = instance;
break;
}
}
} while (wf == null);
assertThat(wf.actions.size(), is(2));
ListWorkflowInstanceResponse wfr =
assertTimeoutPreemptively(ofSeconds(5),
() -> {
ListWorkflowInstanceResponse wf = null;
do {
sleep(200);
ListWorkflowInstanceResponse[] instances = fromClient(workflowInstanceResource, true).query("type", "demo")
.query("include", "actions").get(ListWorkflowInstanceResponse[].class);
assertThat(instances.length, greaterThanOrEqualTo(1));
for (ListWorkflowInstanceResponse instance : instances) {
if (instance.id == resp.id && "done".equals(instance.state) && instance.nextActivation == null) {
wf = instance;
break;
}
}
} while (wf == null);
return wf;
});
assertThat(wfr.actions.size(), is(2));
}

@Test
Expand Down
Loading

0 comments on commit 775c197

Please sign in to comment.