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

do-not-reply at jboss.org do-not-reply at jboss.org
Sat Jul 4 23:55:25 EDT 2009


Author: alex.guizar at jboss.com
Date: 2009-07-04 23:55:25 -0400 (Sat, 04 Jul 2009)
New Revision: 5228

Modified:
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1072/JBPM1072Test.java
Log:
make JBPM1072Test resistant to stale state exceptions

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1072/JBPM1072Test.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1072/JBPM1072Test.java	2009-07-04 15:19:37 UTC (rev 5227)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/jbpm1072/JBPM1072Test.java	2009-07-05 03:55:25 UTC (rev 5228)
@@ -45,7 +45,7 @@
   private static final int JOB_EXECUTOR_COUNT = 4;
 
   private JobExecutor[] jobExecutors = new JobExecutor[JOB_EXECUTOR_COUNT];
-  private long processDefinitionId;
+  private ProcessDefinition processDefinition;
 
   private static final String PROCESS_DEFINITION = "<process-definition name='job-executors'>" +
       "  <event type='process-end'>" +
@@ -72,10 +72,9 @@
   protected void setUp() throws Exception {
     super.setUp();
 
-    ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(PROCESS_DEFINITION);
+    processDefinition = ProcessDefinition.parseXmlString(PROCESS_DEFINITION);
     jbpmContext.deployProcessDefinition(processDefinition);
     newTransaction();
-    processDefinitionId = processDefinition.getId();
 
     startJobExecutors();
   }
@@ -83,7 +82,7 @@
   protected void tearDown() throws Exception {
     stopJobExecutors();
 
-    graphSession.deleteProcessDefinition(processDefinitionId);
+    graphSession.deleteProcessDefinition(processDefinition.getId());
 
     EventCallback.clear();
     super.tearDown();
@@ -93,10 +92,7 @@
     // Won't Fix [JBPM-1072] Concurrent JobExecutors can process the same job in parallel
     if (getHibernateDialect().indexOf("HSQL") != -1) return;
 
-    Counter.resetCount();
-
     // kick off process instance
-    ProcessDefinition processDefinition = graphSession.loadProcessDefinition(processDefinitionId);
     ProcessInstance processInstance = new ProcessInstance(processDefinition);
     processInstance.getContextInstance().setVariable("eventCallback", new EventCallback());
     processInstance.signal();
@@ -105,13 +101,14 @@
     commitAndCloseSession();
     try {
       EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
-      assertEquals(2, Counter.getCount());
-
-      waitForJobs(EventCallback.DEFAULT_TIMEOUT);
     }
     finally {
       beginSessionTransaction();
     }
+
+    processInstance = jbpmContext.loadProcessInstance(processInstance.getId());
+    Integer count = (Integer) processInstance.getContextInstance().getVariable("count");
+    assertEquals(2, count.intValue());
   }
 
   private void startJobExecutors() {
@@ -136,25 +133,14 @@
 
   public static class Counter implements ActionHandler {
 
-    private volatile static int count;
-
     private static final long serialVersionUID = 1L;
 
     public void execute(ExecutionContext exeContext) throws Exception {
-      incrementCount();
+      Integer count = (Integer) exeContext.getVariable("count");
+      count = count != null ? new Integer(count.intValue() + 1) : new Integer(1);
+      exeContext.setVariable("count", count);
+
       exeContext.leaveNode();
     }
-
-    public static int getCount() {
-      return count;
-    }
-
-    public static void resetCount() {
-      count = 0;
-    }
-
-    private static synchronized void incrementCount() {
-      ++count;
-    }
   }
 }




More information about the jbpm-commits mailing list