-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add scylladb module #8002
Merged
Merged
Add scylladb module #8002
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
86ed2cb
add scylladb module
mkorolyov bc7eb8b
Update docs/modules/databases/scylladb.md
mkorolyov 35ea1c2
remove com.datastax.cassandra:cassandra-driver-core from deps
mkorolyov 8590397
Merge branch 'main' into add-scylladb
mkorolyov f10e620
Merge remote-tracking branch 'origin/main' into add-scylladb
eddumelendez 1805c16
Polish
eddumelendez b5fa599
Add docs
eddumelendez af00b41
add custom config file. add ssl test and document it
mkorolyov 7badf3d
Fix format
eddumelendez 60f7dd4
remove temporary ssl test
mkorolyov ccd7e41
add ssl cqlsh test and docs
mkorolyov 8ac1c15
Merge branch 'main' into add-scylladb
mkorolyov 7a356f2
Merge branch 'main' into add-scylladb
mkorolyov 181472e
add withSsl method to ScyllaDBContainer
mkorolyov 19ae30a
add additional withSsl(certificate, keyfile)
mkorolyov 3b95f64
Merge branch 'main' into add-scylladb
mkorolyov 6ab9c7e
Polish
eddumelendez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
truststore is optional. See https://opensource.docs.scylladb.com/stable/operating-scylla/security/client-node-encryption.html#validate-the-clients. So, we should provide another method
withSsl(MountableFile certificate, MountableFile keyfile)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch! thanks, fixed this one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reverted this because truststore must be at the system truststore and in order to do that we need to copy the file too. Sorry about that.