GH-609 Fix Flux to Mono and Mono to Flux transformation
Given that s-c-f-web always produces input as Flux, Function<Mono, Mono> were having issues. This fixes it
This commit is contained in:
@@ -544,6 +544,12 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect
|
||||
|
||||
Object invocationResult = null;
|
||||
if (this.target instanceof Function) {
|
||||
if (FunctionTypeUtils.isMono(FunctionTypeUtils.getInputType(this.getFunctionType(), 0)) && input instanceof Flux) {
|
||||
input = Mono.from((Publisher) input);
|
||||
}
|
||||
else if (FunctionTypeUtils.isFlux(FunctionTypeUtils.getInputType(this.getFunctionType(), 0)) && input instanceof Mono) {
|
||||
input = Flux.from((Publisher) input);
|
||||
}
|
||||
invocationResult = ((Function) target).apply(input);
|
||||
}
|
||||
else if (this.target instanceof Supplier) {
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.util.stream.Collectors;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.reactivestreams.Publisher;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.util.function.Tuple2;
|
||||
@@ -519,6 +520,17 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
||||
assertThat(((Person) config.consumerInputRef.get()).getName()).isEqualTo("Ricky");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGH_609() {
|
||||
FunctionCatalog catalog = this.configureCatalog(SampleFunctionConfiguration.class);
|
||||
Function<Publisher<String>, Publisher<String>> f = catalog.lookup("monoToMono");
|
||||
Mono<String> result = (Mono<String>) f.apply(Mono.just("hello"));
|
||||
assertThat(result.block()).isEqualTo("hello");
|
||||
|
||||
result = (Mono<String>) f.apply(Flux.just("hello"));
|
||||
assertThat(result.block()).isEqualTo("hello");
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
public static class PojoToMessageFunctionCompositionConfiguration {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user