generated from micronaut-projects/micronaut-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
185 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
dependencyResolutionManagement { | ||
versionCatalogs { | ||
libs { | ||
from(files("../gradle/libs.versions.toml")) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
49 changes: 49 additions & 0 deletions
49
test-suite-kotlin-ksp/src/test/kotlin/io/micronaut/crac/EagerHttpClientCreationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...te-kotlin-ksp/src/test/kotlin/io/micronaut/crac/OrderedResourceCheckpointSimulatorTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[] | ||
} |
22 changes: 22 additions & 0 deletions
22
test-suite-kotlin-ksp/src/test/kotlin/io/micronaut/crac/ResourceBean.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[] |
23 changes: 23 additions & 0 deletions
23
test-suite-kotlin-ksp/src/test/kotlin/io/micronaut/crac/ResourceBeanResource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters