1717
1818package org .apache .solr .cloud ;
1919
20+ import static org .apache .solr .cloud .api .collections .CreateCollectionCmd .PRS_DEFAULT_PROP ;
21+
2022import com .carrotsearch .randomizedtesting .RandomizedTest ;
2123import java .io .IOException ;
2224import java .lang .annotation .ElementType ;
5153import org .apache .solr .common .cloud .Slice ;
5254import org .apache .solr .common .cloud .SolrZkClient ;
5355import org .apache .solr .common .cloud .ZkStateReader ;
56+ import org .apache .solr .common .util .EnvUtils ;
5457import org .apache .solr .common .util .NamedList ;
5558import org .apache .solr .embedded .JettySolrRunner ;
56- import org .junit .After ;
5759import org .junit .AfterClass ;
5860import org .junit .Before ;
59- import org .junit .BeforeClass ;
6061import org .slf4j .Logger ;
6162import org .slf4j .LoggerFactory ;
6263
@@ -83,8 +84,6 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
8384
8485 private static final Logger log = LoggerFactory .getLogger (MethodHandles .lookup ().lookupClass ());
8586
86- public static final String PRS_DEFAULT_PROP = System .getProperty ("use.per-replica" , null );
87-
8887 // this is an important timeout for test stability - can't be too short
8988 public static final int DEFAULT_TIMEOUT = 45 ;
9089
@@ -97,11 +96,12 @@ protected static SolrZkClient zkClient() {
9796 return cluster .getZkStateReader ().getZkClient ();
9897 }
9998
100- /** if the system property is not specified, use a random value */
99+ /**
100+ * if the system property is not specified, default to false. The SystemProperty will be set in a
101+ * beforeClass method.
102+ */
101103 public static boolean isPRS () {
102- return PRS_DEFAULT_PROP == null
103- ? random ().nextBoolean ()
104- : Boolean .parseBoolean (PRS_DEFAULT_PROP );
104+ return EnvUtils .getEnvAsBool (PRS_DEFAULT_PROP , false );
105105 }
106106
107107 /**
@@ -116,7 +116,9 @@ protected static MiniSolrCloudCluster.Builder configureCluster(int nodeCount) {
116116 // By default the MiniSolrCloudCluster being built will randomly (seed based) decide which
117117 // collection API strategy to use (distributed or Overseer based) and which cluster update
118118 // strategy to use (distributed if collection API is distributed, but Overseer based or
119- // distributed randomly chosen if Collection API is Overseer based)
119+ // distributed randomly chosen if Collection API is Overseer based), and whether to use PRS
120+
121+ configurePrsDefault ();
120122
121123 boolean useDistributedCollectionConfigSetExecution = LuceneTestCase .random ().nextInt (2 ) == 0 ;
122124 boolean useDistributedClusterStateUpdate =
@@ -126,6 +128,17 @@ protected static MiniSolrCloudCluster.Builder configureCluster(int nodeCount) {
126128 useDistributedCollectionConfigSetExecution , useDistributedClusterStateUpdate );
127129 }
128130
131+ public static void configurePrsDefault () {
132+ Class <?> target = RandomizedTest .getContext ().getTargetClass ();
133+ boolean usePrs ;
134+ if (target != null && target .isAnnotationPresent (NoPrs .class )) {
135+ usePrs = false ;
136+ } else {
137+ usePrs = EnvUtils .getEnvAsBool (PRS_DEFAULT_PROP , LuceneTestCase .random ().nextBoolean ());
138+ }
139+ System .setProperty (PRS_DEFAULT_PROP , usePrs ? "true" : "false" );
140+ }
141+
129142 @ AfterClass
130143 public static void shutdownCluster () throws Exception {
131144 if (cluster != null ) {
@@ -137,34 +150,6 @@ public static void shutdownCluster() throws Exception {
137150 }
138151 }
139152
140- @ BeforeClass
141- public static void setPrsDefault () {
142- Class <?> target = RandomizedTest .getContext ().getTargetClass ();
143- if (target != null && target .isAnnotationPresent (NoPrs .class )) return ;
144- if (isPRS ()) {
145- System .setProperty ("solr.prs.default" , "true" );
146- }
147- }
148-
149- @ After
150- public void _unsetPrsDefault () {
151- unsetPrsDefault ();
152- }
153-
154- @ Before
155- public void _setPrsDefault () {
156- setPrsDefault ();
157- }
158-
159- @ AfterClass
160- public static void unsetPrsDefault () {
161- Class <?> target = RandomizedTest .getContext ().getTargetClass ();
162- if (target != null && target .isAnnotationPresent (NoPrs .class )) return ;
163- if (isPRS ()) {
164- System .clearProperty ("solr.prs.default" );
165- }
166- }
167-
168153 @ Before
169154 public void checkClusterConfiguration () {}
170155
0 commit comments