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); }