Skip to content

Commit 67c562c

Browse files
committed
feat: implement task caching
1 parent 1fcf78c commit 67c562c

File tree

17 files changed

+338
-24
lines changed

17 files changed

+338
-24
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ configurations["integrationImplementation"].extendsFrom(
7373

7474
dependencies {
7575
integrationImplementation("org.wiremock:wiremock-standalone:3.13.2")
76-
integrationImplementation("org.testcontainers:kafka:1.21.3")
76+
integrationImplementation("org.testcontainers:kafka:1.21.4")
7777
}
7878

7979
task<Test>("integrationTest") {

src/integration/kotlin/com/github/imflog/schema/registry/tasks/compatibility/CompatibilityTaskIT.kt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import org.gradle.testkit.runner.GradleRunner
1515
import org.gradle.testkit.runner.TaskOutcome
1616
import org.junit.jupiter.api.AfterEach
1717
import org.junit.jupiter.api.BeforeEach
18+
import org.junit.jupiter.api.Test
1819
import org.junit.jupiter.api.extension.ExtensionContext
1920
import org.junit.jupiter.params.ParameterizedTest
2021
import org.junit.jupiter.params.provider.Arguments
@@ -279,6 +280,61 @@ class CompatibilityTaskIT : KafkaTestContainersUtils() {
279280
Assertions.assertThat(result?.task(":testSchemasTask")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
280281
}
281282

283+
@Test
284+
fun `CompatibilityTask should be UP-TO-DATE on second run`() {
285+
// Given
286+
val subjectName = "uptodate-test"
287+
client.register(
288+
subjectName,
289+
AvroSchema("""{"type":"record","name":"User","fields":[{"name":"name","type":"string"}]}""")
290+
)
291+
292+
folderRule.create()
293+
val userFile = folderRule.newFile("user.avsc")
294+
userFile.writeText("""{"type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"address","type":["null","string"],"default":null}]}""")
295+
296+
buildFile = folderRule.newFile("build.gradle")
297+
buildFile.writeText(
298+
"""
299+
plugins {
300+
id 'java'
301+
id 'com.github.imflog.kafka-schema-registry-gradle-plugin'
302+
}
303+
304+
schemaRegistry {
305+
url = '$schemaRegistryEndpoint'
306+
compatibility {
307+
subject('$subjectName', '${userFile.absolutePath}', 'AVRO')
308+
}
309+
}
310+
"""
311+
)
312+
313+
// When
314+
val result1: BuildResult = GradleRunner.create()
315+
.withGradleVersion("8.6")
316+
.withProjectDir(folderRule.root)
317+
.withArguments(CompatibilityTask.TASK_NAME)
318+
.withPluginClasspath()
319+
.withDebug(true)
320+
.build()
321+
322+
// Then
323+
Assertions.assertThat(result1.task(":testSchemasTask")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
324+
325+
// When (second run)
326+
val result2: BuildResult = GradleRunner.create()
327+
.withGradleVersion("8.6")
328+
.withProjectDir(folderRule.root)
329+
.withArguments(CompatibilityTask.TASK_NAME)
330+
.withPluginClasspath()
331+
.withDebug(true)
332+
.build()
333+
334+
// Then
335+
Assertions.assertThat(result2.task(":testSchemasTask")?.outcome).isEqualTo(TaskOutcome.UP_TO_DATE)
336+
}
337+
282338
private class SchemaSuccessArgumentProvider : ArgumentsProvider {
283339
override fun provideArguments(parameters: ParameterDeclarations, context: ExtensionContext): Stream<out Arguments> =
284340
Stream.of(

src/integration/kotlin/com/github/imflog/schema/registry/tasks/config/ConfigTaskIT.kt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,51 @@ class ConfigTaskIT : KafkaTestContainersUtils() {
5555
Assertions.assertThat(result?.task(":configSubjectsTask")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
5656
}
5757

58+
@Test
59+
fun `ConfigTask should be UP-TO-DATE on second run`() {
60+
folderRule.create()
61+
buildFile = folderRule.newFile("build.gradle")
62+
buildFile.writeText(
63+
"""
64+
plugins {
65+
id 'java'
66+
id 'com.github.imflog.kafka-schema-registry-gradle-plugin'
67+
}
68+
69+
schemaRegistry {
70+
url = '$schemaRegistryEndpoint'
71+
config {
72+
subject('testSubject1', 'FULL_TRANSITIVE')
73+
}
74+
}
75+
""".trimIndent()
76+
)
77+
78+
// When
79+
val result1: BuildResult = GradleRunner.create()
80+
.withGradleVersion("8.6")
81+
.withProjectDir(folderRule.root)
82+
.withArguments(ConfigTask.TASK_NAME)
83+
.withPluginClasspath()
84+
.withDebug(true)
85+
.build()
86+
87+
// Then
88+
Assertions.assertThat(result1.task(":configSubjectsTask")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
89+
90+
// When (second run)
91+
val result2: BuildResult = GradleRunner.create()
92+
.withGradleVersion("8.6")
93+
.withProjectDir(folderRule.root)
94+
.withArguments(ConfigTask.TASK_NAME)
95+
.withPluginClasspath()
96+
.withDebug(true)
97+
.build()
98+
99+
// Then
100+
Assertions.assertThat(result2.task(":configSubjectsTask")?.outcome).isEqualTo(TaskOutcome.UP_TO_DATE)
101+
}
102+
58103
@Test
59104
fun `ConfigTask should detect and reject invalid compatibility settings`() {
60105
folderRule.create()

src/integration/kotlin/com/github/imflog/schema/registry/tasks/download/DownloadTaskIT.kt

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,92 @@ class DownloadTaskIT : KafkaTestContainersUtils() {
568568
}""".trimIndent().trim())
569569
}}
570570

571+
@Test
572+
fun `Download task should be UP-TO-DATE on second run`() {
573+
// Given
574+
val subjectName = "uptodate-test"
575+
client.register(subjectName, AvroSchema("""{"type":"record","name":"User","fields":[{"name":"name","type":"string"}]}"""))
576+
577+
buildFile = folderRule.newFile("build.gradle")
578+
buildFile.writeText(
579+
"""
580+
plugins {
581+
id 'java'
582+
id 'com.github.imflog.kafka-schema-registry-gradle-plugin'
583+
}
584+
585+
schemaRegistry {
586+
url = '$schemaRegistryEndpoint'
587+
download {
588+
subject('$subjectName', 'src/main/avro/test')
589+
}
590+
}
591+
"""
592+
)
593+
594+
// When
595+
val result1: BuildResult = GradleRunner.create()
596+
.withGradleVersion("8.6")
597+
.withProjectDir(folderRule.root)
598+
.withArguments(DownloadTask.TASK_NAME)
599+
.withPluginClasspath()
600+
.withDebug(true)
601+
.build()
602+
603+
// Then
604+
Assertions.assertThat(result1.task(":downloadSchemasTask")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
605+
606+
// When (second run)
607+
val result2: BuildResult = GradleRunner.create()
608+
.withGradleVersion("8.6")
609+
.withProjectDir(folderRule.root)
610+
.withArguments(DownloadTask.TASK_NAME)
611+
.withPluginClasspath()
612+
.withDebug(true)
613+
.build()
614+
615+
// Then
616+
Assertions.assertThat(result2.task(":downloadSchemasTask")?.outcome).isEqualTo(TaskOutcome.UP_TO_DATE)
617+
}
618+
619+
@Test
620+
fun `Download task should not fail with serialization error when metadata is enabled`() {
621+
// Given
622+
val subjectName = "metadata-serialization-test"
623+
client.register(subjectName, AvroSchema("""{"type":"record","name":"User","fields":[{"name":"name","type":"string"}]}"""))
624+
625+
buildFile = folderRule.newFile("build.gradle")
626+
buildFile.writeText(
627+
"""
628+
plugins {
629+
id 'java'
630+
id 'com.github.imflog.kafka-schema-registry-gradle-plugin'
631+
}
632+
633+
import com.github.imflog.schema.registry.tasks.download.MetadataExtension
634+
schemaRegistry {
635+
url = '$schemaRegistryEndpoint'
636+
download {
637+
metadata = new MetadataExtension(true, 'src/main/avro/metadata')
638+
subject('$subjectName', 'src/main/avro/test')
639+
}
640+
}
641+
"""
642+
)
643+
644+
// When
645+
val result: BuildResult = GradleRunner.create()
646+
.withGradleVersion("8.6")
647+
.withProjectDir(folderRule.root)
648+
.withArguments(DownloadTask.TASK_NAME)
649+
.withPluginClasspath()
650+
.withDebug(true)
651+
.build()
652+
653+
// Then
654+
Assertions.assertThat(result.task(":downloadSchemasTask")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
655+
}
656+
571657
private class SchemaArgumentProvider : ArgumentsProvider {
572658
override fun provideArguments(parameters: ParameterDeclarations, context: ExtensionContext): Stream<out Arguments> =
573659
Stream.of(

src/integration/kotlin/com/github/imflog/schema/registry/tasks/register/RegisterTaskIT.kt

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,26 @@ import org.gradle.testkit.runner.GradleRunner
99
import org.gradle.testkit.runner.TaskOutcome
1010
import org.junit.jupiter.api.AfterEach
1111
import org.junit.jupiter.api.BeforeEach
12+
import org.junit.jupiter.api.Test
1213
import org.junit.jupiter.api.extension.ExtensionContext
1314
import org.junit.jupiter.params.ParameterizedTest
1415
import org.junit.jupiter.params.provider.Arguments
1516
import org.junit.jupiter.params.provider.ArgumentsProvider
16-
import org.junit.jupiter.params.support.ParameterDeclarations
1717
import org.junit.jupiter.params.provider.ArgumentsSource
18+
import org.junit.jupiter.params.support.ParameterDeclarations
1819
import java.io.File
20+
import java.util.UUID
1921
import java.util.stream.Stream
2022

2123
class RegisterTaskIT : KafkaTestContainersUtils() {
2224
private lateinit var folderRule: TemporaryFolder
2325
private lateinit var buildFile: File
26+
private lateinit var subjectId: String
2427

2528
@BeforeEach
2629
fun beforeEach() {
2730
folderRule = TemporaryFolder()
31+
subjectId = UUID.randomUUID().toString().take(8)
2832
}
2933

3034
@AfterEach
@@ -43,7 +47,7 @@ class RegisterTaskIT : KafkaTestContainersUtils() {
4347
folderRule.create()
4448
val typeFolder = folderRule.newFolder(type.name)
4549
val resultFolder = folderRule.newFolder("${type.name}/results")
46-
val subjectName = "parameterized-${type.name}"
50+
val subjectName = "parameterized-${type.name}-$subjectId"
4751
val extension = type.extension
4852

4953
val userFile = typeFolder.resolve("user.$extension")
@@ -108,7 +112,7 @@ class RegisterTaskIT : KafkaTestContainersUtils() {
108112
folderRule.create()
109113
val typeFolder = folderRule.newFolder(type.name)
110114
val resultFolder = folderRule.newFolder("${type.name}/results")
111-
val subjectName = "parameterized-${type.name}"
115+
val subjectName = "parameterized-${type.name}-$subjectId"
112116
val extension = type.extension
113117

114118
val userFile = typeFolder.resolve("user.$extension")
@@ -180,7 +184,7 @@ class RegisterTaskIT : KafkaTestContainersUtils() {
180184
) {
181185
folderRule.create()
182186
folderRule.newFolder(type.name)
183-
val subjectName = "parameterized-${type.name}-local"
187+
val subjectName = "parameterized-${type.name}-local-$subjectId"
184188
val extension = type.extension
185189

186190
val userPath = "$type/user.$extension"
@@ -235,7 +239,7 @@ class RegisterTaskIT : KafkaTestContainersUtils() {
235239
// Also, when all format support mixed local + remote, we will keep only this test.
236240
folderRule.create()
237241
folderRule.newFolder(type.name)
238-
val subjectName = "parameterized-${type.name}-mixed"
242+
val subjectName = "parameterized-${type.name}-mixed-$subjectId"
239243
val extension = type.extension
240244

241245
// Local
@@ -287,6 +291,66 @@ class RegisterTaskIT : KafkaTestContainersUtils() {
287291
}
288292

289293

294+
@Test
295+
fun `RegisterSchemasTask should be UP-TO-DATE on second run`() {
296+
folderRule.create()
297+
val typeFolder = folderRule.newFolder("avro")
298+
val resultFolder = folderRule.newFolder("avro/results")
299+
300+
val userFile = typeFolder.resolve("user.avsc")
301+
userFile.writeText(
302+
"""{
303+
"type": "record",
304+
"name": "User",
305+
"fields": [
306+
{ "name": "name", "type": "string" }
307+
]
308+
}"""
309+
)
310+
311+
buildFile = folderRule.newFile("build.gradle")
312+
buildFile.writeText(
313+
"""
314+
plugins {
315+
id 'java'
316+
id 'com.github.imflog.kafka-schema-registry-gradle-plugin'
317+
}
318+
319+
schemaRegistry {
320+
url = '$schemaRegistryEndpoint'
321+
outputDirectory = '${resultFolder.absolutePath}'
322+
register {
323+
subject('user', '${userFile.absolutePath}', 'AVRO')
324+
}
325+
}
326+
"""
327+
)
328+
329+
// When
330+
val result1: BuildResult = GradleRunner.create()
331+
.withGradleVersion("8.6")
332+
.withProjectDir(folderRule.root)
333+
.withArguments(RegisterSchemasTask.TASK_NAME)
334+
.withPluginClasspath()
335+
.withDebug(true)
336+
.build()
337+
338+
// Then
339+
Assertions.assertThat(result1.task(":registerSchemasTask")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
340+
341+
// When (second run)
342+
val result2: BuildResult = GradleRunner.create()
343+
.withGradleVersion("8.6")
344+
.withProjectDir(folderRule.root)
345+
.withArguments(RegisterSchemasTask.TASK_NAME)
346+
.withPluginClasspath()
347+
.withDebug(true)
348+
.build()
349+
350+
// Then
351+
Assertions.assertThat(result2.task(":registerSchemasTask")?.outcome).isEqualTo(TaskOutcome.UP_TO_DATE)
352+
}
353+
290354
private class SchemaArgumentProvider : ArgumentsProvider {
291355
override fun provideArguments(parameters: ParameterDeclarations, context: ExtensionContext): Stream<out Arguments> =
292356
Stream.of(
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package com.github.imflog.schema.registry
22

33
import java.io.File
4+
import java.io.Serializable
45

56
data class LocalReference(
67
val name: String,
78
val path: String
8-
) {
9+
) : Serializable {
910
fun content(rootDir: File) = rootDir.resolve(path).readText()
1011
}

0 commit comments

Comments
 (0)