Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Edvard Fonsell committed Jan 30, 2015
1 parent 3d11c97 commit b46e83a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class WorkflowStateProcessor implements Runnable {
private final ObjectStringMapper objectMapper;
private final WorkflowInstanceDao workflowInstanceDao;
private final WorkflowExecutorListener[] executorListeners;
private DateTime lastLogged = now();
DateTime lastLogged = now();

WorkflowStateProcessor(int instanceId, ObjectStringMapper objectMapper, WorkflowDefinitionService workflowDefinitions,
WorkflowInstanceService workflowInstances, WorkflowInstanceDao workflowInstanceDao,
Expand Down Expand Up @@ -116,7 +116,7 @@ private void runImpl() {
logger.debug("Finished.");
}

private void logIfLagging(WorkflowInstance instance) {
void logIfLagging(WorkflowInstance instance) {
DateTime now = now();
Duration executionLag = new Duration(instance.nextActivation, now);
if (executionLag.isLongerThan(standardMinutes(1))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.Matchers.not;
import static org.joda.time.DateTime.now;
import static org.joda.time.DateTimeUtils.currentTimeMillis;
import static org.joda.time.DateTimeUtils.setCurrentMillisFixed;
import static org.joda.time.DateTimeUtils.setCurrentMillisSystem;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
Expand All @@ -37,6 +40,7 @@
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.joda.time.DateTime;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
Expand Down Expand Up @@ -97,6 +101,12 @@ public class WorkflowStateProcessorTest extends BaseNflowTest {
public void setup() {
executor = new WorkflowStateProcessor(1, objectMapper, workflowDefinitions, workflowInstances, workflowInstanceDao,
listener1, listener2);
setCurrentMillisFixed(currentTimeMillis());
}

@After
public void cleanUp() {
setCurrentMillisSystem();
}

@Test
Expand Down Expand Up @@ -467,6 +477,30 @@ public void failureListenersAreExecutedAfterFailure() {
verifyNoMoreInteractions(listener1, listener2);
}

@Test
public void logIfLaggingUpdatesLastLoggedWhenLogIsLagging() {
executor.lastLogged = now().minusDays(1);
WorkflowInstance instance = constructWorkflowInstanceBuilder().setNextActivation(now().minusMinutes(2)).build();
executor.logIfLagging(instance);
assertThat(executor.lastLogged, is(now()));
}

@Test
public void logIfLaggingDoesNotUpdateLastLoggedWhenInstanceIsNotLagging() {
executor.lastLogged = now().minusDays(1);
WorkflowInstance instance = constructWorkflowInstanceBuilder().setNextActivation(now().minusSeconds(59)).build();
executor.logIfLagging(instance);
assertThat(executor.lastLogged, is(now().minusDays(1)));
}

@Test
public void logIfLaggingDoesNotUpdateLastLoggedWhenLaggingIsRecentlyLogged() {
executor.lastLogged = now().minusSeconds(29);
WorkflowInstance instance = constructWorkflowInstanceBuilder().setNextActivation(now().minusMinutes(2)).build();
executor.logIfLagging(instance);
assertThat(executor.lastLogged, is(now().minusSeconds(29)));
}

static final class IsTestFailException extends ArgumentMatcher<Throwable> {
@Override
public boolean matches(Object argument) {
Expand Down

0 comments on commit b46e83a

Please sign in to comment.