Author: alex.guizar(a)jboss.com
Date: 2009-01-23 02:13:54 -0500 (Fri, 23 Jan 2009)
New Revision: 3706
Modified:
jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/ejbtimer/EjbSchedulerTest.java
jbpm3/trunk/modules/enterprise/src/test/resources/log4j.xml
Log:
increase time differences in testScheduleFork to decrease deadlock occurrences
reuse existing commands and employ unambiguous names for definition and instance
Modified:
jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/ejbtimer/EjbSchedulerTest.java
===================================================================
---
jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/ejbtimer/EjbSchedulerTest.java 2009-01-23
07:10:21 UTC (rev 3705)
+++
jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/ejbtimer/EjbSchedulerTest.java 2009-01-23
07:13:54 UTC (rev 3706)
@@ -37,6 +37,8 @@
import org.jboss.bpm.api.test.IntegrationTestSetup;
import org.jbpm.command.Command;
import org.jbpm.command.DeployProcessCommand;
+import org.jbpm.command.GetProcessInstanceCommand;
+import org.jbpm.command.SignalCommand;
import org.jbpm.command.StartProcessInstanceCommand;
import org.jbpm.ejb.LocalCommandService;
import org.jbpm.ejb.LocalCommandServiceHome;
@@ -54,7 +56,6 @@
public class EjbSchedulerTest extends ServletTestCase {
private LocalCommandService commandService;
-
private static LocalCommandServiceHome commandServiceHome;
private static final Log log = LogFactory.getLog(EjbSchedulerTest.class);
@@ -67,8 +68,7 @@
if (commandServiceHome == null) {
Context initialContext = new InitialContext();
try {
- commandServiceHome = (LocalCommandServiceHome) initialContext
- .lookup("java:comp/env/ejb/CommandServiceBean");
+ commandServiceHome = (LocalCommandServiceHome)
initialContext.lookup("java:comp/env/ejb/CommandServiceBean");
}
finally {
initialContext.close();
@@ -84,7 +84,7 @@
}
public void testScheduleFuture() throws Exception {
- deployProcess("<process-definition name='future'>"
+ deployProcessDefinition("<process-definition name='future'>"
+ " <event type='process-end'>"
+ " <action
expression='#{eventCallback.processEnd}'/>"
+ " </event>"
@@ -97,13 +97,13 @@
+ " </state>"
+ " <end-state name='end' />"
+ "</process-definition>");
- long processId = launchProcess("future").getId();
+ long processInstanceId = startProcessInstance("future").getId();
EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
- assertTrue(isProcessFinished(processId));
+ assertTrue(hasProcessInstanceEnded(processInstanceId));
}
public void testSchedulePast() throws Exception {
- deployProcess("<process-definition name='past'>"
+ deployProcessDefinition("<process-definition name='past'>"
+ " <event type='process-end'>"
+ " <action
expression='#{eventCallback.processEnd}'/>"
+ " </event>"
@@ -116,13 +116,13 @@
+ " </state>"
+ " <end-state name='end' />"
+ "</process-definition>");
- long processId = launchProcess("past").getId();
+ long processInstanceId = startProcessInstance("past").getId();
EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
- assertTrue(isProcessFinished(processId));
+ assertTrue(hasProcessInstanceEnded(processInstanceId));
}
public void testScheduleRepeat() throws Exception {
- deployProcess("<process-definition name='repeat'>"
+ deployProcessDefinition("<process-definition name='repeat'>"
+ " <event type='timer'>"
+ " <action expression='#{eventCallback.timer}'/>"
+ " </event>"
@@ -135,17 +135,18 @@
+ " </state>"
+ " <end-state name='end' />"
+ "</process-definition>");
- long processId = launchProcess("repeat").getId();
+ ProcessInstance processInstance = startProcessInstance("repeat");
+ long processInstanceId = processInstance.getId();
for (int i = 0; i < 3; i++) {
EventCallback.waitForEvent(Event.EVENTTYPE_TIMER);
- assertEquals("a", getProcessState(processId));
+ assertEquals("a", getProcessInstanceState(processInstanceId));
}
- signalProcess(processId);
- assertTrue(isProcessFinished(processId));
+ signalToken(processInstance.getRootToken().getId());
+ assertTrue(hasProcessInstanceEnded(processInstanceId));
}
public void testCancel() throws Exception {
- deployProcess("<process-definition name='cancel'>"
+ deployProcessDefinition("<process-definition name='cancel'>"
+ " <event type='timer'>"
+ " <action expression='#{eventCallback.timer}'/>"
+ " </event>"
@@ -158,23 +159,26 @@
+ " </state>"
+ " <end-state name='end' />"
+ "</process-definition>");
- ProcessInstance process = launchProcess("cancel");
- long processId = process.getId();
+ ProcessInstance processInstance = startProcessInstance("cancel");
+ long processInstanceId = processInstance.getId();
// first expiration
EventCallback.waitForEvent(Event.EVENTTYPE_TIMER);
- assertEquals("a", getProcessState(processId));
+ assertEquals("a", getProcessInstanceState(processInstanceId));
// repeated expiration
EventCallback.waitForEvent(Event.EVENTTYPE_TIMER);
- assertEquals("a", getProcessState(processId));
+ assertEquals("a", getProcessInstanceState(processInstanceId));
+ // cancel timer
+ long rootTokenId = processInstance.getRootToken().getId();
+ cancelTimer("a", rootTokenId);
// no more expirations
- cancelTimer("a", process.getRootToken().getId());
EventCallback.waitForEvent(Event.EVENTTYPE_TIMER, 2000);
- signalProcess(processId);
- assertTrue(isProcessFinished(processId));
+
+ signalToken(rootTokenId);
+ assertTrue(hasProcessInstanceEnded(processInstanceId));
}
public void testScheduleSequence() throws Exception {
- deployProcess("<process-definition name='sequence'>"
+ deployProcessDefinition("<process-definition
name='sequence'>"
+ " <event type='process-end'>"
+ " <action
expression='#{eventCallback.processEnd}'/>"
+ " </event>"
@@ -206,17 +210,17 @@
+ " </state>"
+ " <end-state name='end' />"
+ "</process-definition>");
- long processId = launchProcess("sequence").getId();
+ long processInstanceId = startProcessInstance("sequence").getId();
for (char state = 'b'; state <= 'e'; state++) {
EventCallback.waitForEvent(Event.EVENTTYPE_TIMER);
- assertEquals(Character.toString(state), getProcessState(processId));
+ assertEquals(Character.toString(state),
getProcessInstanceState(processInstanceId));
}
EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
- assertTrue(isProcessFinished(processId));
+ assertTrue(hasProcessInstanceEnded(processInstanceId));
}
public void testScheduleFork() throws Exception {
- deployProcess("<process-definition name='fork'>"
+ deployProcessDefinition("<process-definition name='fork'>"
+ " <event type='process-end'>"
+ " <action
expression='#{eventCallback.processEnd}'/>"
+ " </event>"
@@ -231,76 +235,64 @@
+ " <transition name='e' to='e' />"
+ " </fork>"
+ " <state name='a'>"
- + " <timer duedate='0.25 seconds' transition='timeout'
/>"
+ + " <timer duedate='0.5 seconds' transition='timeout'
/>"
+ " <transition name='timeout' to='j' />"
+ " </state>"
+ " <state name='b'>"
- + " <timer duedate='0.5 seconds' transition='timeout'
/>"
+ + " <timer duedate='1 second' transition='timeout'
/>"
+ " <transition name='timeout' to='j' />"
+ " </state>"
+ " <state name='c'>"
- + " <timer duedate='0.75 seconds' transition='timeout'
/>"
+ + " <timer duedate='1.5 seconds' transition='timeout'
/>"
+ " <transition name='timeout' to='j' />"
+ " </state>"
+ " <state name='d'>"
- + " <timer duedate='1 second' transition='timeout'
/>"
+ + " <timer duedate='2 seconds' transition='timeout'
/>"
+ " <transition name='timeout' to='j' />"
+ " </state>"
+ " <state name='e'>"
- + " <timer duedate='1.25 second' transition='timeout'
/>"
+ + " <timer duedate='2.5 second' transition='timeout'
/>"
+ " <transition name='timeout' to='j' />"
+ " </state>"
- + " <join name='j' async='exclusive'>"
+ + " <join name='j' async='exclusive'
lock='UPGRADE'>"
+ " <transition to='end' />"
+ " </join>"
+ " <end-state name='end' />"
+ "</process-definition>");
- long processId = launchProcess("fork").getId();
+ long processInstanceId = startProcessInstance("fork").getId();
EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
- assertTrue(isProcessFinished(processId));
+ assertTrue(hasProcessInstanceEnded(processInstanceId));
}
- private ProcessDefinition deployProcess(String xml) throws RemoteException {
+ private ProcessDefinition deployProcessDefinition(String xml) throws RemoteException {
return (ProcessDefinition) commandService.execute(new DeployProcessCommand(xml));
}
- private ProcessInstance launchProcess(String processName) throws RemoteException {
+ private ProcessInstance startProcessInstance(String processName) throws RemoteException
{
StartProcessInstanceCommand command = new StartProcessInstanceCommand();
command.setProcessDefinitionName(processName);
command.setVariables(Collections.singletonMap("eventCallback", new
EventCallback()));
return (ProcessInstance) commandService.execute(command);
}
- private void signalProcess(final long processId) throws RemoteException {
- commandService.execute(new Command() {
- private static final long serialVersionUID = 1L;
-
- public Object execute(JbpmContext jbpmContext) throws Exception {
- jbpmContext.loadProcessInstanceForUpdate(processId).signal();
- return null;
- }
- });
+ private void signalToken(long tokenId) {
+ commandService.execute(new SignalCommand(tokenId, null));
}
- private String getProcessState(final long processId) throws RemoteException {
+ private String getProcessInstanceState(final long processInstanceId) throws
RemoteException {
return (String) commandService.execute(new Command() {
private static final long serialVersionUID = 1L;
public Object execute(JbpmContext jbpmContext) throws Exception {
- return
jbpmContext.loadProcessInstance(processId).getRootToken().getNode().getName();
+ return
jbpmContext.loadProcessInstance(processInstanceId).getRootToken().getNode().getName();
}
});
}
- private boolean isProcessFinished(final long processId) throws RemoteException {
- Boolean isFinished = (Boolean) commandService.execute(new Command() {
- private static final long serialVersionUID = 1L;
-
- public Object execute(JbpmContext jbpmContext) throws Exception {
- return jbpmContext.loadProcessInstance(processId).hasEnded();
- }
- });
- return isFinished.booleanValue();
+ private boolean hasProcessInstanceEnded(final long processInstanceId) throws
RemoteException {
+ ProcessInstance processInstance = (ProcessInstance) commandService.execute(new
GetProcessInstanceCommand(
+ processInstanceId));
+ return processInstance.hasEnded();
}
private void cancelTimer(final String timerName, final long tokenId) throws
RemoteException {
Modified: jbpm3/trunk/modules/enterprise/src/test/resources/log4j.xml
===================================================================
--- jbpm3/trunk/modules/enterprise/src/test/resources/log4j.xml 2009-01-23 07:10:21 UTC
(rev 3705)
+++ jbpm3/trunk/modules/enterprise/src/test/resources/log4j.xml 2009-01-23 07:13:54 UTC
(rev 3706)
@@ -32,10 +32,6 @@
<!-- Limit categories -->
<!-- ================ -->
- <category name="org.jbpm">
- <priority value="DEBUG" />
- </category>
-
<category name="org.hibernate">
<priority value="INFO" />
</category>
@@ -62,6 +58,11 @@
</category>
-->
+ <!-- hide httpclient wire dumps -->
+ <category name="httpclient.wire.header">
+ <priority value="INFO" />
+ </category>
+
<!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->
Show replies by date