-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Eddú Meléndez <[email protected]>
- Loading branch information
1 parent
847bb1a
commit 46fe670
Showing
18 changed files
with
1,144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,7 @@ body: | |
- QuestDB | ||
- RabbitMQ | ||
- Redpanda | ||
- ScyllaDB | ||
- Selenium | ||
- Solace | ||
- Solr | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,7 @@ body: | |
- QuestDB | ||
- RabbitMQ | ||
- Redpanda | ||
- ScyllaDB | ||
- Selenium | ||
- Solace | ||
- Solr | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,7 @@ body: | |
- Pulsar | ||
- RabbitMQ | ||
- Redpanda | ||
- ScyllaDB | ||
- Selenium | ||
- Solace | ||
- Solr | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# ScyllaDB | ||
|
||
Testcontainers module for [ScyllaDB](https://hub.docker.com/r/scylladb/scylla) | ||
|
||
## ScyllaDB's usage examples | ||
|
||
You can start a ScyllaDB container instance from any Java application by using: | ||
|
||
<!--codeinclude--> | ||
[Create container](../../../modules/scylladb/src/test/java/org/testcontainers/scylladb/ScyllaDBContainerTest.java) inside_block:container | ||
<!--/codeinclude--> | ||
|
||
<!--codeinclude--> | ||
[Custom config file](../../../modules/scylladb/src/test/java/org/testcontainers/scylladb/ScyllaDBContainerTest.java) inside_block:customConfiguration | ||
<!--/codeinclude--> | ||
|
||
### Building CqlSession | ||
|
||
<!--codeinclude--> | ||
[Using CQL port](../../../modules/scylladb/src/test/java/org/testcontainers/scylladb/ScyllaDBContainerTest.java) inside_block:session | ||
<!--/codeinclude--> | ||
|
||
<!--codeinclude--> | ||
[Using SSL](../../../modules/scylladb/src/test/java/org/testcontainers/scylladb/ScyllaDBContainerTest.java) inside_block:sslContext | ||
<!--/codeinclude--> | ||
|
||
<!--codeinclude--> | ||
[Using Shard Awareness port](../../../modules/scylladb/src/test/java/org/testcontainers/scylladb/ScyllaDBContainerTest.java) inside_block:shardAwarenessSession | ||
<!--/codeinclude--> | ||
|
||
### Alternator | ||
|
||
<!--codeinclude--> | ||
[Enabling Alternator](../../../modules/scylladb/src/test/java/org/testcontainers/scylladb/ScyllaDBContainerTest.java) inside_block:alternator | ||
<!--/codeinclude--> | ||
|
||
<!--codeinclude--> | ||
[DynamoDbClient with Alternator](../../../modules/scylladb/src/test/java/org/testcontainers/scylladb/ScyllaDBContainerTest.java) inside_block:dynamodDbClient | ||
<!--/codeinclude--> | ||
|
||
## Adding this module to your project dependencies | ||
|
||
Add the following dependency to your `pom.xml`/`build.gradle` file: | ||
|
||
=== "Gradle" | ||
```groovy | ||
testImplementation "org.testcontainers:scylladb:{{latest_version}}" | ||
``` | ||
|
||
=== "Maven" | ||
```xml | ||
<dependency> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>scylladb</artifactId> | ||
<version>{{latest_version}}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
description = "Testcontainers :: ScyllaDB" | ||
|
||
dependencies { | ||
api project(":testcontainers") | ||
|
||
testImplementation 'com.scylladb:java-driver-core:4.15.0.0' | ||
testImplementation 'org.assertj:assertj-core:3.24.2' | ||
testImplementation 'software.amazon.awssdk:dynamodb:2.28.6' | ||
} |
109 changes: 109 additions & 0 deletions
109
modules/scylladb/src/main/java/org/testcontainers/scylladb/ScyllaDBContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package org.testcontainers.scylladb; | ||
|
||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
import org.testcontainers.utility.DockerImageName; | ||
import org.testcontainers.utility.MountableFile; | ||
|
||
import java.net.InetSocketAddress; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Testcontainers implementation for ScyllaDB. | ||
* <p> | ||
* Supported image: {@code scylladb/scylla} | ||
* <p> | ||
* Exposed ports: | ||
* <ul> | ||
* <li>CQL Port: 9042</li> | ||
* <li>Shard Aware Port: 19042</li> | ||
* <li>Alternator Port: 8000</li> | ||
* </ul> | ||
*/ | ||
public class ScyllaDBContainer extends GenericContainer<ScyllaDBContainer> { | ||
|
||
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("scylladb/scylla"); | ||
|
||
private static final Integer CQL_PORT = 9042; | ||
|
||
private static final Integer SHARD_AWARE_PORT = 19042; | ||
|
||
private static final Integer ALTERNATOR_PORT = 8000; | ||
|
||
private static final String COMMAND = "--developer-mode=1 --overprovisioned=1"; | ||
|
||
private static final String CONTAINER_CONFIG_LOCATION = "/etc/scylla"; | ||
|
||
private boolean alternatorEnabled = false; | ||
|
||
private String configLocation; | ||
|
||
public ScyllaDBContainer(String dockerImageName) { | ||
this(DockerImageName.parse(dockerImageName)); | ||
} | ||
|
||
public ScyllaDBContainer(DockerImageName dockerImageName) { | ||
super(dockerImageName); | ||
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME); | ||
|
||
withExposedPorts(CQL_PORT, SHARD_AWARE_PORT); | ||
|
||
withCommand(COMMAND); | ||
waitingFor(Wait.forLogMessage(".*initialization completed..*", 1)); | ||
} | ||
|
||
@Override | ||
protected void configure() { | ||
if (this.alternatorEnabled) { | ||
addExposedPort(8000); | ||
String newCommand = | ||
COMMAND + " --alternator-port=" + ALTERNATOR_PORT + " --alternator-write-isolation=always"; | ||
withCommand(newCommand); | ||
} | ||
|
||
// Map (effectively replace) directory in Docker with the content of resourceLocation if resource location is | ||
// not null. | ||
Optional | ||
.ofNullable(configLocation) | ||
.map(MountableFile::forClasspathResource) | ||
.ifPresent(mountableFile -> withCopyFileToContainer(mountableFile, CONTAINER_CONFIG_LOCATION)); | ||
} | ||
|
||
public ScyllaDBContainer withConfigurationOverride(String configLocation) { | ||
this.configLocation = configLocation; | ||
return this; | ||
} | ||
|
||
public ScyllaDBContainer withSsl(MountableFile certificate, MountableFile keyfile, MountableFile truststore) { | ||
withCopyFileToContainer(certificate, "/etc/scylla/scylla.cer.pem"); | ||
withCopyFileToContainer(keyfile, "/etc/scylla/scylla.key.pem"); | ||
withCopyFileToContainer(truststore, "/etc/scylla/scylla.truststore"); | ||
withEnv("SSL_CERTFILE", "/etc/scylla/scylla.cer.pem"); | ||
return this; | ||
} | ||
|
||
public ScyllaDBContainer withAlternator() { | ||
this.alternatorEnabled = true; | ||
return this; | ||
} | ||
|
||
/** | ||
* Retrieve an {@link InetSocketAddress} for connecting to the ScyllaDB container via the driver. | ||
* | ||
* @return A InetSocketAddress representation of this ScyllaDB container's host and port. | ||
*/ | ||
public InetSocketAddress getContactPoint() { | ||
return new InetSocketAddress(getHost(), getMappedPort(CQL_PORT)); | ||
} | ||
|
||
public InetSocketAddress getShardAwareContactPoint() { | ||
return new InetSocketAddress(getHost(), getMappedPort(SHARD_AWARE_PORT)); | ||
} | ||
|
||
public String getAlternatorEndpoint() { | ||
if (!this.alternatorEnabled) { | ||
throw new IllegalStateException("Alternator is not enabled"); | ||
} | ||
return "http://" + getHost() + ":" + getMappedPort(ALTERNATOR_PORT); | ||
} | ||
} |
Oops, something went wrong.