Skip to content

Commit 2b0ba72

Browse files
committed
Port log4j-jdbc-dbcp2 changes from 2.x (#2163)
1 parent 245da43 commit 2b0ba72

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

log4j-jdbc-dbcp2/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
<name>Apache Log4j JDBC DBCP 2</name>
2929
<description>Connection source for the JDBC Appender using Apache Commons DBCP2.</description>
3030
<properties>
31-
<log4jParentDir>${basedir}/..</log4jParentDir>
3231

3332
<!--
3433
~ OSGi and JPMS options
@@ -75,11 +74,6 @@
7574
<artifactId>h2</artifactId>
7675
<scope>test</scope>
7776
</dependency>
78-
<dependency>
79-
<groupId>org.hamcrest</groupId>
80-
<artifactId>hamcrest</artifactId>
81-
<scope>test</scope>
82-
</dependency>
8377
<dependency>
8478
<groupId>org.junit.jupiter</groupId>
8579
<artifactId>junit-jupiter-engine</artifactId>

log4j-jdbc-dbcp2/src/test/java/org/apache/logging/log4j/dbcp2/appender/PoolingDriverConnectionSourceTest.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@
2525

2626
public class PoolingDriverConnectionSourceTest {
2727

28-
private void openAndClose(final PoolingDriverConnectionSource source) throws SQLException {
29-
try (final Connection conn = source.getConnection()) {
30-
Assert.assertFalse(conn.isClosed());
31-
} finally {
32-
source.stop();
33-
}
34-
}
35-
3628
@Test
3729
public void testH2Properties() throws SQLException {
3830
final Property[] properties = new Property[] {
@@ -47,6 +39,7 @@ public void testH2Properties() throws SQLException {
4739
.setConnectionString(JdbcH2TestHelper.CONNECTION_STRING_IN_MEMORY)
4840
.setProperties(properties)
4941
.build();
42+
// @formatter:on
5043
openAndClose(source);
5144
}
5245

@@ -78,9 +71,19 @@ public void testH2UserAndPassword() throws SQLException {
7871
.setUserName(JdbcH2TestHelper.USER_NAME.toCharArray())
7972
.setPassword(JdbcH2TestHelper.PASSWORD.toCharArray())
8073
.build();
74+
// @formatter:on
8175
openAndClose(source);
8276
}
8377

78+
private void openAndClose(final PoolingDriverConnectionSource source) throws SQLException {
79+
Assert.assertNotNull("PoolingDriverConnectionSource is null", source);
80+
try (final Connection conn = source.getConnection()) {
81+
Assert.assertFalse(conn.isClosed());
82+
} finally {
83+
source.stop();
84+
}
85+
}
86+
8487
@Test
8588
public void testH2UserPasswordAndPoolName() throws SQLException {
8689
// @formatter:off
@@ -91,6 +94,7 @@ public void testH2UserPasswordAndPoolName() throws SQLException {
9194
.setPassword(JdbcH2TestHelper.PASSWORD.toCharArray())
9295
.setPoolName("MyPoolName")
9396
.build();
97+
// @formatter:on
9498
openAndClose(source);
9599
}
96100

log4j-jdbc-dbcp2/src/test/resources/log4j2-jdbc-dbcp2.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
rollbackOnReturn="true"
4040
validationQuery=""
4141
validationQueryTimeoutSeconds="-1">
42+
<DisconnectionSqlCodes>
43+
<String>1</String>
44+
<String>2</String>
45+
</DisconnectionSqlCodes>
4246
</PoolableConnectionFactory>
4347
</PoolingDriver>
4448
<ColumnMapping name="ColumnA" />

0 commit comments

Comments
 (0)