details:   https://code.openbravo.com/erp/devel/pi/rev/4ecfba1d868c
changeset: 26671:4ecfba1d868c
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Thu May 21 09:39:04 2015 +0200
summary:   fixed bug 29902: ProcessBundle.setCloseConnection(false) closes 
connection

  When a process is invoked through ProcessRunner and its bundle is set as
  setCloseConnection(false) there were 2 problems:
    - connection was close after execution so it could not be reused by another
      process invoking it
    - ProcessRunner tried to update the process run status on a closed 
connection
      causing an error

  The problem is caused by the fix for issue #27878 which correctly closes the
  connection in DalConnectionProvider when invoking releaseCommitConnection. But
  when setCloseConnection it relied in that bug not closing the connection to
  leave it open.

  The solution consists in doing directly the commit or rollback in 
DalBaseProcess
  without closing the connection.

details:   https://code.openbravo.com/erp/devel/pi/rev/f74892c7bc32
changeset: 26672:f74892c7bc32
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Thu May 21 10:32:06 2015 +0200
summary:   related to bug 29902: added test case

diffstat:

 src-test/src/org/openbravo/test/AllAntTaskTests.java                  |   7 +-
 src-test/src/org/openbravo/test/scheduling/ProcessSchedulingTest.java |  87 
++++++++++
 src/org/openbravo/service/db/DalBaseProcess.java                      |  18 +-
 3 files changed, 106 insertions(+), 6 deletions(-)

diffs (164 lines):

diff -r 65e2c94fcafa -r f74892c7bc32 
src-test/src/org/openbravo/test/AllAntTaskTests.java
--- a/src-test/src/org/openbravo/test/AllAntTaskTests.java      Thu May 21 
10:27:18 2015 +0200
+++ b/src-test/src/org/openbravo/test/AllAntTaskTests.java      Thu May 21 
10:32:06 2015 +0200
@@ -57,6 +57,7 @@
 import org.openbravo.test.modularity.MergePropertiesTest;
 import org.openbravo.test.modularity.TableNameTest;
 import org.openbravo.test.preference.PreferenceTest;
+import org.openbravo.test.scheduling.ProcessSchedulingTest;
 import org.openbravo.test.security.AccessLevelTest;
 import org.openbravo.test.security.AllowedOrganizationsTest;
 import org.openbravo.test.security.EntityAccessTest;
@@ -154,6 +155,10 @@
 
     // Accounting
     RecordID2Test.class, //
-    PostDocumentTest.class })
+    PostDocumentTest.class, //
+
+    // scheduling
+    ProcessSchedulingTest.class //
+})
 public class AllAntTaskTests {
 }
diff -r 65e2c94fcafa -r f74892c7bc32 
src-test/src/org/openbravo/test/scheduling/ProcessSchedulingTest.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/test/scheduling/ProcessSchedulingTest.java     
Thu May 21 10:32:06 2015 +0200
@@ -0,0 +1,87 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License. 
+ * The Original Code is Openbravo ERP. 
+ * The Initial Developer of the Original Code is Openbravo SLU 
+ * All portions are Copyright (C) 2015 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.test.scheduling;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+import java.util.HashMap;
+
+import org.junit.Test;
+import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.ad.ui.ProcessRun;
+import org.openbravo.scheduling.Process;
+import org.openbravo.scheduling.ProcessBundle;
+import org.openbravo.scheduling.ProcessLogger;
+import org.openbravo.scheduling.ProcessRunner;
+import org.openbravo.service.db.DalBaseProcess;
+import org.openbravo.service.db.DalConnectionProvider;
+import org.openbravo.test.base.OBBaseTest;
+
+/**
+ * Test cases for process schedule and process runner
+ * 
+ * @author alostale
+ *
+ */
+public class ProcessSchedulingTest extends OBBaseTest {
+  private static final String anyProcessID = "800170";
+  private static final String USER_ID = "100";
+  private static final String ROLE_ID = "0";
+  private static final String CLIENT_ID = "0";
+  private static final String ORG_ID = "0";
+
+  /**
+   * Test case to cover issue #29902. Before its fix it failed throwing an 
exception due to
+   * ProcessRunner attempting to set process run status on an already closed 
connection.
+   */
+  @Test
+  public void processRunnerNotClosingConnection() throws Exception {
+    DalConnectionProvider conn = new DalConnectionProvider();
+    VariablesSecureApp vsa = new VariablesSecureApp(USER_ID, CLIENT_ID, 
ORG_ID, ROLE_ID);
+    ProcessBundle bundle = new ProcessBundle(anyProcessID, vsa);
+
+    // fake the bundle to execute MyProcess even it's not defined in AD
+    bundle.setProcessClass(MyProcess.class);
+    bundle.setParams(new HashMap<String, Object>());
+    bundle.setConnection(conn);
+    bundle.setLog(new ProcessLogger(conn));
+
+    // do not close the connection after executing the process
+    bundle.setCloseConnection(false);
+
+    // invoke the process through ProcessRunner
+    String executionId = new ProcessRunner(bundle).execute(conn);
+
+    ProcessRun pr = OBDal.getInstance().get(ProcessRun.class, executionId);
+    assertThat("Process Run is saved", pr, notNullValue());
+    assertThat("Process status", pr.getStatus(), equalTo(Process.SUCCESS));
+  }
+
+  /** Fake process */
+  public static class MyProcess extends DalBaseProcess {
+    @Override
+    protected void doExecute(ProcessBundle bundle) throws Exception {
+      // do nothing
+    }
+  }
+}
diff -r 65e2c94fcafa -r f74892c7bc32 
src/org/openbravo/service/db/DalBaseProcess.java
--- a/src/org/openbravo/service/db/DalBaseProcess.java  Thu May 21 10:27:18 
2015 +0200
+++ b/src/org/openbravo/service/db/DalBaseProcess.java  Thu May 21 10:32:06 
2015 +0200
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2009-2012 Openbravo SLU 
+ * All portions are Copyright (C) 2009-2015 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -19,6 +19,8 @@
 
 package org.openbravo.service.db;
 
+import java.sql.Connection;
+
 import org.apache.log4j.Logger;
 import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.client.kernel.RequestContext;
@@ -89,18 +91,24 @@
         if (bundle.getCloseConnection()) {
           OBDal.getInstance().rollbackAndClose();
         } else {
-          
bundle.getConnection().releaseRollbackConnection(bundle.getConnection().getConnection());
+          // connection shoulnd't be closed after process execution: do roll 
back but leave it open
+          Connection con = bundle.getConnection().getConnection();
+          if (con != null && !con.isClosed()) {
+            con.rollback();
+          }
         }
-
       } else {
         if (isDoCommit()) {
           if (bundle.getCloseConnection()) {
             OBDal.getInstance().commitAndClose();
           } else {
-            
bundle.getConnection().releaseCommitConnection(bundle.getConnection().getConnection());
+            // connection shoulnd't be closed after process execution: do 
commit but leave it open
+            Connection con = bundle.getConnection().getConnection();
+            if (con != null && !con.isClosed()) {
+              con.commit();
+            }
           }
         }
-
       }
 
       // remove the context at the end, maybe the process scheduler

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to