mirror of https://github.com/apache/lucene.git
SOLR-6801: Use static random initialized with random.seed and use it in Collections.shuffle to make forbidden-api checks pass
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1649877 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
037b72a00c
commit
76fa1005db
|
@ -27,6 +27,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
@ -51,6 +52,18 @@ import org.slf4j.LoggerFactory;
|
|||
public class JarRepository {
|
||||
public static Logger log = LoggerFactory.getLogger(JarRepository.class);
|
||||
|
||||
static final Random RANDOM;
|
||||
static {
|
||||
// We try to make things reproducible in the context of our tests by initializing the random instance
|
||||
// based on the current seed
|
||||
String seed = System.getProperty("tests.seed");
|
||||
if (seed == null) {
|
||||
RANDOM = new Random();
|
||||
} else {
|
||||
RANDOM = new Random(seed.hashCode());
|
||||
}
|
||||
}
|
||||
|
||||
private final CoreContainer coreContainer;
|
||||
|
||||
private Map<String,JarContent> jars = new ConcurrentHashMap<>();
|
||||
|
@ -75,7 +88,7 @@ public class JarRepository {
|
|||
if (coll == null) throw new SolrException(SERVICE_UNAVAILABLE, ".system collection not available");
|
||||
ArrayList<Slice> slices = new ArrayList<>(coll.getActiveSlices());
|
||||
if (slices.isEmpty()) throw new SolrException(SERVICE_UNAVAILABLE, ".no active slices for .system collection");
|
||||
Collections.shuffle(slices); //do load balancing
|
||||
Collections.shuffle(slices, RANDOM); //do load balancing
|
||||
Slice slice = slices.get(0) ;
|
||||
Replica replica = slice.getReplicas().iterator().next();
|
||||
if (replica == null) throw new SolrException(SERVICE_UNAVAILABLE, ".no active replica available for .system collection");
|
||||
|
|
Loading…
Reference in New Issue