[
https://issues.apache.org/jira/browse/LUCENE-4020?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13262228#comment-13262228
]
Hoss Man commented on LUCENE-4020:
----------------------------------
straw man suggestion:
change the impl of randomLocale(Random) to ensure that it only returns Locale
objects that can be round tripped...
{code}
public static Locale randomLocale(final Random outerRandom) {
// consume a fixed amount of randomness from outerRandom
final Random random = new Random(outerRandom.nextLong());
Locale locales[] = Locale.getAvailableLocales();
Locale result = null;
for (int i = 0; i < 100; i++) {
Locale candidate = locales[random.nextInt(locales.length)];
try {
Locale roundTrip = localeForName(candidate.toString());
if (candidate.equals(roundTrip)) {
result = candidate;
break;
}
} catch (Exception e) {
// :NOOP: ... go around again
}
}
if (null == result) {
throw new YourJvmIsFuckedException("Gave up trying to pick a random Locale")
}
return result;
}
{code}
> Tests may not be repeatable across different platforms/ JVMs due to different
> locale/ timezone being picked.
> ------------------------------------------------------------------------------------------------------------
>
> Key: LUCENE-4020
> URL: https://issues.apache.org/jira/browse/LUCENE-4020
> Project: Lucene - Java
> Issue Type: Bug
> Reporter: Dawid Weiss
> Assignee: Dawid Weiss
> Priority: Minor
> Fix For: 4.0
>
> Attachments: LUCENE-4020.diff, LUCENE-4020.patch
>
>
> This is because the source array can be/ is different for each system/ JVM.
> So this pick is not repeatable for example:
> {code}
> /**
> * Return a random Locale from the available locales on the system.
> */
> public static Locale randomLocale(Random random) {
> Locale locales[] = Locale.getAvailableLocales();
> return locales[random.nextInt(locales.length)];
> }
> {code}
> I don't think there is much we can do to make it repeatable (other than maybe
> enforcing locale using system property).
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]