Skip to content

Commit 2071473

Browse files
committed
add r2dbc test
1 parent d1186f9 commit 2071473

File tree

6 files changed

+81
-16
lines changed

6 files changed

+81
-16
lines changed

smoke-tests-otel-starter/spring-boot-3-reactive/src/main/java/io/opentelemetry/spring/smoketest/OtelReactiveSpringStarterSmokeTestController.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,16 @@
1313
public class OtelReactiveSpringStarterSmokeTestController {
1414

1515
public static final String WEBFLUX = "/webflux";
16+
private final PlayerRepository playerRepository;
17+
18+
public OtelReactiveSpringStarterSmokeTestController(PlayerRepository playerRepository) {
19+
this.playerRepository = playerRepository;
20+
}
1621

1722
@GetMapping(WEBFLUX)
1823
public Mono<String> getStock() {
19-
return Mono.just("pong");
24+
return playerRepository
25+
.findById(1)
26+
.map(player -> "Player: " + player.getName() + " Age: " + player.getAge());
2027
}
2128
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.spring.smoketest;
7+
8+
import org.springframework.data.annotation.Id;
9+
10+
public class Player {
11+
@Id Integer id;
12+
String name;
13+
Integer age;
14+
15+
public Player() {}
16+
17+
public Player(Integer id, String name, Integer age) {
18+
this.id = id;
19+
this.name = name;
20+
this.age = age;
21+
}
22+
23+
public Integer getId() {
24+
return id;
25+
}
26+
27+
public String getName() {
28+
return name;
29+
}
30+
31+
public Integer getAge() {
32+
return age;
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.spring.smoketest;
7+
8+
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
9+
10+
public interface PlayerRepository extends ReactiveCrudRepository<Player, Integer> {}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
spring:
22
r2dbc:
33
url: r2dbc:h2:mem:///testdb
4+
jpa:
5+
hibernate:
6+
ddl-auto: create
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE TABLE IF NOT EXISTS player(id INT NOT NULL AUTO_INCREMENT, name VARCHAR(255), age INT, PRIMARY KEY (id));

smoke-tests-otel-starter/spring-boot-3-reactive/src/test/java/io/opentelemetry/smoketest/OtelReactiveSpringStarterSmokeTest.java

+25-15
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension;
1313
import io.opentelemetry.semconv.HttpAttributes;
1414
import io.opentelemetry.semconv.UrlAttributes;
15+
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes;
1516
import io.opentelemetry.spring.smoketest.OtelReactiveSpringStarterSmokeTestApplication;
1617
import io.opentelemetry.spring.smoketest.OtelReactiveSpringStarterSmokeTestController;
1718
import org.junit.jupiter.api.AfterEach;
@@ -64,7 +65,7 @@ void tearDown(CapturedOutput output) {
6465
}
6566

6667
@Test
67-
void webflux() {
68+
void webClientAndWebFluxAndR2dbc() {
6869
webClient
6970
.get()
7071
.uri(OtelReactiveSpringStarterSmokeTestController.WEBFLUX)
@@ -73,19 +74,28 @@ void webflux() {
7374
.blockLast();
7475

7576
testing.waitAndAssertTraces(
76-
trace ->
77-
trace.hasSpansSatisfyingExactly(
78-
clientSpan ->
79-
clientSpan
80-
.hasKind(SpanKind.CLIENT)
81-
.hasAttributesSatisfying(
82-
a ->
83-
assertThat(a.get(UrlAttributes.URL_FULL)).endsWith("/webflux")),
84-
serverSpan ->
85-
serverSpan
86-
.hasKind(SpanKind.SERVER)
87-
.hasAttribute(HttpAttributes.HTTP_REQUEST_METHOD, "GET")
88-
.hasAttribute(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)
89-
.hasAttribute(HttpAttributes.HTTP_ROUTE, "/webflux")));
77+
trace ->
78+
trace.hasSpansSatisfyingExactly(
79+
span ->
80+
span.hasKind(SpanKind.CLIENT)
81+
.hasName("GET")
82+
.hasAttributesSatisfying(
83+
a -> assertThat(a.get(UrlAttributes.URL_FULL)).endsWith("/webflux")),
84+
span ->
85+
span.hasKind(SpanKind.SERVER)
86+
.hasName("GET /webflux")
87+
.hasAttribute(HttpAttributes.HTTP_REQUEST_METHOD, "GET")
88+
.hasAttribute(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 200L)
89+
.hasAttribute(HttpAttributes.HTTP_ROUTE, "/webflux"),
90+
span ->
91+
span.hasKind(SpanKind.CLIENT)
92+
.hasName("SELECT testdb.PLAYER")
93+
.hasAttribute(DbIncubatingAttributes.DB_NAME, "testdb")
94+
.hasAttribute(DbIncubatingAttributes.DB_SQL_TABLE, "PLAYER")
95+
.hasAttribute(DbIncubatingAttributes.DB_OPERATION, "SELECT")
96+
.hasAttribute(
97+
DbIncubatingAttributes.DB_STATEMENT,
98+
"SELECT PLAYER.* FROM PLAYER WHERE PLAYER.ID = $? LIMIT ?")
99+
.hasAttribute(DbIncubatingAttributes.DB_SYSTEM, "h2")));
90100
}
91101
}

0 commit comments

Comments
 (0)