Skip to content

Commit 0693115

Browse files
runningcodeclaude
andauthored
test(spring-boot): Move the Boot 4 Kafka test into the module (#6298)
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 6535064 commit 0693115

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
@@ -67,9 +67,6 @@ jobs:
6767
- sample: "sentry-samples-jul"
6868
agent: "false"
6969
agent-auto-init: "true"
70-
- sample: "sentry-samples-spring-boot-4"
71-
agent: "false"
72-
agent-auto-init: "true"
7370
- sample: "sentry-samples-spring-boot-4-log4j2"
7471
agent: "false"
7572
agent-auto-init: "true"

‎gradle/libs.versions.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ spring-kafka2 = { module = "org.springframework.kafka:spring-kafka", version = "
223223
spring-kafka3 = { module = "org.springframework.kafka:spring-kafka", version.ref = "springKafka3" }
224224
spring-kafka3-test = { module = "org.springframework.kafka:spring-kafka-test", version.ref = "springKafka3" }
225225
spring-kafka4 = { module = "org.springframework.kafka:spring-kafka" }
226+
spring-kafka4-test = { module = "org.springframework.kafka:spring-kafka-test" }
226227
kafka-clients = { module = "org.apache.kafka:kafka-clients", version = "3.8.1" }
227228
springboot4-otel = { module = "io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter", version.ref = "otelInstrumentation" }
228229
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"
@@ -61,35 +60,4 @@ dependencies {
6160
// database query tracing
6261
implementation(projects.sentryJdbc)
6362
runtimeOnly(libs.hsqldb)
64-
65-
testImplementation(kotlin(Config.kotlinStdLib))
66-
testImplementation(projects.sentry)
67-
testImplementation(projects.sentrySystemTestSupport)
68-
testImplementation(libs.apollo3.kotlin)
69-
testImplementation(libs.kotlin.test.junit)
70-
testImplementation(libs.slf4j2.api)
71-
testImplementation(libs.springboot4.starter.test) {
72-
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
73-
}
74-
testImplementation("ch.qos.logback:logback-classic:1.5.16")
75-
testImplementation("ch.qos.logback:logback-core:1.5.16")
76-
}
77-
78-
tasks.register<Test>("systemTest").configure {
79-
group = "verification"
80-
description = "Runs the System tests"
81-
82-
val test = project.extensions.getByType<SourceSetContainer>()["test"]
83-
testClassesDirs = test.output.classesDirs
84-
classpath = test.runtimeClasspath
85-
86-
maxParallelForks = 1
87-
88-
filter { includeTestsMatching("io.sentry.systemtest*") }
89-
}
90-
91-
tasks.named("test").configure {
92-
require(this is Test)
93-
94-
filter { excludeTestsMatching("io.sentry.systemtest.*") }
9563
}

‎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
@@ -169,6 +169,7 @@ testing {
169169
implementation(projects.sentryAsyncProfiler)
170170
implementation(projects.sentryGraphql22)
171171
implementation(projects.sentryJdbc)
172+
implementation(projects.sentryKafka)
172173
implementation(projects.sentryLogback)
173174
implementation(projects.sentryOkhttp)
174175
implementation(projects.sentryTestSupport)
@@ -184,11 +185,13 @@ testing {
184185
implementation(libs.springboot4.starter.cache)
185186
implementation(libs.springboot4.starter.graphql)
186187
implementation(libs.springboot4.starter.jdbc)
188+
implementation(libs.springboot4.starter.kafka)
187189
implementation(libs.springboot4.starter.restclient)
188190
implementation(libs.springboot4.starter.test)
189191
implementation(libs.springboot4.starter.web)
190192
implementation(libs.springboot4.starter.webclient)
191193
implementation(libs.springboot4.starter.webflux)
194+
implementation(libs.spring.kafka4.test)
192195
runtimeOnly(libs.hsqldb)
193196
}
194197
}

‎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)