Fixed consumer sample to accept bare string
This commit is contained in:
@@ -26,7 +26,7 @@ public class ConsumerCompiler<T> extends AbstractFunctionCompiler<Consumer<T>> {
|
||||
private final String inputType;
|
||||
|
||||
public ConsumerCompiler() {
|
||||
this("Object");
|
||||
this("Flux<Object>");
|
||||
}
|
||||
|
||||
public ConsumerCompiler(String inputType) {
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class CompilationFailedException extends RuntimeException {
|
||||
|
||||
public CompilationFailedException(List<CompilationMessage> messages) {
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.cloud.function.compiler.CompilationResultFactory;
|
||||
import org.springframework.cloud.function.compiler.FunctionCompiler;
|
||||
import org.springframework.cloud.function.compiler.java.SimpleClassLoader;
|
||||
import org.springframework.cloud.function.support.FunctionFactoryMetadata;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
@@ -30,7 +31,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public abstract class AbstractByteCodeLoadingProxy<T> implements InitializingBean {
|
||||
public abstract class AbstractByteCodeLoadingProxy<T> implements InitializingBean, FunctionFactoryMetadata {
|
||||
|
||||
private final Resource resource;
|
||||
|
||||
@@ -81,6 +82,7 @@ public abstract class AbstractByteCodeLoadingProxy<T> implements InitializingBea
|
||||
return this.factory.getResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Method getFactoryMethod() {
|
||||
return this.method;
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ public class AbstractLambdaCompilingProxy<T> implements InitializingBean, BeanNa
|
||||
return this.factory.getResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Method getFactoryMethod() {
|
||||
return this.factory.getFactoryMethod();
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.cloud.function.compiler.proxy;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.springframework.cloud.function.support.ConsumerProxy;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
/**
|
||||
@@ -25,7 +26,7 @@ import org.springframework.core.io.Resource;
|
||||
*
|
||||
* @param <T> type
|
||||
*/
|
||||
public class ByteCodeLoadingConsumer<T> extends AbstractByteCodeLoadingProxy<Consumer<T>> implements Consumer<T> {
|
||||
public class ByteCodeLoadingConsumer<T> extends AbstractByteCodeLoadingProxy<Consumer<T>> implements ConsumerProxy<T> {
|
||||
|
||||
public ByteCodeLoadingConsumer(Resource resource) {
|
||||
super(resource, Consumer.class);
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.cloud.function.compiler.proxy;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.cloud.function.support.FunctionProxy;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
@@ -28,7 +27,7 @@ import org.springframework.core.io.Resource;
|
||||
* @param <T> Function input type
|
||||
* @param <R> Function result type
|
||||
*/
|
||||
public class ByteCodeLoadingFunction<T, R> extends AbstractByteCodeLoadingProxy<Function<T, R>> implements FunctionProxy<T, R>, InitializingBean {
|
||||
public class ByteCodeLoadingFunction<T, R> extends AbstractByteCodeLoadingProxy<Function<T, R>> implements FunctionProxy<T, R> {
|
||||
|
||||
public ByteCodeLoadingFunction(Resource resource) {
|
||||
super(resource, Function.class);
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.springframework.cloud.function.compiler.CompiledFunctionFactory;
|
||||
import org.springframework.cloud.function.compiler.ConsumerCompiler;
|
||||
import org.springframework.cloud.function.compiler.FunctionCompiler;
|
||||
import org.springframework.cloud.function.compiler.SupplierCompiler;
|
||||
import org.springframework.cloud.function.support.FunctionFactoryMetadata;
|
||||
import org.springframework.cloud.function.support.FunctionUtils;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
|
||||
@@ -51,6 +52,7 @@ public class ByteCodeLoadingFunctionTests {
|
||||
};
|
||||
ByteCodeLoadingConsumer<String> consumer = new ByteCodeLoadingConsumer<>(resource);
|
||||
consumer.afterPropertiesSet();
|
||||
assertThat(consumer instanceof FunctionFactoryMetadata);
|
||||
assertThat(FunctionUtils.isFluxConsumer(consumer.getFactoryMethod())).isFalse();
|
||||
consumer.accept("foo");
|
||||
}
|
||||
@@ -67,6 +69,7 @@ public class ByteCodeLoadingFunctionTests {
|
||||
};
|
||||
ByteCodeLoadingSupplier<String> supplier = new ByteCodeLoadingSupplier<>(resource);
|
||||
supplier.afterPropertiesSet();
|
||||
assertThat(supplier instanceof FunctionFactoryMetadata);
|
||||
assertThat(FunctionUtils.isFluxSupplier(supplier.getFactoryMethod())).isFalse();
|
||||
assertThat(supplier.get()).isEqualTo("foo");
|
||||
}
|
||||
@@ -83,6 +86,7 @@ public class ByteCodeLoadingFunctionTests {
|
||||
};
|
||||
ByteCodeLoadingFunction<String, String> function = new ByteCodeLoadingFunction<>(resource);
|
||||
function.afterPropertiesSet();
|
||||
assertThat(function instanceof FunctionFactoryMetadata);
|
||||
assertThat(FunctionUtils.isFluxFunction(function.getFactoryMethod())).isFalse();
|
||||
assertThat(function.apply("foo")).isEqualTo("FOO");
|
||||
}
|
||||
@@ -99,6 +103,7 @@ public class ByteCodeLoadingFunctionTests {
|
||||
};
|
||||
ByteCodeLoadingFunction<Flux<String>, Flux<String>> function = new ByteCodeLoadingFunction<>(resource);
|
||||
function.afterPropertiesSet();
|
||||
assertThat(function instanceof FunctionFactoryMetadata);
|
||||
assertThat(FunctionUtils.isFluxFunction(function.getFactoryMethod())).isTrue();
|
||||
assertThat(function.apply(Flux.just("foo")).blockFirst()).isEqualTo("FOO");
|
||||
}
|
||||
Reference in New Issue
Block a user