[jbpm-commits] JBoss JBPM SVN: r1677 - in jbpm4/pvm/trunk/modules/core/src: main/java/org/jbpm/pvm/internal/model and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Jul 21 04:34:37 EDT 2008


Author: pascal.verdage
Date: 2008-07-21 04:34:37 -0400 (Mon, 21 Jul 2008)
New Revision: 1677

Modified:
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/ExecuteJobCmd.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
   jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/timer/TimerIntegrationTest.java
Log:
fix indentation in ExecuteJobCommand
fix destroyTimers implementation + add equals method (hibernate proxies)
add tests for timers

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/ExecuteJobCmd.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/ExecuteJobCmd.java	2008-07-18 15:41:20 UTC (rev 1676)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/jobexecutor/ExecuteJobCmd.java	2008-07-21 08:34:37 UTC (rev 1677)
@@ -50,19 +50,19 @@
   }
 
   public Job execute(Environment environment) throws Exception {
-	Session session = environment.get(Session.class);
-	if (session==null) {
-	  throw new PvmException("no hibernate-session configured to get job "+jobDbid+" for execution");
-	}
-  JobImpl<?> job = (JobImpl<?>) session.get(JobImpl.class, jobDbid);
+  	Session session = environment.get(Session.class);
+  	if (session==null) {
+  	  throw new PvmException("no hibernate-session configured to get job "+jobDbid+" for execution");
+  	}
+    JobImpl<?> job = (JobImpl<?>) session.get(JobImpl.class, jobDbid);
 
-	// in case of exclusive jobs, the jobImpl might have been deleted
-	// before we execute it (they are in a list)
-	if (job != null) {
+  	// in case of exclusive jobs, the jobImpl might have been deleted
+  	// before we execute it (they are in a list)
+  	if (job != null) {
 	    try {
 	      log.debug("executing job "+job+"...");
 	      job.execute(environment);
-	
+
 	      // if this job is locked too long, it could be unlocked by the lockmonitor and 
 	      // executed by another thread.
 	      Date lockExpirationDate = job.getLockExpirationTime();

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java	2008-07-18 15:41:20 UTC (rev 1676)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java	2008-07-21 08:34:37 UTC (rev 1677)
@@ -58,6 +58,7 @@
 import org.jbpm.pvm.internal.type.variable.NullVariable;
 import org.jbpm.pvm.internal.type.variable.UnpersistableVariable;
 import org.jbpm.pvm.internal.util.Clock;
+import org.jbpm.pvm.internal.util.EqualsUtil;
 import org.jbpm.pvm.internal.util.Priority;
 import org.jbpm.pvm.job.Timer;
 import org.jbpm.pvm.listener.EventListener;
@@ -802,12 +803,23 @@
   }
 
   protected void destroyTimers(CompositeElementImpl scope) {
-    // TODO: is it correct?
-    TimerSession timerSession = Environment.getCurrent().get(TimerSession.class);
+    log.debug("destroying timers of "+toString());
     if (hasTimers && timers!=null && !timers.isEmpty()) {
+      // get the TimerSession from the environment
+      Environment environment = Environment.getCurrent();
+      if (environment==null) {
+        throw new PvmException("non environment for initializing timers");
+      }
+      TimerSession timerSession = environment.get(TimerSession.class);
+      if (timerSession==null) {
+        throw new PvmException("no TimerSession in environment for initializing timers");
+      }
       for (Timer timer : timers) {
         timerSession.cancel(timer);
+        System.out.println("timer deleted");
       }
+      timers.clear();
+      hasTimers = false;
     }
   }
 
@@ -1314,6 +1326,13 @@
     throw new PvmException("unsuppported extension "+extensionClass.getName());
   }
 
+  // equals ///////////////////////////////////////////////////////////////////
+  // hack to support comparing hibernate proxies against the real objects
+  // since this always falls back to ==, we don't need to overwrite the hashcode
+  public boolean equals(Object o) {
+    return EqualsUtil.equals(this, o);
+  }
+
   // getters and setters /////////////////////////////////////////////////////////
 
   public List<Comment> getComments() {

Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/timer/TimerIntegrationTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/timer/TimerIntegrationTest.java	2008-07-18 15:41:20 UTC (rev 1676)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/timer/TimerIntegrationTest.java	2008-07-21 08:34:37 UTC (rev 1677)
@@ -33,6 +33,7 @@
 import org.jbpm.pvm.model.OpenExecution;
 import org.jbpm.pvm.model.ProcessDefinition;
 import org.jbpm.pvm.model.ProcessFactory;
+import org.jbpm.pvm.samples.activities.AutomaticActivity;
 import org.jbpm.pvm.session.DbSession;
 import org.jbpm.pvm.session.PvmDbSession;
 import org.jbpm.pvm.test.base.DbTestCase;
@@ -244,9 +245,6 @@
     // timer execution is tested in testTimerExecution
   }
 
-  //TODO: the test fails because the child execution is not deleted and the timer
-  // still exist.
-  //Still, main execution is in the the good state
   public void testReschedulingTimer() {
     Date now = Clock.getCurrentTime();
     long twoDaysFromNow = now.getTime() + twoDaysDuration;
@@ -279,22 +277,19 @@
       // check that timer's dueDate is good
       Timer timer = child.getTimers().iterator().next();
       assertTrue("error is "+(timer.getDueDate().getTime()-twoDaysFromNow)+" millis",
-          twoDaysFromNow <= timer.getDueDate().getTime());
+          twoDaysFromNow <= timer.getDueDate().getTime()+200);
 
+      // set next minimum due date
+      twoDaysFromNow = Clock.getCurrentTime().getTime() + twoDaysDuration;
+
       // execute timer
-      twoDaysFromNow = Clock.getCurrentTime().getTime() + twoDaysDuration - 100;
       JobTestHelper jobTestHelper = getEnvironmentFactory().get(JobTestHelper.class);
       jobTestHelper.executeTimer(timer.getDbid());
       child = loadExecutionFromDb(child.getDbid());
     }
 
-    // check that the subExecution was deleted
-    if (child!=null) {
-      System.out.println(child.getNodeName());
-      System.out.println(child.getVariable("counter"));
-      execution = loadExecutionFromDb(processInstance.getDbid());
-      System.out.println(execution.getNodeName());
-    }
+    newTransaction();
+    child = loadExecutionFromDb(child.getDbid());
     assertNull(child);
 
     // check that timers have been deleted
@@ -307,45 +302,42 @@
     assertEquals("reassign", execution.getNodeName());
   }
 
-  /*
-  TODO finish after refactoring
-
-  public void testTimerEndingProcess() {
-    ProcessDefinition processDefinition = ProcessFactory.build("timed2")
-      .node("get input").initial().behaviour(WaitState.class)
-        .timer("2 business days", "escalate")
-        .transition("escalate").to("manager decision")
-        .transition("submit").to("process input")
-      .node("process input").behaviour(WaitState.class)
-      .node("manager decision").behaviour(AutomaticActivity.class)
+  public void testTimerEndingProcessExecution() {
+    ProcessDefinition processDefinition = ProcessFactory.build("timerEndingProcess")
+      .node("decide").initial().behaviour(WaitState.class)
+        .timer("2 business days", "timeout")
+        .transition("decision made").to("response") // first defined transition is the default one
+        .transition("timeout").to("reassign")
+      .node("reassign").behaviour(AutomaticActivity.class)
+      .node("response").behaviour(WaitState.class)
     .done();
     
-    EnvironmentFactory environmentFactory = TimerConfiguration.getEnvironmentFactory();
-    ProcessService processService = environmentFactory.get(ProcessService.class);
-  
-    processService.deploy(processDefinition);
-    
-    Date now = new Date();
-    long fourtyEightHoursFromNow = now.getTime() + 48*60*60*1000;
-  
-    ExecutionService executionService = TimerConfiguration.getExecutionService();
-    Execution execution = executionService.startExecution("timed2");
+    ExecutionImpl processInstance = deployAndInstanciateProcess(processDefinition);
 
-    ActivityInstance activityInstance = execution.getActivityInstance();
-    Node node = activityInstance.getNode();
-    assertEquals("get input", node.getName());
-    Timer timer = activityInstance
-            .getTimers()
-            .iterator()
-            .next();
+    Execution execution = processInstance;
+    OpenExecution child = ((OpenExecution) execution).getExecutions().iterator().next();
+    assertEquals("decide", child.getNodeName());
 
-    assertTrue(fourtyEightHoursFromNow < timer.getDueDate().getTime());
-    
-    JobTestHelper jobTestHelper = environmentFactory.get(JobTestHelper.class);
-    execution = jobTestHelper.executeTimer(timer.getDbid());
-    
-    assertEquals("manager decision", execution.getNode().getName());
+    // timer execution
+    Timer timer = child.getTimers().iterator().next();
+
+    JobTestHelper jobTestHelper = getEnvironmentFactory().get(JobTestHelper.class);
+    child = (OpenExecution) jobTestHelper.executeTimer(timer.getDbid());
+    assertEquals(Execution.STATE_ENDED, child.getState());
+
+    // check that the subExecution was deleted
+    child = loadExecutionFromDb(child.getDbid());
+    assertNull(child);
+
+    // check that timers have been deleted
+    List<Job> jobs = Environment.getCurrent().get(PvmDbSession.class).findAllJobs();
+    assertNotNull(jobs);
+    assertTrue(jobs.isEmpty());
+
+    // check that process is in the right state
+    execution = loadExecutionFromDb(processInstance.getDbid());
+    assertEquals("reassign", execution.getNodeName());
     assertEquals(Execution.STATE_ENDED, execution.getState());
   }
-  */
+
 }




More information about the jbpm-commits mailing list