Skip to content

Commit f1d50b6

Browse files
committed
Provide compatibility with 2.5 images
Address problem with 2.5-ss/2.5.x-ss images in README
1 parent f84dfba commit f1d50b6

4 files changed

Lines changed: 52 additions & 5 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ to provide lightweight, throwaway instances of Firebird for JUnit tests.
88

99
The docker image used is [jacobalberty/firebird](https://hub.docker.com/r/jacobalberty/firebird/).
1010

11+
If you want to use 2.5, use the 2.5.x-sc (SuperClassic) variant of the image, as
12+
the 2.5.x-ss (SuperServer) variant seems to be broken.
13+
1114
Prerequisites
1215
-------------
1316

src/main/java/org/firebirdsql/testcontainers/FirebirdContainer.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import lombok.extern.slf4j.Slf4j;
44
import org.testcontainers.containers.JdbcDatabaseContainer;
5+
import org.testcontainers.utility.DockerImageName;
56

67
import javax.crypto.Cipher;
78
import java.security.NoSuchAlgorithmException;
@@ -71,14 +72,27 @@ public String getDriverClassName() {
7172

7273
@Override
7374
public String getJdbcUrl() {
74-
return "jdbc:firebirdsql://" + getContainerIpAddress() + ":" + getMappedPort(FIREBIRD_PORT) + "/" + databaseName;
75+
return "jdbc:firebirdsql://" + getContainerIpAddress() + ":" + getMappedPort(FIREBIRD_PORT) + "/" + getDatabaseName();
7576
}
7677

7778
@Override
7879
public String getDatabaseName() {
80+
if (isRunning()) {
81+
if (isFirebird25Image()) {
82+
// The 2.5 images of jacobalberty/firebird require an absolute path to access the database
83+
// Provide this value only when the container is running
84+
String databasePath = getEnvMap().getOrDefault("DBPATH", "/firebird/data");
85+
return databasePath + "/" + databaseName;
86+
}
87+
}
7988
return databaseName;
8089
}
8190

91+
private boolean isFirebird25Image() {
92+
DockerImageName imageName = new DockerImageName(getDockerImageName());
93+
return imageName.getUnversionedPart().equals(IMAGE) && imageName.getVersionPart().startsWith("2.5");
94+
}
95+
8296
@Override
8397
public String getUsername() {
8498
return username;
@@ -160,6 +174,7 @@ public SELF withSysdbaPassword(final String sysdbaPassword) {
160174
@Override
161175
protected void waitUntilContainerStarted() {
162176
getWaitStrategy().waitUntilReady(this);
177+
super.waitUntilContainerStarted();
163178
}
164179

165180
/**

src/test/java/org/firebirdsql/testcontainers/FirebirdContainerTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
import java.sql.*;
88

9+
import static org.firebirdsql.testcontainers.FirebirdContainer.FIREBIRD_PORT;
10+
import static org.firebirdsql.testcontainers.FirebirdContainer.IMAGE;
11+
import static org.junit.Assert.assertEquals;
12+
import static org.junit.Assert.assertTrue;
913
import static org.rnorth.visibleassertions.VisibleAssertions.*;
1014

1115
public class FirebirdContainerTest {
@@ -71,4 +75,27 @@ public void testWithEnableWireCrypt() throws SQLException {
7175
}
7276
}
7377
}
78+
79+
/**
80+
* The 2.5 images of jacobalberty/firebird handle FIREBIRD_DATABASE and need an absolute path to access the database
81+
*/
82+
@Test
83+
public void test258_scImage() throws Exception {
84+
try (FirebirdContainer container = new FirebirdContainer(IMAGE + ":2.5.8-sc").withDatabaseName("test")) {
85+
assertEquals("Expect original database name before start",
86+
"test", container.getDatabaseName());
87+
88+
container.start();
89+
90+
assertEquals("Expect modified database name after start",
91+
"/firebird/data/test", container.getDatabaseName());
92+
93+
try (Connection connection = DriverManager
94+
.getConnection("jdbc:firebirdsql://" + container.getContainerIpAddress() + ":" + container.getMappedPort(FIREBIRD_PORT) + "/" + container.getDatabaseName(),
95+
container.getUsername(), container.getPassword())
96+
) {
97+
assertTrue(connection.isValid(1000));
98+
}
99+
}
100+
}
74101
}

src/test/java/org/firebirdsql/testcontainers/JDBCDriverTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public class JDBCDriverTest {
2525
private enum Options {
2626
ScriptedSchema,
2727
JDBCParams,
28-
RequiresTable,
2928
}
3029

3130
@Parameter
@@ -37,9 +36,12 @@ private enum Options {
3736
public static Iterable<Object[]> data() {
3837
return asList(
3938
new Object[][]{
40-
{"jdbc:tc:firebird://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction", EnumSet.of(Options.ScriptedSchema, Options.JDBCParams, Options.RequiresTable)},
41-
{"jdbc:tc:firebird:3.0.4://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction", EnumSet.of(Options.ScriptedSchema, Options.JDBCParams, Options.RequiresTable)},
42-
{"jdbc:tc:firebirdsql:3.0.4://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction", EnumSet.of(Options.ScriptedSchema, Options.JDBCParams, Options.RequiresTable)},
39+
{"jdbc:tc:firebird://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction", EnumSet.of(Options.ScriptedSchema, Options.JDBCParams)},
40+
{"jdbc:tc:firebird:3.0.4://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction", EnumSet.of(Options.ScriptedSchema, Options.JDBCParams)},
41+
{"jdbc:tc:firebirdsql:3.0.4://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction", EnumSet.of(Options.ScriptedSchema, Options.JDBCParams)},
42+
{"jdbc:tc:firebirdsql:2.5.8-sc://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction", EnumSet.of(Options.ScriptedSchema, Options.JDBCParams)},
43+
// 2.5.x-ss seems to be broken, see https://github.com/jacobalberty/firebird-docker/issues/33
44+
// {"jdbc:tc:firebirdsql:2.5.8-ss://hostname/databasename?user=someuser&password=somepwd&charSet=utf-8&TC_INITFUNCTION=org.firebirdsql.testcontainers.JDBCDriverTest::sampleInitFunction", EnumSet.of(Options.ScriptedSchema, Options.JDBCParams)},
4345
});
4446
}
4547

0 commit comments

Comments
 (0)