Skip to content

Commit 8fec214

Browse files
authored
Fix UCP typos and cleanup ES tests (#14029)
1 parent a6ab2c6 commit 8fec214

File tree

8 files changed

+143
-159
lines changed

8 files changed

+143
-159
lines changed

instrumentation/elasticsearch/elasticsearch-api-client-7.16/javaagent-unit-tests/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchEndpointMapTest.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
package io.opentelemetry.javaagent.instrumentation.elasticsearch.rest;
77

8-
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.assertj.core.api.Assertions.assertThat;
99

1010
import io.opentelemetry.instrumentation.elasticsearch.rest.common.v5_0.internal.ElasticsearchEndpointDefinition;
1111
import io.opentelemetry.javaagent.instrumentation.elasticsearch.apiclient.ElasticsearchEndpointMap;
@@ -20,7 +20,7 @@
2020
import java.util.stream.Collectors;
2121
import org.junit.jupiter.api.Test;
2222

23-
public class ElasticsearchEndpointMapTest {
23+
class ElasticsearchEndpointMapTest {
2424

2525
private static final Set<String> SEARCH_ENDPOINTS =
2626
new HashSet<>(
@@ -57,16 +57,17 @@ private static List<String> getPathParts(String route) {
5757
}
5858

5959
@Test
60-
public void testIsSearchEndpoint() {
60+
void testIsSearchEndpoint() {
6161
for (ElasticsearchEndpointDefinition esEndpointDefinition :
6262
ElasticsearchEndpointMap.getAllEndpoints()) {
6363
String endpointId = esEndpointDefinition.getEndpointName();
64-
assertEquals(SEARCH_ENDPOINTS.contains(endpointId), esEndpointDefinition.isSearchEndpoint());
64+
assertThat(SEARCH_ENDPOINTS.contains(endpointId))
65+
.isEqualTo(esEndpointDefinition.isSearchEndpoint());
6566
}
6667
}
6768

6869
@Test
69-
public void testProcessPathParts() {
70+
void testProcessPathParts() {
7071
for (ElasticsearchEndpointDefinition esEndpointDefinition :
7172
ElasticsearchEndpointMap.getAllEndpoints()) {
7273
for (String route :
@@ -81,44 +82,45 @@ public void testProcessPathParts() {
8182
Map<String, String> expectedMap = new HashMap<>();
8283
pathParts.forEach(part -> expectedMap.put(part, part));
8384

84-
assertEquals(expectedMap, observedParams);
85+
assertThat(expectedMap).isEqualTo(observedParams);
8586
}
8687
}
8788
}
8889

8990
@Test
90-
public void testSearchEndpoint() {
91+
void testSearchEndpoint() {
9192
ElasticsearchEndpointDefinition esEndpoint = ElasticsearchEndpointMap.get("search");
9293
Map<String, String> observedParams = new HashMap<>();
9394
esEndpoint.processPathParts(
9495
"/test-index-1,test-index-2/_search", (k, v) -> observedParams.put(k, v));
9596

96-
assertEquals("test-index-1,test-index-2", observedParams.get("index"));
97+
assertThat(observedParams.get("index")).isEqualTo("test-index-1,test-index-2");
9798
}
9899

99100
@Test
100-
public void testBuildRegexPattern() {
101+
void testBuildRegexPattern() {
101102
Pattern pattern =
102103
ElasticsearchEndpointDefinition.EndpointPattern.buildRegexPattern(
103104
"/_nodes/{node_id}/shutdown");
104-
assertEquals("^/_nodes/(?<node0id>[^/]+)/shutdown$", pattern.pattern());
105+
assertThat(pattern.pattern()).isEqualTo("^/_nodes/(?<node0id>[^/]+)/shutdown$");
105106

106107
pattern =
107108
ElasticsearchEndpointDefinition.EndpointPattern.buildRegexPattern(
108109
"/_snapshot/{repository}/{snapshot}/_mount");
109-
assertEquals("^/_snapshot/(?<repository>[^/]+)/(?<snapshot>[^/]+)/_mount$", pattern.pattern());
110+
assertThat(pattern.pattern())
111+
.isEqualTo("^/_snapshot/(?<repository>[^/]+)/(?<snapshot>[^/]+)/_mount$");
110112

111113
pattern =
112114
ElasticsearchEndpointDefinition.EndpointPattern.buildRegexPattern(
113115
"/_security/profile/_suggest");
114-
assertEquals("^/_security/profile/_suggest$", pattern.pattern());
116+
assertThat(pattern.pattern()).isEqualTo("^/_security/profile/_suggest$");
115117

116118
pattern =
117119
ElasticsearchEndpointDefinition.EndpointPattern.buildRegexPattern(
118120
"/_application/search_application/{name}");
119-
assertEquals("^/_application/search_application/(?<name>[^/]+)$", pattern.pattern());
121+
assertThat(pattern.pattern()).isEqualTo("^/_application/search_application/(?<name>[^/]+)$");
120122

121123
pattern = ElasticsearchEndpointDefinition.EndpointPattern.buildRegexPattern("/");
122-
assertEquals("^/$", pattern.pattern());
124+
assertThat(pattern.pattern()).isEqualTo("^/$");
123125
}
124126
}

instrumentation/elasticsearch/elasticsearch-api-client-7.16/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/apiclient/ElasticsearchClientTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_ELASTICSEARCH_PATH_PARTS;
1818
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_OPERATION;
1919
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM;
20+
import static org.assertj.core.api.Assertions.assertThat;
2021

2122
import co.elastic.clients.elasticsearch.ElasticsearchAsyncClient;
2223
import co.elastic.clients.elasticsearch.ElasticsearchClient;
@@ -33,7 +34,6 @@
3334
import org.apache.http.HttpHost;
3435
import org.elasticsearch.client.RestClient;
3536
import org.junit.jupiter.api.AfterAll;
36-
import org.junit.jupiter.api.Assertions;
3737
import org.junit.jupiter.api.BeforeAll;
3838
import org.junit.jupiter.api.Test;
3939
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -82,9 +82,9 @@ static void cleanUp() {
8282
}
8383

8484
@Test
85-
public void elasticsearchStatus() throws IOException {
85+
void elasticsearchStatus() throws IOException {
8686
InfoResponse response = client.info();
87-
Assertions.assertEquals(response.version().number(), "7.17.2");
87+
assertThat(response.version().number()).isEqualTo("7.17.2");
8888

8989
testing.waitAndAssertTraces(
9090
trace ->
@@ -114,7 +114,7 @@ public void elasticsearchStatus() throws IOException {
114114
}
115115

116116
@Test
117-
public void elasticsearchIndex() throws IOException {
117+
void elasticsearchIndex() throws IOException {
118118
client.index(
119119
r ->
120120
r.id("test-id")
@@ -157,7 +157,7 @@ public void elasticsearchIndex() throws IOException {
157157
}
158158

159159
@Test
160-
public void elasticsearchStatusAsync() throws Exception {
160+
void elasticsearchStatusAsync() throws Exception {
161161
CountDownLatch countDownLatch = new CountDownLatch(1);
162162
AsyncRequest request = new AsyncRequest();
163163

@@ -177,7 +177,7 @@ public void elasticsearchStatusAsync() throws Exception {
177177
//noinspection ResultOfMethodCallIgnored
178178
countDownLatch.await(10, TimeUnit.SECONDS);
179179

180-
Assertions.assertEquals(request.getResponse().version().number(), "7.17.2");
180+
assertThat(request.getResponse().version().number()).isEqualTo("7.17.2");
181181

182182
testing.waitAndAssertTraces(
183183
trace ->

instrumentation/elasticsearch/elasticsearch-rest-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v5_0/ElasticsearchRest5Test.java

Lines changed: 55 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import static io.opentelemetry.semconv.ServerAttributes.SERVER_PORT;
1515
import static io.opentelemetry.semconv.UrlAttributes.URL_FULL;
1616
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM;
17+
import static org.assertj.core.api.Assertions.assertThat;
1718

1819
import com.fasterxml.jackson.databind.ObjectMapper;
1920
import io.opentelemetry.api.trace.SpanKind;
@@ -27,7 +28,6 @@
2728
import org.elasticsearch.client.ResponseListener;
2829
import org.elasticsearch.client.RestClient;
2930
import org.junit.jupiter.api.AfterAll;
30-
import org.junit.jupiter.api.Assertions;
3131
import org.junit.jupiter.api.BeforeAll;
3232
import org.junit.jupiter.api.Test;
3333
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -89,36 +89,32 @@ void elasticsearchStatus() throws IOException {
8989
Map result = objectMapper.readValue(response.getEntity().getContent(), Map.class);
9090

9191
// 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");
9493

9594
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))));
122118
}
123119

124120
@Test
@@ -151,52 +147,44 @@ public void onFailure(Exception e) {
151147
};
152148

153149
testing.runWithSpan(
154-
"parent",
155-
() -> {
156-
client.performRequestAsync("GET", "_cluster/health", responseListener);
157-
});
150+
"parent", () -> client.performRequestAsync("GET", "_cluster/health", responseListener));
158151
countDownLatch.await();
159152
if (exception[0] != null) {
160153
throw exception[0];
161154
}
162155
Map result = objectMapper.readValue(requestResponse[0].getEntity().getContent(), Map.class);
163156

164157
// 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");
167159

168160
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))));
201189
}
202190
}

0 commit comments

Comments
 (0)