[jbpm-commits] JBoss JBPM SVN: r4095 - jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/test/java/org/jbpm/perf.
do-not-reply at jboss.org
do-not-reply at jboss.org
Mon Mar 2 07:52:00 EST 2009
Author: mvecera at redhat.com
Date: 2009-03-02 07:52:00 -0500 (Mon, 02 Mar 2009)
New Revision: 4095
Modified:
jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/test/java/org/jbpm/perf/SimplePerformanceTest.java
Log:
SimplePerformanceTest update
Modified: jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/test/java/org/jbpm/perf/SimplePerformanceTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/test/java/org/jbpm/perf/SimplePerformanceTest.java 2009-03-01 03:01:13 UTC (rev 4094)
+++ jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/test/java/org/jbpm/perf/SimplePerformanceTest.java 2009-03-02 12:52:00 UTC (rev 4095)
@@ -22,17 +22,28 @@
package org.jbpm.perf;
// $Id$
-
+import java.io.File;
+import java.util.Date;
+import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jbpm.JbpmContext;
+import org.jbpm.JbpmException;
import org.jbpm.command.CommandService;
-import org.jbpm.command.StartProcessInstanceCommand;
+import org.jbpm.command.NewProcessInstanceCommand;
+import org.jbpm.command.SignalCommand;
import org.jbpm.command.impl.CommandServiceImpl;
import org.jbpm.db.AbstractDbTestCase;
+import org.jbpm.graph.def.Action;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.graph.exe.Token;
+import org.jbpm.instantiation.Delegation;
+import org.jbpm.job.ExecuteActionJob;
+import org.jbpm.msg.MessageService;
+import org.jbpm.svc.Services;
/**
* This tests creates a number of process instances.
@@ -45,66 +56,114 @@
* @author thomas.diesler at jboss.com
* @since 18-Feb-2009
*/
-public class SimplePerformanceTest extends AbstractDbTestCase
-{
- private static final Log log = LogFactory.getLog(SimplePerformanceTest.class);
-
- private CommandService commandService = new CommandServiceImpl(getJbpmConfiguration());
- private static final int INSTANCES = 1000;
- private static int count;
-
- ProcessDefinition processDefinition;
+public class SimplePerformanceTest extends AbstractDbTestCase {
+ private static final Log log = LogFactory.getLog(SimplePerformanceTest.class);
+ private static final String ESB_ASYNC_SIGNAL_ACTION_NAME = "ESB_ASYNC_SIGNAL_ACTION";
+ private CommandService commandService = new CommandServiceImpl(getJbpmConfiguration());
+ private static final int INSTANCES = 10;
+ private static int count = 1;
+ private static AtomicInteger signaled = new AtomicInteger(0);
+ private Action signalAction;
+ ProcessDefinition processDefinition;
- public void setUp() throws Exception
- {
- super.setUp();
-
- processDefinition = ProcessDefinition.parseXmlString(
- "<process-definition xmlns='urn:jbpm.org:jpdl-3.1' name='processDefinition1'>" +
- " <start-state name='start'>" +
- " <transition name='to_state' to='end'>" +
- " <action class='" + PerfActionHandler.class.getName() + "'/>" +
- " </transition>" +
- " </start-state>" +
- " <end-state name='end'/>" +
- "</process-definition>");
-
- saveAndReload(processDefinition);
- }
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
- public void tearDown() throws Exception
- {
- beginSessionTransaction();
- jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
- super.tearDown();
- }
+ processDefinition = ProcessDefinition.parseXmlString(
+ "<process-definition xmlns='urn:jbpm.org:jpdl-3.1' name='processDefinition1'>" +
+ " <start-state name='start'>" +
+ " <transition name='to_state' to='end'>" +
+ " <action class='" + PerfActionHandler.class.getName() + "'/>" +
+ " </transition>" +
+ " </start-state>" +
+ " <end-state name='end'/>" +
+ "</process-definition>");
- public void testAsyncCall()
- {
- long start = System.currentTimeMillis();
+ final Delegation delegation = new Delegation(AsyncSignalAction.class.getName());
+ delegation.setConfigType("constructor");
+ signalAction = new Action(delegation);
+ signalAction.setName(ESB_ASYNC_SIGNAL_ACTION_NAME);
+ processDefinition.addAction(signalAction);
- commitAndCloseSession();
+ saveAndReload(processDefinition);
+ }
- for (count = 0; count < INSTANCES; count++)
- {
+ @Override
+ public void tearDown() throws Exception {
beginSessionTransaction();
- StartProcessInstanceCommand startCommand = new StartProcessInstanceCommand();
- startCommand.setProcessId(processDefinition.getId());
- startCommand.setProcessName("processDefinition1");
- ProcessInstance pi = (ProcessInstance)commandService.execute(startCommand);
+ jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
+ super.tearDown();
+ }
+
+ public void testAsyncCall() {
+ long start = System.currentTimeMillis();
+
+ startJobExecutor();
+
commitAndCloseSession();
- }
- long stop = System.currentTimeMillis();
- System.out.println("=== Test finished processing " + INSTANCES + " instances in " + (stop - start) + "ms ===");
- System.out.println("=== This is " + Math.round(1000 * INSTANCES / (stop - start)) + " instances per second ===");
- }
+ for (int i = 0; i < INSTANCES; i++) {
+ beginSessionTransaction();
+ NewProcessInstanceCommand startCommand = new NewProcessInstanceCommand();
+ startCommand.setProcessDefinitionId(processDefinition.getId());
+ startCommand.setProcessDefinitionName("processDefinition1");
+ ProcessInstance pi = (ProcessInstance) commandService.execute(startCommand);
- public static class PerfActionHandler implements ActionHandler
- {
- public void execute(ExecutionContext executionContext) throws Exception
- {
- //System.out.println(count);
- }
- }
+ Token token = pi.getRootToken();
+ token.lock(ESB_ASYNC_SIGNAL_ACTION_NAME);
+ final ExecuteActionJob signalJob = new ExecuteActionJob(token);
+
+ signalJob.setAction(signalAction);
+ signalJob.setDueDate(new Date());
+ signalJob.setSuspended(token.isSuspended());
+
+ final MessageService messageService = (MessageService) Services.getCurrentService(Services.SERVICENAME_MESSAGE, true);
+ messageService.send(signalJob);
+
+ commitAndCloseSession();
+ }
+
+ while (signaled.get() < INSTANCES) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ // no problem, computer's fault
+ }
+ }
+
+ stopJobExecutor();
+
+ long stop = System.currentTimeMillis();
+ System.out.println("=== Test finished processing " + INSTANCES + " instances in " + (stop - start) + "ms ===");
+ System.out.println("=== This is " + Math.round(1000 * INSTANCES / (stop - start)) + " instances per second ===");
+ }
+
+ public static class PerfActionHandler implements ActionHandler {
+ private static final long serialVersionUID = -2171981067863454024L;
+ public void execute(ExecutionContext executionContext) throws Exception {
+ //System.out.println(count);
+ count++;
+ }
+ }
+
+ private static class AsyncSignalAction implements ActionHandler {
+ private static final long serialVersionUID = -8617329370138396271L;
+
+ AsyncSignalAction(final String configuration) throws JbpmException {
+ }
+
+ public void execute(final ExecutionContext executionContext)
+ throws Exception {
+ final Token token = executionContext.getToken();
+ final long tokenId = token.getId();
+ token.unlock(ESB_ASYNC_SIGNAL_ACTION_NAME);
+ final JbpmContext jbpmContext = executionContext.getJbpmContext();
+
+ final SignalCommand signalCommand = new SignalCommand(tokenId, null);
+ signalCommand.execute(jbpmContext);
+
+ signaled.incrementAndGet();
+ }
+ }
}
More information about the jbpm-commits
mailing list