Merge branch '1.2.x'

This commit is contained in:
Marcin Grzejszczak
2017-10-20 12:48:11 +02:00
5 changed files with 51 additions and 2 deletions

View File

@@ -54,7 +54,7 @@ class ApacheHttpClientRibbonRequestCustomizer extends SpanInjectingRibbonRequest
}
@Override public void put(String key, String value) {
context.addHeader(key, value);
context.setHeader(key, value);
}
};
}

View File

@@ -57,7 +57,7 @@ class OkHttpClientRibbonRequestCustomizer extends SpanInjectingRibbonRequestCust
}
@Override public void put(String key, String value) {
context.addHeader(key, value);
context.header(key, value);
}
};
}

View File

@@ -71,7 +71,22 @@ public class ApacheHttpClientRibbonRequestCustomizerTests {
thenThereIsAHeaderWithNameAndValue(request, Span.PROCESS_ID_NAME, "processId");
}
@Test
public void should_not_set_duplicate_tracing_headers_on_the_context_when_there_is_a_span() throws Exception {
RequestBuilder requestBuilder = RequestBuilder.create("GET");
this.customizer.inject(this.span, this.customizer.toSpanTextMap(requestBuilder));
this.customizer.inject(this.span, this.customizer.toSpanTextMap(requestBuilder));
HttpUriRequest request = requestBuilder.build();
thenThereIsAHeaderWithNameAndValue(request, Span.SPAN_ID_NAME, "0000000000000001");
thenThereIsAHeaderWithNameAndValue(request, Span.TRACE_ID_NAME, "0000000000000002");
thenThereIsAHeaderWithNameAndValue(request, Span.PARENT_ID_NAME, "0000000000000003");
thenThereIsAHeaderWithNameAndValue(request, Span.PROCESS_ID_NAME, "processId");
}
private void thenThereIsAHeaderWithNameAndValue(HttpUriRequest request, String name, String value) {
then(request.getHeaders(name)).hasSize(1);
Header header = request.getFirstHeader(name);
then(header.getName()).isEqualTo(name);
then(header.getValue()).isEqualTo(value);

View File

@@ -68,7 +68,22 @@ public class OkHttpClientRibbonRequestCustomizerTests {
thenThereIsAHeaderWithNameAndValue(request, Span.PROCESS_ID_NAME, "processId");
}
@Test
public void should_not_set_duplicate_tracing_headers_on_the_context_when_there_is_a_span() throws Exception {
Request.Builder requestBuilder = requestBuilder();
this.customizer.inject(this.span, this.customizer.toSpanTextMap(requestBuilder));
this.customizer.inject(this.span, this.customizer.toSpanTextMap(requestBuilder));
Request request = requestBuilder.build();
thenThereIsAHeaderWithNameAndValue(request, Span.SPAN_ID_NAME, "0000000000000001");
thenThereIsAHeaderWithNameAndValue(request, Span.TRACE_ID_NAME, "0000000000000002");
thenThereIsAHeaderWithNameAndValue(request, Span.PARENT_ID_NAME, "0000000000000003");
thenThereIsAHeaderWithNameAndValue(request, Span.PROCESS_ID_NAME, "processId");
}
private void thenThereIsAHeaderWithNameAndValue(Request request, String name, String value) {
then(request.headers(name)).hasSize(1);
then(request.header(name)).isEqualTo(value);
}

View File

@@ -16,6 +16,8 @@
package org.springframework.cloud.sleuth.instrument.zuul;
import java.util.stream.Collectors;
import com.netflix.client.http.HttpRequest;
import org.junit.Test;
@@ -68,7 +70,24 @@ public class RestClientRibbonRequestCustomizerTests {
thenThereIsAHeaderWithNameAndValue(request, Span.PROCESS_ID_NAME, "processId");
}
@Test
public void should_not_set_duplicate_tracing_headers_on_the_context_when_there_is_a_span() throws Exception {
HttpRequest.Builder requestBuilder = requestBuilder();
this.customizer.inject(this.span, this.customizer.toSpanTextMap(requestBuilder));
this.customizer.inject(this.span, this.customizer.toSpanTextMap(requestBuilder));
HttpRequest request = requestBuilder.build();
thenThereIsAHeaderWithNameAndValue(request, Span.SPAN_ID_NAME, "0000000000000001");
thenThereIsAHeaderWithNameAndValue(request, Span.TRACE_ID_NAME, "0000000000000002");
thenThereIsAHeaderWithNameAndValue(request, Span.PARENT_ID_NAME, "0000000000000003");
thenThereIsAHeaderWithNameAndValue(request, Span.PROCESS_ID_NAME, "processId");
}
private void thenThereIsAHeaderWithNameAndValue(HttpRequest request, String name, String value) {
then(request.getHttpHeaders().getAllHeaders()
.stream().filter(stringStringEntry -> stringStringEntry.getKey().equals(name)).collect(
Collectors.toList())).hasSize(1);
then(request.getHttpHeaders().getFirstValue(name)).isEqualTo(value);
}