[jbpm-commits] JBoss JBPM SVN: r2185 - in jbpm3/trunk/modules: core/src/main/java/org/jbpm and 14 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Sep 12 03:16:36 EDT 2008
Author: alex.guizar at jboss.com
Date: 2008-09-12 03:16:36 -0400 (Fri, 12 Sep 2008)
New Revision: 2185
Added:
jbpm3/trunk/modules/core/src/main/java/org/jbpm/EventCallback.java
Removed:
jbpm3/trunk/modules/core/src/test/java/org/jbpm/job/executor/EventCallback.java
jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/test/
Modified:
jbpm3/trunk/modules/console/src/main/webapp/WEB-INF/jboss-web.xml
jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java
jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/LockMonitorThread.java
jbpm3/trunk/modules/core/src/main/java/org/jbpm/jpdl/el/impl/JbpmExpressionEvaluator.java
jbpm3/trunk/modules/core/src/main/java/org/jbpm/jpdl/el/impl/JbpmVariableResolver.java
jbpm3/trunk/modules/core/src/main/resources/hibernate.common.xml
jbpm3/trunk/modules/core/src/test/java/org/jbpm/SerializabilityTest.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/enterprise/jar/pom.xml
jbpm3/trunk/modules/enterprise/jar/scripts/antrun-test-jars.xml
jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/ejb/impl/ExecuteJobCommand.java
jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/scheduler/ejbtimer/ExecuteTimerCommand.java
jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/msg/jms/JmsMessageTest.java
jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerTest.java
Log:
[JBPM-1709] moved EventCallback to core jar, so it can be shared between core and enterprise tests
removed enterprise-test.jar
EventCallback move also addresses sporadic class loading exception probably caused by continuously reloading enterprise-test.jar
Modified: jbpm3/trunk/modules/console/src/main/webapp/WEB-INF/jboss-web.xml
===================================================================
--- jbpm3/trunk/modules/console/src/main/webapp/WEB-INF/jboss-web.xml 2008-09-12 07:05:33 UTC (rev 2184)
+++ jbpm3/trunk/modules/console/src/main/webapp/WEB-INF/jboss-web.xml 2008-09-12 07:16:36 UTC (rev 2185)
@@ -21,14 +21,4 @@
<jndi-name>java:JmsXA</jndi-name>
</resource-ref>
- <ejb-local-ref>
- <ejb-ref-name>ejb/TimerEntityBean</ejb-ref-name>
- <local-jndi-name>java:ejb/TimerEntityBean</local-jndi-name>
- </ejb-local-ref>
-
- <message-destination-ref>
- <message-destination-ref-name>jms/JobQueue</message-destination-ref-name>
- <jndi-name>queue/JbpmJobQueue</jndi-name>
- </message-destination-ref>
-
</jboss-web>
Copied: jbpm3/trunk/modules/core/src/main/java/org/jbpm/EventCallback.java (from rev 2154, jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/enterprise/test/EventCallback.java)
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/EventCallback.java (rev 0)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/EventCallback.java 2008-09-12 07:16:36 UTC (rev 2185)
@@ -0,0 +1,118 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm;
+
+import java.io.Serializable;
+
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.jbpm.graph.def.Event;
+
+public class EventCallback implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+ private static final Log log = LogFactory.getLog(EventCallback.class);
+
+ public void processStart() {
+ registerNotification(Event.EVENTTYPE_PROCESS_START);
+ }
+
+ public void processEnd() {
+ registerNotification(Event.EVENTTYPE_PROCESS_END);
+ }
+
+ public void nodeEnter() {
+ registerNotification(Event.EVENTTYPE_NODE_ENTER);
+ }
+
+ public void nodeLeave() {
+ registerNotification(Event.EVENTTYPE_NODE_LEAVE);
+ }
+
+ public void taskCreate() {
+ registerNotification(Event.EVENTTYPE_TASK_CREATE);
+ }
+
+ public void taskEnd() {
+ registerNotification(Event.EVENTTYPE_TASK_END);
+ }
+
+ public void timerCreate() {
+ registerNotification(Event.EVENTTYPE_TIMER_CREATE);
+ }
+
+ public void timer() {
+ registerNotification(Event.EVENTTYPE_TIMER);
+ }
+
+ public void transition() {
+ registerNotification(Event.EVENTTYPE_TRANSITION);
+ }
+
+ private static void registerNotification(final String event) {
+ Synchronization notification = new Synchronization() {
+
+ public void beforeCompletion() {}
+
+ public void afterCompletion(int status) {
+ if (status == Status.STATUS_COMMITTED) {
+ String canonEvent = event.intern();
+ log.debug("notifying " + canonEvent + "@" + Integer.toHexString(System.identityHashCode(canonEvent)));
+ synchronized (canonEvent) {
+ canonEvent.notify();
+ }
+ }
+ }
+
+ };
+ JbpmContext.getCurrentJbpmContext()
+ .getSession()
+ .getTransaction()
+ .registerSynchronization(notification);
+ }
+
+ public static void waitForEvent(String event) {
+ waitForEvent(event, 10000);
+ }
+
+ public static void waitForEvent(String event, long timeout) {
+ String canonEvent = event.intern();
+ long startTime = System.currentTimeMillis();
+ log.debug("waiting for " + canonEvent + "@" + Integer.toHexString(System.identityHashCode(canonEvent)));
+ try {
+ synchronized (canonEvent) {
+ canonEvent.wait(timeout);
+ }
+ }
+ catch (InterruptedException e) {
+ // reassert interruption
+ Thread.currentThread().interrupt();
+ }
+ if (System.currentTimeMillis() - startTime >= timeout) {
+ log.debug("event '" + canonEvent + "' took longer than " + timeout + " ms to occur");
+ }
+ }
+}
\ No newline at end of file
Property changes on: jbpm3/trunk/modules/core/src/main/java/org/jbpm/EventCallback.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java 2008-09-12 07:05:33 UTC (rev 2184)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java 2008-09-12 07:16:36 UTC (rev 2185)
@@ -202,7 +202,17 @@
jobExecutor.addMonitoredJobId(getName(), job.getId());
}
} finally {
- jbpmContext.close();
+ try {
+ jbpmContext.close();
+ } catch (JbpmPersistenceException e) {
+ // if this is a stale object exception, keep it quiet
+ if (Services.isCausedByStaleState(e)) {
+ log.debug("optimistic locking failed, couldn't get next due date");
+ nextDueDate = null;
+ } else {
+ throw e;
+ }
+ }
}
return nextDueDate;
}
@@ -211,10 +221,10 @@
long interval = currentIdleInterval;
Date nextDueDate = getNextDueDate();
if (nextDueDate!=null) {
- long currentTimeMillis = System.currentTimeMillis();
- long nextDueDateTime = nextDueDate.getTime();
- if (nextDueDateTime < currentTimeMillis+currentIdleInterval) {
- interval = nextDueDateTime-currentTimeMillis;
+ long currentTime = System.currentTimeMillis();
+ long nextDueTime = nextDueDate.getTime();
+ if (nextDueTime < currentTime+currentIdleInterval) {
+ interval = nextDueTime-currentTime;
}
}
if (interval<0) {
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/LockMonitorThread.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/LockMonitorThread.java 2008-09-12 07:05:33 UTC (rev 2184)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/job/executor/LockMonitorThread.java 2008-09-12 07:16:36 UTC (rev 2185)
@@ -10,6 +10,8 @@
import org.jbpm.JbpmContext;
import org.jbpm.db.JobSession;
import org.jbpm.job.Job;
+import org.jbpm.persistence.JbpmPersistenceException;
+import org.jbpm.svc.Services;
public class LockMonitorThread extends Thread {
@@ -76,9 +78,13 @@
} finally {
try {
jbpmContext.close();
- } catch (RuntimeException e) {
- log.error("problem committing job execution transaction", e);
- throw e;
+ } catch (JbpmPersistenceException e) {
+ // if this is a stale object exception, keep it quiet
+ if (Services.isCausedByStaleState(e)) {
+ log.debug("optimistic locking failed, couldn't unlock overdue jobs");
+ } else {
+ throw e;
+ }
}
}
}
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/jpdl/el/impl/JbpmExpressionEvaluator.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/jpdl/el/impl/JbpmExpressionEvaluator.java 2008-09-12 07:05:33 UTC (rev 2184)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/jpdl/el/impl/JbpmExpressionEvaluator.java 2008-09-12 07:16:36 UTC (rev 2185)
@@ -49,16 +49,15 @@
}
static String translateExpressionToDollars(String expression) {
- char[] chars = expression.toCharArray();
- int index = 0;
- while (index!=-1) {
- index = expression.indexOf("#{", index);
- if (index!=-1) {
- chars[index] = '$';
- index++;
- }
- }
- return new String(chars);
+ int hashIndex = expression.indexOf("#{");
+ if (hashIndex == -1) return expression;
+
+ char[] expressionChars = expression.toCharArray();
+ do {
+ expressionChars[hashIndex] = '$';
+ hashIndex = expression.indexOf("#{", hashIndex + 2);
+ } while (hashIndex != -1);
+ return new String(expressionChars);
}
public static VariableResolver getUsedVariableResolver() {
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/jpdl/el/impl/JbpmVariableResolver.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/jpdl/el/impl/JbpmVariableResolver.java 2008-09-12 07:05:33 UTC (rev 2184)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/jpdl/el/impl/JbpmVariableResolver.java 2008-09-12 07:16:36 UTC (rev 2185)
@@ -61,11 +61,6 @@
SwimlaneInstance swimlaneInstance = taskMgmtInstance.getSwimlaneInstance(name);
value = (swimlaneInstance!=null ? swimlaneInstance.getActorId() : null);
- } else if ( (contextInstance!=null)
- && (contextInstance.hasTransientVariable(name))
- ) {
- value = contextInstance.getTransientVariable(name);
-
} else if (JbpmConfiguration.Configs.hasObject(name)) {
value = JbpmConfiguration.Configs.getObject(name);
}
Modified: jbpm3/trunk/modules/core/src/main/resources/hibernate.common.xml
===================================================================
--- jbpm3/trunk/modules/core/src/main/resources/hibernate.common.xml 2008-09-12 07:05:33 UTC (rev 2184)
+++ jbpm3/trunk/modules/core/src/main/resources/hibernate.common.xml 2008-09-12 07:16:36 UTC (rev 2185)
@@ -17,9 +17,10 @@
<!-- # common settings # -->
<!-- ################################### -->
- <!-- Create schema on demand -->
+ <!-- Automatic schema creation (begin) -->
<property name="hibernate.hbm2ddl.auto">create</property>
-
+ <!-- Automatic schema creation (end) -->
+
<!-- Simple memory-only cache -->
<property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/SerializabilityTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/SerializabilityTest.java 2008-09-12 07:05:33 UTC (rev 2184)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/SerializabilityTest.java 2008-09-12 07:16:36 UTC (rev 2185)
@@ -116,7 +116,8 @@
"org.jbpm.util.CustomLoaderObjectInputStream",
"org.jbpm.web.JobExecutorLauncher",
"org.jbpm.web.JbpmConfigurationCloser",
- "org.jbpm.JbpmContextTestHelper"
+ "org.jbpm.JbpmContextTestHelper",
+ "org.jbpm.EventCallback$1"
}));
public void testForNonSerializableClasses() {
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-09-12 07:05:33 UTC (rev 2184)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1072/JBPM1072Test.java 2008-09-12 07:16:36 UTC (rev 2185)
@@ -4,6 +4,7 @@
import junit.framework.TestCase;
+import org.jbpm.EventCallback;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.graph.def.ActionHandler;
@@ -11,7 +12,6 @@
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.graph.exe.ProcessInstance;
-import org.jbpm.job.executor.EventCallback;
import org.jbpm.job.executor.JobExecutor;
/**
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-09-12 07:05:33 UTC (rev 2184)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1135/JBPM1135Test.java 2008-09-12 07:16:36 UTC (rev 2185)
@@ -21,11 +21,11 @@
*/
package org.jbpm.jbpm1135;
+import org.jbpm.EventCallback;
import org.jbpm.db.AbstractDbTestCase;
import org.jbpm.graph.def.Event;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
-import org.jbpm.job.executor.EventCallback;
/**
* JobSession.deleteJobsForProcessInstance doesn't work if jbpm isn't the transaction manager
Deleted: jbpm3/trunk/modules/core/src/test/java/org/jbpm/job/executor/EventCallback.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/job/executor/EventCallback.java 2008-09-12 07:05:33 UTC (rev 2184)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/job/executor/EventCallback.java 2008-09-12 07:16:36 UTC (rev 2185)
@@ -1,105 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jbpm.job.executor;
-
-import java.io.Serializable;
-
-import javax.transaction.Status;
-import javax.transaction.Synchronization;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jbpm.JbpmContext;
-import org.jbpm.graph.def.Event;
-
-public class EventCallback implements Serializable {
-
- private static final long serialVersionUID = 1L;
- private static final Log log = LogFactory.getLog(EventCallback.class);
-
- public void processStart() {
- registerNotification(Event.EVENTTYPE_PROCESS_START);
- }
-
- public void processEnd() {
- registerNotification(Event.EVENTTYPE_PROCESS_END);
- }
-
- public void nodeEnter() {
- registerNotification(Event.EVENTTYPE_NODE_ENTER);
- }
-
- public void nodeLeave() {
- registerNotification(Event.EVENTTYPE_NODE_LEAVE);
- }
-
- public void taskCreate() {
- registerNotification(Event.EVENTTYPE_TASK_CREATE);
- }
-
- public void taskEnd() {
- registerNotification(Event.EVENTTYPE_TASK_END);
- }
-
- public void timerCreate() {
- registerNotification(Event.EVENTTYPE_TIMER_CREATE);
- }
-
- public void timer() {
- registerNotification(Event.EVENTTYPE_TIMER);
- }
-
- private static void registerNotification(final String event) {
- Synchronization notification = new Synchronization() {
-
- public void beforeCompletion() {
- // nothing to do here
- }
-
- public void afterCompletion(int status) {
- if (status == Status.STATUS_COMMITTED) {
- log.info("delivering " + event + " notification");
- synchronized (event) {
- event.notify();
- }
- }
- }
-
- };
- JbpmContext.getCurrentJbpmContext()
- .getSession()
- .getTransaction()
- .registerSynchronization(notification);
- }
-
- public static void waitForEvent(String event) {
- synchronized (event) {
- try {
- event.wait(30000);
- }
- catch (InterruptedException e) {
- // reassert interruption
- Thread.currentThread().interrupt();
- }
- }
- }
-}
\ No newline at end of file
Modified: jbpm3/trunk/modules/enterprise/jar/pom.xml
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/pom.xml 2008-09-12 07:05:33 UTC (rev 2184)
+++ jbpm3/trunk/modules/enterprise/jar/pom.xml 2008-09-12 07:16:36 UTC (rev 2185)
@@ -166,14 +166,6 @@
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <excludes>
- <!-- https://jira.jboss.org/jira/browse/JBPM-1708 -->
- <exclude>org/jbpm/scheduler/ejbtimer/EjbSchedulerTest.java</exclude>
- <!-- https://jira.jboss.org/jira/browse/JBPM-1709 -->
- <exclude>org/jbpm/msg/jms/AsyncProcessingTest.java</exclude>
- </excludes>
- </configuration>
</plugin>
</plugins>
</build>
Modified: jbpm3/trunk/modules/enterprise/jar/scripts/antrun-test-jars.xml
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/scripts/antrun-test-jars.xml 2008-09-12 07:05:33 UTC (rev 2184)
+++ jbpm3/trunk/modules/enterprise/jar/scripts/antrun-test-jars.xml 2008-09-12 07:16:36 UTC (rev 2185)
@@ -22,10 +22,7 @@
<!-- enterprise-test -->
<war warfile="${tests.output.dir}/test-libs/enterprise-test.war" webxml="${tests.resources.dir}/WEB-INF/web.xml">
- <classes dir="${tests.output.dir}/test-classes">
- <include name="org/jbpm/**" />
- <exclude name="org/jbpm/enterprise/test/**" />
- </classes>
+ <classes dir="${tests.output.dir}/test-classes" />
<lib dir="${tests.output.dir}/test-dependencies">
<include name="aspectjrt*.jar"/>
<include name="cactus*.jar"/>
@@ -36,12 +33,6 @@
</webinf>
</war>
- <jar destfile="${tests.output.dir}/test-libs/enterprise-test.jar">
- <fileset dir="${tests.output.dir}/test-classes">
- <include name="org/jbpm/enterprise/test/**" />
- </fileset>
- </jar>
-
<!-- Please add alphabetically -->
</target>
Modified: jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/ejb/impl/ExecuteJobCommand.java
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/ejb/impl/ExecuteJobCommand.java 2008-09-12 07:05:33 UTC (rev 2184)
+++ jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/ejb/impl/ExecuteJobCommand.java 2008-09-12 07:16:36 UTC (rev 2185)
@@ -30,11 +30,17 @@
jobSession.deleteJob(job);
}
}
+ catch (RuntimeException e) {
+ // nothing to do but clean up and exit
+ throw e;
+ }
catch (Exception e) {
- log.debug("exception while executing " + job, e);
+ // save data about recoverable error condition
+ log.error("exception while executing " + job, e);
StringWriter memoryWriter = new StringWriter();
e.printStackTrace(new PrintWriter(memoryWriter));
job.setException(memoryWriter.toString());
+ job.setRetries(job.getRetries() - 1);
}
return job;
}
Modified: jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/scheduler/ejbtimer/ExecuteTimerCommand.java
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/scheduler/ejbtimer/ExecuteTimerCommand.java 2008-09-12 07:05:33 UTC (rev 2184)
+++ jbpm3/trunk/modules/enterprise/jar/src/main/java/org/jbpm/scheduler/ejbtimer/ExecuteTimerCommand.java 2008-09-12 07:16:36 UTC (rev 2185)
@@ -7,7 +7,6 @@
import org.apache.commons.logging.LogFactory;
import org.jbpm.JbpmContext;
import org.jbpm.command.Command;
-import org.jbpm.db.JobSession;
import org.jbpm.job.Timer;
public class ExecuteTimerCommand implements Command {
@@ -21,8 +20,7 @@
}
public Object execute(JbpmContext jbpmContext) throws Exception {
- JobSession jobSession = jbpmContext.getJobSession();
- Timer timer = jobSession.loadTimer(timerId);
+ Timer timer = jbpmContext.getJobSession().loadTimer(timerId);
timer.setLockOwner(getClass().getName()); // prevent others from removing timer
log.debug("executing " + timer);
try {
@@ -30,11 +28,17 @@
jbpmContext.getServices().getSchedulerService().deleteTimer(timer);
}
}
+ catch (RuntimeException e) {
+ // nothing to do but clean up and exit
+ throw e;
+ }
catch (Exception e) {
- log.debug("exception while executing " + timer, e);
+ // save data about recoverable error condition
+ log.error("exception while executing " + timer, e);
StringWriter memoryWriter = new StringWriter();
e.printStackTrace(new PrintWriter(memoryWriter));
timer.setException(memoryWriter.toString());
+ timer.setRetries(timer.getRetries() - 1);
}
return timer;
}
Modified: jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/msg/jms/JmsMessageTest.java
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/msg/jms/JmsMessageTest.java 2008-09-12 07:05:33 UTC (rev 2184)
+++ jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/msg/jms/JmsMessageTest.java 2008-09-12 07:16:36 UTC (rev 2185)
@@ -22,11 +22,6 @@
package org.jbpm.msg.jms;
import java.util.Collections;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.TreeSet;
import javax.naming.Context;
import javax.naming.InitialContext;
@@ -37,6 +32,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jbpm.EventCallback;
import org.jbpm.IntegrationTestSetup;
import org.jbpm.JbpmContext;
import org.jbpm.command.Command;
@@ -44,9 +40,6 @@
import org.jbpm.command.StartProcessInstanceCommand;
import org.jbpm.ejb.LocalCommandService;
import org.jbpm.ejb.LocalCommandServiceHome;
-import org.jbpm.enterprise.test.ActionRecorder;
-import org.jbpm.enterprise.test.EventCallback;
-import org.jbpm.enterprise.test.Recorder;
import org.jbpm.graph.def.Event;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
@@ -65,7 +58,7 @@
static final int maxWaitTime = 30000;
public static Test suite() throws Exception {
- return new IntegrationTestSetup(JmsMessageTest.class, "enterprise-test.war, enterprise-test.jar");
+ return new IntegrationTestSetup(JmsMessageTest.class, "enterprise-test.war");
}
protected void setUp() throws Exception {
@@ -102,32 +95,32 @@
+ "</process-definition>");
long processId = launchProcess("node").getId();
EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
- assertTrue(isProcessFinished(processId));
+ assertTrue(hasProcessEnded(processId));
}
public void testAsyncAction() {
- Recorder.resetCollections();
- deleteAllJobs();
deployProcess("<process-definition name='action'>"
- + " <event type='process-end'>"
- + " <action expression='#{eventCallback.processEnd}'/>"
- + " </event>"
+ " <start-state name='start'>"
+ " <transition to='a' />"
+ " </start-state>"
+ " <node name='a'>"
+ " <event type='node-enter'>"
- + " <action name='X' async='true' class='" + ActionRecorder.class.getName() + "' />"
+ + " <action async='true' expression='#{eventCallback.nodeEnter}' />"
+ " </event>"
- + " <transition to='end' />"
+ + " <event type='node-leave'>"
+ + " <action async='true' expression='#{eventCallback.nodeLeave}' />"
+ + " </event>"
+ + " <transition to='end'>"
+ + " <action async='true' expression='#{eventCallback.transition}' />"
+ + " </transition>"
+ " </node>"
+ " <end-state name='end' />"
+ "</process-definition>");
long processId = launchProcess("action").getId();
- assertTrue(isProcessFinished(processId));
- // action continues in the background
- processAllJobs(maxWaitTime);
- assertEquals(Collections.singleton(processId + "X"), Recorder.collectedResults);
+ EventCallback.waitForEvent(Event.EVENTTYPE_NODE_ENTER);
+ EventCallback.waitForEvent(Event.EVENTTYPE_NODE_LEAVE);
+ EventCallback.waitForEvent(Event.EVENTTYPE_TRANSITION);
+ assertTrue(hasProcessEnded(processId));
}
public void testAsyncSequence() {
@@ -157,7 +150,7 @@
+ "</process-definition>");
long processId = launchProcess("sequence").getId();
EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
- assertTrue(isProcessFinished(processId));
+ assertTrue(hasProcessEnded(processId));
}
public void testAsyncFork() {
@@ -197,62 +190,48 @@
+ "</process-definition>");
long processId = launchProcess("fork").getId();
EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
- assertTrue(isProcessFinished(processId));
+ assertTrue(hasProcessEnded(processId));
}
public void testAsyncExecutions() {
- Recorder.resetCollections();
- deleteAllJobs();
- deployProcess("<process-definition name='executions'>" +
- " <start-state>" +
- " <transition to='a' />" +
- " </start-state>" +
- " <node name='a' async='true'>" +
- " <action class='"+Recorder.class.getName()+"' />" +
- " <transition to='b' />" +
- " </node>" +
- " <node name='b' async='true'>" +
- " <event type='node-enter'>" +
- " <action name='X' async='true' class='"+ActionRecorder.class.getName()+"' />" +
- " </event>" +
- " <action class='"+Recorder.class.getName()+"' />" +
- " <transition to='c' />" +
- " </node>" +
- " <node name='c' async='true'>" +
- " <action class='"+Recorder.class.getName()+"' />" +
- " <transition to='d'>" +
- " <action name='Y' async='true' class='"+ActionRecorder.class.getName()+"' />" +
- " </transition>" +
- " </node>" +
- " <node name='d' async='true'>" +
- " <action class='"+Recorder.class.getName()+"' />" +
- " <transition to='e' />" +
- " <event type='node-leave'>" +
- " <action name='Z' async='true' class='"+ActionRecorder.class.getName()+"' />" +
- " </event>" +
- " </node>" +
- " <node name='e' async='true'>" +
- " <action class='"+Recorder.class.getName()+"' />" +
- " <transition to='end' />" +
- " </node>" +
- " <end-state name='end'/>" +
- "</process-definition>");
- launchProcesses("executions");
- processAllJobs(maxWaitTime);
- Set expectedResults = new TreeSet();
- for (Iterator i = Recorder.collectedProcessInstanceIds.iterator(); i.hasNext();) {
- Long processInstanceId = (Long) i.next();
- expectedResults.add(processInstanceId+"a");
- expectedResults.add(processInstanceId+"b");
- expectedResults.add(processInstanceId+"c");
- expectedResults.add(processInstanceId+"d");
- expectedResults.add(processInstanceId+"e");
- expectedResults.add(processInstanceId+"X");
- expectedResults.add(processInstanceId+"Y");
- expectedResults.add(processInstanceId+"Z");
+ deployProcess("<process-definition name='execution'>"
+ + " <event type='process-end'>"
+ + " <action expression='#{eventCallback.processEnd}' />"
+ + " </event>"
+ + " <start-state>"
+ + " <transition to='a' />"
+ + " </start-state>"
+ + " <node name='a' async='true'>"
+ + " <transition to='b' />"
+ + " </node>"
+ + " <node name='b'>"
+ + " <event type='node-enter'>"
+ + " <action async='true' expression='#{eventCallback.nodeEnter}' />"
+ + " </event>"
+ + " <transition to='c' />"
+ + " </node>"
+ + " <node name='c' async='true'>"
+ + " <transition to='d' />"
+ + " </node>"
+ + " <node name='d'>"
+ + " <transition to='e' />"
+ + " <event type='node-leave'>"
+ + " <action async='true' expression='#{eventCallback.nodeLeave}' />"
+ + " </event>"
+ + " </node>"
+ + " <node name='e' async='true'>"
+ + " <transition to='end' />"
+ + " </node>"
+ + " <end-state name='end' />"
+ + "</process-definition>");
+ long[] processIds = new long[processExecutionCount];
+ for (int i = 0; i < processExecutionCount; i++) {
+ processIds[i] = launchProcess("execution").getId();
}
- assertEquals(processExecutionCount, Recorder.collectedProcessInstanceIds.size());
- assertEquals(expectedResults, Recorder.collectedResults);
+ for (int i = 0; i < processExecutionCount; i++) {
+ waitForProcessEnd(processIds[i]);
+ assertTrue(hasProcessEnded(processIds[i]));
+ }
}
private ProcessDefinition deployProcess(String xml) {
@@ -266,13 +245,7 @@
return (ProcessInstance) commandService.execute(command);
}
- private void launchProcesses(String processName) {
- for (int i=0; i<processExecutionCount; i++) {
- launchProcess(processName);
- }
- }
-
- private boolean isProcessFinished(final long processId) {
+ private boolean hasProcessEnded(final long processId) {
Boolean isFinished = (Boolean) commandService.execute(new Command() {
private static final long serialVersionUID = 1L;
public Object execute(JbpmContext jbpmContext) throws Exception {
@@ -282,57 +255,16 @@
return isFinished.booleanValue();
}
- private void deleteAllJobs() {
- commandService.execute(new Command() {
- private static final long serialVersionUID = 1L;
- public Object execute(JbpmContext jbpmContext) throws Exception {
- int jobCount = jbpmContext.getSession()
- .createQuery("delete from org.jbpm.job.Job")
- .executeUpdate();
- log.debug(jobCount + " jobs deleted");
- return null;
+ private void waitForProcessEnd(long processId) {
+ long startTime = System.currentTimeMillis();
+ while (!hasProcessEnded(processId)) {
+ if (System.currentTimeMillis() - startTime > maxWaitTime) {
+ log.warn("process " + processId + " took too long");
+ break;
}
- });
- }
-
- private void processAllJobs(long maxWait) {
- // 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: interrupting...");
- testThread.interrupt();
- }
- };
- Timer timer = new Timer();
- timer.schedule(interruptTask, maxWait);
-
- try {
- while (getAvailableJobCount() > 0) {
- log.debug("waiting for job listener to process more jobs");
- Thread.sleep(200);
- }
- } catch (InterruptedException e) {
- fail("test execution exceeded treshold of "+maxWait+" milliseconds");
- } finally {
- timer.cancel();
+ EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END, 500);
}
}
- private int getAvailableJobCount() {
- Number jobCount = (Number) commandService.execute(new Command() {
- private static final long serialVersionUID = 1L;
- public Object execute(JbpmContext jbpmContext) throws Exception {
- Object jobCount = jbpmContext.getSession()
- .createQuery("select count(*) from org.jbpm.job.Job")
- .uniqueResult();
- log.debug(jobCount + " jobs remaining");
- return jobCount;
- }
- });
- return jobCount.intValue();
- }
-
private static Log log = LogFactory.getLog(JmsMessageTest.class);
}
Modified: jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerTest.java
===================================================================
--- jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerTest.java 2008-09-12 07:05:33 UTC (rev 2184)
+++ jbpm3/trunk/modules/enterprise/jar/src/test/java/org/jbpm/scheduler/ejbtimer/EjbSchedulerTest.java 2008-09-12 07:16:36 UTC (rev 2185)
@@ -32,6 +32,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jbpm.EventCallback;
import org.jbpm.IntegrationTestSetup;
import org.jbpm.JbpmContext;
import org.jbpm.command.Command;
@@ -39,7 +40,6 @@
import org.jbpm.command.StartProcessInstanceCommand;
import org.jbpm.ejb.LocalCommandService;
import org.jbpm.ejb.LocalCommandServiceHome;
-import org.jbpm.enterprise.test.EventCallback;
import org.jbpm.graph.def.Event;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
@@ -58,8 +58,7 @@
private static final Log log = LogFactory.getLog(EjbSchedulerTest.class);
public static Test suite() throws Exception {
- return new IntegrationTestSetup(EjbSchedulerTest.class,
- "enterprise-test.war, enterprise-test.jar");
+ return new IntegrationTestSetup(EjbSchedulerTest.class, "enterprise-test.war");
}
protected void setUp() throws Exception {
More information about the jbpm-commits
mailing list