Polish
This commit is contained in:
@@ -91,7 +91,9 @@ public class TraceFunctionAroundWrapper extends FunctionAroundWrapper
|
||||
traceMessageHandler.afterMessageHandled(wrappedInputMessage.childSpan, throwable);
|
||||
}
|
||||
if (result == null) {
|
||||
log.debug("Returned message is null - we have a consumer");
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Returned message is null - we have a consumer");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
Message msgResult = toMessage(result);
|
||||
@@ -111,7 +113,7 @@ public class TraceFunctionAroundWrapper extends FunctionAroundWrapper
|
||||
return (Message) result;
|
||||
}
|
||||
|
||||
private String inputDestination(String functionDefinition) {
|
||||
String inputDestination(String functionDefinition) {
|
||||
return this.functionToDestinationCache.computeIfAbsent(functionDefinition, s -> {
|
||||
String bindingMappingProperty = "spring.cloud.stream.function.bindings." + s + "-in-0";
|
||||
String bindingProperty = this.environment.containsProperty(bindingMappingProperty)
|
||||
@@ -120,7 +122,7 @@ public class TraceFunctionAroundWrapper extends FunctionAroundWrapper
|
||||
});
|
||||
}
|
||||
|
||||
private String outputDestination(String functionDefinition) {
|
||||
String outputDestination(String functionDefinition) {
|
||||
return this.functionToDestinationCache.computeIfAbsent(functionDefinition, s -> {
|
||||
String bindingMappingProperty = "spring.cloud.stream.function.bindings." + s + "-out-0";
|
||||
String bindingProperty = this.environment.containsProperty(bindingMappingProperty)
|
||||
@@ -131,7 +133,9 @@ public class TraceFunctionAroundWrapper extends FunctionAroundWrapper
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(RefreshScopeRefreshedEvent event) {
|
||||
log.debug("Context refreshed, will reset the cache");
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Context refreshed, will reset the cache");
|
||||
}
|
||||
this.functionToDestinationCache.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,12 +16,9 @@
|
||||
|
||||
package org.springframework.cloud.sleuth.instrument.messaging;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
@@ -40,53 +37,35 @@ class TraceFunctionAroundWrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_with_standard_bindings() throws Exception {
|
||||
try (GenericApplicationContext context = new GenericApplicationContext()) {
|
||||
System.setProperty("spring.cloud.stream.bindings.marcin-in-0.destination", "oleg");
|
||||
System.setProperty("spring.cloud.stream.bindings.marcin-out-0.destination", "bob");
|
||||
TraceFunctionAroundWrapper wrapper = new TraceFunctionAroundWrapper(context.getEnvironment(), null, null,
|
||||
null, null);
|
||||
void should_point_to_proper_destination_when_working_with_function_definition() {
|
||||
MockEnvironment mockEnvironment = new MockEnvironment();
|
||||
mockEnvironment.setProperty("spring.cloud.stream.bindings.marcin-in-0.destination", "oleg");
|
||||
mockEnvironment.setProperty("spring.cloud.stream.bindings.marcin-out-0.destination", "bob");
|
||||
TraceFunctionAroundWrapper wrapper = new TraceFunctionAroundWrapper(mockEnvironment, null, null,
|
||||
null, null);
|
||||
|
||||
Method inputDestinationMethod = ReflectionUtils.findMethod(TraceFunctionAroundWrapper.class,
|
||||
"inputDestination", String.class);
|
||||
inputDestinationMethod.setAccessible(true);
|
||||
assertThat(inputDestinationMethod.invoke(wrapper, "marcin")).isEqualTo("oleg"); // gross
|
||||
// overestimation
|
||||
// ;)
|
||||
assertThat(wrapper.inputDestination("marcin")).isEqualTo("oleg");
|
||||
|
||||
wrapper.functionToDestinationCache.clear();
|
||||
Method outputDestinationMethod = ReflectionUtils.findMethod(TraceFunctionAroundWrapper.class,
|
||||
"outputDestination", String.class);
|
||||
outputDestinationMethod.setAccessible(true);
|
||||
assertThat(outputDestinationMethod.invoke(wrapper, "marcin")).isEqualTo("bob");
|
||||
}
|
||||
wrapper.functionToDestinationCache.clear();
|
||||
|
||||
assertThat(wrapper.outputDestination("marcin")).isEqualTo("bob");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_with_remapped_bindings() throws Exception {
|
||||
try (GenericApplicationContext context = new GenericApplicationContext()) {
|
||||
System.setProperty("spring.cloud.stream.function.bindings.marcin-in-0", "input");
|
||||
System.setProperty("spring.cloud.stream.bindings.input.destination", "oleg");
|
||||
System.setProperty("spring.cloud.stream.function.bindings.marcin-out-0", "output");
|
||||
System.setProperty("spring.cloud.stream.bindings.output.destination", "bob");
|
||||
TraceFunctionAroundWrapper wrapper = new TraceFunctionAroundWrapper(context.getEnvironment(), null, null,
|
||||
null, null);
|
||||
void should_point_to_proper_destination_when_working_with_remapped_functions() {
|
||||
MockEnvironment mockEnvironment = new MockEnvironment();
|
||||
mockEnvironment.setProperty("spring.cloud.stream.function.bindings.marcin-in-0", "input");
|
||||
mockEnvironment.setProperty("spring.cloud.stream.bindings.input.destination", "oleg");
|
||||
mockEnvironment.setProperty("spring.cloud.stream.function.bindings.marcin-out-0", "output");
|
||||
mockEnvironment.setProperty("spring.cloud.stream.bindings.output.destination", "bob");
|
||||
TraceFunctionAroundWrapper wrapper = new TraceFunctionAroundWrapper(mockEnvironment, null, null,
|
||||
null, null);
|
||||
|
||||
Method inputDestinationMethod = ReflectionUtils.findMethod(TraceFunctionAroundWrapper.class,
|
||||
"inputDestination", String.class);
|
||||
inputDestinationMethod.setAccessible(true);
|
||||
assertThat(inputDestinationMethod.invoke(wrapper, "marcin")).isEqualTo("oleg"); // that's
|
||||
// a
|
||||
// gross
|
||||
// overestimation
|
||||
// ;)
|
||||
assertThat(wrapper.inputDestination("marcin")).isEqualTo("oleg");
|
||||
|
||||
wrapper.functionToDestinationCache.clear();
|
||||
Method outputDestinationMethod = ReflectionUtils.findMethod(TraceFunctionAroundWrapper.class,
|
||||
"outputDestination", String.class);
|
||||
outputDestinationMethod.setAccessible(true);
|
||||
assertThat(outputDestinationMethod.invoke(wrapper, "marcin")).isEqualTo("bob");
|
||||
}
|
||||
wrapper.functionToDestinationCache.clear();
|
||||
|
||||
assertThat(wrapper.outputDestination("marcin")).isEqualTo("bob");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user