[jbpm-commits] JBoss JBPM SVN: r6701 - in jbpm3/branches/jbpm-3.2-soa/core/src: main/java/org/jbpm/logging/db and 4 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Sep 29 17:14:18 EDT 2010


Author: alex.guizar at jboss.com
Date: 2010-09-29 17:14:17 -0400 (Wed, 29 Sep 2010)
New Revision: 6701

Added:
   jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm2947/
   jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm2947/CustomLoggingServiceTest.java
   jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm2947/MemoryLoggingService.java
   jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm2947/NoLoggingServiceTest.java
   jbpm3/branches/jbpm-3.2-soa/core/src/test/resources/org/jbpm/jbpm2947/
   jbpm3/branches/jbpm-3.2-soa/core/src/test/resources/org/jbpm/jbpm2947/custom-log.cfg.xml
   jbpm3/branches/jbpm-3.2-soa/core/src/test/resources/org/jbpm/jbpm2947/no-log.cfg.xml
Modified:
   jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/VariableContainer.java
   jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/logging/db/DbLoggingService.java
Log:
JBPM-2947 provide test cases for (a) custom logging service and (b) no logging service

Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/VariableContainer.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/VariableContainer.java	2010-09-29 18:45:19 UTC (rev 6700)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/VariableContainer.java	2010-09-29 21:14:17 UTC (rev 6701)
@@ -196,16 +196,15 @@
     if (variableInstances != null) {
       VariableInstance variableInstance = (VariableInstance) variableInstances.remove(name);
       if (variableInstance != null) {
+        // unlink variable
         variableInstance.removeReferences();
-        // is engine running in memory only or with logging enabled?
+        // log variable deletion
+        getToken().addLog(new VariableDeleteLog(variableInstance));
+
+        // if a context is present and its logging service is not connected to the database 
         JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
-        if (jbpmContext == null || (jbpmContext.getServices().getLoggingService() !=null )) {
-          // record variable deletion
-          // do not actually delete variable instance because log refers to it
-          getToken().addLog(new VariableDeleteLog(variableInstance));
-        }
-                
-        if (jbpmContext != null && ((jbpmContext.getServices().getLoggingService() != null) && !(jbpmContext.getServices().getLoggingService() instanceof DbLoggingService))){
+        if (jbpmContext != null
+          && !(jbpmContext.getServices().getLoggingService() instanceof DbLoggingService)) {
           // delete variable instance here before all references to it are lost
           Session session = jbpmContext.getSession();
           if (session != null) session.delete(variableInstance);

Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/logging/db/DbLoggingService.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/logging/db/DbLoggingService.java	2010-09-29 18:45:19 UTC (rev 6700)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/logging/db/DbLoggingService.java	2010-09-29 21:14:17 UTC (rev 6701)
@@ -30,23 +30,23 @@
 public class DbLoggingService implements LoggingService {
 
   private static final long serialVersionUID = 1L;
-  
-  Session session = null;
-  
+
+  private final Session session;
+
   public DbLoggingService() {
-    JbpmContext currentJbpmContext = JbpmContext.getCurrentJbpmContext();
-    if (currentJbpmContext==null) {
-      throw new JbpmException("instantiation of the DbLoggingService requires a current JbpmContext");
+    JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
+    if (jbpmContext == null) {
+      throw new JbpmException("no active jbpm context");
     }
-    session = currentJbpmContext.getSession();
+    session = jbpmContext.getSession();
   }
 
   public void log(ProcessLog processLog) {
-    if (session!=null) {
+    if (session != null) {
       // Improvement suggestions by Max :
-      // db-level: use some hilo based id strategy to avoid repetitive insert. (dependent on db-lock)
-      // sessionwise: use statelesssession or at least different session
-      // can we borrow connection safely. Nag Steve. (open ontop of another session)
+      // db-level: use hilo based id strategy to avoid repetitive insert (dependent on db-lock)
+      // session: use stateless session or at least different session
+      // can we borrow connection safely. (open on top of another session)
       session.save(processLog);
     }
   }

Added: jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm2947/CustomLoggingServiceTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm2947/CustomLoggingServiceTest.java	                        (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm2947/CustomLoggingServiceTest.java	2010-09-29 21:14:17 UTC (rev 6701)
@@ -0,0 +1,88 @@
+/*
+ * 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.jbpm2947;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.hibernate.criterion.Projections;
+
+import org.jbpm.context.def.ContextDefinition;
+import org.jbpm.context.exe.VariableInstance;
+import org.jbpm.context.log.VariableDeleteLog;
+import org.jbpm.db.AbstractDbTestCase;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.logging.log.ProcessLog;
+
+/**
+ * Custom logging causes orphaned variables.
+ * 
+ * @see <a href="https://jira.jboss.org/browse/JBPM-2947">JBPM-2947</a>
+ * @author Alejandro Guizar
+ */
+public class CustomLoggingServiceTest extends AbstractDbTestCase {
+
+  protected String getJbpmTestConfig() {
+    return "org/jbpm/jbpm2947/custom-log.cfg.xml";
+  }
+
+  protected void tearDown() throws Exception {
+    super.tearDown();
+    jbpmConfiguration.close();
+  }
+
+  public void testDeleteVariable() {
+    ProcessDefinition processDefinition = new ProcessDefinition("jbpm2947");
+    processDefinition.addDefinition(new ContextDefinition());
+    deployProcessDefinition(processDefinition);
+
+    ProcessInstance processInstance = jbpmContext.newProcessInstance("jbpm2947");
+    processInstance.getContextInstance().setVariable("var", "what's up, doc?");
+
+    processInstance = saveAndReload(processInstance);
+    processInstance.getContextInstance().deleteVariable("var");
+    jbpmContext.save(processInstance);
+
+    // verify the variable instance was deleted
+    Number varCount = (Number) session.createCriteria(VariableInstance.class)
+      .setProjection(Projections.rowCount())
+      .uniqueResult();
+    assertEquals(0, varCount.intValue());
+
+    // check the variable delete log was passed to the logging service
+    MemoryLoggingService loggingService = (MemoryLoggingService) jbpmContext.getServices()
+      .getLoggingService();
+    VariableDeleteLog processLog = (VariableDeleteLog) findLog(loggingService.getProcessLogs(), VariableDeleteLog.class);
+    assertEquals("var", processLog.getVariableInstance().getName());
+  }
+
+  private static ProcessLog findLog(List processLogs, Class logType) {
+    for (Iterator i = processLogs.iterator(); i.hasNext();) {
+      ProcessLog processLog = (ProcessLog) i.next();
+      if (logType.isInstance(processLog)) {
+        return processLog;
+      }
+    }
+    return null;
+  }
+}


Property changes on: jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm2947/CustomLoggingServiceTest.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm2947/MemoryLoggingService.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm2947/MemoryLoggingService.java	                        (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm2947/MemoryLoggingService.java	2010-09-29 21:14:17 UTC (rev 6701)
@@ -0,0 +1,64 @@
+/*
+ * 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.jbpm2947;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jbpm.logging.LoggingService;
+import org.jbpm.logging.log.ProcessLog;
+import org.jbpm.svc.Service;
+import org.jbpm.svc.ServiceFactory;
+
+/**
+ * @author Alejandro Guizar
+ */
+public class MemoryLoggingService implements LoggingService {
+
+  private final List processLogs = new ArrayList();
+  private static final long serialVersionUID = 1L;
+
+  public List getProcessLogs() {
+    return processLogs;
+  }
+
+  public void log(ProcessLog processLog) {
+    processLogs.add(processLog);
+  }
+
+  public void close() {
+    // nothing to do here
+  }
+
+  public static class Factory implements ServiceFactory {
+
+    private static final long serialVersionUID = 1L;
+
+    public Service openService() {
+      return new MemoryLoggingService();
+    }
+
+    public void close() {
+      // nothing to do here
+    }
+  }
+}


Property changes on: jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm2947/MemoryLoggingService.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm2947/NoLoggingServiceTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm2947/NoLoggingServiceTest.java	                        (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm2947/NoLoggingServiceTest.java	2010-09-29 21:14:17 UTC (rev 6701)
@@ -0,0 +1,70 @@
+/*
+ * 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.jbpm2947;
+
+import org.hibernate.criterion.Projections;
+
+import org.jbpm.context.def.ContextDefinition;
+import org.jbpm.context.exe.VariableInstance;
+import org.jbpm.db.AbstractDbTestCase;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ProcessInstance;
+
+/**
+ * Custom logging causes orphaned variables.
+ * 
+ * @see <a href="https://jira.jboss.org/browse/JBPM-2947">JBPM-2947</a>
+ * @author Alejandro Guizar
+ */
+public class NoLoggingServiceTest extends AbstractDbTestCase {
+
+  protected String getJbpmTestConfig() {
+    return "org/jbpm/jbpm2947/no-log.cfg.xml";
+  }
+
+  protected void tearDown() throws Exception {
+    super.tearDown();
+    jbpmConfiguration.close();
+  }
+
+  public void testDeleteVariable() {
+    assertNull("expected logging service to be absent",
+      jbpmContext.getServices().getLoggingService());
+
+    ProcessDefinition processDefinition = new ProcessDefinition("jbpm2947");
+    processDefinition.addDefinition(new ContextDefinition());
+    deployProcessDefinition(processDefinition);
+
+    ProcessInstance processInstance = jbpmContext.newProcessInstance("jbpm2947");
+    processInstance.getContextInstance().setVariable("var", "what's up, doc?");
+
+    processInstance = saveAndReload(processInstance);
+    processInstance.getContextInstance().deleteVariable("var");
+    jbpmContext.save(processInstance);
+
+    // verify the variable instance was deleted
+    Number varCount = (Number) session.createCriteria(VariableInstance.class)
+      .setProjection(Projections.rowCount())
+      .uniqueResult();
+    assertEquals(0, varCount.intValue());
+  }
+}


Property changes on: jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm2947/NoLoggingServiceTest.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: jbpm3/branches/jbpm-3.2-soa/core/src/test/resources/org/jbpm/jbpm2947/custom-log.cfg.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/test/resources/org/jbpm/jbpm2947/custom-log.cfg.xml	                        (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/test/resources/org/jbpm/jbpm2947/custom-log.cfg.xml	2010-09-29 21:14:17 UTC (rev 6701)
@@ -0,0 +1,10 @@
+<jbpm-configuration>
+  <jbpm-context>
+    <service name="authentication" factory="org.jbpm.security.authentication.DefaultAuthenticationServiceFactory" />
+    <service name="logging" factory="org.jbpm.jbpm2947.MemoryLoggingService$Factory" />
+    <service name="message" factory="org.jbpm.msg.db.DbMessageServiceFactory" />
+    <service name="persistence" factory="org.jbpm.persistence.db.DbPersistenceServiceFactory" />
+    <service name="scheduler" factory="org.jbpm.scheduler.db.DbSchedulerServiceFactory" />
+    <service name="tx" factory="org.jbpm.tx.TxServiceFactory" />
+  </jbpm-context>
+</jbpm-configuration>
\ No newline at end of file


Property changes on: jbpm3/branches/jbpm-3.2-soa/core/src/test/resources/org/jbpm/jbpm2947/custom-log.cfg.xml
___________________________________________________________________
Name: svn:eol-style
   + native

Added: jbpm3/branches/jbpm-3.2-soa/core/src/test/resources/org/jbpm/jbpm2947/no-log.cfg.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/test/resources/org/jbpm/jbpm2947/no-log.cfg.xml	                        (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/test/resources/org/jbpm/jbpm2947/no-log.cfg.xml	2010-09-29 21:14:17 UTC (rev 6701)
@@ -0,0 +1,9 @@
+<jbpm-configuration>
+  <jbpm-context>
+    <service name="authentication" factory="org.jbpm.security.authentication.DefaultAuthenticationServiceFactory" />
+    <service name="message" factory="org.jbpm.msg.db.DbMessageServiceFactory" />
+    <service name="persistence" factory="org.jbpm.persistence.db.DbPersistenceServiceFactory" />
+    <service name="scheduler" factory="org.jbpm.scheduler.db.DbSchedulerServiceFactory" />
+    <service name="tx" factory="org.jbpm.tx.TxServiceFactory" />
+  </jbpm-context>
+</jbpm-configuration>
\ No newline at end of file


Property changes on: jbpm3/branches/jbpm-3.2-soa/core/src/test/resources/org/jbpm/jbpm2947/no-log.cfg.xml
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the jbpm-commits mailing list