You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2015/01/06 18:48:45 UTC
svn commit: r1649888 - in /lucene/dev/branches/branch_5x: ./ solr/
solr/core/ solr/core/src/java/org/apache/solr/core/JarRepository.java
Author: shalin
Date: Tue Jan 6 17:48:44 2015
New Revision: 1649888
URL: http://svn.apache.org/r1649888
Log:
SOLR-6801: Use static random initialized with random.seed and use it in Collections.shuffle to make forbidden-api checks pass
Modified:
lucene/dev/branches/branch_5x/ (props changed)
lucene/dev/branches/branch_5x/solr/ (props changed)
lucene/dev/branches/branch_5x/solr/core/ (props changed)
lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/core/JarRepository.java
Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/core/JarRepository.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/core/JarRepository.java?rev=1649888&r1=1649887&r2=1649888&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/core/JarRepository.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/core/JarRepository.java Tue Jan 6 17:48:44 2015
@@ -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;
@@ -50,6 +51,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;
@@ -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");