Skip to content

Commit 231c856

Browse files
authored
Merge pull request #1153 from cucumber/fix-spring-factory
[Spring] Do not share ContextCache between threads
2 parents bf8efda + 6eece8d commit 231c856

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

History.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
* [Guice] Use the ContextClassLoader when loading InjectorSource. ([#1036](https://github.com/cucumber/cucumber-jvm/pull/1036), [#1037](https://github.com/cucumber/cucumber-jvm/pull/1037) Kyle Moore)
44
* [Core] Allow global registration of custom XStream converters. ([#1010](https://github.com/cucumber/cucumber-jvm/pull/1010), [#1009](https://github.com/cucumber/cucumber-jvm/issues/1009) Chris Rankin)
5-
* [Spring] Support multithreaded execution of scenarios ([#1106](https://github.com/cucumber/cucumber-jvm/issues/1106), [#1107](https://github.com/cucumber/cucumber-jvm/issues/1107), [#1148](https://github.com/cucumber/cucumber-jvm/issues/1148) Ismail Bhana, M.P. Korstanje)
5+
* [Spring] Support multithreaded execution of scenarios ([#1106](https://github.com/cucumber/cucumber-jvm/issues/1106), [#1107](https://github.com/cucumber/cucumber-jvm/issues/1107), [#1148](https://github.com/cucumber/cucumber-jvm/issues/1148), [#1153](https://github.com/cucumber/cucumber-jvm/pull/1153) Ismail Bhana, M.P. Korstanje)
66
* [Java8, Kotlin Java8] Support java 8 method references ([#1140](https://github.com/cucumber/cucumber-jvm/pull/1140) M.P. Korstanje)
77
* [Core] Show explicit error message when field name missed in table header ([#1014](https://github.com/cucumber/cucumber-jvm/pull/1014) Mykola Gurov)
88
* [Examples] Properly quit selenium in webbit examples ([#1146](https://github.com/cucumber/cucumber-jvm/pull/1146) Alberto Scotto)

spring/src/main/java/cucumber/runtime/java/spring/SpringFactory.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package cucumber.runtime.java.spring;
22

3-
import cucumber.runtime.CucumberException;
3+
import static org.springframework.test.context.FixBootstrapUtils.createBootstrapContext;
4+
import static org.springframework.test.context.FixBootstrapUtils.resolveTestContextBootstrapper;
5+
46
import cucumber.api.java.ObjectFactory;
7+
import cucumber.runtime.CucumberException;
58
import org.springframework.beans.BeansException;
69
import org.springframework.beans.factory.config.BeanDefinition;
710
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
@@ -202,12 +205,14 @@ private boolean annotatedWithSupportedSpringRootTestAnnotations(Class<?> type) {
202205

203206
class CucumberTestContextManager extends TestContextManager {
204207

205-
public CucumberTestContextManager(Class<?> testClass) {
206-
super(testClass);
208+
CucumberTestContextManager(Class<?> testClass) {
209+
// Does the same as TestContextManager(Class<?>) but creates a
210+
// DefaultCacheAwareContextLoaderDelegate that uses a thread local contextCache.
211+
super(resolveTestContextBootstrapper(createBootstrapContext(testClass)));
207212
registerGlueCodeScope(getContext());
208213
}
209214

210-
public ConfigurableListableBeanFactory getBeanFactory() {
215+
ConfigurableListableBeanFactory getBeanFactory() {
211216
return getContext().getBeanFactory();
212217
}
213218

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.springframework.test.context;
2+
3+
import org.springframework.test.context.cache.ContextCache;
4+
import org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate;
5+
import org.springframework.test.context.cache.DefaultContextCache;
6+
import org.springframework.test.context.support.DefaultBootstrapContext;
7+
8+
public class FixBootstrapUtils extends BootstrapUtils {
9+
10+
private static ThreadLocal<ContextCache> contextCache = new ThreadLocal<ContextCache>(){
11+
@Override
12+
protected ContextCache initialValue() {
13+
return new DefaultContextCache();
14+
}
15+
};
16+
17+
public static BootstrapContext createBootstrapContext(Class<?> testClass) {
18+
CacheAwareContextLoaderDelegate contextLoader = new DefaultCacheAwareContextLoaderDelegate(contextCache.get());
19+
return new DefaultBootstrapContext(testClass, contextLoader);
20+
}
21+
22+
public static TestContextBootstrapper resolveTestContextBootstrapper(BootstrapContext bootstrapContext) {
23+
return BootstrapUtils.resolveTestContextBootstrapper(bootstrapContext);
24+
}
25+
}

0 commit comments

Comments
 (0)