GH-1204 Polishing aftre refactoring of TypeTools
This commit is contained in:
@@ -121,7 +121,7 @@ public class FunctionRegistration<T> implements BeanNameAware {
|
|||||||
if (KotlinDetector.isKotlinPresent() && this.target instanceof KotlinLambdaToFunctionAutoConfiguration.KotlinFunctionWrapper) {
|
if (KotlinDetector.isKotlinPresent() && this.target instanceof KotlinLambdaToFunctionAutoConfiguration.KotlinFunctionWrapper) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
Type discoveredFunctionType = FunctionTypeUtils.discoverFunctionTypeFromClass(this.target.getClass());
|
Type discoveredFunctionType = type; //FunctionTypeUtils.discoverFunctionTypeFromClass(this.target.getClass());
|
||||||
if (discoveredFunctionType == null) { // only valid for Kafka Stream KStream[] return type.
|
if (discoveredFunctionType == null) { // only valid for Kafka Stream KStream[] return type.
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -146,7 +146,6 @@ public class FunctionRegistration<T> implements BeanNameAware {
|
|||||||
+ discoveredFunctionType + "; Provided: " + type);
|
+ discoveredFunctionType + "; Provided: " + type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -180,6 +180,10 @@ public class BeanFactoryAwareFunctionRegistry extends SimpleFunctionRegistry imp
|
|||||||
else {
|
else {
|
||||||
functionType = FunctionTypeUtils.discoverFunctionType(functionCandidate, functionName, this.applicationContext);
|
functionType = FunctionTypeUtils.discoverFunctionType(functionCandidate, functionName, this.applicationContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("Discovered function type for: " + functionDefinition + " - " + functionType);
|
||||||
|
}
|
||||||
if (functionRegistration == null) {
|
if (functionRegistration == null) {
|
||||||
functionRegistration = new FunctionRegistration(functionCandidate, functionName).type(functionType);
|
functionRegistration = new FunctionRegistration(functionCandidate, functionName).type(functionType);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -371,7 +371,7 @@ public final class FunctionTypeUtils {
|
|||||||
else {
|
else {
|
||||||
inputType = resolvableInputType.getType();
|
inputType = resolvableInputType.getType();
|
||||||
}
|
}
|
||||||
return inputType;
|
return inputType instanceof TypeVariable ? Object.class : inputType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@@ -465,7 +465,7 @@ public final class FunctionTypeUtils {
|
|||||||
else {
|
else {
|
||||||
outputType = resolvableOutputType.getType();
|
outputType = resolvableOutputType.getType();
|
||||||
}
|
}
|
||||||
return outputType;
|
return outputType instanceof TypeVariable ? Object.class : outputType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Type getImmediateGenericType(Type type, int index) {
|
public static Type getImmediateGenericType(Type type, int index) {
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
|||||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
import org.springframework.cloud.function.context.FunctionCatalog;
|
import org.springframework.cloud.function.context.FunctionCatalog;
|
||||||
import org.springframework.cloud.function.context.FunctionRegistration;
|
import org.springframework.cloud.function.context.FunctionRegistration;
|
||||||
import org.springframework.cloud.function.context.FunctionRegistry;
|
|
||||||
import org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry.FunctionInvocationWrapper;
|
import org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry.FunctionInvocationWrapper;
|
||||||
import org.springframework.cloud.function.json.JsonMapper;
|
import org.springframework.cloud.function.json.JsonMapper;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
@@ -80,7 +79,6 @@ import org.springframework.util.ReflectionUtils;
|
|||||||
|
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -671,46 +669,6 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
|||||||
assertThat(f.apply(Flux.just(25)).blockFirst()).isEqualTo(25);
|
assertThat(f.apply(Flux.just(25)).blockFirst()).isEqualTo(25);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
|
||||||
@Test
|
|
||||||
public void testRegisteringWithTypeThatDoesNotMatchDiscoveredType() {
|
|
||||||
FunctionCatalog catalog = this.configureCatalog(EmptyConfiguration.class);
|
|
||||||
Function func = catalog.lookup("func");
|
|
||||||
assertThat(func).isNull();
|
|
||||||
FunctionRegistry registry = (FunctionRegistry) catalog;
|
|
||||||
try {
|
|
||||||
FunctionRegistration registration = new FunctionRegistration(new MyFunction(), "a")
|
|
||||||
.type(FunctionTypeUtils.functionType(Integer.class, String.class));
|
|
||||||
registry.register(registration);
|
|
||||||
fail();
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException e) {
|
|
||||||
// good as we expect it to fail
|
|
||||||
}
|
|
||||||
//
|
|
||||||
try {
|
|
||||||
FunctionRegistration registration = new FunctionRegistration(new MyFunction(), "b")
|
|
||||||
.type(FunctionTypeUtils.functionType(String.class, Integer.class));
|
|
||||||
registry.register(registration);
|
|
||||||
fail();
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException e) {
|
|
||||||
// good as we expect it to fail
|
|
||||||
}
|
|
||||||
//
|
|
||||||
FunctionRegistration c = new FunctionRegistration(new MyFunction(), "c")
|
|
||||||
.type(FunctionTypeUtils.functionType(String.class, String.class));
|
|
||||||
registry.register(c);
|
|
||||||
//
|
|
||||||
FunctionRegistration d = new FunctionRegistration(new RawFunction(), "d")
|
|
||||||
.type(FunctionTypeUtils.functionType(Person.class, String.class));
|
|
||||||
registry.register(d);
|
|
||||||
//
|
|
||||||
FunctionRegistration e = new FunctionRegistration(new RawFunction(), "e")
|
|
||||||
.type(FunctionTypeUtils.functionType(Object.class, Object.class));
|
|
||||||
registry.register(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
@Test
|
@Test
|
||||||
public void testNoConversionOnInputMapIfInputIsMap() {
|
public void testNoConversionOnInputMapIfInputIsMap() {
|
||||||
|
|||||||
Reference in New Issue
Block a user