This is an automated email from the ASF dual-hosted git repository.

vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/main by this push:
     new 2b0ba72f06 Port `log4j-jdbc-dbcp2` changes from `2.x` (#2163)
2b0ba72f06 is described below

commit 2b0ba72f06d613adf82b18c5d652173ae733ee1e
Author: Volkan Yazıcı <[email protected]>
AuthorDate: Wed Jan 10 14:36:47 2024 +0100

    Port `log4j-jdbc-dbcp2` changes from `2.x` (#2163)
---
 log4j-jdbc-dbcp2/pom.xml                             |  6 ------
 .../appender/PoolingDriverConnectionSourceTest.java  | 20 ++++++++++++--------
 .../src/test/resources/log4j2-jdbc-dbcp2.xml         |  4 ++++
 3 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/log4j-jdbc-dbcp2/pom.xml b/log4j-jdbc-dbcp2/pom.xml
index 302ea20ac5..ec67a8828e 100644
--- a/log4j-jdbc-dbcp2/pom.xml
+++ b/log4j-jdbc-dbcp2/pom.xml
@@ -28,7 +28,6 @@
   <name>Apache Log4j JDBC DBCP 2</name>
   <description>Connection source for the JDBC Appender using Apache Commons 
DBCP2.</description>
   <properties>
-    <log4jParentDir>${basedir}/..</log4jParentDir>
 
     <!--
       ~ OSGi and JPMS options
@@ -75,11 +74,6 @@
       <artifactId>h2</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.hamcrest</groupId>
-      <artifactId>hamcrest</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>org.junit.jupiter</groupId>
       <artifactId>junit-jupiter-engine</artifactId>
diff --git 
a/log4j-jdbc-dbcp2/src/test/java/org/apache/logging/log4j/dbcp2/appender/PoolingDriverConnectionSourceTest.java
 
b/log4j-jdbc-dbcp2/src/test/java/org/apache/logging/log4j/dbcp2/appender/PoolingDriverConnectionSourceTest.java
index 6dc7153bbe..41282207f3 100644
--- 
a/log4j-jdbc-dbcp2/src/test/java/org/apache/logging/log4j/dbcp2/appender/PoolingDriverConnectionSourceTest.java
+++ 
b/log4j-jdbc-dbcp2/src/test/java/org/apache/logging/log4j/dbcp2/appender/PoolingDriverConnectionSourceTest.java
@@ -25,14 +25,6 @@ import org.junit.Test;
 
 public class PoolingDriverConnectionSourceTest {
 
-    private void openAndClose(final PoolingDriverConnectionSource source) 
throws SQLException {
-        try (final Connection conn = source.getConnection()) {
-            Assert.assertFalse(conn.isClosed());
-        } finally {
-            source.stop();
-        }
-    }
-
     @Test
     public void testH2Properties() throws SQLException {
         final Property[] properties = new Property[] {
@@ -47,6 +39,7 @@ public class PoolingDriverConnectionSourceTest {
                         
.setConnectionString(JdbcH2TestHelper.CONNECTION_STRING_IN_MEMORY)
                         .setProperties(properties)
                         .build();
+        // @formatter:on
         openAndClose(source);
     }
 
@@ -78,9 +71,19 @@ public class PoolingDriverConnectionSourceTest {
                         .setUserName(JdbcH2TestHelper.USER_NAME.toCharArray())
                         .setPassword(JdbcH2TestHelper.PASSWORD.toCharArray())
                         .build();
+        // @formatter:on
         openAndClose(source);
     }
 
+    private void openAndClose(final PoolingDriverConnectionSource source) 
throws SQLException {
+        Assert.assertNotNull("PoolingDriverConnectionSource is null", source);
+        try (final Connection conn = source.getConnection()) {
+            Assert.assertFalse(conn.isClosed());
+        } finally {
+            source.stop();
+        }
+    }
+
     @Test
     public void testH2UserPasswordAndPoolName() throws SQLException {
         // @formatter:off
@@ -91,6 +94,7 @@ public class PoolingDriverConnectionSourceTest {
                         .setPassword(JdbcH2TestHelper.PASSWORD.toCharArray())
                         .setPoolName("MyPoolName")
                         .build();
+        // @formatter:on
         openAndClose(source);
     }
 
diff --git a/log4j-jdbc-dbcp2/src/test/resources/log4j2-jdbc-dbcp2.xml 
b/log4j-jdbc-dbcp2/src/test/resources/log4j2-jdbc-dbcp2.xml
index 762ceefe35..b778288960 100644
--- a/log4j-jdbc-dbcp2/src/test/resources/log4j2-jdbc-dbcp2.xml
+++ b/log4j-jdbc-dbcp2/src/test/resources/log4j2-jdbc-dbcp2.xml
@@ -39,6 +39,10 @@
           rollbackOnReturn="true"
           validationQuery=""
           validationQueryTimeoutSeconds="-1">
+          <DisconnectionSqlCodes>
+               <String>1</String>
+               <String>2</String>
+          </DisconnectionSqlCodes>
         </PoolableConnectionFactory>
       </PoolingDriver>
       <ColumnMapping name="ColumnA" />

Reply via email to