GH-752 Add support to stop caching functions in FunctionCatalog

Resolves #752
This commit is contained in:
Oleg Zhurakousky
2021-10-07 15:02:06 +02:00
parent c4922da6a3
commit 7c8d32246a
2 changed files with 52 additions and 7 deletions

View File

@@ -86,6 +86,39 @@ public class SimpleFunctionRegistryTests {
this.conversionService = new DefaultConversionService();
}
@Test
public void testCachingOfFunction() {
Echo function = new Echo();
FunctionRegistration<Echo> registration = new FunctionRegistration<>(
function, "echo").type(FunctionType.of(Echo.class));
SimpleFunctionRegistry catalog = new SimpleFunctionRegistry(this.conversionService, this.messageConverter,
new JacksonMapper(new ObjectMapper()));
catalog.register(registration);
FunctionInvocationWrapper instanceA = catalog.lookup("echo", "application/json");
FunctionInvocationWrapper instanceb = catalog.lookup("echo", "text/plain");
FunctionInvocationWrapper instanceC = catalog.lookup("echo", "foo/bar");
assertThat(instanceA).isSameAs(instanceb).isSameAs(instanceC);
}
@Test
public void testNoCachingOfFunction() {
Echo function = new Echo();
FunctionRegistration<Echo> registration = new FunctionRegistration<>(
function, "echo").type(FunctionType.of(Echo.class));
registration.getProperties().put("singleton", "false");
SimpleFunctionRegistry catalog = new SimpleFunctionRegistry(this.conversionService, this.messageConverter,
new JacksonMapper(new ObjectMapper()));
catalog.register(registration);
FunctionInvocationWrapper instanceA = catalog.lookup("echo", "application/json");
FunctionInvocationWrapper instanceb = catalog.lookup("echo", "text/plain");
FunctionInvocationWrapper instanceC = catalog.lookup("echo", "foo/bar");
assertThat(instanceA).isNotSameAs(instanceb).isNotSameAs(instanceC);
}
@Test
public void testSCF640() {
Echo function = new Echo();