[jbpm-commits] JBoss JBPM SVN: r3387 - in jbpm4/trunk/modules: test-base/src/main/java/org/jbpm/test and 8 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Mon Dec 15 05:48:39 EST 2008
Author: tom.baeyens at jboss.com
Date: 2008-12-15 05:48:39 -0500 (Mon, 15 Dec 2008)
New Revision: 3387
Added:
jbpm4/trunk/modules/test-load/src/test/java/org/
jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/
jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/
jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/
jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/ExclusiveTestCommand.java
jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/FailOnceTestCommand.java
jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/FailingTestCommand.java
jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/GenerateExceptionTestCommand.java
jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/JobExecutorIsolationDbTest.java
jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/JobExecutorTest.java
jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/TestMessageCommand.java
jbpm4/trunk/modules/test-load/src/test/resources/
jbpm4/trunk/modules/test-load/src/test/resources/hibernate.properties
jbpm4/trunk/modules/test-load/src/test/resources/jbpm.cfg.xml
jbpm4/trunk/modules/test-load/src/test/resources/logging.properties
Removed:
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/ExclusiveTestCommand.java
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/FailOnceTestCommand.java
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/FailingTestCommand.java
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/GenerateExceptionTestCommand.java
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorIsolationDbTest.java
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTest.java
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/TestMessageCommand.java
Modified:
jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/DbTestCase.java
jbpm4/trunk/modules/test-load/pom.xml
Log:
set up test-load
Deleted: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/ExclusiveTestCommand.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/ExclusiveTestCommand.java 2008-12-15 10:16:26 UTC (rev 3386)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/ExclusiveTestCommand.java 2008-12-15 10:48:39 UTC (rev 3387)
@@ -1,98 +0,0 @@
-/*
- * 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 java.util.HashSet;
-import java.util.Map;
-import java.util.Random;
-import java.util.Set;
-
-import org.hibernate.Session;
-import org.jbpm.cmd.Command;
-import org.jbpm.env.Environment;
-import org.jbpm.log.Log;
-import org.jbpm.model.OpenExecution;
-import org.jbpm.pvm.internal.job.CommandMessage;
-import org.jbpm.pvm.internal.model.ExecutionImpl;
-import org.jbpm.pvm.internal.wire.descriptor.LongDescriptor;
-import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
-import org.jbpm.session.DbSession;
-
-
-/**
- * @author Tom Baeyens
- */
-public class ExclusiveTestCommand implements Command<Object> {
-
- private static final long serialVersionUID = 1L;
- private static final Log log = Log.getLog(ExclusiveTestCommand.class.getName());
- static Random random = new Random();
-
- long executionId;
-
- public ExclusiveTestCommand() {
- }
-
- public static CommandMessage createMessage(OpenExecution execution) {
- CommandMessage commandMessage = new CommandMessage();
- commandMessage.setExecution((ExecutionImpl) execution);
- commandMessage.setExclusive(true);
-
- ObjectDescriptor commandDescriptor = new ObjectDescriptor(ExclusiveTestCommand.class);
- commandDescriptor.addInjection("executionId", new LongDescriptor(execution.getDbid()));
- commandMessage.setCommandDescriptor(commandDescriptor);
- return commandMessage;
- }
-
- public Object execute(Environment environment) throws Exception {
- Long threadId = Thread.currentThread().getId();
-
- Session session = environment.get(Session.class);
- ExecutionImpl execution = (ExecutionImpl) session.get(ExecutionImpl.class, executionId);
-
- String executionKey = execution.getKey();
-
- // exclusiveMessageIds maps execution keys to a set of thread ids.
- // the idea is that for each execution, all the exclusive jobs will
- // be executed by 1 thread sequentially.
-
- // in the end, each set should contain exactly 1 element
- Set<Long> groupMessages = JobExecutorTest.exclusiveThreadIds.get(executionKey);
- if (groupMessages==null) {
- groupMessages = new HashSet<Long>();
- JobExecutorTest.exclusiveThreadIds.put(executionKey, groupMessages);
- }
- groupMessages.add(threadId);
-
- // let's assume that an average jobImpl takes between 0 and 150 millis to complete.
- int workTime = random.nextInt(150);
- log.debug("executing exclusive message for "+execution+". this is going to take "+workTime+"ms");
- try {
- Thread.sleep(workTime);
- } catch (RuntimeException e) {
- log.debug("sleeping was interrupted");
- }
-
- return null;
- }
-
-}
Deleted: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/FailOnceTestCommand.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/FailOnceTestCommand.java 2008-12-15 10:16:26 UTC (rev 3386)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/FailOnceTestCommand.java 2008-12-15 10:48:39 UTC (rev 3387)
@@ -1,78 +0,0 @@
-/*
- * 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.cmd.Command;
-import org.jbpm.env.Environment;
-import org.jbpm.log.Log;
-import org.jbpm.model.Comment;
-import org.jbpm.pvm.internal.job.CommandMessage;
-import org.jbpm.pvm.internal.job.MessageImpl;
-import org.jbpm.pvm.internal.model.CommentImpl;
-import org.jbpm.pvm.internal.wire.descriptor.IntegerDescriptor;
-import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
-import org.jbpm.session.DbSession;
-
-
-/**
- * @author Tom Baeyens
- */
-public class FailOnceTestCommand implements Command<Object> {
-
- private static final long serialVersionUID = 1L;
- private static final Log log = Log.getLog(FailOnceTestCommand.class.getName());
-
- int messageId;
-
- public FailOnceTestCommand() {
- }
-
- public static CommandMessage createMessage(int messageId) {
- CommandMessage commandMessage = new CommandMessage();
- ObjectDescriptor commandDescriptor = new ObjectDescriptor(FailOnceTestCommand.class);
- commandDescriptor.addInjection("messageId", new IntegerDescriptor(messageId));
- commandMessage.setCommandDescriptor(commandDescriptor);
- return commandMessage;
- }
-
- public Object execute(Environment environment) throws Exception {
- DbSession dbSession = environment.get(DbSession.class);
-
- // this message execution should be rolled back
- Comment comment = new CommentImpl(Integer.toString(messageId));
- dbSession.save(comment);
-
- if (!JobExecutorTest.failOnceMessageIds.contains(messageId)) {
- // registering the failed message in a non-transactional resource
- // so the messageId will still be added even after the transaction has rolled back
- log.debug("adding failonce message "+messageId);
- JobExecutorTest.failOnceMessageIds.add(messageId);
-
- throw new RuntimeException("failing once");
- }
-
- log.debug("message "+messageId+" now succeeds");
-
- return null;
- }
-
-}
Deleted: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/FailingTestCommand.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/FailingTestCommand.java 2008-12-15 10:16:26 UTC (rev 3386)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/FailingTestCommand.java 2008-12-15 10:48:39 UTC (rev 3387)
@@ -1,57 +0,0 @@
-/*
- * 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.cmd.Command;
-import org.jbpm.env.Environment;
-import org.jbpm.model.Comment;
-import org.jbpm.pvm.internal.job.CommandMessage;
-import org.jbpm.pvm.internal.model.CommentImpl;
-import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
-import org.jbpm.session.DbSession;
-
-
-/**
- * @author Tom Baeyens
- */
-public class FailingTestCommand implements Command<Object> {
-
- private static final long serialVersionUID = 1L;
-
- public Object execute(Environment environment) throws Exception {
- DbSession dbSession = environment.get(DbSession.class);
-
- // this message execution should be rolled back
- Comment comment = new CommentImpl("failing update");
- dbSession.save(comment);
-
- throw new RuntimeException("ooops");
- }
-
- public static CommandMessage createMessage() {
- CommandMessage commandMessage = new CommandMessage();
- ObjectDescriptor commandDescriptor = new ObjectDescriptor(FailingTestCommand.class);
- commandMessage.setCommandDescriptor(commandDescriptor);
- return commandMessage;
- }
-
-}
Deleted: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/GenerateExceptionTestCommand.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/GenerateExceptionTestCommand.java 2008-12-15 10:16:26 UTC (rev 3386)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/GenerateExceptionTestCommand.java 2008-12-15 10:48:39 UTC (rev 3387)
@@ -1,66 +0,0 @@
-/*
- * 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.cmd.Command;
-import org.jbpm.env.Environment;
-import org.jbpm.pvm.internal.job.CommandMessage;
-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 length parameter).
- *
- * This class is to test the persistence of exception stacktrace in jobs.
- */
-public class GenerateExceptionTestCommand implements Command<Object> {
-
- private static final long serialVersionUID = 1L;
-
- int length;
-
- public GenerateExceptionTestCommand() {
- }
-
- public static CommandMessage createMessage(int recursionInitialDepth) {
- CommandMessage commandMessage = new CommandMessage();
- ObjectDescriptor commandDescriptor = new ObjectDescriptor(GenerateExceptionTestCommand.class);
- commandDescriptor.addInjection("length", new IntegerDescriptor(recursionInitialDepth));
- commandMessage.setCommandDescriptor(commandDescriptor);
- return commandMessage;
- }
-
- public Object execute(Environment environment) throws Exception {
- StringBuilder stringBuilder = new StringBuilder();
- while (stringBuilder.length() < length) {
- stringBuilder.append("This is a test message. ");
- }
- throw new RuntimeException(stringBuilder.toString());
- }
-
-}
Deleted: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorIsolationDbTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorIsolationDbTest.java 2008-12-15 10:16:26 UTC (rev 3386)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorIsolationDbTest.java 2008-12-15 10:48:39 UTC (rev 3387)
@@ -1,86 +0,0 @@
-/**
- * Copyright (C) 2007 Bull S. A. S.
- * Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois
- * This library 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
- * version 2.1 of the License.
- * This library 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
- * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
- * Floor, Boston, MA 02110-1301, USA.
- **/
-package org.jbpm.pvm.internal.jobexecutor;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jbpm.cmd.Command;
-import org.jbpm.env.Environment;
-import org.jbpm.job.Message;
-import org.jbpm.log.Log;
-import org.jbpm.pvm.internal.job.CommandMessage;
-import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
-import org.jbpm.session.MessageSession;
-import org.jbpm.session.PvmDbSession;
-import org.jbpm.test.OldDbTestCase;
-
-
-/**
- * This class contains job executor tests which requires to have a read commited isolation level.
- *
- * @author Guillaume Porcher
- *
- */
-public class JobExecutorIsolationDbTest extends OldDbTestCase {
-
- static int jobExecutorTimeoutMillis = 500;
- static int checkInterval = 400;
-
- public static class SimpleTestCommand implements Command<Object> {
- private static final Log log = Log.getLog(SimpleTestCommand.class.getName());
-
- public Object execute(Environment environment) throws Exception {
- log.debug("command executed !");
- return null;
- }
- }
-
- public void testInsertMessage() {
- System.out.println("FIXME: JBPM-1769 fix db isolation test");
- }
-
-
- /*
- * Basic test that only shows a simple situation in which we need to have a read commited isolation level.
- */
-
- // FIX rename test method back to testInsertMessage
- public void dontTestInsertMessage() throws InterruptedException {
- JobExecutorTest.processedMessageIds = new ArrayList<Integer>();
- JobExecutor jobExecutor = getEnvironmentFactory().get(JobExecutor.class);
- jobExecutor.setIdleInterval(jobExecutorTimeoutMillis);
- jobExecutor.start();
- try {
- commandService.execute(new Command<Object>() {
- public Object execute(Environment environment) throws Exception {
- MessageSession messageSession = environment.get(MessageSession.class);
- CommandMessage commandMessage = new CommandMessage(new ObjectDescriptor(SimpleTestCommand.class));
- messageSession.send(commandMessage);
- List<Message> messages = environment.get(PvmDbSession.class).findMessages(0, 10);
- assertNotNull(messages);
- assertEquals(1, messages.size());
- Thread.sleep(jobExecutorTimeoutMillis * 2);
- messages = environment.get(PvmDbSession.class).findMessages(0, 10);
- assertNotNull(messages);
- assertEquals("Job has been executed before the transaction is committed !!", 1, messages.size());
- return null;
- }
- });
- Thread.sleep(jobExecutorTimeoutMillis * 2);
- } finally {
- jobExecutor.stop(true);
- }
- }
-}
Deleted: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTest.java 2008-12-15 10:16:26 UTC (rev 3386)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTest.java 2008-12-15 10:48:39 UTC (rev 3387)
@@ -1,378 +0,0 @@
-/*
- * 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 java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Timer;
-import java.util.TimerTask;
-
-import junit.framework.Test;
-
-import org.hibernate.Session;
-import org.jbpm.ProcessService;
-import org.jbpm.activity.ActivityExecution;
-import org.jbpm.activity.ExternalActivity;
-import org.jbpm.client.ClientExecution;
-import org.jbpm.client.ClientProcessDefinition;
-import org.jbpm.cmd.Command;
-import org.jbpm.env.Environment;
-import org.jbpm.job.Job;
-import org.jbpm.log.Log;
-import org.jbpm.model.Comment;
-import org.jbpm.pvm.internal.job.CommandMessage;
-import org.jbpm.pvm.internal.job.JobImpl;
-import org.jbpm.pvm.internal.svc.DeploymentImpl;
-import org.jbpm.pvm.model.ProcessFactory;
-import org.jbpm.session.MessageSession;
-import org.jbpm.session.PvmDbSession;
-import org.jbpm.test.EnvironmentFactoryTestSetup;
-import org.jbpm.test.OldDbTestCase;
-
-/**
- * @author Tom Baeyens
- * @author Guillaume Porcher
- */
-public class JobExecutorTest extends OldDbTestCase {
-
- private static final Log log = Log.getLog(JobExecutorTest.class.getName());
-
- static List<Integer> processedMessageIds;
- static Map<String, Set<Long>> exclusiveThreadIds;
- static List<Integer> failOnceMessageIds;
-
- static int nbrOfTestMessages = 50;
- static int timeoutMillis = 10000;
- static int checkInterval = 400;
- static int nbrOfTestMessagesPerExecution = 7;
- static int nbrOfTestExecutions = 5;
-
- public static Test suite()
- {
- return new EnvironmentFactoryTestSetup(JobExecutorTest.class);
- }
-
- public void setUp() throws Exception {
- super.setUp();
- processedMessageIds = new ArrayList<Integer>();
- exclusiveThreadIds = new HashMap<String, Set<Long>>();
- failOnceMessageIds = new ArrayList<Integer>();
- }
-
- public void testSuccessfulMessageProcessing() {
- JobExecutor jobExecutor = getEnvironmentFactory().get(JobExecutor.class);
- jobExecutor.start();
- try {
- insertTestMessages();
- waitTillNoMoreMessages(jobExecutor);
-
- } finally {
- jobExecutor.stop(true);
- }
-
- for (int i=0; i<nbrOfTestMessages; i++) {
- assertTrue("message "+i+" is not processed: "+processedMessageIds, processedMessageIds.contains(i));
- }
- }
-
- public void testMessagesPresentUponJobExecutorStartUp() {
-
- insertTestMessages();
-
- JobExecutor jobExecutor = getEnvironmentFactory().get(JobExecutor.class);
- jobExecutor.start();
- try {
- waitTillNoMoreMessages(jobExecutor);
-
- } finally {
- jobExecutor.stop(true);
- }
-
- for (int i=0; i<nbrOfTestMessages; i++) {
- assertTrue("message "+i+" is not processed", processedMessageIds.contains(i));
- }
- }
-
- public void testExclusiveMessageProcessing() {
- insertExclusiveTestMessages();
-
- JobExecutor jobExecutor = getEnvironmentFactory().get(JobExecutor.class);
- jobExecutor.start();
- try {
-
- waitTillNoMoreMessages(jobExecutor);
-
- } finally {
- jobExecutor.stop(true);
- }
-
- commandService.execute(new Command<Object>() {
- public Object execute(Environment environment) throws Exception {
- // exclusiveMessageIds maps execution keys to a set of thread ids.
- // the idea is that for each execution, all the exclusive jobs will
- // be executed by 1 thread sequentially.
-
- for (int i=0; i<nbrOfTestExecutions; i++) {
- String executionKey = "execution-"+i;
- Set<Long> threadIds = exclusiveThreadIds.get(executionKey);
- assertNotNull("no thread id set for "+executionKey+" in: "+exclusiveThreadIds, threadIds);
- assertEquals("exclusive messages for "+executionKey+" have been executed by multiple threads: "+threadIds,
- 1,
- threadIds.size());
- }
- return null;
- }
- });
- }
-
- public void testFailOnceMessages() {
- failOnceMessageIds.clear();
-
- JobExecutor jobExecutor = getEnvironmentFactory().get(JobExecutor.class);
- jobExecutor.start();
- try {
- insertFailOnceTestMessages();
- waitTillNoMoreMessages(jobExecutor);
-
- } finally {
- jobExecutor.stop(true);
- }
-
- for (int i=0; i<nbrOfTestMessages; i++) {
- assertTrue("message "+i+" is not failed once: "+failOnceMessageIds, failOnceMessageIds.contains(i));
- }
- assertEquals(nbrOfTestMessages, failOnceMessageIds.size());
-
- commandService.execute(new Command<Object>() {
- public Object execute(Environment environment) throws Exception {
- Session session = environment.get(Session.class);
- List<Comment> comments = session.createQuery("from org.jbpm.pvm.internal.model.CommentImpl").list();
-
- for (Comment comment: comments) {
- Integer messageId = new Integer(comment.getMessage());
- assertTrue("message "+messageId+" committed twice", failOnceMessageIds.remove(messageId));
- }
-
- assertTrue("not all messages made a successful commit: "+failOnceMessageIds, failOnceMessageIds.isEmpty());
- return null;
- }
- });
- }
-
- public void testFailedMessageProcessing() {
- JobExecutor jobExecutor = getEnvironmentFactory().get(JobExecutor.class);
- jobExecutor.start();
- try {
- commandService.execute(new Command<Object>() {
- public Object execute(Environment environment) throws Exception {
- MessageSession messageSession = environment.get(MessageSession.class);
- CommandMessage commandMessage = FailingTestCommand.createMessage();
- 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.findJobsWithException(0, 10);
- assertEquals("there should be one dead job", 1, deadJobs.size());
-
- Session session = environment.get(Session.class);
- List commands = session.createQuery("from org.jbpm.pvm.internal.model.CommentImpl").list();
- assertTrue("command insertion should have been rolled back", commands.isEmpty());
- return null;
- }
- });
- }
-
- public void testExceptionInJob() {
-
- JobExecutor jobExecutor = getEnvironmentFactory().get(JobExecutor.class);
- jobExecutor.start();
- try {
- commandService.execute(new Command<Object>() {
- // size of the error message to generate
- // (currently there is a limit of 4000 characters)
- int msgLength = 4100;
-
- public Object execute(Environment environment) throws Exception {
- MessageSession messageSession = environment.get(MessageSession.class);
- CommandMessage commandMessage = GenerateExceptionTestCommand.createMessage(msgLength);
- 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.findJobsWithException(0, 10);
- assertEquals("there should be one dead jobImpl", 1, deadJobs.size());
- return null;
- }
- });
- }
- // helper methods ///////////////////////////////////////////////////////////
-
- public static class InsertMessageCmd implements Command<Object> {
- private static final long serialVersionUID = 1L;
- int i;
- public InsertMessageCmd(int i) {
- this.i = i;
- }
- public Object execute(Environment environment) throws Exception {
- MessageSession messageSession = environment.get(MessageSession.class);
- CommandMessage commandMessage = TestMessageCommand.createMessage(i);
- messageSession.send(commandMessage);
- return null;
- }
- }
-
- void insertTestMessages() {
- for (int i=0; i<nbrOfTestMessages; i++) {
- commandService.execute(new InsertMessageCmd(i));
- }
- }
-
- public static class WaitState implements ExternalActivity {
- private static final long serialVersionUID = 1L;
- public void execute(ActivityExecution execution) throws Exception {
- execution.waitForSignal();
- }
- public void signal(ActivityExecution execution, String signalName, Map<String, Object> parameters) throws Exception {
- execution.take(signalName);
- }
- }
-
- void insertExclusiveTestMessages() {
- commandService.execute(new Command<Object>() {
- public Object execute(Environment environment) throws Exception {
- ClientProcessDefinition processDefinition = ProcessFactory.build("excl")
- .node("initial").initial().behaviour(WaitState.class)
- .done();
- DeploymentImpl deploymentImpl = new DeploymentImpl(processDefinition);
- ProcessService processService = environment.get(ProcessService.class);
- processService.deploy(deploymentImpl);
-
- PvmDbSession pvmDbSession = environment.get(PvmDbSession.class);
- MessageSession messageSession = environment.get(MessageSession.class);
- for (int i=0; i<nbrOfTestExecutions; i++) {
- ClientExecution execution = processDefinition.startProcessInstance("execution-"+i);
- pvmDbSession.save(execution);
-
- for (int j=0; j<nbrOfTestMessagesPerExecution; j++) {
- CommandMessage exclusiveTestMessage = ExclusiveTestCommand.createMessage(execution);
- messageSession.send(exclusiveTestMessage);
- }
- }
- return null;
- }
- });
- }
-
-
- public static class InsertFailOnceTestMsgCmd implements Command<Object> {
- private static final long serialVersionUID = 1L;
- int i;
- public InsertFailOnceTestMsgCmd(int i) {
- this.i = i;
- }
- public Object execute(Environment environment) throws Exception {
- MessageSession messageSession = environment.get(MessageSession.class);
- CommandMessage commandMessage = FailOnceTestCommand.createMessage(i);
- messageSession.send(commandMessage);
- return null;
- }
- }
-
- void insertFailOnceTestMessages() {
- for (int i=0; i<nbrOfTestMessages; i++) {
- commandService.execute(new InsertFailOnceTestMsgCmd(i));
- }
- }
-
- private void waitTillNoMoreMessages(JobExecutor jobExecutor) {
-
- // install a timer that will interrupt if it takes too long
- // if that happens, it will lead to an interrupted exception and the test will fail
- TimerTask interruptTask = new TimerTask() {
- Thread testThread = Thread.currentThread();
- public void run() {
- log.debug("test "+getName()+" took too long. going to interrupt..."+testThread);
- testThread.interrupt();
- }
- };
- Timer timer = new Timer();
- timer.schedule(interruptTask, timeoutMillis);
-
- try {
- boolean jobsAvailable = true;
- while (jobsAvailable) {
- log.debug("going to sleep for "+checkInterval+" millis, waiting for the jobImpl executor to process more jobs");
- Thread.sleep(checkInterval);
- jobsAvailable = areJobsAvailable();
- }
-
- } catch (InterruptedException e) {
- fail("test execution exceeded treshold of "+timeoutMillis+" milliseconds");
- } finally {
- timer.cancel();
- }
- }
-
- boolean areJobsAvailable() {
- return commandService.execute(new Command<Boolean>() {
- public Boolean execute(Environment environment) throws Exception {
- JobDbSession jobDbSession = environment.get(JobDbSession.class);
-
- JobImpl<?> firstAcquirableJob = jobDbSession.findFirstAcquirableJob();
- if (firstAcquirableJob!=null) {
- log.debug("found more jobs to process");
- return true;
- }
- return false;
- }
-
-
- public void signal(ActivityExecution execution, String signalName, Map<String, Object> parameters) throws Exception {
- }
-
- public void execute(ActivityExecution execution) throws Exception {
- } });
- }
-}
Deleted: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/TestMessageCommand.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/TestMessageCommand.java 2008-12-15 10:16:26 UTC (rev 3386)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/TestMessageCommand.java 2008-12-15 10:48:39 UTC (rev 3387)
@@ -1,75 +0,0 @@
-/*
- * 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 java.util.List;
-import java.util.Random;
-
-import org.jbpm.cmd.Command;
-import org.jbpm.env.Environment;
-import org.jbpm.log.Log;
-import org.jbpm.pvm.internal.job.CommandMessage;
-import org.jbpm.pvm.internal.wire.descriptor.IntegerDescriptor;
-import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
-import org.jbpm.session.DbSession;
-
-/**
- * @author Tom Baeyens
- */
-public class TestMessageCommand implements Command<Object> {
-
- private static final long serialVersionUID = 1L;
- private static final Log log = Log.getLog(TestMessageCommand.class.getName());
- static Random random = new Random();
-
- int messageId;
-
- public TestMessageCommand() {
- }
-
- public TestMessageCommand(int messageId) {
- this.messageId = messageId;
- }
-
- public Object execute(Environment environment) throws Exception {
- JobExecutorTest.processedMessageIds.add(messageId);
-
- // let's assume that an average jobImpl takes between 0 and 150 millis to complete.
- int workTime = random.nextInt(150);
- log.debug("executing test message "+messageId+". this is going to take "+workTime+"ms");
- try {
- Thread.sleep(workTime);
- } catch (RuntimeException e) {
- log.debug("sleeping was interrupted");
- }
-
- return null;
- }
-
- public static CommandMessage createMessage(int i) {
- CommandMessage commandMessage = new CommandMessage();
- ObjectDescriptor commandDescriptor = new ObjectDescriptor(TestMessageCommand.class);
- commandDescriptor.addInjection("messageId", new IntegerDescriptor(i));
- commandMessage.setCommandDescriptor(commandDescriptor);
- return commandMessage;
- }
-}
Modified: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/DbTestCase.java
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/DbTestCase.java 2008-12-15 10:16:26 UTC (rev 3386)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/DbTestCase.java 2008-12-15 10:48:39 UTC (rev 3387)
@@ -35,6 +35,7 @@
import org.jbpm.ProcessEngine;
import org.jbpm.ProcessService;
import org.jbpm.TaskService;
+import org.jbpm.client.ClientProcessDefinition;
import org.jbpm.task.Task;
/**
@@ -116,6 +117,16 @@
return addDeployedProcessDefinition(deployedProcessDefinitions);
}
+ protected ProcessDefinition addDeployedProcessDefinition(ProcessDefinition deployedProcessDefinition) {
+ if (processDefinitions==null) {
+ processDefinitions = new ArrayList<ProcessDefinition>();
+ }
+
+ processDefinitions.add(deployedProcessDefinition);
+
+ return deployedProcessDefinition;
+ }
+
protected ProcessDefinition addDeployedProcessDefinition(List<ProcessDefinition> deployedProcessDefinitions) {
if (processDefinitions==null) {
processDefinitions = new ArrayList<ProcessDefinition>();
Modified: jbpm4/trunk/modules/test-load/pom.xml
===================================================================
--- jbpm4/trunk/modules/test-load/pom.xml 2008-12-15 10:16:26 UTC (rev 3386)
+++ jbpm4/trunk/modules/test-load/pom.xml 2008-12-15 10:48:39 UTC (rev 3387)
@@ -32,14 +32,28 @@
<artifactId>jbpm-api</artifactId>
<version>${version}</version>
</dependency>
+
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
+ <groupId>org.jbpm.jbpm4</groupId>
+ <artifactId>jbpm-test-base</artifactId>
+ <version>${version}</version>
</dependency>
+
<dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
+ <groupId>org.jbpm.jbpm4</groupId>
+ <artifactId>jbpm-jpdl</artifactId>
+ <version>${version}</version>
</dependency>
+
+
+ <!-- TODO remove PVM dependency for compilation (keep it for test)-->
+ <dependency>
+ <groupId>org.jbpm.jbpm4</groupId>
+ <artifactId>jbpm-pvm</artifactId>
+ <version>${version}</version>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
<!-- Plugins -->
@@ -50,48 +64,6 @@
<!-- Profiles -->
<profiles>
-
- <!--
- Name: no-impl
- Descr: The default implementation profile
- -->
- <profile>
- <id>no-impl</id>
- <activation>
- <property>
- <name>!impl</name>
- </property>
- </activation>
- <dependencies>
- <dependency>
- <groupId>org.jbpm.jbpm4</groupId>
- <artifactId>jbpm-pvm</artifactId>
- <version>4.0.0-SNAPSHOT</version>
- </dependency>
- </dependencies>
- </profile>
-
- <!--
- Name: impl-ri
- Descr: The RI implementation profile
- -->
- <profile>
- <id>impl-ri</id>
- <activation>
- <property>
- <name>impl</name>
- <value>ri</value>
- </property>
- </activation>
- <dependencies>
- <dependency>
- <groupId>org.jbpm.spec</groupId>
- <artifactId>jbpm-spec-ri</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- </dependency>
- </dependencies>
- </profile>
-
</profiles>
</project>
\ No newline at end of file
Copied: jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/ExclusiveTestCommand.java (from rev 3382, jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/ExclusiveTestCommand.java)
===================================================================
--- jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/ExclusiveTestCommand.java (rev 0)
+++ jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/ExclusiveTestCommand.java 2008-12-15 10:48:39 UTC (rev 3387)
@@ -0,0 +1,96 @@
+/*
+ * 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.load;
+
+import java.util.HashSet;
+import java.util.Random;
+import java.util.Set;
+
+import org.hibernate.Session;
+import org.jbpm.Execution;
+import org.jbpm.cmd.Command;
+import org.jbpm.env.Environment;
+import org.jbpm.log.Log;
+import org.jbpm.pvm.internal.job.CommandMessage;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.pvm.internal.wire.descriptor.LongDescriptor;
+import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ExclusiveTestCommand implements Command<Object> {
+
+ private static final long serialVersionUID = 1L;
+ private static final Log log = Log.getLog(ExclusiveTestCommand.class.getName());
+ static Random random = new Random();
+
+ long executionId;
+
+ public ExclusiveTestCommand() {
+ }
+
+ public static CommandMessage createMessage(Execution execution) {
+ CommandMessage commandMessage = new CommandMessage();
+ commandMessage.setExecution((ExecutionImpl) execution);
+ commandMessage.setExclusive(true);
+
+ ObjectDescriptor commandDescriptor = new ObjectDescriptor(ExclusiveTestCommand.class);
+ commandDescriptor.addInjection("executionId", new LongDescriptor(execution.getDbid()));
+ commandMessage.setCommandDescriptor(commandDescriptor);
+ return commandMessage;
+ }
+
+ public Object execute(Environment environment) throws Exception {
+ Long threadId = Thread.currentThread().getId();
+
+ Session session = environment.get(Session.class);
+ ExecutionImpl execution = (ExecutionImpl) session.get(ExecutionImpl.class, executionId);
+
+ String executionKey = execution.getKey();
+
+ // exclusiveMessageIds maps execution keys to a set of thread ids.
+ // the idea is that for each execution, all the exclusive jobs will
+ // be executed by 1 thread sequentially.
+
+ // in the end, each set should contain exactly 1 element
+ Set<Long> groupMessages = JobExecutorTest.exclusiveThreadIds.get(executionKey);
+ if (groupMessages==null) {
+ groupMessages = new HashSet<Long>();
+ JobExecutorTest.exclusiveThreadIds.put(executionKey, groupMessages);
+ }
+ groupMessages.add(threadId);
+
+ // let's assume that an average jobImpl takes between 0 and 150 millis to complete.
+ int workTime = random.nextInt(150);
+ log.debug("executing exclusive message for "+execution+". this is going to take "+workTime+"ms");
+ try {
+ Thread.sleep(workTime);
+ } catch (RuntimeException e) {
+ log.debug("sleeping was interrupted");
+ }
+
+ return null;
+ }
+
+}
Copied: jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/FailOnceTestCommand.java (from rev 3382, jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/FailOnceTestCommand.java)
===================================================================
--- jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/FailOnceTestCommand.java (rev 0)
+++ jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/FailOnceTestCommand.java 2008-12-15 10:48:39 UTC (rev 3387)
@@ -0,0 +1,78 @@
+/*
+ * 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.load;
+
+import org.jbpm.cmd.Command;
+import org.jbpm.env.Environment;
+import org.jbpm.log.Log;
+import org.jbpm.model.Comment;
+import org.jbpm.pvm.internal.job.CommandMessage;
+import org.jbpm.pvm.internal.job.MessageImpl;
+import org.jbpm.pvm.internal.model.CommentImpl;
+import org.jbpm.pvm.internal.wire.descriptor.IntegerDescriptor;
+import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
+import org.jbpm.session.DbSession;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class FailOnceTestCommand implements Command<Object> {
+
+ private static final long serialVersionUID = 1L;
+ private static final Log log = Log.getLog(FailOnceTestCommand.class.getName());
+
+ int messageId;
+
+ public FailOnceTestCommand() {
+ }
+
+ public static CommandMessage createMessage(int messageId) {
+ CommandMessage commandMessage = new CommandMessage();
+ ObjectDescriptor commandDescriptor = new ObjectDescriptor(FailOnceTestCommand.class);
+ commandDescriptor.addInjection("messageId", new IntegerDescriptor(messageId));
+ commandMessage.setCommandDescriptor(commandDescriptor);
+ return commandMessage;
+ }
+
+ public Object execute(Environment environment) throws Exception {
+ DbSession dbSession = environment.get(DbSession.class);
+
+ // this message execution should be rolled back
+ Comment comment = new CommentImpl(Integer.toString(messageId));
+ dbSession.save(comment);
+
+ if (!JobExecutorTest.failOnceMessageIds.contains(messageId)) {
+ // registering the failed message in a non-transactional resource
+ // so the messageId will still be added even after the transaction has rolled back
+ log.debug("adding failonce message "+messageId);
+ JobExecutorTest.failOnceMessageIds.add(messageId);
+
+ throw new RuntimeException("failing once");
+ }
+
+ log.debug("message "+messageId+" now succeeds");
+
+ return null;
+ }
+
+}
Copied: jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/FailingTestCommand.java (from rev 3382, jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/FailingTestCommand.java)
===================================================================
--- jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/FailingTestCommand.java (rev 0)
+++ jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/FailingTestCommand.java 2008-12-15 10:48:39 UTC (rev 3387)
@@ -0,0 +1,57 @@
+/*
+ * 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.load;
+
+import org.jbpm.cmd.Command;
+import org.jbpm.env.Environment;
+import org.jbpm.model.Comment;
+import org.jbpm.pvm.internal.job.CommandMessage;
+import org.jbpm.pvm.internal.model.CommentImpl;
+import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
+import org.jbpm.session.DbSession;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class FailingTestCommand implements Command<Object> {
+
+ private static final long serialVersionUID = 1L;
+
+ public Object execute(Environment environment) throws Exception {
+ DbSession dbSession = environment.get(DbSession.class);
+
+ // this message execution should be rolled back
+ Comment comment = new CommentImpl("failing update");
+ dbSession.save(comment);
+
+ throw new RuntimeException("ooops");
+ }
+
+ public static CommandMessage createMessage() {
+ CommandMessage commandMessage = new CommandMessage();
+ ObjectDescriptor commandDescriptor = new ObjectDescriptor(FailingTestCommand.class);
+ commandMessage.setCommandDescriptor(commandDescriptor);
+ return commandMessage;
+ }
+
+}
Copied: jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/GenerateExceptionTestCommand.java (from rev 3382, jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/GenerateExceptionTestCommand.java)
===================================================================
--- jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/GenerateExceptionTestCommand.java (rev 0)
+++ jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/GenerateExceptionTestCommand.java 2008-12-15 10:48:39 UTC (rev 3387)
@@ -0,0 +1,66 @@
+/*
+ * 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.load;
+
+import org.jbpm.cmd.Command;
+import org.jbpm.env.Environment;
+import org.jbpm.pvm.internal.job.CommandMessage;
+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 length parameter).
+ *
+ * This class is to test the persistence of exception stacktrace in jobs.
+ */
+public class GenerateExceptionTestCommand implements Command<Object> {
+
+ private static final long serialVersionUID = 1L;
+
+ int length;
+
+ public GenerateExceptionTestCommand() {
+ }
+
+ public static CommandMessage createMessage(int recursionInitialDepth) {
+ CommandMessage commandMessage = new CommandMessage();
+ ObjectDescriptor commandDescriptor = new ObjectDescriptor(GenerateExceptionTestCommand.class);
+ commandDescriptor.addInjection("length", new IntegerDescriptor(recursionInitialDepth));
+ commandMessage.setCommandDescriptor(commandDescriptor);
+ return commandMessage;
+ }
+
+ public Object execute(Environment environment) throws Exception {
+ StringBuilder stringBuilder = new StringBuilder();
+ while (stringBuilder.length() < length) {
+ stringBuilder.append("This is a long test message. ");
+ }
+ throw new RuntimeException(stringBuilder.toString());
+ }
+
+}
Copied: jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/JobExecutorIsolationDbTest.java (from rev 3382, jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorIsolationDbTest.java)
===================================================================
--- jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/JobExecutorIsolationDbTest.java (rev 0)
+++ jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/JobExecutorIsolationDbTest.java 2008-12-15 10:48:39 UTC (rev 3387)
@@ -0,0 +1,88 @@
+/**
+ * Copyright (C) 2007 Bull S. A. S.
+ * Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois
+ * This library 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
+ * version 2.1 of the License.
+ * This library 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
+ * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
+ * Floor, Boston, MA 02110-1301, USA.
+ **/
+package org.jbpm.test.load;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jbpm.cmd.Command;
+import org.jbpm.cmd.CommandService;
+import org.jbpm.env.Environment;
+import org.jbpm.job.Message;
+import org.jbpm.log.Log;
+import org.jbpm.pvm.internal.job.CommandMessage;
+import org.jbpm.pvm.internal.jobexecutor.JobExecutor;
+import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
+import org.jbpm.session.MessageSession;
+import org.jbpm.session.PvmDbSession;
+import org.jbpm.test.DbTestCase;
+
+
+/**
+ * This class contains job executor tests which requires to have a read commited isolation level.
+ *
+ * @author Guillaume Porcher
+ *
+ */
+public class JobExecutorIsolationDbTest extends DbTestCase {
+
+ static int jobExecutorTimeoutMillis = 500;
+ static int checkInterval = 400;
+
+ public static class SimpleTestCommand implements Command<Object> {
+ private static final Log log = Log.getLog(SimpleTestCommand.class.getName());
+
+ public Object execute(Environment environment) throws Exception {
+ log.debug("command executed !");
+ return null;
+ }
+ }
+
+ public void testInsertMessage() {
+ System.out.println("FIXME: JBPM-1769 fix db isolation test");
+ }
+
+
+ /*
+ * Basic test that only shows a simple situation in which we need to have a read commited isolation level.
+ */
+
+ // FIX rename test method back to testInsertMessage
+ public void dontTestInsertMessage() throws InterruptedException {
+ JobExecutorTest.processedMessageIds = new ArrayList<Integer>();
+ JobExecutor jobExecutor = processEngine.get(JobExecutor.class);
+ jobExecutor.setIdleInterval(jobExecutorTimeoutMillis);
+ jobExecutor.start();
+ try {
+ processEngine.get(CommandService.class).execute(new Command<Object>() {
+ public Object execute(Environment environment) throws Exception {
+ MessageSession messageSession = environment.get(MessageSession.class);
+ CommandMessage commandMessage = new CommandMessage(new ObjectDescriptor(SimpleTestCommand.class));
+ messageSession.send(commandMessage);
+ List<Message> messages = environment.get(PvmDbSession.class).findMessages(0, 10);
+ assertNotNull(messages);
+ assertEquals(1, messages.size());
+ Thread.sleep(jobExecutorTimeoutMillis * 2);
+ messages = environment.get(PvmDbSession.class).findMessages(0, 10);
+ assertNotNull(messages);
+ assertEquals("Job has been executed before the transaction is committed !!", 1, messages.size());
+ return null;
+ }
+ });
+ Thread.sleep(jobExecutorTimeoutMillis * 2);
+ } finally {
+ jobExecutor.stop(true);
+ }
+ }
+}
Property changes on: jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/JobExecutorIsolationDbTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:mergeinfo
+
Copied: jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/JobExecutorTest.java (from rev 3382, jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTest.java)
===================================================================
--- jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/JobExecutorTest.java (rev 0)
+++ jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/JobExecutorTest.java 2008-12-15 10:48:39 UTC (rev 3387)
@@ -0,0 +1,384 @@
+/*
+ * 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.load;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import org.hibernate.Session;
+import org.jbpm.Execution;
+import org.jbpm.activity.ActivityExecution;
+import org.jbpm.activity.ExternalActivity;
+import org.jbpm.cmd.Command;
+import org.jbpm.cmd.CommandService;
+import org.jbpm.env.Environment;
+import org.jbpm.job.Job;
+import org.jbpm.log.Log;
+import org.jbpm.model.Comment;
+import org.jbpm.pvm.internal.cmd.StartExecutionCmd;
+import org.jbpm.pvm.internal.job.CommandMessage;
+import org.jbpm.pvm.internal.job.JobImpl;
+import org.jbpm.pvm.internal.jobexecutor.JobDbSession;
+import org.jbpm.pvm.internal.jobexecutor.JobExecutor;
+import org.jbpm.pvm.internal.model.CommentImpl;
+import org.jbpm.session.MessageSession;
+import org.jbpm.session.PvmDbSession;
+import org.jbpm.test.DbTestCase;
+
+/**
+ * @author Tom Baeyens
+ * @author Guillaume Porcher
+ */
+public class JobExecutorTest extends DbTestCase {
+
+ private static final Log log = Log.getLog(JobExecutorTest.class.getName());
+
+ static List<Integer> processedMessageIds;
+ static Map<String, Set<Long>> exclusiveThreadIds;
+ static List<Integer> failOnceMessageIds;
+
+ static int nbrOfTestMessages = 500;
+ static int timeoutMillis = 10 * 60 * 1000; // 10 minutes
+ static int checkInterval = 400;
+ static int nbrOfTestMessagesPerExecution = 10;
+ static int nbrOfTestExecutions = 20;
+
+ CommandService commandService;
+
+ public void setUp() throws Exception {
+ super.setUp();
+ processedMessageIds = new ArrayList<Integer>();
+ exclusiveThreadIds = new HashMap<String, Set<Long>>();
+ failOnceMessageIds = new ArrayList<Integer>();
+
+ commandService = processEngine.get(CommandService.class);
+ }
+
+ public void testSuccessfulMessageProcessing() {
+ JobExecutor jobExecutor = processEngine.get(JobExecutor.class);
+ jobExecutor.start();
+ try {
+ insertTestMessages();
+ waitTillNoMoreMessages(jobExecutor);
+
+ } finally {
+ jobExecutor.stop(true);
+ }
+
+ for (int i = 0; i < nbrOfTestMessages; i++) {
+ assertTrue("message " + i + " is not processed: " + processedMessageIds, processedMessageIds.contains(i));
+ }
+ }
+
+ public void testMessagesPresentUponJobExecutorStartUp() {
+
+ insertTestMessages();
+
+ JobExecutor jobExecutor = processEngine.get(JobExecutor.class);
+ jobExecutor.start();
+ try {
+ waitTillNoMoreMessages(jobExecutor);
+
+ } finally {
+ jobExecutor.stop(true);
+ }
+
+ for (int i = 0; i < nbrOfTestMessages; i++) {
+ assertTrue("message " + i + " is not processed", processedMessageIds.contains(i));
+ }
+ }
+
+ public void testExclusiveMessageProcessing() {
+ insertExclusiveTestMessages();
+
+ JobExecutor jobExecutor = processEngine.get(JobExecutor.class);
+ jobExecutor.start();
+ try {
+
+ waitTillNoMoreMessages(jobExecutor);
+
+ } finally {
+ jobExecutor.stop(true);
+ }
+
+ commandService.execute(new Command<Object>() {
+
+ public Object execute(Environment environment) throws Exception {
+ // exclusiveMessageIds maps execution keys to a set of thread ids.
+ // the idea is that for each execution, all the exclusive jobs will
+ // be executed by 1 thread sequentially.
+
+ for (int i = 0; i < nbrOfTestExecutions; i++) {
+ String executionKey = "execution-" + i;
+ Set<Long> threadIds = exclusiveThreadIds.get(executionKey);
+ assertNotNull("no thread id set for " + executionKey + " in: " + exclusiveThreadIds, threadIds);
+ assertEquals("exclusive messages for " + executionKey + " have been executed by multiple threads: " + threadIds, 1, threadIds.size());
+ }
+ return null;
+ }
+ });
+ }
+
+ public void testFailOnceMessages() {
+ failOnceMessageIds.clear();
+
+ JobExecutor jobExecutor = processEngine.get(JobExecutor.class);
+ jobExecutor.start();
+ try {
+ insertFailOnceTestMessages();
+ waitTillNoMoreMessages(jobExecutor);
+
+ } finally {
+ jobExecutor.stop(true);
+ }
+
+ for (int i = 0; i < nbrOfTestMessages; i++) {
+ assertTrue("message " + i + " is not failed once: " + failOnceMessageIds, failOnceMessageIds.contains(i));
+ }
+ assertEquals(nbrOfTestMessages, failOnceMessageIds.size());
+
+ commandService.execute(new Command<Object>() {
+
+ public Object execute(Environment environment) throws Exception {
+ Session session = environment.get(Session.class);
+ List<Comment> comments = session.createQuery("from " + CommentImpl.class.getName()).list();
+
+ for (Comment comment : comments) {
+ Integer messageId = new Integer(comment.getMessage());
+ assertTrue("message " + messageId + " committed twice", failOnceMessageIds.remove(messageId));
+ }
+
+ assertTrue("not all messages made a successful commit: " + failOnceMessageIds, failOnceMessageIds.isEmpty());
+ return null;
+ }
+ });
+ }
+
+ public void testFailedMessageProcessing() {
+ JobExecutor jobExecutor = processEngine.get(JobExecutor.class);
+ jobExecutor.start();
+ try {
+ commandService.execute(new Command<Object>() {
+
+ public Object execute(Environment environment) throws Exception {
+ MessageSession messageSession = environment.get(MessageSession.class);
+ CommandMessage commandMessage = FailingTestCommand.createMessage();
+ 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.findJobsWithException(0, 10);
+ assertEquals("there should be one dead job", 1, deadJobs.size());
+
+ Session session = environment.get(Session.class);
+ List commands = session.createQuery("from " + CommentImpl.class.getName()).list();
+ assertTrue("command insertion should have been rolled back", commands.isEmpty());
+ return null;
+ }
+ });
+ }
+
+ public void testExceptionInJob() {
+
+ JobExecutor jobExecutor = processEngine.get(JobExecutor.class);
+ jobExecutor.start();
+ try {
+ commandService.execute(new Command<Object>() {
+
+ // size of the error message to generate
+ // (currently there is a limit of 4000 characters)
+ int msgLength = 4100;
+
+ public Object execute(Environment environment) throws Exception {
+ MessageSession messageSession = environment.get(MessageSession.class);
+ CommandMessage commandMessage = GenerateExceptionTestCommand.createMessage(msgLength);
+ 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.findJobsWithException(0, 10);
+ assertEquals("there should be one dead jobImpl", 1, deadJobs.size());
+ return null;
+ }
+ });
+ }
+
+ // helper methods ///////////////////////////////////////////////////////////
+
+ public static class InsertMessageCmd implements Command<Object> {
+
+ private static final long serialVersionUID = 1L;
+ int i;
+
+ public InsertMessageCmd(int i) {
+ this.i = i;
+ }
+ public Object execute(Environment environment) throws Exception {
+ MessageSession messageSession = environment.get(MessageSession.class);
+ CommandMessage commandMessage = TestMessageCommand.createMessage(i);
+ messageSession.send(commandMessage);
+ return null;
+ }
+ }
+
+ void insertTestMessages() {
+ for (int i = 0; i < nbrOfTestMessages; i++) {
+ commandService.execute(new InsertMessageCmd(i));
+ }
+ }
+
+ public static class WaitState implements ExternalActivity {
+
+ private static final long serialVersionUID = 1L;
+
+ public void execute(ActivityExecution execution) throws Exception {
+ execution.waitForSignal();
+ }
+ public void signal(ActivityExecution execution, String signalName, Map<String, Object> parameters) throws Exception {
+ execution.take(signalName);
+ }
+ }
+
+ void insertExclusiveTestMessages() {
+ deployJpdlXmlString(
+ "<process name='excl'>" +
+ " <start>" +
+ " <flow to='a' />" +
+ " </start>" +
+ " <state name='a' />" +
+ "</process>"
+ );
+
+ commandService.execute(new Command<Object>() {
+ public Object execute(Environment environment) throws Exception {
+ MessageSession messageSession = environment.get(MessageSession.class);
+ for (int i = 0; i < nbrOfTestExecutions; i++) {
+ Execution execution =
+ new StartExecutionCmd("excl:1", null, "execution-" + i)
+ .execute(environment);
+
+ for (int j = 0; j < nbrOfTestMessagesPerExecution; j++) {
+ CommandMessage exclusiveTestMessage = ExclusiveTestCommand.createMessage(execution);
+ messageSession.send(exclusiveTestMessage);
+ }
+ }
+ return null;
+ }
+ });
+ }
+
+ public static class InsertFailOnceTestMsgCmd implements Command<Object> {
+
+ private static final long serialVersionUID = 1L;
+ int i;
+
+ public InsertFailOnceTestMsgCmd(int i) {
+ this.i = i;
+ }
+ public Object execute(Environment environment) throws Exception {
+ MessageSession messageSession = environment.get(MessageSession.class);
+ CommandMessage commandMessage = FailOnceTestCommand.createMessage(i);
+ messageSession.send(commandMessage);
+ return null;
+ }
+ }
+
+ void insertFailOnceTestMessages() {
+ for (int i = 0; i < nbrOfTestMessages; i++) {
+ commandService.execute(new InsertFailOnceTestMsgCmd(i));
+ }
+ }
+
+ private void waitTillNoMoreMessages(JobExecutor jobExecutor) {
+
+ // install a timer that will interrupt if it takes too long
+ // if that happens, it will lead to an interrupted exception and the test
+ // will fail
+ TimerTask interruptTask = new TimerTask() {
+
+ Thread testThread = Thread.currentThread();
+
+ public void run() {
+ log.debug("test " + getName() + " took too long. going to interrupt..." + testThread);
+ testThread.interrupt();
+ }
+ };
+ Timer timer = new Timer();
+ timer.schedule(interruptTask, timeoutMillis);
+
+ try {
+ boolean jobsAvailable = true;
+ while (jobsAvailable) {
+ log.debug("going to sleep for " + checkInterval + " millis, waiting for the jobImpl executor to process more jobs");
+ Thread.sleep(checkInterval);
+ jobsAvailable = areJobsAvailable();
+ }
+
+ } catch (InterruptedException e) {
+ fail("test execution exceeded treshold of " + timeoutMillis + " milliseconds");
+ } finally {
+ timer.cancel();
+ }
+ }
+
+ boolean areJobsAvailable() {
+ return commandService.execute(new Command<Boolean>() {
+ public Boolean execute(Environment environment) {
+ JobDbSession jobDbSession = environment.get(JobDbSession.class);
+
+ JobImpl< ? > firstAcquirableJob = jobDbSession.findFirstAcquirableJob();
+ if (firstAcquirableJob != null) {
+ log.debug("found more jobs to process");
+ return true;
+ }
+ return false;
+ }
+ });
+ }
+}
Copied: jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/TestMessageCommand.java (from rev 3382, jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/jobexecutor/TestMessageCommand.java)
===================================================================
--- jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/TestMessageCommand.java (rev 0)
+++ jbpm4/trunk/modules/test-load/src/test/java/org/jbpm/test/load/TestMessageCommand.java 2008-12-15 10:48:39 UTC (rev 3387)
@@ -0,0 +1,75 @@
+/*
+ * 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.load;
+
+import java.util.List;
+import java.util.Random;
+
+import org.jbpm.cmd.Command;
+import org.jbpm.env.Environment;
+import org.jbpm.log.Log;
+import org.jbpm.pvm.internal.job.CommandMessage;
+import org.jbpm.pvm.internal.wire.descriptor.IntegerDescriptor;
+import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
+import org.jbpm.session.DbSession;
+
+/**
+ * @author Tom Baeyens
+ */
+public class TestMessageCommand implements Command<Object> {
+
+ private static final long serialVersionUID = 1L;
+ private static final Log log = Log.getLog(TestMessageCommand.class.getName());
+ static Random random = new Random();
+
+ int messageId;
+
+ public TestMessageCommand() {
+ }
+
+ public TestMessageCommand(int messageId) {
+ this.messageId = messageId;
+ }
+
+ public Object execute(Environment environment) throws Exception {
+ JobExecutorTest.processedMessageIds.add(messageId);
+
+ // let's assume that an average jobImpl takes between 0 and 150 millis to complete.
+ int workTime = random.nextInt(150);
+ log.debug("executing test message "+messageId+". this is going to take "+workTime+"ms");
+ try {
+ Thread.sleep(workTime);
+ } catch (RuntimeException e) {
+ log.debug("sleeping was interrupted");
+ }
+
+ return null;
+ }
+
+ public static CommandMessage createMessage(int i) {
+ CommandMessage commandMessage = new CommandMessage();
+ ObjectDescriptor commandDescriptor = new ObjectDescriptor(TestMessageCommand.class);
+ commandDescriptor.addInjection("messageId", new IntegerDescriptor(i));
+ commandMessage.setCommandDescriptor(commandDescriptor);
+ return commandMessage;
+ }
+}
Added: jbpm4/trunk/modules/test-load/src/test/resources/hibernate.properties
===================================================================
--- jbpm4/trunk/modules/test-load/src/test/resources/hibernate.properties (rev 0)
+++ jbpm4/trunk/modules/test-load/src/test/resources/hibernate.properties 2008-12-15 10:48:39 UTC (rev 3387)
@@ -0,0 +1,11 @@
+hibernate.dialect org.hibernate.dialect.HSQLDialect
+hibernate.connection.driver_class org.hsqldb.jdbcDriver
+hibernate.connection.url jdbc:hsqldb:mem:.
+hibernate.connection.username sa
+hibernate.connection.password
+hibernate.hbm2ddl.auto create-drop
+hibernate.cache.use_second_level_cache true
+hibernate.cache.provider_class org.hibernate.cache.HashtableCacheProvider
+# hibernate.show_sql true
+hibernate.format_sql true
+hibernate.use_sql_comments true
Added: jbpm4/trunk/modules/test-load/src/test/resources/jbpm.cfg.xml
===================================================================
--- jbpm4/trunk/modules/test-load/src/test/resources/jbpm.cfg.xml (rev 0)
+++ jbpm4/trunk/modules/test-load/src/test/resources/jbpm.cfg.xml 2008-12-15 10:48:39 UTC (rev 3387)
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<jbpm-configuration xmlns="http://jbpm.org/xsd/cfg">
+
+ <process-engine>
+
+ <deployer-manager>
+ <assign-file-type>
+ <file extension=".jpdl.xml" type="jpdl" />
+ </assign-file-type>
+ <parse-jpdl />
+ <check-process />
+ <check-problems />
+ <save />
+ </deployer-manager>
+
+ <process-service />
+ <execution-service />
+ <management-service />
+
+ <command-service>
+ <retry-interceptor />
+ <environment-interceptor />
+ <standard-transaction-interceptor />
+ </command-service>
+
+ <hibernate-configuration>
+ <properties resource="hibernate.properties" />
+ <mapping resource="jbpm.pvm.typedefs.hbm.xml" />
+ <mapping resource="jbpm.pvm.wire.hbm.xml" />
+ <mapping resource="jbpm.pvm.definition.hbm.xml" />
+ <mapping resource="jbpm.pvm.execution.hbm.xml" />
+ <mapping resource="jbpm.pvm.variable.hbm.xml" />
+ <mapping resource="jbpm.pvm.job.hbm.xml" />
+ <mapping resource="jbpm.jpdl.hbm.xml" />
+ <cache-configuration resource="jbpm.pvm.cache.xml"
+ usage="nonstrict-read-write" />
+ </hibernate-configuration>
+
+ <hibernate-session-factory />
+
+ <job-executor auto-start="false" />
+ <job-test-helper />
+
+ <id-generator />
+ <variable-types resource="jbpm.pvm.types.xml" />
+
+ <business-calendar>
+ <monday hours="9:00-12:00 and 12:30-17:00"/>
+ <tuesday hours="9:00-12:00 and 12:30-17:00"/>
+ <wednesday hours="9:00-12:00 and 12:30-17:00"/>
+ <thursday hours="9:00-12:00 and 12:30-17:00"/>
+ <friday hours="9:00-12:00 and 12:30-17:00"/>
+ <holiday period="01/07/2008 - 31/08/2008"/>
+ </business-calendar>
+
+ </process-engine>
+
+ <environment>
+ <hibernate-session />
+ <transaction />
+ <pvm-db-session />
+ <job-db-session />
+ <message-session />
+ <timer-session />
+ </environment>
+
+</jbpm-configuration>
Property changes on: jbpm4/trunk/modules/test-load/src/test/resources/jbpm.cfg.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: jbpm4/trunk/modules/test-load/src/test/resources/logging.properties
===================================================================
--- jbpm4/trunk/modules/test-load/src/test/resources/logging.properties (rev 0)
+++ jbpm4/trunk/modules/test-load/src/test/resources/logging.properties 2008-12-15 10:48:39 UTC (rev 3387)
@@ -0,0 +1,28 @@
+handlers= java.util.logging.ConsoleHandler
+# to add the error triggered file handler
+# handlers= java.util.logging.ConsoleHandler org.jbpm.util.ErrorTriggeredFileHandler
+
+redirect.commons.logging = enabled
+
+java.util.logging.ConsoleHandler.level = FINEST
+java.util.logging.ConsoleHandler.formatter = org.jbpm.log.LogFormatter
+
+# org.jbpm.util.ErrorTriggeredFileHandler.size = 500
+# org.jbpm.util.ErrorTriggeredFileHandler.push = OFF
+# org.jbpm.util.ErrorTriggeredFileHandler.pattern = %h/jbpm%u.log
+
+# For example, set the com.xyz.foo logger to only log SEVERE messages:
+# com.xyz.foo.level = SEVERE
+
+org.jbpm.level=FINEST
+org.jbpm.pvm.internal.tx.level=FINE
+org.jbpm.pvm.internal.wire.level=FINE
+org.jbpm.pvm.internal.util.level=FINE
+
+org.hibernate.cfg.HbmBinder.level=SEVERE
+org.hibernate.cfg.SettingsFactory.level=SEVERE
+# org.hibernate.level=FINE
+# org.hibernate.SQL.level=FINEST
+# org.hibernate.type.level=FINEST
+# org.hibernate.tool.hbm2ddl.SchemaExport.level=FINEST
+# org.hibernate.transaction.level=FINEST
More information about the jbpm-commits
mailing list