Skip to content

Commit 09a1818

Browse files
runningcodeclaude
andcommitted
test(spring-boot): Move the Boot 4 Kafka test into the module
Ports the Boot 4 sample's KafkaQueueSystemTest to the integrationTest suite with @embeddedkafka, as for Boot 3. Spring Boot 4 needs its Kafka starter for the auto-configuration, and spring-kafka-test comes from the Boot BOM like spring-kafka. The Boot 4 sample has no system tests left, so it comes off the system-test runner, the backend workflow and the Spring Boot 4 matrix. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 37725db commit 09a1818

12 files changed

Lines changed: 90 additions & 196 deletions

File tree

‎.github/workflows/spring-boot-4-matrix.yml‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ jobs:
7171
- name: Build sample artifacts
7272
run: |
7373
./gradlew \
74-
:sentry-samples:sentry-samples-spring-boot-4:bootJar \
75-
:sentry-samples:sentry-samples-spring-boot-4:testClasses \
7674
:sentry-samples:sentry-samples-spring-boot-4-webflux:bootJar \
7775
:sentry-samples:sentry-samples-spring-boot-4-webflux:testClasses \
7876
:sentry-samples:sentry-samples-spring-boot-4-opentelemetry:bootJar \
@@ -86,13 +84,6 @@ jobs:
8684
- name: Test sentry-spring-boot-4 integration suite
8785
run: ./gradlew :sentry-spring-boot-4:integrationTest
8886

89-
- name: Run sentry-samples-spring-boot-4
90-
run: |
91-
python3 test/system-test-runner.py test \
92-
--module "sentry-samples-spring-boot-4" \
93-
--agent false \
94-
--auto-init "true"
95-
9687
- name: Run sentry-samples-spring-boot-4-webflux
9788
run: |
9889
python3 test/system-test-runner.py test \

‎.github/workflows/system-tests-backend.yml‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ jobs:
7070
- sample: "sentry-samples-jul"
7171
agent: "false"
7272
agent-auto-init: "true"
73-
- sample: "sentry-samples-spring-boot-4"
74-
agent: "false"
75-
agent-auto-init: "true"
7673
- sample: "sentry-samples-spring-boot-4-log4j2"
7774
agent: "false"
7875
agent-auto-init: "true"

‎gradle/libs.versions.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ spring-kafka2 = { module = "org.springframework.kafka:spring-kafka", version = "
218218
spring-kafka3 = { module = "org.springframework.kafka:spring-kafka", version.ref = "springKafka3" }
219219
spring-kafka3-test = { module = "org.springframework.kafka:spring-kafka-test", version.ref = "springKafka3" }
220220
spring-kafka4 = { module = "org.springframework.kafka:spring-kafka" }
221+
spring-kafka4-test = { module = "org.springframework.kafka:spring-kafka-test" }
221222
kafka-clients = { module = "org.apache.kafka:kafka-clients", version = "3.8.1" }
222223
springboot4-otel = { module = "io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter", version.ref = "otelInstrumentation" }
223224
springboot4-resttestclient = { module = "org.springframework.boot:spring-boot-resttestclient", version.ref = "springboot4" }

‎sentry-samples/sentry-samples-spring-boot-4/build.gradle.kts‎

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ plugins {
66
alias(libs.plugins.spring.dependency.management)
77
alias(libs.plugins.kotlin.jvm)
88
alias(libs.plugins.kotlin.spring)
9-
id("io.sentry.systemtest")
109
}
1110

1211
group = "io.sentry.sample.spring-boot-4"
@@ -71,35 +70,4 @@ dependencies {
7170
// database query tracing
7271
implementation(projects.sentryJdbc)
7372
runtimeOnly(libs.hsqldb)
74-
75-
testImplementation(kotlin(Config.kotlinStdLib))
76-
testImplementation(projects.sentry)
77-
testImplementation(projects.sentrySystemTestSupport)
78-
testImplementation(libs.apollo3.kotlin)
79-
testImplementation(libs.kotlin.test.junit)
80-
testImplementation(libs.slf4j2.api)
81-
testImplementation(libs.springboot4.starter.test) {
82-
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
83-
}
84-
testImplementation("ch.qos.logback:logback-classic:1.5.16")
85-
testImplementation("ch.qos.logback:logback-core:1.5.16")
86-
}
87-
88-
tasks.register<Test>("systemTest").configure {
89-
group = "verification"
90-
description = "Runs the System tests"
91-
92-
val test = project.extensions.getByType<SourceSetContainer>()["test"]
93-
testClassesDirs = test.output.classesDirs
94-
classpath = test.runtimeClasspath
95-
96-
maxParallelForks = 1
97-
98-
filter { includeTestsMatching("io.sentry.systemtest*") }
99-
}
100-
101-
tasks.named("test").configure {
102-
require(this is Test)
103-
104-
filter { excludeTestsMatching("io.sentry.systemtest.*") }
10573
}

‎sentry-samples/sentry-samples-spring-boot-4/src/test/kotlin/io/sentry/DummyTest.kt‎

Lines changed: 0 additions & 12 deletions
This file was deleted.

‎sentry-samples/sentry-samples-spring-boot-4/src/test/kotlin/io/sentry/systemtest/KafkaQueueSystemTest.kt‎

Lines changed: 0 additions & 117 deletions
This file was deleted.

‎sentry-samples/sentry-samples-spring-boot-4/src/test/resources/logback.xml‎

Lines changed: 0 additions & 17 deletions
This file was deleted.

‎sentry-spring-boot-4/build.gradle.kts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ testing {
171171
implementation(projects.sentryAsyncProfiler)
172172
implementation(projects.sentryGraphql22)
173173
implementation(projects.sentryJdbc)
174+
implementation(projects.sentryKafka)
174175
implementation(projects.sentryLogback)
175176
implementation(projects.sentryOkhttp)
176177
implementation(projects.sentryTestSupport)
@@ -186,11 +187,13 @@ testing {
186187
implementation(libs.springboot4.starter.cache)
187188
implementation(libs.springboot4.starter.graphql)
188189
implementation(libs.springboot4.starter.jdbc)
190+
implementation(libs.springboot4.starter.kafka)
189191
implementation(libs.springboot4.starter.restclient)
190192
implementation(libs.springboot4.starter.test)
191193
implementation(libs.springboot4.starter.web)
192194
implementation(libs.springboot4.starter.webclient)
193195
implementation(libs.springboot4.starter.webflux)
196+
implementation(libs.spring.kafka4.test)
194197
runtimeOnly(libs.hsqldb)
195198
}
196199
}

‎sentry-spring-boot-4/src/integrationTest/kotlin/io/sentry/spring/boot4/integrationtest/IntegrationTest.kt‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,22 @@ import org.springframework.boot.restclient.RestTemplateBuilder
77
import org.springframework.boot.resttestclient.TestRestTemplate
88
import org.springframework.boot.test.context.SpringBootTest
99
import org.springframework.boot.test.web.server.LocalServerPort
10+
import org.springframework.kafka.test.context.EmbeddedKafka
1011
import org.springframework.test.context.DynamicPropertyRegistry
1112
import org.springframework.test.context.DynamicPropertySource
1213
import org.springframework.test.context.junit4.SpringRunner
1314

1415
/**
1516
* Drives [IntegrationTestApplication] over HTTP and asserts what reaches [server].
1617
*
17-
* Subclasses share one application context and one server, so the app starts once per suite.
18-
* Envelopes that arrive late can outlive [server]'s reset, so tests match on values only they
19-
* produce.
18+
* Subclasses share one application context, one server and one Kafka broker, so each starts once
19+
* per suite. Envelopes that arrive late can outlive [server]'s reset, so tests match on values only
20+
* they produce.
2021
*/
2122
@RunWith(SpringRunner::class)
23+
// An in-JVM KRaft broker, so no Docker is needed. As part of the context, it starts before the
24+
// app's Kafka listener connects and stops after it.
25+
@EmbeddedKafka(topics = [KAFKA_TOPIC], bootstrapServersProperty = "spring.kafka.bootstrap-servers")
2226
@SpringBootTest(
2327
classes = [IntegrationTestApplication::class],
2428
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
@@ -27,12 +31,14 @@ import org.springframework.test.context.junit4.SpringRunner
2731
"sentry.traces-sample-rate=1.0",
2832
"sentry.clients.ok-http-enabled=true",
2933
"sentry.enable-cache-tracing=true",
34+
"sentry.enable-queue-tracing=true",
3035
"sentry.logs.enabled=true",
3136
"sentry.profile-session-sample-rate=1.0",
3237
"sentry.profile-lifecycle=TRACE",
3338
"sentry.profiling-traces-dir-path=\${java.io.tmpdir}/sentry-integration-test/profiling-traces",
3439
"spring.datasource.url=jdbc:p6spy:hsqldb:mem:testdb",
3540
"spring.datasource.driver-class-name=com.p6spy.engine.spy.P6SpyDriver",
41+
"spring.kafka.consumer.auto-offset-reset=earliest",
3642
],
3743
)
3844
abstract class IntegrationTest {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package io.sentry.spring.boot4.integrationtest
2+
3+
import org.springframework.kafka.annotation.KafkaListener
4+
import org.springframework.kafka.core.KafkaTemplate
5+
import org.springframework.stereotype.Component
6+
import org.springframework.web.bind.annotation.GetMapping
7+
import org.springframework.web.bind.annotation.RequestMapping
8+
import org.springframework.web.bind.annotation.RequestParam
9+
import org.springframework.web.bind.annotation.RestController
10+
11+
const val KAFKA_TOPIC = "sentry-topic"
12+
13+
@RestController
14+
@RequestMapping("/kafka")
15+
class KafkaController(private val kafkaTemplate: KafkaTemplate<String, String>) {
16+
@GetMapping("/produce")
17+
fun produce(@RequestParam message: String): String {
18+
kafkaTemplate.send(KAFKA_TOPIC, message)
19+
return "Message sent: $message"
20+
}
21+
}
22+
23+
@Component
24+
class KafkaConsumer {
25+
/** Does nothing with the message; Sentry traces the listener invocation. */
26+
@KafkaListener(topics = [KAFKA_TOPIC], groupId = "sentry-integration-test")
27+
fun listen(message: String) {}
28+
}

0 commit comments

Comments
 (0)