[jbpm-commits] JBoss JBPM SVN: r1835 - in jbpm4/pvm/trunk/modules/core/src: test/java/org/jbpm/pvm and 4 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Wed Aug 6 07:34:18 EDT 2008
Author: tom.baeyens at jboss.com
Date: 2008-08-06 07:34:18 -0400 (Wed, 06 Aug 2008)
New Revision: 1835
Modified:
jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobAddedNotification.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/DbTests.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/continuation/AutomaticActivity.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/continuation/ContinuationTest.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/continuation/ContinuationTests.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/continuation/Recorder.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/continuation/WaitState.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/DbModelTests.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTests.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/wire/WireTests.java
Log:
added continuation tests
Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobAddedNotification.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobAddedNotification.java 2008-08-06 09:59:01 UTC (rev 1834)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobAddedNotification.java 2008-08-06 11:34:18 UTC (rev 1835)
@@ -48,4 +48,8 @@
public void beforeCompletion() {
}
+
+ public String toString() {
+ return "job-added-notification";
+ }
}
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/DbTests.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/DbTests.java 2008-08-06 09:59:01 UTC (rev 1834)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/DbTests.java 2008-08-06 11:34:18 UTC (rev 1835)
@@ -46,7 +46,7 @@
defaultConfigTests.addTest(DbModelTests.suite());
defaultConfigTests.addTest(DbSvcTests.suite());
defaultConfigTests.addTest(JobExecutorTests.suite());
- // defaultConfigTests.addTest(ContinuationTests.suite());
+ defaultConfigTests.addTest(ContinuationTests.suite());
suite.addTest(new EnvironmentFactoryTestSetup(defaultConfigTests, "environment.cfg.xml"));
suite.addTest(new EnvironmentFactoryTestSetup(DbLangExtTests.suite(), "org/jbpm/pvm/internal/db/langext/environment.cfg.xml"));
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/continuation/AutomaticActivity.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/continuation/AutomaticActivity.java 2008-08-06 09:59:01 UTC (rev 1834)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/continuation/AutomaticActivity.java 2008-08-06 11:34:18 UTC (rev 1835)
@@ -23,7 +23,6 @@
import org.jbpm.pvm.activity.Activity;
import org.jbpm.pvm.activity.ActivityExecution;
-import org.jbpm.pvm.env.Environment;
/** a node behaviour implementation that records its execution and then
* just proceeds.
@@ -38,10 +37,6 @@
}
public void execute(ActivityExecution execution) throws Exception {
- Environment environment = Environment.getCurrent();
- Recorder recorder = environment.get(Recorder.class);
- if (recorder!=null) {
- recorder.record(execution.getDbid(), execution.getNode().getName());
- }
+ ContinuationTest.recorder.record(execution.getDbid(), "execute("+execution.getNode().getName()+")");
}
}
\ No newline at end of file
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/continuation/ContinuationTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/continuation/ContinuationTest.java 2008-08-06 09:59:01 UTC (rev 1834)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/continuation/ContinuationTest.java 2008-08-06 11:34:18 UTC (rev 1835)
@@ -21,7 +21,9 @@
*/
package org.jbpm.pvm.api.db.continuation;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
@@ -31,7 +33,7 @@
import org.jbpm.pvm.client.ClientProcessInstance;
import org.jbpm.pvm.env.Environment;
import org.jbpm.pvm.env.EnvironmentFactory;
-import org.jbpm.pvm.env.PvmEnvironmentFactory;
+import org.jbpm.pvm.internal.cmd.Command;
import org.jbpm.pvm.internal.job.JobImpl;
import org.jbpm.pvm.internal.jobexecutor.JobExecutor;
import org.jbpm.pvm.internal.log.Log;
@@ -39,80 +41,87 @@
import org.jbpm.pvm.model.ProcessFactory;
import org.jbpm.pvm.session.DbSession;
import org.jbpm.pvm.session.PvmDbSession;
-import org.jbpm.pvm.test.base.JbpmTestCase;
+import org.jbpm.pvm.test.base.DbTestCase;
/**
* @author Tom Baeyens
*/
-public class ContinuationTest extends JbpmTestCase {
+public class ContinuationTest extends DbTestCase {
private static final Log log = Log.getLog(ContinuationTest.class.getName());
+ static Recorder recorder = new Recorder();
+
public void testContinuations() {
int nbrOfExecutions = 20;
- int testTimeoutMillis = 200000;
+ int testTimeoutMillis = 20000;
int checkInterval = 500;
- EnvironmentFactory environmentFactory = new PvmEnvironmentFactory(
- "org/jbpm/pvm/api/db/continuation/ContinuationTest.cfg.xml"
- );
+ EnvironmentFactory environmentFactory = getEnvironmentFactory();
Set<Integer> expected = new HashSet<Integer>();
JobExecutor jobExecutor = environmentFactory.get(JobExecutor.class);
try {
deployProcess(environmentFactory);
startExecutions(nbrOfExecutions, environmentFactory, expected);
- startExecutions(nbrOfExecutions, environmentFactory, expected);
+ jobExecutor.start();
waitTillNoMoreMessages(jobExecutor, testTimeoutMillis, checkInterval, environmentFactory);
} finally {
jobExecutor.stop(true);
}
- Recorder recorder = environmentFactory.get(Recorder.class);
- log.debug("recorder: "+recorder.executionEvents);
+ List<String> expectedLogs = new ArrayList<String>();
+ expectedLogs.add("execute(start)");
+ expectedLogs.add("execute(a)");
+ expectedLogs.add("execute(b)");
+ expectedLogs.add("execute(c)");
+ expectedLogs.add("execute(end)");
+
+ assertEquals(nbrOfExecutions, recorder.executionEvents.size());
+ for (List<String> executionLogs: recorder.executionEvents.values()) {
+ assertEquals(expectedLogs, executionLogs);
+ }
}
- public void startExecutions(int nbrOfExecutions, EnvironmentFactory environmentFactory, Set<Integer> expected) {
- for (int i=0; i<nbrOfExecutions; i++) {
- Environment environment = environmentFactory.openEnvironment();
- try {
- PvmDbSession pvmDbSession = environment.get(PvmDbSession.class);
- ClientProcessDefinition processDefinition = pvmDbSession.findProcessDefinition("continuations");
- ClientProcessInstance execution = processDefinition.beginProcessInstance();
- pvmDbSession.save(execution);
-
- } finally {
- environment.close();
+ public void deployProcess(EnvironmentFactory environmentFactory) {
+ commandService.execute(new Command<Object>() {
+ public Object execute(Environment environment) throws Exception {
+ log.debug("building process 'continuations'");
+ ProcessDefinition processDefinition = ProcessFactory.build("continuations")
+ .node("start").initial().behaviour(AutomaticActivity.class)
+ .asyncExecute()
+ .transition().to("a")
+ .node("a").behaviour(AutomaticActivity.class)
+ .asyncExecute()
+ .transition().to("b")
+ .node("b").behaviour(AutomaticActivity.class)
+ .asyncExecute()
+ .transition().to("c")
+ .node("c").behaviour(AutomaticActivity.class)
+ .asyncExecute()
+ .transition().to("end")
+ .node("end").behaviour(WaitState.class)
+ .done();
+
+ log.debug("saving process 'continuations'");
+ environment.get(DbSession.class).save(processDefinition);
+ return null;
}
- }
+ });
}
- public void deployProcess(EnvironmentFactory environmentFactory) {
- Environment environment = environmentFactory.openEnvironment();
- try {
- log.debug("building process 'continuations'");
- ProcessDefinition processDefinition = ProcessFactory.build("continuations")
- .node("start").initial().behaviour(AutomaticActivity.class)
- .asyncExecute()
- .transition().to("a")
- .node("a").behaviour(AutomaticActivity.class)
- .asyncExecute()
- .transition().to("b")
- .node("b").behaviour(AutomaticActivity.class)
- .asyncExecute()
- .transition().to("c")
- .node("c").behaviour(AutomaticActivity.class)
- .asyncExecute()
- .transition().to("end")
- .node("end").behaviour(WaitState.class)
- .done();
-
- log.debug("saving process 'continuations'");
- environment.get(DbSession.class).save(processDefinition);
-
- } finally {
- environment.close();
+ public void startExecutions(int nbrOfExecutions, EnvironmentFactory environmentFactory, Set<Integer> expected) {
+ for (int i=0; i<nbrOfExecutions; i++) {
+ commandService.execute(new Command<Object>() {
+ public Object execute(Environment environment) throws Exception {
+ PvmDbSession pvmDbSession = environment.get(PvmDbSession.class);
+ ClientProcessDefinition processDefinition = pvmDbSession.findProcessDefinition("continuations");
+ ClientProcessInstance execution = processDefinition.beginProcessInstance();
+ pvmDbSession.save(execution);
+ return null;
+ }
+ });
}
}
@@ -146,17 +155,17 @@
}
private boolean areJobsAvailable(EnvironmentFactory environmentFactory) {
- int nbrOfJobsAvailable = 0;
- Environment environment = environmentFactory.openEnvironment();
- try {
- Session session = environment.get(Session.class);
- Number jobs = (Number) session.createQuery("select count(*) from " + JobImpl.class.getName()).uniqueResult();
- if (jobs!=null) {
- nbrOfJobsAvailable = jobs.intValue();
+ Integer nbrOfJobsAvailable = (Integer) commandService.execute(new Command<Object>() {
+ public Object execute(Environment environment) throws Exception {
+ Session session = environment.get(Session.class);
+ Number jobs = (Number) session.createQuery("select count(*) from " + JobImpl.class.getName()).uniqueResult();
+ if (jobs!=null) {
+ return jobs.intValue();
+ }
+ return 0;
}
- } finally {
- environment.close();
- }
+ });
+
boolean areJobsAvailable = nbrOfJobsAvailable>0;
if (areJobsAvailable) {
log.debug("there are "+nbrOfJobsAvailable+" jobs currently in the jobImpl table");
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/continuation/ContinuationTests.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/continuation/ContinuationTests.java 2008-08-06 09:59:01 UTC (rev 1834)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/continuation/ContinuationTests.java 2008-08-06 11:34:18 UTC (rev 1835)
@@ -31,7 +31,7 @@
public class ContinuationTests {
public static Test suite() {
- TestSuite suite = new TestSuite("Test for org.jbpm.pvm.api.db.continuation");
+ TestSuite suite = new TestSuite("org.jbpm.pvm.api.db.continuation");
//$JUnit-BEGIN$
suite.addTestSuite(ContinuationTest.class);
//$JUnit-END$
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/continuation/Recorder.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/continuation/Recorder.java 2008-08-06 09:59:01 UTC (rev 1834)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/continuation/Recorder.java 2008-08-06 11:34:18 UTC (rev 1835)
@@ -31,15 +31,15 @@
*/
public class Recorder {
- public Map<Object, List<Object>> executionEvents = null;
+ public Map<Object, List<String>> executionEvents = null;
- public synchronized void record(long executionDbid, Object event) {
+ public synchronized void record(long executionDbid, String event) {
if (executionEvents==null) {
- executionEvents = new HashMap<Object, List<Object>>();
+ executionEvents = new HashMap<Object, List<String>>();
}
- List<Object> events = executionEvents.get(executionDbid);
+ List<String> events = executionEvents.get(executionDbid);
if (events == null) {
- events = new ArrayList<Object>();
+ events = new ArrayList<String>();
executionEvents.put(executionDbid, events);
}
events.add(event);
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/continuation/WaitState.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/continuation/WaitState.java 2008-08-06 09:59:01 UTC (rev 1834)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/continuation/WaitState.java 2008-08-06 11:34:18 UTC (rev 1835)
@@ -25,7 +25,6 @@
import org.jbpm.pvm.activity.ActivityExecution;
import org.jbpm.pvm.activity.ExternalActivity;
-import org.jbpm.pvm.env.Environment;
/**
* @author Tom Baeyens
@@ -38,18 +37,14 @@
}
public void execute(ActivityExecution execution) throws Exception {
- record("execute", execution);
- execution.waitForSignal();
+ ContinuationTest.recorder.record(execution.getDbid(), "execute("+execution.getNode().getName()+")");
}
public void signal(ActivityExecution execution, String signal, Map<String, Object> parameters) throws Exception {
- record("signal", execution);
+ throw new UnsupportedOperationException();
}
/** records event[currentNodeName] if there is a recorder */
public void record(String event, ActivityExecution execution) {
- Environment environment = Environment.getCurrent();
- Recorder recorder = environment.get(Recorder.class);
- recorder.record(execution.getDbid(), event+"["+execution.getNode().getName()+"]");
}
}
\ No newline at end of file
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/DbModelTests.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/DbModelTests.java 2008-08-06 09:59:01 UTC (rev 1834)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/model/DbModelTests.java 2008-08-06 11:34:18 UTC (rev 1835)
@@ -31,7 +31,7 @@
public class DbModelTests {
public static Test suite() {
- TestSuite suite = new TestSuite("Test for org.jbpm.pvm.db.model");
+ TestSuite suite = new TestSuite("org.jbpm.pvm.internal.db.model");
//$JUnit-BEGIN$
suite.addTestSuite(SessionFactoryDbTest.class);
suite.addTestSuite(ProcessCacheDbTest.class);
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTests.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTests.java 2008-08-06 09:59:01 UTC (rev 1834)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTests.java 2008-08-06 11:34:18 UTC (rev 1835)
@@ -31,7 +31,7 @@
public class JobExecutorTests {
public static Test suite() {
- TestSuite suite = new TestSuite("Test for org.jbpm.pvm.jobexecutor");
+ TestSuite suite = new TestSuite("org.jbpm.pvm.internal.jobexecutor");
//$JUnit-BEGIN$
suite.addTestSuite(JobExecutorTest.class);
//$JUnit-END$
Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/wire/WireTests.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/wire/WireTests.java 2008-08-06 09:59:01 UTC (rev 1834)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/wire/WireTests.java 2008-08-06 11:34:18 UTC (rev 1835)
@@ -31,7 +31,7 @@
public class WireTests {
public static Test suite() {
- TestSuite suite = new TestSuite("Test for org.jbpm.wire");
+ TestSuite suite = new TestSuite("org.jbpm.pvm.internal.wire");
//$JUnit-BEGIN$
suite.addTestSuite(AutoWireTest.class);
suite.addTestSuite(BasicTypeWireTest.class);
More information about the jbpm-commits
mailing list