[Fix] a bug in ClearRealmCacheTests

Original commit: elastic/x-pack-elasticsearch@8d8fdf4c2a
This commit is contained in:
uboness 2015-01-16 18:36:58 +01:00
parent 56957f98bc
commit 9e078f4924

View File

@ -41,7 +41,7 @@ public class ClearRealmsCacheTests extends ShieldIntegrationTest {
public static void init() throws Exception { public static void init() throws Exception {
usernames = new String[randomIntBetween(5, 10)]; usernames = new String[randomIntBetween(5, 10)];
for (int i = 0; i < usernames.length; i++) { for (int i = 0; i < usernames.length; i++) {
usernames[i] = "user_" + i; usernames[i] = randomAsciiOfLength(6) + "_" + i;
} }
} }
@ -63,6 +63,9 @@ public class ClearRealmsCacheTests extends ShieldIntegrationTest {
EVICT_SOME() { EVICT_SOME() {
private final String[] evicted_usernames = randomSelection(usernames); private final String[] evicted_usernames = randomSelection(usernames);
{
Arrays.sort(evicted_usernames);
}
@Override @Override
public ClearRealmCacheRequest createRequest() { public ClearRealmCacheRequest createRequest() {
@ -194,11 +197,13 @@ public class ClearRealmsCacheTests extends ShieldIntegrationTest {
// selects a random sub-set of the give values // selects a random sub-set of the give values
private static String[] randomSelection(String[] values) { private static String[] randomSelection(String[] values) {
double base = randomDouble();
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
for (String value : values) { while (list.isEmpty()) {
if (randomDouble() < base) { double base = randomDouble();
list.add(value); for (String value : values) {
if (randomDouble() < base) {
list.add(value);
}
} }
} }
return list.toArray(new String[list.size()]); return list.toArray(new String[list.size()]);