-
Notifications
You must be signed in to change notification settings - Fork 785
Closed
Description
Dear team,
I have written a simple Consumer.
The function works as expected when I execute it through the main class.
However, when I write a unit test for that function, I get a ClassCastException because of Sleuth:
java.lang.ClassCastException: class me.julb.library.dto.googlechat.GoogleChatMessageDTO cannot be cast to class org.springframework.messaging.Message (me.julb.library.dto.googlechat.GoogleChatMessageDTO and org.springframework.messaging.Message are in unnamed module of loader 'app')
at org.springframework.cloud.sleuth.instrument.messaging.TraceFunctionAroundWrapper.doApply(TraceFunctionAroundWrapper.java:99)
at org.springframework.cloud.function.context.catalog.FunctionAroundWrapper.apply(FunctionAroundWrapper.java:47)
at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$1.doApply(SimpleFunctionRegistry.java:256)
at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.apply(SimpleFunctionRegistry.java:550)
at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.accept(SimpleFunctionRegistry.java:566)
at me.julb.functions.SendGoogleChatFunctionTest.whenInvokingFunction_thenSendGoogleChat(SendGoogleChatFunctionTest.java:69)
From what I understand, it seems that the Sleuth TraceFunctionAroundWrapper is invoked before the input is converted to a Message in FunctionInvocationWrapper#convertInputIfNecessary.
I'm using :
- Spring Cloud Function 3.2.1
- Spring Cloud Sleuth 3.1.0.
Workarounds found:
1/ Transform the Consumer<GoogleChatMessageDTO> to a Consumer<Message<GoogleChatMessageDTO>>
2/ Set property spring.sleuth.function.enabled: false for unit tests