[jbpm-commits] JBoss JBPM SVN: r5363 - jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/test/java/org/jbpm/enterprise.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Jul 28 16:41:37 EDT 2009


Author: alex.guizar at jboss.com
Date: 2009-07-28 16:41:37 -0400 (Tue, 28 Jul 2009)
New Revision: 5363

Modified:
   jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/test/java/org/jbpm/enterprise/AbstractEnterpriseTestCase.java
Log:
address intermittent failures in enterprise tests by decorating the command service with a retrier

Modified: jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/test/java/org/jbpm/enterprise/AbstractEnterpriseTestCase.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/test/java/org/jbpm/enterprise/AbstractEnterpriseTestCase.java	2009-07-28 19:57:11 UTC (rev 5362)
+++ jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/test/java/org/jbpm/enterprise/AbstractEnterpriseTestCase.java	2009-07-28 20:41:37 UTC (rev 5363)
@@ -26,10 +26,6 @@
 import java.util.Iterator;
 import java.util.List;
 
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.Destination;
-import javax.jms.Session;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
@@ -38,6 +34,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hibernate.cfg.Environment;
+
 import org.jbpm.JbpmContext;
 import org.jbpm.command.Command;
 import org.jbpm.command.CommandService;
@@ -50,7 +47,9 @@
 import org.jbpm.graph.def.EventCallback;
 import org.jbpm.graph.def.ProcessDefinition;
 import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.persistence.db.DbPersistenceService;
 import org.jbpm.persistence.db.DbPersistenceServiceFactory;
+import org.jbpm.persistence.db.StaleObjectLogConfigurer;
 import org.jbpm.svc.Services;
 
 public abstract class AbstractEnterpriseTestCase extends ServletTestCase {
@@ -61,8 +60,6 @@
 
   private static Context environment;
   private static LocalCommandServiceHome commandServiceHome;
-  private static Destination commandQueue;
-  private static ConnectionFactory jmsConnectionFactory;
 
   private static final Log log = LogFactory.getLog(AbstractEnterpriseTestCase.class);
 
@@ -86,22 +83,22 @@
 
   protected CommandService createCommandService() throws Exception {
     if (commandServiceHome == null) {
-      commandServiceHome = (LocalCommandServiceHome) getEnvironment()
-          .lookup("ejb/CommandServiceBean");
+      commandServiceHome = (LocalCommandServiceHome) getEnvironment().lookup(
+          "ejb/CommandServiceBean");
     }
-    return commandServiceHome.create();
+    return new RetryCommandService(commandServiceHome.create());
   }
 
   protected ProcessDefinition deployProcessDefinition(String xml) {
-    ProcessDefinition processDefinition = (ProcessDefinition) commandService.execute(
-        new DeployProcessCommand(xml));
+    ProcessDefinition processDefinition = (ProcessDefinition) commandService
+        .execute(new DeployProcessCommand(xml));
     processDefinitions.add(processDefinition);
     return processDefinition;
   }
 
   protected ProcessDefinition deployProcessDefinition(byte[] processArchive) {
-    ProcessDefinition processDefinition = (ProcessDefinition) commandService.execute(
-        new DeployProcessCommand(processArchive));
+    ProcessDefinition processDefinition = (ProcessDefinition) commandService
+        .execute(new DeployProcessCommand(processArchive));
     processDefinitions.add(processDefinition);
     return processDefinition;
   }
@@ -118,8 +115,8 @@
   }
 
   protected boolean hasProcessInstanceEnded(final long processInstanceId) {
-    ProcessInstance processInstance = (ProcessInstance) commandService.execute(
-        new GetProcessInstanceCommand(processInstanceId));
+    ProcessInstance processInstance = (ProcessInstance) commandService
+        .execute(new GetProcessInstanceCommand(processInstanceId));
     return processInstance.hasEnded();
   }
 
@@ -147,43 +144,9 @@
   }
 
   private void deleteProcessDefinition(long processDefinitionId) throws Exception {
-    if (true) {
-      // [JBPM-1812] Fix tests that don't cleanup the database
-      // deleting process definition makes subsequent tests unstable
-      return;
-    }
-
-    Connection jmsConnection = getConnectionFactory().createConnection();
-    try {
-      Session jmsSession = jmsConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-      try {
-        Command command = new DeleteProcessDefinitionCommand(processDefinitionId);
-        jmsSession.createProducer(getCommandQueue()).send(jmsSession.createObjectMessage(command));
-      }
-      finally {
-        jmsSession.close();
-      }
-    }
-    finally {
-      jmsConnection.close();
-    }
+    commandService.execute(new DeleteProcessDefinitionCommand(processDefinitionId));
   }
 
-  private Destination getCommandQueue() throws NamingException {
-    if (commandQueue == null) {
-      commandQueue = (Destination) getEnvironment().lookup("jms/CommandQueue");
-    }
-    return commandQueue;
-  }
-
-  private ConnectionFactory getConnectionFactory() throws NamingException {
-    if (jmsConnectionFactory == null) {
-      jmsConnectionFactory = (ConnectionFactory) getEnvironment()
-          .lookup("jms/JbpmConnectionFactory");
-    }
-    return jmsConnectionFactory;
-  }
-
   private static Context getEnvironment() throws NamingException {
     if (environment == null) {
       Context initial = new InitialContext();
@@ -197,4 +160,32 @@
     return environment;
   }
 
+  static final class RetryCommandService implements CommandService {
+
+    private final CommandService delegate;
+
+    RetryCommandService(CommandService delegate) {
+      this.delegate = delegate;
+    }
+
+    public Object execute(Command command) {
+      RuntimeException lockingException = null;
+
+      for (int i = 0; i < 3; i++) {
+        try {
+          return delegate.execute(command);
+        }
+        catch (RuntimeException e) {
+          if (!DbPersistenceService.isLockingException(e)) throw e;
+          // if this is a locking exception, keep it quiet
+          StaleObjectLogConfigurer.getStaleObjectExceptionsLog().error(
+              "failed to execute " + command);
+          lockingException = e;
+        }
+      }
+
+      throw lockingException;
+    }
+  }
+
 }
\ No newline at end of file



More information about the jbpm-commits mailing list