Skip to content

Commit

Permalink
Use the current JDK for testing, but 17 for building (#9989)
Browse files Browse the repository at this point in the history
* Use the current JDK for testing, but 17 for building

Previously we added a PR to run (and compile) under Java 21

#9978

This did not work as expected, as in reality this is configuring under the current JDK,
but compilation is being done by Java 17 from the ToolChain set up by the micronaut-build
plugin.

This PR modifies the test tasks to run on the JDK that is used to start the build.

But all compilation will be done via Java 17 from the toolchain.
  • Loading branch information
timyates authored Oct 20, 2023
1 parent d140815 commit 2d1dbbd
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 71 deletions.
15 changes: 0 additions & 15 deletions config/accepted-api-changes.json
Original file line number Diff line number Diff line change
Expand Up @@ -348,20 +348,5 @@
"type": "io.micronaut.core.graal.AutomaticFeatureUtils",
"member": "Constructor io.micronaut.core.graal.AutomaticFeatureUtils()",
"reason": "Was deprecated"
},
{
"type": "io.micronaut.ast.groovy.TypeElementVisitorTransform$ElementVisitor$_visitNativeProperty_lambda1",
"member": "Constructor io.micronaut.ast.groovy.TypeElementVisitorTransform$ElementVisitor$_visitNativeProperty_lambda1(java.lang.Object,java.lang.Object,groovy.lang.Reference)",
"reason": "Under Java 21 the constructor is absent"
},
{
"type": "io.micronaut.ast.groovy.TypeElementVisitorTransform$ElementVisitor$_visitNativeProperty_lambda2",
"member": "Constructor io.micronaut.ast.groovy.TypeElementVisitorTransform$ElementVisitor$_visitNativeProperty_lambda2(java.lang.Object,java.lang.Object,groovy.lang.Reference)",
"reason": "Under Java 21 the constructor is absent"
},
{
"type": "io.micronaut.ast.groovy.TypeElementVisitorTransform$ElementVisitor$_visitNativeProperty_lambda3",
"member": "Constructor io.micronaut.ast.groovy.TypeElementVisitorTransform$ElementVisitor$_visitNativeProperty_lambda3(java.lang.Object,java.lang.Object,groovy.lang.Reference)",
"reason": "Under Java 21 the constructor is absent"
}
]
6 changes: 4 additions & 2 deletions context-propagation/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id "io.micronaut.build.internal.convention-library"
id "org.jetbrains.kotlin.jvm"
id("com.google.devtools.ksp")
id "org.jetbrains.kotlin.kapt"
}

dependencies {
Expand Down Expand Up @@ -58,7 +58,9 @@ dependencies {

// Kotlin
dependencies {
kspTest projects.injectKotlin
kapt project(':inject-java')
kaptTest project(':inject-java')

compileOnly libs.managed.kotlin.stdlib.jdk8
compileOnly libs.managed.kotlinx.coroutines.core

Expand Down
13 changes: 13 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,16 @@ org.gradle.parallel=true
org.gradle.jvmargs=-Xmx1g
systemProp.predictiveTestSelection=false
predictiveTestSelection=false

# No matter which Java toolchain we use, the Kotlin Daemon is always invoked by the current JDK.
# Therefor to fix Kapt errors when running tests under Java 21, we need to open up some modules for the Kotlin Daemon.
kotlin.daemon.jvmargs=--add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED\
--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED \
--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED \
--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED \
--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED \
--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED \
--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@ import reactor.core.publisher.Flux
import reactor.core.publisher.FluxSink
import reactor.core.publisher.Mono
import spock.lang.Specification
import spock.lang.Unroll

import java.util.concurrent.ExecutorService

class ThreadSelectionSpec extends Specification {

static final String IO = "io-executor-thread-"
static final String VIRTUAL = "virtual-executor"
static final String LOOP = "default-nioEventLoopGroup"

@Unroll
private String jdkSwitch(String java17, String other) {
Runtime.version().feature() == 17 ? java17 : other
}

void "test thread selection strategy #strategy"() {
given:
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer, ['micronaut.server.thread-selection': strategy])
Expand All @@ -54,13 +57,13 @@ class ThreadSelectionSpec extends Specification {
embeddedServer.close()

where:
strategy | blocking | nonBlocking | scheduleBlocking
ThreadSelection.AUTO | IO | LOOP | IO
ThreadSelection.IO | IO | IO | IO
ThreadSelection.MANUAL | LOOP | LOOP | IO
strategy | blocking | nonBlocking | scheduleBlocking
ThreadSelection.AUTO | jdkSwitch(IO, VIRTUAL) | LOOP | IO
ThreadSelection.BLOCKING | jdkSwitch(IO, VIRTUAL) | jdkSwitch(IO, VIRTUAL) | IO
ThreadSelection.IO | IO | IO | IO
ThreadSelection.MANUAL | LOOP | LOOP | IO
}

@Unroll
void "test thread selection strategy for reactive types #strategy"() {
given:
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer, ['micronaut.server.thread-selection': strategy])
Expand All @@ -77,13 +80,14 @@ class ThreadSelectionSpec extends Specification {
embeddedServer.close()

where:
strategy | reactive | blockingReactive | scheduleSse | scheduleReactive
ThreadSelection.AUTO | LOOP | IO | IO | IO
ThreadSelection.IO | IO | IO | IO | IO
ThreadSelection.MANUAL | LOOP | LOOP | IO | IO
strategy | reactive | blockingReactive | scheduleSse | scheduleReactive
ThreadSelection.AUTO | LOOP | jdkSwitch(IO, VIRTUAL) | IO | IO
ThreadSelection.BLOCKING | jdkSwitch(IO, VIRTUAL) | jdkSwitch(IO, VIRTUAL) | IO | IO
ThreadSelection.IO | IO | IO | IO | IO
ThreadSelection.MANUAL | LOOP | LOOP | IO | IO
}

void "test thread selection for exception handlers"() {
void "test thread selection for exception handlers #strategy"() {
given:
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer, ['micronaut.server.thread-selection': strategy])
ThreadSelectionClient client = embeddedServer.applicationContext.getBean(ThreadSelectionClient)
Expand All @@ -102,13 +106,14 @@ class ThreadSelectionSpec extends Specification {
embeddedServer.close()

where:
strategy | controller | handler | scheduledHandler
ThreadSelection.AUTO | "controller: $IO" | "handler: $IO" | "handler: $IO"
ThreadSelection.IO | "controller: $IO" | "handler: $IO" | "handler: $IO"
ThreadSelection.MANUAL | "controller: $LOOP" | "handler: $LOOP" | "handler: $IO"
strategy | controller | handler | scheduledHandler
ThreadSelection.AUTO | "controller: ${jdkSwitch(IO, VIRTUAL)}" | "handler: ${jdkSwitch(IO, VIRTUAL)}" | "handler: $IO"
ThreadSelection.BLOCKING | "controller: ${jdkSwitch(IO, VIRTUAL)}" | "handler: ${jdkSwitch(IO, VIRTUAL)}" | "handler: $IO"
ThreadSelection.IO | "controller: $IO" | "handler: $IO" | "handler: $IO"
ThreadSelection.MANUAL | "controller: $LOOP" | "handler: $LOOP" | "handler: $IO"
}

void "test thread selection for error route"() {
void "test thread selection for error route #strategy"() {
given:
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer, ['micronaut.server.thread-selection': strategy])
ThreadSelectionClient client = embeddedServer.applicationContext.getBean(ThreadSelectionClient)
Expand All @@ -124,10 +129,11 @@ class ThreadSelectionSpec extends Specification {
embeddedServer.close()

where:
strategy | controller | handler
ThreadSelection.AUTO | "controller: $IO" | "handler: $IO"
ThreadSelection.IO | "controller: $IO" | "handler: $IO"
ThreadSelection.MANUAL | "controller: $LOOP" | "handler: $LOOP"
strategy | controller | handler
ThreadSelection.AUTO | "controller: ${jdkSwitch(IO, VIRTUAL)}" | "handler: ${jdkSwitch(IO, VIRTUAL)}"
ThreadSelection.BLOCKING | "controller: ${jdkSwitch(IO, VIRTUAL)}" | "handler: ${jdkSwitch(IO, VIRTUAL)}"
ThreadSelection.IO | "controller: $IO" | "handler: $IO"
ThreadSelection.MANUAL | "controller: $LOOP" | "handler: $LOOP"
}

void "test injecting an executor service does not inject the Netty event loop"() {
Expand Down Expand Up @@ -232,10 +238,10 @@ class ThreadSelectionSpec extends Specification {
@ExecuteOn(TaskExecutors.IO)
@Get(uri = "/scheduleSse", produces = MediaType.TEXT_EVENT_STREAM)
Flux<Event<String>> scheduleSse() {
return Flux.<Event<String>>create(emitter -> {
emitter.next( Event.of("thread: ${Thread.currentThread().name}".toString()))
emitter.complete()
}, FluxSink.OverflowStrategy.BUFFER)
return Flux.<Event<String>> create(emitter -> {
emitter.next(Event.of("thread: ${Thread.currentThread().name}".toString()))
emitter.complete()
}, FluxSink.OverflowStrategy.BUFFER)
}

@Get("/exception")
Expand Down Expand Up @@ -265,8 +271,8 @@ class ThreadSelectionSpec extends Specification {
@Override
Publisher<MutableHttpResponse<?>> doFilter(HttpRequest<?> request, ServerFilterChain chain) {
return Flux.create(emitter -> {
emitter.next("Good")
emitter.complete()
emitter.next("Good")
emitter.complete()
}, FluxSink.OverflowStrategy.LATEST).switchMap({ String it ->
return chain.proceed(request)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class MyBean {
def lines = e.message.readLines().collect { it.trim() }
lines[0] == 'No bean of type [test.MyBean] exists. The following matching beans are disabled by bean requirements:'
lines[1] == '* Bean of type [test.MyBean] is disabled because:'
lines[2] == '- Java major version [17] must be at least 800'
lines[2] == "- Java major version [${Runtime.version().feature()}] must be at least 800"

cleanup:
context.close()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/*
* Copyright 2017-2019 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.runtime.executor

import io.micronaut.context.ApplicationContext
Expand All @@ -23,20 +8,19 @@ import io.micronaut.scheduling.executor.ExecutorConfiguration
import io.micronaut.scheduling.executor.UserExecutorConfiguration
import io.micronaut.scheduling.instrument.InstrumentedExecutor
import spock.lang.Specification
import spock.lang.Unroll

import java.util.concurrent.ExecutorService
import java.util.concurrent.ForkJoinPool
import java.util.concurrent.ScheduledExecutorService
import java.util.concurrent.ThreadPoolExecutor

/**
* @author Graeme Rocher
* @since 1.0
*/
class ExecutorServiceConfigSpec extends Specification {
static final int expectedExecutorCount = LoomSupport.isSupported() ? 6 : 5

@Unroll
void "test configure custom executor with invalidate cache: #invalidateCache"() {
given:
ApplicationContext ctx = ApplicationContext.run(
Expand All @@ -49,7 +33,7 @@ class ExecutorServiceConfigSpec extends Specification {
def configs = ctx.getBeansOfType(ExecutorConfiguration)

then:
configs.size() == 4
configs.name ==~ ['one', 'two', 'io', 'scheduled'] + (Runtime.version().feature() == 17 ? [] : ['virtual'])

when:
Collection<ExecutorService> executorServices = ctx.getBeansOfType(ExecutorService.class)
Expand Down Expand Up @@ -106,7 +90,6 @@ class ExecutorServiceConfigSpec extends Specification {
}


@Unroll
void "test configure custom executor - distinct initialization order with invalidate cache: #invalidateCache"() {
given:
ApplicationContext ctx = ApplicationContext.run(
Expand Down Expand Up @@ -152,7 +135,7 @@ class ExecutorServiceConfigSpec extends Specification {

then:
executorServices.size() == expectedExecutorCount
moreConfigs.size() == 4
moreConfigs.name ==~ ['one', 'two', 'io', 'scheduled'] + (Runtime.version().feature() == 17 ? [] : ['virtual'])
configs.size() == 2

when:
Expand All @@ -175,7 +158,6 @@ class ExecutorServiceConfigSpec extends Specification {
false | "test"
}

@Unroll
void "test configure existing IO executor - distinct initialization order with invalidate cache: #invalidateCache"() {
given:
ApplicationContext ctx = ApplicationContext.run(
Expand Down Expand Up @@ -205,7 +187,7 @@ class ExecutorServiceConfigSpec extends Specification {

then:
executorServices.size() == expectedExecutorCount - 1
moreConfigs.size() == 3
moreConfigs.name ==~ ['two', 'io', 'scheduled'] + (Runtime.version().feature() == 17 ? [] : ['virtual'])
configs.size() == 2

where:
Expand Down
6 changes: 2 additions & 4 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pluginManagement {
}

plugins {
id 'io.micronaut.build.shared.settings' version '6.5.7'
id 'io.micronaut.build.shared.settings' version '6.6.0'
}
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

Expand Down Expand Up @@ -68,9 +68,7 @@ include "test-suite-javax-inject"
include "test-suite-jakarta-inject-bean-import"
include "test-suite-http-server-tck-jdk"
include "test-suite-http-server-tck-netty"
if (JavaVersion.current() < JavaVersion.VERSION_21) {
include "test-suite-kotlin"
}
include "test-suite-kotlin"
include "test-suite-kotlin-ksp"
include "test-suite-groovy"
include "test-suite-groovy"
Expand Down

0 comments on commit 2d1dbbd

Please sign in to comment.