17
17
package org .apache .logging .log4j .core .test .appender .db .jdbc ;
18
18
19
19
import java .io .IOException ;
20
- import java .nio .file .Files ;
21
- import java .nio .file .Path ;
22
20
import java .sql .Connection ;
23
21
import java .sql .DriverManager ;
24
22
import java .sql .SQLException ;
25
23
26
24
import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
27
- import org .apache .commons .io .file .PathUtils ;
28
- import org .apache .commons .lang3 .SystemUtils ;
29
25
import org .apache .logging .log4j .core .appender .db .jdbc .AbstractConnectionSource ;
30
26
import org .apache .logging .log4j .core .appender .db .jdbc .ConnectionSource ;
31
27
@@ -37,9 +33,12 @@ public class JdbcH2TestHelper {
37
33
public static final String CONNECTION_STRING_IN_MEMORY = "jdbc:h2:mem:Log4j" ;
38
34
39
35
/**
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.
41
39
*/
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" ;
43
42
44
43
public static final String USER_NAME = "sa" ;
45
44
public static final String PASSWORD = "" ;
@@ -51,35 +50,31 @@ public Connection getConnection() throws SQLException {
51
50
}
52
51
};
53
52
53
+ @ Deprecated
54
54
public static ConnectionSource TEST_CONFIGURATION_SOURCE_TMPDIR = new AbstractConnectionSource () {
55
55
@ Override
56
56
public Connection getConnection () throws SQLException {
57
57
return JdbcH2TestHelper .getConnectionTempDir ();
58
58
}
59
59
};
60
60
61
- /** Directory used in configuration files and connection strings. */
62
- static final String H2_TEST_RELATIVE_DIR = "h2" ;
63
-
61
+ @ Deprecated
64
62
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
69
64
}
70
65
71
66
@ SuppressFBWarnings (value = "DMI_EMPTY_DB_PASSWORD" )
72
67
public static Connection getConnectionInMemory () throws SQLException {
73
68
return DriverManager .getConnection (CONNECTION_STRING_IN_MEMORY , USER_NAME , PASSWORD );
74
69
}
75
70
71
+ /**
72
+ * Since 2.22.0 this uses a permanent in-memory database.
73
+ */
74
+ @ Deprecated
76
75
@ SuppressFBWarnings (value = "DMI_EMPTY_DB_PASSWORD" )
77
76
public static Connection getConnectionTempDir () throws SQLException {
78
77
return DriverManager .getConnection (CONNECTION_STRING_TEMP_DIR , USER_NAME , PASSWORD );
79
78
}
80
79
81
- private static Path getH2Path () {
82
- return SystemUtils .getJavaIoTmpDir ().toPath ().resolve (H2_TEST_RELATIVE_DIR ).normalize ();
83
- }
84
-
85
80
}
0 commit comments