[jbpm-commits] JBoss JBPM SVN: r3439 - jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/jms.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Dec 19 04:06:20 EST 2008


Author: thomas.diesler at jboss.com
Date: 2008-12-19 04:06:20 -0500 (Fri, 19 Dec 2008)
New Revision: 3439

Modified:
   jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/jms/JmsMessageTest.java
Log:
[JBPM-1811] JmsMessageTest fails intermitently on HSQLDB

Modified: jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/jms/JmsMessageTest.java
===================================================================
--- jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/jms/JmsMessageTest.java	2008-12-19 09:06:06 UTC (rev 3438)
+++ jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/jms/JmsMessageTest.java	2008-12-19 09:06:20 UTC (rev 3439)
@@ -52,8 +52,10 @@
  * 
  * @author Alejandro Guizar
  */
-public class JmsMessageTest extends ServletTestCase {
-
+public class JmsMessageTest extends ServletTestCase 
+{
+  private static Log log = LogFactory.getLog(JmsMessageTest.class);
+  
   private LocalCommandService commandService;
 
   private static LocalCommandServiceHome commandServiceHome;
@@ -61,17 +63,22 @@
   static final int processExecutionCount = 5;
   static final int maxWaitTime = 10 * 1000;
 
-  public static Test suite() throws Exception {
+  public static Test suite() throws Exception
+  {
     return new IntegrationTestSetup(JmsMessageTest.class, "enterprise-test.war");
   }
 
-  protected void setUp() throws Exception {
-    if (commandServiceHome == null) {
+  protected void setUp() throws Exception
+  {
+    if (commandServiceHome == null)
+    {
       Context initialContext = new InitialContext();
-      try {
-        commandServiceHome = (LocalCommandServiceHome) initialContext
-            .lookup("java:comp/env/ejb/CommandServiceBean");
-      } finally {
+      try
+      {
+        commandServiceHome = (LocalCommandServiceHome)initialContext.lookup("java:comp/env/ejb/CommandServiceBean");
+      }
+      finally
+      {
         initialContext.close();
       }
     }
@@ -79,13 +86,15 @@
     log.info("### " + getName() + " started ###");
   }
 
-  protected void tearDown() throws Exception {
+  protected void tearDown() throws Exception
+  {
     log.info("### " + getName() + " done ###");
     commandService = null;
     EventCallback.clear();
   }
 
-  public void testAsyncNode() {
+  public void testAsyncNode() 
+  {
     deployProcess("<process-definition name='node'>"
         + "  <event type='process-end'>"
         + "    <action expression='#{eventCallback.processEnd}'/>"
@@ -98,12 +107,14 @@
         + "  </node>"
         + "  <end-state name='end' />"
         + "</process-definition>");
+    
     long processId = launchProcess("node").getId();
     EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
     assertTrue("Process has ended", hasProcessEnded(processId));
   }
 
-  public void testAsyncAction() {
+  public void testAsyncAction() 
+  {
     deployProcess("<process-definition name='action'>"
         + "  <start-state name='start'>"
         + "    <transition to='a' />"
@@ -121,6 +132,7 @@
         + "  </node>"
         + "  <end-state name='end' />"
         + "</process-definition>");
+    
     long processId = launchProcess("action").getId();
     EventCallback.waitForEvent(Event.EVENTTYPE_NODE_ENTER);
     EventCallback.waitForEvent(Event.EVENTTYPE_NODE_LEAVE);
@@ -128,7 +140,8 @@
     assertTrue("Process has ended", hasProcessEnded(processId));
   }
 
-  public void testAsyncSequence() {
+  public void testAsyncSequence() 
+  {
     deployProcess("<process-definition name='sequence'>"
         + "  <event type='process-end'>"
         + "    <action expression='#{eventCallback.processEnd}'/>"
@@ -153,14 +166,17 @@
         + "  </node>"
         + "  <end-state name='end' />"
         + "</process-definition>");
+    
     long processId = launchProcess("sequence").getId();
     EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
     assertTrue("Process has ended", hasProcessEnded(processId));
   }
 
-  public void testAsyncFork() throws Exception {
-    if (getDialect().indexOf("HSQL") != -1) {
-      // [JBPM-1811] JmsMessageTest fails intermittently on HSQLDB
+  public void testAsyncFork() throws Exception 
+  {
+    // [JBPM-1811] JmsMessageTest fails intermittently on HSQLDB
+    if (getHibernateDialect().indexOf("HSQL") != -1) 
+    {
       return;
     }
 
@@ -198,24 +214,29 @@
         + "  </join>"
         + "  <end-state name='end' />"
         + "</process-definition>");
+    
     long processId = launchProcess("fork").getId();
     EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
     Thread.sleep(1000);
     assertTrue("Process has ended", hasProcessEnded(processId));
   }
 
-  private String getDialect() {
-    return (String) commandService.execute(new Command() {
+  private String getHibernateDialect()
+  {
+    return (String)commandService.execute(new Command()
+    {
       private static final long serialVersionUID = 1L;
 
-      public Object execute(JbpmContext jbpmContext) throws Exception {
-        DbPersistenceServiceFactory factory = (DbPersistenceServiceFactory) jbpmContext.getServiceFactory(Services.SERVICENAME_PERSISTENCE);
+      public Object execute(JbpmContext jbpmContext) throws Exception
+      {
+        DbPersistenceServiceFactory factory = (DbPersistenceServiceFactory)jbpmContext.getServiceFactory(Services.SERVICENAME_PERSISTENCE);
         return factory.getConfiguration().getProperty(Environment.DIALECT);
-      }      
+      }
     });
   }
 
-  public void testAsyncExecutions() {
+  public void testAsyncExecutions() 
+  {
     deployProcess("<process-definition name='execution'>"
         + "  <event type='process-end'>"
         + "    <action expression='#{eventCallback.processEnd}' />"
@@ -246,53 +267,63 @@
         + "  </node>"
         + "  <end-state name='end' />"
         + "</process-definition>");
+    
     long[] processIds = new long[processExecutionCount];
-    for (int i = 0; i < processExecutionCount; i++) {
+    for (int i = 0; i < processExecutionCount; i++)
+    {
       processIds[i] = launchProcess("execution").getId();
       EventCallback.waitForEvent(Event.EVENTTYPE_NODE_ENTER);
     }
-    for (int i = 0; i < processExecutionCount; i++) {
+    for (int i = 0; i < processExecutionCount; i++)
+    {
       EventCallback.waitForEvent(Event.EVENTTYPE_NODE_LEAVE);
     }
-    for (int i = 0; i < processExecutionCount; i++) {
+    for (int i = 0; i < processExecutionCount; i++)
+    {
       waitForProcessEnd(processIds[i]);
       assertTrue(hasProcessEnded(processIds[i]));
     }
   }
 
-  private ProcessDefinition deployProcess(String xml) {
-    return (ProcessDefinition) commandService.execute(new DeployProcessCommand(xml));
+  private ProcessDefinition deployProcess(String xml)
+  {
+    return (ProcessDefinition)commandService.execute(new DeployProcessCommand(xml));
   }
 
-  private ProcessInstance launchProcess(String processName) {
+  private ProcessInstance launchProcess(String processName)
+  {
     StartProcessInstanceCommand command = new StartProcessInstanceCommand();
     command.setProcessDefinitionName(processName);
-    command.setVariables(Collections.singletonMap("eventCallback",
-        new EventCallback()));
-    return (ProcessInstance) commandService.execute(command);
+    command.setVariables(Collections.singletonMap("eventCallback", new EventCallback()));
+    return (ProcessInstance)commandService.execute(command);
   }
 
-  private boolean hasProcessEnded(final long processId) {
-    Boolean isFinished = (Boolean) commandService.execute(new Command() {
+  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 {
+      public Object execute(JbpmContext jbpmContext) throws Exception
+      {
         return jbpmContext.loadProcessInstance(processId).hasEnded();
       }
     });
     return isFinished.booleanValue();
   }
 
-  private void waitForProcessEnd(long processId) {
+  private void waitForProcessEnd(long processId)
+  {
     long startTime = System.currentTimeMillis();
-    do {
+    do
+    {
       EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END, 1000);
-      if (System.currentTimeMillis() - startTime > maxWaitTime) {
+      if (System.currentTimeMillis() - startTime > maxWaitTime)
+      {
         log.warn("process " + processId + " took too long");
         break;
       }
-    } while (!hasProcessEnded(processId));
+    }
+    while (!hasProcessEnded(processId));
   }
-
-  private static Log log = LogFactory.getLog(JmsMessageTest.class);
 }




More information about the jbpm-commits mailing list