Skip to content

ISSUE-1106: Added multi-threading support to cucumber-glue scope #1107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@
import java.util.Map;

class GlueCodeContext {
public static final GlueCodeContext INSTANCE = new GlueCodeContext();

private static final ThreadLocal<GlueCodeContext> localContext = new ThreadLocal<GlueCodeContext>() {
protected GlueCodeContext initialValue() {
return new GlueCodeContext();
}
};

private final Map<String, Object> objects = new HashMap<String, Object>();
private final Map<String, Runnable> callbacks = new HashMap<String, Runnable>();
private int counter;

private GlueCodeContext() {
}

public static GlueCodeContext getInstance() {
return localContext.get();
}

public void start() {
cleanUp();
counter++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
class GlueCodeScope implements Scope {
public static final String NAME = "cucumber-glue";

private final GlueCodeContext context = GlueCodeContext.INSTANCE;

@Override
public Object get(String name, ObjectFactory<?> objectFactory) {
GlueCodeContext context = GlueCodeContext.getInstance();
Object obj = context.get(name);
if (obj == null) {
obj = objectFactory.getObject();
Expand All @@ -21,11 +20,13 @@ public Object get(String name, ObjectFactory<?> objectFactory) {

@Override
public Object remove(String name) {
GlueCodeContext context = GlueCodeContext.getInstance();
return context.remove(name);
}

@Override
public void registerDestructionCallback(String name, Runnable callback) {
GlueCodeContext context = GlueCodeContext.getInstance();
context.registerDestructionCallback(name, callback);
}

Expand All @@ -36,6 +37,7 @@ public Object resolveContextualObject(String key) {

@Override
public String getConversationId() {
GlueCodeContext context = GlueCodeContext.getInstance();
return context.getId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void start() {
registerStepClassBeanDefinition(beanFactory, stepClass);
}
}
GlueCodeContext.INSTANCE.start();
GlueCodeContext.getInstance().start();
}

@SuppressWarnings("resource")
Expand Down Expand Up @@ -161,7 +161,7 @@ private void registerStepClassBeanDefinition(ConfigurableListableBeanFactory bea
@Override
public void stop() {
notifyContextManagerAboutTestClassFinished();
GlueCodeContext.INSTANCE.stop();
GlueCodeContext.getInstance().stop();
}

private void notifyContextManagerAboutTestClassFinished() {
Expand Down