[jbpm-commits] JBoss JBPM SVN: r1921 - jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Aug 18 07:50:23 EDT 2008


Author: porcherg
Date: 2008-08-18 07:50:23 -0400 (Mon, 18 Aug 2008)
New Revision: 1921

Added:
   jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/FailRecursivelyTestCommand.java
Modified:
   jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTest.java
Log:
add test for JBPM-1685

Added: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/FailRecursivelyTestCommand.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/FailRecursivelyTestCommand.java	                        (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/FailRecursivelyTestCommand.java	2008-08-18 11:50:23 UTC (rev 1921)
@@ -0,0 +1,76 @@
+/*
+ * 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.pvm.internal.jobexecutor;
+
+import org.jbpm.pvm.env.Environment;
+import org.jbpm.pvm.internal.cmd.Command;
+import org.jbpm.pvm.internal.job.CommandMessage;
+import org.jbpm.pvm.internal.log.Log;
+import org.jbpm.pvm.internal.wire.descriptor.IntegerDescriptor;
+import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
+
+
+/**
+ * @author Tom Baeyens
+ * @author Guillaume Porcher
+ * 
+ * Simple command that will create an exception during execution. 
+ * The exception will generate a stacktrace with variable length 
+ * (controlled by the recursionInitialDepth parameter).
+ * 
+ * This class is to test the persistence of exception stacktrace in jobs.
+ */
+public class FailRecursivelyTestCommand implements Command<Object> {
+
+  private static final long serialVersionUID = 1L;
+  private static final Log log = Log.getLog(FailRecursivelyTestCommand.class.getName());
+  
+  int recursionInitialDepth;
+  
+  public FailRecursivelyTestCommand() {
+  }
+
+  private void recursiveException(int val) {
+    if (val <= 0) {
+      throw new RuntimeException("val <= 0");
+    }
+    try {
+      recursiveException(val-1);
+    } catch (Exception e) {
+      throw new RuntimeException("Error in reccursive call", e);
+    }
+  }
+  
+  public static CommandMessage createMessage(int recursionInitialDepth) {
+    CommandMessage commandMessage = new CommandMessage();
+    ObjectDescriptor commandDescriptor = new ObjectDescriptor(FailRecursivelyTestCommand.class);
+    commandDescriptor.addInjection("recursionInitialDepth", new IntegerDescriptor(recursionInitialDepth));
+    commandMessage.setCommandDescriptor(commandDescriptor);
+    return commandMessage;
+  }
+
+  public Object execute(Environment environment) throws Exception {
+    recursiveException(recursionInitialDepth);
+    return null;
+  }
+
+}


Property changes on: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/FailRecursivelyTestCommand.java
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTest.java	2008-08-18 10:55:41 UTC (rev 1920)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTest.java	2008-08-18 11:50:23 UTC (rev 1921)
@@ -33,7 +33,6 @@
 import org.jbpm.pvm.client.ClientProcessDefinition;
 import org.jbpm.pvm.client.ClientProcessInstance;
 import org.jbpm.pvm.env.Environment;
-import org.jbpm.pvm.env.Transaction;
 import org.jbpm.pvm.internal.cmd.Command;
 import org.jbpm.pvm.internal.job.CommandMessage;
 import org.jbpm.pvm.internal.job.JobImpl;
@@ -47,6 +46,7 @@
 
 /**
  * @author Tom Baeyens
+ * @author Guillaume Porcher
  */
 public class JobExecutorTest extends DbTestCase {
   
@@ -203,6 +203,39 @@
     });
   }
 
+  public void testExceptionInJob() {
+
+    JobExecutor jobExecutor = getEnvironmentFactory().get(JobExecutor.class);
+    jobExecutor.start();
+    try {
+      commandService.execute(new Command<Object>() {
+        // size of the recursion (to create a long stacktrace)
+        // 10 creates an exception if there is a limit of 4000 characters
+        int recursiveDepth = 10; 
+        
+        public Object execute(Environment environment) throws Exception {
+          MessageSession messageSession = environment.get(MessageSession.class);
+          CommandMessage commandMessage = FailRecursivelyTestCommand.createMessage(recursiveDepth);
+          messageSession.send(commandMessage);
+          return null;
+        }
+      });
+      
+      waitTillNoMoreMessages(jobExecutor);
+
+    } finally {
+      jobExecutor.stop(true);
+    }
+    
+    commandService.execute(new Command<Object>() {
+      public Object execute(Environment environment) throws Exception {
+        PvmDbSession pvmDbSession = environment.get(PvmDbSession.class);
+        List<Job> deadJobs = pvmDbSession.findDeadJobs();
+        assertEquals("there should be one dead jobImpl", 1, deadJobs.size());
+        return null;
+      }
+    });
+  }
   // helper methods ///////////////////////////////////////////////////////////
 
   void insertTestMessages() {




More information about the jbpm-commits mailing list