Testcontainers FoundationDB Module
Helps running FoundationDB using Testcontainers.
It's based on the docker images provided by FoundationDB Community.
Adding this module to your project dependencies
- Add Foundation DB java client dependency, for example:
implementation("org.foundationdb:fdb-java:7.1.23")
<dependency>
<groupId>org.foundationdb</groupId>
<artifactId>fdb-java</artifactId>
<version>7.1.23</version>
</dependency>
Note that the FDB client requires the native client libraries to be installed:
- Add Testcontainers dependency, for example:
testImplementation "org.testcontainers:testcontainers:1.17.6"
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.17.6</version>
<scope>test</scope>
</dependency>
- Finally add the module dependency to your
build.gradle
/pom.xml
file:
testImplementation "io.github.aleris:testcontainers-foundationdb:1.0.0"
<dependency>
<groupId>io.github.aleris</groupId>
<artifactId>testcontainers-foundationdb</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
Usage example
You can start a FoundationDB container instance from a Java application by using:
try (final FoundationDBContainer foundationDBContainer = new FoundationDBContainer()) {
foundationDBContainer.start();
final FDB fdb = FDB.selectAPIVersion(710);
try (final Database db = fdb.open(foundationDBContainer.getClusterFilePath())) {
db.run(tr -> {
tr.set(Tuple.from("hello").pack(), Tuple.from("world").pack());
return null;
});
}
}
To start with a specific version use:
final FoundationDBContainer foundationDBContainer = new FoundationDBContainer(
DockerImageName.parse("foundationdb/foundationdb:7.1.23")
)
See also the tests for other examples.
Caveats
- FDB requires the native client libraries be installed separately for the java dependency to work. Install the libraries before using the java FDB client.
- Also, it might have issues working on newer macOS with the java bindings, try using java 8 and
export DYLD_LIBRARY_PATH=/usr/local/lib
in environment variables after installing FDB clients locally.
Dev
To publish a new version, increment the version in build.gradle, set the following:
export ORG_GRADLE_PROJECT_sonatypeUsername=sonatypeUsername
export ORG_GRADLE_PROJECT_sonatypePassword='sonatypePassword'
And then run sh ./scripts/publish.sh
.