|
14 | 14 | import static io.opentelemetry.semconv.ServerAttributes.SERVER_PORT;
|
15 | 15 | import static io.opentelemetry.semconv.UrlAttributes.URL_FULL;
|
16 | 16 | import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM;
|
| 17 | +import static org.assertj.core.api.Assertions.assertThat; |
17 | 18 |
|
18 | 19 | import com.fasterxml.jackson.databind.ObjectMapper;
|
19 | 20 | import io.opentelemetry.api.trace.SpanKind;
|
|
27 | 28 | import org.elasticsearch.client.ResponseListener;
|
28 | 29 | import org.elasticsearch.client.RestClient;
|
29 | 30 | import org.junit.jupiter.api.AfterAll;
|
30 |
| -import org.junit.jupiter.api.Assertions; |
31 | 31 | import org.junit.jupiter.api.BeforeAll;
|
32 | 32 | import org.junit.jupiter.api.Test;
|
33 | 33 | import org.junit.jupiter.api.extension.RegisterExtension;
|
@@ -89,36 +89,32 @@ void elasticsearchStatus() throws IOException {
|
89 | 89 | Map result = objectMapper.readValue(response.getEntity().getContent(), Map.class);
|
90 | 90 |
|
91 | 91 | // usually this test reports green status, but sometimes it is yellow
|
92 |
| - Assertions.assertTrue( |
93 |
| - "green".equals(result.get("status")) || "yellow".equals(result.get("status"))); |
| 92 | + assertThat(result.get("status")).isIn("green", "yellow"); |
94 | 93 |
|
95 | 94 | testing.waitAndAssertTraces(
|
96 |
| - trace -> { |
97 |
| - trace.hasSpansSatisfyingExactly( |
98 |
| - span -> { |
99 |
| - span.hasName("GET") |
100 |
| - .hasKind(SpanKind.CLIENT) |
101 |
| - .hasNoParent() |
102 |
| - .hasAttributesSatisfyingExactly( |
103 |
| - equalTo(maybeStable(DB_SYSTEM), "elasticsearch"), |
104 |
| - equalTo(HTTP_REQUEST_METHOD, "GET"), |
105 |
| - equalTo(SERVER_ADDRESS, httpHost.getHostName()), |
106 |
| - equalTo(SERVER_PORT, httpHost.getPort()), |
107 |
| - equalTo(URL_FULL, httpHost.toURI() + "/_cluster/health")); |
108 |
| - }, |
109 |
| - span -> { |
110 |
| - span.hasName("GET") |
111 |
| - .hasKind(SpanKind.CLIENT) |
112 |
| - .hasParent(trace.getSpan(0)) |
113 |
| - .hasAttributesSatisfyingExactly( |
114 |
| - equalTo(SERVER_ADDRESS, httpHost.getHostName()), |
115 |
| - equalTo(SERVER_PORT, httpHost.getPort()), |
116 |
| - equalTo(HTTP_REQUEST_METHOD, "GET"), |
117 |
| - equalTo(NETWORK_PROTOCOL_VERSION, "1.1"), |
118 |
| - equalTo(URL_FULL, httpHost.toURI() + "/_cluster/health"), |
119 |
| - equalTo(HTTP_RESPONSE_STATUS_CODE, 200)); |
120 |
| - }); |
121 |
| - }); |
| 95 | + trace -> |
| 96 | + trace.hasSpansSatisfyingExactly( |
| 97 | + span -> |
| 98 | + span.hasName("GET") |
| 99 | + .hasKind(SpanKind.CLIENT) |
| 100 | + .hasNoParent() |
| 101 | + .hasAttributesSatisfyingExactly( |
| 102 | + equalTo(maybeStable(DB_SYSTEM), "elasticsearch"), |
| 103 | + equalTo(HTTP_REQUEST_METHOD, "GET"), |
| 104 | + equalTo(SERVER_ADDRESS, httpHost.getHostName()), |
| 105 | + equalTo(SERVER_PORT, httpHost.getPort()), |
| 106 | + equalTo(URL_FULL, httpHost.toURI() + "/_cluster/health")), |
| 107 | + span -> |
| 108 | + span.hasName("GET") |
| 109 | + .hasKind(SpanKind.CLIENT) |
| 110 | + .hasParent(trace.getSpan(0)) |
| 111 | + .hasAttributesSatisfyingExactly( |
| 112 | + equalTo(SERVER_ADDRESS, httpHost.getHostName()), |
| 113 | + equalTo(SERVER_PORT, httpHost.getPort()), |
| 114 | + equalTo(HTTP_REQUEST_METHOD, "GET"), |
| 115 | + equalTo(NETWORK_PROTOCOL_VERSION, "1.1"), |
| 116 | + equalTo(URL_FULL, httpHost.toURI() + "/_cluster/health"), |
| 117 | + equalTo(HTTP_RESPONSE_STATUS_CODE, 200)))); |
122 | 118 | }
|
123 | 119 |
|
124 | 120 | @Test
|
@@ -151,52 +147,44 @@ public void onFailure(Exception e) {
|
151 | 147 | };
|
152 | 148 |
|
153 | 149 | testing.runWithSpan(
|
154 |
| - "parent", |
155 |
| - () -> { |
156 |
| - client.performRequestAsync("GET", "_cluster/health", responseListener); |
157 |
| - }); |
| 150 | + "parent", () -> client.performRequestAsync("GET", "_cluster/health", responseListener)); |
158 | 151 | countDownLatch.await();
|
159 | 152 | if (exception[0] != null) {
|
160 | 153 | throw exception[0];
|
161 | 154 | }
|
162 | 155 | Map result = objectMapper.readValue(requestResponse[0].getEntity().getContent(), Map.class);
|
163 | 156 |
|
164 | 157 | // usually this test reports green status, but sometimes it is yellow
|
165 |
| - Assertions.assertTrue( |
166 |
| - "green".equals(result.get("status")) || "yellow".equals(result.get("status"))); |
| 158 | + assertThat(result.get("status")).isIn("green", "yellow"); |
167 | 159 |
|
168 | 160 | testing.waitAndAssertTraces(
|
169 |
| - trace -> { |
170 |
| - trace.hasSpansSatisfyingExactly( |
171 |
| - span -> { |
172 |
| - span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(); |
173 |
| - }, |
174 |
| - span -> { |
175 |
| - span.hasName("GET") |
176 |
| - .hasKind(SpanKind.CLIENT) |
177 |
| - .hasParent(trace.getSpan(0)) |
178 |
| - .hasAttributesSatisfyingExactly( |
179 |
| - equalTo(maybeStable(DB_SYSTEM), "elasticsearch"), |
180 |
| - equalTo(HTTP_REQUEST_METHOD, "GET"), |
181 |
| - equalTo(SERVER_ADDRESS, httpHost.getHostName()), |
182 |
| - equalTo(SERVER_PORT, httpHost.getPort()), |
183 |
| - equalTo(URL_FULL, httpHost.toURI() + "/_cluster/health")); |
184 |
| - }, |
185 |
| - span -> { |
186 |
| - span.hasName("GET") |
187 |
| - .hasKind(SpanKind.CLIENT) |
188 |
| - .hasParent(trace.getSpan(1)) |
189 |
| - .hasAttributesSatisfyingExactly( |
190 |
| - equalTo(SERVER_ADDRESS, httpHost.getHostName()), |
191 |
| - equalTo(SERVER_PORT, httpHost.getPort()), |
192 |
| - equalTo(HTTP_REQUEST_METHOD, "GET"), |
193 |
| - equalTo(NETWORK_PROTOCOL_VERSION, "1.1"), |
194 |
| - equalTo(URL_FULL, httpHost.toURI() + "/_cluster/health"), |
195 |
| - equalTo(HTTP_RESPONSE_STATUS_CODE, 200)); |
196 |
| - }, |
197 |
| - span -> { |
198 |
| - span.hasName("callback").hasKind(SpanKind.INTERNAL).hasParent(trace.getSpan(0)); |
199 |
| - }); |
200 |
| - }); |
| 161 | + trace -> |
| 162 | + trace.hasSpansSatisfyingExactly( |
| 163 | + span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), |
| 164 | + span -> |
| 165 | + span.hasName("GET") |
| 166 | + .hasKind(SpanKind.CLIENT) |
| 167 | + .hasParent(trace.getSpan(0)) |
| 168 | + .hasAttributesSatisfyingExactly( |
| 169 | + equalTo(maybeStable(DB_SYSTEM), "elasticsearch"), |
| 170 | + equalTo(HTTP_REQUEST_METHOD, "GET"), |
| 171 | + equalTo(SERVER_ADDRESS, httpHost.getHostName()), |
| 172 | + equalTo(SERVER_PORT, httpHost.getPort()), |
| 173 | + equalTo(URL_FULL, httpHost.toURI() + "/_cluster/health")), |
| 174 | + span -> |
| 175 | + span.hasName("GET") |
| 176 | + .hasKind(SpanKind.CLIENT) |
| 177 | + .hasParent(trace.getSpan(1)) |
| 178 | + .hasAttributesSatisfyingExactly( |
| 179 | + equalTo(SERVER_ADDRESS, httpHost.getHostName()), |
| 180 | + equalTo(SERVER_PORT, httpHost.getPort()), |
| 181 | + equalTo(HTTP_REQUEST_METHOD, "GET"), |
| 182 | + equalTo(NETWORK_PROTOCOL_VERSION, "1.1"), |
| 183 | + equalTo(URL_FULL, httpHost.toURI() + "/_cluster/health"), |
| 184 | + equalTo(HTTP_RESPONSE_STATUS_CODE, 200)), |
| 185 | + span -> |
| 186 | + span.hasName("callback") |
| 187 | + .hasKind(SpanKind.INTERNAL) |
| 188 | + .hasParent(trace.getSpan(0)))); |
201 | 189 | }
|
202 | 190 | }
|
0 commit comments