-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Guice] Replace CucumberModules.SCENARIO with threadsafe factory method
Fixes an issue where the same SequentialScenarioScope is shared across multiple threads when running in parallel. This causes IllegalStateExceptions to be thrown. CucumberModules.SCENARIO and CucumberScopes.SCENARIO have been deprecated and replaced with a factory methods - CucumberModules.createScenarioModule() and CucumberScopes.createScenario() respectively. Fixes: #1485
- Loading branch information
1 parent
98ca518
commit 4ac37a8
Showing
6 changed files
with
71 additions
and
23 deletions.
There are no files selected for viewing
25 changes: 22 additions & 3 deletions
25
guice/src/main/java/cucumber/api/guice/CucumberModules.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,32 @@ | ||
package cucumber.api.guice; | ||
|
||
import com.google.inject.Module; | ||
import cucumber.runtime.java.guice.ScenarioScope; | ||
import cucumber.runtime.java.guice.ScenarioScoped; | ||
import cucumber.runtime.java.guice.impl.ScenarioModule; | ||
|
||
/** | ||
* Provides a convenient <code>com.google.inject.Module</code> instance that contains bindings for | ||
* <code>cucumber.runtime.java.guice.ScenarioScoped</code> annotation and for | ||
* <code>cucumber.runtime.java.guice.ScenarioScope</code>. | ||
* Provides a convenient {@link Module} instance that contains bindings for | ||
* {@link ScenarioScoped} annotation and for {@link ScenarioScope}. | ||
*/ | ||
public class CucumberModules { | ||
/** | ||
* A convenient instance of {@link Module}. Should only be used | ||
* in combination with {@link CucumberScopes#SCENARIO}. | ||
* <p> | ||
* Note that using this in combination with parallel execution results in | ||
* undefined behaviour. | ||
* | ||
* @deprecated please use {@link #createScenarioModule()} instead | ||
*/ | ||
@Deprecated | ||
public static final Module SCENARIO = new ScenarioModule(CucumberScopes.SCENARIO); | ||
|
||
public static Module createScenarioModule() { | ||
return new ScenarioModule(CucumberScopes.createScenarioScope()); | ||
} | ||
|
||
public static Module createScenarioModule(ScenarioScope scenarioScope) { | ||
return new ScenarioModule(scenarioScope); | ||
} | ||
} |
31 changes: 29 additions & 2 deletions
31
guice/src/main/java/cucumber/api/guice/CucumberScopes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,39 @@ | ||
package cucumber.api.guice; | ||
|
||
import com.google.inject.Module; | ||
import cucumber.runtime.java.guice.ScenarioScope; | ||
import cucumber.runtime.java.guice.ScenarioScoped; | ||
import cucumber.runtime.java.guice.impl.SequentialScenarioScope; | ||
|
||
/** | ||
* Provides a convenient <code>cucumber.runtime.java.guice.ScenarioScope</code> instance for use when declaring bindings | ||
* in implementations of <code>com.google.inject.Module</code>. | ||
* Creates an instance of {@link ScenarioScope} for use when declaring bindings | ||
* in implementations of {@link Module}. | ||
* <p> | ||
* Note that when binding objects to the scenario scope it is recommended to bind | ||
* them to the {@link ScenarioScoped} annotation instead. E.g: | ||
* | ||
* <code>bind(ScenarioScopedObject.class).in(ScenarioScoped.class);</code> | ||
*/ | ||
public class CucumberScopes { | ||
/** | ||
* A convenient instance of {@link ScenarioScope}. Should only be used | ||
* in combination with {@link CucumberModules#SCENARIO}. | ||
* <p> | ||
* Note that using this in combination with parallel execution results in | ||
* undefined behaviour. | ||
* | ||
* @deprecated please use {@link #createScenarioScope()} instead | ||
*/ | ||
@Deprecated | ||
public static final ScenarioScope SCENARIO = new SequentialScenarioScope(); | ||
|
||
/** | ||
* Creates a new instance of a ScenarioScope. | ||
* | ||
* @return a new instance of a ScenarioScope. | ||
*/ | ||
public static ScenarioScope createScenarioScope() { | ||
return new SequentialScenarioScope(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters