[jbpm-commits] JBoss JBPM SVN: r2119 - in jbpm3/trunk/modules/jpdl/core: src/test/java/org/jbpm/job/executor and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Sep 4 17:15:04 EDT 2008


Author: alex.guizar at jboss.com
Date: 2008-09-04 17:15:04 -0400 (Thu, 04 Sep 2008)
New Revision: 2119

Added:
   jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/JobConcurrencyDbTest.java
   jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/MultiJobExecutorDbTest.java
   jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/TestCallback.java
Removed:
   jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/ConcurrencyTest.java
   jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/MultiJobExecutorTest.java
Modified:
   jbpm3/trunk/modules/jpdl/core/pom.xml
   jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/JobExecutorDbTest.java
   jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/JobLoadJoinTest.java
   jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/JobLoadSubProcessTest.java
   jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/NoJobExecutorDbTest.java
   jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/TimerOnTimerDbTest.java
Log:
JBPM-1704: merged revision 2004 and 2005 - brought back job executor tests

Modified: jbpm3/trunk/modules/jpdl/core/pom.xml
===================================================================
--- jbpm3/trunk/modules/jpdl/core/pom.xml	2008-09-04 20:04:22 UTC (rev 2118)
+++ jbpm3/trunk/modules/jpdl/core/pom.xml	2008-09-04 21:15:04 UTC (rev 2119)
@@ -190,8 +190,6 @@
                 <exclude>org/jbpm/instantiation/UserCodeInterceptorTest.java</exclude>
                 <exclude>org/jbpm/JbpmDefaultConfigTest.java</exclude>
                 <exclude>org/jbpm/jcr/JcrDbTest.java</exclude>
-                <exclude>org/jbpm/job/executor/ConcurrencyTest.java</exclude>
-                <exclude>org/jbpm/job/executor/JobExecutorDbTest.java</exclude>
                 <exclude>org/jbpm/job/executor/JobLoadJoinTest.java</exclude>
                 <exclude>org/jbpm/job/executor/JobLoadSubProcessTest.java</exclude>
                 <exclude>org/jbpm/jpdl/convert/ConversionTestCase.java</exclude>
@@ -250,8 +248,6 @@
                 <exclude>org/jbpm/instantiation/UserCodeInterceptorTest.java</exclude>
                 <exclude>org/jbpm/JbpmDefaultConfigTest.java</exclude>
                 <exclude>org/jbpm/jcr/JcrDbTest.java</exclude>
-                <exclude>org/jbpm/job/executor/ConcurrencyTest.java</exclude>
-                <exclude>org/jbpm/job/executor/JobExecutorDbTest.java</exclude>
                 <exclude>org/jbpm/job/executor/JobLoadJoinTest.java</exclude>
                 <exclude>org/jbpm/job/executor/JobLoadSubProcessTest.java</exclude>
                 <exclude>org/jbpm/jpdl/convert/ConversionTestCase.java</exclude>
@@ -310,8 +306,6 @@
                 <exclude>org/jbpm/instantiation/UserCodeInterceptorTest.java</exclude>
                 <exclude>org/jbpm/JbpmDefaultConfigTest.java</exclude>
                 <exclude>org/jbpm/jcr/JcrDbTest.java</exclude>
-                <exclude>org/jbpm/job/executor/ConcurrencyTest.java</exclude>
-                <exclude>org/jbpm/job/executor/JobExecutorDbTest.java</exclude>
                 <exclude>org/jbpm/job/executor/JobLoadJoinTest.java</exclude>
                 <exclude>org/jbpm/job/executor/JobLoadSubProcessTest.java</exclude>
                 <exclude>org/jbpm/jpdl/convert/ConversionTestCase.java</exclude>
@@ -376,8 +370,6 @@
                 <exclude>org/jbpm/instantiation/UserCodeInterceptorTest.java</exclude>
                 <exclude>org/jbpm/JbpmDefaultConfigTest.java</exclude>
                 <exclude>org/jbpm/jcr/JcrDbTest.java</exclude>
-                <exclude>org/jbpm/job/executor/ConcurrencyTest.java</exclude>
-                <exclude>org/jbpm/job/executor/JobExecutorDbTest.java</exclude>
                 <exclude>org/jbpm/job/executor/JobLoadJoinTest.java</exclude>
                 <exclude>org/jbpm/job/executor/JobLoadSubProcessTest.java</exclude>
                 <exclude>org/jbpm/jpdl/convert/ConversionTestCase.java</exclude>
@@ -436,8 +428,6 @@
                 <exclude>org/jbpm/instantiation/UserCodeInterceptorTest.java</exclude>
                 <exclude>org/jbpm/JbpmDefaultConfigTest.java</exclude>
                 <exclude>org/jbpm/jcr/JcrDbTest.java</exclude>
-                <exclude>org/jbpm/job/executor/ConcurrencyTest.java</exclude>
-                <exclude>org/jbpm/job/executor/JobExecutorDbTest.java</exclude>
                 <exclude>org/jbpm/job/executor/JobLoadJoinTest.java</exclude>
                 <exclude>org/jbpm/job/executor/JobLoadSubProcessTest.java</exclude>
                 <exclude>org/jbpm/jpdl/convert/ConversionTestCase.java</exclude>

Deleted: jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/ConcurrencyTest.java
===================================================================
--- jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/ConcurrencyTest.java	2008-09-04 20:04:22 UTC (rev 2118)
+++ jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/ConcurrencyTest.java	2008-09-04 21:15:04 UTC (rev 2119)
@@ -1,238 +0,0 @@
-package org.jbpm.job.executor;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jbpm.JbpmConfiguration;
-import org.jbpm.JbpmContext;
-import org.jbpm.graph.def.ActionHandler;
-import org.jbpm.graph.def.ProcessDefinition;
-import org.jbpm.graph.exe.ExecutionContext;
-import org.jbpm.graph.exe.ProcessInstance;
-
-/**
- * test case for http://jira.jboss.com/jira/browse/JBPM-983
- */
-public class ConcurrencyTest extends TestCase {
-
-  private static Log log = LogFactory.getLog(ConcurrencyTest.class);
-
-  protected static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance("org/jbpm/jbpm.test.cfg.xml");
-
-  protected void setUp() throws Exception {
-    jbpmConfiguration.createSchema();
-
-    JobExecutor jobExecutor = jbpmConfiguration.getJobExecutor();
-    jobExecutor.setNbrOfThreads(5);
-    jobExecutor.start();
-
-    log.debug("");
-    log.debug("### starting " + getName() + " ####################################################");
-  }
-
-  protected void tearDown() throws Exception {
-    log.debug("### " + getName() + " done ####################################################");
-    log.debug("");
-
-    jbpmConfiguration.getJobExecutor().stop();
-
-    jbpmConfiguration.dropSchema();
-  }
-
-  static String SUBPROCESS_XML = "<?xml version='1.0' encoding='UTF-8'?>"
-      + "<process-definition xmlns='urn:jbpm.org:jpdl-3.2' name='simplesubtest'>"
-      + "<start-state name='start-state1'>"
-      + "   <description>start of the process</description>"
-      + "   <transition name='start-to-check' to='fileCheck' />"
-      + "</start-state>"
-      + ""
-      + "<node name='fileCheck' async='exclusive'>"
-      + "   <action name='action_filecheck' class='"
-      + TestAction.class.getName()
-      + "'>"
-      + "   </action>"
-      + "   <transition name='check-to-do' to='doWhatever'></transition>"
-      + "</node>"
-      + ""
-      + "<node name='doWhatever' async='exclusive'>"
-      + "   <action name='action_do' class='"
-      + TestAction.class.getName()
-      + "'>"
-      + "   </action>"
-      + "   <transition name='check-to-end' to='end-state-success'></transition>"
-      + "</node>"
-      + ""
-      + "<end-state name='end-state-success'>"
-      + "   <description>process finished normally</description>"
-      + "</end-state>"
-      + "</process-definition>";
-
-  static String PROCESS_XML = "<?xml version='1.0' encoding='UTF-8'?>"
-      + "<process-definition xmlns='urn:jbpm.org:jpdl-3.2' name='simpletest'>"
-      + "<start-state name='start-state1'>"
-      + "   <description>start of the process</description>"
-      + "   <transition name='start-to-check' to='fileCheck' />"
-      + "</start-state>"
-      + ""
-      + "<node name='fileCheck' async='true'>"
-      + "   <action name='action_check' class='"
-      + TestAction.class.getName()
-      + "'>"
-      + "   </action>"
-      + "   <transition name='check-to-fork' to='fork1'></transition>"
-      + "</node>"
-      + ""
-      + "<fork name='fork1'>"
-      + "   <transition name='toNode1' to='node1'></transition>"
-      + "   <transition name='toNode2' to='node2'></transition>"
-      + "</fork>"
-      + ""
-      + "<process-state name='node1' async='exclusive'>"
-      + "   <sub-process name='simplesubtest' />"
-      + "   <transition name='node1toJoin1' to='join1'></transition>"
-      + "</process-state>"
-      + ""
-      + "<process-state name='node2' async='exclusive'>"
-      + "   <sub-process name='simplesubtest' />"
-      + "   <transition name='node2toJoin1' to='join1'></transition>"
-      + "</process-state>"
-      + ""
-      + "<join name='join1'>"
-      + "   <transition name='joinToEnd' to='end-state-success'></transition>"
-      + "</join>"
-      + ""
-      + "<end-state name='end-state-success'>"
-      + "   <description>process finished normally</description>"
-      + "</end-state>"
-      + "</process-definition>";
-
-  public void testSimple() throws Exception {
-    assertTrue(jbpmConfiguration.getJobExecutor().getNbrOfThreads() > 1);
-
-    log.info("### TEST: deploy + start processes ###");
-
-    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
-    try {
-      jbpmContext.deployProcessDefinition(ProcessDefinition.parseXmlString(SUBPROCESS_XML));
-      jbpmContext.deployProcessDefinition(ProcessDefinition.parseXmlString(PROCESS_XML));
-
-    }
-    finally {
-      jbpmContext.close();
-    }
-
-    // create test properties
-    Map testVariables = new HashMap();
-    testVariables.put("test", "true");
-
-    for (int i = 0; i < 10; i++) {
-      log.info("#################### TEST: starting process " + i + " ####################");
-
-      ProcessInstance pi = null;
-
-      jbpmContext = jbpmConfiguration.createJbpmContext();
-      try {
-        pi = jbpmContext.newProcessInstance("simpletest");
-        pi.getContextInstance().addVariables(testVariables);
-        jbpmContext.save(pi);
-        pi.signal();
-
-      }
-      finally {
-        jbpmContext.close();
-      }
-      log.info("### TEST: wait for process completion ###");
-
-      waitFor(pi.getId());
-
-      jbpmContext = jbpmConfiguration.createJbpmContext();
-      try {
-        ProcessInstance pi2 = jbpmContext.getProcessInstance(pi.getId());
-        assertEquals("end-state-success", pi2.getRootToken().getNode().getName());
-      }
-      finally {
-        jbpmContext.close();
-      }
-
-      log.info("#################### TEST: finished ####################");
-    }
-  }
-
-  protected void waitFor(final long piId) throws Exception {
-    long startTime = System.currentTimeMillis();
-    int SECONDS = 30;
-
-    while (true) {
-      if (System.currentTimeMillis() - startTime > SECONDS * 1000) {
-        fail("Aborting after " + SECONDS + " seconds.");
-        return;
-      }
-
-      log.info("waiting for workflow completion...."); // + pi.getRootToken().getNode().getName()
-      // );
-      try {
-        Thread.sleep(5000);
-      }
-      catch (InterruptedException e) {
-        log.error("wait for workflow was interruputed", e);
-        fail();
-      }
-
-      JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
-      try {
-        if (jbpmContext.getProcessInstance(piId).hasEnded())
-          break;
-      }
-      finally {
-        jbpmContext.close();
-      }
-    }
-  }
-
-  public static class TestAction implements ActionHandler {
-
-    private static final long serialVersionUID = 1L;
-
-    public void execute(ExecutionContext executionContext) throws Exception {
-      String processName = executionContext.getProcessDefinition().getName()
-          + ":"
-          + executionContext.getProcessInstance().getId();
-      String nodeName = executionContext.getToken().getNode().getName();
-      String tokenName = executionContext.getToken().toString();
-
-      log.info("ACTION (process="
-          + processName
-          + ",node="
-          + nodeName
-          + ",token="
-          + tokenName
-          + "): begin");
-
-      for (int i = 0; i < 5; i++) {
-        Thread.sleep(500);
-        log.info("ACTION (process="
-            + processName
-            + ",node="
-            + nodeName
-            + ",token="
-            + tokenName
-            + "): working...");
-        Thread.sleep(500);
-      }
-
-      log.info("ACTION (process="
-          + processName
-          + ",node="
-          + nodeName
-          + ",token="
-          + tokenName
-          + "): end");
-
-      executionContext.leaveNode();
-    }
-  }
-}

Added: jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/JobConcurrencyDbTest.java
===================================================================
--- jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/JobConcurrencyDbTest.java	                        (rev 0)
+++ jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/JobConcurrencyDbTest.java	2008-09-04 21:15:04 UTC (rev 2119)
@@ -0,0 +1,238 @@
+package org.jbpm.job.executor;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmContext;
+import org.jbpm.graph.def.ActionHandler;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ExecutionContext;
+import org.jbpm.graph.exe.ProcessInstance;
+
+/**
+ * test case for http://jira.jboss.com/jira/browse/JBPM-983
+ */
+public class JobConcurrencyDbTest extends TestCase {
+
+  private static Log log = LogFactory.getLog(JobConcurrencyDbTest.class);
+
+  protected static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance("org/jbpm/jbpm.test.cfg.xml");
+
+  protected void setUp() throws Exception {
+    jbpmConfiguration.createSchema();
+
+    JobExecutor jobExecutor = jbpmConfiguration.getJobExecutor();
+    jobExecutor.setNbrOfThreads(5);
+    jobExecutor.start();
+
+    log.debug("");
+    log.debug("### starting " + getName() + " ####################################################");
+  }
+
+  protected void tearDown() throws Exception {
+    log.debug("### " + getName() + " done ####################################################");
+    log.debug("");
+
+    jbpmConfiguration.getJobExecutor().stop();
+
+    jbpmConfiguration.dropSchema();
+  }
+
+  static String SUBPROCESS_XML = "<?xml version='1.0' encoding='UTF-8'?>"
+      + "<process-definition xmlns='urn:jbpm.org:jpdl-3.2' name='subprocess'>"
+      + "<start-state name='start-state1'>"
+      + "   <description>start of the process</description>"
+      + "   <transition name='start-to-check' to='fileCheck' />"
+      + "</start-state>"
+      + ""
+      + "<node name='fileCheck' async='exclusive'>"
+      + "   <action name='action_filecheck' class='"
+      + TestAction.class.getName()
+      + "'>"
+      + "   </action>"
+      + "   <transition name='check-to-do' to='doWhatever'></transition>"
+      + "</node>"
+      + ""
+      + "<node name='doWhatever' async='exclusive'>"
+      + "   <action name='action_do' class='"
+      + TestAction.class.getName()
+      + "'>"
+      + "   </action>"
+      + "   <transition name='check-to-end' to='end-state-success'></transition>"
+      + "</node>"
+      + ""
+      + "<end-state name='end-state-success'>"
+      + "   <description>process finished normally</description>"
+      + "</end-state>"
+      + "</process-definition>";
+
+  static String PROCESS_XML = "<?xml version='1.0' encoding='UTF-8'?>"
+      + "<process-definition xmlns='urn:jbpm.org:jpdl-3.2' name='superprocess'>"
+      + "<start-state name='start-state1'>"
+      + "   <description>start of the process</description>"
+      + "   <transition name='start-to-check' to='fileCheck' />"
+      + "</start-state>"
+      + ""
+      + "<node name='fileCheck' async='true'>"
+      + "   <action name='action_check' class='"
+      + TestAction.class.getName()
+      + "'>"
+      + "   </action>"
+      + "   <transition name='check-to-fork' to='fork1'></transition>"
+      + "</node>"
+      + ""
+      + "<fork name='fork1'>"
+      + "   <transition name='toNode1' to='node1'></transition>"
+      + "   <transition name='toNode2' to='node2'></transition>"
+      + "</fork>"
+      + ""
+      + "<process-state name='node1' async='exclusive'>"
+      + "   <sub-process name='subprocess' />"
+      + "   <transition name='node1toJoin1' to='join1'></transition>"
+      + "</process-state>"
+      + ""
+      + "<process-state name='node2' async='exclusive'>"
+      + "   <sub-process name='subprocess' />"
+      + "   <transition name='node2toJoin1' to='join1'></transition>"
+      + "</process-state>"
+      + ""
+      + "<join name='join1'>"
+      + "   <transition name='joinToEnd' to='end-state-success'></transition>"
+      + "</join>"
+      + ""
+      + "<end-state name='end-state-success'>"
+      + "   <description>process finished normally</description>"
+      + "</end-state>"
+      + "</process-definition>";
+
+  public void testConcurrentJobs() throws Exception {
+    assertTrue(jbpmConfiguration.getJobExecutor().getNbrOfThreads() > 1);
+
+    log.info("### TEST: deploy + start processes ###");
+
+    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
+    try {
+      jbpmContext.deployProcessDefinition(ProcessDefinition.parseXmlString(SUBPROCESS_XML));
+      jbpmContext.deployProcessDefinition(ProcessDefinition.parseXmlString(PROCESS_XML));
+    }
+    finally {
+      jbpmContext.close();
+    }
+
+    // create test properties
+    Map testVariables = new HashMap();
+    testVariables.put("test", "true");
+
+    final int processCount = 10;
+    long[] piIds = new long[processCount];
+    for (int i = 0; i < processCount; i++) {
+      log.info("#################### TEST: starting process " + i + " ####################");
+
+      jbpmContext = jbpmConfiguration.createJbpmContext();
+      try {
+        ProcessInstance pi = jbpmContext.newProcessInstanceForUpdate("superprocess");
+        pi.getContextInstance().addVariables(testVariables);
+        pi.signal();
+        piIds[i] = pi.getId();
+      }
+      finally {
+        jbpmContext.close();
+      }
+    }
+
+    for (int i = 0; i < processCount; i++) {
+      log.info("### TEST: wait for process completion ###");
+
+      long piId = piIds[i];
+      waitFor(piId);
+
+      jbpmContext = jbpmConfiguration.createJbpmContext();
+      try {
+        ProcessInstance pi = jbpmContext.loadProcessInstance(piId);
+        assertEquals("end-state-success", pi.getRootToken().getNode().getName());
+      }
+      finally {
+        jbpmContext.close();
+      }
+
+      log.info("#################### TEST: finished ####################");
+    }
+  }
+
+  protected void waitFor(long piId) throws Exception {
+    final int endTimeout = 30;
+    long startTime = System.currentTimeMillis();
+
+    while (true) {
+      if (System.currentTimeMillis() - startTime > endTimeout * 1000) {
+        fail("Aborting after " + endTimeout + " seconds.");
+        return;
+      }
+
+      log.info("waiting for workflow completion....");
+      try {
+        Thread.sleep(1000);
+      }
+      catch (InterruptedException e) {
+        log.error("wait for workflow was interruputed", e);
+        fail();
+      }
+
+      JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
+      try {
+        if (jbpmContext.loadProcessInstance(piId).hasEnded())
+          break;
+      }
+      finally {
+        jbpmContext.close();
+      }
+    }
+  }
+
+  public static class TestAction implements ActionHandler {
+
+    private static final long serialVersionUID = 1L;
+
+    public void execute(ExecutionContext executionContext) throws Exception {
+      String processName = executionContext.getProcessDefinition().getName()
+          + ":"
+          + executionContext.getProcessInstance().getId();
+      String nodeName = executionContext.getToken().getNode().getName();
+      String tokenName = executionContext.getToken().toString();
+
+      log.info("ACTION (process="
+          + processName
+          + ",node="
+          + nodeName
+          + ",token="
+          + tokenName
+          + "): begin");
+
+      for (int i = 0; i < 5; i++) {
+        log.info("ACTION (process="
+            + processName
+            + ",node="
+            + nodeName
+            + ",token="
+            + tokenName
+            + "): working...");
+        Thread.sleep(100);
+      }
+
+      log.info("ACTION (process="
+          + processName
+          + ",node="
+          + nodeName
+          + ",token="
+          + tokenName
+          + "): end");
+
+      executionContext.leaveNode();
+    }
+  }
+}

Modified: jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/JobExecutorDbTest.java
===================================================================
--- jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/JobExecutorDbTest.java	2008-09-04 20:04:22 UTC (rev 2118)
+++ jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/JobExecutorDbTest.java	2008-09-04 21:15:04 UTC (rev 2119)
@@ -22,7 +22,7 @@
 public class JobExecutorDbTest extends TestCase {
 
   static int nbrOfConcurrentProcessExecutions = 20;
-  static int maxWaitTime = 20000;
+  static int maxWaitTime = 60000;
   static Set collectedResults = Collections.synchronizedSet(new TreeSet());
   
   protected static JbpmConfiguration jbpmConfiguration = 
@@ -37,7 +37,7 @@
   public static class AutomaticActivity implements ActionHandler {
     private static final long serialVersionUID = 1L;
     public void execute(ExecutionContext executionContext) throws Exception {
-      String id = (String) Long.toString(executionContext.getProcessInstance().getId());
+      long id = executionContext.getProcessInstance().getId();
       String nodeName = executionContext.getNode().getName();
       collectedResults.add(id+nodeName);
       executionContext.leaveNode();
@@ -47,14 +47,14 @@
   public static class AsyncAction implements ActionHandler {
     private static final long serialVersionUID = 1L;
     public void execute(ExecutionContext executionContext) throws Exception {
-      String id = (String) Long.toString(executionContext.getProcessInstance().getId());
+      long id = executionContext.getProcessInstance().getId();
       Action action = executionContext.getAction();
       String actionName = action.getName();
       collectedResults.add(id+actionName);
     }
   }
 
-  public void testBulkJobs() {
+  public void testJobExecutor() {
     jbpmConfiguration.createSchema();
     deployProcess();
     launchProcesses();

Modified: jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/JobLoadJoinTest.java
===================================================================
--- jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/JobLoadJoinTest.java	2008-09-04 20:04:22 UTC (rev 2118)
+++ jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/JobLoadJoinTest.java	2008-09-04 21:15:04 UTC (rev 2119)
@@ -24,16 +24,16 @@
 
   static Set finishedProcesses = Collections.synchronizedSet(new HashSet());
   long start;
-
-  static {   
-    jbpmConfiguration.createSchema();      
-  }
   
   protected void setUp() throws Exception {
-	  super.setUp();
+	  jbpmConfiguration.createSchema();
 	  start = System.currentTimeMillis();
   }
-  
+
+  protected void tearDown() throws Exception {
+    jbpmConfiguration.dropSchema();
+  }
+
   private boolean timeIsUp(int maxWait) {
 	  return System.currentTimeMillis() - start > maxWait;
   }

Modified: jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/JobLoadSubProcessTest.java
===================================================================
--- jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/JobLoadSubProcessTest.java	2008-09-04 20:04:22 UTC (rev 2118)
+++ jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/JobLoadSubProcessTest.java	2008-09-04 21:15:04 UTC (rev 2119)
@@ -18,7 +18,7 @@
 public class JobLoadSubProcessTest extends TestCase {
 
   // TODO see JobLoadJoinTest, but instead of the joins, use a process with a sub process
-  private static Log log = LogFactory.getLog(JobLoadJoinTest.class);
+  private static Log log = LogFactory.getLog(JobLoadSubProcessTest.class);
 
   static Set finishedProcesses = Collections.synchronizedSet(new HashSet());
   long start;
@@ -26,15 +26,15 @@
   private static JbpmConfiguration jbpmConfiguration = 
     JbpmConfiguration.getInstance("org/jbpm/job/executor/loadtests.jbpm.cfg.xml");
 
-  static {   
-    jbpmConfiguration.createSchema();      
-  }
-		  
   protected void setUp() throws Exception {
-	  super.setUp();
+	  jbpmConfiguration.createSchema();
 	  start = System.currentTimeMillis();
   }
-  
+
+  protected void tearDown() throws Exception {
+    jbpmConfiguration.dropSchema();
+  }
+
   private boolean timeIsUp(int maxWait) {
 	  return System.currentTimeMillis() - start > maxWait;
   }

Added: jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/MultiJobExecutorDbTest.java
===================================================================
--- jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/MultiJobExecutorDbTest.java	                        (rev 0)
+++ jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/MultiJobExecutorDbTest.java	2008-09-04 21:15:04 UTC (rev 2119)
@@ -0,0 +1,135 @@
+package org.jbpm.job.executor;
+
+import java.sql.SQLException;
+
+import junit.framework.TestCase;
+
+import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmContext;
+import org.jbpm.graph.def.ActionHandler;
+import org.jbpm.graph.def.Event;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ExecutionContext;
+import org.jbpm.graph.exe.ProcessInstance;
+
+/**
+ * Test case for JBPM-1072.
+ * @author Jiri Pechanec
+ * @author Alejandro Guizar
+ */
+public class MultiJobExecutorDbTest extends TestCase {
+
+  private static final int EXECUTOR_COUNT = 20;
+  public static final String PROCESS_NAME = "TestProcess";
+
+  private JobExecutor[] executors = new JobExecutor[EXECUTOR_COUNT];
+
+  private static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
+
+  public static final String PROCESS_DEFINITION = "<?xml version='1.0' encoding='UTF-8'?>"
+      + "<process-definition name='" + PROCESS_NAME + "'>"
+      + "<event type='process-end'>"
+      + "<action expression='#{testCallback.processEnd}' />"
+      + "</event>"
+      + "<start-state name='start-state1'>"
+      + "<transition to='Service 1'></transition>"
+      + "</start-state>"
+      + "<node name='Service 1'>"
+      + "<action class='"
+      + SimpleAction.class.getName()
+      + "' />"
+      + "<transition to='Service 2' />"
+      + "</node>"
+      + "<node name='Service 2' async='true'>"
+      + "<action class='"
+      + SimpleAction2.class.getName()
+      + "' />"
+      + "<transition to='end-state1' />"
+      + "</node>"
+      + "<end-state name='end-state1' />"
+      + "</process-definition>";
+
+  protected void setUp() throws SQLException {
+    jbpmConfiguration.createSchema();
+
+    // deploy process definition
+    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
+    try {
+      jbpmContext.deployProcessDefinition(ProcessDefinition.parseXmlString(PROCESS_DEFINITION));
+    }
+    finally {
+      jbpmContext.close();
+    }
+  }
+
+  public void testMultipleJobExecutors() {
+    // start job executors
+    for (int i = 0; i < executors.length; i++) {
+      executors[i] = (JobExecutor) JbpmConfiguration.Configs.getObjectFactory().createObject(
+          "jbpm.job.executor");
+      executors[i].setName("JbpmJobExecutor/" + (i + 1));
+      executors[i].start();
+    }
+
+    // kick off process instance
+    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
+    try {
+      ProcessInstance processInstance = jbpmContext.newProcessInstanceForUpdate(PROCESS_NAME);
+      processInstance.getContextInstance().setVariable("testCallback", new TestCallback());
+      processInstance.signal();
+    }
+    finally {
+      jbpmContext.close();
+    }
+
+    // wait for process end
+    TestCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
+
+    // stop job executors
+    for (int i = executors.length - 1; i >= 0; i--) {
+      try {
+        executors[i].stopAndJoin();
+      }
+      catch (InterruptedException e) {
+        // continue to next executor
+      }
+    }
+
+    assertEquals(1, SimpleAction2.getExecutionCount());
+  }
+
+  protected void tearDown() {
+    jbpmConfiguration.dropSchema();
+  }
+
+  public static class SimpleAction implements ActionHandler {
+
+    private static final long serialVersionUID = 1L;
+
+    public void execute(ExecutionContext exeContext) throws Exception {
+      System.out.println("Action 1");
+      exeContext.leaveNode();
+    }
+
+  }
+
+  public static class SimpleAction2 implements ActionHandler {
+
+    private static int executionCount = 0;
+
+    private static final long serialVersionUID = 1L;
+
+    public void execute(ExecutionContext exeContext) throws Exception {
+      System.out.println("Action 2: " + incrementCount());
+      exeContext.leaveNode();
+    }
+
+    private static synchronized int incrementCount() {
+      return ++executionCount;
+    }
+
+    public static synchronized int getExecutionCount() {
+      return executionCount;
+    }
+  }
+}

Deleted: jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/MultiJobExecutorTest.java
===================================================================
--- jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/MultiJobExecutorTest.java	2008-09-04 20:04:22 UTC (rev 2118)
+++ jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/MultiJobExecutorTest.java	2008-09-04 21:15:04 UTC (rev 2119)
@@ -1,209 +0,0 @@
-package org.jbpm.job.executor;
-
-import java.sql.SQLException;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jbpm.JbpmConfiguration;
-import org.jbpm.JbpmContext;
-import org.jbpm.command.Command;
-import org.jbpm.command.CommandService;
-import org.jbpm.command.DeployProcessCommand;
-import org.jbpm.command.StartProcessInstanceCommand;
-import org.jbpm.command.impl.CommandServiceImpl;
-import org.jbpm.configuration.ObjectFactory;
-import org.jbpm.graph.def.ActionHandler;
-import org.jbpm.graph.exe.ExecutionContext;
-import org.jbpm.graph.exe.Token;
-
-/**
- * Test case for JBPM-1072.
- * @author Jiri Pechanec
- * @author Alejandro Guizar
- */
-public class MultiJobExecutorTest extends TestCase {
-
-  private static final int EXECUTOR_COUNT = 16;
-  private static final int JOB_COUNT = 1;
-  private static final int IDLE_INTERVAL = 1000;
-  private static final String PROCESS_NAME = "TestProcess";
-
-  private static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
-  private static CommandService commandService = new CommandRetryService(new CommandServiceImpl(jbpmConfiguration), 3);
-
-  private static final Log log = LogFactory.getLog(MultiJobExecutorTest.class);
-
-  private static final String PROCESS_DEFINITION = "<process-definition name='" 
-      + PROCESS_NAME 
-      + "'>"
-      + "<event type='process-end'>"
-      + "<action name='endAction' class='"
-      + EndAction.class.getName()
-      + "'/>"
-      + "</event>"
-      + "<start-state name='start'>"
-      + "<transition to='fork'/>"
-      + "</start-state>"
-      + "<node name='fork'>"
-      + "<action class='"
-      + MultiFork.class.getName()
-      + "'/>"
-      + "<transition to='async'/>"
-      + "</node>"
-      + "<node name='async' async='true'>"
-      + "<action class='"
-      + AsyncAction.class.getName()
-      + "'/>"
-      + "<transition to='join'/>"
-      + "</node>"
-      + "<join name='join'>" 
-      + "<transition to='end'/>" 
-      + "</join>"
-      + "<end-state name='end'/>"
-      + "</process-definition>";
-
-  protected void setUp() throws SQLException {
-    jbpmConfiguration.createSchema();
-    commandService.execute(new DeployProcessCommand(PROCESS_DEFINITION));
-  }
-
-  public void testMultipleExecutors() {
-    // create job executors
-    JobExecutor[] jobExecutors = new JobExecutor[EXECUTOR_COUNT];
-    // jobExecutors[0] = jbpmConfiguration.getJobExecutor();
-
-    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
-    try {
-      ObjectFactory objectFactory = jbpmContext.getObjectFactory();
-      for (int i = 0; i < jobExecutors.length; i++) {
-        JobExecutor jobExecutor = (JobExecutor) objectFactory.createObject("jbpm.job.executor");
-        jobExecutor.setName(jobExecutor.getName() + '-' + i);
-        jobExecutor.setIdleInterval(IDLE_INTERVAL);
-        jobExecutors[i] = jobExecutor;
-      }
-    }
-    finally {
-      jbpmContext.close();
-    }
-
-    // start job executors
-    for (int i = 0; i < jobExecutors.length; i++) {
-      jobExecutors[i].start();
-    }
-
-    // kick off process instance
-    StartProcessInstanceCommand startCommand = new StartProcessInstanceCommand();
-    startCommand.setProcessName(PROCESS_NAME);
-    commandService.execute(startCommand);
-  
-    // wait till process instance ends
-    EndAction.waitFor(IDLE_INTERVAL);
-  
-    // stop job executors
-    for (int i = jobExecutors.length - 1; i >= 0; i--) {
-      try {
-        jobExecutors[i].stopAndJoin();
-      }
-      catch (InterruptedException e) {
-        // continue to next executor
-      }
-    }
-  
-    assertEquals(JOB_COUNT, AsyncAction.getCount());
-  }
-
-  protected void tearDown() {
-    jbpmConfiguration.dropSchema();
-  }
-
-  static class CommandRetryService implements CommandService {
-  
-    private final CommandService commandService;
-    private final int retryCount;
-
-    CommandRetryService(CommandService commandService, int retryCount) {
-      this.commandService = commandService;
-      this.retryCount = retryCount;
-    }
-
-    public Object execute(Command command) {
-      for (int i = 1;; i++) {
-        try {
-          return commandService.execute(command);
-        }
-        catch (RuntimeException e) {
-          log.error("attempt " + i + " to execute command failed", e);
-          if (i == retryCount)
-            throw e;
-        }
-      }
-    }
-  }
-
-  public static class MultiFork implements ActionHandler {
-
-    private static final long serialVersionUID = 1L;
-
-    public void execute(ExecutionContext ctx) throws Exception {
-      Token parentToken = ctx.getToken();
-      for (int i = 0; i < JOB_COUNT; i++) {
-        Token childToken = new Token(parentToken, Integer.toString(i));
-        new ExecutionContext(childToken).leaveNode();
-      }
-    }
-  }
-
-  public static class AsyncAction implements ActionHandler {
-
-    private static volatile int count = 0;
-
-    private static final long serialVersionUID = 1L;
-
-    public void execute(ExecutionContext exeContext) throws Exception {
-      log.info("execution count: " + incrementCount());
-      exeContext.leaveNode();
-    }
-
-    private static synchronized int incrementCount() {
-      return ++count;
-    }
-
-    public static int getCount() {
-      return count;
-    }
-  }
-
-  public static class EndAction implements ActionHandler {
-
-    private static final Object lock = new Object();
-    private static volatile boolean ended;
-
-    private static final long serialVersionUID = 1L;
-
-    public void execute(ExecutionContext exeContext) throws Exception {
-      ended = true;
-      log.debug("process-end event fired, notifying");
-      synchronized (lock) {
-        lock.notify();
-      }
-    }
-
-    public static void waitFor(long timeout) {
-      while (!ended) {
-        log.debug("process not ended, waiting");
-        try {
-          synchronized (lock) {
-            lock.wait(timeout);
-          }
-        }
-        catch (InterruptedException e) {
-          // check condition again
-        }
-        log.debug("checking whether process has ended");
-      }
-      log.debug("process ended, proceeding");
-    }
-  }
-}

Modified: jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/NoJobExecutorDbTest.java
===================================================================
--- jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/NoJobExecutorDbTest.java	2008-09-04 20:04:22 UTC (rev 2118)
+++ jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/NoJobExecutorDbTest.java	2008-09-04 21:15:04 UTC (rev 2119)
@@ -25,6 +25,7 @@
 
 import org.jbpm.JbpmConfiguration;
 import org.jbpm.JbpmContext;
+import org.jbpm.configuration.ObjectFactory;
 import org.jbpm.graph.def.ProcessDefinition;
 import org.jbpm.graph.exe.ProcessInstance;
 
@@ -51,10 +52,13 @@
     jbpmConfiguration.dropSchema();
   }
 
-  public void testJobExecutorDoesNotExist() {
+  public void testNoJobExecutor() {
     // check the job executor is properly nullified
-    assertNull(jbpmContext.getObjectFactory().createObject("jbpm.job.executor"));
-    // start and end a process instance, confirm no exception gets thrown
+    ObjectFactory objectFactory = jbpmContext.getObjectFactory();
+    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();

Added: jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/TestCallback.java
===================================================================
--- jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/TestCallback.java	                        (rev 0)
+++ jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/TestCallback.java	2008-09-04 21:15:04 UTC (rev 2119)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.job.executor;
+
+import java.io.Serializable;
+
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jbpm.JbpmContext;
+import org.jbpm.graph.def.Event;
+
+public class TestCallback implements Serializable {
+
+  private static final long serialVersionUID = 1L;
+  private static final Log log = LogFactory.getLog(TestCallback.class);
+
+  public void processStart() {
+    registerNotification(Event.EVENTTYPE_PROCESS_START);
+  }
+
+  public void processEnd() {
+    registerNotification(Event.EVENTTYPE_PROCESS_END);
+  }
+
+  public void nodeEnter() {
+    registerNotification(Event.EVENTTYPE_NODE_ENTER);
+  }
+
+  public void nodeLeave() {
+    registerNotification(Event.EVENTTYPE_NODE_LEAVE);
+  }
+
+  public void taskCreate() {
+    registerNotification(Event.EVENTTYPE_TASK_CREATE);
+  }
+
+  public void taskEnd() {
+    registerNotification(Event.EVENTTYPE_TASK_END);
+  }
+
+  public void timerCreate() {
+    registerNotification(Event.EVENTTYPE_TIMER_CREATE);
+  }
+
+  public void timer() {
+    registerNotification(Event.EVENTTYPE_TIMER);
+  }
+
+  private static void registerNotification(final String event) {
+    Synchronization notification = new Synchronization() {
+
+      public void beforeCompletion() {
+        // nothing to do here
+      }
+
+      public void afterCompletion(int status) {
+        if (status == Status.STATUS_COMMITTED) {
+          log.info("delivering " + event + " notification");
+          synchronized (event) {
+            event.notify();
+          }
+        }
+      }
+
+    };
+    JbpmContext.getCurrentJbpmContext()
+        .getSession()
+        .getTransaction()
+        .registerSynchronization(notification);
+  }
+
+  public static void waitForEvent(String event) {
+    synchronized (event) {
+      try {
+        event.wait(30000);
+      }
+      catch (InterruptedException e) {
+        // reassert interruption
+        Thread.currentThread().interrupt();
+      }
+    }
+  }
+}
\ No newline at end of file

Modified: jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/TimerOnTimerDbTest.java
===================================================================
--- jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/TimerOnTimerDbTest.java	2008-09-04 20:04:22 UTC (rev 2118)
+++ jbpm3/trunk/modules/jpdl/core/src/test/java/org/jbpm/job/executor/TimerOnTimerDbTest.java	2008-09-04 21:15:04 UTC (rev 2119)
@@ -21,13 +21,6 @@
  */
 package org.jbpm.job.executor;
 
-import java.io.Serializable;
-
-import javax.transaction.Status;
-import javax.transaction.Synchronization;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.jbpm.db.AbstractDbTestCase;
 import org.jbpm.graph.def.Event;
 import org.jbpm.graph.def.ProcessDefinition;
@@ -68,77 +61,4 @@
       stopJobExecutor();
     }
   }
-
-  public static class TestCallback implements Serializable {
-
-    private static final long serialVersionUID = 1L;
-    private static final Log log = LogFactory.getLog(TestCallback.class);
-
-    public void processStart() {
-      registerNotification(Event.EVENTTYPE_PROCESS_START);
-    }
-
-    public void processEnd() {
-      registerNotification(Event.EVENTTYPE_PROCESS_END);
-    }
-
-    public void nodeEnter() {
-      registerNotification(Event.EVENTTYPE_NODE_ENTER);
-    }
-
-    public void nodeLeave() {
-      registerNotification(Event.EVENTTYPE_NODE_LEAVE);
-    }
-
-    public void taskCreate() {
-      registerNotification(Event.EVENTTYPE_TASK_CREATE);
-    }
-
-    public void taskEnd() {
-      registerNotification(Event.EVENTTYPE_TASK_END);
-    }
-
-    public void timerCreate() {
-      registerNotification(Event.EVENTTYPE_TIMER_CREATE);
-    }
-
-    public void timer() {
-      registerNotification(Event.EVENTTYPE_TIMER);
-    }
-
-    private static void registerNotification(final String event) {
-      Synchronization notification = new Synchronization() {
-
-        public void beforeCompletion() {
-          // nothing to do here
-        }
-
-        public void afterCompletion(int status) {
-          if (status == Status.STATUS_COMMITTED) {
-            log.info("delivering " + event + " notification");
-            synchronized (event) {
-              event.notify();
-            }
-          }
-        }
-
-      };
-      jbpmConfiguration.getCurrentJbpmContext()
-          .getSession()
-          .getTransaction()
-          .registerSynchronization(notification);
-    }
-
-    public static void waitForEvent(String event) {
-      synchronized (event) {
-        try {
-          event.wait(60000);
-        }
-        catch (InterruptedException e) {
-          // reassert interruption
-          Thread.currentThread().interrupt();
-        }
-      }
-    }
-  }
 }




More information about the jbpm-commits mailing list