Add reactive Supplier test

This commit is contained in:
Oleg Zhurakousky
2021-07-09 16:39:39 +02:00
parent 8b61684168
commit 3793c58fe8

View File

@@ -20,6 +20,8 @@ import java.util.function.Function;
import java.util.function.Supplier;
import org.junit.jupiter.api.Test;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
@@ -60,6 +62,25 @@ public abstract class TraceFunctionAroundWrapperTests {
}
}
@Test
public void test_tracing_with_reactive_supplier() {
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(configuration(),
SampleConfiguration.class).run("--logging.level.org.springframework.cloud.function=DEBUG",
"--spring.main.lazy-initialization=true");) {
TestSpanHandler spanHandler = context.getBean(TestSpanHandler.class);
assertThat(spanHandler.reportedSpans()).isEmpty();
FunctionCatalog catalog = context.getBean(FunctionCatalog.class);
FunctionInvocationWrapper function = catalog.lookup("reactiveGreeter");
function.setSkipOutputConversion(true);
Object result = function.get();
assertThat(result).isInstanceOf(Publisher.class);
/* TODO
* We'll need more assertions but for now this one will ensure that wrapper does not change the type of return value
* specifically for reactive cases where Flux became Message<Flux> due to the current code in TraceFunctionAroundWrapper
*/
}
}
@Test
public void test_tracing_with_function() {
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(configuration(),
@@ -89,6 +110,11 @@ public abstract class TraceFunctionAroundWrapperTests {
return () -> "hello";
}
@Bean
public Supplier<Flux<String>> reactiveGreeter() {
return () -> Flux.just("hello");
}
@Bean
public Function<String, String> uppercase() {
return v -> v.toUpperCase();