Apache Solr open-source search software
SOLR-17265: Fix randomized PRS testing (#2436)
Houston Putmancae69c797330
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.javaindex e101e79961d..14ea22e7013 100644--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/CreateCollectionCmd.java@@ -76,6 +76,7 @@ import org.apache.solr.common.params.CollectionAdminParams;import org.apache.solr.common.params.CommonAdminParams;import org.apache.solr.common.params.CoreAdminParams;import org.apache.solr.common.params.ModifiableSolrParams;+import org.apache.solr.common.util.EnvUtils;import org.apache.solr.common.util.NamedList;import org.apache.solr.common.util.SimpleOrderedMap;import org.apache.solr.common.util.Utils;@@ -94,6 +95,8 @@ public class CreateCollectionCmd implements CollApiCmds.CollectionApiCommand {private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());private final CollectionCommandContext ccc;+ public static final String PRS_DEFAULT_PROP = "solr.prs.default";+public CreateCollectionCmd(CollectionCommandContext ccc) {this.ccc = ccc;}@@ -109,7 +112,7 @@ public class CreateCollectionCmd implements CollApiCmds.CollectionApiCommand {final boolean waitForFinalState = message.getBool(WAIT_FOR_FINAL_STATE, false);final String alias = message.getStr(ALIAS, collectionName);log.info("Create collection {}", collectionName);- boolean prsDefault = Boolean.parseBoolean(System.getProperty("solr.prs.default", "false"));+ boolean prsDefault = EnvUtils.getEnvAsBool(PRS_DEFAULT_PROP, false);final boolean isPRS = message.getBool(CollectionStateProps.PER_REPLICA_STATE, prsDefault);if (log.isInfoEnabled()) {log.info(diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractBasicDistributedZk2TestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractBasicDistributedZk2TestBase.javaindex f50cb9b2aa4..056c5e69c5e 100644--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractBasicDistributedZk2TestBase.java+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractBasicDistributedZk2TestBase.java@@ -16,8 +16,7 @@*/package org.apache.solr.cloud;-import static org.apache.solr.cloud.SolrCloudTestCase.setPrsDefault;-import static org.apache.solr.cloud.SolrCloudTestCase.unsetPrsDefault;+import static org.apache.solr.cloud.SolrCloudTestCase.configurePrsDefault;import java.nio.file.Files;import java.nio.file.Path;@@ -40,8 +39,7 @@ import org.apache.solr.common.params.ModifiableSolrParams;import org.apache.solr.embedded.JettySolrRunner;import org.apache.solr.handler.BackupStatusChecker;import org.apache.solr.handler.ReplicationHandler;-import org.junit.After;-import org.junit.Before;+import org.junit.BeforeClass;import org.junit.Test;/**@@ -71,14 +69,9 @@ public abstract class AbstractBasicDistributedZk2TestBase extends AbstractFullDi// and it's TestInjection use}- @After- public void _unsetPrsDefault() {- unsetPrsDefault();- }-- @Before- public void _setPrsDefault() {- setPrsDefault();+ @BeforeClass+ public static void _setPrsDefault() {+ configurePrsDefault();}@Testdiff --git a/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java b/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.javaindex 7010666edbd..37d200f0f02 100644--- a/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java+++ b/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java@@ -17,6 +17,8 @@package org.apache.solr.cloud;+import static org.apache.solr.cloud.api.collections.CreateCollectionCmd.PRS_DEFAULT_PROP;+import com.carrotsearch.randomizedtesting.RandomizedTest;import java.io.IOException;import java.lang.annotation.ElementType;@@ -51,12 +53,11 @@ import org.apache.solr.common.cloud.Replica;import org.apache.solr.common.cloud.Slice;import org.apache.solr.common.cloud.SolrZkClient;import org.apache.solr.common.cloud.ZkStateReader;+import org.apache.solr.common.util.EnvUtils;import org.apache.solr.common.util.NamedList;import org.apache.solr.embedded.JettySolrRunner;-import org.junit.After;import org.junit.AfterClass;import org.junit.Before;-import org.junit.BeforeClass;import org.slf4j.Logger;import org.slf4j.LoggerFactory;@@ -83,8 +84,6 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());- public static final String PRS_DEFAULT_PROP = System.getProperty("use.per-replica", null);-// this is an important timeout for test stability - can't be too shortpublic static final int DEFAULT_TIMEOUT = 45;@@ -97,11 +96,12 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {return cluster.getZkStateReader().getZkClient();}- /** if the system property is not specified, use a random value */+ /**+ * if the system property is not specified, default to false. The SystemProperty will be set in a+ * beforeClass method.+ */public static boolean isPRS() {- return PRS_DEFAULT_PROP == null- ? random().nextBoolean()- : Boolean.parseBoolean(PRS_DEFAULT_PROP);+ return EnvUtils.getEnvAsBool(PRS_DEFAULT_PROP, false);}/**@@ -116,7 +116,9 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {// By default the MiniSolrCloudCluster being built will randomly (seed based) decide which// collection API strategy to use (distributed or Overseer based) and which cluster update// strategy to use (distributed if collection API is distributed, but Overseer based or- // distributed randomly chosen if Collection API is Overseer based)+ // distributed randomly chosen if Collection API is Overseer based), and whether to use PRS++ configurePrsDefault();boolean useDistributedCollectionConfigSetExecution = LuceneTestCase.random().nextInt(2) == 0;boolean useDistributedClusterStateUpdate =@@ -126,6 +128,17 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {useDistributedCollectionConfigSetExecution, useDistributedClusterStateUpdate);}+ public static void configurePrsDefault() {+ Class<?> target = RandomizedTest.getContext().getTargetClass();+ boolean usePrs;+ if (target != null && target.isAnnotationPresent(NoPrs.class)) {+ usePrs = false;+ } else {+ usePrs = EnvUtils.getEnvAsBool(PRS_DEFAULT_PROP, LuceneTestCase.random().nextBoolean());+ }+ System.setProperty(PRS_DEFAULT_PROP, usePrs ? "true" : "false");+ }+@AfterClasspublic static void shutdownCluster() throws Exception {if (cluster != null) {@@ -137,34 +150,6 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {}}- @BeforeClass- public static void setPrsDefault() {- Class<?> target = RandomizedTest.getContext().getTargetClass();- if (target != null && target.isAnnotationPresent(NoPrs.class)) return;- if (isPRS()) {- System.setProperty("solr.prs.default", "true");- }- }-- @After- public void _unsetPrsDefault() {- unsetPrsDefault();- }-- @Before- public void _setPrsDefault() {- setPrsDefault();- }-- @AfterClass- public static void unsetPrsDefault() {- Class<?> target = RandomizedTest.getContext().getTargetClass();- if (target != null && target.isAnnotationPresent(NoPrs.class)) return;- if (isPRS()) {- System.clearProperty("solr.prs.default");- }- }-@Beforepublic void checkClusterConfiguration() {}