Skip to content

Commit

Permalink
Port log4j-jdbc-dbcp2 changes from 2.x (#2163)
Browse files Browse the repository at this point in the history
  • Loading branch information
vy committed Jan 10, 2024
1 parent 245da43 commit 2b0ba72
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
6 changes: 0 additions & 6 deletions log4j-jdbc-dbcp2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@

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[] {
Expand All @@ -47,6 +39,7 @@ public void testH2Properties() throws SQLException {
.setConnectionString(JdbcH2TestHelper.CONNECTION_STRING_IN_MEMORY)
.setProperties(properties)
.build();
// @formatter:on
openAndClose(source);
}

Expand Down Expand Up @@ -78,9 +71,19 @@ public void testH2UserAndPassword() throws SQLException {
.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
Expand All @@ -91,6 +94,7 @@ public void testH2UserPasswordAndPoolName() throws SQLException {
.setPassword(JdbcH2TestHelper.PASSWORD.toCharArray())
.setPoolName("MyPoolName")
.build();
// @formatter:on
openAndClose(source);
}

Expand Down
4 changes: 4 additions & 0 deletions log4j-jdbc-dbcp2/src/test/resources/log4j2-jdbc-dbcp2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
rollbackOnReturn="true"
validationQuery=""
validationQueryTimeoutSeconds="-1">
<DisconnectionSqlCodes>
<String>1</String>
<String>2</String>
</DisconnectionSqlCodes>
</PoolableConnectionFactory>
</PoolingDriver>
<ColumnMapping name="ColumnA" />
Expand Down

0 comments on commit 2b0ba72

Please sign in to comment.