Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/modules/databases/mariadb.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ Add the following dependency to your `pom.xml`/`build.gradle` file:

!!! hint
Adding this Testcontainers library JAR will not automatically add a database driver JAR to your project. You should ensure that your project also has a suitable database driver as a dependency.
The JDBC driver is required even if your application only uses R2DBC, because the container startup check connects over JDBC.

1 change: 1 addition & 0 deletions docs/modules/databases/mssqlserver.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Add the following dependency to your `pom.xml`/`build.gradle` file:

!!! hint
Adding this Testcontainers library JAR will not automatically add a database driver JAR to your project. You should ensure that your project also has a suitable database driver as a dependency.
The JDBC driver is required even if your application only uses R2DBC, because the container startup check connects over JDBC.

## License

Expand Down
1 change: 1 addition & 0 deletions docs/modules/databases/mysql.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ Add the following dependency to your `pom.xml`/`build.gradle` file:

!!! hint
Adding this Testcontainers library JAR will not automatically add a database driver JAR to your project. You should ensure that your project also has a suitable database driver as a dependency.
The JDBC driver is required even if your application only uses R2DBC, because the container startup check connects over JDBC.
3 changes: 3 additions & 0 deletions docs/modules/databases/r2dbc.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ The started container will be terminated when the `ConnectionFactory` is closed.
!!! warning
Both the database module (e.g. `org.testcontainers:testcontainers-mysql`) **and** `org.testcontainers:testcontainers-r2dbc` need to be on your application's classpath at runtime.

!!! warning
For MySQL, MariaDB and MS SQL Server, the JDBC driver also needs to be on the test classpath, even if your application only uses R2DBC. Testcontainers checks that these databases are ready by connecting over JDBC; without the driver, the container fails to start with `Could not get Driver`.

**Original URL**: `r2dbc:mysql://localhost:3306/databasename`

1. Insert `tc:` after `r2dbc:` as follows. Note that the hostname, port and database name will be ignored; you can leave these as-is or set them to any value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,14 @@ public Driver getJdbcDriverInstance() throws NoDriverFoundException {
try {
driver = (Driver) Class.forName(this.getDriverClassName()).newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new NoDriverFoundException("Could not get Driver", e);
throw new NoDriverFoundException(
String.format(
"Could not get Driver %s. The JDBC driver must be on the classpath because the " +
"container startup check connects over JDBC, even if the application only uses R2DBC",
this.getDriverClassName()
),
e
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.concurrent.atomic.AtomicInteger;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.fail;

class MissingJdbcDriverTest {
Expand All @@ -35,6 +36,17 @@ void shouldFailFastIfNoDriverFound() {
.isEqualTo(1);
}

@Test
void shouldNameTheMissingDriverClass() {
final MissingDriverContainer container = new MissingDriverContainer();

assertThatThrownBy(container::getJdbcDriverInstance)
.isInstanceOf(JdbcDatabaseContainer.NoDriverFoundException.class)
.hasMessageContaining("nonexistent.ClassName")
.hasMessageContaining("R2DBC")
.hasCauseInstanceOf(ClassNotFoundException.class);
}

/**
* Container class for the purposes of testing, with a known non-existent driver
*/
Expand Down
Loading