Skip to content

Commit

Permalink
fix r2dbc test
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitlinger committed May 10, 2024
1 parent 4cc2b90 commit 5ae374e
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public OtelReactiveSpringStarterSmokeTestController(PlayerRepository playerRepos
public Mono<String> webflux() {
return playerRepository
.findById(1)
.map(player -> "Player: " + player.name() + " Age: " + player.age());
.map(player -> "Player: " + player.getName() + " Age: " + player.getAge());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
});
}
Expand Down

0 comments on commit 5ae374e

Please sign in to comment.