[jbpm-commits] JBoss JBPM SVN: r2573 - jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1072.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Oct 21 20:29:10 EDT 2008


Author: alex.guizar at jboss.com
Date: 2008-10-21 20:29:09 -0400 (Tue, 21 Oct 2008)
New Revision: 2573

Modified:
   jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1072/JBPM1072Test.java
Log:
[JBPM-1072] fixed test case database record leaks

Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1072/JBPM1072Test.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1072/JBPM1072Test.java	2008-10-21 15:58:15 UTC (rev 2572)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/jbpm1072/JBPM1072Test.java	2008-10-22 00:29:09 UTC (rev 2573)
@@ -1,3 +1,24 @@
+/*
+ * 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.jbpm1072;
 
 import org.jbpm.EventCallback;
@@ -2,4 +23,2 @@
 import org.jbpm.JbpmConfiguration;
-import org.jbpm.JbpmConfigurationTestHelper;
-import org.jbpm.JbpmContext;
 import org.jbpm.db.AbstractDbTestCase;
@@ -20,16 +39,17 @@
  * @author Jiri Pechanec
  * @author Alejandro Guizar
  */
-public class JBPM1072Test extends AbstractDbTestCase 
-{
+public class JBPM1072Test extends AbstractDbTestCase {
 
-  private static final int EXECUTOR_COUNT = 20;
-  public static final String PROCESS_NAME = "TestProcess";
+  private static final int JOB_EXECUTOR_COUNT = 20;
 
-  private JobExecutor[] executors = new JobExecutor[EXECUTOR_COUNT];
+  private JobExecutor[] jobExecutors = new JobExecutor[JOB_EXECUTOR_COUNT];
+  private ProcessDefinition processDefinition;
 
-  public static final String PROCESS_DEFINITION = "<?xml version='1.0' encoding='UTF-8'?>"
-      + "<process-definition name='" + PROCESS_NAME + "'>"
+  private static final String PROCESS_DEFINITION = "<?xml version='1.0' encoding='UTF-8'?>"
+      + "<process-definition name='"
+      + JBPM1072Test.class.getName()
+      + "'>"
       + "<event type='process-end'>"
       + "<action expression='#{eventCallback.processEnd}' />"
       + "</event>"
@@ -52,87 +72,75 @@
       + "</process-definition>";
 
   @Override
-  protected JbpmConfiguration getJbpmConfiguration()
-  {
-    JbpmConfigurationTestHelper.reset();
-    return JbpmConfiguration.getInstance();
+  protected void setUp() throws Exception {
+    super.setUp();
+    processDefinition = ProcessDefinition.parseXmlString(PROCESS_DEFINITION);
+    jbpmContext.deployProcessDefinition(processDefinition);
   }
 
-  public void testMultipleJobExecutors()
-  {
+  @Override
+  protected void tearDown() throws Exception {
+    graphSession.deleteProcessDefinition(processDefinition);
+    super.tearDown();
+  }
+
+  public void testMultipleJobExecutors() {
     // start job executors
-    for (int i = 0; i < executors.length; i++)
-    {
-      executors[i] = (JobExecutor)JbpmConfiguration.Configs.getObjectFactory().createObject("jbpm.job.executor");
-      executors[i].setName("JbpmJobExecutor/" + (i + 1));
-      executors[i].start();
+    for (int i = 0; i < jobExecutors.length; i++) {
+      jobExecutors[i] = (JobExecutor) JbpmConfiguration.Configs.getObject("jbpm.job.executor");
+      jobExecutors[i].setName("JbpmJobExecutor/" + (i + 1));
+      jobExecutors[i].start();
     }
 
     // kick off process instance
-    JbpmContext jbpmContext = getJbpmConfiguration().createJbpmContext();
-    try
-    {
-      jbpmContext.deployProcessDefinition(ProcessDefinition.parseXmlString(PROCESS_DEFINITION));
-      ProcessInstance processInstance = jbpmContext.newProcessInstance(PROCESS_NAME);
-      processInstance.getContextInstance().setVariable("eventCallback", new EventCallback());
-      processInstance.signal();
-    }
-    finally
-    {
-      jbpmContext.close();
-    }
+    ProcessInstance processInstance = new ProcessInstance(processDefinition);
+    processInstance.getContextInstance().setVariable("eventCallback", new EventCallback());
+    processInstance.signal();
+    commitAndCloseSession();
 
     // wait for process end
     EventCallback.waitForEvent(Event.EVENTTYPE_PROCESS_END);
 
     // stop job executors
-    for (int i = executors.length - 1; i >= 0; i--)
-    {
-      try
-      {
-        executors[i].stopAndJoin();
+    for (int i = jobExecutors.length - 1; i >= 0; i--) {
+      try {
+        jobExecutors[i].stopAndJoin();
       }
-      catch (InterruptedException e)
-      {
+      catch (InterruptedException e) {
         // continue to next executor
       }
     }
 
+    beginSessionTransaction();
     assertEquals(1, SimpleAction2.getExecutionCount());
   }
 
-  public static class SimpleAction implements ActionHandler
-  {
+  public static class SimpleAction implements ActionHandler {
 
     private static final long serialVersionUID = 1L;
 
-    public void execute(ExecutionContext exeContext) throws Exception
-    {
+    public void execute(ExecutionContext exeContext) throws Exception {
       exeContext.leaveNode();
     }
 
   }
 
-  public static class SimpleAction2 implements ActionHandler
-  {
+  public static class SimpleAction2 implements ActionHandler {
 
     private static int executionCount = 0;
 
     private static final long serialVersionUID = 1L;
 
-    public void execute(ExecutionContext exeContext) throws Exception
-    {
+    public void execute(ExecutionContext exeContext) throws Exception {
       incrementCount();
       exeContext.leaveNode();
     }
 
-    private static synchronized int incrementCount()
-    {
+    private static synchronized int incrementCount() {
       return ++executionCount;
     }
 
-    public static synchronized int getExecutionCount()
-    {
+    public static synchronized int getExecutionCount() {
       return executionCount;
     }
   }




More information about the jbpm-commits mailing list