Skip to content

Commit 27f0627

Browse files
committed
Replace H2 file-based databases with in-memory databases
This improves parallelization of the tests.
1 parent c215cb6 commit 27f0627

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/appender/db/jdbc/JdbcH2TestHelper.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,11 @@
1717
package org.apache.logging.log4j.core.test.appender.db.jdbc;
1818

1919
import java.io.IOException;
20-
import java.nio.file.Files;
21-
import java.nio.file.Path;
2220
import java.sql.Connection;
2321
import java.sql.DriverManager;
2422
import java.sql.SQLException;
2523

2624
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
27-
import org.apache.commons.io.file.PathUtils;
28-
import org.apache.commons.lang3.SystemUtils;
2925
import org.apache.logging.log4j.core.appender.db.jdbc.AbstractConnectionSource;
3026
import org.apache.logging.log4j.core.appender.db.jdbc.ConnectionSource;
3127

@@ -37,9 +33,12 @@ public class JdbcH2TestHelper {
3733
public static final String CONNECTION_STRING_IN_MEMORY = "jdbc:h2:mem:Log4j";
3834

3935
/**
40-
* A JDBC connection string for an H2 database in the Java temporary directory.
36+
* A JDBC connection string for a permanent H2 database.
37+
*
38+
* Since 2.22.0 this uses a permanent in-memory database.
4139
*/
42-
public static final String CONNECTION_STRING_TEMP_DIR = "jdbc:h2:" + getH2Path() + "/test_log4j;TRACE_LEVEL_SYSTEM_OUT=0";
40+
@Deprecated
41+
public static final String CONNECTION_STRING_TEMP_DIR = "jdbc:h2:mem:Log4j_perm;DB_CLOSE_DELAY=-1";
4342

4443
public static final String USER_NAME = "sa";
4544
public static final String PASSWORD = "";
@@ -51,35 +50,31 @@ public Connection getConnection() throws SQLException {
5150
}
5251
};
5352

53+
@Deprecated
5454
public static ConnectionSource TEST_CONFIGURATION_SOURCE_TMPDIR = new AbstractConnectionSource() {
5555
@Override
5656
public Connection getConnection() throws SQLException {
5757
return JdbcH2TestHelper.getConnectionTempDir();
5858
}
5959
};
6060

61-
/** Directory used in configuration files and connection strings. */
62-
static final String H2_TEST_RELATIVE_DIR = "h2";
63-
61+
@Deprecated
6462
public static void deleteDir() throws IOException {
65-
final Path resolve = getH2Path();
66-
if (Files.exists(resolve)) {
67-
PathUtils.deleteDirectory(resolve);
68-
}
63+
// Since 2.22.0 this is a no-op
6964
}
7065

7166
@SuppressFBWarnings(value = "DMI_EMPTY_DB_PASSWORD")
7267
public static Connection getConnectionInMemory() throws SQLException {
7368
return DriverManager.getConnection(CONNECTION_STRING_IN_MEMORY, USER_NAME, PASSWORD);
7469
}
7570

71+
/**
72+
* Since 2.22.0 this uses a permanent in-memory database.
73+
*/
74+
@Deprecated
7675
@SuppressFBWarnings(value = "DMI_EMPTY_DB_PASSWORD")
7776
public static Connection getConnectionTempDir() throws SQLException {
7877
return DriverManager.getConnection(CONNECTION_STRING_TEMP_DIR, USER_NAME, PASSWORD);
7978
}
8079

81-
private static Path getH2Path() {
82-
return SystemUtils.getJavaIoTmpDir().toPath().resolve(H2_TEST_RELATIVE_DIR).normalize();
83-
}
84-
8580
}

log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/appender/db/jdbc/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the license.
1616
*/
1717
@Export
18-
@Version("2.20.1")
18+
@Version("2.20.2")
1919
package org.apache.logging.log4j.core.test.appender.db.jdbc;
2020

2121
import org.osgi.annotation.bundle.Export;

log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/db/jdbc/log4j2-dm-column-mapping-literal.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<PatternLayout pattern="%C{1.} %m %level MDC%X%n"/>
2323
</Console>
2424
<Jdbc name="databaseAppender" tableName="dsMappingLogEntry" ignoreExceptions="false">
25-
<DriverManager connectionString="jdbc:h2:${sys:java.io.tmpdir}/h2/test_log4j;TRACE_LEVEL_SYSTEM_OUT=0" userName="sa" password="" />
25+
<DriverManager connectionString="jdbc:h2:mem:Log4j_perm;DB_CLOSE_DELAY=-1" userName="sa" password="" />
2626
<ColumnMapping name="level" pattern="%level" />
2727
<ColumnMapping name="logger" pattern="%logger" />
2828
<ColumnMapping name="message" literal="'Hello World!'" />

0 commit comments

Comments
 (0)