Skip to content

Commit 7289e62

Browse files
Ashish AggarwalAshish Aggarwal
authored andcommitted
adding one more unit test
1 parent 54ae156 commit 7289e62

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

core/src/main/java/com/expedia/www/haystack/client/dispatchers/clients/HttpCollectorClient.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ public boolean send(Span span) throws ClientException {
8181
if (headers != null && headers.length > 0) {
8282
post.setHeaders(headers);
8383
}
84-
post.setHeader(new BasicHeader("Content-Type", "application/octet-stream"));
85-
post.setEntity(new ByteArrayEntity(spanBytes));
84+
final ByteArrayEntity entity = new ByteArrayEntity(spanBytes);
85+
entity.setContentType("application/octet-stream");
86+
post.setEntity(entity);
8687
CloseableHttpResponse response = null;
8788
try {
8889
response = httpClient.execute(post);

core/src/test/java/com/expedia/www/haystack/client/dispatchers/clients/HttpCollectorClientTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,22 @@ public void testFailedDispatch() throws Exception {
102102
client.send(span);
103103
}
104104

105+
@Test(expected = ClientException.class)
106+
public void testAnotherFailedDispatch() throws Exception {
107+
final Span span = tracer.buildSpan("sad-path").start();
108+
span.finish();
109+
final ArgumentCaptor<HttpPost> httpPostCapture = ArgumentCaptor.forClass(HttpPost.class);
110+
final CloseableHttpClient http = Mockito.mock(CloseableHttpClient.class);
111+
when(http.execute(httpPostCapture.capture())).thenThrow(new IOException());
112+
113+
final HttpCollectorClient client = new HttpCollectorClient("http://myendpoint:8080/span", new HashMap<>(), http);
114+
client.send(span);
115+
}
116+
105117
private void verifyCapturedHttpPost(final HttpPost httpPost) throws IOException {
106118
assertEquals(httpPost.getMethod(), "POST");
107119
assertEquals(httpPost.getURI().toString(), "http://myendpoint:8080/span");
108-
assertEquals(httpPost.getFirstHeader("Content-Type").getValue(), "application/octet-stream");
120+
assertEquals(httpPost.getEntity().getContentType().getValue(), "application/octet-stream");
109121
assertEquals(httpPost.getFirstHeader("client-id").getValue(), "my-client");
110122
com.expedia.open.tracing.Span span = com.expedia.open.tracing.Span.parseFrom(httpPost.getEntity().getContent());
111123
assertEquals(span.getServiceName(), serviceName);

0 commit comments

Comments
 (0)