This commit is contained in:
@@ -52,7 +52,7 @@ import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
|
||||
@ContextConfiguration(classes = MultipleHopsIntegrationTests.TestConfig.class)
|
||||
@TestPropertySource(properties = { "spring.sleuth.baggage.remote-fields=x-vcap-request-id,country-code",
|
||||
@TestPropertySource(properties = { "spring.sleuth.baggage.remote-fields=x-vcap-request-id,country-code,Foo-Id",
|
||||
"spring.sleuth.baggage.local-fields=bp", "spring.sleuth.integration.enabled=true" })
|
||||
public abstract class MultipleHopsIntegrationTests {
|
||||
|
||||
@@ -62,6 +62,10 @@ public abstract class MultipleHopsIntegrationTests {
|
||||
|
||||
protected static final String COUNTRY_CODE = "country-code";
|
||||
|
||||
protected static final String CASE_INSENSITIVE_ID = "Foo-Id";
|
||||
|
||||
protected static final String NOT_PROPAGATED_HEADER = "baz-id";
|
||||
|
||||
@Autowired
|
||||
Tracer tracer;
|
||||
|
||||
@@ -117,6 +121,8 @@ public abstract class MultipleHopsIntegrationTests {
|
||||
// set request ID in a header not with the api explicitly
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.put(REQUEST_ID, Collections.singletonList("f4308d05-2228-4468-80f6-92a8377ba193"));
|
||||
headers.put(CASE_INSENSITIVE_ID, Collections.singletonList("123"));
|
||||
headers.put(NOT_PROPAGATED_HEADER, Collections.singletonList("456"));
|
||||
RequestEntity requestEntity = new RequestEntity(headers, HttpMethod.GET,
|
||||
URI.create("http://localhost:" + this.testConfig.port + "/greeting"));
|
||||
this.restTemplate.exchange(requestEntity, String.class);
|
||||
|
||||
@@ -45,8 +45,10 @@ import org.springframework.messaging.support.ErrorMessage;
|
||||
import org.springframework.messaging.support.ExecutorChannelInterceptor;
|
||||
import org.springframework.messaging.support.ExecutorSubscribableChannel;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.messaging.support.NativeMessageHeaderAccessor.NATIVE_HEADERS;
|
||||
|
||||
@@ -348,6 +350,44 @@ public abstract class TracingChannelInterceptorTest implements TestTracingAwareS
|
||||
assertThat(this.spans).extracting(FinishedSpan::getRemoteServiceName).containsOnly("broker", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_propagate_headers_case_insensitive() {
|
||||
channel.addInterceptor(this.interceptor);
|
||||
Map<String, Object> headers = new HashMap<>();
|
||||
headers.put("Foo-Id", "123");
|
||||
headers.put("baz-id", "456");
|
||||
|
||||
channel.send(MessageBuilder.createMessage("foo", new MessageHeaders(headers)));
|
||||
|
||||
Message<?> actualMessage = channel.receive();
|
||||
|
||||
assertThat(actualMessage.getHeaders()).isNotEmpty();
|
||||
assertThat(actualMessage.getHeaders().get("not-propagated-header")).isNull();
|
||||
assertThat(actualMessage.getHeaders().get("Foo-Id")).isEqualTo("123");
|
||||
assertThat(actualMessage.getHeaders().get("baz-id")).isEqualTo("456");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_propagate_native_headers_case_insensitive() {
|
||||
channel.addInterceptor(this.interceptor);
|
||||
LinkedMultiValueMap<String, String> nativeHeaders = new LinkedMultiValueMap<>();
|
||||
nativeHeaders.put("Foo-Id", singletonList("123"));
|
||||
nativeHeaders.put("baz-id", singletonList("456"));
|
||||
Map<String, Object> headers = new HashMap<>();
|
||||
headers.put(NATIVE_HEADERS, nativeHeaders);
|
||||
|
||||
channel.send(MessageBuilder.createMessage("foo", new MessageHeaders(headers)));
|
||||
|
||||
Message<?> actualMessage = channel.receive();
|
||||
|
||||
assertThat(actualMessage.getHeaders()).isNotEmpty();
|
||||
LinkedMultiValueMap<String, String> actualNativeHeaders = (LinkedMultiValueMap) actualMessage.getHeaders().get(NATIVE_HEADERS);
|
||||
assertThat(actualNativeHeaders).isNotEmpty();
|
||||
assertThat(actualNativeHeaders.get("not-propagated-header")).isNull();
|
||||
assertThat(actualNativeHeaders.get("Foo-Id")).isEqualTo(singletonList("123"));
|
||||
assertThat(actualNativeHeaders.get("baz-id")).isEqualTo(singletonList("456"));
|
||||
}
|
||||
|
||||
public ChannelInterceptor producerSideOnly(ChannelInterceptor delegate) {
|
||||
return new ChannelInterceptorAdapter() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user