-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Edvard Fonsell
committed
Mar 16, 2015
1 parent
31cd6fe
commit 0b5b1e9
Showing
2 changed files
with
120 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
nflow-tests/src/test/java/com/nitorcreations/nflow/tests/StatisticsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package com.nitorcreations.nflow.tests; | ||
|
||
import static com.nitorcreations.nflow.tests.demo.DemoWorkflow.DEMO_WORKFLOW_TYPE; | ||
import static java.lang.System.clearProperty; | ||
import static java.lang.System.setProperty; | ||
import static org.apache.cxf.jaxrs.client.WebClient.fromClient; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
import static org.joda.time.DateTime.now; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertThat; | ||
import static org.junit.runners.MethodSorters.NAME_ASCENDING; | ||
|
||
import java.util.Map; | ||
|
||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.core.Response.Status.Family; | ||
|
||
import org.joda.time.DateTime; | ||
import org.junit.After; | ||
import org.junit.ClassRule; | ||
import org.junit.FixMethodOrder; | ||
import org.junit.Test; | ||
|
||
import com.nitorcreations.nflow.rest.v1.msg.CreateWorkflowInstanceRequest; | ||
import com.nitorcreations.nflow.rest.v1.msg.CreateWorkflowInstanceResponse; | ||
import com.nitorcreations.nflow.rest.v1.msg.DefinitionStatisticsResponse; | ||
import com.nitorcreations.nflow.rest.v1.msg.StatisticsResponse; | ||
import com.nitorcreations.nflow.rest.v1.msg.UpdateWorkflowInstanceRequest; | ||
import com.nitorcreations.nflow.rest.v1.msg.WorkflowDefinitionStatisticsResponse; | ||
import com.nitorcreations.nflow.tests.DemoWorkflowTest.DemoConfiguration; | ||
import com.nitorcreations.nflow.tests.runner.NflowServerRule; | ||
|
||
@FixMethodOrder(NAME_ASCENDING) | ||
public class StatisticsTest extends AbstractNflowTest { | ||
|
||
static DateTime FUTURE = now().plusYears(1); | ||
|
||
@ClassRule | ||
public static NflowServerRule server = new NflowServerRule.Builder().springContextClass(DemoConfiguration.class) | ||
.prop("nflow.executor.timeout.seconds", 1) | ||
.prop("nflow.executor.keepalive.seconds", 5) | ||
.prop("nflow.dispatcher.await.termination.seconds", 1) | ||
.prop("nflow.db.h2.url", "jdbc:h2:mem:statisticstest;TRACE_LEVEL_FILE=4;DB_CLOSE_DELAY=-1") | ||
.build(); | ||
|
||
private static CreateWorkflowInstanceResponse resp; | ||
|
||
public StatisticsTest() { | ||
super(server); | ||
} | ||
|
||
@After | ||
public void cleanup() { | ||
clearProperty("nflow.autostart"); | ||
} | ||
|
||
@Test | ||
public void t01_submitWorkflow() { | ||
CreateWorkflowInstanceRequest req = new CreateWorkflowInstanceRequest(); | ||
req.type = DEMO_WORKFLOW_TYPE; | ||
req.businessKey = "1"; | ||
req.activationTime = FUTURE; | ||
resp = fromClient(workflowInstanceResource, true).put(req, CreateWorkflowInstanceResponse.class); | ||
assertThat(resp.id, notNullValue()); | ||
} | ||
|
||
@Test | ||
public void t02_queryStatistics() { | ||
StatisticsResponse statistics = getStatistics(); | ||
assertEquals(0, statistics.executionStatistics.count); | ||
assertEquals(0, statistics.queueStatistics.count); | ||
} | ||
|
||
@Test | ||
public void t03_queryDefinitionStatistics() { | ||
WorkflowDefinitionStatisticsResponse statistics = getDefinitionStatistics(DEMO_WORKFLOW_TYPE); | ||
assertThat(statistics.stateStatistics, is(notNullValue())); | ||
Map<String, DefinitionStatisticsResponse> map = statistics.stateStatistics.get("begin"); | ||
assertThat(map.get("created").allInstances, is(1L)); | ||
assertThat(map.get("created").queuedInstances, is(0L)); | ||
} | ||
|
||
@Test | ||
public void t04_stopServer() { | ||
// This does not actually stop the executor threads, because JVM does not exit. | ||
// Connection pool is closed though, so the workflow instance state cannot be updated by the stopped nflow engine. | ||
server.stopServer(); | ||
} | ||
|
||
@Test | ||
public void t05_restartServer() throws Exception { | ||
setProperty("nflow.autostart", "false"); | ||
server.startServer(); | ||
} | ||
|
||
@Test | ||
public void t06_updateNextActivationToPast() { | ||
UpdateWorkflowInstanceRequest req = new UpdateWorkflowInstanceRequest(); | ||
req.nextActivationTime = now().minusMinutes(5); | ||
Response response = fromClient(workflowInstanceResource, true).path(resp.id).put(req); | ||
assertThat(response.getStatusInfo().getFamily(), is(Family.SUCCESSFUL)); | ||
} | ||
|
||
@Test | ||
public void t07_queryStatistics() { | ||
StatisticsResponse statistics = getStatistics(); | ||
assertEquals(0, statistics.executionStatistics.count); | ||
assertEquals(1, statistics.queueStatistics.count); | ||
} | ||
|
||
@Test | ||
public void t08_queryDefinitionStatistics() { | ||
WorkflowDefinitionStatisticsResponse statistics = getDefinitionStatistics(DEMO_WORKFLOW_TYPE); | ||
assertThat(statistics.stateStatistics, is(notNullValue())); | ||
Map<String, DefinitionStatisticsResponse> map = statistics.stateStatistics.get("begin"); | ||
assertThat(map.get("created").allInstances, is(1L)); | ||
assertThat(map.get("created").queuedInstances, is(1L)); | ||
} | ||
} |