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 GraalVM native testing and fix metadata #307

Merged
merged 1 commit into from
Apr 20, 2023
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
8 changes: 8 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
plugins {
id 'groovy-gradle-plugin'
}
repositories {
gradlePluginPortal()
mavenCentral()
}

dependencies {
implementation libs.gradle.micronaut
}
8 changes: 8 additions & 0 deletions buildSrc/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
rootProject.name = 'cassandra-parent'
dependencyResolutionManagement {
versionCatalogs {
libs {
from(files("../gradle/libs.versions.toml"))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
repositories {
mavenCentral()
maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots/" }
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
plugins {
id "io.micronaut.build.internal.module"
id "io.micronaut.build.internal.cassandra-base"
}

repositories {
mavenCentral()
maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots/" }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
plugins {
id "io.micronaut.build.internal.cassandra-base"
id "io.micronaut.application"
id "io.micronaut.test-resources"
id 'org.graalvm.buildtools.native'
}

tasks.named("check") { task ->
def graal = ["jvmci.Compiler", "java.vendor.version", "java.vendor"].any {
System.getProperty(it)?.toLowerCase(Locale.ENGLISH)?.contains("graal")
}
if (graal) {
task.dependsOn("nativeTest")
}
}

tasks.named("test") {
useJUnitPlatform()
}

graalvmNative {
toolchainDetection = false
metadataRepository {
enabled = true
}
binaries {
all {
resources.autodetect()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@
# limitations under the License.
#

Args = --initialize-at-run-time=io.micronaut.cassandra.health.$CassandraHealthIndicatorDefinition \
--initialize-at-build-time=com.datastax.oss.driver.internal.core.util.Reflection,com.datastax.oss.driver.internal.core.util.DependencyCheck,com.datastax.oss.driver.internal.core.util.Dependency
Args = --initialize-at-build-time=com.datastax.oss.driver.internal.core.util.DependencyCheck,com.datastax.oss.driver.internal.core.util.Dependency
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
managed-datastax-cassandra-driver = "4.15.0"
micronaut = "4.0.0-M1"
micronaut-docs = "2.0.0"
micronaut-test = "4.0.0-SNAPSHOT"
micronaut-test = "4.0.0-M1"
groovy = "4.0.10"
spock = "2.3-groovy-4.0"
testcontainers = "1.18.0"
micronaut-gradle-plugin = "4.0.0-M1"

[libraries]
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" }

testcontainers-cassandra = { module = "org.testcontainers:cassandra", version.ref = "testcontainers" }
testcontainers-spock = { module = "org.testcontainers:spock", version.ref = "testcontainers" }
gradle-micronaut = { module = "io.micronaut.gradle:micronaut-gradle-plugin", version.ref = "micronaut-gradle-plugin" }
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ plugins {
rootProject.name = 'cassandra-parent'
include 'cassandra'
include 'cassandra-bom'
include 'test-suite-graal'

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

mainClassName = "helloworld.Application"
micronaut {
version "4.0.0-M1"
testRuntime "junit5"
enableNativeImage false
processing {
incremental(true)
annotations("helloworld.*")
}
testResources {
clientTimeout = 600
}
}

configurations.all {
resolutionStrategy.dependencySubstitution {
substitute module('io.micronaut.cassandra:micronaut-cassandra') using project(':micronaut-cassandra')
}
}

dependencies {
implementation mn.micronaut.context
implementation mn.micronaut.jackson.databind
implementation project(':micronaut-cassandra')
implementation mn.snakeyaml
runtimeOnly mn.logback.classic
}

graalvmNative {
binaries {
all {
buildArgs.add("--trace-class-initialization=com.datastax.oss.driver.internal.core.util.Dependency")
}
}
}
22 changes: 22 additions & 0 deletions test-suite-graal/src/main/java/example/CassandraInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package example;

import io.micronaut.core.annotation.Introspected;

@Introspected
public class CassandraInfo {
private final String clusterName;
private final String releaseVersion;

public CassandraInfo(String clusterName, String releaseVersion) {
this.clusterName = clusterName;
this.releaseVersion = releaseVersion;
}

public String getClusterName() {
return clusterName;
}

public String getReleaseVersion() {
return releaseVersion;
}
}
32 changes: 32 additions & 0 deletions test-suite-graal/src/main/java/example/CassandraRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package example;

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 jakarta.inject.Singleton;

import java.util.Optional;

@Singleton
public class CassandraRepository {
private final CqlSession cqlSession;

public CassandraRepository(CqlSession cqlSession) {
this.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();
}
}
17 changes: 17 additions & 0 deletions test-suite-graal/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
micronaut:
application:
name: cassandra
cassandra:
default:
basic:
contact-points:
- "127.0.0.1:${cassandra.port}"
load-balancing-policy:
local-datacenter: datacenter1
test-resources:
containers:
cassandra:
startup-timeout: 600s
image-name: cassandra
exposed-ports:
- cassandra.port: 9042
16 changes: 16 additions & 0 deletions test-suite-graal/src/test/java/example/CassandraTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package example;

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

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

@MicronautTest
class CassandraTest {

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

}
16 changes: 16 additions & 0 deletions test-suite-graal/src/test/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n</pattern>
</encoder>
</appender>

<root level="info">
<appender-ref ref="STDOUT" />
</root>

<!-- <logger name="io.micronaut.context.env" level="trace" />-->
</configuration>