GH-444 Fixed support for default function lookup
Given that function can be looked up with no definition, the fallback alternative should be 'spring.cloud.function.definition' property Resolves #444
This commit is contained in:
@@ -125,6 +125,9 @@ public class BeanFactoryAwareFunctionRegistry
|
|||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T lookup(String definition, String... acceptedOutputTypes) {
|
public <T> T lookup(String definition, String... acceptedOutputTypes) {
|
||||||
|
if (!StringUtils.hasText(definition)) {
|
||||||
|
definition = this.applicationContext.getEnvironment().getProperty("spring.cloud.function.definition");
|
||||||
|
}
|
||||||
Object function = this.proxyInvokerIfNecessary((FunctionInvocationWrapper) this.compose(null, definition, acceptedOutputTypes));
|
Object function = this.proxyInvokerIfNecessary((FunctionInvocationWrapper) this.compose(null, definition, acceptedOutputTypes));
|
||||||
return (T) function;
|
return (T) function;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,6 +69,27 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
|||||||
return catalog;
|
return catalog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDefaultLookup() throws Exception {
|
||||||
|
FunctionCatalog catalog = this.configureCatalog();
|
||||||
|
Object function = catalog.lookup("");
|
||||||
|
assertThat(function).isNull();
|
||||||
|
//==
|
||||||
|
System.setProperty("spring.cloud.function.definition", "uppercase");
|
||||||
|
function = catalog.lookup("");
|
||||||
|
assertThat(function).isNotNull();
|
||||||
|
Field field = ReflectionUtils.findField(FunctionInvocationWrapper.class, "composed");
|
||||||
|
field.setAccessible(true);
|
||||||
|
assertThat(((boolean) field.get(function))).isFalse();
|
||||||
|
//==
|
||||||
|
System.setProperty("spring.cloud.function.definition", "uppercase|uppercaseFlux");
|
||||||
|
function = catalog.lookup("");
|
||||||
|
assertThat(function).isNotNull();
|
||||||
|
field = ReflectionUtils.findField(FunctionInvocationWrapper.class, "composed");
|
||||||
|
field.setAccessible(true);
|
||||||
|
assertThat(((boolean) field.get(function))).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImperativeFunction() {
|
public void testImperativeFunction() {
|
||||||
FunctionCatalog catalog = this.configureCatalog();
|
FunctionCatalog catalog = this.configureCatalog();
|
||||||
@@ -530,6 +551,7 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
|||||||
public void setId(int id) {
|
public void setId(int id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Person: " + name + "/" + id;
|
return "Person: " + name + "/" + id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2017-2019 the original author or authors.
|
* Copyright 2017-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -21,6 +21,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.util.function.Tuple2;
|
import reactor.util.function.Tuple2;
|
||||||
@@ -42,6 +43,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
*/
|
*/
|
||||||
public class FunctionDeployerTests {
|
public class FunctionDeployerTests {
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void before() {
|
||||||
|
System.clearProperty("spring.cloud.function.definition");
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Target function `class UpperCaseFunction implements Function<String, String>`
|
* Target function `class UpperCaseFunction implements Function<String, String>`
|
||||||
* Main/Start class present, no Spring configuration
|
* Main/Start class present, no Spring configuration
|
||||||
|
|||||||
Reference in New Issue
Block a user