[jbpm-commits] JBoss JBPM SVN: r2633 - in jbpm3/trunk/modules/core: src/main/java/org/jbpm and 9 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Tue Oct 28 04:20:51 EDT 2008
Author: alex.guizar at jboss.com
Date: 2008-10-28 04:20:50 -0400 (Tue, 28 Oct 2008)
New Revision: 2633
Modified:
jbpm3/trunk/modules/core/pom.xml
jbpm3/trunk/modules/core/src/main/java/org/jbpm/EventCallback.java
jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java
jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/GraphSession.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1072/JBPM1072Test.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1135/JBPM1135Test.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1755/JBPM1755Test.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm983/JBPM983Test.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/job/executor/JobExecutorDbTest.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/optimisticlocking/LockingTest.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/scheduler/exe/TimerDbTest.java
jbpm3/trunk/modules/core/src/test/java/org/jbpm/taskmgmt/exe/TaskTimerExecutionDbTest.java
Log:
revised core tests that were taking too long, acting funny, or both
ran test suite like a maniac against postgresql, mysql and hsqldb to check stability
Modified: jbpm3/trunk/modules/core/pom.xml
===================================================================
--- jbpm3/trunk/modules/core/pom.xml 2008-10-28 01:24:17 UTC (rev 2632)
+++ jbpm3/trunk/modules/core/pom.xml 2008-10-28 08:20:50 UTC (rev 2633)
@@ -226,11 +226,6 @@
<!-- https://jira.jboss.org/jira/browse/JBPM-1723 -->
<exclude>org/jbpm/perf/PerfWithoutDbTest.java</exclude>
<exclude>org/jbpm/perf/StateUpdateTest.java</exclude>
- <!-- https://jira.jboss.org/jira/browse/JBPM-1724 -->
- <exclude>org/jbpm/seam/SeamPageFlowTest.java</exclude>
- <!-- https://jira.jboss.org/jira/browse/JBPM-1709 -->
- <exclude>org/jbpm/scheduler/exe/TimerDbTest.java</exclude>
- <exclude>org/jbpm/taskmgmt/exe/TaskTimerExecutionDbTest.java</exclude>
</excludes>
</configuration>
</plugin>
@@ -262,9 +257,6 @@
<!-- https://jira.jboss.org/jira/browse/JBPM-1723 -->
<exclude>org/jbpm/perf/PerfWithoutDbTest.java</exclude>
<exclude>org/jbpm/perf/StateUpdateTest.java</exclude>
- <!-- https://jira.jboss.org/jira/browse/JBPM-1709 -->
- <exclude>org/jbpm/scheduler/exe/TimerDbTest.java</exclude>
- <exclude>org/jbpm/taskmgmt/exe/TaskTimerExecutionDbTest.java</exclude>
</excludes>
</configuration>
</plugin>
@@ -298,9 +290,6 @@
<exclude>org/jbpm/perf/StateUpdateTest.java</exclude>
<!-- https://jira.jboss.org/jira/browse/JBPM-1735 -->
<exclude>org/jbpm/graph/node/ProcessStateDbTest.java</exclude>
- <!-- https://jira.jboss.org/jira/browse/JBPM-1709 -->
- <exclude>org/jbpm/scheduler/exe/TimerDbTest.java</exclude>
- <exclude>org/jbpm/taskmgmt/exe/TaskTimerExecutionDbTest.java</exclude>
</excludes>
</configuration>
</plugin>
@@ -337,9 +326,6 @@
<exclude>org/jbpm/graph/exe/SubProcessPlusConcurrencyDbTest.java</exclude>
<!-- https://jira.jboss.org/jira/browse/JBPM-1782 -->
<exclude>org/jbpm/jpdl/exe/JoinExecutionDbTest.java</exclude>
- <!-- https://jira.jboss.org/jira/browse/JBPM-1709 -->
- <exclude>org/jbpm/scheduler/exe/TimerDbTest.java</exclude>
- <exclude>org/jbpm/taskmgmt/exe/TaskTimerExecutionDbTest.java</exclude>
</excludes>
</configuration>
</plugin>
@@ -373,9 +359,6 @@
<exclude>org/jbpm/perf/StateUpdateTest.java</exclude>
<!-- https://jira.jboss.org/jira/browse/JBPM-1764 -->
<exclude>org/jbpm/job/executor/JobExecutorDbTest</exclude>
- <!-- https://jira.jboss.org/jira/browse/JBPM-1709 -->
- <exclude>org/jbpm/scheduler/exe/TimerDbTest.java</exclude>
- <exclude>org/jbpm/taskmgmt/exe/TaskTimerExecutionDbTest.java</exclude>
</excludes>
</configuration>
</plugin>
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/EventCallback.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/EventCallback.java 2008-10-28 01:24:17 UTC (rev 2632)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/EventCallback.java 2008-10-28 08:20:50 UTC (rev 2633)
@@ -37,6 +37,8 @@
public class EventCallback implements Serializable {
+ public static final int DEFAULT_TIMEOUT = 30 * 1000;
+
private static final long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(EventCallback.class);
@@ -100,7 +102,7 @@
}
public static void waitForEvent(String event) {
- waitForEvent(event, 10000);
+ waitForEvent(event, DEFAULT_TIMEOUT);
}
public static void waitForEvent(String event, long timeout) {
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java 2008-10-28 01:24:17 UTC (rev 2632)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java 2008-10-28 08:20:50 UTC (rev 2633)
@@ -199,7 +199,7 @@
jobExecutor.start();
}
- protected void processAllJobs(final long maxWait, int maxJobs)
+ protected void waitForJobs(long timeout, int maxJobs)
{
// install a timer that will interrupt if it takes too long
// if that happens, it will lead to an interrupted exception and the test
@@ -215,7 +215,7 @@
}
};
Timer timer = new Timer();
- timer.schedule(interruptTask, maxWait);
+ timer.schedule(interruptTask, timeout);
try
{
@@ -227,7 +227,7 @@
}
catch (InterruptedException e)
{
- fail("test execution exceeded treshold of " + maxWait + " milliseconds");
+ fail("test execution exceeded treshold of " + timeout + " milliseconds");
}
finally
{
@@ -289,7 +289,7 @@
startJobExecutor();
try
{
- processAllJobs(maxWait, maxJobs);
+ waitForJobs(maxWait, maxJobs);
}
finally
{
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/GraphSession.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/GraphSession.java 2008-10-28 01:24:17 UTC (rev 2632)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/GraphSession.java 2008-10-28 08:20:50 UTC (rev 2633)
@@ -29,7 +29,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.Query;
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1072/JBPM1072Test.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1072/JBPM1072Test.java 2008-10-28 01:24:17 UTC (rev 2632)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1072/JBPM1072Test.java 2008-10-28 08:20:50 UTC (rev 2633)
@@ -32,7 +32,10 @@
import org.jbpm.job.executor.JobExecutor;
/**
- * Concurrent JobExecutors can process the same job in parallel
+ * Concurrent job executors can process the same job in parallel.
+ * The test simulates multiple nodes in the network processing a common job set.
+ * The key setting is to give each job executor a different name;
+ * normally, a job executor is named after the node's inet address
*
* https://jira.jboss.org/jira/browse/JBPM-1072
*
@@ -41,15 +44,14 @@
*/
public class JBPM1072Test extends AbstractDbTestCase {
- private static final int JOB_EXECUTOR_COUNT = 8;
+ private static final int JOB_EXECUTOR_COUNT = 4;
private JobExecutor[] jobExecutors = new JobExecutor[JOB_EXECUTOR_COUNT];
- private ProcessDefinition processDefinition;
+ private long processDefinitionId;
- private static final String PROCESS_DEFINITION = "<?xml version='1.0' encoding='UTF-8'?>"
- + "<process-definition name='"
- + JBPM1072Test.class.getName()
- + "'>"
+ private volatile static int executionCount;
+
+ private static final String PROCESS_DEFINITION = "<process-definition name='job-executors'>"
+ "<event type='process-end'>"
+ "<action expression='#{eventCallback.processEnd}' />"
+ "</event>"
@@ -74,36 +76,55 @@
@Override
protected void setUp() throws Exception {
super.setUp();
- processDefinition = ProcessDefinition.parseXmlString(PROCESS_DEFINITION);
+
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(PROCESS_DEFINITION);
jbpmContext.deployProcessDefinition(processDefinition);
+ newTransaction();
+ processDefinitionId = processDefinition.getId();
+
+ startJobExecutors();
}
@Override
protected void tearDown() throws Exception {
+ stopJobExecutors();
+ graphSession.deleteProcessDefinition(processDefinitionId);
+ super.tearDown();
+
EventCallback.clear();
- graphSession.deleteProcessDefinition(processDefinition);
- super.tearDown();
}
public void testMultipleJobExecutors() {
- // start job executors
- for (int i = 0; i < jobExecutors.length; i++) {
- jobExecutors[i] = (JobExecutor) JbpmConfiguration.Configs.getObject("jbpm.job.executor");
- jobExecutors[i].setName("JbpmJobExecutor/" + (i + 1));
- jobExecutors[i].start();
- }
+ executionCount = 0;
// kick off process instance
+ ProcessDefinition processDefinition = graphSession.loadProcessDefinition(processDefinitionId);
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.getContextInstance().setVariable("eventCallback", new EventCallback());
processInstance.signal();
+ jbpmContext.save(processInstance);
+
commitAndCloseSession();
+ try {
+ EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
+ assertEquals(2, executionCount);
- // wait for process end
- EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
- assertEquals(2, Counter.getExecutionCount());
+ waitForJobs(EventCallback.DEFAULT_TIMEOUT, 0);
+ }
+ finally {
+ beginSessionTransaction();
+ }
+ }
- // stop job executors
+ private void startJobExecutors() {
+ for (int i = 0; i < jobExecutors.length; i++) {
+ jobExecutors[i] = (JobExecutor) JbpmConfiguration.Configs.getObject("jbpm.job.executor");
+ jobExecutors[i].setName("JbpmJobExecutor/" + i);
+ jobExecutors[i].start();
+ }
+ }
+
+ private void stopJobExecutors() {
for (int i = jobExecutors.length - 1; i >= 0; i--) {
try {
jobExecutors[i].stopAndJoin();
@@ -112,27 +133,19 @@
// continue to next executor
}
}
+ }
- beginSessionTransaction();
+ private static synchronized void incrementCount() {
+ ++executionCount;
}
public static class Counter implements ActionHandler {
- private static int executionCount = 0;
-
private static final long serialVersionUID = 1L;
public void execute(ExecutionContext exeContext) throws Exception {
incrementCount();
exeContext.leaveNode();
}
-
- private static synchronized int incrementCount() {
- return ++executionCount;
- }
-
- public static synchronized int getExecutionCount() {
- return executionCount;
- }
}
}
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1135/JBPM1135Test.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1135/JBPM1135Test.java 2008-10-28 01:24:17 UTC (rev 2632)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1135/JBPM1135Test.java 2008-10-28 08:20:50 UTC (rev 2633)
@@ -27,9 +27,9 @@
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
-/**
- * JobSession.deleteJobsForProcessInstance doesn't work if jbpm isn't the
- * transaction manager
+/**
+ * When a timer fires and another timer is created as part of its execution,
+ * no exception should be thrown.
*
* https://jira.jboss.org/jira/browse/JBPM-1135
*
@@ -42,18 +42,22 @@
@Override
protected void setUp() throws Exception {
super.setUp();
+
ProcessDefinition processDefinition = ProcessDefinition.parseXmlResource("org/jbpm/jbpm1135/timerprocess.xml");
jbpmContext.deployProcessDefinition(processDefinition);
processDefinitionId = processDefinition.getId();
+ newTransaction();
+
startJobExecutor();
}
@Override
protected void tearDown() throws Exception {
- EventCallback.clear();
stopJobExecutor();
graphSession.deleteProcessDefinition(processDefinitionId);
super.tearDown();
+
+ EventCallback.clear();
}
public void testTimerOnTimer() {
@@ -63,19 +67,19 @@
processInstance.signal();
jbpmContext.save(processInstance);
assertEquals("firstNode", processInstance.getRootToken().getNode().getName());
- commitAndCloseSession();
+ newTransaction();
+
EventCallback.waitForEvent(Event.EVENTTYPE_TIMER);
- beginSessionTransaction();
long processInstanceId = processInstance.getId();
assertEquals("secondNode", jbpmContext.loadProcessInstance(processInstanceId)
.getRootToken()
.getNode()
.getName());
- commitAndCloseSession();
+ newTransaction();
+
EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
- beginSessionTransaction();
assertTrue(jbpmContext.loadProcessInstance(processInstanceId).hasEnded());
}
}
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1755/JBPM1755Test.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1755/JBPM1755Test.java 2008-10-28 01:24:17 UTC (rev 2632)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1755/JBPM1755Test.java 2008-10-28 08:20:50 UTC (rev 2633)
@@ -38,11 +38,11 @@
@Override
protected void tearDown() throws Exception {
- EventCallback.clear();
-
stopJobExecutor();
graphSession.deleteProcessDefinition(processDefinitionId);
super.tearDown();
+
+ EventCallback.clear();
}
public void testReadLock() {
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm983/JBPM983Test.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm983/JBPM983Test.java 2008-10-28 01:24:17 UTC (rev 2632)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm983/JBPM983Test.java 2008-10-28 08:20:50 UTC (rev 2633)
@@ -10,7 +10,6 @@
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.graph.exe.ProcessInstance;
-import org.jbpm.job.executor.JobExecutor;
/**
* Concurrent process execution fails
@@ -42,17 +41,17 @@
jbpmContext.deployProcessDefinition(processDefinition);
processDefinitionId = processDefinition.getId();
- JobExecutor jobExecutor = getJbpmConfiguration().getJobExecutor();
- jobExecutor.setNbrOfThreads(5);
- jobExecutor.start();
+ newTransaction();
+
+ getJbpmConfiguration().getJobExecutor().setNbrOfThreads(5);
+ startJobExecutor();
}
protected void tearDown() throws Exception {
- getJbpmConfiguration().getJobExecutor().stop();
+ stopJobExecutor();
- newTransaction();
graphSession.deleteProcessDefinition(processDefinitionId);
- graphSession.deleteProcessDefinition(subProcessDefinitionId);
+ graphSession.deleteProcessDefinition(subProcessDefinitionId);
super.tearDown();
}
@@ -132,11 +131,11 @@
final int processCount = 10;
long[] processInstanceIds = new long[processCount];
for (int i = 0; i < processCount; i++) {
- newTransaction();
ProcessInstance processInstance = jbpmContext.newProcessInstanceForUpdate("superprocess");
processInstance.getContextInstance().addVariables(testVariables);
processInstance.signal();
processInstanceIds[i] = processInstance.getId();
+ newTransaction();
}
for (int i = 0; i < processCount; i++) {
@@ -146,21 +145,21 @@
ProcessInstance pi = jbpmContext.loadProcessInstance(piId);
assertEquals("end-state-success", pi.getRootToken().getNode().getName());
}
+
+ processJobs(30 * 1000);
}
protected void waitFor(long piId) throws Exception {
final int endTimeout = 30;
long startTime = System.currentTimeMillis();
- boolean processInstanceHasEnded = false;
- while (!processInstanceHasEnded) {
+ while(!jbpmContext.loadProcessInstance(piId).hasEnded()) {
if (System.currentTimeMillis() - startTime > endTimeout * 1000) {
fail("Aborting after " + endTimeout + " seconds.");
- return;
+ break;
}
newTransaction();
- processInstanceHasEnded = jbpmContext.loadProcessInstance(piId).hasEnded();
log.info("waiting for workflow completion....");
try {
@@ -168,6 +167,7 @@
}
catch (InterruptedException e) {
log.error("wait for workflow was interruputed", e);
+ break;
}
}
}
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/job/executor/JobExecutorDbTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/job/executor/JobExecutorDbTest.java 2008-10-28 01:24:17 UTC (rev 2632)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/job/executor/JobExecutorDbTest.java 2008-10-28 08:20:50 UTC (rev 2633)
@@ -4,121 +4,113 @@
import java.util.Collections;
import java.util.List;
import java.util.Set;
-import java.util.Timer;
-import java.util.TimerTask;
import java.util.TreeSet;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.hibernate.Session;
-import org.jbpm.AbstractJbpmTestCase;
-import org.jbpm.JbpmConfiguration;
-import org.jbpm.JbpmContext;
+import org.jbpm.db.AbstractDbTestCase;
import org.jbpm.graph.def.Action;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.graph.exe.ProcessInstance;
-public class JobExecutorDbTest extends AbstractJbpmTestCase
-{
- private static Log log = LogFactory.getLog(JobExecutorDbTest.class);
+public class JobExecutorDbTest extends AbstractDbTestCase {
- static int nbrOfConcurrentProcessExecutions = 20;
- static int maxWaitTime = 60000;
+ static final int nbrOfConcurrentProcessExecutions = 20;
+ static final int timeout = 60000;
+
static Set<String> collectedResults = Collections.synchronizedSet(new TreeSet<String>());
+ static List<Long> allocatedProcessIds = Collections.synchronizedList(new ArrayList<Long>());
- static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance("org/jbpm/jbpm.test.cfg.xml");
+ @Override
+ protected String getJbpmTestConfig() {
+ return "org/jbpm/jbpm.test.cfg.xml";
+ }
- static List<Long> allocatedProcessIds = Collections.synchronizedList(new ArrayList<Long>());
-
- {
- jbpmConfiguration.getJobExecutor().nbrOfThreads = 5;
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ deployProcess();
+ getJbpmConfiguration().getJobExecutor().setNbrOfThreads(5);
}
- private JobExecutor jobExecutor;
+ @Override
+ protected void tearDown() throws Exception {
+ deleteProcess();
+ super.tearDown();
+ }
- public void testJobExecutor()
- {
- jbpmConfiguration.createSchema();
- deployProcess();
+ public void testJobExecutor() {
launchProcesses();
- processJobs(maxWaitTime);
+ processJobs(timeout);
assertEquals(createExpectedResults(), collectedResults);
- jbpmConfiguration.createSchema();
}
- public void deployProcess()
- {
- JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
- try
- {
- ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition name='bulk messages'>"
- + " <start-state>"
- + " <transition to='a' />"
- + " </start-state>"
- + " <node name='a' async='true'>"
- + " <action class='" + AutomaticActivity.class.getName() + "' />"
- + " <transition to='b' />"
- + " </node>"
- + " <node name='b' async='true'>"
- + " <event type='node-enter'>"
- + " <action name='X' async='true' class='" + AsyncAction.class.getName() + "' />"
- + " </event>"
- + " <action class='" + AutomaticActivity.class.getName() + "' />"
- + " <transition to='c' />"
- + " </node>"
- + " <node name='c' async='true'>"
- + " <action class='" + AutomaticActivity.class.getName() + "' />"
- + " <transition to='d'>"
- + " <action name='Y' async='true' class='" + AsyncAction.class.getName() + "' />"
- + " </transition>"
- + " </node>"
- + " <node name='d' async='true'>"
- + " <action class='" + AutomaticActivity.class.getName() + "' />"
- + " <transition to='e' />"
- + " <event type='node-leave'>"
- + " <action name='Z' async='true' class='" + AsyncAction.class.getName() + "' />"
- + " </event>"
- + " </node>"
- + " <node name='e' async='true'>"
- + " <action class='" + AutomaticActivity.class.getName() + "' />"
- + " <transition to='end' />"
- + " </node>"
- + " <end-state name='end'/>"
- + "</process-definition>");
+ void deployProcess() {
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition name='bulk messages'>"
+ + " <start-state>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <node name='a' async='true'>"
+ + " <action class='"
+ + AutomaticActivity.class.getName()
+ + "' />"
+ + " <transition to='b' />"
+ + " </node>"
+ + " <node name='b' async='true'>"
+ + " <event type='node-enter'>"
+ + " <action name='X' async='true' class='"
+ + AsyncAction.class.getName()
+ + "' />"
+ + " </event>"
+ + " <action class='"
+ + AutomaticActivity.class.getName()
+ + "' />"
+ + " <transition to='c' />"
+ + " </node>"
+ + " <node name='c' async='true'>"
+ + " <action class='"
+ + AutomaticActivity.class.getName()
+ + "' />"
+ + " <transition to='d'>"
+ + " <action name='Y' async='true' class='"
+ + AsyncAction.class.getName()
+ + "' />"
+ + " </transition>"
+ + " </node>"
+ + " <node name='d' async='true'>"
+ + " <action class='"
+ + AutomaticActivity.class.getName()
+ + "' />"
+ + " <transition to='e' />"
+ + " <event type='node-leave'>"
+ + " <action name='Z' async='true' class='"
+ + AsyncAction.class.getName()
+ + "' />"
+ + " </event>"
+ + " </node>"
+ + " <node name='e' async='true'>"
+ + " <action class='"
+ + AutomaticActivity.class.getName()
+ + "' />"
+ + " <transition to='end' />"
+ + " </node>"
+ + " <end-state name='end'/>"
+ + "</process-definition>");
- jbpmContext.deployProcessDefinition(processDefinition);
- }
- finally
- {
- jbpmContext.close();
- }
+ jbpmContext.deployProcessDefinition(processDefinition);
}
- public void launchProcesses()
- {
- for (int i = 0; i < nbrOfConcurrentProcessExecutions; i++)
- {
- JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
- try
- {
- ProcessInstance processInstance = jbpmContext.newProcessInstanceForUpdate("bulk messages");
- processInstance.signal();
- }
- finally
- {
- jbpmContext.close();
- }
+ void launchProcesses() {
+ for (int i = 0; i < nbrOfConcurrentProcessExecutions; i++) {
+ newTransaction();
+ ProcessInstance processInstance = jbpmContext.newProcessInstanceForUpdate("bulk messages");
+ processInstance.signal();
}
}
- public Set<String> createExpectedResults()
- {
+ Set<String> createExpectedResults() {
Set<String> expectedResults = new TreeSet<String>();
- for (int i = 0; i < nbrOfConcurrentProcessExecutions; i++)
- {
+ for (int i = 0; i < nbrOfConcurrentProcessExecutions; i++) {
String prefix = (i < 10 ? "0" : "");
expectedResults.add(prefix + i + "a");
expectedResults.add(prefix + i + "b");
@@ -132,153 +124,43 @@
return expectedResults;
}
- protected void startJobExecutor()
- {
- jobExecutor = jbpmConfiguration.getJobExecutor();
- jobExecutor.start();
+ void deleteProcess() {
+ ProcessDefinition processDefinition = graphSession.findLatestProcessDefinition("bulk messages");
+ graphSession.deleteProcessDefinition(processDefinition);
}
- private void processAllJobs(final long maxWait)
- {
- boolean jobsAvailable = true;
+ public static class AutomaticActivity implements ActionHandler {
- // install a timer that will interrupt if it takes too long
- // if that happens, it will lead to an interrupted exception and the test will fail
- TimerTask interruptTask = new TimerTask()
- {
- Thread testThread = Thread.currentThread();
-
- public void run()
- {
- log.debug("test " + getName() + " took too long. going to interrupt...");
- testThread.interrupt();
- }
- };
- Timer timer = new Timer();
- timer.schedule(interruptTask, maxWait);
-
- try
- {
- while (jobsAvailable)
- {
- log.debug("going to sleep for 200 millis, waiting for the job executor to process more jobs");
- Thread.sleep(200);
- jobsAvailable = areJobsAvailable();
- }
- jobExecutor.stopAndJoin();
-
- }
- catch (InterruptedException e)
- {
- fail("test execution exceeded treshold of " + maxWait + " milliseconds");
- }
- finally
- {
- timer.cancel();
- }
- }
-
- private int getNbrOfJobsAvailable()
- {
- int nbrOfJobsAvailable = 0;
- JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
- try
- {
- Session session = jbpmContext.getSession();
- Number jobs = (Number)session.createQuery("select count(*) from org.jbpm.job.Job").uniqueResult();
- log.debug("there are '" + jobs + "' jobs currently in the job table");
- if (jobs != null)
- {
- nbrOfJobsAvailable = jobs.intValue();
- }
- }
- finally
- {
- jbpmContext.close();
- }
- return nbrOfJobsAvailable;
- }
-
- protected boolean areJobsAvailable()
- {
- return (getNbrOfJobsAvailable() > 0);
- }
-
- protected void processJobs(long maxWait)
- {
- try
- {
- Thread.sleep(300);
- }
- catch (InterruptedException e)
- {
- // ignore
- }
- startJobExecutor();
- try
- {
- processAllJobs(maxWait);
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- finally
- {
- stopJobExecutor();
- }
- }
-
- protected void stopJobExecutor()
- {
- if (jobExecutor != null)
- {
- try
- {
- jobExecutor.stopAndJoin();
- }
- catch (InterruptedException e)
- {
- throw new RuntimeException("waiting for job executor to stop and join got interrupted", e);
- }
- }
- }
-
- public static class AutomaticActivity implements ActionHandler
- {
private static final long serialVersionUID = 1L;
- public void execute(ExecutionContext executionContext) throws Exception
- {
+ public void execute(ExecutionContext executionContext) throws Exception {
Long id = executionContext.getProcessInstance().getId();
String procIndex = getProcessIndex(id);
-
+
String nodeName = executionContext.getNode().getName();
collectedResults.add(procIndex + nodeName);
executionContext.leaveNode();
}
}
- public static class AsyncAction implements ActionHandler
- {
+ public static class AsyncAction implements ActionHandler {
+
private static final long serialVersionUID = 1L;
- public void execute(ExecutionContext executionContext) throws Exception
- {
+ public void execute(ExecutionContext executionContext) throws Exception {
Long id = executionContext.getProcessInstance().getId();
String procIndex = getProcessIndex(id);
-
+
Action action = executionContext.getAction();
String actionName = action.getName();
collectedResults.add(procIndex + actionName);
}
}
-
- private static synchronized String getProcessIndex(Long id)
- {
+
+ static synchronized String getProcessIndex(Long id) {
if (allocatedProcessIds.contains(id) == false)
allocatedProcessIds.add(id);
-
+
int procIndex = allocatedProcessIds.indexOf(id);
String prefix = (procIndex < 10 ? "0" : "");
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/optimisticlocking/LockingTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/optimisticlocking/LockingTest.java 2008-10-28 01:24:17 UTC (rev 2632)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/optimisticlocking/LockingTest.java 2008-10-28 08:20:50 UTC (rev 2633)
@@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.concurrent.Semaphore;
import org.hibernate.Query;
import org.jbpm.JbpmConfiguration;
@@ -21,8 +22,8 @@
private long processDefinitionId;
- static int nbrOfThreads = 5;
- static int nbrOfIterations = 20;
+ static final int nbrOfThreads = 5;
+ static final int nbrOfIterations = 20;
protected void setUp() throws Exception {
super.setUp();
@@ -33,6 +34,7 @@
+ " <end-state name='end' />"
+ "</process-definition>");
jbpmContext.deployProcessDefinition(processDefinition);
+ newTransaction();
processDefinitionId = processDefinition.getId();
}
@@ -47,27 +49,28 @@
// the root token in the start state
// Transaction 2 will signal the process instance while it is in the
// start state, and that signal will bring the process to it's end state.
-
// multiple competing threads will be set up for the second transaction
+
+ ProcessDefinition processDefinition = graphSession.loadProcessDefinition(processDefinitionId);
for (int i = 0; i < nbrOfIterations; i++) {
- long processInstanceId = jbpmContext.newProcessInstanceForUpdate("lockprocess").getId();
- commitAndCloseSession();
+ ProcessInstance processInstance = new ProcessInstance(processDefinition);
+ jbpmContext.save(processInstance);
+ newTransaction();
+
// create a bunch of threads that will all wait on the
// semaphore before they will try to signal the same process instance
- Object semaphore = new Object();
+ long processInstanceId = processInstance.getId();
+ Semaphore semaphore = new Semaphore(0);
List threads = startThreads(semaphore, processInstanceId);
// release all the threads
- synchronized (semaphore) {
- semaphore.notifyAll();
- }
+ semaphore.release(nbrOfThreads);
// wait for all threads to finish
joinAllThreads(threads);
// check that only 1 of those threads committed
- beginSessionTransaction();
Query query = session.createQuery("from org.jbpm.graph.exe.Comment");
List results = query.list();
assertEquals(results.toString(), 1, results.size());
@@ -76,37 +79,43 @@
session.delete(results.get(0));
// check that the process instance has ended
- ProcessInstance processInstance = jbpmContext.loadProcessInstance(processInstanceId);
+ processInstance = jbpmContext.loadProcessInstance(processInstanceId);
assertTrue(processInstance.hasEnded());
}
}
- private List startThreads(Object semaphore, long processInstanceId) {
+ private List startThreads(Semaphore semaphore, long processInstanceId) {
+ JbpmConfiguration jbpmConfiguration = getJbpmConfiguration();
+
List threads = new ArrayList();
for (int i = 0; i < nbrOfThreads; i++) {
- Thread thread = new LockThread(getJbpmConfiguration(), semaphore, processInstanceId);
- thread.start();
+ Thread thread = new LockThread(jbpmConfiguration, semaphore, processInstanceId);
threads.add(thread);
+ thread.start();
}
+ return threads;
+ }
- try {
- // giving the threads the opportunity to start and arrive in the wait
- Thread.sleep(200);
+ private void joinAllThreads(List threads) {
+ Iterator iter = threads.iterator();
+ while (iter.hasNext()) {
+ Thread thread = (Thread) iter.next();
+ try {
+ thread.join(10000);
+ }
+ catch (InterruptedException e) {
+ fail("join interrupted");
+ }
}
- catch (InterruptedException e) {
- // ignore
- }
-
- return threads;
}
static class LockThread extends Thread {
- Object semaphore;
+ Semaphore semaphore;
long processInstanceId;
JbpmConfiguration jbpmConfiguration;
- public LockThread(JbpmConfiguration jbpmConfiguration, Object semaphore, long processInstanceId) {
+ public LockThread(JbpmConfiguration jbpmConfiguration, Semaphore semaphore, long processInstanceId) {
this.semaphore = semaphore;
this.processInstanceId = processInstanceId;
this.jbpmConfiguration = jbpmConfiguration;
@@ -116,9 +125,7 @@
try {
// first wait until the all threads are released at once in the
// method testLocking
- synchronized (semaphore) {
- semaphore.wait();
- }
+ semaphore.acquire();
// after a thread is released (=notified), it will try to load the
// process instance,
@@ -134,7 +141,7 @@
Comment comment = new Comment(getName() + " committed");
jbpmContext.getSession().save(comment);
}
- catch (Exception e) {
+ catch (RuntimeException e) {
jbpmContext.setRollbackOnly();
}
finally {
@@ -144,22 +151,9 @@
catch (InterruptedException e) {
fail("semaphore waiting got interrupted");
}
- catch (Throwable t) {
- // ignore
+ catch (RuntimeException e) {
+ // ignore other exceptions
}
}
}
-
- private void joinAllThreads(List threads) {
- Iterator iter = threads.iterator();
- while (iter.hasNext()) {
- Thread thread = (Thread) iter.next();
- try {
- thread.join();
- }
- catch (InterruptedException e) {
- fail("join interrupted");
- }
- }
- }
}
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/scheduler/exe/TimerDbTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/scheduler/exe/TimerDbTest.java 2008-10-28 01:24:17 UTC (rev 2632)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/scheduler/exe/TimerDbTest.java 2008-10-28 08:20:50 UTC (rev 2633)
@@ -60,6 +60,7 @@
session.save(timer);
try {
newTransaction();
+
timer = (Timer) session.load(Timer.class, new Long(timer.getId()));
assertEquals("timer-name", timer.getName());
@@ -104,19 +105,18 @@
graphSession.saveProcessDefinition(processDefinition);
try {
ProcessInstance processInstance = new ProcessInstance(processDefinition);
- jbpmContext.save(processInstance);
// long before = System.currentTimeMillis();
processInstance.signal();
// long after = System.currentTimeMillis();
jbpmContext.save(processInstance);
newTransaction();
+
Timer timer = (Timer) session.createQuery("from org.jbpm.job.Timer").uniqueResult();
assertNotNull("Timer is null", timer);
assertEquals("reminder", timer.getName());
// Commented out because of timer latency is changing between time
- // required
- // to connect to the database
+ // required to connect to the database
// assertTrue((before + 5000) <= timer.getDueDate().getTime());
// assertTrue(timer.getDueDate().getTime() <= (after + 5000));
assertEquals("catch crooks", timer.getGraphElement().getName());
@@ -147,6 +147,7 @@
processInstance.signal();
newTransaction();
+
assertEquals(0, getTimerCount());
}
finally {
@@ -174,8 +175,10 @@
graphSession.saveProcessDefinition(processDefinition);
try {
Node node = processDefinition.getNode("sometask");
+
List actions = node.getEvent(Event.EVENTTYPE_NODE_ENTER).getActions();
assertEquals(1, actions.size());
+
actions = node.getEvent(Event.EVENTTYPE_NODE_LEAVE).getActions();
assertEquals(1, actions.size());
@@ -184,6 +187,7 @@
jbpmContext.save(processInstance);
newTransaction();
+
assertEquals(1, getTimerCount());
}
finally {
@@ -210,6 +214,7 @@
processInstance.signal();
newTransaction();
+
assertEquals(1, getTimerCount());
}
finally {
@@ -224,7 +229,7 @@
+ " </start-state>"
+ " <state name='s'>"
+ " <event type='node-enter'>"
- + " <create-timer duedate='26 business seconds'>"
+ + " <create-timer duedate='52 seconds'>"
+ " <action class='claim.you.are.Innocent' />"
+ " </create-timer>"
+ " </event>"
@@ -241,7 +246,7 @@
assertEquals(1, getTimerCount());
processInstance.signal();
- processJobs(5000, 0);
+ processJobs(30 * 1000, 1);
assertEquals(0, getTimerCount());
}
finally {
@@ -310,6 +315,7 @@
jbpmContext.save(processInstance);
newTransaction();
+
Timer timer = (Timer) jobSession.getFirstAcquirableJob(null);
assertNotNull(timer);
Date date = timer.getDueDate();
@@ -318,7 +324,7 @@
// assertTrue(date.getTime() <= after);
long origDueDate = date.getTime();
- processJobs(2000, 1);
+ processJobs(2500, 1);
timer = (Timer) session.createQuery("from org.jbpm.job.Timer")
.setMaxResults(1)
@@ -329,10 +335,10 @@
// before = System.currentTimeMillis();
processInstance.signal("back");
// after = System.currentTimeMillis();
-
jbpmContext.save(processInstance);
newTransaction();
+
timer = (Timer) jobSession.getFirstAcquirableJob(null);
assertNotNull(timer);
date = timer.getDueDate();
@@ -341,11 +347,13 @@
// assertTrue(date.getTime() <= after);
newTransaction();
+
processInstance = jbpmContext.loadProcessInstance(processInstance.getId());
processInstance.signal();
jbpmContext.save(processInstance);
newTransaction();
+
assertEquals(0, getTimerCount());
}
finally {
@@ -383,11 +391,10 @@
processInstance.signal();
jbpmContext.save(processInstance);
- processJobs(2000, 1);
+ processJobs(2500, 1);
processInstance = jbpmContext.loadProcessInstance(processInstance.getId());
contextInstance = processInstance.getContextInstance();
-
assertEquals("value a", contextInstance.getVariable("a"));
assertEquals("value b updated", contextInstance.getVariable("b"));
@@ -401,7 +408,6 @@
finally {
jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
}
-
}
public static class ConcurrentUpdateAction implements ActionHandler {
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/taskmgmt/exe/TaskTimerExecutionDbTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/taskmgmt/exe/TaskTimerExecutionDbTest.java 2008-10-28 01:24:17 UTC (rev 2632)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/taskmgmt/exe/TaskTimerExecutionDbTest.java 2008-10-28 08:20:50 UTC (rev 2633)
@@ -79,7 +79,6 @@
{
jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
}
-
}
public void testTimerDeletion() {
@@ -105,19 +104,19 @@
{
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.signal();
-
jbpmContext.save(processInstance);
+
newTransaction();
-
+
List taskInstances = taskMgmtSession.findTaskInstancesByToken(processInstance.getRootToken().getId());
- assertEquals(1, taskInstances.size() );
-
+ assertEquals(1, taskInstances.size());
+
TaskInstance taskInstance = (TaskInstance) taskInstances.get(0);
taskInstance.end();
-
- jbpmContext.save(taskInstance.getTaskMgmtInstance().getProcessInstance());
+ jbpmContext.save(taskInstance);
+
newTransaction();
-
+
assertEquals(0, getTimerCount());
}
finally
@@ -147,11 +146,10 @@
{
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.signal();
-
jbpmContext.save(processInstance);
processJobs(5000);
-
+
assertEquals(1, counter);
}
finally
@@ -181,13 +179,10 @@
{
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.signal();
-
jbpmContext.save(processInstance);
newTransaction();
- // the timer executor creates its own JbpmSession.
- assertEquals(0, counter);
processJobs(5000);
assertEquals(1, counter);
}
@@ -195,7 +190,6 @@
{
jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
}
-
}
public void testTimerExecutionRepeat() {
@@ -219,17 +213,15 @@
{
ProcessInstance processInstance = new ProcessInstance(processDefinition);
processInstance.signal();
-
jbpmContext.save(processInstance);
+
newTransaction();
-
+
// fetch the original duedate
Timer timer = (Timer) getJob();
assertNotNull(timer);
long originalDueDate = timer.getDueDate().getTime();
-
- assertEquals(0, counter);
processJobs(5000, 1);
assertEquals(1, counter);
@@ -264,16 +256,15 @@
processDefinition = saveAndReload(processDefinition);
try
{
- ProcessInstance processInstance = new ProcessInstance(processDefinition);
-
Calendar baseDate = Calendar.getInstance();
Date dateTestDate = new Date();
baseDate.setTime(dateTestDate);
baseDate.clear(Calendar.MILLISECOND);
- processInstance.getContextInstance().setVariable("baseDate", baseDate.getTime());
+ ProcessInstance processInstance = new ProcessInstance(processDefinition);
+ processInstance.getContextInstance().setVariable("baseDate", baseDate.getTime());
processInstance.signal();
-
+
processInstance = saveAndReload(processInstance);
Calendar baseDateTest = Calendar.getInstance();
@@ -284,8 +275,8 @@
Timer timer = (Timer) getJob();
assertEquals("ceiling-timer", timer.getName());
- assertEquals(baseDateTest.getTime().getTime(), timer.getDueDate().getTime());
assertNotNull(timer.getDueDate());
+ assertEquals(baseDateTest.getTime(), timer.getDueDate());
}
finally
{
More information about the jbpm-commits
mailing list