From 214c42b26761eaa8d6249be43d5c099f7240949c Mon Sep 17 00:00:00 2001 From: Mikko Tiihonen Date: Fri, 19 Jul 2019 14:47:58 +0300 Subject: [PATCH 1/4] Bump db2 timeout --- travis/setup-db-db2.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/travis/setup-db-db2.sh b/travis/setup-db-db2.sh index 7b7f46f21..a3b2a30ae 100755 --- a/travis/setup-db-db2.sh +++ b/travis/setup-db-db2.sh @@ -7,7 +7,7 @@ docker run --rm --name db2 --entrypoint /bin/sh ibmcom/db2:$VER -c "cat /opt/ibm docker run --rm --name db2 --cap-add IPC_LOCK --cap-add IPC_OWNER -e 'instance_name=root' -e 'DB2INST1_PASSWORD=nflow' -e 'LICENSE=accept' -e 'DBNAME=nflow' --publish 50000:50000 --detach ibmcom/db2:$VER db2start echo "waiting for DB2 to start" -fgrep -m1 'Setup has completed' <(timeout 120 docker logs -f db2) +fgrep -m1 'Setup has completed' <(timeout 240 docker logs -f db2) echo "DB2 started" #docker exec -it db2 su - db2inst1 -c '/opt/ibm/db2/V*/bin/db2 -tvs "CREATE DATABASE nflow USING CODESET UTF-8 TERRITORY us;"' From ab1d49dde9bb61c0ded6145127a20c78b710f30a Mon Sep 17 00:00:00 2001 From: Mikko Tiihonen Date: Fri, 19 Jul 2019 15:24:51 +0300 Subject: [PATCH 2/4] add back timeouts to tests --- .../io/nflow/tests/AbstractNflowTest.java | 13 ++++- .../test/java/io/nflow/tests/ArchiveTest.java | 53 +++++++++++-------- .../java/io/nflow/tests/BulkWorkflowTest.java | 7 +-- .../io/nflow/tests/ChildWorkflowTest.java | 5 +- .../tests/CreditApplicationWorkflowTest.java | 15 ++---- .../io/nflow/tests/DeleteHistoryTest.java | 6 ++- .../java/io/nflow/tests/DemoWorkflowTest.java | 37 +++++++------ .../PreviewCreditApplicationWorkflowTest.java | 15 ++---- .../io/nflow/tests/StateVariablesTest.java | 15 +++--- 9 files changed, 95 insertions(+), 71 deletions(-) diff --git a/nflow-tests/src/test/java/io/nflow/tests/AbstractNflowTest.java b/nflow-tests/src/test/java/io/nflow/tests/AbstractNflowTest.java index 442dc15ac..f353c99c2 100644 --- a/nflow-tests/src/test/java/io/nflow/tests/AbstractNflowTest.java +++ b/nflow-tests/src/test/java/io/nflow/tests/AbstractNflowTest.java @@ -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; @@ -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); diff --git a/nflow-tests/src/test/java/io/nflow/tests/ArchiveTest.java b/nflow-tests/src/test/java/io/nflow/tests/ArchiveTest.java index 7d77551f1..dbdc2845c 100644 --- a/nflow-tests/src/test/java/io/nflow/tests/ArchiveTest.java +++ b/nflow-tests/src/test/java/io/nflow/tests/ArchiveTest.java @@ -2,10 +2,12 @@ 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.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively; import java.util.ArrayList; import java.util.List; @@ -36,6 +38,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 int ARCHIVE_TIMEOUT = 15; public static NflowServerConfig server = new NflowServerConfig.Builder().prop("nflow.dispatcher.sleep.ms", 25) .springContextClass(ArchiveConfiguration.class).build(); @@ -47,13 +50,14 @@ public ArchiveTest() { super(server); } - @Test // (timeout = ARCHIVE_TIMEOUT) + @Test @Order(1) public void cleanupExistingArchivableStuff() { - archiveService.archiveWorkflows(DateTime.now(), 10); + assertTimeoutPreemptively(ofSeconds(ARCHIVE_TIMEOUT), () -> + archiveService.archiveWorkflows(DateTime.now(), 10)); } - @Test // (timeout = CREATE_TIMEOUT) + @Test @Order(2) public void createWorkflows() throws InterruptedException { waitUntilWorkflowsFinished(createWorkflows(STEP_1_WORKFLOWS)); @@ -63,7 +67,7 @@ public void createWorkflows() throws InterruptedException { sleep(SECONDS.toMillis(1)); } - @Test // (timeout = CREATE_TIMEOUT) + @Test @Order(3) public void createMoreWorkflows() throws InterruptedException { waitUntilWorkflowsFinished(createWorkflows(STEP_2_WORKFLOWS)); @@ -71,45 +75,50 @@ public void createMoreWorkflows() throws InterruptedException { sleep(SECONDS.toMillis(1)); } - @Test // (timeout = ARCHIVE_TIMEOUT) + @Test @Order(4) public void archiveBeforeTime1ArchiveAllWorkflows() { - int archived = archiveService.archiveWorkflows(archiveLimit1, 3); + int archived = assertTimeoutPreemptively(ofSeconds(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(ofSeconds(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(ofSeconds(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(ofSeconds(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(ofSeconds(ARCHIVE_TIMEOUT), () -> + archiveService.archiveWorkflows(archiveLimit2, 3)); assertEquals(0, archived); } @@ -132,13 +141,15 @@ private int createWorkflow() { } private void waitUntilWorkflowsFinished(List 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 diff --git a/nflow-tests/src/test/java/io/nflow/tests/BulkWorkflowTest.java b/nflow-tests/src/test/java/io/nflow/tests/BulkWorkflowTest.java index 2d426d309..0741ff3d2 100644 --- a/nflow-tests/src/test/java/io/nflow/tests/BulkWorkflowTest.java +++ b/nflow-tests/src/test/java/io/nflow/tests/BulkWorkflowTest.java @@ -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; @@ -69,7 +70,7 @@ public void t01_startDemoBulkWorkflow() { workflowId = resp.id; } - @Test // (timeout = 30000) + @Test @Order(2) public void t02_waitForBulkToFinish() throws InterruptedException { waitForBulkToFinish(); @@ -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 childWorkflowIds = instance.childWorkflows.values().iterator().next(); assertThat(childWorkflowIds.size(), equalTo(CHILDREN_COUNT)); diff --git a/nflow-tests/src/test/java/io/nflow/tests/ChildWorkflowTest.java b/nflow-tests/src/test/java/io/nflow/tests/ChildWorkflowTest.java index cf7a69d16..76df620fd 100644 --- a/nflow-tests/src/test/java/io/nflow/tests/ChildWorkflowTest.java +++ b/nflow-tests/src/test/java/io/nflow/tests/ChildWorkflowTest.java @@ -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; @@ -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")); } diff --git a/nflow-tests/src/test/java/io/nflow/tests/CreditApplicationWorkflowTest.java b/nflow-tests/src/test/java/io/nflow/tests/CreditApplicationWorkflowTest.java index 70aab4f48..2ec25f821 100644 --- a/nflow-tests/src/test/java/io/nflow/tests/CreditApplicationWorkflowTest.java +++ b/nflow-tests/src/test/java/io/nflow/tests/CreditApplicationWorkflowTest.java @@ -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; @@ -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 @@ -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 diff --git a/nflow-tests/src/test/java/io/nflow/tests/DeleteHistoryTest.java b/nflow-tests/src/test/java/io/nflow/tests/DeleteHistoryTest.java index c62a2b7d8..eb84541d1 100644 --- a/nflow-tests/src/test/java/io/nflow/tests/DeleteHistoryTest.java +++ b/nflow-tests/src/test/java/io/nflow/tests/DeleteHistoryTest.java @@ -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; @@ -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 diff --git a/nflow-tests/src/test/java/io/nflow/tests/DemoWorkflowTest.java b/nflow-tests/src/test/java/io/nflow/tests/DemoWorkflowTest.java index 8aebf37de..2ff7dede2 100644 --- a/nflow-tests/src/test/java/io/nflow/tests/DemoWorkflowTest.java +++ b/nflow-tests/src/test/java/io/nflow/tests/DemoWorkflowTest.java @@ -1,6 +1,7 @@ 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; @@ -8,6 +9,7 @@ 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; @@ -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 diff --git a/nflow-tests/src/test/java/io/nflow/tests/PreviewCreditApplicationWorkflowTest.java b/nflow-tests/src/test/java/io/nflow/tests/PreviewCreditApplicationWorkflowTest.java index bc4771bab..53a6cc813 100644 --- a/nflow-tests/src/test/java/io/nflow/tests/PreviewCreditApplicationWorkflowTest.java +++ b/nflow-tests/src/test/java/io/nflow/tests/PreviewCreditApplicationWorkflowTest.java @@ -1,6 +1,7 @@ package io.nflow.tests; import static io.nflow.engine.workflow.instance.WorkflowInstanceAction.WorkflowActionType.stateExecution; +import static java.time.Duration.ofSeconds; import static java.util.Arrays.asList; import static org.apache.cxf.jaxrs.client.WebClient.fromClient; import static org.hamcrest.MatcherAssert.assertThat; @@ -61,13 +62,10 @@ public void createCreditApplicationWorkflow() { assertThat(resp.id, notNullValue()); } - @Test // (timeout = 5000) + @Test @Order(2) public void checkAcceptCreditApplicationReached() throws InterruptedException { - ListWorkflowInstanceResponse response; - do { - response = getWorkflowInstance(resp.id, "acceptCreditApplication"); - } while (response.nextActivation != null); + ListWorkflowInstanceResponse response = getWorkflowInstanceWithTimeout(resp.id, "acceptCreditApplication", ofSeconds(5)); wfModifiedAtAcceptCreditApplication = response.modified; assertTrue(response.stateVariables.containsKey("info")); } @@ -83,13 +81,10 @@ public void moveToGrantLoanState() { } } - @Test // (timeout = 5000) + @Test @Order(4) public void checkDoneStateReached() throws InterruptedException { - ListWorkflowInstanceResponse response; - do { - response = getWorkflowInstance(resp.id, "done"); - } while (response.nextActivation != null); + ListWorkflowInstanceResponse response = getWorkflowInstanceWithTimeout(resp.id, "done", ofSeconds(5)); assertTrue(response.modified.isAfter(wfModifiedAtAcceptCreditApplication), "nflow_workflow.modified should be updated"); } diff --git a/nflow-tests/src/test/java/io/nflow/tests/StateVariablesTest.java b/nflow-tests/src/test/java/io/nflow/tests/StateVariablesTest.java index 7a06aa94b..a58ac262e 100644 --- a/nflow-tests/src/test/java/io/nflow/tests/StateVariablesTest.java +++ b/nflow-tests/src/test/java/io/nflow/tests/StateVariablesTest.java @@ -1,11 +1,13 @@ package io.nflow.tests; +import static java.time.Duration.ofSeconds; import static java.util.Collections.singletonMap; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively; import java.io.IOException; import java.util.List; @@ -51,24 +53,23 @@ public StateWorkflow stateWorkflow() { } } - @Test // (timeout = 5000) + @Test @Order(1) public void createStateWorkflow() throws JsonProcessingException, IOException { createRequest = new CreateWorkflowInstanceRequest(); createRequest.type = "stateWorkflow"; createRequest.externalId = UUID.randomUUID().toString(); createRequest.stateVariables.put("requestData", new ObjectMapper().readTree("{\"test\":5}")); - createResponse = createWorkflowInstance(createRequest); + createResponse = assertTimeoutPreemptively(ofSeconds(5), + () -> createWorkflowInstance(createRequest)); assertThat(createResponse.id, notNullValue()); } - @Test // (timeout = 5000) + @Test @Order(2) public void checkStateVariables() throws InterruptedException { - ListWorkflowInstanceResponse listResponse; - do { - listResponse = getWorkflowInstance(createResponse.id, "done"); - } while (listResponse.nextActivation != null); + ListWorkflowInstanceResponse listResponse = getWorkflowInstanceWithTimeout(createResponse.id, "done", ofSeconds(5)); + assertEquals(3, listResponse.stateVariables.size()); assertEquals(singletonMap("test", 5), listResponse.stateVariables.get("requestData")); assertEquals(singletonMap("value", "foo1"), listResponse.stateVariables.get("variable1")); From aae29dd757ff0c1cc773e367a00aba861a30a76e Mon Sep 17 00:00:00 2001 From: Mikko Tiihonen Date: Fri, 19 Jul 2019 15:36:43 +0300 Subject: [PATCH 3/4] Enable mariadb testing via docker --- .travis.yml | 1 + CHANGELOG.md | 2 +- travis/setup-db-mariadb.sh | 13 +++++++------ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7be36033d..49dd3cea7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ env: - DB=h2 - DB=postgresql - DB=mysql + - DB=mariadb - DB=sqlserver - DB=db2 addons: diff --git a/CHANGELOG.md b/CHANGELOG.md index 630d23cbc..a1ada29e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` diff --git a/travis/setup-db-mariadb.sh b/travis/setup-db-mariadb.sh index 13737cdbb..41654808d 100755 --- a/travis/setup-db-mariadb.sh +++ b/travis/setup-db-mariadb.sh @@ -1,8 +1,9 @@ #!/bin/bash -ev -mysql -v -e "create database nflow character set utf8mb4;" -u root -mysql -v -e "create user 'nflow'@'%' identified by 'nflow';" -u root -mysql -v -e "create user 'nflow'@'localhost' identified by 'nflow';" -u root -mysql -v -e "grant all on nflow.* TO 'nflow'@'%';" -u root -mysql -v -e "grant all on nflow.* TO 'nflow'@'localhost';" -u root -mysql -v -e "flush privileges;" -u root +if [[ -n "$TRAVIS" ]]; then + sudo service mysql stop || true +fi + +docker run --rm --name mariadb -e MYSQL_RANDOM_ROOT_PASSWORD=yes -e MYSQL_DATABASE=nflow -e MYSQL_USER=nflow -e MYSQL_PASSWORD=nflow --publish 3306:3306 --detach mariadb:10.4 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci + +fgrep -m1 'ready for connections' <(timeout 120 docker logs -f mariadb 2>&1) From 321b6454455fe4f552f12044ecd9ddd20532c68b Mon Sep 17 00:00:00 2001 From: Mikko Tiihonen Date: Mon, 22 Jul 2019 14:42:20 +0300 Subject: [PATCH 4/4] Fix review comments --- .../test/java/io/nflow/tests/ArchiveTest.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/nflow-tests/src/test/java/io/nflow/tests/ArchiveTest.java b/nflow-tests/src/test/java/io/nflow/tests/ArchiveTest.java index dbdc2845c..e9213a4b3 100644 --- a/nflow-tests/src/test/java/io/nflow/tests/ArchiveTest.java +++ b/nflow-tests/src/test/java/io/nflow/tests/ArchiveTest.java @@ -6,9 +6,11 @@ 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; @@ -38,7 +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 int ARCHIVE_TIMEOUT = 15; + 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(); @@ -53,15 +55,15 @@ public ArchiveTest() { @Test @Order(1) public void cleanupExistingArchivableStuff() { - assertTimeoutPreemptively(ofSeconds(ARCHIVE_TIMEOUT), () -> - archiveService.archiveWorkflows(DateTime.now(), 10)); + assertTimeoutPreemptively(ARCHIVE_TIMEOUT, () -> + archiveService.archiveWorkflows(now(), 10)); } @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)); @@ -71,14 +73,14 @@ public void createWorkflows() throws InterruptedException { @Order(3) public void createMoreWorkflows() throws InterruptedException { waitUntilWorkflowsFinished(createWorkflows(STEP_2_WORKFLOWS)); - archiveLimit2 = DateTime.now(); + archiveLimit2 = now(); sleep(SECONDS.toMillis(1)); } @Test @Order(4) public void archiveBeforeTime1ArchiveAllWorkflows() { - int archived = assertTimeoutPreemptively(ofSeconds(ARCHIVE_TIMEOUT), () -> + int archived = assertTimeoutPreemptively(ARCHIVE_TIMEOUT, () -> archiveService.archiveWorkflows(archiveLimit1, 3)); // fibonacci(3) workflow creates 1 child workflow assertEquals(STEP_1_WORKFLOWS * 2, archived); @@ -87,7 +89,7 @@ public void archiveBeforeTime1ArchiveAllWorkflows() { @Test @Order(5) public void archiveAgainBeforeTime1DoesNotArchivesAnything() { - int archived = assertTimeoutPreemptively(ofSeconds(ARCHIVE_TIMEOUT), () -> + int archived = assertTimeoutPreemptively(ARCHIVE_TIMEOUT, () -> archiveService.archiveWorkflows(archiveLimit1, 3)); assertEquals(0, archived); } @@ -95,7 +97,7 @@ public void archiveAgainBeforeTime1DoesNotArchivesAnything() { @Test @Order(6) public void archiveBeforeTime2Archives() { - int archived = assertTimeoutPreemptively(ofSeconds(ARCHIVE_TIMEOUT), () -> + int archived = assertTimeoutPreemptively(ARCHIVE_TIMEOUT, () -> archiveService.archiveWorkflows(archiveLimit2, 5)); assertEquals(STEP_2_WORKFLOWS * 2, archived); } @@ -109,7 +111,7 @@ public void createMoreWorkflows_again() { @Test @Order(8) public void archiveAgainBeforeTime1DoesNotArchiveAnything() { - int archived = assertTimeoutPreemptively(ofSeconds(ARCHIVE_TIMEOUT), () -> + int archived = assertTimeoutPreemptively(ARCHIVE_TIMEOUT, () -> archiveService.archiveWorkflows(archiveLimit1, 3)); assertEquals(0, archived); } @@ -117,7 +119,7 @@ public void archiveAgainBeforeTime1DoesNotArchiveAnything() { @Test @Order(9) public void archiveAgainBeforeTime2DoesNotArchiveAnything() { - int archived = assertTimeoutPreemptively(ofSeconds(ARCHIVE_TIMEOUT), () -> + int archived = assertTimeoutPreemptively(ARCHIVE_TIMEOUT, () -> archiveService.archiveWorkflows(archiveLimit2, 3)); assertEquals(0, archived); }