Skip to content

Commit cae69c7

Browse files
SOLR-17265: Fix randomized PRS testing (#2436)
"use.per-replica" is no longer supported, only "solr.prs.default", which is the property that Solr itself uses.
1 parent f468120 commit cae69c7

File tree

3 files changed

+31
-50
lines changed

3 files changed

+31
-50
lines changed

solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import org.apache.solr.common.params.CommonAdminParams;
7777
import org.apache.solr.common.params.CoreAdminParams;
7878
import org.apache.solr.common.params.ModifiableSolrParams;
79+
import org.apache.solr.common.util.EnvUtils;
7980
import org.apache.solr.common.util.NamedList;
8081
import org.apache.solr.common.util.SimpleOrderedMap;
8182
import org.apache.solr.common.util.Utils;
@@ -94,6 +95,8 @@ public class CreateCollectionCmd implements CollApiCmds.CollectionApiCommand {
9495
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
9596
private final CollectionCommandContext ccc;
9697

98+
public static final String PRS_DEFAULT_PROP = "solr.prs.default";
99+
97100
public CreateCollectionCmd(CollectionCommandContext ccc) {
98101
this.ccc = ccc;
99102
}
@@ -109,7 +112,7 @@ public void call(ClusterState clusterState, ZkNodeProps message, NamedList<Objec
109112
final boolean waitForFinalState = message.getBool(WAIT_FOR_FINAL_STATE, false);
110113
final String alias = message.getStr(ALIAS, collectionName);
111114
log.info("Create collection {}", collectionName);
112-
boolean prsDefault = Boolean.parseBoolean(System.getProperty("solr.prs.default", "false"));
115+
boolean prsDefault = EnvUtils.getEnvAsBool(PRS_DEFAULT_PROP, false);
113116
final boolean isPRS = message.getBool(CollectionStateProps.PER_REPLICA_STATE, prsDefault);
114117
if (log.isInfoEnabled()) {
115118
log.info(

solr/test-framework/src/java/org/apache/solr/cloud/AbstractBasicDistributedZk2TestBase.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
*/
1717
package org.apache.solr.cloud;
1818

19-
import static org.apache.solr.cloud.SolrCloudTestCase.setPrsDefault;
20-
import static org.apache.solr.cloud.SolrCloudTestCase.unsetPrsDefault;
19+
import static org.apache.solr.cloud.SolrCloudTestCase.configurePrsDefault;
2120

2221
import java.nio.file.Files;
2322
import java.nio.file.Path;
@@ -40,8 +39,7 @@
4039
import org.apache.solr.embedded.JettySolrRunner;
4140
import org.apache.solr.handler.BackupStatusChecker;
4241
import org.apache.solr.handler.ReplicationHandler;
43-
import org.junit.After;
44-
import org.junit.Before;
42+
import org.junit.BeforeClass;
4543
import org.junit.Test;
4644

4745
/**
@@ -71,14 +69,9 @@ protected boolean useTlogReplicas() {
7169
// and it's TestInjection use
7270
}
7371

74-
@After
75-
public void _unsetPrsDefault() {
76-
unsetPrsDefault();
77-
}
78-
79-
@Before
80-
public void _setPrsDefault() {
81-
setPrsDefault();
72+
@BeforeClass
73+
public static void _setPrsDefault() {
74+
configurePrsDefault();
8275
}
8376

8477
@Test

solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.apache.solr.cloud;
1919

20+
import static org.apache.solr.cloud.api.collections.CreateCollectionCmd.PRS_DEFAULT_PROP;
21+
2022
import com.carrotsearch.randomizedtesting.RandomizedTest;
2123
import java.io.IOException;
2224
import java.lang.annotation.ElementType;
@@ -51,12 +53,11 @@
5153
import org.apache.solr.common.cloud.Slice;
5254
import org.apache.solr.common.cloud.SolrZkClient;
5355
import org.apache.solr.common.cloud.ZkStateReader;
56+
import org.apache.solr.common.util.EnvUtils;
5457
import org.apache.solr.common.util.NamedList;
5558
import org.apache.solr.embedded.JettySolrRunner;
56-
import org.junit.After;
5759
import org.junit.AfterClass;
5860
import org.junit.Before;
59-
import org.junit.BeforeClass;
6061
import org.slf4j.Logger;
6162
import 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

Comments
 (0)