Skip to content
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 tests and documentation for datastax driver SSL integration #403

Merged
merged 21 commits into from
Jan 26, 2024
Merged
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
File renamed without changes.
6 changes: 3 additions & 3 deletions cassandra/build.gradle → cassandra/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "io.micronaut.build.internal.cassandra-module"
id("io.micronaut.build.internal.cassandra-module")
}

dependencies {
Expand All @@ -19,7 +19,7 @@ dependencies {
testRuntimeOnly(mn.snakeyaml)
}

tasks.withType(Test) {
tasks.withType<Test> {
// this is needed by libs.system.stubs
jvmArgs = ["--add-opens", "java.base/java.util=ALL-UNNAMED"]
jvmArgs = listOf("--add-opens", "java.base/java.util=ALL-UNNAMED")
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import io.micronaut.context.event.BeanCreatedEvent
import io.micronaut.context.event.BeanCreatedEventListener
import io.micronaut.inject.qualifiers.Qualifiers
import org.testcontainers.containers.CassandraContainer
import org.testcontainers.utility.DockerImageName
import spock.lang.Specification

import jakarta.inject.Singleton
Expand All @@ -46,7 +47,7 @@ class CassandraConfigurationSpec extends Specification {

void "test single cluster connection"() {
given:
CassandraContainer cassandra = new CassandraContainer()
CassandraContainer cassandra = new CassandraContainer(DockerImageName.parse('cassandra:latest'))
cassandra.start()
// tag::single[]
ApplicationContext applicationContext = new DefaultApplicationContext("test")
Expand Down Expand Up @@ -81,7 +82,7 @@ class CassandraConfigurationSpec extends Specification {

void "test multiple cluster connections"() {
given:
CassandraContainer cassandra = new CassandraContainer()
CassandraContainer cassandra = new CassandraContainer(DockerImageName.parse('cassandra:latest'))
cassandra.start()

// tag::multiple[]
Expand Down
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ micronaut-platform = "4.1.4"
micronaut-docs = "2.0.0"
micronaut-test = "4.0.2"
micronaut-logging = "1.1.2"
micronaut-reactor = "3.2.1"
micronaut-micrometer = "5.3.0"
micronaut-gradle-plugin = "4.2.1"

Expand All @@ -13,16 +14,19 @@ groovy = "4.0.14"
spock = "2.3-groovy-4.0"
testcontainers = "1.19.3"
system-stubs = "2.1.6"
bcpkix = "1.77"

[libraries]
# Core
micronaut-core = { module = 'io.micronaut:micronaut-core-bom', version.ref = 'micronaut' }
micronaut-micrometer = { module = "io.micronaut.micrometer:micronaut-micrometer-bom", version.ref = "micronaut-micrometer" }
micronaut-reactor = { module = "io.micronaut.reactor:micronaut-reactor-bom", version.ref = "micronaut-reactor" }

managed-datastax-cassandra-driver-core = { module = "com.datastax.oss:java-driver-core", version.ref = "managed-datastax-cassandra-driver" }
managed-datastax-cassandra-driver-mapper-processor = { module = "com.datastax.oss:java-driver-mapper-processor", version.ref = "managed-datastax-cassandra-driver" }
managed-datastax-cassandra-driver-metrics-micrometer = { module = "com.datastax.oss:java-driver-metrics-micrometer", version.ref = "managed-datastax-cassandra-driver" }

bcpkix = { module = "org.bouncycastle:bcpkix-jdk18on", version.ref = "bcpkix" }
system-stubs = { module = "uk.org.webcompere:system-stubs-core", version.ref = "system-stubs" }
testcontainers-cassandra = { module = "org.testcontainers:cassandra", version.ref = "testcontainers" }
testcontainers-spock = { module = "org.testcontainers:spock", version.ref = "testcontainers" }
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ include 'cassandra'
include 'cassandra-bom'
include 'test-suite-graal'
include 'tests:cassandra-jackson'
include 'tests:cassandra-ssl'
include 'test-suite-cassandra-micrometer'

micronautBuild {
useStandardizedProjectNames = true
importMicronautCatalog()
importMicronautCatalog("micronaut-micrometer")
importMicronautCatalog("micronaut-reactor")
}
4 changes: 2 additions & 2 deletions src/main/docs/guide/setup.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Micronaut will create a https://docs.datastax.com/en/drivers/java/4.4/com/datast
can be then injected into any other Micronaut bean.

.Supply Single Configuration
[source,yaml]
[configuration]
----
cassandra:
default:
Expand All @@ -37,7 +37,7 @@ cassandra:
Multiple Cluster instances can be configured as follows:

.Supply Multiple Configuration
[source,yaml]
[configuration]
----
cassandra:
default:
Expand Down
18 changes: 18 additions & 0 deletions src/main/docs/guide/ssl.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
The Cassandra DataStax Java Driver includes https://docs.datastax.com/en/developer/java-driver/latest/manual/core/ssl/#driver-configuration[support for SSL], to secure traffic between the driver and Cassandra.

This an example of additional configuration for Micronaut Cassandra that enables SSL connections. The relevant values are defined under the `cassandra.\*.advanced.ssl-engine-factory.*` property key and documented further in the https://docs.datastax.com/en/developer/java-driver/latest/manual/core/configuration/reference/[Datastax Configuration Reference].

[configuration]
----
cassandra:
default:
advanced:
ssl-engine-factory:
class: DefaultSslEngineFactory
truststore-path: <path to trust store>
truststore-password: <password>
----

- `class`: The class of the factory. `DefaultSslEngineFactory` is the default built-in implementation
- `truststore` properties: these are optional and if not present system property configuration is used instead

1 change: 1 addition & 0 deletions src/main/docs/guide/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ releaseHistory: Release History
setup: Setting up Cassandra
health: Health Checks
metrics: Micrometer Integration
ssl: SSL Integration
additional: Additional Notes
graalvm: GraalVM support
repository: Repository
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.micronaut.cassandra.micrometertest

import groovy.transform.Canonical
import io.micronaut.core.annotation.Introspected

@Canonical
@Introspected
class CassandraInfo {

String clusterName
String releaseVersion
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package example
package io.micronaut.cassandra.micrometertest

import com.datastax.oss.driver.api.core.CqlSession
import io.micrometer.core.instrument.Counter
Expand Down Expand Up @@ -46,7 +46,7 @@ class CassandraMetricsSpec extends Specification {

when:
CassandraRepository repository = context.getBean(CassandraRepository)
repository.getInfo()
def info = repository.getInfo()
Timer cqlRequests0 = meterRegistry.timer("defaultSession.cql-requests")
Timer cqlRequests1 = meterRegistry.timer("secondarySession.cql-requests")
Counter bytesSentS0 = meterRegistry.counter("defaultSession.bytes-sent")
Expand All @@ -55,6 +55,7 @@ class CassandraMetricsSpec extends Specification {
Counter bytesReceivedS1 = meterRegistry.counter("secondarySession.bytes-received")

then:
info.isPresent()
cqlRequests0.totalTime(TimeUnit.MILLISECONDS) > 0.0
cqlRequests1.totalTime(TimeUnit.MILLISECONDS) == 0
bytesSentS0.count() > 0.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package example
package io.micronaut.cassandra.micrometertest

import com.datastax.oss.driver.api.core.CqlSession
import com.datastax.oss.driver.api.core.cql.ResultSet
import com.datastax.oss.driver.api.core.cql.Row
import io.micronaut.context.annotation.Requires
import jakarta.inject.Singleton

Expand All @@ -18,13 +17,6 @@ class CassandraRepository {

Optional<CassandraInfo> getInfo() {
ResultSet resultSet = cqlSession.execute('select cluster_name, release_version from system.local')
Row row = resultSet.one()

if (row != null) {
Optional.of(
new CassandraInfo(row.getString('cluster_name'), row.getString('release_version'))
)
}
Optional.empty()
Optional.ofNullable(resultSet.one()).map(r -> new CassandraInfo(r.getString('cluster_name'), r.getString('release_version')))
}
}
34 changes: 0 additions & 34 deletions test-suite-graal/build.gradle

This file was deleted.

28 changes: 28 additions & 0 deletions test-suite-graal/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
plugins {
id("io.micronaut.test-resources")
id("io.micronaut.build.internal.cassandra-native-tests")
}

micronaut {
importMicronautPlatform = false
testRuntime("junit5")
enableNativeImage(false)
processing {
incremental(true)
annotations("io.micronaut.cassandra.graaltest")
}
testResources {
clientTimeout = 600
}
}

dependencies {
testImplementation(projects.micronautCassandra)

testImplementation(mn.micronaut.context)
testImplementation(mn.micronaut.jackson.databind)
testImplementation(mnTest.micronaut.test.junit5)

testRuntimeOnly(mn.snakeyaml)
testRuntimeOnly(mnLogging.logback.classic)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package example;
package io.micronaut.cassandra.graaltest;

import io.micronaut.core.annotation.Introspected;

Expand All @@ -19,4 +19,4 @@ public String getClusterName() {
public String getReleaseVersion() {
return releaseVersion;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package example;
package io.micronaut.cassandra.graaltest;

import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.cql.ResultSet;
import com.datastax.oss.driver.api.core.cql.Row;
import io.micronaut.context.annotation.Requires;
import jakarta.inject.Singleton;

import java.util.Optional;

@Singleton
@Requires(property = "spec.name", value = "CassandraTest")
public class CassandraRepository {
private final CqlSession cqlSession;

Expand All @@ -17,16 +18,7 @@ public CassandraRepository(CqlSession cqlSession) {

public Optional<CassandraInfo> getInfo() {
ResultSet resultSet = cqlSession.execute("select cluster_name, release_version from system.local");
Row row = resultSet.one();

if (row != null) {
return Optional.of(
new CassandraInfo(
row.getString("cluster_name"),
row.getString("release_version")
)
);
}
return Optional.empty();
return Optional.ofNullable(resultSet.one())
.map(r -> new CassandraInfo(r.getString("cluster_name"), r.getString("release_version")));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package example;
package io.micronaut.cassandra.graaltest;

import static org.junit.jupiter.api.Assertions.assertTrue;

import io.micronaut.context.annotation.Property;
import org.junit.jupiter.api.Test;

import io.micronaut.test.extensions.junit5.annotation.MicronautTest;

@MicronautTest
@Property(name = "spec.name", value = "CassandraTest")
class CassandraTest {

@Test
void testCassandra(CassandraRepository repository) {
assertTrue(repository.getInfo().isPresent());
}

}
}
37 changes: 0 additions & 37 deletions tests/cassandra-jackson/build.gradle

This file was deleted.

27 changes: 27 additions & 0 deletions tests/cassandra-jackson/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
plugins {
groovy
id("io.micronaut.build.internal.cassandra-tests")
}

dependencies {
testImplementation(projects.micronautCassandra)
testImplementation(mn.micronaut.http.client)
testImplementation(mn.micronaut.jackson.databind)
testImplementation(mn.micronaut.management)
testImplementation(mnReactor.micronaut.reactor)

testImplementation(libs.testcontainers.spock)
testImplementation(libs.testcontainers.cassandra)

testRuntimeOnly(mnLogging.logback.classic)
}

micronaut {
version.set(libs.versions.micronaut.platform.get())
runtime("netty")
testRuntime("spock2")
processing {
incremental(true)
annotations("example.*")
}
}
Loading
Loading