From 5ae374eef7ba1e248de422889d319b428a2d334b Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Fri, 10 May 2024 13:18:58 +0200 Subject: [PATCH] fix r2dbc test --- .../spring-boot-reactive-2/build.gradle.kts | 4 +++ .../build.gradle.kts | 1 + ...actOtelReactiveSpringStarterSmokeTest.java | 22 +++++++++------- ...ctiveSpringStarterSmokeTestController.java | 2 +- .../spring/smoketest/Player.java | 26 ++++++++++++++++--- .../src/main/resources/application.yaml | 0 .../src/main/resources/schema.sql | 0 .../AbstractSpringStarterSmokeTest.java | 7 +++-- 8 files changed, 45 insertions(+), 17 deletions(-) rename smoke-tests-otel-starter/{spring-boot-3-reactive => spring-boot-reactive-common}/src/main/resources/application.yaml (100%) rename smoke-tests-otel-starter/{spring-boot-3-reactive => spring-boot-reactive-common}/src/main/resources/schema.sql (100%) diff --git a/smoke-tests-otel-starter/spring-boot-reactive-2/build.gradle.kts b/smoke-tests-otel-starter/spring-boot-reactive-2/build.gradle.kts index 315c1f77694e..7d026d937396 100644 --- a/smoke-tests-otel-starter/spring-boot-reactive-2/build.gradle.kts +++ b/smoke-tests-otel-starter/spring-boot-reactive-2/build.gradle.kts @@ -11,6 +11,10 @@ dependencies { implementation(project(":smoke-tests-otel-starter:spring-boot-reactive-common")) implementation("org.springframework.boot:spring-boot-starter-webflux") + implementation("org.springframework.boot:spring-boot-starter-data-r2dbc") + + runtimeOnly("com.h2database:h2") + runtimeOnly("io.r2dbc:r2dbc-h2") testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation("io.projectreactor:reactor-test") diff --git a/smoke-tests-otel-starter/spring-boot-reactive-common/build.gradle.kts b/smoke-tests-otel-starter/spring-boot-reactive-common/build.gradle.kts index 2bfc4d850c28..ecd694186b28 100644 --- a/smoke-tests-otel-starter/spring-boot-reactive-common/build.gradle.kts +++ b/smoke-tests-otel-starter/spring-boot-reactive-common/build.gradle.kts @@ -13,6 +13,7 @@ dependencies { compileOnly("org.springframework.boot:spring-boot-starter-web") compileOnly("org.springframework.boot:spring-boot-starter-webflux") compileOnly("org.springframework.boot:spring-boot-starter-test") + compileOnly("org.springframework.boot:spring-boot-starter-data-r2dbc") api(project(":smoke-tests-otel-starter:spring-smoke-testing")) } diff --git a/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelReactiveSpringStarterSmokeTest.java b/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelReactiveSpringStarterSmokeTest.java index b0ad69f99a29..27a427ef02a4 100644 --- a/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelReactiveSpringStarterSmokeTest.java +++ b/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/java/io/opentelemetry/spring/smoketest/AbstractOtelReactiveSpringStarterSmokeTest.java @@ -11,10 +11,6 @@ import io.opentelemetry.semconv.HttpAttributes; import io.opentelemetry.semconv.UrlAttributes; import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; -import io.opentelemetry.spring.smoketest.AbstractSpringStarterSmokeTest; -import io.opentelemetry.spring.smoketest.OtelReactiveSpringStarterSmokeTestApplication; -import io.opentelemetry.spring.smoketest.OtelReactiveSpringStarterSmokeTestController; -import io.opentelemetry.spring.smoketest.SpringSmokeOtelConfiguration; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -67,13 +63,21 @@ void webClientAndWebFluxAndR2dbc() { .hasAttribute(HttpAttributes.HTTP_ROUTE, "/webflux"), span -> span.hasKind(SpanKind.CLIENT) - .hasName("SELECT testdb.PLAYER") + .satisfies( + s -> + assertThat(s.getName()) + .isEqualToIgnoringCase("SELECT testdb.PLAYER")) .hasAttribute(DbIncubatingAttributes.DB_NAME, "testdb") - .hasAttribute(DbIncubatingAttributes.DB_SQL_TABLE, "PLAYER") + .hasAttributesSatisfying( + a -> + assertThat(a.get(DbIncubatingAttributes.DB_SQL_TABLE)) + .isEqualToIgnoringCase("PLAYER")) .hasAttribute(DbIncubatingAttributes.DB_OPERATION, "SELECT") - .hasAttribute( - DbIncubatingAttributes.DB_STATEMENT, - "SELECT PLAYER.* FROM PLAYER WHERE PLAYER.ID = $? LIMIT ?") + .hasAttributesSatisfying( + a -> + assertThat(a.get(DbIncubatingAttributes.DB_STATEMENT)) + .isEqualToIgnoringCase( + "SELECT PLAYER.* FROM PLAYER WHERE PLAYER.ID = $? LIMIT ?")) .hasAttribute(DbIncubatingAttributes.DB_SYSTEM, "h2"))); } } diff --git a/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/java/io/opentelemetry/spring/smoketest/OtelReactiveSpringStarterSmokeTestController.java b/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/java/io/opentelemetry/spring/smoketest/OtelReactiveSpringStarterSmokeTestController.java index d2cbd9e90dd9..2eebba8d6bb8 100644 --- a/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/java/io/opentelemetry/spring/smoketest/OtelReactiveSpringStarterSmokeTestController.java +++ b/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/java/io/opentelemetry/spring/smoketest/OtelReactiveSpringStarterSmokeTestController.java @@ -23,6 +23,6 @@ public OtelReactiveSpringStarterSmokeTestController(PlayerRepository playerRepos public Mono webflux() { return playerRepository .findById(1) - .map(player -> "Player: " + player.name() + " Age: " + player.age()); + .map(player -> "Player: " + player.getName() + " Age: " + player.getAge()); } } diff --git a/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/java/io/opentelemetry/spring/smoketest/Player.java b/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/java/io/opentelemetry/spring/smoketest/Player.java index fef7611b931b..7d14fcf5537b 100644 --- a/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/java/io/opentelemetry/spring/smoketest/Player.java +++ b/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/java/io/opentelemetry/spring/smoketest/Player.java @@ -7,8 +7,28 @@ import org.springframework.data.annotation.Id; -public record Player(@Id Integer id, String name, Integer age) { - public Player() { - this(null, null, 0); +public class Player { + @Id Integer id; + String name; + Integer age; + + public Player() {} + + public Player(Integer id, String name, Integer age) { + this.id = id; + this.name = name; + this.age = age; + } + + public Integer getId() { + return id; + } + + public String getName() { + return name; + } + + public Integer getAge() { + return age; } } diff --git a/smoke-tests-otel-starter/spring-boot-3-reactive/src/main/resources/application.yaml b/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/resources/application.yaml similarity index 100% rename from smoke-tests-otel-starter/spring-boot-3-reactive/src/main/resources/application.yaml rename to smoke-tests-otel-starter/spring-boot-reactive-common/src/main/resources/application.yaml diff --git a/smoke-tests-otel-starter/spring-boot-3-reactive/src/main/resources/schema.sql b/smoke-tests-otel-starter/spring-boot-reactive-common/src/main/resources/schema.sql similarity index 100% rename from smoke-tests-otel-starter/spring-boot-3-reactive/src/main/resources/schema.sql rename to smoke-tests-otel-starter/spring-boot-reactive-common/src/main/resources/schema.sql diff --git a/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/AbstractSpringStarterSmokeTest.java b/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/AbstractSpringStarterSmokeTest.java index c9f823099320..378d402e785b 100644 --- a/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/AbstractSpringStarterSmokeTest.java +++ b/smoke-tests-otel-starter/spring-smoke-testing/src/main/java/io/opentelemetry/spring/smoketest/AbstractSpringStarterSmokeTest.java @@ -31,17 +31,16 @@ void setUpTesting() { void checkSpringLogs(CapturedOutput output) { // warnings are emitted if the auto-configuration have non-fatal problems assertThat(output) + // not a warning in Spring Boot 2 + .doesNotContain("is not eligible for getting processed by all BeanPostProcessors") // only look for WARN and ERROR log level, e.g. [Test worker] WARN .doesNotContain("] WARN") - .doesNotContain("] ERROR") .satisfies( s -> { if (!s.toString() .contains( "Unable to load io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider")) { - assertThat(s).doesNotContain("] ERROR") - // not a warning in Spring Boot 2 - .doesNotContain("is not eligible for getting processed by all BeanPostProcessors"); + assertThat(s).doesNotContain("] ERROR"); } }); }