Skip to content

Commit

Permalink
Corrects most of the test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
anuragagarwal561994 committed Mar 26, 2022
1 parent 7c2c4cf commit cdea4a6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Integer statusCode(ApacheHttpClientRequest request, HttpResponse response
@Override
@Nullable
public String flavor(ApacheHttpClientRequest request, @Nullable HttpResponse response) {
return request.getFlavor();
return request.getFlavor(response);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void transform(TypeTransformer transformer) {
.and(takesArgument(2, named("org.apache.hc.core5.http.nio.HandlerFactory")))
.and(takesArgument(3, named("org.apache.hc.core5.http.protocol.HttpContext")))
.and(takesArgument(4, named("org.apache.hc.core5.concurrent.FutureCallback"))),
ApacheHttpAsyncClientInstrumentation.class.getName() + "$ClientAdvice");
this.getClass().getName() + "$ClientAdvice");
}

@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.apache.hc.core5.http.EntityDetails;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.ProtocolVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -50,8 +51,8 @@ static List<String> headersToList(Header[] headers) {
return headersList;
}

public long requestContentLength() {
return entityDetails.getContentLength();
public Long requestContentLength() {
return entityDetails != null ? entityDetails.getContentLength() : null;
}

public void setHeader(String name, String value) {
Expand All @@ -66,8 +67,11 @@ public String getUrl() {
return uri != null ? uri.toString() : null;
}

public String getFlavor() {
ProtocolVersion protocolVersion = delegate.getVersion();
public String getFlavor(HttpResponse response) {
if (response == null) {
return null;
}
ProtocolVersion protocolVersion = response.getVersion();
String protocol = protocolVersion.getProtocol();
if (!protocol.equals("HTTP")) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
import org.apache.hc.core5.concurrent.FutureCallback;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.message.BasicHeader;
import org.apache.hc.core5.io.CloseMode;
import org.apache.hc.core5.util.Timeout;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -56,9 +58,9 @@ void setUp() {
}

@AfterAll
void tearDown() throws Exception {
client.close();
clientWithReadTimeout.close();
void tearDown() {
client.close(CloseMode.GRACEFUL);
clientWithReadTimeout.close(CloseMode.GRACEFUL);
}

CloseableHttpAsyncClient getClient(URI uri) {
Expand Down Expand Up @@ -104,8 +106,9 @@ class ApacheClientHostRequestTest extends AbstractHttpClientTest<SimpleHttpReque

@Override
protected SimpleHttpRequest buildRequest(String method, URI uri, Map<String, String> headers) {
HttpHost httpHost = new HttpHost(uri.getScheme(), uri.getHost(), uri.getPort());
return configureRequest(
new SimpleHttpRequest(method, URI.create(fullPathFromUri(uri))), headers);
new SimpleHttpRequest(method, httpHost, fullPathFromUri(uri)), headers);
}

@Override
Expand Down Expand Up @@ -198,8 +201,13 @@ void configureTest(HttpClientTestOptions options) {
options.enableTestReadTimeout();
options.setHttpAttributes(
endpoint -> {
Set<AttributeKey<?>> attributes =
new HashSet<>(HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES);
Set<AttributeKey<?>> attributes = new HashSet<>();
attributes.add(SemanticAttributes.NET_PEER_NAME);
attributes.add(SemanticAttributes.NET_PEER_PORT);
attributes.add(SemanticAttributes.HTTP_URL);
attributes.add(SemanticAttributes.HTTP_METHOD);
// attributes.add(SemanticAttributes.HTTP_FLAVOR);
attributes.add(SemanticAttributes.HTTP_USER_AGENT);
attributes.add(SemanticAttributes.HTTP_SCHEME);
attributes.add(SemanticAttributes.HTTP_TARGET);
return attributes;
Expand Down

0 comments on commit cdea4a6

Please sign in to comment.