// BeanFactoryAwareFunctionRegistryTests.java
@Test
public void testBoundedFunctionCache() throws Exception {
FunctionCatalog catalog = this.configureCatalog(CompositionWithNullReturnInBetween.class);
Field wrappedFunctionDefinitionsCacheSizeField = ReflectionUtils
.findField(catalog.getClass(), "wrappedFunctionDefinitionsCacheSize");
wrappedFunctionDefinitionsCacheSizeField.setAccessible(true);
wrappedFunctionDefinitionsCacheSizeField.set(catalog, 10);
Field wrappedFunctionDefinitionsField = ReflectionUtils
.findField(catalog.getClass(), "wrappedFunctionDefinitions");
wrappedFunctionDefinitionsField.setAccessible(true);
int threadCount = 20;
CountDownLatch latch = new CountDownLatch(threadCount);
for (int i = 0; i < threadCount; i++) {
new Thread(() -> {
catalog.lookup("echo1|echo2|echo1|echo2|echo1|echo2|echo1|echo2");
catalog.lookup("echo2|echo1|echo2|echo1|echo2|echo1|echo2|echo1|echo2|echo1|echo2|echo1|echo2|echo1|echo2|echo1");
latch.countDown();
}).start();
}
latch.await();
assertThat(((Map<?, ?>) (wrappedFunctionDefinitionsField.get(catalog))).size()).isEqualTo(10);
}
Describe the bug
branch: 4.3.x
SimpleFunctionRegistry.wrappedFunctionDefinitionsis not thread-safe. And thetestBoundedFunctionCachetestcase inBeanFactoryAwareFunctionRegistryTests.javashould test onwrappedFunctionDefinitions.size()but notcatalog.size().Sample