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

CRaC to Java 21 #209

Merged
merged 7 commits into from
Oct 12, 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
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: ['17']
java: ['17', '21']
env:
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
GRADLE_ENTERPRISE_CACHE_USERNAME: ${{ secrets.GRADLE_ENTERPRISE_CACHE_USERNAME }}
Expand Down
7 changes: 5 additions & 2 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ repositories {
}

dependencies {
implementation("io.micronaut.gradle:micronaut-gradle-plugin:4.1.1")
implementation("io.micronaut.gradle:micronaut-crac-plugin:4.1.1")
implementation(libs.micronaut.gradle.plugin)
implementation(libs.micronaut.crac.plugin)
implementation(libs.kotlin.gradle.plugin)
implementation(libs.kotlin.gradle.allopen)
implementation(libs.kotlin.gradle.ksp)
}
7 changes: 7 additions & 0 deletions buildSrc/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dependencyResolutionManagement {
versionCatalogs {
libs {
from(files("../gradle/libs.versions.toml"))
}
}
}
9 changes: 9 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ micronaut = "4.1.6"
micronaut-cache = "4.0.2"
micronaut-data = "4.1.3"
micronaut-docs = "2.0.0"
micronaut-gradle-plugin = "4.1.1"
micronaut-platform = "4.1.3"
micronaut-redis = "6.0.2"
micronaut-serialization = "2.2.5"
micronaut-sql = "5.0.1"
micronaut-test = "4.0.1"

groovy = "4.0.13"
kotlin = '1.9.10'
ksp = '1.9.10-1.0.13'
spock = "2.3-groovy-4.0"

managed-crac = "1.4.0"
Expand All @@ -33,3 +36,9 @@ micronaut-sql = { module = "io.micronaut.sql:micronaut-sql-bom", version.ref = "
managed-crac = { module = "org.crac:crac", version.ref = "managed-crac" }

testcontainers = { module = "org.testcontainers:testcontainers", version.ref = "testcontainers" }

micronaut-gradle-plugin = { module = "io.micronaut.gradle:micronaut-gradle-plugin", version.ref = 'micronaut-gradle-plugin' }
micronaut-crac-plugin = { module = "io.micronaut.gradle:micronaut-crac-plugin", version.ref = 'micronaut-gradle-plugin' }
kotlin-gradle-plugin = { module = 'org.jetbrains.kotlin:kotlin-gradle-plugin', version.ref = 'kotlin' }
kotlin-gradle-allopen = { module = 'org.jetbrains.kotlin:kotlin-allopen', version.ref = 'kotlin' }
kotlin-gradle-ksp = { module = 'com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin', version.ref = 'ksp' }
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
17 changes: 9 additions & 8 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -144,15 +145,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -201,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
5 changes: 4 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ include 'test-suite-dbcp-jooq'
include 'test-suite-docker'
include 'test-suite-groovy'
include 'test-suite-hikari-jooq'
include 'test-suite-kotlin'
if (JavaVersion.current() < JavaVersion.VERSION_21) {
include 'test-suite-kotlin'
}
include 'test-suite-kotlin-ksp'
include 'test-suite-redis'

micronautBuild {
Expand Down
3 changes: 3 additions & 0 deletions test-suite-docker/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ micronaut {
importMicronautPlatform.set(false)
runtime("netty")
testRuntime("spock")
crac {
this.javaVersion.set(JavaLanguageVersion.of(JavaVersion.current().majorVersion))
}
}
25 changes: 25 additions & 0 deletions test-suite-kotlin-ksp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("org.jetbrains.kotlin.jvm")
id("com.google.devtools.ksp")
id("io.micronaut.build.internal.crac-test-suite")
}

dependencies {
ksp(mn.micronaut.inject.kotlin)

testImplementation(projects.micronautCrac)
testImplementation(mnTest.micronaut.test.junit5)

testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "17"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.micronaut.crac

import io.micronaut.context.DefaultApplicationContextBuilder
import io.micronaut.context.annotation.Property
import io.micronaut.context.annotation.Requires
import io.micronaut.core.annotation.Introspected
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get
import io.micronaut.http.client.HttpClient
import io.micronaut.runtime.server.EmbeddedServer
import io.micronaut.test.extensions.junit5.annotation.MicronautTest
import jakarta.inject.Inject
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

@MicronautTest(contextBuilder = [EagerHttpClientCreationTest.EagerSingletons::class])
@Property(name = "spec.name", value = "EagerHttpClientCreationTest")
class EagerHttpClientCreationTest {

//tag::test[]
@field:Inject
lateinit var server: EmbeddedServer // <1>

val client by lazy {
server.applicationContext.createBean(HttpClient::class.java, server.url) // <2>
}

@Test
fun testClient() {
assertEquals("ok", client.toBlocking().retrieve("/eager")) // <3>
}
//end::test[]

@Requires(property = "spec.name", value = "EagerHttpClientCreationTest")
@Controller("/eager")
internal class EagerController {
@Get
fun test(): String {
return "ok"
}
}

@Introspected
internal class EagerSingletons : DefaultApplicationContextBuilder() {
init {
eagerInitSingletons(true)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.micronaut.crac

import io.micronaut.context.BeanContext
import io.micronaut.context.annotation.Property
import io.micronaut.crac.test.CheckpointSimulator
import io.micronaut.test.extensions.junit5.annotation.MicronautTest
import jakarta.inject.Inject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test

@MicronautTest
@Property(name = "spec.name", value = OrderedResourceCheckpointSimulatorTest.SPEC_NAME)
class OrderedResourceCheckpointSimulatorTest {
companion object {
const val SPEC_NAME = "OrderedResourceCheckpointSimulatorTest"
}

//tag::test[]
@field:Inject
lateinit var ctx: BeanContext

@Test
fun testCustomOrderedResourceUsingCheckpointSimulator() {
val myBean = ctx.getBean(ResourceBean::class.java)
val checkpointSimulator = ctx.getBean(CheckpointSimulator::class.java) // <1>
Assertions.assertTrue(myBean.isRunning)

checkpointSimulator.runBeforeCheckpoint() // <2>
Assertions.assertFalse(myBean.isRunning)

checkpointSimulator.runAfterRestore() // <3>
Assertions.assertTrue(myBean.isRunning)
}
//end::test[]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.micronaut.crac

import io.micronaut.context.annotation.Requires
import jakarta.inject.Singleton

@Requires(property = "spec.name", value = OrderedResourceCheckpointSimulatorTest.SPEC_NAME)
//tag::bean[]
@Singleton
class ResourceBean {

var isRunning = true // <1>
private set

fun stop() {
isRunning = false
}

fun start() {
isRunning = true
}
}
//end::bean[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.micronaut.crac

import io.micronaut.context.annotation.Requires
import jakarta.inject.Singleton
import org.crac.Context
import org.crac.Resource

@Requires(property = "spec.name", value = OrderedResourceCheckpointSimulatorTest.SPEC_NAME)
//tag::resource[]
@Singleton
class ResourceBeanResource(private val resourceBean: ResourceBean) : OrderedResource { // <1>

@Throws(Exception::class)
override fun beforeCheckpoint(context: Context<out Resource?>?) { // <2>
resourceBean.stop()
}

@Throws(Exception::class)
override fun afterRestore(context: Context<out Resource?>?) { // <3>
resourceBean.start()
}
}
//end::resource[]
4 changes: 2 additions & 2 deletions test-suite-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id("org.jetbrains.kotlin.jvm") version "1.9.10"
id("org.jetbrains.kotlin.kapt") version "1.9.10"
id("org.jetbrains.kotlin.jvm")
id("org.jetbrains.kotlin.kapt")
id("io.micronaut.build.internal.crac-test-suite")
}

Expand Down