[jbpm-commits] JBoss JBPM SVN: r5006 - in jbpm4/trunk/modules: pvm/src/main/java/org/jbpm/pvm/internal/job and 5 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Jun 8 18:57:42 EDT 2009


Author: tom.baeyens at jboss.com
Date: 2009-06-08 18:57:42 -0400 (Mon, 08 Jun 2009)
New Revision: 5006

Added:
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/execution/ExecutionQueryTest.java
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/timer/
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/timer/TimerTest.java
Modified:
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/TimerImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTimerSession.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
Log:
JBPM-2055 added ExecutionQueryTest and fixed timer deletion problem

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java	2009-06-08 11:49:49 UTC (rev 5005)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java	2009-06-08 22:57:42 UTC (rev 5006)
@@ -33,6 +33,7 @@
 import org.jbpm.api.ProcessDefinition;
 import org.jbpm.api.client.ClientExecution;
 import org.jbpm.api.client.ClientProcessDefinition;
+import org.jbpm.api.env.Environment;
 import org.jbpm.api.history.HistoryProcessInstance;
 import org.jbpm.api.task.Task;
 import org.jbpm.internal.log.Log;
@@ -264,9 +265,12 @@
       }
 
       // delete remaining jobs for this process instance
+      JobImpl currentJob = Environment.getFromCurrent(JobImpl.class, false);
       List<JobImpl> jobs = findJobs(processInstanceId);
       for (JobImpl job: jobs) {
-        session.delete(job);
+        if (job!=currentJob){ 
+          session.delete(job);
+        }
       }
 
       if (log.isDebugEnabled()) {

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/TimerImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/TimerImpl.java	2009-06-08 11:49:49 UTC (rev 5005)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/job/TimerImpl.java	2009-06-08 22:57:42 UTC (rev 5006)
@@ -47,7 +47,7 @@
  * @author Pascal Verdage
  * @author Alejandro Guizar
  */
-public class TimerImpl extends JobImpl<Boolean> implements Timer {
+public class TimerImpl extends JobImpl<Void> implements Timer {
 
   private static final long serialVersionUID = 1L;
   private static final Log log = Log.getLog(TimerImpl.class.getName());
@@ -94,7 +94,7 @@
     }
   }
 
-  public Boolean execute(Environment environment) throws Exception {
+  public Void execute(Environment environment) throws Exception {
     if (log.isDebugEnabled()) log.debug("executing " + this);
 
     if (environment==null) {
@@ -112,7 +112,6 @@
       execution.fire(eventName, eventSource);
     }
     
-    boolean deleteThisJob = true;
     // if there is no repeat on this timer
     if (repeat==null) {
       // delete the job
@@ -124,7 +123,6 @@
       dbSession.delete(this);
 
     } else { // there is a repeat on this timer
-      deleteThisJob = false;
       // suppose that it took the timer runner thread a very long time to execute the timers
       // then the repeat action dueDate could already have passed
       do {
@@ -147,8 +145,8 @@
         transaction.registerSynchronization(jobNotificator);
       }
     }
-
-    return deleteThisJob;
+    
+    return null;
   }
 
   public String toString() {

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTimerSession.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTimerSession.java	2009-06-08 11:49:49 UTC (rev 5005)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTimerSession.java	2009-06-08 22:57:42 UTC (rev 5006)
@@ -48,9 +48,14 @@
   boolean jobExecutorNotificationScheduled = false;
 
   public void schedule(Timer timer) {
+    if (timer == null) throw new JbpmException("null timer scheduled");
+    if (timer.getExecution() == null) throw new JbpmException("timer has no execution specified");
+    if ((timer.getSignalName() == null) && (timer.getEventName() == null)) throw new JbpmException("timer has no signalName or eventName specified");
+    if (timer.getDueDate() == null) throw new JbpmException("timer scheduled at null date");
+
     log.debug("scheduling " + timer);
-    validate(timer);
     session.save(timer);
+    
     if ( (!jobExecutorNotificationScheduled)
          && (jobExecutor!=null)
        ) {
@@ -59,20 +64,6 @@
     }
   }
 
-  protected void validate(Timer timer) {
-    if (timer == null)
-      throw new JbpmException("null timer scheduled");
-    if (timer.getExecution() == null) {
-      throw new JbpmException("timer has no execution specified");
-    }
-    if ((timer.getSignalName() == null) && (timer.getEventName() == null))
-      throw new JbpmException("timer has no signalName or eventName specified");
-    if (timer.getDueDate() == null)
-      throw new JbpmException("timer scheduled at null date");
-    if (timer.getDueDate().getTime() < 0)
-      throw new JbpmException("timer scheduled with a negative date");
-  }
-
   public void cancel(Timer timer) {
     log.debug("canceling " + timer);
     if (timer != null) {

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java	2009-06-08 11:49:49 UTC (rev 5005)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java	2009-06-08 22:57:42 UTC (rev 5006)
@@ -42,6 +42,7 @@
 import org.jbpm.api.client.ClientProcessInstance;
 import org.jbpm.api.env.Context;
 import org.jbpm.api.env.Environment;
+import org.jbpm.api.job.Job;
 import org.jbpm.api.job.Timer;
 import org.jbpm.api.listener.EventListenerExecution;
 import org.jbpm.api.model.Activity;
@@ -60,6 +61,7 @@
 import org.jbpm.pvm.internal.history.events.DecisionEnd;
 import org.jbpm.pvm.internal.history.events.ProcessInstanceEnd;
 import org.jbpm.pvm.internal.history.events.ProcessInstanceStart;
+import org.jbpm.pvm.internal.job.JobImpl;
 import org.jbpm.pvm.internal.job.MessageImpl;
 import org.jbpm.pvm.internal.model.op.AtomicOperation;
 import org.jbpm.pvm.internal.model.op.MoveToChildActivity;
@@ -276,7 +278,11 @@
       log.debug("destroying timers of "+this);
       List<Timer> timers = timerSession.findTimersByExecution(this);
       for (Timer timer: timers) {
-        timerSession.cancel(timer);
+        
+        Job job = Environment.getFromCurrent(JobImpl.class, false);
+        if (timer!=job) {
+          timerSession.cancel(timer);
+        }
       }
     }
   }

Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/execution/ExecutionQueryTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/execution/ExecutionQueryTest.java	                        (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/execution/ExecutionQueryTest.java	2009-06-08 22:57:42 UTC (rev 5006)
@@ -0,0 +1,65 @@
+/*
+ * 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.test.execution;
+
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ExecutionQueryTest extends JbpmTestCase {
+
+  public void testQueryForEndedExecutions() {
+    deployJpdlXmlString(
+      "<process name='p'>" +
+      "  <start>" +
+      "    <transition to='a' />" +
+      "  </start>" +
+      "  <state name='a'>" +
+      "    <transition to='end' />" +
+      "  </state>" +
+      "  <end name='end' />" +
+      "</process>"
+    );
+
+    ProcessInstance processInstance = executionService.startProcessInstanceByKey("p");
+    executionService.signalExecutionById(processInstance.getId());
+    
+    processInstance = executionService.startProcessInstanceByKey("p");
+    executionService.signalExecutionById(processInstance.getId());
+    
+    processInstance = executionService.startProcessInstanceByKey("p");
+    executionService.signalExecutionById(processInstance.getId());
+    
+    processInstance = executionService.startProcessInstanceByKey("p");
+    executionService.signalExecutionById(processInstance.getId());
+
+    assertEquals(0, 
+      executionService.createProcessInstanceQuery()
+          .processDefinitionId("p-1")
+          .list()
+          .size()
+    );
+  }
+}


Property changes on: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/execution/ExecutionQueryTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/timer/TimerTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/timer/TimerTest.java	                        (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/timer/TimerTest.java	2009-06-08 22:57:42 UTC (rev 5006)
@@ -0,0 +1,60 @@
+/*
+ * 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.test.timer;
+
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.job.Job;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class TimerTest extends JbpmTestCase {
+
+  public void testSignalExecutionById() {
+    deployJpdlXmlString(
+      "<process name='Insurance claim' key='ICL'>" +
+      "  <start>" +
+      "    <transition to='a' />" +
+      "  </start>" +
+      "  <state name='a'>" +
+      "    <transition to='b' />" +
+      "    <transition name='timeout' to='escalate'>" +
+      "      <timer duedate='2 minutes' />" +
+      "    </transition>" +
+      "  </state>" +
+      "  <state name='b' />" +
+      "  <end name='escalate' />" +
+      "</process>"
+    );
+
+    ProcessInstance processInstance = executionService.startProcessInstanceByKey("ICL", "82436");
+
+    Job job = managementService.createJobQuery()
+      .processInstanceId(processInstance.getId())
+      .uniqueResult();
+    
+    managementService.executeJob(job.getDbid());
+  }
+
+}


Property changes on: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/timer/TimerTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain




More information about the jbpm-commits mailing list