Skip to content

Commit a8e5e24

Browse files
committed
remove commented out code, fix latest dep test
1 parent 61aacbb commit a8e5e24

File tree

3 files changed

+24
-218
lines changed

3 files changed

+24
-218
lines changed

instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v5_3/Elasticsearch53NodeClientTest.java

Lines changed: 0 additions & 211 deletions
Original file line numberDiff line numberDiff line change
@@ -89,215 +89,4 @@ static void cleanUp() throws Exception {
8989
public Client client() {
9090
return client;
9191
}
92-
93-
/*
94-
private Stream<Arguments> healthArguments() {
95-
return Stream.of(
96-
Arguments.of(
97-
named(
98-
"sync",
99-
(ThrowingSupplier<ClusterHealthStatus, Exception>) this::clusterHealthSync)),
100-
Arguments.of(
101-
named(
102-
"async",
103-
(ThrowingSupplier<ClusterHealthStatus, Exception>) this::clusterHealthAsync)));
104-
}
105-
106-
@ParameterizedTest
107-
@MethodSource("healthArguments")
108-
void elasticsearchStatus(ThrowingSupplier<ClusterHealthStatus, Exception> supplier)
109-
throws Exception {
110-
ClusterHealthStatus clusterHealthStatus = testing.runWithSpan("parent", supplier);
111-
112-
assertThat(clusterHealthStatus.name()).isEqualTo("GREEN");
113-
114-
testing.waitAndAssertTraces(
115-
trace ->
116-
trace.hasSpansSatisfyingExactly(
117-
span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(),
118-
span ->
119-
span.hasName("ClusterHealthAction")
120-
.hasKind(SpanKind.CLIENT)
121-
.hasParent(trace.getSpan(0))
122-
.hasAttributesSatisfyingExactly(
123-
equalTo(
124-
DbIncubatingAttributes.DB_SYSTEM,
125-
DbIncubatingAttributes.DbSystemValues.ELASTICSEARCH),
126-
equalTo(DbIncubatingAttributes.DB_OPERATION, "ClusterHealthAction"),
127-
equalTo(ELASTICSEARCH_ACTION, "ClusterHealthAction"),
128-
equalTo(ELASTICSEARCH_REQUEST, "ClusterHealthRequest")),
129-
span ->
130-
span.hasName("callback")
131-
.hasKind(SpanKind.INTERNAL)
132-
.hasParent(trace.getSpan(0))));
133-
}
134-
135-
private Stream<Arguments> errorArguments() {
136-
return Stream.of(
137-
Arguments.of(
138-
named("sync", (Runnable) () -> prepareGetSync("invalid-index", "test-type", "1"))),
139-
Arguments.of(
140-
named("async", (Runnable) () -> prepareGetAsync("invalid-index", "test-type", "1"))));
141-
}
142-
143-
@ParameterizedTest
144-
@MethodSource("errorArguments")
145-
void elasticsearchError(Runnable action) {
146-
assertThatThrownBy(() -> testing.runWithSpan("parent", action::run))
147-
.isInstanceOf(IndexNotFoundException.class)
148-
.hasMessage("no such index");
149-
150-
IndexNotFoundException expectedException = new IndexNotFoundException("no such index");
151-
testing.waitAndAssertTraces(
152-
trace ->
153-
trace.hasSpansSatisfyingExactly(
154-
span ->
155-
span.hasName("parent")
156-
.hasKind(SpanKind.INTERNAL)
157-
.hasNoParent()
158-
.hasStatus(StatusData.error())
159-
.hasException(expectedException),
160-
span ->
161-
span.hasName("GetAction")
162-
.hasKind(SpanKind.CLIENT)
163-
.hasParent(trace.getSpan(0))
164-
.hasStatus(StatusData.error())
165-
.hasException(expectedException)
166-
.hasAttributesSatisfyingExactly(
167-
equalTo(
168-
DbIncubatingAttributes.DB_SYSTEM,
169-
DbIncubatingAttributes.DbSystemValues.ELASTICSEARCH),
170-
equalTo(DbIncubatingAttributes.DB_OPERATION, "GetAction"),
171-
equalTo(ELASTICSEARCH_ACTION, "GetAction"),
172-
equalTo(ELASTICSEARCH_REQUEST, "GetRequest"),
173-
equalTo(ELASTICSEARCH_REQUEST_INDICES, "invalid-index")),
174-
span ->
175-
span.hasName("callback")
176-
.hasKind(SpanKind.INTERNAL)
177-
.hasParent(trace.getSpan(0))));
178-
}
179-
180-
@Test
181-
void elasticsearchGet() {
182-
String indexName = "test-index";
183-
String indexType = "test-type";
184-
String id = "1";
185-
186-
CreateIndexResponse indexResult = client.admin().indices().prepareCreate(indexName).get();
187-
assertThat(indexResult.isAcknowledged()).isTrue();
188-
189-
client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(TIMEOUT);
190-
GetResponse emptyResult = client.prepareGet(indexName, indexType, id).get();
191-
assertThat(emptyResult.isExists()).isFalse();
192-
assertThat(emptyResult.getId()).isEqualTo(id);
193-
assertThat(emptyResult.getType()).isEqualTo(indexType);
194-
assertThat(emptyResult.getIndex()).isEqualTo(indexName);
195-
196-
IndexResponse createResult =
197-
client.prepareIndex(indexName, indexType, id).setSource(Collections.emptyMap()).get();
198-
assertThat(createResult.getId()).isEqualTo(id);
199-
assertThat(createResult.getType()).isEqualTo(indexType);
200-
assertThat(createResult.getIndex()).isEqualTo(indexName);
201-
assertThat(createResult.status().getStatus()).isEqualTo(201);
202-
cleanup.deferCleanup(() -> client.admin().indices().prepareDelete(indexName).get());
203-
204-
GetResponse result = client.prepareGet(indexName, indexType, id).get();
205-
assertThat(result.isExists()).isTrue();
206-
assertThat(result.getId()).isEqualTo(id);
207-
assertThat(result.getType()).isEqualTo(indexType);
208-
assertThat(result.getIndex()).isEqualTo(indexName);
209-
210-
testing.waitAndAssertTraces(
211-
trace ->
212-
trace.hasSpansSatisfyingExactly(
213-
span ->
214-
span.hasName("CreateIndexAction")
215-
.hasKind(SpanKind.CLIENT)
216-
.hasNoParent()
217-
.hasAttributesSatisfyingExactly(
218-
equalTo(
219-
DbIncubatingAttributes.DB_SYSTEM,
220-
DbIncubatingAttributes.DbSystemValues.ELASTICSEARCH),
221-
equalTo(DbIncubatingAttributes.DB_OPERATION, "CreateIndexAction"),
222-
equalTo(ELASTICSEARCH_ACTION, "CreateIndexAction"),
223-
equalTo(ELASTICSEARCH_REQUEST, "CreateIndexRequest"),
224-
equalTo(ELASTICSEARCH_REQUEST_INDICES, indexName))),
225-
trace ->
226-
trace.hasSpansSatisfyingExactly(
227-
span ->
228-
span.hasName("ClusterHealthAction")
229-
.hasKind(SpanKind.CLIENT)
230-
.hasNoParent()
231-
.hasAttributesSatisfyingExactly(
232-
equalTo(
233-
DbIncubatingAttributes.DB_SYSTEM,
234-
DbIncubatingAttributes.DbSystemValues.ELASTICSEARCH),
235-
equalTo(DbIncubatingAttributes.DB_OPERATION, "ClusterHealthAction"),
236-
equalTo(ELASTICSEARCH_ACTION, "ClusterHealthAction"),
237-
equalTo(ELASTICSEARCH_REQUEST, "ClusterHealthRequest"))),
238-
trace ->
239-
trace.hasSpansSatisfyingExactly(
240-
span ->
241-
span.hasName("GetAction")
242-
.hasKind(SpanKind.CLIENT)
243-
.hasNoParent()
244-
.hasAttributesSatisfyingExactly(
245-
equalTo(
246-
DbIncubatingAttributes.DB_SYSTEM,
247-
DbIncubatingAttributes.DbSystemValues.ELASTICSEARCH),
248-
equalTo(DbIncubatingAttributes.DB_OPERATION, "GetAction"),
249-
equalTo(ELASTICSEARCH_ACTION, "GetAction"),
250-
equalTo(ELASTICSEARCH_REQUEST, "GetRequest"),
251-
equalTo(ELASTICSEARCH_REQUEST_INDICES, indexName),
252-
equalTo(ELASTICSEARCH_TYPE, indexType),
253-
equalTo(ELASTICSEARCH_ID, id),
254-
equalTo(ELASTICSEARCH_VERSION, -1))),
255-
trace ->
256-
trace.hasSpansSatisfyingExactly(
257-
span ->
258-
span.hasName("IndexAction")
259-
.hasKind(SpanKind.CLIENT)
260-
.hasNoParent()
261-
.hasAttributesSatisfyingExactly(
262-
equalTo(
263-
DbIncubatingAttributes.DB_SYSTEM,
264-
DbIncubatingAttributes.DbSystemValues.ELASTICSEARCH),
265-
equalTo(DbIncubatingAttributes.DB_OPERATION, "IndexAction"),
266-
equalTo(ELASTICSEARCH_ACTION, "IndexAction"),
267-
equalTo(ELASTICSEARCH_REQUEST, "IndexRequest"),
268-
equalTo(ELASTICSEARCH_REQUEST_INDICES, indexName),
269-
equalTo(
270-
AttributeKey.stringKey("elasticsearch.request.write.type"),
271-
indexType),
272-
equalTo(
273-
AttributeKey.longKey("elasticsearch.request.write.version"), -3),
274-
equalTo(AttributeKey.longKey("elasticsearch.response.status"), 201),
275-
equalTo(
276-
AttributeKey.longKey("elasticsearch.shard.replication.total"), 2),
277-
equalTo(
278-
AttributeKey.longKey("elasticsearch.shard.replication.successful"),
279-
1),
280-
equalTo(
281-
AttributeKey.longKey("elasticsearch.shard.replication.failed"),
282-
0))),
283-
trace ->
284-
trace.hasSpansSatisfyingExactly(
285-
span ->
286-
span.hasName("GetAction")
287-
.hasKind(SpanKind.CLIENT)
288-
.hasNoParent()
289-
.hasAttributesSatisfyingExactly(
290-
equalTo(
291-
DbIncubatingAttributes.DB_SYSTEM,
292-
DbIncubatingAttributes.DbSystemValues.ELASTICSEARCH),
293-
equalTo(DbIncubatingAttributes.DB_OPERATION, "GetAction"),
294-
equalTo(ELASTICSEARCH_ACTION, "GetAction"),
295-
equalTo(ELASTICSEARCH_REQUEST, "GetRequest"),
296-
equalTo(ELASTICSEARCH_REQUEST_INDICES, indexName),
297-
equalTo(ELASTICSEARCH_TYPE, indexType),
298-
equalTo(ELASTICSEARCH_ID, id),
299-
equalTo(ELASTICSEARCH_VERSION, 1))));
300-
}
301-
302-
*/
30392
}

instrumentation/elasticsearch/elasticsearch-transport-6.0/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/v6_0/AbstractElasticsearch6NodeClientTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,17 @@ void cleanUp() throws Exception {
8585
protected Client client() {
8686
return client;
8787
}
88+
89+
@Override
90+
protected void waitYellowStatus() {
91+
// although the body of this method looks exactly the same as the super class method we need to
92+
// have this here because return type of the execute() method has changed
93+
client()
94+
.admin()
95+
.cluster()
96+
.prepareHealth()
97+
.setWaitForYellowStatus()
98+
.execute()
99+
.actionGet(TIMEOUT);
100+
}
88101
}

instrumentation/elasticsearch/elasticsearch-transport-common/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/transport/AbstractElasticsearchNodeClientTest.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.elasticsearch.action.index.IndexResponse;
2727
import org.elasticsearch.client.Client;
2828
import org.elasticsearch.cluster.health.ClusterHealthStatus;
29-
import org.elasticsearch.common.unit.TimeValue;
3029
import org.elasticsearch.index.IndexNotFoundException;
3130
import org.junit.jupiter.api.Test;
3231
import org.junit.jupiter.api.TestInstance;
@@ -128,6 +127,16 @@ void elasticsearchError(Runnable action) {
128127
.hasParent(trace.getSpan(0))));
129128
}
130129

130+
protected void waitYellowStatus() {
131+
client()
132+
.admin()
133+
.cluster()
134+
.prepareHealth()
135+
.setWaitForYellowStatus()
136+
.execute()
137+
.actionGet(TIMEOUT);
138+
}
139+
131140
@Test
132141
void elasticsearchGet() {
133142
String indexName = "test-index";
@@ -138,12 +147,7 @@ void elasticsearchGet() {
138147
CreateIndexResponse indexResult = client.admin().indices().prepareCreate(indexName).get();
139148
assertThat(indexResult.isAcknowledged()).isTrue();
140149

141-
client
142-
.admin()
143-
.cluster()
144-
.prepareHealth()
145-
.setWaitForYellowStatus()
146-
.get(TimeValue.timeValueMillis(TIMEOUT));
150+
waitYellowStatus();
147151
GetResponse emptyResult = client.prepareGet(indexName, indexType, id).get();
148152
assertThat(emptyResult.isExists()).isFalse();
149153
assertThat(emptyResult.getId()).isEqualTo(id);

0 commit comments

Comments
 (0)