lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dawid Weiss <>
Subject Re: Possible problem with RAMDirectory; tips please
Date Mon, 08 Apr 2013 21:05:41 GMT
> thought I checked for that but apparently I got confused.  I do find it
> disconcerting that the random seed can get incremented by
> LuceneTestCase.newDirectory() a different number of times depending on
> wether or not -Dtests.seed has been set.

It's not really like that. By passing -Dtests.seed you're not "just"
incrementing/ changing the random generator. You're starting from a
different seed so you're running a whole different execution scenario.
Think of it as Heisenberg's uncertainty principle -- if you've touched
something on the lab plate (anything) then the outcome will be

If you want your test to pick a random directory but make this choice
insensitive to tests.seed then use the newDirectory(Random) method
with a "forked" random number generator. As in here:

Random forkedRandom = new Random(random().nextLong());
Directory myDirectory = LuceneTestCase.newDirectory(forkedRandom);

then you can change "myDirectory" to your liking and it won't affect
the default random generator...

Random forkedRandom = new Random(random().nextLong());
// you don't even need to call newDirectory(forkedRandom) but I'll keep it here.
Directory myDirectory = LuceneTestCase.newDirectory(forkedRandom);
// temporarily substitute with something else...
myDirectory = ...;

> test that uses randomization to "just" change the directory for a given test
> run (i.e. for a given seed).  It would be nice if there was a mechanism to
> restore the random state so you could restore it from when it was captured
> at the beginning of a method call.  This wouldn't just apply to
> newDirectory() but to some other similar utility methods.

I'm sorry but I don't see the advantage of that. You're trying to do
something for which better alternatives exist, as explained above. If
your code wants to make certain branch/ logic independent of the
default randomness you can just use your own Random instance (seeded
with a constant or whatever else that comes to your mind or is helpful
in the context).


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message