You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using JGiven version 0.11.4 -- my test class looks like:
@Test(singleThreaded=true)
public class Caching extends PegasusRestTest {
@Test
public void shouldCacheProduct() {
given_pegasus_machine_with_cache();
dukesClientActions
.when().deleting_key("1999757850_-1_-1");
....
It has few other similarly looking methods.
The deleting_key method is implemented as follows:
public class PegasusDukesClientActions<SELF extends PegasusDukesClientActions<SELF>>
extends GenericActions<DukesClient, SELF> {
@ExpectedScenarioState
protected ThreadLocal<CacheConfiguration> targetDukesConfiguration;
public SELF deleting_key(final String key) {
log.debug("deleting key {}", key); //$NON-NLS-1$
log.trace("targetDukesConfiguration = {}", targetDukesConfiguration);
try (val dukesClient = new DukesClientWrapper<>(
new InflateDeflateTranscoder(), targetDukesConfiguration.get())) { <<<--- NPE here
dukesClient.delete(key);
.....
The targetDukesConfiguration is initialized like this:
public class PegasusDukesClientFixtures<SELF extends PegasusDukesClientFixtures<SELF>>
extends GenericFixtures<DukesClient, SELF> {
@ProvidedScenarioState
protected final ThreadLocal<CacheConfiguration> targetDukesConfiguration =
new ThreadLocal<>();
public SELF a_Dukes_cache_at(final URI url, final int timeoutMs) {
log.debug("target Dukes cache at {}", url); //$NON-NLS-1$
targetDukesConfiguration.set(new CacheConfiguration() {
{
setHostsAndPorts(url.toString());
.....
Hence I expect in the PegasusDukesClientActions stage to have targetDukesConfiguration initialized at least with a new empty ThreadLocal.
However, when I am setting @test(singleThreaded=false) on Caching class I am sporadically getting a NullPointerException when accessing targetDukesConfiguration in the deleting_key method implementation above.
Sometimes it works, but most of the times it does not. Easy to reproduce :)
The text was updated successfully, but these errors were encountered:
adrian-herscu
changed the title
@ScenarioState is not injected while running multithreaded under TestNG
@ScenarioState sometimes not injected while running multithreaded under TestNG
Oct 9, 2016
Using JGiven version 0.11.4 -- my test class looks like:
It has few other similarly looking methods.
The
deleting_key
method is implemented as follows:The
targetDukesConfiguration
is initialized like this:Hence I expect in the
PegasusDukesClientActions
stage to havetargetDukesConfiguration
initialized at least with a new emptyThreadLocal
.However, when I am setting @test(singleThreaded=false) on
Caching
class I am sporadically getting aNullPointerException
when accessingtargetDukesConfiguration
in thedeleting_key
method implementation above.Here is a log with just two test methods:
Sometimes it works, but most of the times it does not. Easy to reproduce :)
The text was updated successfully, but these errors were encountered: