-
Notifications
You must be signed in to change notification settings - Fork 875
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert HttpClientTest to JUnit (#3652)
* Migrate HttpClientTest to junit to allow both Java or spock tests. * More * Update * Finish * Cleanup * Better stack * Java 15 * Merge * Fix name * Cleanup * ? extends * Moar
- Loading branch information
Anuraag Agrawal
authored
Jul 27, 2021
1 parent
262feb1
commit 47be4a1
Showing
48 changed files
with
1,962 additions
and
1,110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
...oovy/io/opentelemetry/javaagent/instrumentation/armeria/v1_3/ArmeriaHttpClientTest.groovy
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
...t/java/io/opentelemetry/javaagent/instrumentation/armeria/v1_3/ArmeriaHttpClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.armeria.v1_3; | ||
|
||
import com.linecorp.armeria.client.WebClientBuilder; | ||
import io.opentelemetry.instrumentation.armeria.v1_3.AbstractArmeriaHttpClientTest; | ||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; | ||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
class ArmeriaHttpClientTest extends AbstractArmeriaHttpClientTest { | ||
|
||
@RegisterExtension | ||
static final InstrumentationExtension testing = HttpClientInstrumentationExtension.forAgent(); | ||
|
||
@Override | ||
protected WebClientBuilder configureClient(WebClientBuilder clientBuilder) { | ||
return clientBuilder; | ||
} | ||
} |
34 changes: 0 additions & 34 deletions
34
...rc/test/groovy/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpClientTest.groovy
This file was deleted.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
...ry/src/test/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.armeria.v1_3; | ||
|
||
import com.linecorp.armeria.client.WebClientBuilder; | ||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; | ||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
class ArmeriaHttpClientTest extends AbstractArmeriaHttpClientTest { | ||
|
||
@RegisterExtension | ||
static final InstrumentationExtension testing = HttpClientInstrumentationExtension.forLibrary(); | ||
|
||
@Override | ||
protected WebClientBuilder configureClient(WebClientBuilder clientBuilder) { | ||
return clientBuilder.decorator( | ||
ArmeriaTracing.create(testing.getOpenTelemetry()).newClientDecorator()); | ||
} | ||
|
||
// library instrumentation doesn't have a good way of suppressing nested CLIENT spans yet | ||
@Override | ||
protected boolean testWithClientParent() { | ||
return false; | ||
} | ||
|
||
// Agent users have automatic propagation through executor instrumentation, but library users | ||
// should do manually using Armeria patterns. | ||
@Override | ||
protected boolean testCallbackWithParent() { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected boolean testErrorWithCallback() { | ||
return false; | ||
} | ||
} |
77 changes: 0 additions & 77 deletions
77
...groovy/io/opentelemetry/instrumentation/armeria/v1_3/AbstractArmeriaHttpClientTest.groovy
This file was deleted.
Oops, something went wrong.
96 changes: 96 additions & 0 deletions
96
...ain/java/io/opentelemetry/instrumentation/armeria/v1_3/AbstractArmeriaHttpClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.armeria.v1_3; | ||
|
||
import com.linecorp.armeria.client.ClientFactory; | ||
import com.linecorp.armeria.client.WebClient; | ||
import com.linecorp.armeria.client.WebClientBuilder; | ||
import com.linecorp.armeria.common.HttpMethod; | ||
import com.linecorp.armeria.common.HttpRequest; | ||
import com.linecorp.armeria.common.RequestHeaders; | ||
import com.linecorp.armeria.common.util.Exceptions; | ||
import io.opentelemetry.api.common.AttributeKey; | ||
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; | ||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; | ||
import java.net.URI; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.concurrent.CompletionException; | ||
import org.junit.jupiter.api.BeforeEach; | ||
|
||
public abstract class AbstractArmeriaHttpClientTest extends AbstractHttpClientTest<HttpRequest> { | ||
|
||
protected abstract WebClientBuilder configureClient(WebClientBuilder clientBuilder); | ||
|
||
private WebClient client; | ||
|
||
@BeforeEach | ||
void setupClient() { | ||
client = | ||
configureClient( | ||
WebClient.builder() | ||
.factory(ClientFactory.builder().connectTimeout(connectTimeout()).build())) | ||
.build(); | ||
} | ||
|
||
@Override | ||
protected final HttpRequest buildRequest(String method, URI uri, Map<String, String> headers) { | ||
return HttpRequest.of( | ||
RequestHeaders.builder(HttpMethod.valueOf(method), uri.toString()) | ||
.set(headers.entrySet()) | ||
.build()); | ||
} | ||
|
||
@Override | ||
protected final int sendRequest( | ||
HttpRequest request, String method, URI uri, Map<String, String> headers) { | ||
try { | ||
return client.execute(request).aggregate().join().status().code(); | ||
} catch (CompletionException e) { | ||
return Exceptions.throwUnsafely(e.getCause()); | ||
} | ||
} | ||
|
||
@Override | ||
protected final void sendRequestWithCallback( | ||
HttpRequest request, | ||
String method, | ||
URI uri, | ||
Map<String, String> headers, | ||
RequestResult requestResult) { | ||
client | ||
.execute(request) | ||
.aggregate() | ||
.whenComplete( | ||
(response, throwable) -> | ||
requestResult.complete(() -> response.status().code(), throwable)); | ||
} | ||
|
||
// Not supported yet: https://github.com/line/armeria/issues/2489 | ||
@Override | ||
protected final boolean testRedirects() { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected final boolean testReusedRequest() { | ||
// armeria requests can't be reused | ||
return false; | ||
} | ||
|
||
@Override | ||
protected Set<AttributeKey<?>> httpAttributes(URI uri) { | ||
Set<AttributeKey<?>> extra = new HashSet<>(); | ||
extra.add(SemanticAttributes.HTTP_HOST); | ||
extra.add(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH); | ||
extra.add(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH); | ||
extra.add(SemanticAttributes.HTTP_SCHEME); | ||
extra.add(SemanticAttributes.HTTP_TARGET); | ||
extra.addAll(super.httpAttributes(uri)); | ||
return extra; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.