Skip to content

Commit

Permalink
CRaC to Java 21 (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
timyates authored Oct 12, 2023
1 parent a028e28 commit 34ed8a2
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 6 deletions.
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.4"
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.3"
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' }
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

0 comments on commit 34ed8a2

Please sign in to comment.