Skip to content

Commit a3b45f4

Browse files
committed
GH-1204 Polishing aftre refactoring of TypeTools
1 parent 5e179a2 commit a3b45f4

File tree

4 files changed

+7
-46
lines changed

4 files changed

+7
-46
lines changed

spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/FunctionRegistration.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public FunctionRegistration<T> type(Type type) {
121121
if (KotlinDetector.isKotlinPresent() && this.target instanceof KotlinLambdaToFunctionAutoConfiguration.KotlinFunctionWrapper) {
122122
return this;
123123
}
124-
Type discoveredFunctionType = FunctionTypeUtils.discoverFunctionTypeFromClass(this.target.getClass());
124+
Type discoveredFunctionType = type; //FunctionTypeUtils.discoverFunctionTypeFromClass(this.target.getClass());
125125
if (discoveredFunctionType == null) { // only valid for Kafka Stream KStream[] return type.
126126
return null;
127127
}
@@ -146,7 +146,6 @@ else if (outputType == null && inputType != Object.class) {
146146
+ discoveredFunctionType + "; Provided: " + type);
147147
}
148148

149-
150149
return this;
151150
}
152151

spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/catalog/BeanFactoryAwareFunctionRegistry.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ else if (this.isSpecialFunctionRegistration(functionNames, functionName)) {
180180
else {
181181
functionType = FunctionTypeUtils.discoverFunctionType(functionCandidate, functionName, this.applicationContext);
182182
}
183+
184+
if (logger.isDebugEnabled()) {
185+
logger.debug("Discovered function type for: " + functionDefinition + " - " + functionType);
186+
}
183187
if (functionRegistration == null) {
184188
functionRegistration = new FunctionRegistration(functionCandidate, functionName).type(functionType);
185189
}

spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/catalog/FunctionTypeUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ else if (functionType instanceof ParameterizedType) {
371371
else {
372372
inputType = resolvableInputType.getType();
373373
}
374-
return inputType;
374+
return inputType instanceof TypeVariable ? Object.class : inputType;
375375
}
376376

377377
@SuppressWarnings("rawtypes")
@@ -465,7 +465,7 @@ else if (functionType instanceof ParameterizedType) {
465465
else {
466466
outputType = resolvableOutputType.getType();
467467
}
468-
return outputType;
468+
return outputType instanceof TypeVariable ? Object.class : outputType;
469469
}
470470

471471
public static Type getImmediateGenericType(Type type, int index) {

spring-cloud-function-context/src/test/java/org/springframework/cloud/function/context/catalog/BeanFactoryAwareFunctionRegistryTests.java

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
import org.springframework.boot.builder.SpringApplicationBuilder;
6060
import org.springframework.cloud.function.context.FunctionCatalog;
6161
import org.springframework.cloud.function.context.FunctionRegistration;
62-
import org.springframework.cloud.function.context.FunctionRegistry;
6362
import org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry.FunctionInvocationWrapper;
6463
import org.springframework.cloud.function.json.JsonMapper;
6564
import org.springframework.context.ApplicationContext;
@@ -80,7 +79,6 @@
8079

8180
import static java.util.Collections.singletonList;
8281
import static org.assertj.core.api.Assertions.assertThat;
83-
import static org.junit.jupiter.api.Assertions.fail;
8482

8583
/**
8684
*
@@ -671,46 +669,6 @@ public void testWithComplexHierarchyAndTypeConversion() {
671669
assertThat(f.apply(Flux.just(25)).blockFirst()).isEqualTo(25);
672670
}
673671

674-
@SuppressWarnings({ "unchecked", "rawtypes" })
675-
@Test
676-
public void testRegisteringWithTypeThatDoesNotMatchDiscoveredType() {
677-
FunctionCatalog catalog = this.configureCatalog(EmptyConfiguration.class);
678-
Function func = catalog.lookup("func");
679-
assertThat(func).isNull();
680-
FunctionRegistry registry = (FunctionRegistry) catalog;
681-
try {
682-
FunctionRegistration registration = new FunctionRegistration(new MyFunction(), "a")
683-
.type(FunctionTypeUtils.functionType(Integer.class, String.class));
684-
registry.register(registration);
685-
fail();
686-
}
687-
catch (IllegalArgumentException e) {
688-
// good as we expect it to fail
689-
}
690-
//
691-
try {
692-
FunctionRegistration registration = new FunctionRegistration(new MyFunction(), "b")
693-
.type(FunctionTypeUtils.functionType(String.class, Integer.class));
694-
registry.register(registration);
695-
fail();
696-
}
697-
catch (IllegalArgumentException e) {
698-
// good as we expect it to fail
699-
}
700-
//
701-
FunctionRegistration c = new FunctionRegistration(new MyFunction(), "c")
702-
.type(FunctionTypeUtils.functionType(String.class, String.class));
703-
registry.register(c);
704-
//
705-
FunctionRegistration d = new FunctionRegistration(new RawFunction(), "d")
706-
.type(FunctionTypeUtils.functionType(Person.class, String.class));
707-
registry.register(d);
708-
//
709-
FunctionRegistration e = new FunctionRegistration(new RawFunction(), "e")
710-
.type(FunctionTypeUtils.functionType(Object.class, Object.class));
711-
registry.register(e);
712-
}
713-
714672
@SuppressWarnings({ "unchecked", "rawtypes" })
715673
@Test
716674
public void testNoConversionOnInputMapIfInputIsMap() {

0 commit comments

Comments
 (0)