[jbpm-commits] JBoss JBPM SVN: r3762 - in jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise: jms and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Feb 4 02:36:06 EST 2009


Author: alex.guizar at jboss.com
Date: 2009-02-04 02:36:06 -0500 (Wed, 04 Feb 2009)
New Revision: 3762

Modified:
   jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/AbstractEnterpriseTestCase.java
   jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/jms/JmsMessageTest.java
Log:
skip process deletion under sybase, seems to cause particular trouble there

Modified: jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/AbstractEnterpriseTestCase.java
===================================================================
--- jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/AbstractEnterpriseTestCase.java	2009-02-04 00:28:27 UTC (rev 3761)
+++ jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/AbstractEnterpriseTestCase.java	2009-02-04 07:36:06 UTC (rev 3762)
@@ -28,14 +28,18 @@
 import javax.jms.Connection;
 import javax.jms.ConnectionFactory;
 import javax.jms.Destination;
+import javax.jms.JMSException;
 import javax.jms.Session;
 import javax.naming.Context;
 import javax.naming.InitialContext;
+import javax.naming.NamingException;
 
 import org.apache.cactus.ServletTestCase;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.hibernate.cfg.Environment;
 import org.jbpm.EventCallback;
+import org.jbpm.JbpmContext;
 import org.jbpm.command.Command;
 import org.jbpm.command.CommandService;
 import org.jbpm.command.DeleteProcessDefinitionCommand;
@@ -46,14 +50,20 @@
 import org.jbpm.ejb.LocalCommandServiceHome;
 import org.jbpm.graph.def.ProcessDefinition;
 import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.persistence.db.DbPersistenceServiceFactory;
+import org.jbpm.svc.Services;
 
 public abstract class AbstractEnterpriseTestCase extends ServletTestCase {
 
   protected CommandService commandService;
 
-  private static LocalCommandServiceHome commandServiceHome;
   private List<ProcessDefinition> processDefinitions = new ArrayList<ProcessDefinition>();
 
+  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);
 
   protected AbstractEnterpriseTestCase() {
@@ -75,13 +85,7 @@
 
   protected CommandService createCommandService() throws Exception {
     if (commandServiceHome == null) {
-      Context initialContext = new InitialContext();
-      try {
-        commandServiceHome = (LocalCommandServiceHome) initialContext.lookup("java:comp/env/ejb/CommandServiceBean");
-      }
-      finally {
-        initialContext.close();
-      }
+      commandServiceHome = lookup("ejb/CommandServiceBean", LocalCommandServiceHome.class);
     }
     return commandServiceHome.create();
   }
@@ -117,26 +121,64 @@
     return processInstance.hasEnded();
   }
 
+  protected 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);
+        return factory.getConfiguration().getProperty(Environment.DIALECT);
+      }
+    });
+  }
+
   private void deleteProcessDefinition(long processDefinitionId) throws Exception {
+    // deleting process definition seems to cause problems in sybase
+    if (getHibernateDialect().contains("Sybase")) {
+      return;
+    }
+
     Command command = new DeleteProcessDefinitionCommand(processDefinitionId);
-    // CleanUpProcessJob races against DeleteProcessDefinitionCommand
-    // JMS has built-in retry logic
-    Context initial = new InitialContext();
+
+    Connection jmsConnection = createJmsConnection();
     try {
-      ConnectionFactory jmsConnectionfactory = (ConnectionFactory) initial.lookup("java:comp/env/jms/JbpmConnectionFactory");
-      Destination commandQueue = (Destination) initial.lookup("java:comp/env/jms/CommandQueue");
+      Session jmsSession = jmsConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      jmsSession.createProducer(getCommandQueue()).send(jmsSession.createObjectMessage(command));
+    }
+    finally {
+      jmsConnection.close();
+    }
+  }
 
-      Connection jmsConnection = jmsConnectionfactory.createConnection();
+  private Destination getCommandQueue() throws NamingException {
+    if (commandQueue == null) {
+      commandQueue = lookup("jms/CommandQueue", Destination.class);
+    }
+    return commandQueue;
+  }
+
+  private Connection createJmsConnection() throws NamingException, JMSException {
+    if (jmsConnectionFactory == null) {
+      jmsConnectionFactory = lookup("jms/JbpmConnectionFactory", ConnectionFactory.class);
+    }
+    return jmsConnectionFactory.createConnection();
+  }
+
+  private static <T> T lookup(String name, Class<T> type) throws NamingException {
+    return type.cast(getEnvironment().lookup(name));
+  }
+
+  private static Context getEnvironment() throws NamingException {
+    if (environment == null) {
+      Context initial = new InitialContext();
       try {
-        Session jmsSession = jmsConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        jmsSession.createProducer(commandQueue).send(jmsSession.createObjectMessage(command));
+        environment = (Context) initial.lookup("java:comp/env");
       }
       finally {
-        jmsConnection.close();
+        initial.close();
       }
     }
-    finally {
-      initial.close();
-    }
+    return environment;
   }
+
 }
\ No newline at end of file

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	2009-02-04 00:28:27 UTC (rev 3761)
+++ jbpm3/trunk/modules/enterprise/src/test/java/org/jbpm/enterprise/jms/JmsMessageTest.java	2009-02-04 07:36:06 UTC (rev 3762)
@@ -23,16 +23,11 @@
 
 import junit.framework.Test;
 
-import org.hibernate.cfg.Environment;
 import org.jboss.bpm.api.test.IntegrationTestSetup;
 import org.jbpm.EventCallback;
-import org.jbpm.JbpmContext;
-import org.jbpm.command.Command;
 import org.jbpm.enterprise.AbstractEnterpriseTestCase;
 import org.jbpm.graph.def.Event;
 import org.jbpm.msg.jms.JmsMessageService;
-import org.jbpm.persistence.db.DbPersistenceServiceFactory;
-import org.jbpm.svc.Services;
 
 /**
  * Exercises for the {@linkplain JmsMessageService JMS message service}.
@@ -129,7 +124,7 @@
 
   public void testAsyncFork() throws Exception {
     // [JBPM-1811] JmsMessageTest fails intermittently on HSQLDB
-    if (getHibernateDialect().indexOf("HSQL") != -1) {
+    if (getHibernateDialect().contains("HSQL")) {
       return;
     }
 
@@ -221,17 +216,6 @@
     }
   }
 
-  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);
-        return factory.getConfiguration().getProperty(Environment.DIALECT);
-      }
-    });
-  }
-
   private boolean waitForProcessInstanceEnd(long processInstanceId) {
     long startTime = System.currentTimeMillis();
     do {




More information about the jbpm-commits mailing list