[jbpm-commits] JBoss JBPM SVN: r2563 - in jbpm3/trunk/modules/core/src: main/java/org/jbpm/logging/log and 5 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Oct 21 07:42:08 EDT 2008


Author: tom.baeyens at jboss.com
Date: 2008-10-21 07:42:08 -0400 (Tue, 21 Oct 2008)
New Revision: 2563

Modified:
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/GraphSession.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/JbpmSchema.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/logging/log/ProcessLog.java
   jbpm3/trunk/modules/core/src/main/resources/hibernate.common.xml
   jbpm3/trunk/modules/core/src/main/resources/org/jbpm/db/hibernate.queries.hbm.xml
   jbpm3/trunk/modules/core/src/main/resources/org/jbpm/graph/log/ActionLog.hbm.xml
   jbpm3/trunk/modules/core/src/main/resources/org/jbpm/graph/log/SignalLog.hbm.xml
   jbpm3/trunk/modules/core/src/main/resources/org/jbpm/graph/log/TransitionLog.hbm.xml
   jbpm3/trunk/modules/core/src/test/java/org/jbpm/graph/node/ProcessStateDbTest.java
   jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1452/JBPM1452Test.java
Log:
[JBPM-1735] Cleanup ProcessStateDbTest

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java	2008-10-21 08:46:20 UTC (rev 2562)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/AbstractDbTestCase.java	2008-10-21 11:42:08 UTC (rev 2563)
@@ -21,12 +21,16 @@
  */
 package org.jbpm.db;
 
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 import java.util.Timer;
 import java.util.TimerTask;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hibernate.Session;
+import org.hibernate.cfg.Configuration;
 import org.hibernate.tool.hbm2ddl.SchemaExport;
 import org.jbpm.AbstractJbpmTestCase;
 import org.jbpm.JbpmConfiguration;
@@ -37,13 +41,15 @@
 import org.jbpm.job.Job;
 import org.jbpm.job.executor.JobExecutor;
 import org.jbpm.logging.log.ProcessLog;
+import org.jbpm.persistence.db.DbPersistenceService;
+import org.jbpm.persistence.db.DbPersistenceServiceFactory;
 import org.jbpm.taskmgmt.exe.TaskInstance;
 
 public abstract class AbstractDbTestCase extends AbstractJbpmTestCase
 {
   private static Log log = LogFactory.getLog(AbstractDbTestCase.class);
 
-  private JbpmConfiguration jbpmConfiguration;
+  protected JbpmConfiguration jbpmConfiguration;
 
   protected JbpmContext jbpmContext;
   protected SchemaExport schemaExport;
@@ -68,55 +74,37 @@
   {
     resetMembers();
     closeJbpmContext();
+    ensureCleanDatabase();
     
-    if (hasLeftOverRecords())
-    {
-      dropSchema();
-      // Failing here, will probably hide a potential previous failure.
-      // Is there a better way to fail without hiding a potential cause?
-      fail("Test failed to cleanup database records");
-    }
-    
     super.tearDown();
   }
 
-  private boolean hasLeftOverRecords()
+  private void ensureCleanDatabase()
   {
-    boolean foundLeftOvers = false;
-    JbpmContext jbpmContext = getJbpmConfiguration().createJbpmContext();
-    Session session = jbpmContext.getSession();
-    try
-    {
-      if (session.createQuery("from " + ProcessDefinition.class.getName()).list().size() > 0)
-      {
-        System.err.println("FIXME: left over ProcessDefinition after: " + getShortName());
-        foundLeftOvers = true;
+    boolean hasLeftOvers = false;
+    
+    DbPersistenceServiceFactory dbPersistenceServiceFactory = (DbPersistenceServiceFactory) getJbpmConfiguration().getServiceFactory("persistence");
+    Configuration configuration = dbPersistenceServiceFactory.getConfiguration();
+    JbpmSchema jbpmSchema = new JbpmSchema(configuration);
+    
+    Map jbpmTablesRecordCount = jbpmSchema.getJbpmTablesRecordCount();
+    Iterator iter = jbpmTablesRecordCount.entrySet().iterator();
+    while (iter.hasNext()) {
+      Map.Entry entry = (Map.Entry) iter.next();
+      String tableName = (String) entry.getKey();
+      Integer count = (Integer) entry.getValue();
+      
+      if ( (count==null)
+           || (count != 0)
+         ) {
+        hasLeftOvers = true;
+        System.err.println("FIXME: "+getClass().getName()+"."+getName()+" left "+count+" records in " + tableName);
       }
-      if (session.createQuery("from " + ProcessInstance.class.getName()).list().size() > 0)
-      {
-        System.err.println("FIXME: left over ProcessInstance after: " + getShortName());
-        foundLeftOvers = true;
-      }
-      if (session.createQuery("from " + ProcessLog.class.getName()).list().size() > 0)
-      {
-        System.err.println("FIXME: left over ProcessLog after: " + getShortName());
-        foundLeftOvers = true;
-      }
-      if (session.createQuery("from " + Token.class.getName()).list().size() > 0)
-      {
-        System.err.println("FIXME: left over Token after: " + getShortName());
-        foundLeftOvers = true;
-      }
     }
-    catch (Exception ex)
-    {
-      System.err.println("FIXME: cannot query left overs: " + ex);
+    
+    if (hasLeftOvers) {
+      jbpmSchema.cleanSchema();
     }
-    finally
-    {
-      jbpmContext.close();
-    }
-    return foundLeftOvers;
   }
 
   public void beginSessionTransaction()

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/GraphSession.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/GraphSession.java	2008-10-21 08:46:20 UTC (rev 2562)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/GraphSession.java	2008-10-21 11:42:08 UTC (rev 2563)
@@ -29,6 +29,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.hibernate.Hibernate;
 import org.hibernate.HibernateException;
 import org.hibernate.LockMode;
 import org.hibernate.Query;
@@ -38,6 +39,7 @@
 import org.jbpm.graph.exe.ProcessInstance;
 import org.jbpm.graph.exe.Token;
 import org.jbpm.graph.node.ProcessState;
+import org.jbpm.logging.log.ProcessLog;
 
 /**
  * are the graph related database operations.
@@ -226,12 +228,10 @@
     if (processDefinition==null) throw new JbpmException("processDefinition is null in JbpmSession.deleteProcessDefinition()");
     try {
       // delete all the process instances of this definition
-      List processInstances = findProcessInstances(processDefinition.getId());
-      if (processInstances!=null) {
-        Iterator iter = processInstances.iterator();
-        while (iter.hasNext()) {
-          deleteProcessInstance((ProcessInstance) iter.next());
-        }
+      ProcessInstance processInstance = findNextProcessInstance(processDefinition.getId());
+      while (processInstance!=null) {
+        deleteProcessInstance(processInstance);
+        processInstance = findNextProcessInstance(processDefinition.getId());
       }
       
       List referencingProcessStates = findReferencingProcessStates(processDefinition);
@@ -251,6 +251,13 @@
     } 
   }
 
+  protected ProcessInstance findNextProcessInstance(long processDefinitionId) {
+    Query query = session.getNamedQuery("GraphSession.findAllProcessInstancesForADefinition");
+    query.setLong("processDefinitionId", processDefinitionId);
+    query.setMaxResults(1);
+    return (ProcessInstance) query.uniqueResult();
+  }
+
   protected List findReferencingProcessStates(ProcessDefinition subProcessDefinition) {
     Query query = session.getNamedQuery("GraphSession.findReferencingProcessStates");
     query.setEntity("subProcessDefinition", subProcessDefinition);
@@ -379,52 +386,51 @@
 
   public void deleteProcessInstance(ProcessInstance processInstance, boolean includeTasks, boolean includeJobs) {
     if (processInstance==null) throw new JbpmException("processInstance is null in JbpmSession.deleteProcessInstance()");
+    log.debug("deleting process instance "+processInstance.getId());
+    
     try {
-      // find the tokens
-      Query query = session.getNamedQuery("GraphSession.findTokensForProcessInstance");
-      query.setEntity("processInstance", processInstance);
-      List tokens = query.list();
-
-      if (!tokens.isEmpty()) {
-        // deleteSubProcesses
-        Iterator iter = tokens.iterator();
-        while (iter.hasNext()) {
-          Token token = (Token) iter.next();
-          deleteSubProcesses(token);
-        }
-      }
-
       // jobs
       if (includeJobs) {
-        query = session.getNamedQuery("GraphSession.deleteJobsForProcessInstance");
+        log.debug("deleting jobs for process instance "+processInstance.getId());
+        Query query = session.getNamedQuery("GraphSession.deleteJobsForProcessInstance");
         query.setEntity("processInstance", processInstance);
         query.executeUpdate();
       }
       
       // tasks
       if (includeTasks) {
-        query = session.getNamedQuery("GraphSession.findTaskInstanceIdsForProcessInstance");
+        Query query = session.getNamedQuery("GraphSession.findTaskInstanceIdsForProcessInstance");
         query.setEntity("processInstance", processInstance);
         List taskInstanceIds = query.list();
         
-        query = session.getNamedQuery("GraphSession.deleteTaskInstancesById");
-        query.setParameterList("taskInstanceIds", taskInstanceIds);
-      }
-       
-      if (!tokens.isEmpty()) {
-        // delete the logs for all the process instance's tokens
-        query = session.getNamedQuery("GraphSession.selectLogsForTokens");
-        query.setParameterList("tokens", tokens);
-        List logs = query.list();
-        Iterator iter = logs.iterator();
-        while (iter.hasNext()) {
-          session.delete(iter.next());
+        if ( (taskInstanceIds!=null)
+             && (!taskInstanceIds.isEmpty())
+           ) {
+          log.debug("deleting tasks "+taskInstanceIds+" for process instance "+processInstance.getId());
+          query = session.getNamedQuery("GraphSession.deleteTaskInstancesById");
+          query.setParameterList("taskInstanceIds", taskInstanceIds);
         }
       }
 
-      // then delete the process instance
+      // delete the logs
+      log.debug("deleting logs for process instance "+processInstance.getId());
+      deleteLogs(processInstance);
+
+      // delete the tokens and subprocess instances
+      log.debug("deleting subprocesses for process instance "+processInstance.getId());
+      deleteSubProcesses(processInstance.getRootToken());
+
+      // null out the parent process token
+      Token superProcessToken = processInstance.getSuperProcessToken();
+      if (superProcessToken!=null) {
+        log.debug("nulling property subProcessInstance in superProcessToken "+superProcessToken.getId()+" which is referencing the process instance "+processInstance.getId()+" which is being deleted");
+        superProcessToken.setSubProcessInstance(null);
+      } 
+
+      // add the process instance
+      log.debug("hibernate session delete for process instance "+processInstance.getId());
       session.delete(processInstance);
-      
+
     } catch (Exception e) {
       log.error(e);
       jbpmSession.handleException();
@@ -432,33 +438,40 @@
     } 
   }
 
-  void deleteSubProcesses(Token token) {
-    Query query = session.getNamedQuery("GraphSession.findSubProcessInstances");
-    query.setEntity("processInstance", token.getProcessInstance());
-    List processInstances = query.list();
-
-    if (processInstances == null || processInstances.isEmpty()) {
-      return; 
-    }
-    
-    Iterator iter = processInstances.iterator();
+  void deleteLogs(ProcessInstance processInstance) {
+    Query query = session.getNamedQuery("GraphSession.findLogsForProcessInstance");
+    query.setEntity("processInstance", processInstance);
+    List logs = query.list();
+    Iterator iter = logs.iterator();
     while (iter.hasNext()) {
-      ProcessInstance subProcessInstance = (ProcessInstance) iter.next();
-      subProcessInstance.setSuperProcessToken(null);
-      token.setSubProcessInstance(null);
-      deleteProcessInstance(subProcessInstance);
-      session.flush();
+      ProcessLog processLog = (ProcessLog) iter.next();
+      session.delete(processLog);
     }
-    
-    if (token.getChildren()!=null) {
-      iter = token.getChildren().values().iterator();
+  }
+
+  void deleteSubProcesses(Token token) {
+    if (token!=null) {
+      Query query = session.getNamedQuery("GraphSession.findSubProcessInstances");
+      query.setEntity("processInstance", token.getProcessInstance());
+      List processInstances = query.list();
+      
+      if (processInstances == null || processInstances.isEmpty()) {
+        log.debug("no subprocesses to delete for token "+token.getId());
+        return; 
+      }
+  
+      Iterator iter = processInstances.iterator();
       while (iter.hasNext()) {
-        Token child = (Token) iter.next();
-        deleteSubProcesses(child);
+        ProcessInstance subProcessInstance = (ProcessInstance) iter.next();
+        subProcessInstance.setSuperProcessToken(null);
+        token.setSubProcessInstance(null);
+        log.debug("deleting sub process "+subProcessInstance.getId());
+        deleteProcessInstance(subProcessInstance);
       }
     }
   }
 
+
   public static class AverageNodeTimeEntry {
     private long nodeId;
     private String nodeName;

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/JbpmSchema.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/JbpmSchema.java	2008-10-21 08:46:20 UTC (rev 2562)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/db/JbpmSchema.java	2008-10-21 11:42:08 UTC (rev 2563)
@@ -35,8 +35,10 @@
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Properties;
 
 import org.apache.commons.logging.Log;
@@ -115,6 +117,8 @@
   {
     if (cleanSql == null)
     {
+      new SchemaExport(configuration);
+      
       String catalog = properties.getProperty(Environment.DEFAULT_CATALOG);
       String schema = properties.getProperty(Environment.DEFAULT_SCHEMA);
 
@@ -132,25 +136,16 @@
           {
             ForeignKey fk = (ForeignKey)subIter.next();
 
-            // Prevent NPE in ForeignKey.isPhysicalConstraint
-            // http://opensource.atlassian.com/projects/hibernate/browse/HHH-3479
-            if (fk.getReferencedTable() != null)
+            if (fk.isPhysicalConstraint())
             {
-              if (fk.isPhysicalConstraint())
-              {
-                // collect the drop foreign key constraint sql
-                String sqlDropString = fk.sqlDropString(dialect, catalog, schema);
-                dropForeignKeysSql.add(sqlDropString);
+              // collect the drop foreign key constraint sql
+              String sqlDropString = fk.sqlDropString(dialect, catalog, schema);
+              dropForeignKeysSql.add(sqlDropString);
 
-                // and collect the create foreign key constraint sql
-                String sqlCreateString = fk.sqlCreateString(dialect, mapping, catalog, schema);
-                createForeignKeysSql.add(sqlCreateString);
-              }
+              // and collect the create foreign key constraint sql
+              String sqlCreateString = fk.sqlCreateString(dialect, mapping, catalog, schema);
+              createForeignKeysSql.add(sqlCreateString);
             }
-            else
-            {
-              System.out.println("NoReferencedTable: " + fk);
-            }
           }
         }
       }
@@ -210,7 +205,41 @@
     }
     return jbpmTableNames;
   }
+  
+  public Map getJbpmTablesRecordCount() {
+    Map recordCounts = new HashMap();
+    
+    String sql = null;
+    
+    try
+    {
+      Iterator iter = getJbpmTables().iterator();
 
+      createConnection();
+      while (iter.hasNext()) {
+        statement = connection.createStatement();
+        String tableName = (String) iter.next();
+        sql = "SELECT COUNT(*) FROM "+tableName;
+        ResultSet resultSet = statement.executeQuery(sql);
+        resultSet.next();
+        int count = resultSet.getInt(1);
+        resultSet.close();
+        statement.close();
+        recordCounts.put(tableName, count);
+      }
+    }
+    catch (SQLException e)
+    {
+      throw new JbpmException("couldn't execute sql '" + sql + "'", e);
+    }
+    finally
+    {
+      closeConnection();
+    }
+
+    return recordCounts;
+  }
+
   public void dropSchema()
   {
     execute(getDropSql());

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/logging/log/ProcessLog.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/logging/log/ProcessLog.java	2008-10-21 08:46:20 UTC (rev 2562)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/logging/log/ProcessLog.java	2008-10-21 11:42:08 UTC (rev 2563)
@@ -82,4 +82,7 @@
   public int getIndex() {
     return index;
   }
+  public List getChildren() {
+    return null;
+  }
 }

Modified: jbpm3/trunk/modules/core/src/main/resources/hibernate.common.xml
===================================================================
--- jbpm3/trunk/modules/core/src/main/resources/hibernate.common.xml	2008-10-21 08:46:20 UTC (rev 2562)
+++ jbpm3/trunk/modules/core/src/main/resources/hibernate.common.xml	2008-10-21 11:42:08 UTC (rev 2563)
@@ -25,7 +25,7 @@
     <property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
 
     <!-- logging properties --> 
-    <property name="hibernate.format_sql">true</property>
+    <property name="hibernate.format_sql">false</property>
     <property name="hibernate.use_sql_comments">true</property>
 
     <!-- ############################################ -->

Modified: jbpm3/trunk/modules/core/src/main/resources/org/jbpm/db/hibernate.queries.hbm.xml
===================================================================
--- jbpm3/trunk/modules/core/src/main/resources/org/jbpm/db/hibernate.queries.hbm.xml	2008-10-21 08:46:20 UTC (rev 2562)
+++ jbpm3/trunk/modules/core/src/main/resources/org/jbpm/db/hibernate.queries.hbm.xml	2008-10-21 11:42:08 UTC (rev 2563)
@@ -133,14 +133,6 @@
     ]]>
   </query>
   
-  <query name="GraphSession.findTokensForProcessInstance">
-    <![CDATA[
-      select token
-      from org.jbpm.graph.exe.Token token
-      where token.processInstance = :processInstance
-    ]]>
-  </query>
-  
   <query name="GraphSession.findTokensForProcessInNode">
     <![CDATA[
       select token
@@ -158,15 +150,16 @@
       and  processInstance.key = :key
     ]]>
   </query>
-
-  <query name="GraphSession.selectLogsForTokens">
+  
+  <query name="GraphSession.findLogsForProcessInstance">
     <![CDATA[
       select pl
       from org.jbpm.logging.log.ProcessLog as pl
-      where pl.token in (:tokens)
+      where pl.token.processInstance = :processInstance
     ]]>
   </query>
   
+  
   <query name="GraphSession.findTaskInstanceIdsForProcessInstance">
     <![CDATA[
       select t 

Modified: jbpm3/trunk/modules/core/src/main/resources/org/jbpm/graph/log/ActionLog.hbm.xml
===================================================================
--- jbpm3/trunk/modules/core/src/main/resources/org/jbpm/graph/log/ActionLog.hbm.xml	2008-10-21 08:46:20 UTC (rev 2562)
+++ jbpm3/trunk/modules/core/src/main/resources/org/jbpm/graph/log/ActionLog.hbm.xml	2008-10-21 11:42:08 UTC (rev 2563)
@@ -7,7 +7,7 @@
 <hibernate-mapping auto-import="false" default-access="field">
 
   <subclass name="org.jbpm.graph.log.ActionLog" 
-            extends="org.jbpm.logging.log.ProcessLog"
+            extends="org.jbpm.logging.log.CompositeLog"
             discriminator-value="A">
             
     <property name="exception" column="EXCEPTION_" type="text"/>

Modified: jbpm3/trunk/modules/core/src/main/resources/org/jbpm/graph/log/SignalLog.hbm.xml
===================================================================
--- jbpm3/trunk/modules/core/src/main/resources/org/jbpm/graph/log/SignalLog.hbm.xml	2008-10-21 08:46:20 UTC (rev 2562)
+++ jbpm3/trunk/modules/core/src/main/resources/org/jbpm/graph/log/SignalLog.hbm.xml	2008-10-21 11:42:08 UTC (rev 2563)
@@ -7,7 +7,7 @@
 <hibernate-mapping auto-import="false" default-access="field">
 
   <subclass name="org.jbpm.graph.log.SignalLog" 
-            extends="org.jbpm.logging.log.ProcessLog"
+            extends="org.jbpm.logging.log.CompositeLog"
             discriminator-value="S">
     <many-to-one name="transition" column="TRANSITION_" class="org.jbpm.graph.def.Transition" foreign-key="FK_LOG_TRANSITION" />
   </subclass>

Modified: jbpm3/trunk/modules/core/src/main/resources/org/jbpm/graph/log/TransitionLog.hbm.xml
===================================================================
--- jbpm3/trunk/modules/core/src/main/resources/org/jbpm/graph/log/TransitionLog.hbm.xml	2008-10-21 08:46:20 UTC (rev 2562)
+++ jbpm3/trunk/modules/core/src/main/resources/org/jbpm/graph/log/TransitionLog.hbm.xml	2008-10-21 11:42:08 UTC (rev 2563)
@@ -7,7 +7,7 @@
 <hibernate-mapping auto-import="false" default-access="field">
 
   <subclass name="org.jbpm.graph.log.TransitionLog" 
-            extends="org.jbpm.logging.log.ProcessLog"
+            extends="org.jbpm.logging.log.CompositeLog"
             discriminator-value="T">
             
     <many-to-one name="transition" 

Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/graph/node/ProcessStateDbTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/graph/node/ProcessStateDbTest.java	2008-10-21 08:46:20 UTC (rev 2562)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/graph/node/ProcessStateDbTest.java	2008-10-21 11:42:08 UTC (rev 2563)
@@ -54,6 +54,74 @@
     }
   }
 
+  public void testRecursiveProcessDefinition() 
+  {
+    ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
+      "<process-definition name='recursive process'>" +
+      "  <start-state>" +
+      "    <transition to='first wait' />" +
+      "  </start-state>" +
+      "  <state name='first wait'>" +
+      "    <transition to='subprocessnode' />" +
+      "    <transition name='done' to='end' />" +
+      "  </state>" +
+      "  <process-state name='subprocessnode'>" +
+      "    <sub-process name='recursive process' />" +
+      "    <transition to='end' />" +
+      "  </process-state>" +
+      "  <end-state name='end' />" +
+      "</process-definition>" 
+    );
+  
+    processDefinition = saveAndReload(processDefinition);
+    try
+    {
+      ProcessInstance superProcessInstance = processDefinition.createProcessInstance();
+      superProcessInstance.signal();
+      superProcessInstance.signal();
+  
+      superProcessInstance = saveAndReload(superProcessInstance);
+  
+      Token superToken = superProcessInstance.getRootToken();
+      assertEquals("subprocessnode", superToken.getNode().getName());
+      
+      ProcessInstance subProcessInstance = superToken.getSubProcessInstance();
+      assertNotNull(subProcessInstance);
+      assertEquals("recursive process", subProcessInstance.getProcessDefinition().getName());
+      Token subToken = subProcessInstance.getRootToken();
+  
+      assertEquals("first wait", subToken.getNode().getName());
+      
+      subProcessInstance.signal("done");
+  
+      subProcessInstance = saveAndReload(subProcessInstance);
+      superProcessInstance = graphSession.loadProcessInstance(superProcessInstance.getId());
+  
+      assertTrue(subProcessInstance.hasEnded());    
+      assertTrue(superProcessInstance.hasEnded());
+      
+    }
+    finally
+    {
+      newTransaction();
+      try {
+        jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
+      } catch (RuntimeException e) {
+        e.printStackTrace();
+      } finally {
+        newTransaction();
+      }
+    }
+  }
+
+  public void testMultipleRecursiveProcessDefinitions() {
+    for (int i=0; i<30; i++) {
+      testRecursiveProcessDefinition();
+      newTransaction();
+    }
+  }
+
+
   public void testProcessStateSubProcessDefinition() 
   {
     // create the subprocess
@@ -108,6 +176,41 @@
     }
   }
 
+  public void testSubProcessBindingWithLatestVersion() 
+  {
+    jbpmContext.deployProcessDefinition(new ProcessDefinition("the multiversion subprocess"));
+    jbpmContext.deployProcessDefinition(new ProcessDefinition("the multiversion subprocess"));
+    jbpmContext.deployProcessDefinition(new ProcessDefinition("the multiversion subprocess"));
+    
+    newTransaction();
+    
+    ProcessDefinition processDefinitionTwo = ProcessDefinition.parseXmlString(
+      "<process-definition>" +
+      "  <process-state name='the sub process state'>" +
+      "    <sub-process name='the multiversion subprocess'/>" +
+      "  </process-state>" +
+      "</process-definition>"
+    );
+    processDefinitionTwo = saveAndReload(processDefinitionTwo);
+    try
+    {
+      ProcessState processState = (ProcessState) processDefinitionTwo.getNode("the sub process state");
+      assertEquals("the multiversion subprocess", processState.getSubProcessDefinition().getName() );
+      assertEquals(3, processState.getSubProcessDefinition().getVersion() );
+    }
+    finally
+    {
+      newTransaction();
+      ProcessDefinition processDefinition = graphSession.findProcessDefinition("the multiversion subprocess", 1);
+      graphSession.deleteProcessDefinition(processDefinition.getId());
+      processDefinition = graphSession.findProcessDefinition("the multiversion subprocess", 2);
+      graphSession.deleteProcessDefinition(processDefinition.getId());
+      processDefinition = graphSession.findProcessDefinition("the multiversion subprocess", 3);
+      graphSession.deleteProcessDefinition(processDefinition.getId());
+      graphSession.deleteProcessDefinition(processDefinitionTwo.getId());
+    }
+  }
+
   public void testAverageSubProcess() 
   {
     ProcessDefinition subProcessDefinition = ProcessDefinition.parseXmlString(
@@ -223,91 +326,6 @@
     }
   }
 
-  public void testSubProcessBindingWithLatestVersion() 
-  {
-    ProcessDefinition processDefinitionOne = new ProcessDefinition("the multiversion subprocess");
-    jbpmContext.deployProcessDefinition(processDefinitionOne);
-    jbpmContext.deployProcessDefinition(processDefinitionOne);
-    jbpmContext.deployProcessDefinition(processDefinitionOne);
-    
-    newTransaction();
-    
-    ProcessDefinition processDefinitionTwo = ProcessDefinition.parseXmlString(
-      "<process-definition>" +
-      "  <process-state name='the sub process state'>" +
-      "    <sub-process name='the multiversion subprocess'/>" +
-      "  </process-state>" +
-      "</process-definition>"
-    );
-    processDefinitionTwo = saveAndReload(processDefinitionTwo);
-    try
-    {
-      ProcessState processState = (ProcessState) processDefinitionTwo.getNode("the sub process state");
-      assertEquals("the multiversion subprocess", processState.getSubProcessDefinition().getName() );
-      assertEquals(3, processState.getSubProcessDefinition().getVersion() );
-    }
-    finally
-    {
-      newTransaction();
-      jbpmContext.getGraphSession().deleteProcessDefinition(processDefinitionOne.getId());
-      jbpmContext.getGraphSession().deleteProcessDefinition(processDefinitionTwo.getId());
-    }
-  }
-
-  public void testRecursiveProcessDefinition() 
-  {
-    ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
-      "<process-definition name='recursive process'>" +
-      "  <start-state>" +
-      "    <transition to='first wait' />" +
-      "  </start-state>" +
-      "  <state name='first wait'>" +
-      "    <transition to='subprocessnode' />" +
-      "    <transition name='done' to='end' />" +
-      "  </state>" +
-      "  <process-state name='subprocessnode'>" +
-      "    <sub-process name='recursive process' />" +
-      "    <transition to='end' />" +
-      "  </process-state>" +
-      "  <end-state name='end' />" +
-      "</process-definition>" 
-    );
-
-    processDefinition = saveAndReload(processDefinition);
-    try
-    {
-      ProcessInstance superProcessInstance = new ProcessInstance(processDefinition);
-      superProcessInstance.signal();
-      superProcessInstance.signal();
-
-      superProcessInstance = saveAndReload(superProcessInstance);
-
-      Token superToken = superProcessInstance.getRootToken();
-      assertEquals("subprocessnode", superToken.getNode().getName());
-      
-      ProcessInstance subProcessInstance = superToken.getSubProcessInstance();
-      assertNotNull(subProcessInstance);
-      assertEquals("recursive process", subProcessInstance.getProcessDefinition().getName());
-      Token subToken = subProcessInstance.getRootToken();
-
-      assertEquals("first wait", subToken.getNode().getName());
-      
-      subProcessInstance.signal("done");
-
-      subProcessInstance = saveAndReload(subProcessInstance);
-      superProcessInstance = graphSession.loadProcessInstance(superProcessInstance.getId());
-
-      assertTrue(subProcessInstance.hasEnded());    
-      assertTrue(superProcessInstance.hasEnded());
-      
-    }
-    finally
-    {
-      newTransaction();
-      jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
-    }
-  }
-  
   public void testSubProcessLogs() {
     ProcessDefinition subProcessDefinition = ProcessDefinition.parseXmlString(
       "<process-definition name='subprocess'>" +

Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1452/JBPM1452Test.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1452/JBPM1452Test.java	2008-10-21 08:46:20 UTC (rev 2562)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1452/JBPM1452Test.java	2008-10-21 11:42:08 UTC (rev 2563)
@@ -36,13 +36,23 @@
  */
 public class JBPM1452Test extends AbstractDbTestCase 
 {
-  @Override
+
+  static{
+    // making sure System.err and System.out are synchronized
+    System.setErr(System.out);
+  }
+
+ at Override
   protected JbpmConfiguration getJbpmConfiguration()
   {
-    return JbpmConfiguration.parseXmlString(
-        "<jbpm-configuration>" +
-        "  <null name='jbpm.job.executor' />" +
-        "</jbpm-configuration>");
+    if (jbpmConfiguration == null)
+    {
+      jbpmConfiguration = JbpmConfiguration.parseXmlString(
+              "<jbpm-configuration>" +
+              "  <null name='jbpm.job.executor' />" +
+              "</jbpm-configuration>");
+    }
+    return jbpmConfiguration;
   }
 
   public void testNoJobExecutor()
@@ -52,8 +62,15 @@
     assertTrue("expected object factory to have object jbpm.job.executor", objectFactory.hasObject("jbpm.job.executor"));
     assertNull(objectFactory.createObject("jbpm.job.executor"));
     // start and end a process instance, no exception should be thrown
-    jbpmContext.deployProcessDefinition(new ProcessDefinition("Audit"));
-    ProcessInstance processInstance = jbpmContext.newProcessInstanceForUpdate("Audit");
-    processInstance.end();
+    ProcessDefinition processDefinition = new ProcessDefinition("Audit");
+    jbpmContext.deployProcessDefinition(processDefinition);
+    try {
+      jbpmContext.newProcessInstanceForUpdate("Audit");
+    } catch(Throwable t) {
+      t.printStackTrace();
+    } finally {
+      newTransaction();
+      graphSession.deleteProcessDefinition(processDefinition.getId());
+    }
   }
 }




More information about the jbpm-commits mailing list