Skip to content

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gmokki committed Jul 22, 2019
1 parent aae29dd commit 321b645
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions nflow-tests/src/test/java/io/nflow/tests/ArchiveTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand All @@ -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));
Expand All @@ -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);
Expand All @@ -87,15 +89,15 @@ 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);
}

@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);
}
Expand All @@ -109,15 +111,15 @@ 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);
}

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

0 comments on commit 321b645

Please sign in to comment.