I am running JUnit tests on a Spring3 app on two different platforms (Win7 and Ubuntu PP).
For testing/reproducibility purposes I have set the seed of my random generator in my application context
<bean class="org.apache.commons.math3.random.MersenneTwister">
<property name="seed" value="1111111" />
</bean>
Now this test
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration( { Config.APP_CONFIG_PATH })
public class StatTestAtomicInitOut {
@Autowired
RandomGenerator rg;
@Test
public void testRandomGenerator() {
Assert.assertEquals(9183, rg.nextInt(10000));
}
}
passes consistently in Windows7, but fails consistently on Ubuntu PP (java.lang.AssertionError: expected:<9183> but was:<9561>).
This other test
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration( { Config.APP_CONFIG_PATH })
public class StatTestAtomicInitIn {
@Autowired
RandomGenerator rg;
@Test
public void testRandomGenerator() {
rg.setSeed(new Long(1111111));
Assert.assertEquals(9183, rg.nextInt(10000));
}
}
passes consistently both on Windows7 and on Ubuntu PP.
Why does Spring initialization of the random generator on Ubuntu (but not on Win7) yield results which are diffrent from those obtained setting the seed at runtime?
Thanks in advance for any feedback.
aa
With this configuration
the tests pass on both platforms.
Thanks to Tom McIntyre for putting me on the right track.
Another possibility is
for which the tests pass.
The somewhat academic question of why Spring chooses different default setters on different platforms remains unanswered. Curiously, for me at least, with the following configuration
StatTestAtomicInitOut passes on win7, but fails on Ubuntu.