* Simplify functionalTracingEnabled variable logic
* Add `BeanFactoryAwareFunctionRegistryTests.testWrappedWithAroundAdviseNotMessageReturnConfiguration()` to verify that non-Message return from the target function is wrapped to the `Message` before return to the `FunctionAroundWrapper`
This commit is contained in:
committed by
Oleg Zhurakousky
parent
80305e630b
commit
49e027a0ee
@@ -38,9 +38,8 @@ public abstract class FunctionAroundWrapper implements BiFunction<Object, Functi
|
||||
|
||||
@Override
|
||||
public final Object apply(Object input, FunctionInvocationWrapper targetFunction) {
|
||||
String functionalTracingEnabledStr = System.getProperty("spring.sleuth.function.enabled");
|
||||
boolean functionalTracingEnabled =
|
||||
!StringUtils.hasText(functionalTracingEnabledStr) || Boolean.parseBoolean(functionalTracingEnabledStr);
|
||||
String functionalTracingEnabledStr = System.getProperty("spring.sleuth.function.enabled", "true");
|
||||
boolean functionalTracingEnabled = Boolean.parseBoolean(functionalTracingEnabledStr);
|
||||
if (functionalTracingEnabled) {
|
||||
return this.doApply(input, targetFunction);
|
||||
}
|
||||
|
||||
@@ -566,6 +566,16 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
||||
assertThat(result.getHeaders().get("after")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Test
|
||||
public void testWrappedWithAroundAdviseNotMessageReturnConfiguration() {
|
||||
FunctionCatalog catalog = this.configureCatalog(WrappedWithAroundAdviseNotMessageReturnConfiguration.class);
|
||||
Function f = catalog.lookup("uppercase");
|
||||
Message result = (Message) f.apply(MessageBuilder.withPayload("hello").setHeader("myHeader", "myValue").build());
|
||||
assertThat(result.getHeaders()).containsEntry("myHeader", "myValue").containsEntry("advised", "true");
|
||||
assertThat(result.getPayload()).isEqualTo("HELLO");
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Test
|
||||
public void testEachElementInFluxIsProcessed() {
|
||||
@@ -917,6 +927,32 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
||||
}
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@Configuration
|
||||
protected static class WrappedWithAroundAdviseNotMessageReturnConfiguration {
|
||||
|
||||
@Bean
|
||||
public Function<Message<String>, String> uppercase() {
|
||||
return v -> v.getPayload().toUpperCase();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FunctionAroundWrapper wrapper() {
|
||||
return new FunctionAroundWrapper() {
|
||||
|
||||
@Override
|
||||
protected Object doApply(Object input, FunctionInvocationWrapper targetFunction) {
|
||||
// in this test we know input is a Message
|
||||
Message<?> mInput = (Message<?>) input;
|
||||
Message<?> advisedMessage = MessageBuilder.fromMessage(mInput).setHeader("advised", "true").build();
|
||||
Object result = targetFunction.apply(advisedMessage);
|
||||
assertThat(result).isInstanceOf(Message.class);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@Configuration
|
||||
protected static class SampleFunctionConfiguration {
|
||||
|
||||
Reference in New Issue
Block a user