GH-1204 Polishing aftre refactoring of TypeTools

This commit is contained in:
Oleg Zhurakousky
2024-11-24 18:07:40 +01:00
parent 5e179a2052
commit a3b45f4aa7
4 changed files with 7 additions and 46 deletions

View File

@@ -121,7 +121,7 @@ public class FunctionRegistration<T> implements BeanNameAware {
if (KotlinDetector.isKotlinPresent() && this.target instanceof KotlinLambdaToFunctionAutoConfiguration.KotlinFunctionWrapper) {
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.
return null;
}
@@ -146,7 +146,6 @@ public class FunctionRegistration<T> implements BeanNameAware {
+ discoveredFunctionType + "; Provided: " + type);
}
return this;
}

View File

@@ -180,6 +180,10 @@ public class BeanFactoryAwareFunctionRegistry extends SimpleFunctionRegistry imp
else {
functionType = FunctionTypeUtils.discoverFunctionType(functionCandidate, functionName, this.applicationContext);
}
if (logger.isDebugEnabled()) {
logger.debug("Discovered function type for: " + functionDefinition + " - " + functionType);
}
if (functionRegistration == null) {
functionRegistration = new FunctionRegistration(functionCandidate, functionName).type(functionType);
}

View File

@@ -371,7 +371,7 @@ public final class FunctionTypeUtils {
else {
inputType = resolvableInputType.getType();
}
return inputType;
return inputType instanceof TypeVariable ? Object.class : inputType;
}
@SuppressWarnings("rawtypes")
@@ -465,7 +465,7 @@ public final class FunctionTypeUtils {
else {
outputType = resolvableOutputType.getType();
}
return outputType;
return outputType instanceof TypeVariable ? Object.class : outputType;
}
public static Type getImmediateGenericType(Type type, int index) {

View File

@@ -59,7 +59,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.function.context.FunctionCatalog;
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.json.JsonMapper;
import org.springframework.context.ApplicationContext;
@@ -80,7 +79,6 @@ import org.springframework.util.ReflectionUtils;
import static java.util.Collections.singletonList;
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);
}
@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" })
@Test
public void testNoConversionOnInputMapIfInputIsMap() {