-
Notifications
You must be signed in to change notification settings - Fork 881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HttpClient 4.0 java tests #7912
Merged
trask
merged 7 commits into
open-telemetry:main
from
anuragagarwal561994:httpclient-4-0-java-tests
Feb 27, 2023
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8d68242
Adds content lengths in test attributes
anuragagarwal561994 53f7028
Moves test cases to java
anuragagarwal561994 7680bc5
Applies spotless
anuragagarwal561994 26ba0c4
Refactoring attributes method and spotless apply
anuragagarwal561994 e6fa54f
Fixes test cases
anuragagarwal561994 6a42415
Adds comment for test cases
anuragagarwal561994 0d1ba87
Moves back httpclient testing to 4.0
anuragagarwal561994 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
253 changes: 0 additions & 253 deletions
253
...he-httpclient/apache-httpclient-4.0/javaagent/src/test/groovy/ApacheHttpClientTest.groovy
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
...n/apache-httpclient/apache-httpclient-4.0/javaagent/src/test/groovy/HttpUriRequest.groovy
This file was deleted.
Oops, something went wrong.
103 changes: 103 additions & 0 deletions
103
...lemetry/javaagent/instrumentation/apachehttpclient/v4_0/AbstractApacheHttpClientTest.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,103 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.apachehttpclient.v4_0; | ||
|
||
import io.opentelemetry.api.common.AttributeKey; | ||
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; | ||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult; | ||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions; | ||
import java.net.URI; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import org.apache.http.HttpHost; | ||
import org.apache.http.HttpRequest; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.protocol.BasicHttpContext; | ||
import org.apache.http.protocol.HttpContext; | ||
|
||
abstract class AbstractApacheHttpClientTest<T extends HttpRequest> | ||
extends AbstractHttpClientTest<T> { | ||
@Override | ||
protected String userAgent() { | ||
return "apachehttpclient"; | ||
} | ||
|
||
@Override | ||
protected void configure(HttpClientTestOptions.Builder optionsBuilder) { | ||
optionsBuilder.setUserAgent(userAgent()); | ||
optionsBuilder.enableTestReadTimeout(); | ||
optionsBuilder.setHttpAttributes(AbstractApacheHttpClientTest::getHttpAttributes); | ||
} | ||
|
||
private static Set<AttributeKey<?>> getHttpAttributes(URI endpoint) { | ||
return HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES; | ||
} | ||
|
||
@Override | ||
public T buildRequest(String method, URI uri, Map<String, String> headers) { | ||
T request = createRequest(method, uri); | ||
request.addHeader("user-agent", userAgent()); | ||
headers.forEach(request::setHeader); | ||
return request; | ||
} | ||
|
||
@Override | ||
public int sendRequest(T request, String method, URI uri, Map<String, String> headers) | ||
throws Exception { | ||
return getResponseCode(executeRequest(request, uri)); | ||
} | ||
|
||
@Override | ||
public void sendRequestWithCallback( | ||
T request, | ||
String method, | ||
URI uri, | ||
Map<String, String> headers, | ||
HttpClientResult requestResult) { | ||
try { | ||
executeRequestWithCallback(request, uri, requestResult); | ||
} catch (Throwable throwable) { | ||
requestResult.complete(throwable); | ||
} | ||
} | ||
|
||
protected HttpHost getHost(URI uri) { | ||
return new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); | ||
} | ||
|
||
protected HttpContext getContext() { | ||
return new BasicHttpContext(); | ||
} | ||
|
||
protected static String fullPathFromUri(URI uri) { | ||
StringBuilder builder = new StringBuilder(); | ||
if (uri.getPath() != null) { | ||
builder.append(uri.getPath()); | ||
} | ||
|
||
if (uri.getQuery() != null) { | ||
builder.append('?'); | ||
builder.append(uri.getQuery()); | ||
} | ||
|
||
if (uri.getFragment() != null) { | ||
builder.append('#'); | ||
builder.append(uri.getFragment()); | ||
} | ||
return builder.toString(); | ||
} | ||
|
||
abstract T createRequest(String method, URI uri); | ||
|
||
abstract HttpResponse executeRequest(T request, URI uri) throws Exception; | ||
|
||
abstract void executeRequestWithCallback(T request, URI uri, HttpClientResult requestResult) | ||
throws Exception; | ||
|
||
private static int getResponseCode(HttpResponse response) { | ||
return response.getStatusLine().getStatusCode(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes @trask this works, thanks.