Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-14920: Spotless formatting for test-framework (#704)

Kevin Risden2b567e7bb23a
diff --git a/gradle/validation/spotless.gradle b/gradle/validation/spotless.gradle
index cfc765e70d6..c69f06f2656 100644
--- a/gradle/validation/spotless.gradle
+++ b/gradle/validation/spotless.gradle
@@ -46,7 +46,6 @@ configure(project(":solr").subprojects) { prj ->
switch (project.path) {
case ":solr:core":
case ":solr:solrj":
- case ":solr:test-framework":
targetExclude "src/**/*.java"
break
case ":solr:modules:hdfs":
diff --git a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
index fe19dea0520..24409fe114b 100644
--- a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
+++ b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
@@ -42,9 +42,8 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
-
import javax.servlet.Filter;
-
+import junit.framework.Assert;
import org.apache.commons.io.FileUtils;
import org.apache.lucene.util.Constants;
import org.apache.lucene.util.TestUtil;
@@ -75,65 +74,65 @@ import org.junit.runners.model.Statement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import junit.framework.Assert;
-
/**
* Helper base class for distributed search test cases
*
- * By default, all tests in sub-classes will be executed with
- * 1, 2, ... DEFAULT_MAX_SHARD_COUNT number of shards set up repeatedly.
+ * <p>By default, all tests in sub-classes will be executed with 1, 2, ... DEFAULT_MAX_SHARD_COUNT
+ * number of shards set up repeatedly.
*
- * In general, it's preferable to annotate the tests in sub-classes with a
- * {@literal @}ShardsFixed(num = N) or a {@literal @}ShardsRepeat(min = M, max = N)
- * to indicate whether the test should be called once, with a fixed number of shards,
- * or called repeatedly for number of shards = M to N.
+ * <p>In general, it's preferable to annotate the tests in sub-classes with a
+ * {@literal @}ShardsFixed(num = N) or a {@literal @}ShardsRepeat(min = M, max = N) to indicate
+ * whether the test should be called once, with a fixed number of shards, or called repeatedly for
+ * number of shards = M to N.
*
- * In some cases though, if the number of shards has to be fixed, but the number
- * itself is dynamic, or if it has to be set as a default for all sub-classes
- * of a sub-class, there's a fixShardCount(N) available, which is identical to
- * {@literal @}ShardsFixed(num = N) for all tests without annotations in that class
- * hierarchy. Ideally this function should be retired in favour of better annotations..
+ * <p>In some cases though, if the number of shards has to be fixed, but the number itself is
+ * dynamic, or if it has to be set as a default for all sub-classes of a sub-class, there's a
+ * fixShardCount(N) available, which is identical to {@literal @}ShardsFixed(num = N) for all tests
+ * without annotations in that class hierarchy. Ideally this function should be retired in favour of
+ * better annotations..
*
* @since solr 1.5
*/
public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
-
- protected ExecutorService executor = new ExecutorUtil.MDCAwareThreadPoolExecutor(
- 4,
- Integer.MAX_VALUE,
- 15, TimeUnit.SECONDS, // terminate idle threads after 15 sec
- new SynchronousQueue<>(), // directly hand off tasks
- new SolrNamedThreadFactory("BaseDistributedSearchTestCase"),
- false
- );
-
+
+ protected ExecutorService executor =
+ new ExecutorUtil.MDCAwareThreadPoolExecutor(
+ 4,
+ Integer.MAX_VALUE,
+ 15,
+ TimeUnit.SECONDS, // terminate idle threads after 15 sec
+ new SynchronousQueue<>(), // directly hand off tasks
+ new SolrNamedThreadFactory("BaseDistributedSearchTestCase"),
+ false);
+
// TODO: this shouldn't be static. get the random when you need it to avoid sharing.
public static Random r;
-
+
private AtomicInteger nodeCnt = new AtomicInteger(0);
protected boolean useExplicitNodeNames;
-
+
@BeforeClass
public static void initialize() {
- assumeFalse("SOLR-4147: ibm 64bit has jvm bugs!", Constants.JRE_IS_64BIT && Constants.JAVA_VENDOR.startsWith("IBM"));
+ assumeFalse(
+ "SOLR-4147: ibm 64bit has jvm bugs!",
+ Constants.JRE_IS_64BIT && Constants.JAVA_VENDOR.startsWith("IBM"));
r = new Random(random().nextLong());
}
-
+
/**
- * Set's the value of the "hostContext" system property to a random path
- * like string (which may or may not contain sub-paths). This is used
- * in the default constructor for this test to help ensure no code paths have
- * hardcoded assumptions about the servlet context used to run solr.
- * <p>
- * Test configs may use the <code>${hostContext}</code> variable to access
- * this system property.
- * </p>
+ * Set's the value of the "hostContext" system property to a random path like string (which may or
+ * may not contain sub-paths). This is used in the default constructor for this test to help
+ * ensure no code paths have hardcoded assumptions about the servlet context used to run solr.
+ *
+ * <p>Test configs may use the <code>${hostContext}</code> variable to access this system
+ * property.
+ *
* @see #BaseDistributedSearchTestCase()
* @see #clearHostContext
*/
@BeforeClass
public static void initHostContext() {
- // Can't use randomRealisticUnicodeString because unescaped unicode is
+ // Can't use randomRealisticUnicodeString because unescaped unicode is
// not allowed in URL paths
// Can't use URLEncoder.encode(randomRealisticUnicodeString) because
// Jetty freaks out and returns 404's when the context uses escapes
@@ -148,8 +147,8 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
hostContext.append("_");
}
hostContext.append(TestUtil.randomSimpleString(random(), 3));
- if ( ! "/".equals(hostContext.toString())) {
- // if our random string is empty, this might add a trailing slash,
+ if (!"/".equals(hostContext.toString())) {
+ // if our random string is empty, this might add a trailing slash,
// but our code should be ok with that
hostContext.append("/").append(TestUtil.randomSimpleString(random(), 2));
} else {
@@ -158,14 +157,15 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
}
}
// paranoia, we *really* don't want to ever get "//" in a path...
- final String hc = hostContext.toString().replaceAll("\\/+","/");
+ final String hc = hostContext.toString().replaceAll("\\/+", "/");
log.info("Setting hostContext system property: {}", hc);
System.setProperty("hostContext", hc);
}
-
+
/**
* Clears the "hostContext" system property
+ *
* @see #initHostContext
*/
@AfterClass
@@ -186,30 +186,27 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
}
private static String getHostContextSuitableForServletContext() {
- String ctx = System.getProperty("hostContext","/solr");
+ String ctx = System.getProperty("hostContext", "/solr");
if ("".equals(ctx)) ctx = "/solr";
- if (ctx.endsWith("/")) ctx = ctx.substring(0,ctx.length()-1);;
+ if (ctx.endsWith("/")) ctx = ctx.substring(0, ctx.length() - 1);
+ ;
if (!ctx.startsWith("/")) ctx = "/" + ctx;
return ctx;
}
/**
- * Constructs a test in which the jetty+solr instances as well as the
- * solr clients all use the value of the "hostContext" system property.
- * <p>
- * If the system property is not set, or is set to the empty string
- * (neither of which should normally happen unless a subclass explicitly
- * modifies the property set by {@link #initHostContext} prior to calling
- * this constructor) a servlet context of "/solr" is used. (this is for
- * consistency with the default behavior of solr.xml parsing when using
- * <code>hostContext="${hostContext:}"</code>
- * </p>
- * <p>
- * If the system property is set to a value which does not begin with a
- * "/" (which should normally happen unless a subclass explicitly
- * modifies the property set by {@link #initHostContext} prior to calling
- * this constructor) a leading "/" will be prepended.
- * </p>
+ * Constructs a test in which the jetty+solr instances as well as the solr clients all use the
+ * value of the "hostContext" system property.
+ *
+ * <p>If the system property is not set, or is set to the empty string (neither of which should
+ * normally happen unless a subclass explicitly modifies the property set by {@link
+ * #initHostContext} prior to calling this constructor) a servlet context of "/solr" is used.
+ * (this is for consistency with the default behavior of solr.xml parsing when using <code>
+ * hostContext="${hostContext:}"</code>
+ *
+ * <p>If the system property is set to a value which does not begin with a "/" (which should
+ * normally happen unless a subclass explicitly modifies the property set by {@link
+ * #initHostContext} prior to calling this constructor) a leading "/" will be prepended.
*
* @see #initHostContext
*/
@@ -222,14 +219,15 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
*/
protected BaseDistributedSearchTestCase(final String context) {
this.context = context;
- this.deadServers = new String[] {DEAD_HOST_1 + context,
- DEAD_HOST_2 + context,
- DEAD_HOST_3 + context};
+ this.deadServers =
+ new String[] {DEAD_HOST_1 + context, DEAD_HOST_2 + context, DEAD_HOST_3 + context};
}
- private final static int DEFAULT_MAX_SHARD_COUNT = 3;
+ private static final int DEFAULT_MAX_SHARD_COUNT = 3;
+
+ // the actual number of solr cores that will be created in the cluster
+ private int shardCount = -1;
- private int shardCount = -1; // the actual number of solr cores that will be created in the cluster
public int getShardCount() {
return shardCount;
}
@@ -244,7 +242,7 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
protected volatile JettySolrRunner controlJetty;
protected final List<SolrClient> clients = Collections.synchronizedList(new ArrayList<>());
protected final List<JettySolrRunner> jettys = Collections.synchronizedList(new ArrayList<>());
-
+
protected volatile String context;
protected volatile String[] deadServers;
protected volatile String shards;
@@ -259,16 +257,17 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
protected volatile boolean verifyStress = true;
protected volatile int nThreads = 3;
- public final static int ORDERED = 1;
- public final static int SKIP = 2;
- public final static int SKIPVAL = 4;
- public final static int UNORDERED = 8;
-
+ public static final int ORDERED = 1;
+ public static final int SKIP = 2;
+ public static final int SKIPVAL = 4;
+ public static final int UNORDERED = 8;
+
/**
- * When this flag is set, Double values will be allowed a difference ratio of 1E-8
- * between the non-distributed and the distributed returned values
+ * When this flag is set, Double values will be allowed a difference ratio of 1E-8 between the
+ * non-distributed and the distributed returned values
*/
public static int FUZZY = 16;
+
private static final double DOUBLE_RATIO_LIMIT = 1E-8;
protected volatile int flags;
@@ -276,39 +275,45 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
protected String id = "id";
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
- public static RandVal rint = new RandVal() {
- @Override
- public Object val() {
- return r.nextInt();
- }
- };
- public static RandVal rlong = new RandVal() {
- @Override
- public Object val() {
- return r.nextLong();
- }
- };
+ public static RandVal rint =
+ new RandVal() {
+ @Override
+ public Object val() {
+ return r.nextInt();
+ }
+ };
- public static RandVal rfloat = new RandVal() {
- @Override
- public Object val() {
- return r.nextFloat();
- }
- };
+ public static RandVal rlong =
+ new RandVal() {
+ @Override
+ public Object val() {
+ return r.nextLong();
+ }
+ };
- public static RandVal rdouble = new RandVal() {
- @Override
- public Object val() {
- return r.nextDouble();
- }
- };
+ public static RandVal rfloat =
+ new RandVal() {
+ @Override
+ public Object val() {
+ return r.nextFloat();
+ }
+ };
+
+ public static RandVal rdouble =
+ new RandVal() {
+ @Override
+ public Object val() {
+ return r.nextDouble();
+ }
+ };
public static RandVal rdate = new RandDate();
- public static String[] fieldNames = new String[]{"n_ti1", "n_f1", "n_tf1", "n_d1", "n_td1", "n_l1", "n_tl1", "n_dt1", "n_tdt1"};
- public static RandVal[] randVals = new RandVal[]{rint, rfloat, rfloat, rdouble, rdouble, rlong, rlong, rdate, rdate};
+ public static String[] fieldNames =
+ new String[] {"n_ti1", "n_f1", "n_tf1", "n_d1", "n_td1", "n_l1", "n_tl1", "n_dt1", "n_tdt1"};
+ public static RandVal[] randVals =
+ new RandVal[] {rint, rfloat, rfloat, rdouble, rdouble, rlong, rlong, rdate, rdate};
protected String[] getFieldNames() {
return fieldNames;
@@ -318,24 +323,23 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
return randVals;
}
- /**
- * Subclasses can override this to change a test's solr home
- * (default is in test-files)
- */
+ /** Subclasses can override this to change a test's solr home (default is in test-files) */
public String getSolrHome() {
return SolrTestCaseJ4.TEST_HOME();
}
private boolean distribSetUpCalled = false;
+
public void distribSetUp() throws Exception {
distribSetUpCalled = true;
- SolrTestCaseJ4.resetExceptionIgnores(); // ignore anything with ignore_exception in it
+ SolrTestCaseJ4.resetExceptionIgnores(); // ignore anything with ignore_exception in it
System.setProperty("solr.test.sys.prop1", "propone");
System.setProperty("solr.test.sys.prop2", "proptwo");
testDir = createTempDir().toFile();
}
private volatile boolean distribTearDownCalled = false;
+
public void distribTearDown() throws Exception {
ExecutorUtil.shutdownAndAwaitTermination(executor);
distribTearDownCalled = true;
@@ -346,7 +350,8 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
File jettyHomeFile = jettyHome.toFile();
seedSolrHome(jettyHomeFile);
seedCoreRootDirWithDefaultTestCore(jettyHome.resolve("cores"));
- JettySolrRunner jetty = createJetty(jettyHomeFile, null, null, getSolrConfigFile(), getSchemaFile());
+ JettySolrRunner jetty =
+ createJetty(jettyHomeFile, null, null, getSolrConfigFile(), getSchemaFile());
jetty.start();
return jetty;
}
@@ -367,7 +372,8 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
File jettyHomeFile = jettyHome.toFile();
seedSolrHome(jettyHomeFile);
seedCoreRootDirWithDefaultTestCore(jettyHome.resolve("cores"));
- JettySolrRunner j = createJetty(jettyHomeFile, null, null, getSolrConfigFile(), getSchemaFile());
+ JettySolrRunner j =
+ createJetty(jettyHomeFile, null, null, getSolrConfigFile(), getSchemaFile());
j.start();
jettys.add(j);
clients.add(createNewSolrClient(j.getLocalPort()));
@@ -383,24 +389,23 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
shards = sb.toString();
}
-
protected void setDistributedParams(ModifiableSolrParams params) {
params.set("shards", getShardsString());
}
protected String getShardsString() {
if (deadServers == null) return shards;
-
+
StringBuilder sb = new StringBuilder();
for (String shard : shardsArr) {
if (sb.length() > 0) sb.append(',');
- int nDeadServers = r.nextInt(deadServers.length+1);
+ int nDeadServers = r.nextInt(deadServers.length + 1);
if (nDeadServers > 0) {
List<String> replicas = new ArrayList<>(Arrays.asList(deadServers));
Collections.shuffle(replicas, r);
- replicas.add(r.nextInt(nDeadServers+1), shard);
- for (int i=0; i<nDeadServers+1; i++) {
- if (i!=0) sb.append('|');
+ replicas.add(r.nextInt(nDeadServers + 1), shard);
+ for (int i = 0; i < nDeadServers + 1; i++) {
+ if (i != 0) sb.append('|');
sb.append(replicas.get(i));
}
} else {
@@ -412,61 +417,76 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
}
protected void destroyServers() throws Exception {
- ExecutorService customThreadPool = ExecutorUtil.newMDCAwareCachedThreadPool(new SolrNamedThreadFactory("closeThreadPool"));
-
+ ExecutorService customThreadPool =
+ ExecutorUtil.newMDCAwareCachedThreadPool(new SolrNamedThreadFactory("closeThreadPool"));
+
customThreadPool.submit(() -> IOUtils.closeQuietly(controlClient));
- customThreadPool.submit(() -> {
- try {
- controlJetty.stop();
- } catch (NullPointerException e) {
- // ignore
- } catch (Exception e) {
- log.error("Error stopping Control Jetty", e);
- }
- });
+ customThreadPool.submit(
+ () -> {
+ try {
+ controlJetty.stop();
+ } catch (NullPointerException e) {
+ // ignore
+ } catch (Exception e) {
+ log.error("Error stopping Control Jetty", e);
+ }
+ });
for (SolrClient client : clients) {
- customThreadPool.submit(() -> IOUtils.closeQuietly(client));
+ customThreadPool.submit(() -> IOUtils.closeQuietly(client));
}
-
+
for (JettySolrRunner jetty : jettys) {
- customThreadPool.submit(() -> {
- try {
- jetty.stop();
- } catch (Exception e) {
- log.error("Error stopping Jetty", e);
- }
- });
+ customThreadPool.submit(
+ () -> {
+ try {
+ jetty.stop();
+ } catch (Exception e) {
+ log.error("Error stopping Jetty", e);
+ }
+ });
}
ExecutorUtil.shutdownAndAwaitTermination(customThreadPool);
-
+
clients.clear();
jettys.clear();
}
-
+
public JettySolrRunner createJetty(File solrHome, String dataDir) throws Exception {
return createJetty(solrHome, dataDir, null, null, null);
}
- public JettySolrRunner createJetty(File solrHome, String dataDir, String shardId) throws Exception {
+ public JettySolrRunner createJetty(File solrHome, String dataDir, String shardId)
+ throws Exception {
return createJetty(solrHome, dataDir, shardId, null, null);
}
-
- public JettySolrRunner createJetty(File solrHome, String dataDir, String shardList, String solrConfigOverride, String schemaOverride) throws Exception {
- return createJetty(solrHome, dataDir, shardList, solrConfigOverride, schemaOverride, useExplicitNodeNames);
+
+ public JettySolrRunner createJetty(
+ File solrHome,
+ String dataDir,
+ String shardList,
+ String solrConfigOverride,
+ String schemaOverride)
+ throws Exception {
+ return createJetty(
+ solrHome, dataDir, shardList, solrConfigOverride, schemaOverride, useExplicitNodeNames);
}
-
- public JettySolrRunner createJetty(File solrHome, String dataDir, String shardList, String solrConfigOverride, String schemaOverride, boolean explicitCoreNodeName) throws Exception {
+
+ public JettySolrRunner createJetty(
+ File solrHome,
+ String dataDir,
+ String shardList,
+ String solrConfigOverride,
+ String schemaOverride,
+ boolean explicitCoreNodeName)
+ throws Exception {
Properties props = new Properties();
- if (solrConfigOverride != null)
- props.setProperty("solrconfig", solrConfigOverride);
- if (schemaOverride != null)
- props.setProperty("schema", schemaOverride);
- if (shardList != null)
- props.setProperty("shards", shardList);
+ if (solrConfigOverride != null) props.setProperty("solrconfig", solrConfigOverride);
+ if (schemaOverride != null) props.setProperty("schema", schemaOverride);
+ if (shardList != null) props.setProperty("shards", shardList);
if (dataDir != null) {
props.setProperty("solr.data.dir", dataDir);
}
@@ -475,24 +495,34 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
}
props.setProperty("coreRootDirectory", solrHome.toPath().resolve("cores").toString());
- JettySolrRunner jetty = new JettySolrRunner(solrHome.getAbsolutePath(), props, JettyConfig.builder()
- .stopAtShutdown(true)
- .setContext(context)
- .withFilters(getExtraRequestFilters())
- .withServlets(getExtraServlets())
- .withSSLConfig(sslConfig.buildServerSSLConfig())
- .build());
+ JettySolrRunner jetty =
+ new JettySolrRunner(
+ solrHome.getAbsolutePath(),
+ props,
+ JettyConfig.builder()
+ .stopAtShutdown(true)
+ .setContext(context)
+ .withFilters(getExtraRequestFilters())
+ .withServlets(getExtraServlets())
+ .withSSLConfig(sslConfig.buildServerSSLConfig())
+ .build());
return jetty;
}
-
- /** Override this method to insert extra servlets into the JettySolrRunners that are created using createJetty() */
- public SortedMap<ServletHolder,String> getExtraServlets() {
+
+ /**
+ * Override this method to insert extra servlets into the JettySolrRunners that are created using
+ * createJetty()
+ */
+ public SortedMap<ServletHolder, String> getExtraServlets() {
return null;
}
- /** Override this method to insert extra filters into the JettySolrRunners that are created using createJetty() */
- public SortedMap<Class<? extends Filter>,String> getExtraRequestFilters() {
+ /**
+ * Override this method to insert extra filters into the JettySolrRunners that are created using
+ * createJetty()
+ */
+ public SortedMap<Class<? extends Filter>, String> getExtraRequestFilters() {
return null;
}
@@ -505,12 +535,11 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
} else {
return getHttpSolrClient(baseUrl + "/" + DEFAULT_TEST_CORENAME);
}
- }
- catch (Exception ex) {
+ } catch (Exception ex) {
throw new RuntimeException(ex);
}
}
-
+
protected String buildUrl(int port) {
return buildUrl(port, context);
}
@@ -519,7 +548,7 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
for (int i = 0; i < fields.length; i += 2) {
doc.addField((String) (fields[i]), fields[i + 1]);
}
- }// add random fields to the documet before indexing
+ } // add random fields to the documet before indexing
protected void indexr(Object... fields) throws Exception {
SolrInputDocument doc = new SolrInputDocument();
@@ -528,7 +557,7 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
addRandFields(doc);
indexDoc(doc);
}
-
+
protected SolrInputDocument addRandFields(SolrInputDocument sdoc) {
addFields(sdoc, getRandFields(getFieldNames(), getRandValues()));
return sdoc;
@@ -540,31 +569,32 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
indexDoc(doc);
}
- /**
- * Indexes the document in both the control client, and a randomly selected client
- */
+ /** Indexes the document in both the control client, and a randomly selected client */
protected void indexDoc(SolrInputDocument doc) throws IOException, SolrServerException {
controlClient.add(doc);
- if (shardCount == 0) {//mostly for temp debugging
+ if (shardCount == 0) { // mostly for temp debugging
return;
}
int which = (doc.getField(id).toString().hashCode() & 0x7fffffff) % clients.size();
SolrClient client = clients.get(which);
client.add(doc);
}
-
+
/**
- * Indexes the document in both the control client and the specified client asserting
- * that the responses are equivalent
+ * Indexes the document in both the control client and the specified client asserting that the
+ * responses are equivalent
*/
- protected UpdateResponse indexDoc(SolrClient client, SolrParams params, SolrInputDocument... sdocs) throws IOException, SolrServerException {
+ protected UpdateResponse indexDoc(
+ SolrClient client, SolrParams params, SolrInputDocument... sdocs)
+ throws IOException, SolrServerException {
UpdateResponse controlRsp = add(controlClient, params, sdocs);
UpdateResponse specificRsp = add(client, params, sdocs);
compareSolrResponses(specificRsp, controlRsp);
return specificRsp;
}
- protected UpdateResponse add(SolrClient client, SolrParams params, SolrInputDocument... sdocs) throws IOException, SolrServerException {
+ protected UpdateResponse add(SolrClient client, SolrParams params, SolrInputDocument... sdocs)
+ throws IOException, SolrServerException {
UpdateRequest ureq = new UpdateRequest();
ureq.setParams(new ModifiableSolrParams(params));
for (SolrInputDocument sdoc : sdocs) {
@@ -573,19 +603,21 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
return ureq.process(client);
}
- protected UpdateResponse del(SolrClient client, SolrParams params, Object... ids) throws IOException, SolrServerException {
+ protected UpdateResponse del(SolrClient client, SolrParams params, Object... ids)
+ throws IOException, SolrServerException {
UpdateRequest ureq = new UpdateRequest();
ureq.setParams(new ModifiableSolrParams(params));
- for (Object id: ids) {
+ for (Object id : ids) {
ureq.deleteById(id.toString());
}
return ureq.process(client);
}
- protected UpdateResponse delQ(SolrClient client, SolrParams params, String... queries) throws IOException, SolrServerException {
+ protected UpdateResponse delQ(SolrClient client, SolrParams params, String... queries)
+ throws IOException, SolrServerException {
UpdateRequest ureq = new UpdateRequest();
ureq.setParams(new ModifiableSolrParams(params));
- for (String q: queries) {
+ for (String q : queries) {
ureq.deleteByQuery(q);
}
return ureq.process(client);
@@ -607,7 +639,7 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
for (SolrClient client : clients) {
client.deleteByQuery(q);
}
- }// serial commit...
+ } // serial commit...
protected void commit() throws Exception {
controlClient.commit();
@@ -616,7 +648,8 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
}
}
- protected QueryResponse queryServer(ModifiableSolrParams params) throws SolrServerException, IOException {
+ protected QueryResponse queryServer(ModifiableSolrParams params)
+ throws SolrServerException, IOException {
// query a random server
int which = r.nextInt(clients.size());
SolrClient client = clients.get(which);
@@ -624,36 +657,26 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
return rsp;
}
- /**
- * Sets distributed params.
- * Returns the QueryResponse from {@link #queryServer},
- */
+ /** Sets distributed params. Returns the QueryResponse from {@link #queryServer}, */
protected QueryResponse query(Object... q) throws Exception {
return query(true, q);
}
- /**
- * Sets distributed params.
- * Returns the QueryResponse from {@link #queryServer},
- */
+ /** Sets distributed params. Returns the QueryResponse from {@link #queryServer}, */
protected QueryResponse query(SolrParams params) throws Exception {
return query(true, params);
}
- /**
- * Returns the QueryResponse from {@link #queryServer}
- */
+ /** Returns the QueryResponse from {@link #queryServer} */
protected QueryResponse query(boolean setDistribParams, Object[] q) throws Exception {
-
+
final ModifiableSolrParams params = createParams(q);
return query(setDistribParams, params);
}
- /**
- * Returns the QueryResponse from {@link #queryServer}
- */
+ /** Returns the QueryResponse from {@link #queryServer} */
protected QueryResponse query(boolean setDistribParams, SolrParams p) throws Exception {
-
+
final ModifiableSolrParams params = new ModifiableSolrParams(p);
// TODO: look into why passing true causes fails
@@ -661,7 +684,7 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
final QueryResponse controlRsp = controlClient.query(params);
validateControlData(controlRsp);
- if (shardCount == 0) {//mostly for temp debugging
+ if (shardCount == 0) { // mostly for temp debugging
return controlRsp;
}
@@ -676,20 +699,23 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
log.info("starting stress...");
Thread[] threads = new Thread[nThreads];
for (int i = 0; i < threads.length; i++) {
- threads[i] = new Thread(() -> {
- for (int j = 0; j < stress; j++) {
- int which = r.nextInt(clients.size());
- SolrClient client = clients.get(which);
- try {
- QueryResponse rsp1 = client.query(new ModifiableSolrParams(params));
- if (verifyStress) {
- compareResponses(rsp1, controlRsp);
- }
- } catch (SolrServerException | IOException e) {
- throw new RuntimeException(e);
- }
- }
- }, "StressRunner");
+ threads[i] =
+ new Thread(
+ () -> {
+ for (int j = 0; j < stress; j++) {
+ int which = r.nextInt(clients.size());
+ SolrClient client = clients.get(which);
+ try {
+ QueryResponse rsp1 = client.query(new ModifiableSolrParams(params));
+ if (verifyStress) {
+ compareResponses(rsp1, controlRsp);
+ }
+ } catch (SolrServerException | IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ },
+ "StressRunner");
threads[i].start();
}
@@ -699,11 +725,14 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
}
return rsp;
}
-
- public QueryResponse queryAndCompare(SolrParams params, SolrClient... clients) throws SolrServerException, IOException {
+
+ public QueryResponse queryAndCompare(SolrParams params, SolrClient... clients)
+ throws SolrServerException, IOException {
return queryAndCompare(params, Arrays.<SolrClient>asList(clients));
}
- public QueryResponse queryAndCompare(SolrParams params, Iterable<SolrClient> clients) throws SolrServerException, IOException {
+
+ public QueryResponse queryAndCompare(SolrParams params, Iterable<SolrClient> clients)
+ throws SolrServerException, IOException {
QueryResponse first = null;
for (SolrClient client : clients) {
QueryResponse rsp = client.query(new ModifiableSolrParams(params));
@@ -729,22 +758,25 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
}
@SuppressWarnings({"unchecked"})
- public static String compare(@SuppressWarnings({"rawtypes"})NamedList a,
- @SuppressWarnings({"rawtypes"})NamedList b, int flags, Map<String, Integer> handle) {
-// System.out.println("resp a:" + a);
-// System.out.println("resp b:" + b);
+ public static String compare(
+ @SuppressWarnings({"rawtypes"}) NamedList a,
+ @SuppressWarnings({"rawtypes"}) NamedList b,
+ int flags,
+ Map<String, Integer> handle) {
+ // System.out.println("resp a:" + a);
+ // System.out.println("resp b:" + b);
boolean ordered = (flags & UNORDERED) == 0;
if (!ordered) {
@SuppressWarnings({"rawtypes"})
Map mapA = new HashMap(a.size());
- for (int i=0; i<a.size(); i++) {
+ for (int i = 0; i < a.size(); i++) {
Object prev = mapA.put(a.getName(i), a.getVal(i));
}
@SuppressWarnings({"rawtypes"})
Map mapB = new HashMap(b.size());
- for (int i=0; i<b.size(); i++) {
+ for (int i = 0; i < b.size(); i++) {
Object prev = mapB.put(b.getName(i), b.getVal(i));
}
@@ -754,7 +786,7 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
int posa = 0, posb = 0;
int aSkipped = 0, bSkipped = 0;
- for (; ;) {
+ for (; ; ) {
if (posa >= a.size() && posb >= b.size()) {
break;
}
@@ -769,11 +801,12 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
posa++;
flagsa = flags(handle, namea);
if ((flagsa & SKIP) != 0) {
- namea = null; vala = null;
+ namea = null;
+ vala = null;
aSkipped++;
continue;
}
-
+
break;
}
@@ -783,7 +816,8 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
posb++;
flagsb = flags(handle, nameb);
if ((flagsb & SKIP) != 0) {
- nameb = null; valb = null;
+ nameb = null;
+ valb = null;
bSkipped++;
continue;
}
@@ -795,13 +829,12 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
}
// ok, namea and nameb should be equal here already.
- if ((flagsa & SKIPVAL) != 0) continue; // keys matching is enough
+ if ((flagsa & SKIPVAL) != 0) continue; // keys matching is enough
String cmp = compare(vala, valb, flagsa, handle);
if (cmp != null) return "." + namea + cmp;
}
-
if (a.size() - aSkipped != b.size() - bSkipped) {
return ".size()==" + a.size() + "," + b.size() + " skipped=" + aSkipped + "," + bSkipped;
}
@@ -809,9 +842,11 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
return null;
}
- public static String compare1(@SuppressWarnings({"rawtypes"})Map a,
- @SuppressWarnings({"rawtypes"})Map b,
- int flags, Map<String, Integer> handle) {
+ public static String compare1(
+ @SuppressWarnings({"rawtypes"}) Map a,
+ @SuppressWarnings({"rawtypes"}) Map b,
+ int flags,
+ Map<String, Integer> handle) {
String cmp;
for (Object keya : a.keySet()) {
@@ -829,20 +864,24 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
return null;
}
- public static String compare(@SuppressWarnings({"rawtypes"})Map a,
- @SuppressWarnings({"rawtypes"})Map b,
- int flags, Map<String, Integer> handle) {
+ public static String compare(
+ @SuppressWarnings({"rawtypes"}) Map a,
+ @SuppressWarnings({"rawtypes"}) Map b,
+ int flags,
+ Map<String, Integer> handle) {
String cmp;
cmp = compare1(a, b, flags, handle);
if (cmp != null) return cmp;
return compare1(b, a, flags, handle);
}
- public static String compare(SolrDocument a, SolrDocument b, int flags, Map<String, Integer> handle) {
+ public static String compare(
+ SolrDocument a, SolrDocument b, int flags, Map<String, Integer> handle) {
return compare(a.getFieldValuesMap(), b.getFieldValuesMap(), flags, handle);
}
- public static String compare(SolrDocumentList a, SolrDocumentList b, int flags, Map<String, Integer> handle) {
+ public static String compare(
+ SolrDocumentList a, SolrDocumentList b, int flags, Map<String, Integer> handle) {
boolean ordered = (flags & UNORDERED) == 0;
String cmp;
@@ -942,12 +981,12 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
if (a instanceof List && b instanceof List) {
return compare(((List) a).toArray(), ((List) b).toArray(), flags, handle);
-
}
// equivalent integer numbers
- if ((a instanceof Integer || a instanceof Long) && (b instanceof Integer || b instanceof Long)) {
- if (((Number)a).longValue() == ((Number)b).longValue()) {
+ if ((a instanceof Integer || a instanceof Long)
+ && (b instanceof Integer || b instanceof Long)) {
+ if (((Number) a).longValue() == ((Number) b).longValue()) {
return null;
} else {
return ":" + a + "!=" + b;
@@ -962,7 +1001,7 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
return null;
}
if ((aaa == 0.0) || (bbb == 0.0)) {
- return ":" + a + "!=" + b;
+ return ":" + a + "!=" + b;
}
double diff = Math.abs(aaa - bbb);
@@ -974,7 +1013,7 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
if (ratio > DOUBLE_RATIO_LIMIT) {
return ":" + a + "!=" + b;
} else {
- return null;// close enough.
+ return null; // close enough.
}
}
}
@@ -987,7 +1026,8 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
}
protected void compareSolrResponses(SolrResponse a, SolrResponse b) {
- // SOLR-3345: Checking QTime value can be skipped as there is no guarantee that the numbers will match.
+ // SOLR-3345: Checking QTime value can be skipped as there is no guarantee that the numbers will
+ // match.
handle.put("QTime", SKIPVAL);
// rf will be different since the control collection doesn't usually have multiple replicas
handle.put("rf", SKIPVAL);
@@ -997,11 +1037,13 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
Assert.fail(cmp);
}
}
+
protected void compareResponses(QueryResponse a, QueryResponse b) {
if (System.getProperty("remove.version.field") != null) {
// we don't care if one has a version and the other doesnt -
// control vs distrib
- // TODO: this should prob be done by adding an ignore on _version_ rather than mutating the responses?
+ // TODO: this should prob be done by adding an ignore on _version_ rather than mutating the
+ // responses?
if (a.getResults() != null) {
for (SolrDocument doc : a.getResults()) {
doc.removeFields("_version_");
@@ -1013,7 +1055,8 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
}
}
}
- { // we don't care if one has a warnings section in the header and the other doesn't - control vs distrib
+ { // we don't care if one has a warnings section in the header and the other doesn't - control
+ // vs distrib
if (a.getHeader() != null) {
a.getHeader().remove("warnings");
}
@@ -1028,6 +1071,7 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
@Target(ElementType.METHOD)
public @interface ShardsRepeat {
public abstract int min() default 1;
+
public abstract int max() default DEFAULT_MAX_SHARD_COUNT;
}
@@ -1040,19 +1084,19 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
public class ShardsRepeatRule implements TestRule {
private abstract class ShardsStatement extends Statement {
- abstract protected void callStatement() throws Throwable;
+ protected abstract void callStatement() throws Throwable;
@Override
public void evaluate() throws Throwable {
distribSetUp();
- if (! distribSetUpCalled) {
+ if (!distribSetUpCalled) {
Assert.fail("One of the overrides of distribSetUp does not propagate the call.");
}
try {
callStatement();
} finally {
distribTearDown();
- if (! distribTearDownCalled) {
+ if (!distribTearDownCalled) {
Assert.fail("One of the overrides of distribTearDown does not propagate the call.");
}
}
@@ -1074,10 +1118,10 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
public void callStatement() throws Throwable {
RandVal.uniqueValues = new HashSet(); // reset random values
fixShardCount(numShards);
-
+
try {
createServers(numShards);
-
+
statement.evaluate();
} finally {
destroyServers();
@@ -1100,9 +1144,9 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
@Override
@SuppressWarnings({"rawtypes"})
public void callStatement() throws Throwable {
-
+
for (shardCount = min; shardCount <= max; shardCount++) {
- RandVal.uniqueValues = new HashSet(); //reset random values
+ RandVal.uniqueValues = new HashSet(); // reset random values
createServers(shardCount);
try {
statement.evaluate();
@@ -1119,22 +1163,19 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
ShardsRepeat repeat = description.getAnnotation(ShardsRepeat.class);
if (fixed != null && repeat != null) {
throw new RuntimeException("ShardsFixed and ShardsRepeat annotations can't coexist");
- }
- else if (fixed != null) {
+ } else if (fixed != null) {
return new ShardsFixedStatement(fixed.num(), statement);
- }
- else if (repeat != null) {
+ } else if (repeat != null) {
return new ShardsRepeatStatement(repeat.min(), repeat.max(), statement);
- }
- else {
- return (isShardCountFixed ? new ShardsFixedStatement(shardCount, statement) :
- new ShardsRepeatStatement(1, DEFAULT_MAX_SHARD_COUNT, statement));
+ } else {
+ return (isShardCountFixed
+ ? new ShardsFixedStatement(shardCount, statement)
+ : new ShardsRepeatStatement(1, DEFAULT_MAX_SHARD_COUNT, statement));
}
}
}
- @Rule
- public ShardsRepeatRule repeatRule = new ShardsRepeatRule();
+ @Rule public ShardsRepeatRule repeatRule = new ShardsRepeatRule();
public static Object[] getRandFields(String[] fields, RandVal[] randVals) {
Object[] o = new Object[fields.length * 2];
@@ -1144,12 +1185,12 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
}
return o;
}
-
+
/**
- * Implementations can pre-test the control data for basic correctness before using it
- * as a check for the shard data. This is useful, for instance, if a test bug is introduced
- * causing a spelling index not to get built: both control &amp; shard data would have no results
- * but because they match the test would pass. This method gives us a chance to ensure something
+ * Implementations can pre-test the control data for basic correctness before using it as a check
+ * for the shard data. This is useful, for instance, if a test bug is introduced causing a
+ * spelling index not to get built: both control &amp; shard data would have no results but
+ * because they match the test would pass. This method gives us a chance to ensure something
* exists in the control data.
*/
public void validateControlData(QueryResponse control) throws Exception {
@@ -1157,14 +1198,14 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
}
@SuppressWarnings({"unchecked"})
- public static abstract class RandVal {
+ public abstract static class RandVal {
@SuppressWarnings({"rawtypes"})
public static Set uniqueValues = new HashSet();
public abstract Object val();
public Object uval() {
- for (; ;) {
+ for (; ; ) {
Object v = val();
if (uniqueValues.add(v)) return v;
}
@@ -1179,15 +1220,15 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
return d.toInstant().toString();
}
}
-
+
protected String getSolrXml() {
return null;
}
-
+
/**
- * Given a directory that will be used as the SOLR_HOME for a jetty instance, seeds that
- * directory with the contents of {@link #getSolrHome} and ensures that the proper {@link #getSolrXml}
- * file is in place.
+ * Given a directory that will be used as the SOLR_HOME for a jetty instance, seeds that directory
+ * with the contents of {@link #getSolrHome} and ensures that the proper {@link #getSolrXml} file
+ * is in place.
*/
protected void seedSolrHome(File jettyHome) throws IOException {
FileUtils.copyDirectory(new File(getSolrHome()), jettyHome);
@@ -1198,15 +1239,15 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
}
/**
- * Given a directory that will be used as the <code>coreRootDirectory</code> for a jetty instance,
- * Creates a core directory named {@link #DEFAULT_TEST_CORENAME} using a trivial
- * <code>core.properties</code> if this file does not already exist.
+ * Given a directory that will be used as the <code>coreRootDirectory</code> for a jetty instance,
+ * Creates a core directory named {@link #DEFAULT_TEST_CORENAME} using a trivial <code>
+ * core.properties</code> if this file does not already exist.
*
* @see #writeCoreProperties(Path,String)
* @see #CORE_PROPERTIES_FILENAME
*/
private void seedCoreRootDirWithDefaultTestCore(Path coreRootDirectory) throws IOException {
- // Kludgy and brittle with assumptions about writeCoreProperties, but i don't want to
+ // Kludgy and brittle with assumptions about writeCoreProperties, but i don't want to
// try to change the semantics of that method to ignore existing files
Path coreDir = coreRootDirectory.resolve(DEFAULT_TEST_CORENAME);
if (Files.notExists(coreDir.resolve(CORE_PROPERTIES_FILENAME))) {
@@ -1220,7 +1261,7 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
Files.createDirectories(jettyHome.toPath().resolve("cores").resolve("collection1"));
}
- protected ModifiableSolrParams createParams(Object ... q) {
+ protected ModifiableSolrParams createParams(Object... q) {
final ModifiableSolrParams params = new ModifiableSolrParams();
for (int i = 0; i < q.length; i += 2) {
diff --git a/solr/test-framework/src/java/org/apache/solr/EmbeddedSolrServerTestBase.java b/solr/test-framework/src/java/org/apache/solr/EmbeddedSolrServerTestBase.java
index 4c547d61034..458e3ca6ddf 100644
--- a/solr/test-framework/src/java/org/apache/solr/EmbeddedSolrServerTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/EmbeddedSolrServerTestBase.java
@@ -16,6 +16,7 @@
*/
package org.apache.solr;
+import com.google.common.io.ByteStreams;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -29,7 +30,6 @@ import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.common.util.ContentStream;
import org.apache.solr.common.util.ContentStreamBase;
@@ -37,9 +37,7 @@ import org.apache.solr.common.util.ContentStreamBase.ByteArrayStream;
import org.junit.After;
import org.junit.AfterClass;
-import com.google.common.io.ByteStreams;
-
-abstract public class EmbeddedSolrServerTestBase extends SolrTestCaseJ4 {
+public abstract class EmbeddedSolrServerTestBase extends SolrTestCaseJ4 {
protected static final String DEFAULT_CORE_NAME = "collection1";
@@ -52,9 +50,7 @@ abstract public class EmbeddedSolrServerTestBase extends SolrTestCaseJ4 {
}
@AfterClass
- public static void afterEmbeddedSolrServerTestBase() throws Exception {
-
- }
+ public static void afterEmbeddedSolrServerTestBase() throws Exception {}
public synchronized EmbeddedSolrServer getSolrClient() {
if (client == null) {
@@ -63,9 +59,7 @@ abstract public class EmbeddedSolrServerTestBase extends SolrTestCaseJ4 {
return client;
}
- /**
- * Create a new solr client. Subclasses should override for other options.
- */
+ /** Create a new solr client. Subclasses should override for other options. */
public EmbeddedSolrServer createNewSolrClient() {
return new EmbeddedSolrServer(h.getCoreContainer(), DEFAULT_CORE_NAME);
}
@@ -103,7 +97,8 @@ abstract public class EmbeddedSolrServerTestBase extends SolrTestCaseJ4 {
try {
final ByteArrayOutputStream os = new ByteArrayOutputStream();
ByteStreams.copy(new FileInputStream(file), os);
- final ByteArrayStream stream = new ContentStreamBase.ByteArrayStream(os.toByteArray(), name);
+ final ByteArrayStream stream =
+ new ContentStreamBase.ByteArrayStream(os.toByteArray(), name);
result.add(stream);
} catch (final IOException e) {
throw new RuntimeException(e);
diff --git a/solr/test-framework/src/java/org/apache/solr/JSONTestUtil.java b/solr/test-framework/src/java/org/apache/solr/JSONTestUtil.java
index c9449cfae7e..1580e2c9440 100644
--- a/solr/test-framework/src/java/org/apache/solr/JSONTestUtil.java
+++ b/solr/test-framework/src/java/org/apache/solr/JSONTestUtil.java
@@ -16,26 +16,24 @@
*/
package org.apache.solr;
-import org.noggit.JSONParser;
-import org.noggit.ObjectBuilder;
-import org.apache.solr.common.util.StrUtils;
-
import java.io.IOException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
+import org.apache.solr.common.util.StrUtils;
+import org.noggit.JSONParser;
+import org.noggit.ObjectBuilder;
public class JSONTestUtil {
- /**
- * Default delta used in numeric equality comparisons for floats and doubles.
- */
- public final static double DEFAULT_DELTA = 1e-5;
+ /** Default delta used in numeric equality comparisons for floats and doubles. */
+ public static final double DEFAULT_DELTA = 1e-5;
+
public static boolean failRepeatedKeys = false;
/**
* comparison using default delta
+ *
* @see #DEFAULT_DELTA
* @see #match(String,String,double)
*/
@@ -45,6 +43,7 @@ public class JSONTestUtil {
/**
* comparison using default delta
+ *
* @see #DEFAULT_DELTA
* @see #match(String,String,String,double)
*/
@@ -54,11 +53,12 @@ public class JSONTestUtil {
/**
* comparison using default delta
+ *
* @see #DEFAULT_DELTA
* @see #matchObj(String,Object,Object,double)
*/
public static String matchObj(String path, Object input, Object expected) throws IOException {
- return matchObj(path,input,expected, DEFAULT_DELTA);
+ return matchObj(path, input, expected, DEFAULT_DELTA);
}
/**
@@ -66,10 +66,11 @@ public class JSONTestUtil {
* @param pathAndExpected JSON path expression + '==' + expected value
* @param delta tolerance allowed in comparing float/double values
*/
- public static String match(String input, String pathAndExpected, double delta) throws IOException {
+ public static String match(String input, String pathAndExpected, double delta)
+ throws IOException {
int pos = pathAndExpected.indexOf("==");
- String path = pos>=0 ? pathAndExpected.substring(0,pos) : null;
- String expected = pos>=0 ? pathAndExpected.substring(pos+2) : pathAndExpected;
+ String path = pos >= 0 ? pathAndExpected.substring(0, pos) : null;
+ String expected = pos >= 0 ? pathAndExpected.substring(pos + 2) : pathAndExpected;
return match(path, input, expected, delta);
}
@@ -78,11 +79,15 @@ public class JSONTestUtil {
* @param pathAndExpected JSON path expression + '==' + expected value
* @param delta tolerance allowed in comparing float/double values
*/
- public static String matchObj(Object input, String pathAndExpected, double delta) throws IOException {
+ public static String matchObj(Object input, String pathAndExpected, double delta)
+ throws IOException {
int pos = pathAndExpected.indexOf("==");
- String path = pos>=0 ? pathAndExpected.substring(0,pos) : null;
- String expected = pos>=0 ? pathAndExpected.substring(pos+2) : pathAndExpected;
- Object expectObj = failRepeatedKeys ? new NoDupsObjectBuilder(new JSONParser(expected)).getVal() : ObjectBuilder.fromJSON(expected);
+ String path = pos >= 0 ? pathAndExpected.substring(0, pos) : null;
+ String expected = pos >= 0 ? pathAndExpected.substring(pos + 2) : pathAndExpected;
+ Object expectObj =
+ failRepeatedKeys
+ ? new NoDupsObjectBuilder(new JSONParser(expected)).getVal()
+ : ObjectBuilder.fromJSON(expected);
return matchObj(path, input, expectObj, delta);
}
@@ -92,9 +97,16 @@ public class JSONTestUtil {
* @param expected expected value of path
* @param delta tolerance allowed in comparing float/double values
*/
- public static String match(String path, String input, String expected, double delta) throws IOException {
- Object inputObj = failRepeatedKeys ? new NoDupsObjectBuilder(new JSONParser(input)).getVal() : ObjectBuilder.fromJSON(input);
- Object expectObj = failRepeatedKeys ? new NoDupsObjectBuilder(new JSONParser(expected)).getVal() : ObjectBuilder.fromJSON(expected);
+ public static String match(String path, String input, String expected, double delta)
+ throws IOException {
+ Object inputObj =
+ failRepeatedKeys
+ ? new NoDupsObjectBuilder(new JSONParser(input)).getVal()
+ : ObjectBuilder.fromJSON(input);
+ Object expectObj =
+ failRepeatedKeys
+ ? new NoDupsObjectBuilder(new JSONParser(expected)).getVal()
+ : ObjectBuilder.fromJSON(expected);
return matchObj(path, inputObj, expectObj, delta);
}
@@ -108,7 +120,8 @@ public class JSONTestUtil {
@SuppressWarnings({"unchecked"})
Object prev = ((Map<Object, Object>) map).put(key, val);
if (prev != null) {
- throw new RuntimeException("REPEATED JSON OBJECT KEY: key=" + key + " prevValue=" + prev + " thisValue" + val);
+ throw new RuntimeException(
+ "REPEATED JSON OBJECT KEY: key=" + key + " prevValue=" + prev + " thisValue" + val);
}
}
}
@@ -121,7 +134,7 @@ public class JSONTestUtil {
* @return the error message from the match, or null if match was good
*/
public static String matchObj(String path, Object input, Object expected, double delta) {
- CollectionTester tester = new CollectionTester(input,delta);
+ CollectionTester tester = new CollectionTester(input, delta);
boolean reversed = path.startsWith("!");
String positivePath = reversed ? path.substring(1) : path;
if (!tester.seek(positivePath) ^ reversed) {
@@ -134,7 +147,6 @@ public class JSONTestUtil {
}
}
-
/** Tests simple object graphs, like those generated by the noggit JSON parser */
class CollectionTester {
public Object valRoot;
@@ -151,17 +163,18 @@ class CollectionTester {
this.delta = delta;
path = new ArrayList<>();
}
+
public CollectionTester(Object val) {
this(val, JSONTestUtil.DEFAULT_DELTA);
}
public String getPath() {
StringBuilder sb = new StringBuilder();
- boolean first=true;
+ boolean first = true;
for (Object seg : path) {
- if (seg==null) break;
+ if (seg == null) break;
if (!first) sb.append('/');
- else first=false;
+ else first = false;
if (seg instanceof Integer) {
sb.append('[');
@@ -175,11 +188,13 @@ class CollectionTester {
}
void setPath(Object lastSeg) {
- path.set(path.size()-1, lastSeg);
+ path.set(path.size() - 1, lastSeg);
}
+
Object popPath() {
- return path.remove(path.size()-1);
+ return path.remove(path.size() - 1);
}
+
void pushPath(Object lastSeg) {
path.add(lastSeg);
}
@@ -213,21 +228,23 @@ class CollectionTester {
if (!expected.equals(val)) {
if (expected instanceof String) {
- String str = (String)expected;
+ String str = (String) expected;
if (str.length() > 6 && str.startsWith("///") && str.endsWith("///")) {
return handleSpecialString(str);
}
}
// make an exception for some numerics
- if ((expected instanceof Integer && val instanceof Long || expected instanceof Long && val instanceof Integer)
- && ((Number)expected).longValue() == ((Number)val).longValue()) {
+ if ((expected instanceof Integer && val instanceof Long
+ || expected instanceof Long && val instanceof Integer)
+ && ((Number) expected).longValue() == ((Number) val).longValue()) {
return true;
- } else if ((expected instanceof Double || expected instanceof Float) && (val instanceof Double || val instanceof Float)) {
- double a = ((Number)expected).doubleValue();
- double b = ((Number)val).doubleValue();
- if (Double.compare(a,b) == 0) return true;
- if (Math.abs(a-b) < delta) return true;
+ } else if ((expected instanceof Double || expected instanceof Float)
+ && (val instanceof Double || val instanceof Float)) {
+ double a = ((Number) expected).doubleValue();
+ double b = ((Number) val).doubleValue();
+ if (Double.compare(a, b) == 0) return true;
+ if (Math.abs(a - b) < delta) return true;
}
setErr("mismatch: '" + expected + "'!='" + val + "'");
return false;
@@ -238,7 +255,7 @@ class CollectionTester {
}
private boolean handleSpecialString(String str) {
- String code = str.substring(3,str.length()-3);
+ String code = str.substring(3, str.length() - 3);
if ("ignore".equals(code)) {
return true;
} else if (code.startsWith("regex:")) {
@@ -248,7 +265,7 @@ class CollectionTester {
return false;
}
Pattern pattern = Pattern.compile(regex);
- Matcher matcher = pattern.matcher((String)val);
+ Matcher matcher = pattern.matcher((String) val);
if (matcher.find()) {
return true;
}
@@ -262,19 +279,19 @@ class CollectionTester {
boolean matchList() {
@SuppressWarnings({"rawtypes"})
- List expectedList = (List)expected;
+ List expectedList = (List) expected;
@SuppressWarnings({"rawtypes"})
List v = asList();
if (v == null) return false;
int a = 0;
int b = 0;
pushPath(null);
- for (;;) {
- if (a >= expectedList.size() && b >=v.size()) {
+ for (; ; ) {
+ if (a >= expectedList.size() && b >= v.size()) {
break;
}
- if (a >= expectedList.size() || b >=v.size()) {
+ if (a >= expectedList.size() || b >= v.size()) {
popPath();
setErr("List size mismatch");
return false;
@@ -285,24 +302,26 @@ class CollectionTester {
setPath(b);
if (!match()) return false;
- a++; b++;
+ a++;
+ b++;
}
-
+
popPath();
return true;
}
- private static Set<String> reserved = new HashSet<>(Arrays.asList("_SKIP_","_MATCH_","_ORDERED_","_UNORDERED_"));
+ private static Set<String> reserved =
+ new HashSet<>(Arrays.asList("_SKIP_", "_MATCH_", "_ORDERED_", "_UNORDERED_"));
@SuppressWarnings({"unchecked", "rawtypes"})
boolean matchMap() {
- Map<String,Object> expectedMap = (Map<String,Object>)expected;
- Map<String,Object> v = asMap();
+ Map<String, Object> expectedMap = (Map<String, Object>) expected;
+ Map<String, Object> v = asMap();
if (v == null) return false;
boolean ordered = false;
- String skipList = (String)expectedMap.get("_SKIP_");
- String matchList = (String)expectedMap.get("_MATCH_");
+ String skipList = (String) expectedMap.get("_SKIP_");
+ String matchList = (String) expectedMap.get("_MATCH_");
Object orderedStr = expectedMap.get("_ORDERED_");
Object unorderedStr = expectedMap.get("_UNORDERED_");
@@ -311,20 +330,20 @@ class CollectionTester {
Set<String> match = null;
if (matchList != null) {
- match = new HashSet(StrUtils.splitSmart(matchList,",",false));
+ match = new HashSet(StrUtils.splitSmart(matchList, ",", false));
}
Set<String> skips = null;
if (skipList != null) {
- skips = new HashSet(StrUtils.splitSmart(skipList,",",false));
+ skips = new HashSet(StrUtils.splitSmart(skipList, ",", false));
}
Set<String> keys = match != null ? match : expectedMap.keySet();
Set<String> visited = new HashSet<>();
- Iterator<Map.Entry<String,Object>> iter = ordered ? v.entrySet().iterator() : null;
+ Iterator<Map.Entry<String, Object>> iter = ordered ? v.entrySet().iterator() : null;
- int numExpected=0;
+ int numExpected = 0;
pushPath(null);
for (String expectedKey : keys) {
@@ -341,24 +360,29 @@ class CollectionTester {
expected = expectedMap.get(expectedKey);
if (ordered) {
- Map.Entry<String,Object> entry;
+ Map.Entry<String, Object> entry;
String foundKey;
- for(;;) {
+ for (; ; ) {
if (!iter.hasNext()) {
popPath();
setErr("expected key '" + expectedKey + "' in ordered map");
- return false;
+ return false;
}
entry = iter.next();
foundKey = entry.getKey();
- if (skips != null && skips.contains(foundKey))continue;
+ if (skips != null && skips.contains(foundKey)) continue;
if (match != null && !match.contains(foundKey)) continue;
break;
}
if (!entry.getKey().equals(expectedKey)) {
- popPath();
- setErr("expected key '" + expectedKey + "' instead of '"+entry.getKey()+"' in ordered map");
+ popPath();
+ setErr(
+ "expected key '"
+ + expectedKey
+ + "' instead of '"
+ + entry.getKey()
+ + "' in ordered map");
return false;
}
val = entry.getValue();
@@ -372,17 +396,17 @@ class CollectionTester {
popPath();
- // now check if there were any extra keys in the value (as long as there wasn't a specific list to include)
+ // now check if there were any extra keys in the value (as long as there wasn't a specific list
+ // to include)
if (match == null) {
int skipped = 0;
if (skips != null) {
- for (String skipStr : skips)
- if (v.containsKey(skipStr)) skipped++;
+ for (String skipStr : skips) if (v.containsKey(skipStr)) skipped++;
}
if (numExpected != (v.size() - skipped)) {
HashSet<String> set = new HashSet<>(v.keySet());
set.removeAll(expectedMap.keySet());
- setErr("unexpected map keys " + set);
+ setErr("unexpected map keys " + set);
return false;
}
}
@@ -396,7 +420,7 @@ class CollectionTester {
seekPath = seekPath.substring(1);
}
if (seekPath.endsWith("/")) {
- seekPath = seekPath.substring(0,seekPath.length()-1);
+ seekPath = seekPath.substring(0, seekPath.length() - 1);
}
List<String> pathList = StrUtils.splitSmart(seekPath, "/", false);
return seek(pathList);
@@ -406,17 +430,17 @@ class CollectionTester {
List asList() {
// TODO: handle native arrays
if (val instanceof List) {
- return (List)val;
+ return (List) val;
}
setErr("expected List");
return null;
}
-
+
@SuppressWarnings({"unchecked"})
- Map<String,Object> asMap() {
+ Map<String, Object> asMap() {
// TODO: handle NamedList
if (val instanceof Map) {
- return (Map<String,Object>)val;
+ return (Map<String, Object>) val;
}
setErr("expected Map");
return null;
@@ -426,20 +450,20 @@ class CollectionTester {
if (seekPath.size() == 0) return true;
String seg = seekPath.get(0);
- if (seg.charAt(0)=='[') {
+ if (seg.charAt(0) == '[') {
@SuppressWarnings({"rawtypes"})
List listVal = asList();
- if (listVal==null) return false;
+ if (listVal == null) return false;
- int arrIdx = Integer.parseInt(seg.substring(1, seg.length()-1));
+ int arrIdx = Integer.parseInt(seg.substring(1, seg.length() - 1));
if (arrIdx >= listVal.size()) return false;
val = listVal.get(arrIdx);
pushPath(arrIdx);
} else {
- Map<String,Object> mapVal = asMap();
- if (mapVal==null) return false;
+ Map<String, Object> mapVal = asMap();
+ if (mapVal == null) return false;
// use containsKey rather than get to handle null values
if (!mapVal.containsKey(seg)) return false;
@@ -449,9 +473,6 @@ class CollectionTester {
}
// recurse after removing head of the path
- return seek(seekPath.subList(1,seekPath.size()));
+ return seek(seekPath.subList(1, seekPath.size()));
}
-
-
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrIgnoredThreadsFilter.java b/solr/test-framework/src/java/org/apache/solr/SolrIgnoredThreadsFilter.java
index 01974f74206..085364361d5 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrIgnoredThreadsFilter.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrIgnoredThreadsFilter.java
@@ -16,16 +16,11 @@
*/
package org.apache.solr;
+import com.carrotsearch.randomizedtesting.ThreadFilter;
import java.lang.Thread.State;
import org.apache.lucene.search.TimeLimitingCollector.TimerThread;
-import com.carrotsearch.randomizedtesting.ThreadFilter;
-
-
-/**
- * This ignores those threads in Solr for which there is no way to
- * clean up after a suite.
- */
+/** This ignores those threads in Solr for which there is no way to clean up after a suite. */
public class SolrIgnoredThreadsFilter implements ThreadFilter {
@Override
public boolean reject(Thread t) {
@@ -65,12 +60,12 @@ public class SolrIgnoredThreadsFilter implements ThreadFilter {
return true;
}
-
if (threadName.startsWith("SessionTracker")) {
return true;
}
- if (threadName.startsWith("zkConnectionManagerCallback") && t.getState() == State.TIMED_WAITING) {
+ if (threadName.startsWith("zkConnectionManagerCallback")
+ && t.getState() == State.TIMED_WAITING) {
return true;
}
@@ -81,7 +76,7 @@ public class SolrIgnoredThreadsFilter implements ThreadFilter {
if (threadName.startsWith("async-check-index-")) {
return true;
}
-
+
return threadName.startsWith("closeThreadPool");
}
}
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java b/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java
index 07dae975f60..b9d6c89a7fe 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrJettyTestBase.java
@@ -22,11 +22,11 @@ import java.io.OutputStreamWriter;
import java.io.UncheckedIOException;
import java.io.Writer;
import java.lang.invoke.MethodHandles;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;
import java.util.SortedMap;
-
import org.apache.commons.io.FileUtils;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.client.solrj.SolrClient;
@@ -42,62 +42,68 @@ import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.nio.charset.StandardCharsets;
-
-abstract public class SolrJettyTestBase extends SolrTestCaseJ4
-{
+public abstract class SolrJettyTestBase extends SolrTestCaseJ4 {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@BeforeClass
- public static void beforeSolrJettyTestBase() throws Exception {
-
- }
+ public static void beforeSolrJettyTestBase() throws Exception {}
public static JettySolrRunner jetty;
public static int port;
public static SolrClient client = null;
public static String context;
- public static JettySolrRunner createAndStartJetty(String solrHome, String configFile, String schemaFile, String context,
- boolean stopAtShutdown, SortedMap<ServletHolder,String> extraServlets)
+ public static JettySolrRunner createAndStartJetty(
+ String solrHome,
+ String configFile,
+ String schemaFile,
+ String context,
+ boolean stopAtShutdown,
+ SortedMap<ServletHolder, String> extraServlets)
throws Exception {
// creates the data dir
- context = context==null ? "/solr" : context;
+ context = context == null ? "/solr" : context;
SolrJettyTestBase.context = context;
- JettyConfig jettyConfig = JettyConfig.builder()
- .setContext(context)
- .stopAtShutdown(stopAtShutdown)
- .withServlets(extraServlets)
- .withSSLConfig(sslConfig.buildServerSSLConfig())
- .build();
+ JettyConfig jettyConfig =
+ JettyConfig.builder()
+ .setContext(context)
+ .stopAtShutdown(stopAtShutdown)
+ .withServlets(extraServlets)
+ .withSSLConfig(sslConfig.buildServerSSLConfig())
+ .build();
Properties nodeProps = new Properties();
- if (configFile != null)
- nodeProps.setProperty("solrconfig", configFile);
- if (schemaFile != null)
- nodeProps.setProperty("schema", schemaFile);
- if (System.getProperty("solr.data.dir") == null && System.getProperty("solr.hdfs.home") == null) {
+ if (configFile != null) nodeProps.setProperty("solrconfig", configFile);
+ if (schemaFile != null) nodeProps.setProperty("schema", schemaFile);
+ if (System.getProperty("solr.data.dir") == null
+ && System.getProperty("solr.hdfs.home") == null) {
nodeProps.setProperty("solr.data.dir", createTempDir().toFile().getCanonicalPath());
}
return createAndStartJetty(solrHome, nodeProps, jettyConfig);
}
- public static JettySolrRunner createAndStartJetty(String solrHome, String configFile, String context) throws Exception {
+ public static JettySolrRunner createAndStartJetty(
+ String solrHome, String configFile, String context) throws Exception {
return createAndStartJetty(solrHome, configFile, null, context, true, null);
}
- public static JettySolrRunner createAndStartJetty(String solrHome, JettyConfig jettyConfig) throws Exception {
+ public static JettySolrRunner createAndStartJetty(String solrHome, JettyConfig jettyConfig)
+ throws Exception {
return createAndStartJetty(solrHome, new Properties(), jettyConfig);
}
public static JettySolrRunner createAndStartJetty(String solrHome) throws Exception {
- return createAndStartJetty(solrHome, new Properties(), JettyConfig.builder().withSSLConfig(sslConfig.buildServerSSLConfig()).build());
+ return createAndStartJetty(
+ solrHome,
+ new Properties(),
+ JettyConfig.builder().withSSLConfig(sslConfig.buildServerSSLConfig()).build());
}
- public static JettySolrRunner createAndStartJetty(String solrHome, Properties nodeProperties, JettyConfig jettyConfig) throws Exception {
+ public static JettySolrRunner createAndStartJetty(
+ String solrHome, Properties nodeProperties, JettyConfig jettyConfig) throws Exception {
initCore(null, null, solrHome);
@@ -144,10 +150,9 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4
}
/**
- * Create a new solr client.
- * If createJetty was called, an http implementation will be created,
- * otherwise an embedded implementation will be created.
- * Subclasses should override for other options.
+ * Create a new solr client. If createJetty was called, an http implementation will be created,
+ * otherwise an embedded implementation will be created. Subclasses should override for other
+ * options.
*/
public SolrClient createNewSolrClient() {
try {
@@ -160,8 +165,9 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4
}
}
- // Sets up the necessary config files for Jetty. At least some tests require that the solrconfig from the test
- // file directory are used, but some also require that the solr.xml file be explicitly there as of SOLR-4817
+ // Sets up the necessary config files for Jetty. At least some tests require that the solrconfig
+ // from the test file directory are used, but some also require that the solr.xml file be
+ // explicitly there as of SOLR-4817
public static void setupJettyTestHome(File solrHome, String collection) throws Exception {
copySolrHomeToTemp(solrHome, collection);
}
@@ -175,7 +181,8 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4
public static String legacyExampleCollection1SolrHome() {
String sourceHome = ExternalPaths.SOURCE_HOME;
if (sourceHome == null)
- throw new IllegalStateException("No source home! Cannot create the legacy example solr home directory.");
+ throw new IllegalStateException(
+ "No source home! Cannot create the legacy example solr home directory.");
try {
Path tempSolrHome = LuceneTestCase.createTempDir();
@@ -185,11 +192,15 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4
Path sourceConfig = serverSolr.resolve("configsets").resolve("sample_techproducts_configs");
Path collection1Dir = tempSolrHome.resolve("collection1");
- DirectoryUtil.copyDirectoryContents(sourceConfig.resolve("conf"), collection1Dir.resolve("conf"));
+ DirectoryUtil.copyDirectoryContents(
+ sourceConfig.resolve("conf"), collection1Dir.resolve("conf"));
Properties props = new Properties();
props.setProperty("name", "collection1");
- try (Writer writer = new OutputStreamWriter(Files.newOutputStream(collection1Dir.resolve("core.properties")), StandardCharsets.UTF_8)) {
+ try (Writer writer =
+ new OutputStreamWriter(
+ Files.newOutputStream(collection1Dir.resolve("core.properties")),
+ StandardCharsets.UTF_8)) {
props.store(writer, null);
}
return tempSolrHome.toString();
@@ -199,5 +210,4 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4
throw new UncheckedIOException(e);
}
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCase.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCase.java
index 21fc34f86d9..14d05a97c29 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCase.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCase.java
@@ -17,11 +17,14 @@
package org.apache.solr;
-import java.lang.invoke.MethodHandles;
-import java.io.File;
-import java.util.regex.Pattern;
+import static com.carrotsearch.randomizedtesting.RandomizedTest.systemPropertyAsBoolean;
+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;
+import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
+import java.io.File;
+import java.lang.invoke.MethodHandles;
+import java.util.regex.Pattern;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.QuickPatchThreadsFilter;
import org.apache.lucene.util.VerifyTestClassNamingConvention;
@@ -39,76 +42,81 @@ import org.junit.rules.TestRule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
-
-import static com.carrotsearch.randomizedtesting.RandomizedTest.systemPropertyAsBoolean;
-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
-
/**
- * All Solr test cases should derive from this class eventually. This is originally a result of async logging, see:
- * SOLR-12055 and associated. To enable async logging, we must gracefully shut down logging. Many Solr tests subclass
- * LuceneTestCase.
+ * All Solr test cases should derive from this class eventually. This is originally a result of
+ * async logging, see: SOLR-12055 and associated. To enable async logging, we must gracefully shut
+ * down logging. Many Solr tests subclass LuceneTestCase.
*
- * Rather than add the cruft from SolrTestCaseJ4 to all the Solr tests that currently subclass LuceneTestCase,
- * we'll add the shutdown to this class and subclass it.
+ * <p>Rather than add the cruft from SolrTestCaseJ4 to all the Solr tests that currently subclass
+ * LuceneTestCase, we'll add the shutdown to this class and subclass it.
*
- * Other changes that should affect every Solr test case may go here if they don't require the added capabilities in
- * SolrTestCaseJ4.
+ * <p>Other changes that should affect every Solr test case may go here if they don't require the
+ * added capabilities in SolrTestCaseJ4.
*/
- // ThreadLeakFilters are not additive. Any subclass that requires filters
- // other than these must redefine these as well.
-@ThreadLeakFilters(defaultFilters = true, filters = {
- SolrIgnoredThreadsFilter.class,
- QuickPatchThreadsFilter.class
-})
+// ThreadLeakFilters are not additive. Any subclass that requires filters
+// other than these must redefine these as well.
+@ThreadLeakFilters(
+ defaultFilters = true,
+ filters = {SolrIgnoredThreadsFilter.class, QuickPatchThreadsFilter.class})
@ThreadLeakLingering(linger = 0)
public class SolrTestCase extends LuceneTestCase {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- private static final Pattern NAMING_CONVENTION_TEST_SUFFIX = Pattern.compile("(.+\\.)([^.]+)(Test)");
+ private static final Pattern NAMING_CONVENTION_TEST_SUFFIX =
+ Pattern.compile("(.+\\.)([^.]+)(Test)");
- private static final Pattern NAMING_CONVENTION_TEST_PREFIX = Pattern.compile("(.+\\.)(Test)([^.]+)");
+ private static final Pattern NAMING_CONVENTION_TEST_PREFIX =
+ Pattern.compile("(.+\\.)(Test)([^.]+)");
@ClassRule
- public static TestRule solrClassRules =
- RuleChain.outerRule(new SystemPropertiesRestoreRule())
- .around(
- new VerifyTestClassNamingConvention(
- "org.apache.solr.analytics", NAMING_CONVENTION_TEST_SUFFIX))
- .around(
- new VerifyTestClassNamingConvention(
- "org.apache.solr.ltr", NAMING_CONVENTION_TEST_PREFIX))
- .around(new RevertDefaultThreadHandlerRule());
+ public static TestRule solrClassRules =
+ RuleChain.outerRule(new SystemPropertiesRestoreRule())
+ .around(
+ new VerifyTestClassNamingConvention(
+ "org.apache.solr.analytics", NAMING_CONVENTION_TEST_SUFFIX))
+ .around(
+ new VerifyTestClassNamingConvention(
+ "org.apache.solr.ltr", NAMING_CONVENTION_TEST_PREFIX))
+ .around(new RevertDefaultThreadHandlerRule());
/**
- * Sets the <code>solr.default.confdir</code> system property to the value of
- * {@link ExternalPaths#DEFAULT_CONFIGSET} if and only if the system property is not already set,
- * and the <code>DEFAULT_CONFIGSET</code> exists and is a readable directory.
- * <p>
- * Logs INFO/WARNing messages as appropriate based on these 2 conditions.
- * </p>
+ * Sets the <code>solr.default.confdir</code> system property to the value of {@link
+ * ExternalPaths#DEFAULT_CONFIGSET} if and only if the system property is not already set, and the
+ * <code>DEFAULT_CONFIGSET</code> exists and is a readable directory.
+ *
+ * <p>Logs INFO/WARNing messages as appropriate based on these 2 conditions.
+ *
* @see SolrDispatchFilter#SOLR_DEFAULT_CONFDIR_ATTRIBUTE
*/
@BeforeClass
public static void beforeSolrTestCase() {
- final String existingValue = System.getProperty(SolrDispatchFilter.SOLR_DEFAULT_CONFDIR_ATTRIBUTE);
+ final String existingValue =
+ System.getProperty(SolrDispatchFilter.SOLR_DEFAULT_CONFDIR_ATTRIBUTE);
if (null != existingValue) {
- log.info("Test env includes configset dir system property '{}'='{}'", SolrDispatchFilter.SOLR_DEFAULT_CONFDIR_ATTRIBUTE, existingValue);
+ log.info(
+ "Test env includes configset dir system property '{}'='{}'",
+ SolrDispatchFilter.SOLR_DEFAULT_CONFDIR_ATTRIBUTE,
+ existingValue);
return;
}
final File extPath = new File(ExternalPaths.DEFAULT_CONFIGSET);
- if (extPath.canRead(/* implies exists() */) && extPath.isDirectory()) {
- log.info("Setting '{}' system property to test-framework derived value of '{}'",
- SolrDispatchFilter.SOLR_DEFAULT_CONFDIR_ATTRIBUTE, ExternalPaths.DEFAULT_CONFIGSET);
+ if (extPath.canRead(/* implies exists() */ ) && extPath.isDirectory()) {
+ log.info(
+ "Setting '{}' system property to test-framework derived value of '{}'",
+ SolrDispatchFilter.SOLR_DEFAULT_CONFDIR_ATTRIBUTE,
+ ExternalPaths.DEFAULT_CONFIGSET);
assert null == existingValue;
- System.setProperty(SolrDispatchFilter.SOLR_DEFAULT_CONFDIR_ATTRIBUTE, ExternalPaths.DEFAULT_CONFIGSET);
+ System.setProperty(
+ SolrDispatchFilter.SOLR_DEFAULT_CONFDIR_ATTRIBUTE, ExternalPaths.DEFAULT_CONFIGSET);
} else {
- log.warn("System property '{}' is not already set, but test-framework derived value ('{}') either " +
- "does not exist or is not a readable directory, you may need to set the property yourself " +
- "for tests to run properly",
- SolrDispatchFilter.SOLR_DEFAULT_CONFDIR_ATTRIBUTE, ExternalPaths.DEFAULT_CONFIGSET);
+ log.warn(
+ "System property '{}' is not already set, but test-framework derived value ('{}') either "
+ + "does not exist or is not a readable directory, you may need to set the property yourself "
+ + "for tests to run properly",
+ SolrDispatchFilter.SOLR_DEFAULT_CONFDIR_ATTRIBUTE,
+ ExternalPaths.DEFAULT_CONFIGSET);
}
if (!TEST_NIGHTLY) {
@@ -119,33 +127,33 @@ public class SolrTestCase extends LuceneTestCase {
System.setProperty("zookeeper.nio.shutdownTimeout", "100");
}
}
-
- /**
- * Special hook for sanity checking if any tests trigger failures when an
- * Assumption failure occures in a {@link BeforeClass} method
+
+ /**
+ * Special hook for sanity checking if any tests trigger failures when an Assumption failure
+ * occures in a {@link BeforeClass} method
+ *
* @lucene.internal
*/
@BeforeClass
public static void checkSyspropForceBeforeClassAssumptionFailure() {
// ant test -Dargs="-Dtests.force.assumption.failure.beforeclass=true"
final String PROP = "tests.force.assumption.failure.beforeclass";
- assumeFalse(PROP + " == true",
- systemPropertyAsBoolean(PROP, false));
+ assumeFalse(PROP + " == true", systemPropertyAsBoolean(PROP, false));
}
-
- /**
- * Special hook for sanity checking if any tests trigger failures when an
- * Assumption failure occures in a {@link Before} method
+
+ /**
+ * Special hook for sanity checking if any tests trigger failures when an Assumption failure
+ * occures in a {@link Before} method
+ *
* @lucene.internal
*/
@Before
public void checkSyspropForceBeforeAssumptionFailure() {
// ant test -Dargs="-Dtests.force.assumption.failure.before=true"
final String PROP = "tests.force.assumption.failure.before";
- assumeFalse(PROP + " == true",
- systemPropertyAsBoolean(PROP, false));
+ assumeFalse(PROP + " == true", systemPropertyAsBoolean(PROP, false));
}
-
+
@AfterClass
public static void afterSolrTestCase() throws Exception {
if (suiteFailureMarker.wasSuccessful()) {
@@ -157,5 +165,4 @@ public class SolrTestCase extends LuceneTestCase {
}
StartupLoggingUtils.shutdown();
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseHS.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseHS.java
index 84e7e789712..ebb56065544 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseHS.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseHS.java
@@ -16,7 +16,6 @@
*/
package org.apache.solr;
-import javax.xml.xpath.XPathExpressionException;
import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
@@ -36,7 +35,7 @@ import java.util.Map;
import java.util.Properties;
import java.util.Random;
import java.util.Set;
-
+import javax.xml.xpath.XPathExpressionException;
import org.apache.lucene.util.IOUtils;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
@@ -65,12 +64,12 @@ import org.noggit.ObjectBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
@SolrTestCaseJ4.SuppressSSL
-//@LuceneTestCase.SuppressCodecs({"Lucene3x","Lucene40","Lucene41","Lucene42","Lucene45","Appending","Asserting"})
+// @LuceneTestCase.SuppressCodecs({"Lucene3x","Lucene40","Lucene41","Lucene42","Lucene45","Appending","Asserting"})
public class SolrTestCaseHS extends SolrTestCaseJ4 {
-
+
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
@SafeVarargs
public static <T> Set<T> set(T... a) {
LinkedHashSet<T> s = new LinkedHashSet<>();
@@ -82,20 +81,20 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {
@SuppressWarnings({"unchecked"})
public static <T> T rand(T... vals) {
- return vals[ random().nextInt(vals.length) ];
+ return vals[random().nextInt(vals.length)];
}
-
public static ModifiableSolrParams params(SolrParams params, String... moreParams) {
ModifiableSolrParams msp = new ModifiableSolrParams(params);
- for (int i=0; i<moreParams.length; i+=2) {
- msp.add(moreParams[i], moreParams[i+1]);
+ for (int i = 0; i < moreParams.length; i += 2) {
+ msp.add(moreParams[i], moreParams[i + 1]);
}
return msp;
}
- public static Map<String,Object> toObject(Doc doc, IndexSchema schema, Collection<String> fieldNames) {
- Map<String,Object> result = new HashMap<>();
+ public static Map<String, Object> toObject(
+ Doc doc, IndexSchema schema, Collection<String> fieldNames) {
+ Map<String, Object> result = new HashMap<>();
for (Fld fld : doc.fields) {
if (fieldNames != null && !fieldNames.contains(fld.ftype.fname)) continue;
SchemaField sf = schema.getField(fld.ftype.fname);
@@ -107,54 +106,57 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {
}
return result;
}
-
-
+
@SuppressWarnings({"unchecked"})
- public static Object createDocObjects(@SuppressWarnings({"rawtypes"})Map<Comparable, Doc> fullModel,
- @SuppressWarnings({"rawtypes"})Comparator sort, int rows,
- Collection<String> fieldNames) {
+ public static Object createDocObjects(
+ @SuppressWarnings({"rawtypes"}) Map<Comparable, Doc> fullModel,
+ @SuppressWarnings({"rawtypes"}) Comparator sort,
+ int rows,
+ Collection<String> fieldNames) {
List<Doc> docList = new ArrayList<>(fullModel.values());
Collections.sort(docList, sort);
@SuppressWarnings({"rawtypes"})
List sortedDocs = new ArrayList(rows);
for (Doc doc : docList) {
if (sortedDocs.size() >= rows) break;
- Map<String,Object> odoc = toObject(doc, h.getCore().getLatestSchema(), fieldNames);
+ Map<String, Object> odoc = toObject(doc, h.getCore().getLatestSchema(), fieldNames);
sortedDocs.add(toObject(doc, h.getCore().getLatestSchema(), fieldNames));
}
return sortedDocs;
}
-
- public static void compare(SolrQueryRequest req, String path, Object model,
- @SuppressWarnings({"rawtypes"})Map<Comparable, Doc> fullModel) throws Exception {
+ public static void compare(
+ SolrQueryRequest req,
+ String path,
+ Object model,
+ @SuppressWarnings({"rawtypes"}) Map<Comparable, Doc> fullModel)
+ throws Exception {
String strResponse = h.query(req);
Object realResponse = ObjectBuilder.fromJSON(strResponse);
String err = JSONTestUtil.matchObj(path, realResponse, model);
if (err != null) {
- log.error("RESPONSE MISMATCH: {}\n\trequest={}\n\tresult={}" +
- "\n\texpected={}\n\tmodel={}"
- , err, req, strResponse, JSONUtil.toJSON(model), fullModel);
+ String msg = "RESPONSE MISMATCH: {}\n\trequest={}\n\tresult={}\n\texpected={}\n\tmodel={}";
+ log.error(msg, err, req, strResponse, JSONUtil.toJSON(model), fullModel);
// re-execute the request... good for putting a breakpoint here for debugging
String rsp = h.query(req);
fail(err);
}
-
}
/** Pass "null" for the client to query the local server */
- public static void assertJQ(SolrClient client, SolrParams args, String... tests) throws Exception {
+ public static void assertJQ(SolrClient client, SolrParams args, String... tests)
+ throws Exception {
String resp;
resp = getJSON(client, args);
matchJSON(resp, tests);
}
/**
- * Pass "null" for the client to query to the local server.
- * Fetches response in xml format and matches with the given set of xpaths
+ * Pass "null" for the client to query to the local server. Fetches response in xml format and
+ * matches with the given set of xpaths
*/
public static void assertQ(SolrClient client, SolrParams args, String... tests) throws Exception {
String resp;
@@ -162,9 +164,13 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {
try {
String results = TestHarness.validateXPath(resp, tests);
if (null != results) {
- String msg = "REQUEST FAILED: xpath=" + results
- + "\n\txml response was: " + resp
- + "\n\tparams were:" + args.toQueryString();
+ String msg =
+ "REQUEST FAILED: xpath="
+ + results
+ + "\n\txml response was: "
+ + resp
+ + "\n\tparams were:"
+ + args.toQueryString();
log.error(msg);
throw new RuntimeException(msg);
@@ -172,7 +178,7 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {
} catch (XPathExpressionException e1) {
throw new RuntimeException("XPath is invalid", e1);
} catch (Exception e2) {
- SolrException.log(log,"REQUEST FAILED for params: " + args.toQueryString(), e2);
+ SolrException.log(log, "REQUEST FAILED for params: " + args.toQueryString(), e2);
throw new RuntimeException("Exception during query", e2);
}
}
@@ -181,43 +187,39 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {
boolean failed = false;
for (String test : tests) {
- if (test == null || test.length()==0) continue;
+ if (test == null || test.length() == 0) continue;
try {
failed = true;
String err = JSONTestUtil.match(response, test, JSONTestUtil.DEFAULT_DELTA);
failed = false;
if (err != null) {
- log.error("query failed JSON validation. error={}\n expected ={}\n response = {}"
- , err, test, response
- );
+ log.error(
+ "query failed JSON validation. error={}\n expected ={}\n response = {}",
+ err,
+ test,
+ response);
throw new RuntimeException(err);
}
} finally {
if (failed) {
- log.error("JSON query validation threw an exception.\n expected ={}\n response = {}"
- , test, response
- );
+ log.error(
+ "JSON query validation threw an exception.\n expected ={}\n response = {}",
+ test,
+ response);
}
}
}
}
- /***
- public static void clearNCache() {
- SolrQueryRequest req = req();
- req.getSearcher().getnCache().clear(); // OFF-HEAP
- req.close();
- }***/
-
public static void clearQueryCache() {
SolrQueryRequest req = req();
req.getSearcher();
req.close();
}
-
- public static String getQueryResponse(SolrClient client, String wt, SolrParams params) throws Exception {
+ public static String getQueryResponse(SolrClient client, String wt, SolrParams params)
+ throws Exception {
if (client == null) {
return getQueryResponse(wt, params);
}
@@ -225,9 +227,9 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {
p.set("wt", wt);
String path = p.get("qt");
p.remove("qt");
- p.set("indent","true");
+ p.set("indent", "true");
- QueryRequest query = new QueryRequest( p );
+ QueryRequest query = new QueryRequest(p);
if (path != null) {
query.setPath(path);
}
@@ -239,7 +241,7 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {
} else {
query.setResponseParser(new NoOpResponseParser(wt));
NamedList<Object> rsp = client.request(query);
- return (String)rsp.get("response");
+ return (String) rsp.get("response");
}
}
@@ -248,54 +250,55 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {
p.set("wt", wt);
String path = p.get("qt");
p.remove("qt");
- p.set("indent","true");
+ p.set("indent", "true");
DirectSolrConnection connection = new DirectSolrConnection(h.getCore());
String raw = connection.request(path, p, null);
return raw;
}
-
public static String getJSON(SolrClient client, SolrParams params) throws Exception {
return getQueryResponse(client, "json", params);
}
- /** Adds a document using the specific client, or to the local test core if null.
- * Returns the version. TODO: work in progress... version not always returned. */
- public static Long add(SolrClient client, SolrInputDocument sdoc, ModifiableSolrParams params) throws Exception {
+ /**
+ * Adds a document using the specific client, or to the local test core if null. Returns the
+ * version. TODO: work in progress... version not always returned.
+ */
+ public static Long add(SolrClient client, SolrInputDocument sdoc, ModifiableSolrParams params)
+ throws Exception {
if (client == null) {
- Long version = addAndGetVersion( sdoc, params );
+ Long version = addAndGetVersion(sdoc, params);
return version;
} else {
UpdateRequest updateRequest = new UpdateRequest();
if (params != null) {
updateRequest.setParams(params);
}
- updateRequest.add( sdoc );
- UpdateResponse rsp = updateRequest.process( client );
+ updateRequest.add(sdoc);
+ UpdateResponse rsp = updateRequest.process(client);
// TODO - return version
return null;
}
}
-
-
public static class Client {
ClientProvider provider;
ModifiableSolrParams queryDefaults;
public Tester tester = new Tester();
public static class Tester {
- public void assertJQ(SolrClient client, SolrParams args, String... tests) throws Exception {
+ public void assertJQ(SolrClient client, SolrParams args, String... tests) throws Exception {
SolrTestCaseHS.assertJQ(client, args, tests);
}
- public void assertQ(SolrClient client, SolrParams args, String... tests) throws Exception {
+ public void assertQ(SolrClient client, SolrParams args, String... tests) throws Exception {
SolrTestCaseHS.assertQ(client, args, tests);
}
}
public static Client localClient = new Client(null, 1);
+
public static Client localClient() {
return new Client(null, 1);
}
@@ -324,7 +327,10 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {
public boolean local() {
return provider == null;
}
- public ClientProvider getClientProvider() { return provider; }
+
+ public ClientProvider getClientProvider() {
+ return provider;
+ }
public void testJQ(SolrParams args, String... tests) throws Exception {
if (queryDefaults != null) {
@@ -332,25 +338,23 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {
newParams.add(args);
args = newParams;
}
- SolrClient client = provider==null ? null : provider.client(null, args);
+ SolrClient client = provider == null ? null : provider.client(null, args);
tester.assertJQ(client, args, tests);
}
- /**
- * tests are validated against xml response
- */
+ /** tests are validated against xml response */
public void testXQ(SolrParams args, String... tests) throws Exception {
if (queryDefaults != null) {
ModifiableSolrParams newParams = params(queryDefaults);
newParams.add(args);
args = newParams;
}
- SolrClient client = provider==null ? null : provider.client(null, args);
+ SolrClient client = provider == null ? null : provider.client(null, args);
tester.assertQ(client, args, tests);
}
public Long add(SolrInputDocument sdoc, ModifiableSolrParams params) throws Exception {
- SolrClient client = provider==null ? null : provider.client(sdoc, params);
+ SolrClient client = provider == null ? null : provider.client(sdoc, params);
return SolrTestCaseHS.add(client, sdoc, params);
}
@@ -365,9 +369,10 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {
}
}
- public void deleteByQuery(String query, ModifiableSolrParams params) throws IOException, SolrServerException {
+ public void deleteByQuery(String query, ModifiableSolrParams params)
+ throws IOException, SolrServerException {
if (local()) {
- assertU(delQ(query)); // todo - handle extra params
+ assertU(delQ(query)); // todo - handle extra params
return;
}
@@ -375,10 +380,8 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {
client.deleteByQuery(query); // todo - handle extra params
}
}
-
}
-
public static class ClientProvider {
public static String idField = "id";
@@ -397,7 +400,7 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {
String idStr = null;
if (sdoc != null) {
idStr = sdoc.getFieldValue(idField).toString();
- } else if (params!=null) {
+ } else if (params != null) {
idStr = params.get(idField);
}
@@ -409,8 +412,7 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {
hash = r.nextInt();
}
-
- return clients.get( (hash & Integer.MAX_VALUE) % clients.size() );
+ return clients.get((hash & Integer.MAX_VALUE) % clients.size());
}
public List<SolrClient> all() {
@@ -422,11 +424,11 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {
}
}
-
//
// Helper to run an internal Jetty instance.
// Example:
- // SolrInstance s1 = new SolrInstance(createTempDir("s1"), "solrconfig-tlog.xml", "schema_latest.xml");
+ // SolrInstance s1 = new SolrInstance(createTempDir("s1"), "solrconfig-tlog.xml",
+ // "schema_latest.xml");
// s1.start();
// SolrClient c1 = s1.getSolrJ();
// assertJQ(c1, params("q", "*:*"), "/response/numFound==3");
@@ -447,7 +449,6 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {
private boolean homeCreated = false;
-
public SolrInstance(File homeDir, String solrconfigFile, String schemaFile) {
this.baseDir = homeDir;
this.solrconfigFile = solrconfigFile;
@@ -484,13 +485,16 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {
}
public void createHome() throws Exception {
- homeCreated=true;
+ homeCreated = true;
SolrTestCaseJ4.copySolrHomeToTemp(baseDir, collection);
copyConfFile(baseDir, collection, solrconfigFile);
copyConfFile(baseDir, collection, schemaFile);
File collDir = new File(baseDir, collection);
- try (Writer w = new OutputStreamWriter(Files.newOutputStream(collDir.toPath().resolve("core.properties")), StandardCharsets.UTF_8)) {
+ try (Writer w =
+ new OutputStreamWriter(
+ Files.newOutputStream(collDir.toPath().resolve("core.properties")),
+ StandardCharsets.UTF_8)) {
Properties coreProps = new Properties();
coreProps.put("name", "collection1");
coreProps.put("config", solrconfigFile);
@@ -499,19 +503,19 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {
}
}
-
public void start() throws Exception {
if (!homeCreated) {
createHome();
}
if (jetty == null) {
- JettyConfig jettyConfig = JettyConfig.builder()
- .stopAtShutdown(true)
- .setContext("/solr")
- .setPort(port)
- .withSSLConfig(sslConfig.buildServerSSLConfig())
- .build();
+ JettyConfig jettyConfig =
+ JettyConfig.builder()
+ .stopAtShutdown(true)
+ .setContext("/solr")
+ .setPort(port)
+ .withSSLConfig(sslConfig.buildServerSSLConfig())
+ .build();
Properties nodeProperties = new Properties();
nodeProperties.setProperty("solrconfig", solrconfigFile);
nodeProperties.setProperty(CoreDescriptor.CORE_SCHEMA, schemaFile);
@@ -520,7 +524,7 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {
// silly stuff included from solrconfig.snippet.randomindexconfig.xml
System.setProperty("solr.tests.maxBufferedDocs", String.valueOf(100000));
-
+
// If we want to run with allowlist, this must be explicitly set to true for the test
// otherwise we disable the check
if (System.getProperty(AllowListUrlChecker.DISABLE_URL_ALLOW_LIST) == null) {
@@ -543,7 +547,8 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {
IOUtils.deleteFilesIfExist(baseDir.toPath());
}
- private static void copyConfFile(File dstRoot, String destCollection, String file) throws Exception {
+ private static void copyConfFile(File dstRoot, String destCollection, String file)
+ throws Exception {
Path subHome = dstRoot.toPath().resolve(destCollection).resolve("conf");
Path top = SolrTestCaseJ4.TEST_PATH().resolve("collection1").resolve("conf");
Files.copy(top.resolve(file), subHome.resolve(file));
@@ -556,11 +561,10 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {
SolrInstance.copyConfFile(dstRoot, destCollection, file);
}
-
}
-
- // Manages a number of Solr servers and provides a Client to partition documents and randomly assign query requests.
+ // Manages a number of Solr servers and provides a Client to partition documents and randomly
+ // assign query requests.
// Example:
// SolrInstances servers = new SolrInstances(3, "solrconfig-tlog.xml","schema_latest.xml");
// Client = servers.getClient(0);
@@ -575,8 +579,9 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {
public SolrInstances(int numServers, String solrconfig, String schema) throws Exception {
slist = new ArrayList<>(numServers);
- for (int i=0; i<numServers; i++) {
- SolrInstance instance = new SolrInstance(createTempDir("s"+ i).toFile(), solrconfig, schema);
+ for (int i = 0; i < numServers; i++) {
+ SolrInstance instance =
+ new SolrInstance(createTempDir("s" + i).toFile(), solrconfig, schema);
slist.add(instance);
instance.start();
}
@@ -592,11 +597,11 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {
public String getShards() {
return getShardsParam(slist);
}
-
+
public List<SolrClient> getSolrJs() {
List<SolrClient> solrjs = new ArrayList<>(slist.size());
for (SolrInstance instance : slist) {
- solrjs.add( instance.getSolrJ() );
+ solrjs.add(instance.getSolrJ());
}
return solrjs;
}
@@ -617,13 +622,9 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {
} else {
sb.append(',');
}
- sb.append( instance.getShardURL() );
+ sb.append(instance.getShardURL());
}
return sb.toString();
}
-
-
-
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
index cd2730df875..0c3d47cad57 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
@@ -16,7 +16,19 @@
*/
package org.apache.solr;
-import javax.xml.xpath.XPathExpressionException;
+import static java.util.Objects.requireNonNull;
+import static org.apache.solr.cloud.SolrZkServer.ZK_WHITELIST_PROPERTY;
+import static org.apache.solr.common.cloud.ZkStateReader.HTTPS;
+import static org.apache.solr.common.cloud.ZkStateReader.URL_SCHEME;
+import static org.apache.solr.update.processor.DistributedUpdateProcessor.DistribPhase;
+import static org.apache.solr.update.processor.DistributingUpdateProcessorFactory.DISTRIB_UPDATE_PARAM;
+import static org.hamcrest.core.StringContains.containsString;
+
+import com.carrotsearch.randomizedtesting.RandomizedContext;
+import com.carrotsearch.randomizedtesting.RandomizedTest;
+import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
+import io.opentracing.noop.NoopTracerFactory;
+import io.opentracing.util.GlobalTracer;
import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
@@ -62,19 +74,14 @@ import java.util.Map.Entry;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;
-import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
-
-import com.carrotsearch.randomizedtesting.RandomizedContext;
-import com.carrotsearch.randomizedtesting.RandomizedTest;
-import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
-
-import io.opentracing.noop.NoopTracerFactory;
-import io.opentracing.util.GlobalTracer;
+import javax.xml.xpath.XPathExpressionException;
+import org.apache.commons.io.IOUtils;
import org.apache.http.client.HttpClient;
import org.apache.logging.log4j.Level;
import org.apache.lucene.analysis.MockAnalyzer;
@@ -139,9 +146,9 @@ import org.apache.solr.update.processor.DistributedUpdateProcessor;
import org.apache.solr.update.processor.DistributedZkUpdateProcessor;
import org.apache.solr.update.processor.UpdateRequestProcessor;
import org.apache.solr.util.BaseTestHarness;
+import org.apache.solr.util.ErrorLogMuter;
import org.apache.solr.util.ExternalPaths;
import org.apache.solr.util.LogLevel;
-import org.apache.solr.util.ErrorLogMuter;
import org.apache.solr.util.RandomizeSSL;
import org.apache.solr.util.RandomizeSSL.SSLRandomizer;
import org.apache.solr.util.RefCounted;
@@ -164,44 +171,36 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
-import org.apache.commons.io.IOUtils;
-
-import static java.util.Objects.requireNonNull;
-import static org.apache.solr.cloud.SolrZkServer.ZK_WHITELIST_PROPERTY;
-import static org.apache.solr.common.cloud.ZkStateReader.HTTPS;
-import static org.apache.solr.common.cloud.ZkStateReader.URL_SCHEME;
-import static org.apache.solr.update.processor.DistributedUpdateProcessor.DistribPhase;
-import static org.apache.solr.update.processor.DistributingUpdateProcessorFactory.DISTRIB_UPDATE_PARAM;
-import static org.hamcrest.core.StringContains.containsString;
-
/**
- * A junit4 Solr test harness that extends SolrTestCase and, by extension, LuceneTestCase.
- * To change which core is used when loading the schema and solrconfig.xml, simply
- * invoke the {@link #initCore(String, String, String, String)} method.
+ * A junit4 Solr test harness that extends SolrTestCase and, by extension, LuceneTestCase. To change
+ * which core is used when loading the schema and solrconfig.xml, simply invoke the {@link
+ * #initCore(String, String, String, String)} method.
*/
@SuppressSysoutChecks(bugUrl = "Solr dumps tons of logs to console.")
-@SuppressFileSystems("ExtrasFS") // might be ok, the failures with e.g. nightly runs might be "normal"
+// ExtrasFS might be ok, the failures with e.g. nightly runs might be "normal"
+@SuppressFileSystems("ExtrasFS")
@RandomizeSSL()
-
public abstract class SolrTestCaseJ4 extends SolrTestCase {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
+
public static final String DEFAULT_TEST_COLLECTION_NAME = "collection1";
public static final String DEFAULT_TEST_CORENAME = DEFAULT_TEST_COLLECTION_NAME;
protected static final String CORE_PROPERTIES_FILENAME = "core.properties";
- public static final String SYSTEM_PROPERTY_SOLR_TESTS_MERGEPOLICYFACTORY = "solr.tests.mergePolicyFactory";
+ public static final String SYSTEM_PROPERTY_SOLR_TESTS_MERGEPOLICYFACTORY =
+ "solr.tests.mergePolicyFactory";
- public static final String TEST_URL_ALLOW_LIST = "solr.tests." + AllowListUrlChecker.URL_ALLOW_LIST;
+ public static final String TEST_URL_ALLOW_LIST =
+ "solr.tests." + AllowListUrlChecker.URL_ALLOW_LIST;
protected static String coreName = DEFAULT_TEST_CORENAME;
- public static int DEFAULT_CONNECTION_TIMEOUT = 60000; // default socket connection timeout in ms
-
+ public static int DEFAULT_CONNECTION_TIMEOUT = 60000; // default socket connection timeout in ms
+
private static String initialRootLogLevel;
-
- protected volatile static ExecutorService testExecutor;
+
+ protected static volatile ExecutorService testExecutor;
protected void writeCoreProperties(Path coreDirectory, String corename) throws IOException {
Properties props = new Properties();
@@ -213,17 +212,22 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
writeCoreProperties(coreDirectory, props, this.getSaferTestName());
}
- public static void writeCoreProperties(Path coreDirectory, Properties properties, String testname) throws IOException {
+ public static void writeCoreProperties(Path coreDirectory, Properties properties, String testname)
+ throws IOException {
log.info("Writing core.properties file to {}", coreDirectory);
Files.createDirectories(coreDirectory);
try (Writer writer =
- new OutputStreamWriter(Files.newOutputStream(coreDirectory.resolve(CORE_PROPERTIES_FILENAME)), Charset.forName("UTF-8"))) {
+ new OutputStreamWriter(
+ Files.newOutputStream(coreDirectory.resolve(CORE_PROPERTIES_FILENAME)),
+ Charset.forName("UTF-8"))) {
properties.store(writer, testname);
}
}
- protected void assertExceptionThrownWithMessageContaining(Class<? extends Throwable> expectedType,
- List<String> expectedStrings, ThrowingRunnable runnable) {
+ protected void assertExceptionThrownWithMessageContaining(
+ Class<? extends Throwable> expectedType,
+ List<String> expectedStrings,
+ ThrowingRunnable runnable) {
Throwable thrown = expectThrows(expectedType, runnable);
if (expectedStrings != null) {
@@ -233,9 +237,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
}
- /**
- * Annotation for test classes that want to disable SSL
- */
+ /** Annotation for test classes that want to disable SSL */
@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@@ -244,10 +246,10 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
/** Point to JIRA entry. */
public String bugUrl() default "None";
}
-
+
/**
- * Annotation for test classes that want to disable PointFields.
- * PointFields will otherwise randomly used by some schemas.
+ * Annotation for test classes that want to disable PointFields. PointFields will otherwise
+ * randomly used by some schemas.
*/
@Documented
@Inherited
@@ -257,26 +259,28 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
/** Point to JIRA entry. */
public String bugUrl();
}
-
+
// these are meant to be accessed sequentially, but are volatile just to ensure any test
// thread will read the latest value
public static volatile SSLTestConfig sslConfig;
- @Rule
- public TestRule solrTestRules =
- RuleChain.outerRule(new SystemPropertiesRestoreRule());
+ @Rule public TestRule solrTestRules = RuleChain.outerRule(new SystemPropertiesRestoreRule());
@BeforeClass
public static void setupTestCases() {
initialRootLogLevel = StartupLoggingUtils.getLogLevelString();
initClassLogLevels();
resetExceptionIgnores();
-
- testExecutor = new ExecutorUtil.MDCAwareThreadPoolExecutor(0, Integer.MAX_VALUE,
- 15L, TimeUnit.SECONDS,
- new SynchronousQueue<>(),
- new SolrNamedThreadFactory("testExecutor"),
- true);
+
+ testExecutor =
+ new ExecutorUtil.MDCAwareThreadPoolExecutor(
+ 0,
+ Integer.MAX_VALUE,
+ 15L,
+ TimeUnit.SECONDS,
+ new SynchronousQueue<>(),
+ new SolrNamedThreadFactory("testExecutor"),
+ true);
// set solr.install.dir needed by some test configs outside of the test sandbox (!)
System.setProperty("solr.install.dir", ExternalPaths.SOURCE_HOME);
@@ -285,8 +289,8 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
// non-null after calling setupTestCases()
initAndGetDataDir();
- System.setProperty("solr.zkclienttimeout", "90000");
-
+ System.setProperty("solr.zkclienttimeout", "90000");
+
System.setProperty("solr.httpclient.retries", "1");
System.setProperty("solr.retries.on.forward", "1");
System.setProperty("solr.retries.to.followers", "1");
@@ -300,8 +304,18 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
System.setProperty("solr.cloud.wait-for-updates-with-stale-state-pause", "500");
System.setProperty("solr.filterCache.async", String.valueOf(random().nextBoolean()));
- System.setProperty("pkiHandlerPrivateKeyPath", SolrTestCaseJ4.class.getClassLoader().getResource("cryptokeys/priv_key512_pkcs8.pem").toExternalForm());
- System.setProperty("pkiHandlerPublicKeyPath", SolrTestCaseJ4.class.getClassLoader().getResource("cryptokeys/pub_key512.der").toExternalForm());
+ System.setProperty(
+ "pkiHandlerPrivateKeyPath",
+ SolrTestCaseJ4.class
+ .getClassLoader()
+ .getResource("cryptokeys/priv_key512_pkcs8.pem")
+ .toExternalForm());
+ System.setProperty(
+ "pkiHandlerPublicKeyPath",
+ SolrTestCaseJ4.class
+ .getClassLoader()
+ .getResource("cryptokeys/pub_key512.der")
+ .toExternalForm());
System.setProperty(ZK_WHITELIST_PROPERTY, "*");
startTrackingSearchers();
@@ -310,9 +324,10 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
sslConfig = buildSSLConfig();
// based on randomized SSL config, set SocketFactoryRegistryProvider appropriately
- HttpClientUtil.setSocketFactoryRegistryProvider(sslConfig.buildClientSocketFactoryRegistryProvider());
+ HttpClientUtil.setSocketFactoryRegistryProvider(
+ sslConfig.buildClientSocketFactoryRegistryProvider());
Http2SolrClient.setDefaultSSLConfig(sslConfig.buildClientSSLConfig());
- if(isSSLMode()) {
+ if (isSSLMode()) {
// SolrCloud tests should usually clear this
System.setProperty(URL_SCHEME, HTTPS);
}
@@ -323,26 +338,28 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
/**
* GlobalTracer is initialized by org.apache.solr.core.TracerConfigurator by
- * org.apache.solr.core.CoreContainer. Tests may need to reset it in the beginning of a test if
- * it might have differing configuration from other tests in the same suite.
- * It's also important to call {@link ExecutorUtil#resetThreadLocalProviders()}.
+ * org.apache.solr.core.CoreContainer. Tests may need to reset it in the beginning of a test if it
+ * might have differing configuration from other tests in the same suite. It's also important to
+ * call {@link ExecutorUtil#resetThreadLocalProviders()}.
*/
@SuppressForbidden(reason = "Hack to reset internal state of GlobalTracer")
public static void resetGlobalTracer() {
- AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
- try {
- final Class<GlobalTracer> globalTracerClass = GlobalTracer.class;
- final Field isRegistered = globalTracerClass.getDeclaredField("isRegistered");
- isRegistered.setAccessible(true);
- isRegistered.setBoolean(null, false);
- final Field tracer = globalTracerClass.getDeclaredField("tracer");
- tracer.setAccessible(true);
- tracer.set(null, NoopTracerFactory.create());
- } catch (NoSuchFieldException | IllegalAccessException e) {
- throw new RuntimeException(e);
- }
- return null;
- });
+ AccessController.doPrivileged(
+ (PrivilegedAction<Void>)
+ () -> {
+ try {
+ final Class<GlobalTracer> globalTracerClass = GlobalTracer.class;
+ final Field isRegistered = globalTracerClass.getDeclaredField("isRegistered");
+ isRegistered.setAccessible(true);
+ isRegistered.setBoolean(null, false);
+ final Field tracer = globalTracerClass.getDeclaredField("tracer");
+ tracer.setAccessible(true);
+ tracer.set(null, NoopTracerFactory.create());
+ } catch (NoSuchFieldException | IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ return null;
+ });
assert GlobalTracer.isRegistered() == false;
}
@@ -356,7 +373,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
} catch (Exception e) {
log.error("Error deleting SolrCore.");
}
-
+
if (null != testExecutor) {
ExecutorUtil.shutdownAndAwaitTermination(testExecutor);
testExecutor = null;
@@ -396,30 +413,35 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
StartupLoggingUtils.changeLogLevel(initialRootLogLevel);
}
}
-
+
/**
- * a "dead" host, if you try to connect to it, it will likely fail fast
- * please consider using mocks and not real networking to simulate failure
+ * a "dead" host, if you try to connect to it, it will likely fail fast please consider using
+ * mocks and not real networking to simulate failure
*/
public static final String DEAD_HOST_1 = "[::1]:4";
/**
- * a "dead" host, if you try to connect to it, it will likely fail fast
- * please consider using mocks and not real networking to simulate failure
+ * a "dead" host, if you try to connect to it, it will likely fail fast please consider using
+ * mocks and not real networking to simulate failure
*/
public static final String DEAD_HOST_2 = "[::1]:6";
/**
- * a "dead" host, if you try to connect to it, it will likely fail fast
- * please consider using mocks and not real networking to simulate failure
+ * a "dead" host, if you try to connect to it, it will likely fail fast please consider using
+ * mocks and not real networking to simulate failure
*/
public static final String DEAD_HOST_3 = "[::1]:8";
- /** Assumes that Mockito/Bytebuddy is available and can be used to mock classes (e.g., fails if Java version is too new). */
+ /**
+ * Assumes that Mockito/Bytebuddy is available and can be used to mock classes (e.g., fails if
+ * Java version is too new).
+ */
public static void assumeWorkingMockito() {
- // we use reflection here, because we do not have ByteBuddy/Mockito in all modules and the test framework!
+ // we use reflection here, because we do not have ByteBuddy/Mockito in all modules and the test
+ // framework!
try {
Class.forName("net.bytebuddy.ClassFileVersion").getMethod("ofThisVm").invoke(null);
} catch (InvocationTargetException e) {
- RandomizedTest.assumeNoException("SOLR-11606: ByteBuddy used by Mockito is not working with this JVM version.",
+ RandomizedTest.assumeNoException(
+ "SOLR-11606: ByteBuddy used by Mockito is not working with this JVM version.",
e.getTargetException());
} catch (ReflectiveOperationException e) {
fail("ByteBuddy and Mockito are not available on classpath: " + e.toString());
@@ -457,14 +479,14 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
LogLevel.Configurer.restoreLogLevels(savedMethodLogLevels);
savedMethodLogLevels.clear();
}
-
+
protected static boolean isSSLMode() {
return sslConfig != null && sslConfig.isSSLMode();
}
private static boolean changedFactory = false;
private static String savedFactory;
- /** Use a different directory factory. Passing "null" sets to an FS-based factory */
+ /** Use a different directory factory. Passing "null" sets to an FS-based factory */
public static void useFactory(String factory) throws Exception {
// allow calling more than once so a subclass can override a base class
if (!changedFactory) {
@@ -472,7 +494,10 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
if (factory == null) {
- factory = random().nextInt(100) < 75 ? "solr.NRTCachingDirectoryFactory" : "solr.StandardDirectoryFactory"; // test the default most of the time
+ factory =
+ random().nextInt(100) < 75
+ ? "solr.NRTCachingDirectoryFactory"
+ : "solr.StandardDirectoryFactory"; // test the default most of the time
}
System.setProperty("solr.directoryFactory", factory);
changedFactory = true;
@@ -492,27 +517,35 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
private static SSLTestConfig buildSSLConfig() {
SSLRandomizer sslRandomizer =
- SSLRandomizer.getSSLRandomizerForClass(RandomizedContext.current().getTargetClass());
-
+ SSLRandomizer.getSSLRandomizerForClass(RandomizedContext.current().getTargetClass());
+
if (Constants.MAC_OS_X) {
// see SOLR-9039
// If a solution is found to remove this, please make sure to also update
// TestMiniSolrCloudClusterSSL.testSslAndClientAuth as well.
- sslRandomizer = new SSLRandomizer(sslRandomizer.ssl, 0.0D, (sslRandomizer.debug + " w/ MAC_OS_X supressed clientAuth"));
+ sslRandomizer =
+ new SSLRandomizer(
+ sslRandomizer.ssl, 0.0D, (sslRandomizer.debug + " w/ MAC_OS_X supressed clientAuth"));
}
SSLTestConfig result = sslRandomizer.createSSLTestConfig();
if (log.isInfoEnabled()) {
- log.info("Randomized ssl ({}) and clientAuth ({}) via: {}",
- result.isSSLMode(), result.isClientAuthMode(), sslRandomizer.debug);
+ log.info(
+ "Randomized ssl ({}) and clientAuth ({}) via: {}",
+ result.isSSLMode(),
+ result.isClientAuthMode(),
+ sslRandomizer.debug);
}
return result;
}
protected static JettyConfig buildJettyConfig(String context) {
- return JettyConfig.builder().setContext(context).withSSLConfig(sslConfig.buildServerSSLConfig()).build();
+ return JettyConfig.builder()
+ .setContext(context)
+ .withSSLConfig(sslConfig.buildServerSSLConfig())
+ .build();
}
-
+
protected static String buildUrl(final int port, final String context) {
return (isSSLMode() ? "https" : "http") + "://127.0.0.1:" + port + context;
}
@@ -533,24 +566,23 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
* Call this from @BeforeClass to set up the test harness and update handler with no cores.
*
* @param solrHome The solr home directory.
- * @param xmlStr - the text of an XML file to use. If null, use the what's the absolute minimal file.
+ * @param xmlStr - the text of an XML file to use. If null, use the what's the absolute minimal
+ * file.
* @throws Exception Lost of file-type things can go wrong.
*/
public static void setupNoCoreTest(Path solrHome, String xmlStr) throws Exception {
- if (xmlStr == null)
- xmlStr = "<solr></solr>";
- Files.write(solrHome.resolve(SolrXmlConfig.SOLR_XML_FILE), xmlStr.getBytes(StandardCharsets.UTF_8));
+ if (xmlStr == null) xmlStr = "<solr></solr>";
+ Files.write(
+ solrHome.resolve(SolrXmlConfig.SOLR_XML_FILE), xmlStr.getBytes(StandardCharsets.UTF_8));
h = new TestHarness(SolrXmlConfig.fromSolrHome(solrHome, new Properties()));
lrf = h.getRequestFactory("/select", 0, 20, CommonParams.VERSION, "2.2");
}
-
- /**
- * Sets system properties to allow generation of random configurations of
- * solrconfig.xml and schema.xml.
- * Sets properties used on
- * {@link #newIndexWriterConfig(org.apache.lucene.analysis.Analyzer)}
- * and base schema.xml (Point Fields)
+
+ /**
+ * Sets system properties to allow generation of random configurations of solrconfig.xml and
+ * schema.xml. Sets properties used on {@link
+ * #newIndexWriterConfig(org.apache.lucene.analysis.Analyzer)} and base schema.xml (Point Fields)
*/
public static void newRandomConfig() {
IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
@@ -558,7 +590,8 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
System.setProperty("useCompoundFile", String.valueOf(iwc.getUseCompoundFile()));
System.setProperty("solr.tests.maxBufferedDocs", String.valueOf(iwc.getMaxBufferedDocs()));
- System.setProperty("solr.tests.ramPerThreadHardLimitMB", String.valueOf(iwc.getRAMPerThreadHardLimitMB()));
+ System.setProperty(
+ "solr.tests.ramPerThreadHardLimitMB", String.valueOf(iwc.getRAMPerThreadHardLimitMB()));
System.setProperty("solr.tests.ramBufferSizeMB", String.valueOf(iwc.getRAMBufferSizeMB()));
String mergeSchedulerClass = iwc.getMergeScheduler().getClass().getName();
@@ -581,7 +614,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
public void setUp() throws Exception {
super.setUp();
if (log.isInfoEnabled()) {
- log.info("###Starting {}", getTestName()); // returns <unknown>???
+ log.info("###Starting {}", getTestName()); // returns <unknown>???
}
}
@@ -594,19 +627,17 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
/**
- * Subclasses may call this method to access the "dataDir" that will be used by
- * {@link #initCore} (either prior to or after the core is created).
- * <p>
- * If the dataDir has not yet been initialized when this method is called, this method will do so.
- * Calling {@link #deleteCore} will "reset" the value, such that subsequent calls will
- * re-initialize a new value. All directories returned by any calls to this method will
+ * Subclasses may call this method to access the "dataDir" that will be used by {@link #initCore}
+ * (either prior to or after the core is created).
+ *
+ * <p>If the dataDir has not yet been initialized when this method is called, this method will do
+ * so. Calling {@link #deleteCore} will "reset" the value, such that subsequent calls will
+ * re-initialize a new value. All directories returned by any calls to this method will
* automatically be cleaned up per {@link #createTempDir}
- * </p>
- * <p>
- * NOTE: calling this method is not requried, it will be implicitly called as needed when
- * initializing cores. Callers that don't care about using {@link #initCore} and just want
- * a temporary directory to put data in sould instead be using {@link #createTempDir} directly.
- * </p>
+ *
+ * <p>NOTE: calling this method is not requried, it will be implicitly called as needed when
+ * initializing cores. Callers that don't care about using {@link #initCore} and just want a
+ * temporary directory to put data in sould instead be using {@link #createTempDir} directly.
*
* @see #initCoreDataDir
*/
@@ -614,7 +645,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
File dataDir = initCoreDataDir;
if (null == dataDir) {
final int id = dataDirCount.incrementAndGet();
- dataDir = initCoreDataDir = createTempDir("data-dir-"+ id).toFile();
+ dataDir = initCoreDataDir = createTempDir("data-dir-" + id).toFile();
assertNotNull(dataDir);
if (log.isInfoEnabled()) {
log.info("Created dataDir: {}", dataDir.getAbsolutePath());
@@ -622,25 +653,28 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
return dataDir;
}
- /**
- * Counter for ensuring we don't ask {@link #createTempDir} to try and
- * re-create the same dir prefix over and over.
- * <p>
- * (createTempDir has it's own counter for uniqueness, but it tries all numbers in a loop
- * until it finds one available. No reason to force that O(N^2) behavior when we know we've
- * already created N previous directories with the same prefix.)
- * </p>
+ /**
+ * Counter for ensuring we don't ask {@link #createTempDir} to try and re-create the same dir
+ * prefix over and over.
+ *
+ * <p>(createTempDir has it's own counter for uniqueness, but it tries all numbers in a loop until
+ * it finds one available. No reason to force that O(N^2) behavior when we know we've already
+ * created N previous directories with the same prefix.)
*/
private static final AtomicInteger dataDirCount = new AtomicInteger(0);
-
- /** Call initCore in @BeforeClass to instantiate a solr core in your test class.
- * deleteCore will be called for you via SolrTestCaseJ4 @AfterClass */
+
+ /**
+ * Call initCore in @BeforeClass to instantiate a solr core in your test class. deleteCore will be
+ * called for you via SolrTestCaseJ4 @AfterClass
+ */
public static void initCore(String config, String schema) throws Exception {
initCore(config, schema, TEST_HOME());
}
- /** Call initCore in @BeforeClass to instantiate a solr core in your test class.
- * deleteCore will be called for you via SolrTestCaseJ4 @AfterClass */
+ /**
+ * Call initCore in @BeforeClass to instantiate a solr core in your test class. deleteCore will be
+ * called for you via SolrTestCaseJ4 @AfterClass
+ */
public static void initCore(String config, String schema, String solrHome) throws Exception {
assertNotNull(solrHome);
configString = config;
@@ -650,15 +684,19 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
initCore();
}
- /** Call initCore in @BeforeClass to instantiate a solr core in your test class.
- * deleteCore will be called for you via SolrTestCaseJ4 @AfterClass */
- public static void initCore(String config, String schema, String solrHome, String pCoreName) throws Exception {
- coreName=pCoreName;
- initCore(config,schema,solrHome);
+ /**
+ * Call initCore in @BeforeClass to instantiate a solr core in your test class. deleteCore will be
+ * called for you via SolrTestCaseJ4 @AfterClass
+ */
+ public static void initCore(String config, String schema, String solrHome, String pCoreName)
+ throws Exception {
+ coreName = pCoreName;
+ initCore(config, schema, solrHome);
}
-
+
static long numOpens;
static long numCloses;
+
public static void startTrackingSearchers() {
numOpens = SolrIndexSearcher.numOpens.getAndSet(0);
numCloses = SolrIndexSearcher.numCloses.getAndSet(0);
@@ -669,10 +707,11 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
}
- private final static Map<String,ErrorLogMuter> errorMuters = new ConcurrentHashMap<>();
-
- /**
- * Causes any ERROR log messages matching with a substring matching the regex pattern to be filtered out by the ROOT logger
+ private static final Map<String, ErrorLogMuter> errorMuters = new ConcurrentHashMap<>();
+
+ /**
+ * Causes any ERROR log messages matching with a substring matching the regex pattern to be
+ * filtered out by the ROOT logger
*
* @see #resetExceptionIgnores
* @deprecated use a {@link ErrorLogMuter} instead
@@ -688,22 +727,32 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
*/
@Deprecated
public static void unIgnoreException(String pattern) {
- errorMuters.computeIfPresent(pattern, (pat, muter) -> { IOUtils.closeQuietly(muter); return null; } );
+ errorMuters.computeIfPresent(
+ pattern,
+ (pat, muter) -> {
+ IOUtils.closeQuietly(muter);
+ return null;
+ });
}
-
+
/**
- * Clears all exception patterns, immediately re-registering {@code "ignore_exception"}.
- * {@link SolrTestCaseJ4} calls this in both {@link BeforeClass} {@link AfterClass} so usually tests don't need to call this.
- *
+ * Clears all exception patterns, immediately re-registering {@code "ignore_exception"}. {@link
+ * SolrTestCaseJ4} calls this in both {@link BeforeClass} {@link AfterClass} so usually tests
+ * don't need to call this.
+ *
* @see #ignoreException
* @deprecated use a {@link ErrorLogMuter} instead
*/
@Deprecated
public static void resetExceptionIgnores() {
- errorMuters.forEach( (k, muter) -> { IOUtils.closeQuietly(muter); errorMuters.remove(k); } );
+ errorMuters.forEach(
+ (k, muter) -> {
+ IOUtils.closeQuietly(muter);
+ errorMuters.remove(k);
+ });
ignoreException("ignore_exception");
}
-
+
protected static String getClassName() {
return getTestClass().getName();
}
@@ -721,53 +770,42 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
/**
* Harness initialized by create[Default]Core[Container].
*
- * <p>
- * For use in test methods as needed.
- * </p>
+ * <p>For use in test methods as needed.
*/
protected static TestHarness h;
/**
- * LocalRequestFactory initialized by create[Default]Core[Container] using sensible
- * defaults.
+ * LocalRequestFactory initialized by create[Default]Core[Container] using sensible defaults.
*
- * <p>
- * For use in test methods as needed.
- * </p>
+ * <p>For use in test methods as needed.
*/
protected static TestHarness.LocalRequestFactory lrf;
-
- /**
- * Subclasses must define this method to return the name of the
- * schema.xml they wish to use.
- */
+ /** Subclasses must define this method to return the name of the schema.xml they wish to use. */
public static String getSchemaFile() {
return schemaString;
}
/**
- * Subclasses must define this method to return the name of the
- * solrconfig.xml they wish to use.
+ * Subclasses must define this method to return the name of the solrconfig.xml they wish to use.
*/
public static String getSolrConfigFile() {
return configString;
}
/**
- * The directory used as the <code>dataDir</code> for the TestHarness unless
- * {@link #hdfsDataDir} is non null.
- * <p>
- * Will be set to null by {@link #deleteCore} and re-initialized as needed by {@link #createCore}.
- * In the event of a test failure, the contents will be left on disk.
- * </p>
+ * The directory used as the <code>dataDir</code> for the TestHarness unless {@link #hdfsDataDir}
+ * is non null.
+ *
+ * <p>Will be set to null by {@link #deleteCore} and re-initialized as needed by {@link
+ * #createCore}. In the event of a test failure, the contents will be left on disk.
+ *
* @see #createTempDir(String)
* @see #initAndGetDataDir()
* @deprecated use initAndGetDataDir instead of directly accessing this variable
*/
- @Deprecated
- protected static volatile File initCoreDataDir;
-
+ @Deprecated protected static volatile File initCoreDataDir;
+
// hack due to File dataDir
protected static String hdfsDataDir;
@@ -775,23 +813,20 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
* Initializes things your test might need
*
* <ul>
- * <li>Creates a dataDir in the "java.io.tmpdir"</li>
- * <li>initializes the TestHarness h using this data directory, and getSchemaPath()</li>
- * <li>initializes the LocalRequestFactory lrf using sensible defaults.</li>
+ * <li>Creates a dataDir in the "java.io.tmpdir"
+ * <li>initializes the TestHarness h using this data directory, and getSchemaPath()
+ * <li>initializes the LocalRequestFactory lrf using sensible defaults.
* </ul>
- *
*/
-
private static String factoryProp;
-
public static void initCore() throws Exception {
log.info("####initCore");
ignoreException("ignore_exception");
factoryProp = System.getProperty("solr.directoryFactory");
if (factoryProp == null) {
- System.setProperty("solr.directoryFactory","solr.RAMDirectoryFactory");
+ System.setProperty("solr.directoryFactory", "solr.RAMDirectoryFactory");
}
// other methods like starting a jetty instance need these too
@@ -808,11 +843,13 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
public static void createCore() {
assertNotNull(testSolrHome);
solrConfig = TestHarness.createConfig(testSolrHome, coreName, getSolrConfigFile());
- h = new TestHarness( coreName, hdfsDataDir == null ? initAndGetDataDir().getAbsolutePath() : hdfsDataDir,
+ h =
+ new TestHarness(
+ coreName,
+ hdfsDataDir == null ? initAndGetDataDir().getAbsolutePath() : hdfsDataDir,
solrConfig,
getSchemaFile());
- lrf = h.getRequestFactory
- ("",0,20,CommonParams.VERSION,"2.2");
+ lrf = h.getRequestFactory("", 0, 20, CommonParams.VERSION, "2.2");
}
public static CoreContainer createCoreContainer(Path solrHome, String solrXML) {
@@ -830,7 +867,8 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
return h.getCoreContainer();
}
- public static CoreContainer createCoreContainer(String coreName, String dataDir, String solrConfig, String schema) {
+ public static CoreContainer createCoreContainer(
+ String coreName, String dataDir, String solrConfig, String schema) {
NodeConfig nodeConfig = TestHarness.buildTestNodeConfig(TEST_PATH());
CoresLocator locator = new TestHarness.TestCoresLocator(coreName, dataDir, solrConfig, schema);
CoreContainer cc = createCoreContainer(nodeConfig, locator);
@@ -841,29 +879,32 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
public static CoreContainer createDefaultCoreContainer(Path solrHome) {
testSolrHome = requireNonNull(solrHome);
System.setProperty("solr.solr.home", solrHome.toAbsolutePath().toString());
- h = new TestHarness("collection1", initAndGetDataDir().getAbsolutePath(), "solrconfig.xml", "schema.xml");
+ h =
+ new TestHarness(
+ "collection1", initAndGetDataDir().getAbsolutePath(), "solrconfig.xml", "schema.xml");
lrf = h.getRequestFactory("", 0, 20, CommonParams.VERSION, "2.2");
return h.getCoreContainer();
}
public static boolean hasInitException(String message) {
- for (Map.Entry<String, CoreContainer.CoreLoadFailure> entry : h.getCoreContainer().getCoreInitFailures().entrySet()) {
- if (entry.getValue().exception.getMessage().contains(message))
- return true;
+ for (Map.Entry<String, CoreContainer.CoreLoadFailure> entry :
+ h.getCoreContainer().getCoreInitFailures().entrySet()) {
+ if (entry.getValue().exception.getMessage().contains(message)) return true;
}
return false;
}
public static boolean hasInitException(Class<? extends Exception> exceptionType) {
- for (Map.Entry<String, CoreContainer.CoreLoadFailure> entry : h.getCoreContainer().getCoreInitFailures().entrySet()) {
- if (exceptionType.isAssignableFrom(entry.getValue().exception.getClass()))
- return true;
+ for (Map.Entry<String, CoreContainer.CoreLoadFailure> entry :
+ h.getCoreContainer().getCoreInitFailures().entrySet()) {
+ if (exceptionType.isAssignableFrom(entry.getValue().exception.getClass())) return true;
}
return false;
}
- /** Subclasses that override setUp can optionally call this method
- * to log the fact that their setUp process has ended.
+ /**
+ * Subclasses that override setUp can optionally call this method to log the fact that their setUp
+ * process has ended.
*/
public void postSetUp() {
if (log.isInfoEnabled()) {
@@ -871,11 +912,10 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
}
-
- /** Subclasses that override tearDown can optionally call this method
- * to log the fact that the tearDown process has started. This is necessary
- * since subclasses will want to call super.tearDown() at the *end* of their
- * tearDown method.
+ /**
+ * Subclasses that override tearDown can optionally call this method to log the fact that the
+ * tearDown process has started. This is necessary since subclasses will want to call
+ * super.tearDown() at the *end* of their tearDown method.
*/
public void preTearDown() {
if (log.isInfoEnabled()) {
@@ -883,22 +923,21 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
}
- /**
- * Shuts down the test harness and nulls out the values setup by {@link #initCore}
- */
+ /** Shuts down the test harness and nulls out the values setup by {@link #initCore} */
public static void deleteCore() {
if (h != null) {
- log.info("###deleteCore" );
+ log.info("###deleteCore");
// If the test case set up Zk, it should still have it as available,
// otherwise the core close will just be unnecessarily delayed.
CoreContainer cc = h.getCoreContainer();
- if (! cc.getCores().isEmpty() && cc.isZooKeeperAware()) {
+ if (!cc.getCores().isEmpty() && cc.isZooKeeperAware()) {
try {
cc.getZkController().getZkClient().exists("/", false);
} catch (KeeperException e) {
log.error("Testing connectivity to ZK by checking for root path failed", e);
fail("Trying to tear down a ZK aware core container with ZK not reachable");
- } catch (InterruptedException ignored) {}
+ } catch (InterruptedException ignored) {
+ }
}
h.close();
@@ -912,7 +951,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
// clears the updatelog sysprop at the end of the test run
System.clearProperty(UPDATELOG_SYSPROP);
}
-
+
solrConfig = null;
h = null;
lrf = null;
@@ -921,41 +960,36 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
hdfsDataDir = null;
}
- /** Validates an update XML String is successful
- */
+ /** Validates an update XML String is successful */
public static void assertU(String update) {
assertU(null, update);
}
- /** Validates an update XML String is successful
- */
+ /** Validates an update XML String is successful */
public static void assertU(String message, String update) {
checkUpdateU(message, update, true);
}
- /** Validates an update XML String failed
- */
+ /** Validates an update XML String failed */
public static void assertFailedU(String update) {
assertFailedU(null, update);
}
- /** Validates an update XML String failed
- */
+ /** Validates an update XML String failed */
public static void assertFailedU(String message, String update) {
checkUpdateU(message, update, false);
}
- /** Checks the success or failure of an update message
- */
+ /** Checks the success or failure of an update message */
private static void checkUpdateU(String message, String update, boolean shouldSucceed) {
try {
String m = (null == message) ? "" : message + " ";
if (shouldSucceed) {
- String res = h.validateUpdate(update);
- if (res != null) fail(m + "update was not successful: " + res);
+ String res = h.validateUpdate(update);
+ if (res != null) fail(m + "update was not successful: " + res);
} else {
- String res = h.validateErrorUpdate(update);
- if (res != null) fail(m + "update succeeded, but should have failed: " + res);
+ String res = h.validateErrorUpdate(update);
+ if (res != null) fail(m + "update succeeded, but should have failed: " + res);
}
} catch (SAXException e) {
throw new RuntimeException("Invalid XML", e);
@@ -971,11 +1005,11 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
public static void assertQ(String message, SolrQueryRequest req, String... tests) {
try {
String m = (null == message) ? "" : message + " "; // TODO log 'm' !!!
- //since the default (standard) response format is now JSON
- //need to explicitly request XML since this class uses XPath
+ // since the default (standard) response format is now JSON
+ // need to explicitly request XML since this class uses XPath
ModifiableSolrParams xmlWriterTypeParams = new ModifiableSolrParams(req.getParams());
- xmlWriterTypeParams.set(CommonParams.WT,"xml");
- //for tests, let's turn indention off so we don't have to handle extraneous spaces
+ xmlWriterTypeParams.set(CommonParams.WT, "xml");
+ // for tests, let's turn indention off so we don't have to handle extraneous spaces
xmlWriterTypeParams.set("indent", xmlWriterTypeParams.get("indent", "off"));
req.setParams(xmlWriterTypeParams);
String response = h.query(req);
@@ -983,8 +1017,8 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
if (req.getParams().getBool("facet", false)) {
// add a test to ensure that faceting did not throw an exception
// internally, where it would be added to facet_counts/exception
- String[] allTests = new String[tests.length+1];
- System.arraycopy(tests,0,allTests,1,tests.length);
+ String[] allTests = new String[tests.length + 1];
+ System.arraycopy(tests, 0, allTests, 1, tests.length);
allTests[0] = "*[count(//lst[@name='facet_counts']/*[@name='exception'])=0]";
tests = allTests;
}
@@ -992,16 +1026,20 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
String results = BaseTestHarness.validateXPath(response, tests);
if (null != results) {
- String msg = "REQUEST FAILED: xpath=" + results
- + "\n\txml response was: " + response
- + "\n\trequest was:" + req.getParamString();
+ String msg =
+ "REQUEST FAILED: xpath="
+ + results
+ + "\n\txml response was: "
+ + response
+ + "\n\trequest was:"
+ + req.getParamString();
fail(msg);
}
} catch (XPathExpressionException e1) {
throw new RuntimeException("XPath is invalid", e1);
} catch (Exception e2) {
- SolrException.log(log,"REQUEST FAILED: " + req.getParamString(), e2);
+ SolrException.log(log, "REQUEST FAILED: " + req.getParamString(), e2);
throw new RuntimeException("Exception during query", e2);
}
}
@@ -1009,15 +1047,15 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
/** Makes a query request and returns the JSON string response */
public static String JQ(SolrQueryRequest req) throws Exception {
SolrParams params = req.getParams();
- if (!"json".equals(params.get("wt","xml")) || params.get("indent")==null) {
+ if (!"json".equals(params.get("wt", "xml")) || params.get("indent") == null) {
ModifiableSolrParams newParams = new ModifiableSolrParams(params);
- newParams.set("wt","json");
- if (params.get("indent")==null) newParams.set("indent","true");
+ newParams.set("wt", "json");
+ if (params.get("indent") == null) newParams.set("indent", "true");
req.setParams(newParams);
}
String response;
- boolean failed=true;
+ boolean failed = true;
try {
response = h.query(req);
failed = false;
@@ -1032,6 +1070,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
/**
* Validates a query matches some JSON test expressions using the default double delta tolerance.
+ *
* @see JSONTestUtil#DEFAULT_DELTA
* @see #assertJQ(SolrQueryRequest,double,String...)
* @return The request response as a JSON String if all test patterns pass
@@ -1040,33 +1079,32 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
return assertJQ(req, JSONTestUtil.DEFAULT_DELTA, tests);
}
/**
- * Validates a query matches some JSON test expressions and closes the
- * query. The text expression is of the form path:JSON. The Noggit JSON
- * parser used accepts single quoted strings and bare strings to allow
- * easy embedding in Java Strings.
- * <p>
- * Please use this with care: this makes it easy to match complete
- * structures, but doing so can result in fragile tests if you are
- * matching more than what you want to test.
- * </p>
+ * Validates a query matches some JSON test expressions and closes the query. The text expression
+ * is of the form path:JSON. The Noggit JSON parser used accepts single quoted strings and bare
+ * strings to allow easy embedding in Java Strings.
+ *
+ * <p>Please use this with care: this makes it easy to match complete structures, but doing so can
+ * result in fragile tests if you are matching more than what you want to test.
+ *
* @param req Solr request to execute
* @param delta tolerance allowed in comparing float/double values
* @param tests JSON path expression + '==' + expected value
* @return The request response as a JSON String if all test patterns pass
*/
- public static String assertJQ(SolrQueryRequest req, double delta, String... tests) throws Exception {
- SolrParams params = null;
+ public static String assertJQ(SolrQueryRequest req, double delta, String... tests)
+ throws Exception {
+ SolrParams params = null;
try {
params = req.getParams();
- if (!"json".equals(params.get("wt","xml")) || params.get("indent")==null) {
+ if (!"json".equals(params.get("wt", "xml")) || params.get("indent") == null) {
ModifiableSolrParams newParams = new ModifiableSolrParams(params);
- newParams.set("wt","json");
- if (params.get("indent")==null) newParams.set("indent","true");
+ newParams.set("wt", "json");
+ if (params.get("indent") == null) newParams.set("indent", "true");
req.setParams(newParams);
}
String response;
- boolean failed=true;
+ boolean failed = true;
try {
response = h.query(req);
failed = false;
@@ -1077,7 +1115,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
for (String test : tests) {
- if (test == null || test.length()==0) continue;
+ if (test == null || test.length() == 0) continue;
String testJSON = json(test);
try {
@@ -1085,16 +1123,21 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
String err = JSONTestUtil.match(response, testJSON, delta);
failed = false;
if (err != null) {
- log.error("query failed JSON validation. error={}\n expected ={}\n response = {}\n request = {}"
- , err, testJSON, response, req.getParamString()
- );
+ log.error(
+ "query failed JSON validation. error={}\n expected ={}\n response = {}\n request = {}",
+ err,
+ testJSON,
+ response,
+ req.getParamString());
throw new RuntimeException(err);
}
} finally {
if (failed) {
- log.error("JSON query validation threw an exception.\n expected ={} \n response = {}\n request = {}"
- , testJSON, response, req.getParamString()
- );
+ log.error(
+ "JSON query validation threw an exception.\n expected ={} \n response = {}\n request = {}",
+ testJSON,
+ response,
+ req.getParamString());
}
}
}
@@ -1103,17 +1146,16 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
// restore the params
if (params != null && params != req.getParams()) req.setParams(params);
}
- }
-
+ }
/** Makes sure a query throws a SolrException with the listed response code */
- public static void assertQEx(String message, SolrQueryRequest req, int code ) {
+ public static void assertQEx(String message, SolrQueryRequest req, int code) {
try {
ignoreException(".");
h.query(req);
- fail( message );
+ fail(message);
} catch (SolrException sex) {
- assertEquals( code, sex.code() );
+ assertEquals(code, sex.code());
} catch (Exception e2) {
throw new RuntimeException("Exception during query", e2);
} finally {
@@ -1121,13 +1163,13 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
}
- public static void assertQEx(String message, SolrQueryRequest req, SolrException.ErrorCode code ) {
+ public static void assertQEx(String message, SolrQueryRequest req, SolrException.ErrorCode code) {
try {
ignoreException(".");
h.query(req);
- fail( message );
+ fail(message);
} catch (SolrException e) {
- assertEquals( code.code, e.code() );
+ assertEquals(code.code, e.code());
} catch (Exception e2) {
throw new RuntimeException("Exception during query", e2);
} finally {
@@ -1136,20 +1178,31 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
/**
* Makes sure a query throws a SolrException with the listed response code and expected message
- * @param failMessage The assert message to show when the query doesn't throw the expected exception
+ *
+ * @param failMessage The assert message to show when the query doesn't throw the expected
+ * exception
* @param exceptionMessage A substring of the message expected in the exception
* @param req Solr request
* @param code expected error code for the query
*/
- public static void assertQEx(String failMessage, String exceptionMessage, SolrQueryRequest req, SolrException.ErrorCode code ) {
+ public static void assertQEx(
+ String failMessage,
+ String exceptionMessage,
+ SolrQueryRequest req,
+ SolrException.ErrorCode code) {
try {
ignoreException(".");
h.query(req);
- fail( failMessage );
+ fail(failMessage);
} catch (SolrException e) {
- assertEquals( code.code, e.code() );
- assertTrue("Unexpected error message. Expecting \"" + exceptionMessage +
- "\" but got \"" + e.getMessage() + "\"", e.getMessage()!= null && e.getMessage().contains(exceptionMessage));
+ assertEquals(code.code, e.code());
+ assertTrue(
+ "Unexpected error message. Expecting \""
+ + exceptionMessage
+ + "\" but got \""
+ + e.getMessage()
+ + "\"",
+ e.getMessage() != null && e.getMessage().contains(exceptionMessage));
} catch (Exception e2) {
throw new RuntimeException("Exception during query", e2);
} finally {
@@ -1157,7 +1210,6 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
}
-
/**
* @see TestHarness#optimize
*/
@@ -1183,9 +1235,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
return add(d);
}
- /**
- * Generates a simple &lt;add&gt;&lt;doc&gt;... XML String with no options
- */
+ /** Generates a simple &lt;add&gt;&lt;doc&gt;... XML String with no options */
public static String adoc(SolrInputDocument sdoc) {
StringWriter out = new StringWriter(512);
try {
@@ -1201,10 +1251,8 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
public static void addDoc(String doc, String updateRequestProcessorChain) throws Exception {
Map<String, String[]> params = new HashMap<>();
MultiMapSolrParams mmparams = new MultiMapSolrParams(params);
- params.put(UpdateParams.UPDATE_CHAIN, new String[]{updateRequestProcessorChain});
- SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(),
- (SolrParams) mmparams) {
- };
+ params.put(UpdateParams.UPDATE_CHAIN, new String[] {updateRequestProcessorChain});
+ SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(), (SolrParams) mmparams) {};
UpdateRequestHandler handler = new UpdateRequestHandler();
handler.init(null);
@@ -1216,8 +1264,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
/**
- * Generates an &lt;add&gt;&lt;doc&gt;... XML String with options
- * on the add.
+ * Generates an &lt;add&gt;&lt;doc&gt;... XML String with options on the add.
*
* @param doc the Document to add
* @param args 0th and Even numbered args are param names, Odds are param values.
@@ -1234,13 +1281,12 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
r.write(doc.xml);
r.write("</add>");
} else {
- XML.writeUnescapedXML(r, "add", doc.xml, (Object[])args);
+ XML.writeUnescapedXML(r, "add", doc.xml, (Object[]) args);
}
return r.getBuffer().toString();
} catch (IOException e) {
- throw new RuntimeException
- ("this should never happen with a StringWriter", e);
+ throw new RuntimeException("this should never happen with a StringWriter", e);
}
}
@@ -1274,9 +1320,9 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
/**
- * Generates the correct SolrParams from an even list of strings.
- * A string in an even position will represent the name of a parameter, while the following string
- * at position (i+1) will be the assigned value.
+ * Generates the correct SolrParams from an even list of strings. A string in an even position
+ * will represent the name of a parameter, while the following string at position (i+1) will be
+ * the assigned value.
*
* @param params an even list of strings
* @return the ModifiableSolrParams generated from the given list of strings.
@@ -1284,8 +1330,8 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
public static ModifiableSolrParams params(String... params) {
if (params.length % 2 != 0) throw new RuntimeException("Params length should be even");
ModifiableSolrParams msp = new ModifiableSolrParams();
- for (int i=0; i<params.length; i+=2) {
- msp.add(params[i], params[i+1]);
+ for (int i = 0; i < params.length; i += 2) {
+ msp.add(params[i], params[i + 1]);
}
return msp;
}
@@ -1300,6 +1346,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
/**
* Generates a SolrQueryRequest using the LocalRequestFactory
+ *
* @see #lrf
*/
public static SolrQueryRequest req(String... q) {
@@ -1308,27 +1355,26 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
/**
* Generates a SolrQueryRequest using the LocalRequestFactory
+ *
* @see #lrf
*/
public static SolrQueryRequest req(String[] params, String... moreParams) {
String[] allParams = moreParams;
- if (params.length!=0) {
+ if (params.length != 0) {
int len = params.length + moreParams.length;
allParams = new String[len];
- System.arraycopy(params,0,allParams,0,params.length);
- System.arraycopy(moreParams,0,allParams,params.length,moreParams.length);
+ System.arraycopy(params, 0, allParams, 0, params.length);
+ System.arraycopy(moreParams, 0, allParams, params.length, moreParams.length);
}
return lrf.makeRequest(allParams);
}
- /**
- * Generates a SolrQueryRequest
- */
+ /** Generates a SolrQueryRequest */
public static SolrQueryRequest req(SolrParams params, String... moreParams) {
ModifiableSolrParams mp = new ModifiableSolrParams(params);
- for (int i=0; i<moreParams.length; i+=2) {
- mp.add(moreParams[i], moreParams[i+1]);
+ for (int i = 0; i < moreParams.length; i += 2) {
+ mp.add(moreParams[i], moreParams[i + 1]);
}
return new LocalSolrQueryRequest(h.getCore(), mp);
}
@@ -1336,17 +1382,20 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
/** Necessary to make method signatures un-ambiguous */
public static class XmlDoc {
public String xml;
+
@Override
- public String toString() { return xml; }
+ public String toString() {
+ return xml;
+ }
}
/**
- * Does a low level delete of all docs in the index.
+ * Does a low level delete of all docs in the index.
*
- * The behavior of this method is slightly different then doing a normal <code>*:*</code> DBQ because it
- * takes advantage of internal methods to ensure all index data is wiped, regardless of optimistic
- * concurrency version constraints -- making it suitable for tests that create synthetic versions,
- * and/or require a completely pristine index w/o any field metdata.
+ * <p>The behavior of this method is slightly different then doing a normal <code>*:*</code> DBQ
+ * because it takes advantage of internal methods to ensure all index data is wiped, regardless of
+ * optimistic concurrency version constraints -- making it suitable for tests that create
+ * synthetic versions, and/or require a completely pristine index w/o any field metdata.
*
* @see #deleteByQueryAndGetVersion
*/
@@ -1357,8 +1406,13 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
return;
}
try {
- deleteByQueryAndGetVersion("*:*", params("_version_", Long.toString(-Long.MAX_VALUE),
- DISTRIB_UPDATE_PARAM,DistribPhase.FROMLEADER.toString()));
+ deleteByQueryAndGetVersion(
+ "*:*",
+ params(
+ "_version_",
+ Long.toString(-Long.MAX_VALUE),
+ DISTRIB_UPDATE_PARAM,
+ DistribPhase.FROMLEADER.toString()));
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -1368,11 +1422,11 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
public static String updateJ(String json, SolrParams args) throws Exception {
SolrCore core = h.getCore();
if (args == null) {
- args = params("wt","json","indent","true");
+ args = params("wt", "json", "indent", "true");
} else {
ModifiableSolrParams newArgs = new ModifiableSolrParams(args);
- if (newArgs.get("wt") == null) newArgs.set("wt","json");
- if (newArgs.get("indent") == null) newArgs.set("indent","true");
+ if (newArgs.get("wt") == null) newArgs.set("wt", "json");
+ if (newArgs.get("indent") == null) newArgs.set("indent", "true");
args = newArgs;
}
DirectSolrConnection connection = new DirectSolrConnection(core);
@@ -1386,8 +1440,8 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
public static SolrInputDocument sdoc(Object... fieldsAndValues) {
SolrInputDocument sd = new SolrInputDocument();
- for (int i=0; i<fieldsAndValues.length; i+=2) {
- sd.addField((String)fieldsAndValues[i], fieldsAndValues[i+1]);
+ for (int i = 0; i < fieldsAndValues.length; i += 2) {
+ sd.addField((String) fieldsAndValues[i], fieldsAndValues[i + 1]);
}
return sd;
}
@@ -1403,10 +1457,11 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
return doc;
}
+
public SolrInputDocument sdocWithChildren(Integer id, String version, int childCount) {
SolrInputDocument doc = sdoc("id", id, "_version_", version);
for (int i = 1; i <= childCount; i++) {
- doc.addChildDocument(sdoc("id", (1000)*id + i));
+ doc.addChildDocument(sdoc("id", (1000) * id + i));
}
return doc;
}
@@ -1415,19 +1470,21 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
return Arrays.asList(docs);
}
- /** Converts "test JSON" strings into JSON parseable by our JSON parser.
- * For example, this method changed single quoted strings into double quoted strings before
- * the parser could natively handle them.
+ /**
+ * Converts "test JSON" strings into JSON parseable by our JSON parser. For example, this method
+ * changed single quoted strings into double quoted strings before the parser could natively
+ * handle them.
*
- * This transformation is automatically applied to JSON test strings (like assertJQ).
+ * <p>This transformation is automatically applied to JSON test strings (like assertJQ).
*/
public static String json(String testJSON) {
return testJSON;
}
-
- /** Creates JSON from a SolrInputDocument. Doesn't currently handle boosts.
- * @see #json(SolrInputDocument,CharArr)
+ /**
+ * Creates JSON from a SolrInputDocument. Doesn't currently handle boosts.
+ *
+ * @see #json(SolrInputDocument,CharArr)
*/
public static String json(SolrInputDocument doc) {
CharArr out = new CharArr();
@@ -1436,8 +1493,8 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
/**
- * Appends to the <code>out</code> array with JSON from the <code>doc</code>.
- * Doesn't currently handle boosts, but does recursively handle child documents
+ * Appends to the <code>out</code> array with JSON from the <code>doc</code>. Doesn't currently
+ * handle boosts, but does recursively handle child documents
*/
@SuppressWarnings({"unchecked"})
public static void json(SolrInputDocument doc, CharArr out) {
@@ -1445,7 +1502,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
out.append('{');
boolean firstField = true;
for (SolrInputField sfield : doc) {
- if (firstField) firstField=false;
+ if (firstField) firstField = false;
else out.append(',');
JSONUtil.writeString(sfield.getName(), 0, sfield.getName().length(), out);
out.append(':');
@@ -1454,28 +1511,35 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
out.append('[');
boolean firstVal = true;
for (Object val : sfield) {
- if (firstVal) firstVal=false;
+ if (firstVal) firstVal = false;
else out.append(',');
- if(val instanceof SolrInputDocument) {
+ if (val instanceof SolrInputDocument) {
json((SolrInputDocument) val, out);
}
out.append(JSONUtil.toJSON(val));
}
out.append(']');
- } else if(sfield.getValue() instanceof SolrInputDocument) {
+ } else if (sfield.getValue() instanceof SolrInputDocument) {
json((SolrInputDocument) sfield.getValue(), out);
} else if (sfield.getValue() instanceof Map) {
Map<String, Object> valMap = (Map<String, Object>) sfield.getValue();
- Set<String> childDocsKeys = valMap.entrySet().stream().filter(record -> isChildDoc(record.getValue()))
- .map(Entry::getKey).collect(Collectors.toSet());
- if(childDocsKeys.size() > 0) {
+ Set<String> childDocsKeys =
+ valMap.entrySet().stream()
+ .filter(record -> isChildDoc(record.getValue()))
+ .map(Entry::getKey)
+ .collect(Collectors.toSet());
+ if (childDocsKeys.size() > 0) {
Map<String, Object> newMap = new HashMap<>();
- for(Entry<String, Object> entry: valMap.entrySet()) {
+ for (Entry<String, Object> entry : valMap.entrySet()) {
String keyName = entry.getKey();
Object val = entry.getValue();
- if(childDocsKeys.contains(keyName)) {
- if(val instanceof Collection) {
- val = ((Collection) val).stream().map(e -> toSolrDoc((SolrInputDocument) e)).collect(Collectors.toList());
+ if (childDocsKeys.contains(keyName)) {
+ if (val instanceof Collection) {
+ val =
+ ((Collection) val)
+ .stream()
+ .map(e -> toSolrDoc((SolrInputDocument) e))
+ .collect(Collectors.toList());
} else {
val = toSolrDoc((SolrInputDocument) val);
}
@@ -1491,11 +1555,11 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
boolean firstChildDoc = true;
- if(doc.hasChildDocuments()) {
+ if (doc.hasChildDocuments()) {
out.append(",\"_childDocuments_\": [");
List<SolrInputDocument> childDocuments = doc.getChildDocuments();
- for(SolrInputDocument childDocument : childDocuments) {
- if (firstChildDoc) firstChildDoc=false;
+ for (SolrInputDocument childDocument : childDocuments) {
+ if (firstChildDoc) firstChildDoc = false;
else out.append(',');
json(childDocument, out);
}
@@ -1507,14 +1571,14 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
}
- /** Creates a JSON add command from a SolrInputDocument list. Doesn't currently handle boosts. */
+ /** Creates a JSON add command from a SolrInputDocument list. Doesn't currently handle boosts. */
public static String jsonAdd(SolrInputDocument... docs) {
CharArr out = new CharArr();
try {
out.append('[');
boolean firstField = true;
for (SolrInputDocument doc : docs) {
- if (firstField) firstField=false;
+ if (firstField) firstField = false;
else out.append(',');
out.append(json(doc));
}
@@ -1525,14 +1589,14 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
return out.toString();
}
- /** Creates a JSON delete command from an id list */
+ /** Creates a JSON delete command from an id list */
public static String jsonDelId(Object... ids) {
CharArr out = new CharArr();
try {
out.append('{');
boolean first = true;
for (Object id : ids) {
- if (first) first=false;
+ if (first) first = false;
else out.append(',');
out.append("\"delete\":{\"id\":");
out.append(JSONUtil.toJSON(id));
@@ -1545,7 +1609,6 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
return out.toString();
}
-
/** Creates a JSON deleteByQuery command */
public static String jsonDelQ(String... queries) {
CharArr out = new CharArr();
@@ -1553,7 +1616,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
out.append('{');
boolean first = true;
for (Object q : queries) {
- if (first) first=false;
+ if (first) first = false;
else out.append(',');
out.append("\"delete\":{\"query\":");
out.append(JSONUtil.toJSON(q));
@@ -1566,48 +1629,47 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
return out.toString();
}
-
public static Long addAndGetVersion(SolrInputDocument sdoc, SolrParams params) throws Exception {
- if (params==null || params.get("versions") == null) {
+ if (params == null || params.get("versions") == null) {
ModifiableSolrParams mparams = new ModifiableSolrParams(params);
- mparams.set("versions","true");
+ mparams.set("versions", "true");
params = mparams;
}
String response = updateJ(jsonAdd(sdoc), params);
@SuppressWarnings({"rawtypes"})
- Map rsp = (Map)ObjectBuilder.fromJSON(response);
+ Map rsp = (Map) ObjectBuilder.fromJSON(response);
@SuppressWarnings({"rawtypes"})
- List lst = (List)rsp.get("adds");
+ List lst = (List) rsp.get("adds");
if (lst == null || lst.size() == 0) return null;
return (Long) lst.get(1);
}
public static Long deleteAndGetVersion(String id, SolrParams params) throws Exception {
- if (params==null || params.get("versions") == null) {
+ if (params == null || params.get("versions") == null) {
ModifiableSolrParams mparams = new ModifiableSolrParams(params);
- mparams.set("versions","true");
+ mparams.set("versions", "true");
params = mparams;
}
String response = updateJ(jsonDelId(id), params);
@SuppressWarnings({"rawtypes"})
- Map rsp = (Map)ObjectBuilder.fromJSON(response);
+ Map rsp = (Map) ObjectBuilder.fromJSON(response);
@SuppressWarnings({"rawtypes"})
- List lst = (List)rsp.get("deletes");
+ List lst = (List) rsp.get("deletes");
if (lst == null || lst.size() == 0) return null;
return (Long) lst.get(1);
}
public static Long deleteByQueryAndGetVersion(String q, SolrParams params) throws Exception {
- if (params==null || params.get("versions") == null) {
+ if (params == null || params.get("versions") == null) {
ModifiableSolrParams mparams = new ModifiableSolrParams(params);
- mparams.set("versions","true");
+ mparams.set("versions", "true");
params = mparams;
}
String response = updateJ(jsonDelQ(q), params);
@SuppressWarnings({"rawtypes"})
- Map rsp = (Map)ObjectBuilder.fromJSON(response);
+ Map rsp = (Map) ObjectBuilder.fromJSON(response);
@SuppressWarnings({"rawtypes"})
- List lst = (List)rsp.get("deleteByQuery");
+ List lst = (List) rsp.get("deleteByQuery");
if (lst == null || lst.size() == 0) return null;
return (Long) lst.get(1);
}
@@ -1615,16 +1677,17 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
/////////////////////////////////////////////////////////////////////////////////////
//////////////////////////// random document / index creation ///////////////////////
/////////////////////////////////////////////////////////////////////////////////////
-
+
public abstract static class Vals {
@SuppressWarnings({"rawtypes"})
public abstract Comparable get();
- public String toJSON(@SuppressWarnings({"rawtypes"})Comparable val) {
+
+ public String toJSON(@SuppressWarnings({"rawtypes"}) Comparable val) {
return JSONUtil.toJSON(val);
}
protected int between(int min, int max) {
- return min != max ? random().nextInt(max-min+1) + min : min;
+ return min != max ? random().nextInt(max - min + 1) + min : min;
}
}
@@ -1635,6 +1698,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
public static class IRange extends IVals {
final int min;
final int max;
+
public IRange(int min, int max) {
this.min = min;
this.max = max;
@@ -1642,7 +1706,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
@Override
public int getInt() {
- return between(min,max);
+ return between(min, max);
}
@Override
@@ -1654,22 +1718,23 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
public static class IValsPercent extends IVals {
final int[] percentAndValue;
+
public IValsPercent(int... percentAndValue) {
this.percentAndValue = percentAndValue;
}
@Override
public int getInt() {
- int r = between(0,99);
+ int r = between(0, 99);
int cumulative = 0;
- for (int i=0; i<percentAndValue.length; i+=2) {
+ for (int i = 0; i < percentAndValue.length; i += 2) {
cumulative += percentAndValue[i];
if (r < cumulative) {
- return percentAndValue[i+1];
+ return percentAndValue[i + 1];
}
}
- return percentAndValue[percentAndValue.length-1];
+ return percentAndValue[percentAndValue.length - 1];
}
@Override
@@ -1682,6 +1747,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
public static class FVal extends Vals {
final float min;
final float max;
+
public FVal(float min, float max) {
this.min = min;
this.max = max;
@@ -1689,7 +1755,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
public float getFloat() {
if (min >= max) return min;
- return min + random().nextFloat() * (max - min);
+ return min + random().nextFloat() * (max - min);
}
@Override
@@ -1715,7 +1781,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
int maxLength;
public SVal() {
- this('a','z',1,10);
+ this('a', 'z', 1, 10);
}
public SVal(char start, char end, int minLength, int maxLength) {
@@ -1728,17 +1794,17 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
@Override
@SuppressWarnings({"rawtypes"})
public Comparable get() {
- char[] arr = new char[between(minLength,maxLength)];
- for (int i=0; i<arr.length; i++) {
- arr[i] = (char)between(start, end);
+ char[] arr = new char[between(minLength, maxLength)];
+ for (int i = 0; i < arr.length; i++) {
+ arr[i] = (char) between(start, end);
}
return new String(arr);
}
}
- public static final IRange ZERO_ONE = new IRange(0,1);
- public static final IRange ZERO_TWO = new IRange(0,2);
- public static final IRange ONE_ONE = new IRange(1,1);
+ public static final IRange ZERO_ONE = new IRange(0, 1);
+ public static final IRange ZERO_TWO = new IRange(0, 2);
+ public static final IRange ONE_ONE = new IRange(1, 1);
@SuppressWarnings({"rawtypes"})
public static class Doc implements Comparable {
@@ -1746,10 +1812,9 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
public List<Fld> fields;
public int order; // the order this document was added to the index
-
@Override
public String toString() {
- return "Doc("+order+"):"+fields.toString();
+ return "Doc(" + order + "):" + fields.toString();
}
@Override
@@ -1760,15 +1825,15 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
@Override
public boolean equals(Object o) {
if (!(o instanceof Doc)) return false;
- Doc other = (Doc)o;
- return this==other || id != null && id.equals(other.id);
+ Doc other = (Doc) o;
+ return this == other || id != null && id.equals(other.id);
}
@Override
@SuppressWarnings({"unchecked"})
public int compareTo(Object o) {
if (!(o instanceof Doc)) return this.getClass().hashCode() - o.getClass().hashCode();
- Doc other = (Doc)o;
+ Doc other = (Doc) o;
return this.id.compareTo(other.id);
}
@@ -1783,11 +1848,11 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
@SuppressWarnings({"rawtypes"})
public Comparable getFirstValue(String field) {
List<Comparable> vals = getValues(field);
- return vals==null || vals.size()==0 ? null : vals.get(0);
+ return vals == null || vals.size() == 0 ? null : vals.get(0);
}
- public Map<String,Object> toObject(IndexSchema schema) {
- Map<String,Object> result = new HashMap<>();
+ public Map<String, Object> toObject(IndexSchema schema) {
+ Map<String, Object> result = new HashMap<>();
for (Fld fld : fields) {
SchemaField sf = schema.getField(fld.ftype.fname);
if (!sf.multiValued()) {
@@ -1798,16 +1863,17 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
return result;
}
-
}
public static class Fld {
public FldType ftype;
+
@SuppressWarnings({"rawtypes"})
public List<Comparable> vals;
+
@Override
public String toString() {
- return ftype.fname + "=" + (vals.size()==1 ? vals.get(0).toString() : vals.toString());
+ return ftype.fname + "=" + (vals.size() == 1 ? vals.get(0).toString() : vals.toString());
}
}
@@ -1823,7 +1889,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
public FldType(String fname, IVals numValues, Vals vals) {
this.fname = fname;
this.numValues = numValues;
- this.vals = vals;
+ this.vals = vals;
}
@SuppressWarnings({"rawtypes"})
@@ -1836,8 +1902,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
int nVals = numValues.getInt();
if (nVals <= 0) return null;
List<Comparable> vals = new ArrayList<>(nVals);
- for (int i=0; i<nVals; i++)
- vals.add(createValue());
+ for (int i = 0; i < nVals; i++) vals.add(createValue());
return vals;
}
@@ -1849,73 +1914,90 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
Fld fld = new Fld();
fld.ftype = this;
fld.vals = vals;
- return fld;
+ return fld;
}
-
}
public static void assertResponseValues(SolrResponseBase rsp, Object... assertions) {
Map<String, Object> values = Utils.makeMap(assertions);
- values.forEach((s, o) -> {
- if (o instanceof String) {
- assertEquals(o, rsp.getResponse()._getStr(s, null));
- } else {
- assertEquals(o, rsp.getResponse()._get(s, null));
- }
- });
+ values.forEach(
+ (s, o) -> {
+ if (o instanceof String) {
+ assertEquals(o, rsp.getResponse()._getStr(s, null));
+ } else {
+ assertEquals(o, rsp.getResponse()._get(s, null));
+ }
+ });
}
+
@SuppressWarnings({"rawtypes"})
- public Map<Comparable,Doc> indexDocs(List<FldType> descriptor, Map<Comparable,Doc> model, int nDocs) throws Exception {
+ public Map<Comparable, Doc> indexDocs(
+ List<FldType> descriptor, Map<Comparable, Doc> model, int nDocs) throws Exception {
if (model == null) {
model = new LinkedHashMap<>();
}
// commit an average of 10 times for large sets, or 10% of the time for small sets
- int commitOneOutOf = Math.max(nDocs/10, 10);
+ int commitOneOutOf = Math.max(nDocs / 10, 10);
- for (int i=0; i<nDocs; i++) {
+ for (int i = 0; i < nDocs; i++) {
Doc doc = createDoc(descriptor);
// doc.order = order++;
updateJ(toJSON(doc), null);
model.put(doc.id, doc);
// commit 10% of the time
- if (random().nextInt(commitOneOutOf)==0) {
+ if (random().nextInt(commitOneOutOf) == 0) {
assertU(commit());
}
// duplicate 10% of the docs
- if (random().nextInt(10)==0) {
+ if (random().nextInt(10) == 0) {
updateJ(toJSON(doc), null);
- model.put(doc.id, doc);
+ model.put(doc.id, doc);
}
}
// optimize 10% of the time
- if (random().nextInt(10)==0) {
+ if (random().nextInt(10) == 0) {
assertU(optimize());
} else {
if (random().nextInt(10) == 0) {
assertU(commit());
} else {
- assertU(commit("softCommit","true"));
+ assertU(commit("softCommit", "true"));
}
}
- // merging segments no longer selects just adjacent segments hence ids (doc.order) can be shuffled.
+ // merging segments no longer selects just adjacent segments hence ids (doc.order) can be
+ // shuffled.
// we need to look at the index to determine the order.
- String responseStr = h.query(req("q","*:*", "fl","id", "sort","_docid_ asc", "rows",Integer.toString(model.size()*2), "wt","json", "indent","true"));
+ String responseStr =
+ h.query(
+ req(
+ "q",
+ "*:*",
+ "fl",
+ "id",
+ "sort",
+ "_docid_ asc",
+ "rows",
+ Integer.toString(model.size() * 2),
+ "wt",
+ "json",
+ "indent",
+ "true"));
Object response = ObjectBuilder.fromJSON(responseStr);
- response = ((Map)response).get("response");
- response = ((Map)response).get("docs");
+ response = ((Map) response).get("response");
+ response = ((Map) response).get("docs");
@SuppressWarnings({"unchecked"})
- List<Map> docList = (List<Map>)response;
+ List<Map> docList = (List<Map>) response;
int order = 0;
for (Map doc : docList) {
Object id = doc.get("id");
Doc modelDoc = model.get(id);
- if (modelDoc == null) continue; // may be some docs in the index that aren't modeled
+ if (modelDoc == null) continue; // may be some docs in the index that aren't modeled
modelDoc.order = order++;
}
@@ -1932,21 +2014,21 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
Fld fld = ftype.createField();
if (fld != null) {
doc.fields.add(fld);
- if ("id".equals(ftype.fname))
- doc.id = fld.vals.get(0);
+ if ("id".equals(ftype.fname)) doc.id = fld.vals.get(0);
}
}
return doc;
}
- public static Comparator<Doc> createSort(IndexSchema schema, List<FldType> fieldTypes, String[] out) {
+ public static Comparator<Doc> createSort(
+ IndexSchema schema, List<FldType> fieldTypes, String[] out) {
StringBuilder sortSpec = new StringBuilder();
int nSorts = random().nextInt(4);
List<Comparator<Doc>> comparators = new ArrayList<>();
- for (int i=0; i<nSorts; i++) {
- if (i>0) sortSpec.append(',');
+ for (int i = 0; i < nSorts; i++) {
+ if (i > 0) sortSpec.append(',');
- int which = random().nextInt(fieldTypes.size()+2);
+ int which = random().nextInt(fieldTypes.size() + 2);
boolean asc = random().nextBoolean();
if (which == fieldTypes.size()) {
// sort by score
@@ -1960,7 +2042,13 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
String field = fieldTypes.get(which).fname;
sortSpec.append(field).append(asc ? " asc" : " desc");
SchemaField sf = schema.getField(field);
- comparators.add(createComparator(field, asc, sf.sortMissingLast(), sf.sortMissingFirst(), !(sf.sortMissingLast()||sf.sortMissingFirst()) ));
+ comparators.add(
+ createComparator(
+ field,
+ asc,
+ sf.sortMissingLast(),
+ sf.sortMissingFirst(),
+ !(sf.sortMissingLast() || sf.sortMissingFirst())));
}
}
@@ -1968,17 +2056,22 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
if (comparators.size() == 0) {
// default sort is by score desc
- comparators.add(createComparator("score", false, false, false, false));
+ comparators.add(createComparator("score", false, false, false, false));
}
return createComparator(comparators);
}
- public static Comparator<Doc> createComparator(final String field, final boolean asc, final boolean sortMissingLast, final boolean sortMissingFirst, final boolean sortMissingAsZero) {
+ public static Comparator<Doc> createComparator(
+ final String field,
+ final boolean asc,
+ final boolean sortMissingLast,
+ final boolean sortMissingFirst,
+ final boolean sortMissingAsZero) {
final int mul = asc ? 1 : -1;
if (field.equals("_docid_")) {
- return (o1, o2) -> (o1.order - o2.order) * mul;
+ return (o1, o2) -> (o1.order - o2.order) * mul;
}
if (field.equals("score")) {
@@ -1989,14 +2082,14 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
@SuppressWarnings({"rawtypes"})
private Comparable zeroVal(Comparable template) {
if (template == null) return null;
- if (template instanceof String) return null; // fast-path for string
+ if (template instanceof String) return null; // fast-path for string
if (template instanceof Integer) return 0;
- if (template instanceof Long) return (long)0;
- if (template instanceof Float) return (float)0;
- if (template instanceof Double) return (double)0;
- if (template instanceof Short) return (short)0;
- if (template instanceof Byte) return (byte)0;
- if (template instanceof Character) return (char)0;
+ if (template instanceof Long) return (long) 0;
+ if (template instanceof Float) return (float) 0;
+ if (template instanceof Double) return (double) 0;
+ if (template instanceof Short) return (short) 0;
+ if (template instanceof Byte) return (byte) 0;
+ if (template instanceof Character) return (char) 0;
return null;
}
@@ -2038,20 +2131,19 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
int c = 0;
for (Comparator<Doc> comparator : comparators) {
c = comparator.compare(o1, o2);
- if (c!=0) return c;
+ if (c != 0) return c;
}
return o1.order - o2.order;
};
}
-
public static String toJSON(Doc doc) {
CharArr out = new CharArr();
try {
out.append("{\"add\":{\"doc\":{");
boolean firstField = true;
for (Fld fld : doc.fields) {
- if (firstField) firstField=false;
+ if (firstField) firstField = false;
else out.append(',');
JSONUtil.writeString(fld.ftype.fname, 0, fld.ftype.fname.length(), out);
out.append(':');
@@ -2059,8 +2151,8 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
out.append('[');
}
boolean firstVal = true;
- for (@SuppressWarnings({"rawtypes"})Comparable val : fld.vals) {
- if (firstVal) firstVal=false;
+ for (@SuppressWarnings({"rawtypes"}) Comparable val : fld.vals) {
+ if (firstVal) firstVal = false;
else out.append(',');
out.append(JSONUtil.toJSON(val));
}
@@ -2098,35 +2190,43 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
return value_to_id;
}
-
- /** Gets a resource from the context classloader as {@link File}. This method should only be used,
- * if a real file is needed. To get a stream, code should prefer
- * {@link Class#getResourceAsStream} using {@code this.getClass()}.
+ /**
+ * Gets a resource from the context classloader as {@link File}. This method should only be used,
+ * if a real file is needed. To get a stream, code should prefer {@link Class#getResourceAsStream}
+ * using {@code this.getClass()}.
*/
public static File getFile(String name) {
- final URL url = SolrTestCaseJ4.class.getClassLoader().getResource(name.replace(File.separatorChar, '/'));
+ final URL url =
+ SolrTestCaseJ4.class.getClassLoader().getResource(name.replace(File.separatorChar, '/'));
if (url != null) {
try {
return new File(url.toURI());
} catch (Exception e) {
- throw new RuntimeException("Resource was found on classpath, but cannot be resolved to a " +
- "normal file (maybe it is part of a JAR file): " + name);
+ throw new RuntimeException(
+ "Resource was found on classpath, but cannot be resolved to a "
+ + "normal file (maybe it is part of a JAR file): "
+ + name);
}
}
final File file = new File(name);
if (file.exists()) {
return file;
}
- throw new RuntimeException("Cannot find resource in classpath or in file-system (relative to CWD): " + name);
+ throw new RuntimeException(
+ "Cannot find resource in classpath or in file-system (relative to CWD): " + name);
}
-
+
public static String TEST_HOME() {
return getFile("solr/collection1").getParent();
}
- public static Path TEST_PATH() { return getFile("solr/collection1").getParentFile().toPath(); }
+ public static Path TEST_PATH() {
+ return getFile("solr/collection1").getParentFile().toPath();
+ }
- public static Path TEST_COLL1_CONF() { return TEST_PATH().resolve("collection1").resolve("conf"); }
+ public static Path TEST_COLL1_CONF() {
+ return TEST_PATH().resolve("collection1").resolve("conf");
+ }
public static Path configset(String name) {
return TEST_PATH().resolve("configsets").resolve(name).resolve("conf");
@@ -2147,34 +2247,51 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
String xml = Files.readString(file.toPath());
String results = TestHarness.validateXPath(xml, xpath);
if (null != results) {
- String msg = "File XPath failure: file=" + file.getPath() + " xpath="
- + results + "\n\nxml was: " + xml;
+ String msg =
+ "File XPath failure: file="
+ + file.getPath()
+ + " xpath="
+ + results
+ + "\n\nxml was: "
+ + xml;
fail(msg);
}
} catch (XPathExpressionException e2) {
throw new RuntimeException("XPath is invalid", e2);
}
}
-
+
/**
- * Fails if the number of documents in the given SolrDocumentList differs
- * from the given number of expected values, or if any of the values in the
- * given field don't match the expected values in the same order.
+ * Fails if the number of documents in the given SolrDocumentList differs from the given number of
+ * expected values, or if any of the values in the given field don't match the expected values in
+ * the same order.
*/
- public static void assertFieldValues(SolrDocumentList documents, String fieldName, Object... expectedValues) {
+ public static void assertFieldValues(
+ SolrDocumentList documents, String fieldName, Object... expectedValues) {
if (documents.size() != expectedValues.length) {
- fail("Number of documents (" + documents.size()
- + ") is different from number of expected values (" + expectedValues.length);
+ fail(
+ "Number of documents ("
+ + documents.size()
+ + ") is different from number of expected values ("
+ + expectedValues.length);
}
- for (int docNum = 1 ; docNum <= documents.size() ; ++docNum) {
+ for (int docNum = 1; docNum <= documents.size(); ++docNum) {
SolrDocument doc = documents.get(docNum - 1);
Object expected = expectedValues[docNum - 1];
Object actual = doc.get(fieldName);
- if ((null == expected && null != actual) ||
- (null != expected && null == actual) ||
- (null != expected && null != actual && !expected.equals(actual))) {
- fail("Unexpected " + fieldName + " field value in document #" + docNum
- + ": expected=[" + expected + "], actual=[" + actual + "]");
+ if ((null == expected && null != actual)
+ || (null != expected && null == actual)
+ || (null != expected && null != actual && !expected.equals(actual))) {
+ fail(
+ "Unexpected "
+ + fieldName
+ + " field value in document #"
+ + docNum
+ + ": expected=["
+ + expected
+ + "], actual=["
+ + actual
+ + "]");
}
}
}
@@ -2184,13 +2301,15 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
// Creates a minimal conf dir, adding in a core.properties file from the string passed in
- // the string to write to the core.properties file may be null in which case nothing is done with it.
+ // the string to write to the core.properties file may be null in which case nothing is done with
+ // it.
// propertiesContent may be an empty string, which will actually work.
public static void copyMinConf(File dstRoot, String propertiesContent) throws IOException {
copyMinConf(dstRoot, propertiesContent, "solrconfig-minimal.xml");
}
- public static void copyMinConf(File dstRoot, String propertiesContent, String solrconfigXmlName) throws IOException {
+ public static void copyMinConf(File dstRoot, String propertiesContent, String solrconfigXmlName)
+ throws IOException {
Path dstPath = dstRoot.toPath();
Path subHome = dstPath.resolve("conf");
Files.createDirectories(subHome);
@@ -2201,13 +2320,16 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
Path top = SolrTestCaseJ4.TEST_PATH().resolve("collection1").resolve("conf");
Files.copy(top.resolve("schema-tiny.xml"), subHome.resolve("schema.xml"));
Files.copy(top.resolve(solrconfigXmlName), subHome.resolve("solrconfig.xml"));
- Files.copy(top.resolve("solrconfig.snippet.randomindexconfig.xml"), subHome.resolve("solrconfig.snippet.randomindexconfig.xml"));
+ Files.copy(
+ top.resolve("solrconfig.snippet.randomindexconfig.xml"),
+ subHome.resolve("solrconfig.snippet.randomindexconfig.xml"));
}
// Creates minimal full setup, including solr.xml
public static void copyMinFullSetup(File dstRoot) throws IOException {
Files.createDirectories(dstRoot.toPath());
- Files.copy(SolrTestCaseJ4.TEST_PATH().resolve("solr.xml"), dstRoot.toPath().resolve("solr.xml"));
+ Files.copy(
+ SolrTestCaseJ4.TEST_PATH().resolve("solr.xml"), dstRoot.toPath().resolve("solr.xml"));
copyMinConf(dstRoot);
}
@@ -2216,24 +2338,31 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
Files.createDirectories(dstRoot.toPath());
Files.copy(SolrTestCaseJ4.TEST_PATH().resolve(fromFile), dstRoot.toPath().resolve("solr.xml"));
}
- // Creates a consistent configuration, _including_ solr.xml at dstRoot. Creates collection1/conf and copies
- // the stock files in there.
+ // Creates a consistent configuration, _including_ solr.xml at dstRoot. Creates collection1/conf
+ // and copies the stock files in there.
public static void copySolrHomeToTemp(File dstRoot, String collection) throws IOException {
Path subHome = dstRoot.toPath().resolve(collection).resolve("conf");
Files.createDirectories(subHome);
- Files.copy(SolrTestCaseJ4.TEST_PATH().resolve("solr.xml"), dstRoot.toPath().resolve("solr.xml"), StandardCopyOption.REPLACE_EXISTING);
+ Files.copy(
+ SolrTestCaseJ4.TEST_PATH().resolve("solr.xml"),
+ dstRoot.toPath().resolve("solr.xml"),
+ StandardCopyOption.REPLACE_EXISTING);
Path top = SolrTestCaseJ4.TEST_PATH().resolve("collection1").resolve("conf");
Files.copy(top.resolve("currency.xml"), subHome.resolve("currency.xml"));
- Files.copy(top.resolve("mapping-ISOLatin1Accent.txt"), subHome.resolve("mapping-ISOLatin1Accent.txt"));
+ Files.copy(
+ top.resolve("mapping-ISOLatin1Accent.txt"), subHome.resolve("mapping-ISOLatin1Accent.txt"));
Files.copy(top.resolve("old_synonyms.txt"), subHome.resolve("old_synonyms.txt"));
- Files.copy(top.resolve("open-exchange-rates.json"), subHome.resolve("open-exchange-rates.json"));
+ Files.copy(
+ top.resolve("open-exchange-rates.json"), subHome.resolve("open-exchange-rates.json"));
Files.copy(top.resolve("protwords.txt"), subHome.resolve("protwords.txt"));
Files.copy(top.resolve("schema.xml"), subHome.resolve("schema.xml"));
Files.copy(top.resolve("enumsConfig.xml"), subHome.resolve("enumsConfig.xml"));
- Files.copy(top.resolve("solrconfig.snippet.randomindexconfig.xml"), subHome.resolve("solrconfig.snippet.randomindexconfig.xml"));
+ Files.copy(
+ top.resolve("solrconfig.snippet.randomindexconfig.xml"),
+ subHome.resolve("solrconfig.snippet.randomindexconfig.xml"));
Files.copy(top.resolve("solrconfig.xml"), subHome.resolve("solrconfig.xml"));
Files.copy(top.resolve("stopwords.txt"), subHome.resolve("stopwords.txt"));
Files.copy(top.resolve("synonyms.txt"), subHome.resolve("synonyms.txt"));
@@ -2241,7 +2370,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
public boolean compareSolrDocument(Object expected, Object actual) {
- if (!(expected instanceof SolrDocument) || !(actual instanceof SolrDocument)) {
+ if (!(expected instanceof SolrDocument) || !(actual instanceof SolrDocument)) {
return false;
}
@@ -2252,37 +2381,38 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
SolrDocument solrDocument1 = (SolrDocument) expected;
SolrDocument solrDocument2 = (SolrDocument) actual;
- if(solrDocument1.getFieldNames().size() != solrDocument2.getFieldNames().size()) {
+ if (solrDocument1.getFieldNames().size() != solrDocument2.getFieldNames().size()) {
return false;
}
Iterator<String> iter1 = solrDocument1.getFieldNames().iterator();
Iterator<String> iter2 = solrDocument2.getFieldNames().iterator();
- if(iter1.hasNext()) {
+ if (iter1.hasNext()) {
String key1 = iter1.next();
String key2 = iter2.next();
Object val1 = solrDocument1.getFieldValues(key1);
Object val2 = solrDocument2.getFieldValues(key2);
- if(!key1.equals(key2) || !val1.equals(val2)) {
+ if (!key1.equals(key2) || !val1.equals(val2)) {
return false;
}
}
- if(solrDocument1.getChildDocuments() == null && solrDocument2.getChildDocuments() == null) {
+ if (solrDocument1.getChildDocuments() == null && solrDocument2.getChildDocuments() == null) {
return true;
}
- if(solrDocument1.getChildDocuments() == null || solrDocument2.getChildDocuments() == null) {
+ if (solrDocument1.getChildDocuments() == null || solrDocument2.getChildDocuments() == null) {
return false;
- } else if(solrDocument1.getChildDocuments().size() != solrDocument2.getChildDocuments().size()) {
+ } else if (solrDocument1.getChildDocuments().size()
+ != solrDocument2.getChildDocuments().size()) {
return false;
} else {
Iterator<SolrDocument> childDocsIter1 = solrDocument1.getChildDocuments().iterator();
Iterator<SolrDocument> childDocsIter2 = solrDocument2.getChildDocuments().iterator();
- while(childDocsIter1.hasNext()) {
- if(!compareSolrDocument(childDocsIter1.next(), childDocsIter2.next())) {
+ while (childDocsIter1.hasNext()) {
+ if (!compareSolrDocument(childDocsIter1.next(), childDocsIter2.next())) {
return false;
}
}
@@ -2291,7 +2421,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
public boolean compareSolrDocumentList(Object expected, Object actual) {
- if (!(expected instanceof SolrDocumentList) || !(actual instanceof SolrDocumentList)) {
+ if (!(expected instanceof SolrDocumentList) || !(actual instanceof SolrDocumentList)) {
return false;
}
@@ -2305,17 +2435,18 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
if (list1.getMaxScore() == null) {
if (list2.getMaxScore() != null) {
return false;
- }
+ }
} else if (list2.getMaxScore() == null) {
return false;
} else {
- if (Float.compare(list1.getMaxScore(), list2.getMaxScore()) != 0 || list1.getNumFound() != list2.getNumFound() ||
- list1.getStart() != list2.getStart()) {
+ if (Float.compare(list1.getMaxScore(), list2.getMaxScore()) != 0
+ || list1.getNumFound() != list2.getNumFound()
+ || list1.getStart() != list2.getStart()) {
return false;
}
}
- for(int i=0; i<list1.getNumFound(); i++) {
- if(!compareSolrDocument(list1.get(i), list2.get(i))) {
+ for (int i = 0; i < list1.getNumFound(); i++) {
+ if (!compareSolrDocument(list1.get(i), list2.get(i))) {
return false;
}
}
@@ -2335,7 +2466,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
SolrInputDocument sdoc1 = (SolrInputDocument) expected;
SolrInputDocument sdoc2 = (SolrInputDocument) actual;
- if(sdoc1.getFieldNames().size() != sdoc2.getFieldNames().size()) {
+ if (sdoc1.getFieldNames().size() != sdoc2.getFieldNames().size()) {
return false;
}
@@ -2349,12 +2480,12 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
Object val1 = sdoc1.getFieldValues(key1);
Object val2 = sdoc2.getFieldValues(key2);
- if(!key1.equals(key2)) {
+ if (!key1.equals(key2)) {
return false;
}
- if(!(sdoc1.get(key1).getFirstValue() instanceof SolrInputDocument)) {
- if(!val1.equals(val2)) {
+ if (!(sdoc1.get(key1).getFirstValue() instanceof SolrInputDocument)) {
+ if (!val1.equals(val2)) {
return false;
}
} else {
@@ -2379,18 +2510,18 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
}
}
- if(sdoc1.getChildDocuments() == null && sdoc2.getChildDocuments() == null) {
+ if (sdoc1.getChildDocuments() == null && sdoc2.getChildDocuments() == null) {
return true;
}
- if(sdoc1.getChildDocuments() == null || sdoc2.getChildDocuments() == null) {
+ if (sdoc1.getChildDocuments() == null || sdoc2.getChildDocuments() == null) {
return false;
- } else if(sdoc1.getChildDocuments().size() != sdoc2.getChildDocuments().size()) {
+ } else if (sdoc1.getChildDocuments().size() != sdoc2.getChildDocuments().size()) {
return false;
} else {
Iterator<SolrInputDocument> childDocsIter1 = sdoc1.getChildDocuments().iterator();
Iterator<SolrInputDocument> childDocsIter2 = sdoc2.getChildDocuments().iterator();
- while(childDocsIter1.hasNext()) {
- if(!compareSolrInputDocument(childDocsIter1.next(), childDocsIter2.next())) {
+ while (childDocsIter1.hasNext()) {
+ if (!compareSolrInputDocument(childDocsIter1.next(), childDocsIter2.next())) {
return false;
}
}
@@ -2399,7 +2530,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
public boolean assertSolrInputFieldEquals(Object expected, Object actual) {
- if (!(expected instanceof SolrInputField) || !(actual instanceof SolrInputField)) {
+ if (!(expected instanceof SolrInputField) || !(actual instanceof SolrInputField)) {
return false;
}
@@ -2421,16 +2552,14 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
return true;
}
- /**
- * Returns <code>likely</code> most (1/10) of the time, otherwise <code>unlikely</code>
- */
+ /** Returns <code>likely</code> most (1/10) of the time, otherwise <code>unlikely</code> */
public static Object skewed(Object likely, Object unlikely) {
return (0 == TestUtil.nextInt(random(), 0, 9)) ? unlikely : likely;
}
/**
- * A variant of {@link org.apache.solr.client.solrj.impl.CloudHttp2SolrClient.Builder} that will randomize
- * some internal settings.
+ * A variant of {@link org.apache.solr.client.solrj.impl.CloudHttp2SolrClient.Builder} that will
+ * randomize some internal settings.
*/
public static class CloudHttp2SolrClientBuilder extends CloudHttp2SolrClient.Builder {
@@ -2475,40 +2604,40 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
/**
- * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient.
- * Tests that do not wish to have any randomized behavior should use the
- * {@link org.apache.solr.client.solrj.impl.CloudHttp2SolrClient.Builder} class directly
+ * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
+ * not wish to have any randomized behavior should use the {@link
+ * org.apache.solr.client.solrj.impl.CloudHttp2SolrClient.Builder} class directly
*/
public static CloudHttp2SolrClient getCloudHttp2SolrClient(MiniSolrCloudCluster cluster) {
return new CloudHttp2SolrClientBuilder(cluster).build();
}
/**
- * A variant of {@link org.apache.solr.client.solrj.impl.CloudSolrClient.Builder} that will randomize
- * some internal settings.
+ * A variant of {@link org.apache.solr.client.solrj.impl.CloudSolrClient.Builder} that will
+ * randomize some internal settings.
*/
public static class CloudSolrClientBuilder extends CloudSolrClient.Builder {
-
+
public CloudSolrClientBuilder(List<String> zkHosts, Optional<String> zkChroot) {
super(zkHosts, zkChroot);
randomizeCloudSolrClient();
}
-
+
public CloudSolrClientBuilder(ClusterStateProvider stateProvider) {
this.stateProvider = stateProvider;
randomizeCloudSolrClient();
}
-
+
public CloudSolrClientBuilder(MiniSolrCloudCluster cluster) {
if (random().nextBoolean()) {
this.zkHosts.add(cluster.getZkServer().getZkAddress());
} else {
populateSolrUrls(cluster);
}
-
+
randomizeCloudSolrClient();
}
-
+
private void populateSolrUrls(MiniSolrCloudCluster cluster) {
if (random().nextBoolean()) {
final List<JettySolrRunner> solrNodes = cluster.getJettySolrRunners();
@@ -2519,7 +2648,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
this.solrUrls.add(cluster.getRandomJetty(random()).getBaseUrl().toString());
}
}
-
+
private void randomizeCloudSolrClient() {
this.directUpdatesToLeadersOnly = random().nextBoolean();
this.shardLeadersOnly = random().nextBoolean();
@@ -2528,39 +2657,39 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
/**
- * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient.
- * Tests that do not wish to have any randomized behavior should use the
- * {@link org.apache.solr.client.solrj.impl.CloudSolrClient.Builder} class directly
- */
+ * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
+ * not wish to have any randomized behavior should use the {@link
+ * org.apache.solr.client.solrj.impl.CloudSolrClient.Builder} class directly
+ */
public static CloudSolrClient getCloudSolrClient(String zkHost) {
return new CloudSolrClientBuilder(Collections.singletonList(zkHost), Optional.empty()).build();
}
/**
- * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient.
- * Tests that do not wish to have any randomized behavior should use the
- * {@link org.apache.solr.client.solrj.impl.CloudSolrClient.Builder} class directly
+ * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
+ * not wish to have any randomized behavior should use the {@link
+ * org.apache.solr.client.solrj.impl.CloudSolrClient.Builder} class directly
*/
public static CloudSolrClient getCloudSolrClient(MiniSolrCloudCluster cluster) {
return new CloudSolrClientBuilder(cluster).build();
}
/**
- * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient.
- * Tests that do not wish to have any randomized behavior should use the
- * {@link org.apache.solr.client.solrj.impl.CloudSolrClient.Builder} class directly
- */
+ * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
+ * not wish to have any randomized behavior should use the {@link
+ * org.apache.solr.client.solrj.impl.CloudSolrClient.Builder} class directly
+ */
public static CloudSolrClient getCloudSolrClient(String zkHost, HttpClient httpClient) {
return new CloudSolrClientBuilder(Collections.singletonList(zkHost), Optional.empty())
.withHttpClient(httpClient)
.build();
}
-
+
/**
- * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient.
- * Tests that do not wish to have any randomized behavior should use the
- * {@link org.apache.solr.client.solrj.impl.CloudSolrClient.Builder} class directly
- */
+ * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
+ * not wish to have any randomized behavior should use the {@link
+ * org.apache.solr.client.solrj.impl.CloudSolrClient.Builder} class directly
+ */
public static CloudSolrClient getCloudSolrClient(String zkHost, boolean shardLeadersOnly) {
if (shardLeadersOnly) {
return new CloudSolrClientBuilder(Collections.singletonList(zkHost), Optional.empty())
@@ -2577,11 +2706,12 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
/**
- * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient.
- * Tests that do not wish to have any randomized behavior should use the
- * {@link org.apache.solr.client.solrj.impl.CloudSolrClient.Builder} class directly
- */
- public static CloudSolrClient getCloudSolrClient(String zkHost, boolean shardLeadersOnly, int socketTimeoutMillis) {
+ * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
+ * not wish to have any randomized behavior should use the {@link
+ * org.apache.solr.client.solrj.impl.CloudSolrClient.Builder} class directly
+ */
+ public static CloudSolrClient getCloudSolrClient(
+ String zkHost, boolean shardLeadersOnly, int socketTimeoutMillis) {
if (shardLeadersOnly) {
return new CloudSolrClientBuilder(Collections.singletonList(zkHost), Optional.empty())
.sendUpdatesOnlyToShardLeaders()
@@ -2593,13 +2723,17 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
.withSocketTimeout(socketTimeoutMillis)
.build();
}
-
+
/**
- * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient.
- * Tests that do not wish to have any randomized behavior should use the
- * {@link org.apache.solr.client.solrj.impl.CloudSolrClient.Builder} class directly
- */
- public static CloudSolrClient getCloudSolrClient(String zkHost, boolean shardLeadersOnly, int connectionTimeoutMillis, int socketTimeoutMillis) {
+ * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
+ * not wish to have any randomized behavior should use the {@link
+ * org.apache.solr.client.solrj.impl.CloudSolrClient.Builder} class directly
+ */
+ public static CloudSolrClient getCloudSolrClient(
+ String zkHost,
+ boolean shardLeadersOnly,
+ int connectionTimeoutMillis,
+ int socketTimeoutMillis) {
if (shardLeadersOnly) {
return new CloudSolrClientBuilder(Collections.singletonList(zkHost), Optional.empty())
.sendUpdatesOnlyToShardLeaders()
@@ -2613,15 +2747,14 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
.withSocketTimeout(socketTimeoutMillis)
.build();
}
-
-
-
+
/**
- * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient.
- * Tests that do not wish to have any randomized behavior should use the
- * {@link org.apache.solr.client.solrj.impl.CloudSolrClient.Builder} class directly
- */
- public static CloudSolrClient getCloudSolrClient(String zkHost, boolean shardLeadersOnly, HttpClient httpClient) {
+ * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
+ * not wish to have any randomized behavior should use the {@link
+ * org.apache.solr.client.solrj.impl.CloudSolrClient.Builder} class directly
+ */
+ public static CloudSolrClient getCloudSolrClient(
+ String zkHost, boolean shardLeadersOnly, HttpClient httpClient) {
if (shardLeadersOnly) {
return new CloudSolrClientBuilder(Collections.singletonList(zkHost), Optional.empty())
.withHttpClient(httpClient)
@@ -2633,14 +2766,18 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
.sendUpdatesToAllReplicasInShard()
.build();
}
-
+
/**
- * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient.
- * Tests that do not wish to have any randomized behavior should use the
- * {@link org.apache.solr.client.solrj.impl.CloudSolrClient.Builder} class directly
- */
- public static CloudSolrClient getCloudSolrClient(String zkHost, boolean shardLeadersOnly, HttpClient httpClient,
- int connectionTimeoutMillis, int socketTimeoutMillis) {
+ * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
+ * not wish to have any randomized behavior should use the {@link
+ * org.apache.solr.client.solrj.impl.CloudSolrClient.Builder} class directly
+ */
+ public static CloudSolrClient getCloudSolrClient(
+ String zkHost,
+ boolean shardLeadersOnly,
+ HttpClient httpClient,
+ int connectionTimeoutMillis,
+ int socketTimeoutMillis) {
if (shardLeadersOnly) {
return new CloudSolrClientBuilder(Collections.singletonList(zkHost), Optional.empty())
.withHttpClient(httpClient)
@@ -2656,64 +2793,64 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
.withSocketTimeout(socketTimeoutMillis)
.build();
}
-
+
/**
- * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient.
- * Tests that do not wish to have any randomized behavior should use the
- * {@link org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient.Builder} class directly
- */
- public static ConcurrentUpdateSolrClient getConcurrentUpdateSolrClient(String baseSolrUrl, int queueSize, int threadCount) {
+ * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
+ * not wish to have any randomized behavior should use the {@link
+ * org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient.Builder} class directly
+ */
+ public static ConcurrentUpdateSolrClient getConcurrentUpdateSolrClient(
+ String baseSolrUrl, int queueSize, int threadCount) {
return new ConcurrentUpdateSolrClient.Builder(baseSolrUrl)
.withQueueSize(queueSize)
.withThreadCount(threadCount)
.build();
}
-
+
/**
- * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient.
- * Tests that do not wish to have any randomized behavior should use the
- * {@link org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient.Builder} class directly
- */
- public static ConcurrentUpdateSolrClient getConcurrentUpdateSolrClient(String baseSolrUrl, int queueSize, int threadCount, int connectionTimeoutMillis) {
+ * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
+ * not wish to have any randomized behavior should use the {@link
+ * org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient.Builder} class directly
+ */
+ public static ConcurrentUpdateSolrClient getConcurrentUpdateSolrClient(
+ String baseSolrUrl, int queueSize, int threadCount, int connectionTimeoutMillis) {
return new ConcurrentUpdateSolrClient.Builder(baseSolrUrl)
.withQueueSize(queueSize)
.withThreadCount(threadCount)
.withConnectionTimeout(connectionTimeoutMillis)
.build();
}
-
+
/**
- * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient.
- * Tests that do not wish to have any randomized behavior should use the
- * {@link org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient.Builder} class directly
- */
- public static ConcurrentUpdateSolrClient getConcurrentUpdateSolrClient(String baseSolrUrl, HttpClient httpClient, int queueSize, int threadCount) {
+ * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
+ * not wish to have any randomized behavior should use the {@link
+ * org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient.Builder} class directly
+ */
+ public static ConcurrentUpdateSolrClient getConcurrentUpdateSolrClient(
+ String baseSolrUrl, HttpClient httpClient, int queueSize, int threadCount) {
return new ConcurrentUpdateSolrClient.Builder(baseSolrUrl)
.withHttpClient(httpClient)
.withQueueSize(queueSize)
.withThreadCount(threadCount)
.build();
}
-
+
/**
- * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient.
- * Tests that do not wish to have any randomized behavior should use the
- * {@link org.apache.solr.client.solrj.impl.LBHttpSolrClient.Builder} class directly
- */
+ * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
+ * not wish to have any randomized behavior should use the {@link
+ * org.apache.solr.client.solrj.impl.LBHttpSolrClient.Builder} class directly
+ */
public static LBHttpSolrClient getLBHttpSolrClient(HttpClient client, String... solrUrls) {
- return new LBHttpSolrClient.Builder()
- .withHttpClient(client)
- .withBaseSolrUrls(solrUrls)
- .build();
+ return new LBHttpSolrClient.Builder().withHttpClient(client).withBaseSolrUrls(solrUrls).build();
}
-
+
/**
- * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient.
- * Tests that do not wish to have any randomized behavior should use the
- * {@link org.apache.solr.client.solrj.impl.LBHttpSolrClient.Builder} class directly
- */
- public static LBHttpSolrClient getLBHttpSolrClient(HttpClient client, int connectionTimeoutMillis,
- int socketTimeoutMillis, String... solrUrls) {
+ * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
+ * not wish to have any randomized behavior should use the {@link
+ * org.apache.solr.client.solrj.impl.LBHttpSolrClient.Builder} class directly
+ */
+ public static LBHttpSolrClient getLBHttpSolrClient(
+ HttpClient client, int connectionTimeoutMillis, int socketTimeoutMillis, String... solrUrls) {
return new LBHttpSolrClient.Builder()
.withHttpClient(client)
.withBaseSolrUrls(solrUrls)
@@ -2721,60 +2858,57 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
.withSocketTimeout(socketTimeoutMillis)
.build();
}
-
+
/**
- * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient.
- * Tests that do not wish to have any randomized behavior should use the
- * {@link org.apache.solr.client.solrj.impl.LBHttpSolrClient.Builder} class directly
- */
- public static LBHttpSolrClient getLBHttpSolrClient(String... solrUrls) throws MalformedURLException {
- return new LBHttpSolrClient.Builder()
- .withBaseSolrUrls(solrUrls)
- .build();
+ * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
+ * not wish to have any randomized behavior should use the {@link
+ * org.apache.solr.client.solrj.impl.LBHttpSolrClient.Builder} class directly
+ */
+ public static LBHttpSolrClient getLBHttpSolrClient(String... solrUrls)
+ throws MalformedURLException {
+ return new LBHttpSolrClient.Builder().withBaseSolrUrls(solrUrls).build();
}
-
+
/**
- * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient.
- * Tests that do not wish to have any randomized behavior should use the
- * {@link org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
- */
- public static HttpSolrClient getHttpSolrClient(String url, HttpClient httpClient, ResponseParser responseParser, boolean compression) {
+ * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
+ * not wish to have any randomized behavior should use the {@link
+ * org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+ */
+ public static HttpSolrClient getHttpSolrClient(
+ String url, HttpClient httpClient, ResponseParser responseParser, boolean compression) {
return new Builder(url)
.withHttpClient(httpClient)
.withResponseParser(responseParser)
.allowCompression(compression)
.build();
}
-
+
/**
- * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient.
- * Tests that do not wish to have any randomized behavior should use the
- * {@link org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
- */
- public static HttpSolrClient getHttpSolrClient(String url, HttpClient httpClient, ResponseParser responseParser) {
- return new Builder(url)
- .withHttpClient(httpClient)
- .withResponseParser(responseParser)
- .build();
+ * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
+ * not wish to have any randomized behavior should use the {@link
+ * org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+ */
+ public static HttpSolrClient getHttpSolrClient(
+ String url, HttpClient httpClient, ResponseParser responseParser) {
+ return new Builder(url).withHttpClient(httpClient).withResponseParser(responseParser).build();
}
-
+
/**
- * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient.
- * Tests that do not wish to have any randomized behavior should use the
- * {@link org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
- */
+ * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
+ * not wish to have any randomized behavior should use the {@link
+ * org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+ */
public static HttpSolrClient getHttpSolrClient(String url, HttpClient httpClient) {
- return new Builder(url)
- .withHttpClient(httpClient)
- .build();
+ return new Builder(url).withHttpClient(httpClient).build();
}
-
+
/**
- * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient.
- * Tests that do not wish to have any randomized behavior should use the
- * {@link org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
- */
- public static HttpSolrClient getHttpSolrClient(String url, HttpClient httpClient, int connectionTimeoutMillis) {
+ * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
+ * not wish to have any randomized behavior should use the {@link
+ * org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+ */
+ public static HttpSolrClient getHttpSolrClient(
+ String url, HttpClient httpClient, int connectionTimeoutMillis) {
return new Builder(url)
.withHttpClient(httpClient)
.withConnectionTimeout(connectionTimeoutMillis)
@@ -2782,62 +2916,61 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
/**
- * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient.
- * Tests that do not wish to have any randomized behavior should use the
- * {@link org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
- */
+ * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
+ * not wish to have any randomized behavior should use the {@link
+ * org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+ */
public static HttpSolrClient getHttpSolrClient(String url) {
- return new Builder(url)
- .build();
+ return new Builder(url).build();
}
-
+
/**
- * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient.
- * Tests that do not wish to have any randomized behavior should use the
- * {@link org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
- */
+ * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
+ * not wish to have any randomized behavior should use the {@link
+ * org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+ */
public static HttpSolrClient getHttpSolrClient(String url, int connectionTimeoutMillis) {
- return new Builder(url)
- .withConnectionTimeout(connectionTimeoutMillis)
- .build();
+ return new Builder(url).withConnectionTimeout(connectionTimeoutMillis).build();
}
-
+
/**
- * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient.
- * Tests that do not wish to have any randomized behavior should use the
- * {@link org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
- */
- public static HttpSolrClient getHttpSolrClient(String url, int connectionTimeoutMillis, int socketTimeoutMillis) {
+ * This method <i>may</i> randomize unspecified aspects of the resulting SolrClient. Tests that do
+ * not wish to have any randomized behavior should use the {@link
+ * org.apache.solr.client.solrj.impl.HttpSolrClient.Builder} class directly
+ */
+ public static HttpSolrClient getHttpSolrClient(
+ String url, int connectionTimeoutMillis, int socketTimeoutMillis) {
return new Builder(url)
.withConnectionTimeout(connectionTimeoutMillis)
.withSocketTimeout(socketTimeoutMillis)
.build();
}
- /**
- * Returns a randomly generated Date in the appropriate Solr external (input) format
+ /**
+ * Returns a randomly generated Date in the appropriate Solr external (input) format
+ *
* @see #randomSkewedDate
*/
public static String randomDate() {
return Instant.ofEpochMilli(random().nextLong()).toString();
}
- /**
- * Returns a Date such that all results from this method always have the same values for
- * year+month+day+hour+minute but the seconds are randomized. This can be helpful for
- * indexing documents with random date values that are biased for a narrow window
- * (one day) to test collisions/overlaps
+ /**
+ * Returns a Date such that all results from this method always have the same values for
+ * year+month+day+hour+minute but the seconds are randomized. This can be helpful for indexing
+ * documents with random date values that are biased for a narrow window (one day) to test
+ * collisions/overlaps
*
* @see #randomDate
*/
public static String randomSkewedDate() {
- return String.format(Locale.ROOT, "2010-10-31T10:31:%02d.000Z",
- TestUtil.nextInt(random(), 0, 59));
+ return String.format(
+ Locale.ROOT, "2010-10-31T10:31:%02d.000Z", TestUtil.nextInt(random(), 0, 59));
}
/**
- * We want "realistic" unicode strings beyond simple ascii, but because our
- * updates use XML we need to ensure we don't get "special" code block.
+ * We want "realistic" unicode strings beyond simple ascii, but because our updates use XML we
+ * need to ensure we don't get "special" code block.
*/
public static String randomXmlUsableUnicodeString() {
String result = TestUtil.randomRealisticUnicodeString(random());
@@ -2846,7 +2979,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
return result;
}
-
+
protected static void waitForWarming(SolrCore core) throws InterruptedException {
RefCounted<SolrIndexSearcher> registeredSearcher = core.getRegisteredSearcher();
RefCounted<SolrIndexSearcher> newestSearcher = core.getNewestSearcher(false);
@@ -2877,7 +3010,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
return testName;
}
-
+
@BeforeClass
public static void assertNonBlockingRandomGeneratorAvailable() throws InterruptedException {
final String EGD = "java.security.egd";
@@ -2885,38 +3018,55 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
final String ALLOWED = "test.solr.allowed.securerandom";
final String allowedAlg = System.getProperty(ALLOWED);
final String actualEGD = System.getProperty(EGD);
-
+
log.info("SecureRandom sanity checks: {}={} & {}={}", ALLOWED, allowedAlg, EGD, actualEGD);
if (null != allowedAlg) {
// the user has explicitly requested to bypass our assertions and allow a particular alg
// the only thing we should do is assert that the algorithm they have allowed is actually used
-
-
+
final String actualAlg = (new SecureRandom()).getAlgorithm();
- assertEquals("Algorithm specified using "+ALLOWED+" system property " +
- "does not match actual algorithm", allowedAlg, actualAlg);
+ assertEquals(
+ "Algorithm specified using "
+ + ALLOWED
+ + " system property "
+ + "does not match actual algorithm",
+ allowedAlg,
+ actualAlg);
return;
}
- // else: no user override, do the checks we want including
-
+ // else: no user override, do the checks we want including
+
if (null == actualEGD) {
System.setProperty(EGD, URANDOM);
- log.warn("System property {} was not set by test runner, forcibly set to expected: {}", EGD, URANDOM);
- } else if (! URANDOM.equals(actualEGD) ) {
- log.warn("System property {}={} .. test runner should use expected: {}", EGD, actualEGD, URANDOM);
+ log.warn(
+ "System property {} was not set by test runner, forcibly set to expected: {}",
+ EGD,
+ URANDOM);
+ } else if (!URANDOM.equals(actualEGD)) {
+ log.warn(
+ "System property {}={} .. test runner should use expected: {}", EGD, actualEGD, URANDOM);
}
-
+
final String algorithm = (new SecureRandom()).getAlgorithm();
-
- assertFalse("SecureRandom algorithm '" + algorithm + "' is in use by your JVM, " +
- "which is a potentially blocking algorithm on some environments. " +
- "Please report the details of this failure (and your JVM vendor/version) to [email protected]. " +
- "You can try to run your tests with -D"+EGD+"="+URANDOM+" or bypass this check using " +
- "-Dtest.solr.allowed.securerandom="+ algorithm +" as a JVM option when running tests.",
- // be permissive in our checks and deny only algorithms
- // that are known to be blocking under some circumstances
- algorithm.equals("NativePRNG") || algorithm.equals("NativePRNGBlocking"));
+
+ assertFalse(
+ "SecureRandom algorithm '"
+ + algorithm
+ + "' is in use by your JVM, "
+ + "which is a potentially blocking algorithm on some environments. "
+ + "Please report the details of this failure (and your JVM vendor/version) to [email protected]. "
+ + "You can try to run your tests with -D"
+ + EGD
+ + "="
+ + URANDOM
+ + " or bypass this check using "
+ + "-Dtest.solr.allowed.securerandom="
+ + algorithm
+ + " as a JVM option when running tests.",
+ // be permissive in our checks and deny only algorithms
+ // that are known to be blocking under some circumstances
+ algorithm.equals("NativePRNG") || algorithm.equals("NativePRNGBlocking"));
}
protected static void systemSetPropertySolrTestsMergePolicyFactory(String value) {
@@ -2926,7 +3076,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
protected static void systemClearPropertySolrTestsMergePolicyFactory() {
System.clearProperty(SYSTEM_PROPERTY_SOLR_TESTS_MERGEPOLICYFACTORY);
}
-
+
@Deprecated // For backwards compatibility only. Please do not use in new tests.
protected static void systemSetPropertySolrDisableUrlAllowList(String value) {
System.setProperty(AllowListUrlChecker.DISABLE_URL_ALLOW_LIST, value);
@@ -2941,36 +3091,38 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
protected static <T> T pickRandom(T... options) {
return options[random().nextInt(options.length)];
}
-
+
/**
- * The name of a sysprop that can be set by users when running tests to force the types of numerics
- * used for test classes that do not have the {@link SuppressPointFields} annotation:
+ * The name of a sysprop that can be set by users when running tests to force the types of
+ * numerics used for test classes that do not have the {@link SuppressPointFields} annotation:
+ *
* <ul>
- * <li>If unset, then a random variable will be used to decide the type of numerics.</li>
- * <li>If set to <code>true</code> then Points based numerics will be used.</li>
- * <li>If set to <code>false</code> (or any other string) then Trie based numerics will be used.</li>
+ * <li>If unset, then a random variable will be used to decide the type of numerics.
+ * <li>If set to <code>true</code> then Points based numerics will be used.
+ * <li>If set to <code>false</code> (or any other string) then Trie based numerics will be used.
* </ul>
+ *
* @see #NUMERIC_POINTS_SYSPROP
*/
public static final String USE_NUMERIC_POINTS_SYSPROP = "solr.tests.use.numeric.points";
-
+
/**
- * The name of a sysprop that will either <code>true</code> or <code>false</code> indicating if
- * numeric points fields are currently in use, depending on the user specified value of
- * {@link #USE_NUMERIC_POINTS_SYSPROP} and/or the {@link SuppressPointFields} annotation and/or
+ * The name of a sysprop that will either <code>true</code> or <code>false</code> indicating if
+ * numeric points fields are currently in use, depending on the user specified value of {@link
+ * #USE_NUMERIC_POINTS_SYSPROP} and/or the {@link SuppressPointFields} annotation and/or
* randomization. Tests can use <code>Boolean.getBoolean(NUMERIC_POINTS_SYSPROP)</code>.
*
* @see #randomizeNumericTypesProperties
*/
public static final String NUMERIC_POINTS_SYSPROP = "solr.tests.numeric.points";
-
- /**
- * The name of a sysprop that will be either <code>true</code> or <code>false</code> indicating if
- * docValues should be used on a numeric field. This property string should be used in the
- * <code>docValues</code> attribute of (most) numeric fieldTypes in schemas, and by default will be
- * randomized by this class in a <code>@BeforeClass</code>. Subclasses that need to force specific
- * behavior can use <code>System.setProperty(NUMERIC_DOCVALUES_SYSPROP,"true")</code>
- * to override the default randomization.
+
+ /**
+ * The name of a sysprop that will be either <code>true</code> or <code>false</code> indicating if
+ * docValues should be used on a numeric field. This property string should be used in the <code>
+ * docValues</code> attribute of (most) numeric fieldTypes in schemas, and by default will be
+ * randomized by this class in a <code>@BeforeClass</code>. Subclasses that need to force specific
+ * behavior can use <code>System.setProperty(NUMERIC_DOCVALUES_SYSPROP,"true")</code> to override
+ * the default randomization.
*
* @see #randomizeNumericTypesProperties
*/
@@ -2979,8 +3131,8 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
public static final String UPDATELOG_SYSPROP = "solr.tests.ulog";
/**
- * Sets various sys props related to user specified or randomized choices regarding the types
- * of numerics that should be used in tests.
+ * Sets various sys props related to user specified or randomized choices regarding the types of
+ * numerics that should be used in tests.
*
* @see #NUMERIC_DOCVALUES_SYSPROP
* @see #NUMERIC_POINTS_SYSPROP
@@ -2991,18 +3143,22 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
private static void randomizeNumericTypesProperties() {
final boolean useDV = random().nextBoolean();
- System.setProperty(NUMERIC_DOCVALUES_SYSPROP, ""+useDV);
-
+ System.setProperty(NUMERIC_DOCVALUES_SYSPROP, "" + useDV);
+
// consume a consistent amount of random data even if sysprop/annotation is set
- final boolean randUsePoints = 0 != random().nextInt(5); // 80% likelihood
+ final boolean randUsePoints = 0 != random().nextInt(5); // 80% likelihood
final String usePointsStr = System.getProperty(USE_NUMERIC_POINTS_SYSPROP);
- final boolean usePoints = (null == usePointsStr) ? randUsePoints : Boolean.parseBoolean(usePointsStr);
-
- if (RandomizedContext.current().getTargetClass().isAnnotationPresent(SolrTestCaseJ4.SuppressPointFields.class)
- || (! usePoints)) {
- log.info("Using TrieFields (NUMERIC_POINTS_SYSPROP=false) w/NUMERIC_DOCVALUES_SYSPROP={}", useDV);
-
+ final boolean usePoints =
+ (null == usePointsStr) ? randUsePoints : Boolean.parseBoolean(usePointsStr);
+
+ if (RandomizedContext.current()
+ .getTargetClass()
+ .isAnnotationPresent(SolrTestCaseJ4.SuppressPointFields.class)
+ || (!usePoints)) {
+ log.info(
+ "Using TrieFields (NUMERIC_POINTS_SYSPROP=false) w/NUMERIC_DOCVALUES_SYSPROP={}", useDV);
+
org.apache.solr.schema.PointField.TEST_HACK_IGNORE_USELESS_TRIEFIELD_ARGS = false;
private_RANDOMIZED_NUMERIC_FIELDTYPES.put(Integer.class, "solr.TrieIntField");
private_RANDOMIZED_NUMERIC_FIELDTYPES.put(Float.class, "solr.TrieFloatField");
@@ -3010,10 +3166,11 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
private_RANDOMIZED_NUMERIC_FIELDTYPES.put(Double.class, "solr.TrieDoubleField");
private_RANDOMIZED_NUMERIC_FIELDTYPES.put(Date.class, "solr.TrieDateField");
private_RANDOMIZED_NUMERIC_FIELDTYPES.put(Enum.class, "solr.EnumField");
-
+
System.setProperty(NUMERIC_POINTS_SYSPROP, "false");
} else {
- log.info("Using PointFields (NUMERIC_POINTS_SYSPROP=true) w/NUMERIC_DOCVALUES_SYSPROP={}", useDV);
+ log.info(
+ "Using PointFields (NUMERIC_POINTS_SYSPROP=true) w/NUMERIC_DOCVALUES_SYSPROP={}", useDV);
org.apache.solr.schema.PointField.TEST_HACK_IGNORE_USELESS_TRIEFIELD_ARGS = true;
private_RANDOMIZED_NUMERIC_FIELDTYPES.put(Integer.class, "solr.IntPointField");
@@ -3022,26 +3179,26 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
private_RANDOMIZED_NUMERIC_FIELDTYPES.put(Double.class, "solr.DoublePointField");
private_RANDOMIZED_NUMERIC_FIELDTYPES.put(Date.class, "solr.DatePointField");
private_RANDOMIZED_NUMERIC_FIELDTYPES.put(Enum.class, "solr.EnumFieldType");
-
+
System.setProperty(NUMERIC_POINTS_SYSPROP, "true");
}
- for (Map.Entry<Class<?>,String> entry : RANDOMIZED_NUMERIC_FIELDTYPES.entrySet()) {
- System.setProperty("solr.tests." + entry.getKey().getSimpleName() + "FieldType",
- entry.getValue());
-
+ for (Map.Entry<Class<?>, String> entry : RANDOMIZED_NUMERIC_FIELDTYPES.entrySet()) {
+ System.setProperty(
+ "solr.tests." + entry.getKey().getSimpleName() + "FieldType", entry.getValue());
}
}
- public static DistributedUpdateProcessor createDistributedUpdateProcessor(SolrQueryRequest req, SolrQueryResponse rsp,
- UpdateRequestProcessor next) {
- if(h.getCoreContainer().isZooKeeperAware()) {
+ public static DistributedUpdateProcessor createDistributedUpdateProcessor(
+ SolrQueryRequest req, SolrQueryResponse rsp, UpdateRequestProcessor next) {
+ if (h.getCoreContainer().isZooKeeperAware()) {
return new DistributedZkUpdateProcessor(req, rsp, next);
}
return new DistributedUpdateProcessor(req, rsp, next);
}
-
+
/**
- * Cleans up the randomized sysproperties and variables set by {@link #randomizeNumericTypesProperties}
+ * Cleans up the randomized sysproperties and variables set by {@link
+ * #randomizeNumericTypesProperties}
*
* @see #randomizeNumericTypesProperties
* @lucene.experimental
@@ -3059,16 +3216,16 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
private static SolrDocument toSolrDoc(SolrInputDocument sid) {
SolrDocument doc = new SolrDocument();
- for(SolrInputField field: sid) {
+ for (SolrInputField field : sid) {
doc.setField(field.getName(), field.getValue());
}
return doc;
}
private static boolean isChildDoc(Object o) {
- if(o instanceof Collection) {
+ if (o instanceof Collection) {
Collection<?> col = (Collection<?>) o;
- if(col.size() == 0) {
+ if (col.size() == 0) {
return false;
}
return col.iterator().next() instanceof SolrInputDocument;
@@ -3076,18 +3233,17 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
return o instanceof SolrInputDocument;
}
- private static final Map<Class<?>,String> private_RANDOMIZED_NUMERIC_FIELDTYPES = new HashMap<>();
-
+ private static final Map<Class<?>, String> private_RANDOMIZED_NUMERIC_FIELDTYPES =
+ new HashMap<>();
+
/**
- * A Map of "primitive" java "numeric" types and the string name of the <code>class</code> used in the
- * corresponding schema fieldType declaration.
- * <p>
- * Example: <code>java.util.Date =&gt; "solr.DatePointField"</code>
- * </p>
+ * A Map of "primitive" java "numeric" types and the string name of the <code>class</code> used in
+ * the corresponding schema fieldType declaration.
+ *
+ * <p>Example: <code>java.util.Date =&gt; "solr.DatePointField"</code>
*
* @see #randomizeNumericTypesProperties
*/
- protected static final Map<Class<?>,String> RANDOMIZED_NUMERIC_FIELDTYPES
- = Collections.unmodifiableMap(private_RANDOMIZED_NUMERIC_FIELDTYPES);
-
+ protected static final Map<Class<?>, String> RANDOMIZED_NUMERIC_FIELDTYPES =
+ Collections.unmodifiableMap(private_RANDOMIZED_NUMERIC_FIELDTYPES);
}
diff --git a/solr/test-framework/src/java/org/apache/solr/analysis/MockCharFilterFactory.java b/solr/test-framework/src/java/org/apache/solr/analysis/MockCharFilterFactory.java
index 54bca8c44dc..95438755d0e 100644
--- a/solr/test-framework/src/java/org/apache/solr/analysis/MockCharFilterFactory.java
+++ b/solr/test-framework/src/java/org/apache/solr/analysis/MockCharFilterFactory.java
@@ -18,13 +18,10 @@ package org.apache.solr.analysis;
import java.io.Reader;
import java.util.Map;
-
-import org.apache.lucene.analysis.MockCharFilter;
import org.apache.lucene.analysis.CharFilterFactory;
+import org.apache.lucene.analysis.MockCharFilter;
-/**
- * Factory for {@link MockCharFilter} for testing purposes.
- */
+/** Factory for {@link MockCharFilter} for testing purposes. */
public class MockCharFilterFactory extends CharFilterFactory {
/** SPI name */
@@ -33,7 +30,7 @@ public class MockCharFilterFactory extends CharFilterFactory {
final int remainder;
/** Creates a new MockCharFilterFactory */
- public MockCharFilterFactory(Map<String,String> args) {
+ public MockCharFilterFactory(Map<String, String> args) {
super(args);
remainder = requireInt(args, "remainder");
if (!args.isEmpty()) {
diff --git a/solr/test-framework/src/java/org/apache/solr/analysis/MockTokenFilterFactory.java b/solr/test-framework/src/java/org/apache/solr/analysis/MockTokenFilterFactory.java
index 7780da1c15b..afe91bd12ee 100644
--- a/solr/test-framework/src/java/org/apache/solr/analysis/MockTokenFilterFactory.java
+++ b/solr/test-framework/src/java/org/apache/solr/analysis/MockTokenFilterFactory.java
@@ -18,16 +18,13 @@ package org.apache.solr.analysis;
import java.util.Arrays;
import java.util.Map;
-
import org.apache.lucene.analysis.MockTokenFilter;
-import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.TokenFilterFactory;
+import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.util.automaton.CharacterRunAutomaton;
import org.apache.lucene.util.automaton.RegExp;
-/**
- * Factory for {@link MockTokenFilter} for testing purposes.
- */
+/** Factory for {@link MockTokenFilter} for testing purposes. */
public class MockTokenFilterFactory extends TokenFilterFactory {
/** SPI name */
@@ -42,7 +39,8 @@ public class MockTokenFilterFactory extends TokenFilterFactory {
String stopregex = get(args, "stopregex");
if (null != stopset) {
if (null != stopregex) {
- throw new IllegalArgumentException("Parameters stopset and stopregex cannot both be specified.");
+ throw new IllegalArgumentException(
+ "Parameters stopset and stopregex cannot both be specified.");
}
if ("english".equalsIgnoreCase(stopset)) {
filter = MockTokenFilter.ENGLISH_STOPSET;
@@ -53,8 +51,8 @@ public class MockTokenFilterFactory extends TokenFilterFactory {
RegExp regex = new RegExp(stopregex);
filter = new CharacterRunAutomaton(regex.toAutomaton());
} else {
- throw new IllegalArgumentException
- ("Configuration Error: either the 'stopset' or the 'stopregex' parameter must be specified.");
+ throw new IllegalArgumentException(
+ "Configuration Error: either the 'stopset' or the 'stopregex' parameter must be specified.");
}
if (!args.isEmpty()) {
throw new IllegalArgumentException("Unknown parameters: " + args);
diff --git a/solr/test-framework/src/java/org/apache/solr/analysis/MockTokenizerFactory.java b/solr/test-framework/src/java/org/apache/solr/analysis/MockTokenizerFactory.java
index c8376abdd37..304ac825d1c 100644
--- a/solr/test-framework/src/java/org/apache/solr/analysis/MockTokenizerFactory.java
+++ b/solr/test-framework/src/java/org/apache/solr/analysis/MockTokenizerFactory.java
@@ -18,15 +18,12 @@ package org.apache.solr.analysis;
import java.util.Arrays;
import java.util.Map;
-
import org.apache.lucene.analysis.MockTokenizer;
import org.apache.lucene.analysis.TokenizerFactory;
import org.apache.lucene.util.AttributeFactory;
import org.apache.lucene.util.automaton.CharacterRunAutomaton;
-/**
- * Factory for {@link MockTokenizer} for testing purposes.
- */
+/** Factory for {@link MockTokenizer} for testing purposes. */
public class MockTokenizerFactory extends TokenizerFactory {
/** SPI name */
@@ -34,9 +31,9 @@ public class MockTokenizerFactory extends TokenizerFactory {
final CharacterRunAutomaton pattern;
final boolean enableChecks;
-
+
/** Creates a new MockTokenizerFactory */
- public MockTokenizerFactory(Map<String,String> args) {
+ public MockTokenizerFactory(Map<String, String> args) {
super(args);
String patternArg = get(args, "pattern", Arrays.asList("keyword", "simple", "whitespace"));
if ("keyword".equalsIgnoreCase(patternArg)) {
@@ -46,7 +43,7 @@ public class MockTokenizerFactory extends TokenizerFactory {
} else {
pattern = MockTokenizer.WHITESPACE;
}
-
+
enableChecks = getBoolean(args, "enableChecks", true);
if (!args.isEmpty()) {
throw new IllegalArgumentException("Unknown parameters: " + args);
@@ -64,4 +61,4 @@ public class MockTokenizerFactory extends TokenizerFactory {
t.setEnableChecks(enableChecks);
return t;
}
-}
\ No newline at end of file
+}
diff --git a/solr/test-framework/src/java/org/apache/solr/analysis/StringMockSolrResourceLoader.java b/solr/test-framework/src/java/org/apache/solr/analysis/StringMockSolrResourceLoader.java
index a28ecbcb6a6..d037a184008 100644
--- a/solr/test-framework/src/java/org/apache/solr/analysis/StringMockSolrResourceLoader.java
+++ b/solr/test-framework/src/java/org/apache/solr/analysis/StringMockSolrResourceLoader.java
@@ -20,7 +20,6 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
-
import org.apache.lucene.util.ResourceLoader;
class StringMockSolrResourceLoader implements ResourceLoader {
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.java
index d03ff562e89..86689070970 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
@@ -19,7 +19,6 @@ package org.apache.solr.cloud;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.TimeUnit;
-
import org.apache.lucene.mockfile.FilterPath;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.client.solrj.SolrClient;
@@ -41,28 +40,30 @@ import org.apache.solr.handler.ReplicationHandler;
import org.junit.Test;
/**
- * This test simply does a bunch of basic things in solrcloud mode and asserts things
- * work as expected.
+ * This test simply does a bunch of basic things in solrcloud mode and asserts things work as
+ * expected.
*/
[email protected]({"SimpleText"}) // Backups do checksum validation against a footer value not present in 'SimpleText'
+// Backups do checksum validation against a footer value not present in 'SimpleText'
[email protected]({"SimpleText"})
public abstract class AbstractBasicDistributedZk2TestBase extends AbstractFullDistribZkTestBase {
private static final String SHARD2 = "shard2";
private static final String SHARD1 = "shard1";
private static final String ONE_NODE_COLLECTION = "onenodecollection";
private final boolean onlyLeaderIndexes = random().nextBoolean();
-
public AbstractBasicDistributedZk2TestBase() {
super();
// we need DVs on point fields to compute stats & facets
- if (Boolean.getBoolean(NUMERIC_POINTS_SYSPROP)) System.setProperty(NUMERIC_DOCVALUES_SYSPROP,"true");
+ if (Boolean.getBoolean(NUMERIC_POINTS_SYSPROP))
+ System.setProperty(NUMERIC_DOCVALUES_SYSPROP, "true");
sliceCount = 2;
}
@Override
protected boolean useTlogReplicas() {
- return false; // TODO: tlog replicas makes commits take way to long due to what is likely a bug and it's TestInjection use
+ return false; // TODO: tlog replicas makes commits take way to long due to what is likely a bug
+ // and it's TestInjection use
}
@Test
@@ -75,9 +76,21 @@ public abstract class AbstractBasicDistributedZk2TestBase extends AbstractFullDi
testNodeWithoutCollectionForwarding();
- indexr(id, 1, i1, 100, tlong, 100, t1,
- "now is the time for all good men", "foo_f", 1.414f, "foo_b", "true",
- "foo_d", 1.414d);
+ indexr(
+ id,
+ 1,
+ i1,
+ 100,
+ tlong,
+ 100,
+ t1,
+ "now is the time for all good men",
+ "foo_f",
+ 1.414f,
+ "foo_b",
+ "true",
+ "foo_d",
+ 1.414d);
commit();
@@ -116,8 +129,7 @@ public abstract class AbstractBasicDistributedZk2TestBase extends AbstractFullDi
// TODO: bring this to its own method?
// try indexing to a leader that has no replicas up
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
- ZkNodeProps leaderProps = zkStateReader.getLeaderRetry(
- DEFAULT_COLLECTION, SHARD2);
+ ZkNodeProps leaderProps = zkStateReader.getLeaderRetry(DEFAULT_COLLECTION, SHARD2);
String nodeName = leaderProps.getStr(ZkStateReader.NODE_NAME_PROP);
chaosMonkey.stopShardExcept(SHARD2, nodeName);
@@ -143,18 +155,20 @@ public abstract class AbstractBasicDistributedZk2TestBase extends AbstractFullDi
printLayoutOnTearDown = true;
}
}
-
}
private void testNodeWithoutCollectionForwarding() throws Exception {
- assertEquals(0, CollectionAdminRequest
- .createCollection(ONE_NODE_COLLECTION, "conf1", 1, 1)
- .setCreateNodeSet("")
- .process(cloudClient).getStatus());
- assertTrue(CollectionAdminRequest
- .addReplicaToShard(ONE_NODE_COLLECTION, "shard1")
- .setCoreName(ONE_NODE_COLLECTION + "core")
- .process(cloudClient).isSuccess());
+ assertEquals(
+ 0,
+ CollectionAdminRequest.createCollection(ONE_NODE_COLLECTION, "conf1", 1, 1)
+ .setCreateNodeSet("")
+ .process(cloudClient)
+ .getStatus());
+ assertTrue(
+ CollectionAdminRequest.addReplicaToShard(ONE_NODE_COLLECTION, "shard1")
+ .setCoreName(ONE_NODE_COLLECTION + "core")
+ .process(cloudClient)
+ .isSuccess());
waitForCollection(cloudClient.getZkStateReader(), ONE_NODE_COLLECTION, 1);
waitForRecoveriesToFinish(ONE_NODE_COLLECTION, cloudClient.getZkStateReader(), false);
@@ -170,8 +184,7 @@ public abstract class AbstractBasicDistributedZk2TestBase extends AbstractFullDi
}
// 2 docs added every call
- private void addAndQueryDocs(final String baseUrl, int docs)
- throws Exception {
+ private void addAndQueryDocs(final String baseUrl, int docs) throws Exception {
SolrQuery query = new SolrQuery("*:*");
@@ -186,7 +199,6 @@ public abstract class AbstractBasicDistributedZk2TestBase extends AbstractFullDi
qclient.add(doc);
qclient.commit();
-
QueryResponse results = qclient.query(query);
assertEquals(docs - 1, results.getResults().getNumFound());
}
@@ -248,12 +260,17 @@ public abstract class AbstractBasicDistributedZk2TestBase extends AbstractFullDi
commit();
- long deadShardCount = shardToJetty.get(SHARD2).get(0).client.solrClient
- .query(query).getResults().getNumFound();
+ long deadShardCount =
+ shardToJetty.get(SHARD2).get(0).client.solrClient.query(query).getResults().getNumFound();
query("q", "*:*", "sort", "n_tl1 desc");
- int oldLiveNodes = cloudClient.getZkStateReader().getZkClient().getChildren(ZkStateReader.LIVE_NODES_ZKNODE, null, true).size();
+ int oldLiveNodes =
+ cloudClient
+ .getZkStateReader()
+ .getZkClient()
+ .getChildren(ZkStateReader.LIVE_NODES_ZKNODE, null, true)
+ .size();
assertEquals(5, oldLiveNodes);
@@ -261,10 +278,10 @@ public abstract class AbstractBasicDistributedZk2TestBase extends AbstractFullDi
CloudJettyRunner deadShard = chaosMonkey.stopShard(SHARD1, 0);
// ensure shard is dead
- expectThrows(SolrServerException.class,
+ expectThrows(
+ SolrServerException.class,
"This server should be down and this update should have failed",
- () -> index_specific(deadShard.client.solrClient, id, 999, i1, 107, t1, "specific doc!")
- );
+ () -> index_specific(deadShard.client.solrClient, id, 999, i1, 107, t1, "specific doc!"));
commit();
@@ -276,18 +293,29 @@ public abstract class AbstractBasicDistributedZk2TestBase extends AbstractFullDi
// try to index to a living shard at shard2
-
long numFound1 = cloudClient.query(new SolrQuery("*:*")).getResults().getNumFound();
cloudClient.getZkStateReader().getLeaderRetry(DEFAULT_COLLECTION, SHARD1, 60000);
try {
- index_specific(shardToJetty.get(SHARD1).get(1).client.solrClient, id, 1000, i1, 108, t1,
+ index_specific(
+ shardToJetty.get(SHARD1).get(1).client.solrClient,
+ id,
+ 1000,
+ i1,
+ 108,
+ t1,
"specific doc!");
} catch (Exception e) {
// wait and try again
Thread.sleep(4000);
- index_specific(shardToJetty.get(SHARD1).get(1).client.solrClient, id, 1000, i1, 108, t1,
+ index_specific(
+ shardToJetty.get(SHARD1).get(1).client.solrClient,
+ id,
+ 1000,
+ i1,
+ 108,
+ t1,
"specific doc!");
}
@@ -297,7 +325,6 @@ public abstract class AbstractBasicDistributedZk2TestBase extends AbstractFullDi
query("q", "*:*", "sort", "n_tl1 desc");
-
cloudClient.setDefaultCollection(DEFAULT_COLLECTION);
long numFound2 = cloudClient.query(new SolrQuery("*:*")).getResults().getNumFound();
@@ -316,7 +343,7 @@ public abstract class AbstractBasicDistributedZk2TestBase extends AbstractFullDi
try {
ureq.process(cloudClient);
- } catch(SolrServerException e){
+ } catch (SolrServerException e) {
// try again
Thread.sleep(3500);
ureq.process(cloudClient);
@@ -335,15 +362,13 @@ public abstract class AbstractBasicDistributedZk2TestBase extends AbstractFullDi
testDebugQueries();
if (VERBOSE) {
- System.err.println(controlClient.query(new SolrQuery("*:*")).getResults()
- .getNumFound());
+ System.err.println(controlClient.query(new SolrQuery("*:*")).getResults().getNumFound());
for (SolrClient client : clients) {
try {
SolrQuery q = new SolrQuery("*:*");
q.set("distrib", false);
- System.err.println(client.query(q).getResults()
- .getNumFound());
+ System.err.println(client.query(q).getResults().getNumFound());
} catch (Exception e) {
}
@@ -361,13 +386,12 @@ public abstract class AbstractBasicDistributedZk2TestBase extends AbstractFullDi
waitForRecoveriesToFinish(false);
- deadShardCount = shardToJetty.get(SHARD1).get(0).client.solrClient
- .query(query).getResults().getNumFound();
+ deadShardCount =
+ shardToJetty.get(SHARD1).get(0).client.solrClient.query(query).getResults().getNumFound();
// if we properly recovered, we should now have the couple missing docs that
// came in while shard was down
checkShardConsistency(true, false);
-
// recover over 100 docs so we do more than just peer sync (replicate recovery)
chaosMonkey.stopJetty(deadShard);
@@ -398,7 +422,8 @@ public abstract class AbstractBasicDistributedZk2TestBase extends AbstractFullDi
checkShardConsistency(true, false);
// try a backup command
- try(final HttpSolrClient client = getHttpSolrClient((String) shardToJetty.get(SHARD2).get(0).info.get("base_url"))) {
+ try (final HttpSolrClient client =
+ getHttpSolrClient((String) shardToJetty.get(SHARD2).get(0).info.get("base_url"))) {
final String backupName = "the_backup";
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("qt", ReplicationHandler.PATH);
@@ -412,14 +437,13 @@ public abstract class AbstractBasicDistributedZk2TestBase extends AbstractFullDi
QueryRequest request = new QueryRequest(params);
client.request(request, DEFAULT_TEST_COLLECTION_NAME);
-
- final BackupStatusChecker backupStatus
- = new BackupStatusChecker(client, "/" + DEFAULT_TEST_COLLECTION_NAME + "/replication");
+ final BackupStatusChecker backupStatus =
+ new BackupStatusChecker(client, "/" + DEFAULT_TEST_COLLECTION_NAME + "/replication");
final String backupDirName = backupStatus.waitForBackupSuccess(backupName, 30);
- assertTrue("Backup dir does not exist: " + backupDirName,
+ assertTrue(
+ "Backup dir does not exist: " + backupDirName,
Files.exists(location.resolve(backupDirName)));
}
-
}
private void addNewReplica() throws Exception {
@@ -429,12 +453,16 @@ public abstract class AbstractBasicDistributedZk2TestBase extends AbstractFullDi
// new server should be part of first shard
// how many docs are on the new shard?
for (CloudJettyRunner cjetty : shardToJetty.get(SHARD1)) {
- if (VERBOSE) System.err.println("shard1 total:"
- + cjetty.client.solrClient.query(new SolrQuery("*:*")).getResults().getNumFound());
+ if (VERBOSE)
+ System.err.println(
+ "shard1 total:"
+ + cjetty.client.solrClient.query(new SolrQuery("*:*")).getResults().getNumFound());
}
for (CloudJettyRunner cjetty : shardToJetty.get(SHARD2)) {
- if (VERBOSE) System.err.println("shard2 total:"
- + cjetty.client.solrClient.query(new SolrQuery("*:*")).getResults().getNumFound());
+ if (VERBOSE)
+ System.err.println(
+ "shard2 total:"
+ + cjetty.client.solrClient.query(new SolrQuery("*:*")).getResults().getNumFound());
}
checkShardConsistency(SHARD1);
@@ -448,12 +476,10 @@ public abstract class AbstractBasicDistributedZk2TestBase extends AbstractFullDi
handle.put("debug", UNORDERED);
handle.put("time", SKIPVAL);
handle.put("track", SKIP);
- query("q", "now their fox sat had put", "fl", "*,score",
- CommonParams.DEBUG_QUERY, "true");
+ query("q", "now their fox sat had put", "fl", "*,score", CommonParams.DEBUG_QUERY, "true");
query("q", "id_i1:[1 TO 5]", CommonParams.DEBUG_QUERY, "true");
query("q", "id_i1:[1 TO 5]", CommonParams.DEBUG, CommonParams.TIMING);
query("q", "id_i1:[1 TO 5]", CommonParams.DEBUG, CommonParams.RESULTS);
query("q", "id_i1:[1 TO 5]", CommonParams.DEBUG, CommonParams.QUERY);
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractBasicDistributedZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractBasicDistributedZkTestBase.java
index 4b71235197f..2d8ca5d5677 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractBasicDistributedZkTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractBasicDistributedZkTestBase.java
@@ -38,7 +38,6 @@ import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
-
import org.apache.lucene.util.IOUtils;
import org.apache.solr.JSONTestUtil;
import org.apache.solr.client.solrj.SolrClient;
@@ -86,10 +85,9 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
/**
- * This test simply does a bunch of basic things in solrcloud mode and asserts things
- * work as expected.
+ * This test simply does a bunch of basic things in solrcloud mode and asserts things work as
+ * expected.
*/
public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDistribZkTestBase {
@@ -99,15 +97,15 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
private final boolean onlyLeaderIndexes = random().nextBoolean();
- String t1="a_t";
- String i1="a_i1";
+ String t1 = "a_t";
+ String i1 = "a_i1";
String tlong = "other_tl1";
- String tsort="t_sortable";
+ String tsort = "t_sortable";
- String oddField="oddField_s";
- String missingField="ignore_exception__missing_but_valid_field_t";
+ String oddField = "oddField_s";
+ String missingField = "ignore_exception__missing_but_valid_field_t";
- private Map<String,List<SolrClient>> otherCollectionClients = new HashMap<>();
+ private Map<String, List<SolrClient>> otherCollectionClients = new HashMap<>();
private String oneInstanceCollection = "oneInstanceCollection";
private String oneInstanceCollection2 = "oneInstanceCollection2";
@@ -117,42 +115,44 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
CompletionService<Object> completionService;
Set<Future<Object>> pending;
- private static Hook newSearcherHook = new Hook() {
- volatile CountDownLatch latch;
- AtomicReference<String> collection = new AtomicReference<>();
+ private static Hook newSearcherHook =
+ new Hook() {
+ volatile CountDownLatch latch;
+ AtomicReference<String> collection = new AtomicReference<>();
- @Override
- public void newSearcher(String collectionName) {
- String c = collection.get();
- if (c != null && c.equals(collectionName)) {
- log.info("Hook detected newSearcher");
- try {
- latch.countDown();
- } catch (NullPointerException e) {
+ @Override
+ public void newSearcher(String collectionName) {
+ String c = collection.get();
+ if (c != null && c.equals(collectionName)) {
+ log.info("Hook detected newSearcher");
+ try {
+ latch.countDown();
+ } catch (NullPointerException e) {
+ }
+ }
}
- }
- }
-
- public void waitForSearcher(String collection, int cnt, int timeoutms, boolean failOnTimeout) throws InterruptedException {
- latch = new CountDownLatch(cnt);
- this.collection.set(collection);
- boolean timeout = !latch.await(timeoutms, TimeUnit.MILLISECONDS);
- if (timeout && failOnTimeout) {
- fail("timed out waiting for new searcher event " + latch.getCount());
- }
- }
- };
+ public void waitForSearcher(
+ String collection, int cnt, int timeoutms, boolean failOnTimeout)
+ throws InterruptedException {
+ latch = new CountDownLatch(cnt);
+ this.collection.set(collection);
+ boolean timeout = !latch.await(timeoutms, TimeUnit.MILLISECONDS);
+ if (timeout && failOnTimeout) {
+ fail("timed out waiting for new searcher event " + latch.getCount());
+ }
+ }
+ };
public AbstractBasicDistributedZkTestBase() {
// we need DVs on point fields to compute stats & facets
- if (Boolean.getBoolean(NUMERIC_POINTS_SYSPROP)) System.setProperty(NUMERIC_DOCVALUES_SYSPROP,"true");
+ if (Boolean.getBoolean(NUMERIC_POINTS_SYSPROP))
+ System.setProperty(NUMERIC_DOCVALUES_SYSPROP, "true");
sliceCount = 2;
completionService = new ExecutorCompletionService<>(executor);
pending = new HashSet<>();
-
}
@BeforeClass
@@ -162,7 +162,9 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
@Override
protected boolean useTlogReplicas() {
- return false; // TODO: tlog replicas makes commits take way to long due to what is likely a bug and it's TestInjection use
+ // TODO: tlog replicas makes commits take way to long due to what is likely a bug and it's
+ // TestInjection use
+ return false;
}
@Override
@@ -174,8 +176,7 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
// use shard ids rather than physical locations
StringBuilder sb = new StringBuilder();
for (int i = 0; i < getShardCount(); i++) {
- if (i > 0)
- sb.append(',');
+ if (i > 0) sb.append(',');
sb.append("shard" + (i + 3));
}
params.set("shards", sb.toString());
@@ -184,7 +185,6 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
@Test
@ShardsFixed(num = 4)
- // commented out on: 17-Feb-2019 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // annotated on: 24-Dec-2018
protected void test() throws Exception {
// setLoggingLevel(null);
@@ -192,7 +192,7 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
// make sure we have leaders for each shard
for (int j = 1; j < sliceCount; j++) {
zkStateReader.getLeaderRetry(DEFAULT_COLLECTION, "shard" + j, 10000);
- } // make sure we again have leaders for each shard
+ } // make sure we again have leaders for each shard
waitForRecoveriesToFinish(false);
@@ -207,46 +207,165 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
int foo_i_counter = 0;
for (SolrClient client : clients) {
foo_i_counter++;
- indexDoc(client, params("commit", "true"), // SOLR-4923
- sdoc(id,1, i1,100, tlong,100, "foo_i", foo_i_counter));
+ indexDoc(
+ client,
+ params("commit", "true"), // SOLR-4923
+ sdoc(id, 1, i1, 100, tlong, 100, "foo_i", foo_i_counter));
// after every update+commit, check all the shards consistency
- queryAndCompareShards(params("q", "id:1", "distrib", "false",
- "sanity_check", "non_distrib_id_1_lookup"));
- queryAndCompareShards(params("q", "id:1",
- "sanity_check", "distrib_id_1_lookup"));
+ queryAndCompareShards(
+ params("q", "id:1", "distrib", "false", "sanity_check", "non_distrib_id_1_lookup"));
+ queryAndCompareShards(
+ params(
+ "q", "id:1",
+ "sanity_check", "distrib_id_1_lookup"));
}
- indexr(id,1, i1, 100, tlong, 100,t1,"now is the time for all good men"
- ,"foo_f", 1.414f, "foo_b", "true", "foo_d", 1.414d, tsort, "now is the time for all good men");
- indexr(id, 2, i1, 50, tlong, 50, t1, "to come to the aid of their country."
- , tsort, "to come to the aid of their country.");
+ indexr(
+ id,
+ 1,
+ i1,
+ 100,
+ tlong,
+ 100,
+ t1,
+ "now is the time for all good men",
+ "foo_f",
+ 1.414f,
+ "foo_b",
+ "true",
+ "foo_d",
+ 1.414d,
+ tsort,
+ "now is the time for all good men");
+ indexr(
+ id,
+ 2,
+ i1,
+ 50,
+ tlong,
+ 50,
+ t1,
+ "to come to the aid of their country.",
+ tsort,
+ "to come to the aid of their country.");
indexr(id, 3, i1, 2, tlong, 2, t1, "how now brown cow", tsort, "how now brown cow");
- indexr(id, 4, i1, -100, tlong, 101, t1, "the quick fox jumped over the lazy dog"
- , tsort, "the quick fox jumped over the lazy dog");
- indexr(id, 5, i1, 500, tlong, 500, t1, "the quick fox jumped way over the lazy dog"
- , tsort, "the quick fox jumped over the lazy dog");
- indexr(id, 6, i1, -600, tlong, 600, t1, "humpty dumpy sat on a wall", tsort, "the quick fox jumped over the lazy dog");
- indexr(id, 7, i1, 123, tlong, 123, t1, "humpty dumpy had a great fall", tsort, "the quick fox jumped over the lazy dog");
- indexr(id,8, i1, 876, tlong, 876,t1,"all the kings horses and all the kings men",tsort,"all the kings horses and all the kings men");
- indexr(id, 9, i1, 7, tlong, 7, t1, "couldn't put humpty together again", tsort, "the quick fox jumped over the lazy dog");
- indexr(id,10, i1, 4321, tlong, 4321,t1,"this too shall pass",tsort,"this too shall pass");
- indexr(id,11, i1, -987, tlong, 987,t1,"An eye for eye only ends up making the whole world blind."
- ,tsort,"An eye for eye only ends up making the whole world blind.");
- indexr(id,12, i1, 379, tlong, 379,t1,"Great works are performed, not by strength, but by perseverance.",
- tsort,"Great works are performed, not by strength, but by perseverance.");
- indexr(id,13, i1, 232, tlong, 232,t1,"no eggs on wall, lesson learned", oddField, "odd man out",
- tsort,"no eggs on wall, lesson learned");
-
- indexr(id, 14, "SubjectTerms_mfacet", new String[] {"mathematical models", "mathematical analysis"});
- indexr(id, 15, "SubjectTerms_mfacet", new String[] {"test 1", "test 2", "test3"});
- indexr(id, 16, "SubjectTerms_mfacet", new String[] {"test 1", "test 2", "test3"});
+ indexr(
+ id,
+ 4,
+ i1,
+ -100,
+ tlong,
+ 101,
+ t1,
+ "the quick fox jumped over the lazy dog",
+ tsort,
+ "the quick fox jumped over the lazy dog");
+ indexr(
+ id,
+ 5,
+ i1,
+ 500,
+ tlong,
+ 500,
+ t1,
+ "the quick fox jumped way over the lazy dog",
+ tsort,
+ "the quick fox jumped over the lazy dog");
+ indexr(
+ id,
+ 6,
+ i1,
+ -600,
+ tlong,
+ 600,
+ t1,
+ "humpty dumpy sat on a wall",
+ tsort,
+ "the quick fox jumped over the lazy dog");
+ indexr(
+ id,
+ 7,
+ i1,
+ 123,
+ tlong,
+ 123,
+ t1,
+ "humpty dumpy had a great fall",
+ tsort,
+ "the quick fox jumped over the lazy dog");
+ indexr(
+ id,
+ 8,
+ i1,
+ 876,
+ tlong,
+ 876,
+ t1,
+ "all the kings horses and all the kings men",
+ tsort,
+ "all the kings horses and all the kings men");
+ indexr(
+ id,
+ 9,
+ i1,
+ 7,
+ tlong,
+ 7,
+ t1,
+ "couldn't put humpty together again",
+ tsort,
+ "the quick fox jumped over the lazy dog");
+ indexr(id, 10, i1, 4321, tlong, 4321, t1, "this too shall pass", tsort, "this too shall pass");
+ indexr(
+ id,
+ 11,
+ i1,
+ -987,
+ tlong,
+ 987,
+ t1,
+ "An eye for eye only ends up making the whole world blind.",
+ tsort,
+ "An eye for eye only ends up making the whole world blind.");
+ indexr(
+ id,
+ 12,
+ i1,
+ 379,
+ tlong,
+ 379,
+ t1,
+ "Great works are performed, not by strength, but by perseverance.",
+ tsort,
+ "Great works are performed, not by strength, but by perseverance.");
+ indexr(
+ id,
+ 13,
+ i1,
+ 232,
+ tlong,
+ 232,
+ t1,
+ "no eggs on wall, lesson learned",
+ oddField,
+ "odd man out",
+ tsort,
+ "no eggs on wall, lesson learned");
+
+ indexr(
+ id,
+ 14,
+ "SubjectTerms_mfacet",
+ new String[] {"mathematical models", "mathematical analysis"});
+ indexr(id, 15, "SubjectTerms_mfacet", new String[] {"test 1", "test 2", "test3"});
+ indexr(id, 16, "SubjectTerms_mfacet", new String[] {"test 1", "test 2", "test3"});
String[] vals = new String[100];
- for (int i=0; i<100; i++) {
+ for (int i = 0; i < 100; i++) {
vals[i] = "test " + i;
}
indexr(id, 17, "SubjectTerms_mfacet", vals);
- for (int i=100; i<150; i++) {
+ for (int i = 100; i < 150; i++) {
indexr(id, i);
}
@@ -257,113 +376,311 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
testSortableTextSorting();
testSortableTextGrouping();
- queryAndCompareShards(params("q", "*:*",
- "sort", "id desc",
- "distrib", "false",
- "sanity_check", "is_empty"));
+ queryAndCompareShards(
+ params(
+ "q", "*:*",
+ "sort", "id desc",
+ "distrib", "false",
+ "sanity_check", "is_empty"));
// random value sort
for (String f : fieldNames) {
- query(false, new String[] {"q","*:*", "sort",f+" desc"});
- query(false, new String[] {"q","*:*", "sort",f+" asc"});
+ query(false, new String[] {"q", "*:*", "sort", f + " desc"});
+ query(false, new String[] {"q", "*:*", "sort", f + " asc"});
}
// these queries should be exactly ordered and scores should exactly match
- query(false, new String[] {"q","*:*", "sort",i1+" desc"});
- query(false, new String[] {"q","*:*", "sort",i1+" asc"});
- query(false, new String[] {"q","*:*", "sort",i1+" desc", "fl","*,score"});
- query(false, new String[] {"q","*:*", "sort","n_tl1 asc", "fl","*,score"});
- query(false, new String[] {"q","*:*", "sort","n_tl1 desc"});
+ query(false, new String[] {"q", "*:*", "sort", i1 + " desc"});
+ query(false, new String[] {"q", "*:*", "sort", i1 + " asc"});
+ query(false, new String[] {"q", "*:*", "sort", i1 + " desc", "fl", "*,score"});
+ query(false, new String[] {"q", "*:*", "sort", "n_tl1 asc", "fl", "*,score"});
+ query(false, new String[] {"q", "*:*", "sort", "n_tl1 desc"});
handle.put("maxScore", SKIPVAL);
- query(false, new String[] {"q","{!func}"+i1});// does not expect maxScore. So if it comes ,ignore it. JavaBinCodec.writeSolrDocumentList()
- //is agnostic of request params.
+ query(
+ false,
+ new String[] {"q", "{!func}" + i1}); // does not expect maxScore. So if it comes ,ignore it.
+ // JavaBinCodec.writeSolrDocumentList()
+ // is agnostic of request params.
handle.remove("maxScore");
- query(false, new String[] {"q","{!func}"+i1, "fl","*,score"}); // even scores should match exactly here
+ query(
+ false,
+ new String[] {
+ "q", "{!func}" + i1, "fl", "*,score"
+ }); // even scores should match exactly here
handle.put("highlighting", UNORDERED);
handle.put("response", UNORDERED);
handle.put("maxScore", SKIPVAL);
- query(false, new String[] {"q","quick"});
- query(false, new String[] {"q","all","fl","id","start","0"});
- query(false, new String[] {"q","all","fl","foofoofoo","start","0"}); // no fields in returned docs
- query(false, new String[] {"q","all","fl","id","start","100"});
+ query(false, new String[] {"q", "quick"});
+ query(false, new String[] {"q", "all", "fl", "id", "start", "0"});
+ query(
+ false,
+ new String[] {"q", "all", "fl", "foofoofoo", "start", "0"}); // no fields in returned docs
+ query(false, new String[] {"q", "all", "fl", "id", "start", "100"});
handle.put("score", SKIPVAL);
- query(false, new String[] {"q","quick","fl","*,score"});
- query(false, new String[] {"q","all","fl","*,score","start","1"});
- query(false, new String[] {"q","all","fl","*,score","start","100"});
-
- query(false, new String[] {"q","now their fox sat had put","fl","*,score",
- "hl","true","hl.fl",t1});
-
- query(false, new String[] {"q","now their fox sat had put","fl","foofoofoo",
- "hl","true","hl.fl",t1});
+ query(false, new String[] {"q", "quick", "fl", "*,score"});
+ query(false, new String[] {"q", "all", "fl", "*,score", "start", "1"});
+ query(false, new String[] {"q", "all", "fl", "*,score", "start", "100"});
+
+ query(
+ false,
+ new String[] {
+ "q", "now their fox sat had put", "fl", "*,score", "hl", "true", "hl.fl", t1
+ });
- query(false, new String[] {"q","matchesnothing","fl","*,score"});
+ query(
+ false,
+ new String[] {
+ "q", "now their fox sat had put", "fl", "foofoofoo", "hl", "true", "hl.fl", t1
+ });
- query(false, new Object[] {"q","*:*", "rows",100, "facet","true", "facet.field",t1});
- query(false, new Object[] {"q","*:*", "rows",100, "facet","true", "facet.field",t1, "facet.limit",-1, "facet.sort","count"});
- query(false, new Object[] {"q","*:*", "rows",100, "facet","true", "facet.field",t1, "facet.limit",-1, "facet.sort","count", "facet.mincount",2});
- query(false, new Object[] {"q","*:*", "rows",100, "facet","true", "facet.field",t1, "facet.limit",-1, "facet.sort","index"});
- query(false, new Object[] {"q","*:*", "rows",100, "facet","true", "facet.field",t1, "facet.limit",-1, "facet.sort","index", "facet.mincount",2});
- query(false, new Object[] {"q","*:*", "rows",100, "facet","true", "facet.field",t1,"facet.limit",1});
- query(false, new Object[] {"q","*:*", "rows",100, "facet","true", "facet.query","quick", "facet.query","all", "facet.query","*:*"});
- query(false, new Object[] {"q","*:*", "rows",100, "facet","true", "facet.field",t1, "facet.offset",1});
- query(false, new Object[] {"q","*:*", "rows",100, "facet","true", "facet.field",t1, "facet.mincount",2});
+ query(false, new String[] {"q", "matchesnothing", "fl", "*,score"});
+
+ query(false, new Object[] {"q", "*:*", "rows", 100, "facet", "true", "facet.field", t1});
+ query(
+ false,
+ new Object[] {
+ "q",
+ "*:*",
+ "rows",
+ 100,
+ "facet",
+ "true",
+ "facet.field",
+ t1,
+ "facet.limit",
+ -1,
+ "facet.sort",
+ "count"
+ });
+ query(
+ false,
+ new Object[] {
+ "q",
+ "*:*",
+ "rows",
+ 100,
+ "facet",
+ "true",
+ "facet.field",
+ t1,
+ "facet.limit",
+ -1,
+ "facet.sort",
+ "count",
+ "facet.mincount",
+ 2
+ });
+ query(
+ false,
+ new Object[] {
+ "q",
+ "*:*",
+ "rows",
+ 100,
+ "facet",
+ "true",
+ "facet.field",
+ t1,
+ "facet.limit",
+ -1,
+ "facet.sort",
+ "index"
+ });
+ query(
+ false,
+ new Object[] {
+ "q",
+ "*:*",
+ "rows",
+ 100,
+ "facet",
+ "true",
+ "facet.field",
+ t1,
+ "facet.limit",
+ -1,
+ "facet.sort",
+ "index",
+ "facet.mincount",
+ 2
+ });
+ query(
+ false,
+ new Object[] {
+ "q", "*:*", "rows", 100, "facet", "true", "facet.field", t1, "facet.limit", 1
+ });
+ query(
+ false,
+ new Object[] {
+ "q",
+ "*:*",
+ "rows",
+ 100,
+ "facet",
+ "true",
+ "facet.query",
+ "quick",
+ "facet.query",
+ "all",
+ "facet.query",
+ "*:*"
+ });
+ query(
+ false,
+ new Object[] {
+ "q", "*:*", "rows", 100, "facet", "true", "facet.field", t1, "facet.offset", 1
+ });
+ query(
+ false,
+ new Object[] {
+ "q", "*:*", "rows", 100, "facet", "true", "facet.field", t1, "facet.mincount", 2
+ });
// test faceting multiple things at once
- query(false, new Object[] {"q","*:*", "rows",100, "facet","true", "facet.query","quick", "facet.query","all", "facet.query","*:*"
- ,"facet.field",t1});
+ query(
+ false,
+ new Object[] {
+ "q",
+ "*:*",
+ "rows",
+ 100,
+ "facet",
+ "true",
+ "facet.query",
+ "quick",
+ "facet.query",
+ "all",
+ "facet.query",
+ "*:*",
+ "facet.field",
+ t1
+ });
// test filter tagging, facet exclusion, and naming (multi-select facet support)
- query(false, new Object[] {"q","*:*", "rows",100, "facet","true", "facet.query","{!key=myquick}quick", "facet.query","{!key=myall ex=a}all", "facet.query","*:*"
- ,"facet.field","{!key=mykey ex=a}"+t1
- ,"facet.field","{!key=other ex=b}"+t1
- ,"facet.field","{!key=again ex=a,b}"+t1
- ,"facet.field",t1
- ,"fq","{!tag=a}id_i1:[1 TO 7]", "fq","{!tag=b}id_i1:[3 TO 9]"}
- );
- query(false, new Object[] {"q", "*:*", "facet", "true", "facet.field", "{!ex=t1}SubjectTerms_mfacet", "fq", "{!tag=t1}SubjectTerms_mfacet:(test 1)", "facet.limit", "10", "facet.mincount", "1"});
+ query(
+ false,
+ new Object[] {
+ "q",
+ "*:*",
+ "rows",
+ 100,
+ "facet",
+ "true",
+ "facet.query",
+ "{!key=myquick}quick",
+ "facet.query",
+ "{!key=myall ex=a}all",
+ "facet.query",
+ "*:*",
+ "facet.field",
+ "{!key=mykey ex=a}" + t1,
+ "facet.field",
+ "{!key=other ex=b}" + t1,
+ "facet.field",
+ "{!key=again ex=a,b}" + t1,
+ "facet.field",
+ t1,
+ "fq",
+ "{!tag=a}id_i1:[1 TO 7]",
+ "fq",
+ "{!tag=b}id_i1:[3 TO 9]"
+ });
+ query(
+ false,
+ new Object[] {
+ "q",
+ "*:*",
+ "facet",
+ "true",
+ "facet.field",
+ "{!ex=t1}SubjectTerms_mfacet",
+ "fq",
+ "{!tag=t1}SubjectTerms_mfacet:(test 1)",
+ "facet.limit",
+ "10",
+ "facet.mincount",
+ "1"
+ });
// test field that is valid in schema but missing in all shards
- query(false, new Object[] {"q","*:*", "rows",100, "facet","true", "facet.field",missingField, "facet.mincount",2});
+ query(
+ false,
+ new Object[] {
+ "q", "*:*", "rows", 100, "facet", "true", "facet.field", missingField, "facet.mincount", 2
+ });
// test field that is valid in schema and missing in some shards
- query(false, new Object[] {"q","*:*", "rows",100, "facet","true", "facet.field",oddField, "facet.mincount",2});
+ query(
+ false,
+ new Object[] {
+ "q", "*:*", "rows", 100, "facet", "true", "facet.field", oddField, "facet.mincount", 2
+ });
- query(false, new Object[] {"q","*:*", "sort",i1+" desc", "stats", "true", "stats.field", i1});
+ query(
+ false, new Object[] {"q", "*:*", "sort", i1 + " desc", "stats", "true", "stats.field", i1});
/*** TODO: the failure may come back in "exception"
- try {
- // test error produced for field that is invalid for schema
- query("q","*:*", "rows",100, "facet","true", "facet.field",invalidField, "facet.mincount",2);
- TestCase.fail("SolrServerException expected for invalid field that is not in schema");
- } catch (SolrServerException ex) {
- // expected
- }
- ***/
+ * try {
+ * // test error produced for field that is invalid for schema
+ * query("q","*:*", "rows",100, "facet","true", "facet.field",invalidField, "facet.mincount",2);
+ * TestCase.fail("SolrServerException expected for invalid field that is not in schema");
+ * } catch (SolrServerException ex) {
+ * // expected
+ * }
+ ***/
// Try to get better coverage for refinement queries by turning off over requesting.
// This makes it much more likely that we may not get the top facet values and hence
// we turn of that checking.
handle.put("facet_fields", SKIPVAL);
- query(false, new Object[] {"q","*:*", "rows",0, "facet","true", "facet.field",t1,"facet.limit",5, "facet.shard.limit",5});
+ query(
+ false,
+ new Object[] {
+ "q",
+ "*:*",
+ "rows",
+ 0,
+ "facet",
+ "true",
+ "facet.field",
+ t1,
+ "facet.limit",
+ 5,
+ "facet.shard.limit",
+ 5
+ });
// check a complex key name
- query(false, new Object[] {"q","*:*", "rows",0, "facet","true", "facet.field","{!key='a b/c \\' \\} foo'}"+t1,"facet.limit",5, "facet.shard.limit",5});
+ query(
+ false,
+ new Object[] {
+ "q",
+ "*:*",
+ "rows",
+ 0,
+ "facet",
+ "true",
+ "facet.field",
+ "{!key='a b/c \\' \\} foo'}" + t1,
+ "facet.limit",
+ 5,
+ "facet.shard.limit",
+ 5
+ });
handle.remove("facet_fields");
-
// index the same document to two servers and make sure things
// don't blow up.
- if (clients.size()>=2) {
- index(id,100, i1, 107 ,t1,"oh no, a duplicate!");
- for (int i=0; i<clients.size(); i++) {
- index_specific(i, id,100, i1, 107 ,t1,"oh no, a duplicate!");
+ if (clients.size() >= 2) {
+ index(id, 100, i1, 107, t1, "oh no, a duplicate!");
+ for (int i = 0; i < clients.size(); i++) {
+ index_specific(i, id, 100, i1, 107, t1, "oh no, a duplicate!");
}
commit();
- query(false, new Object[] {"q","duplicate", "hl","true", "hl.fl", t1});
- query(false, new Object[] {"q","fox duplicate horses", "hl","true", "hl.fl", t1});
- query(false, new Object[] {"q","*:*", "rows",100});
+ query(false, new Object[] {"q", "duplicate", "hl", "true", "hl.fl", t1});
+ query(false, new Object[] {"q", "fox duplicate horses", "hl", "true", "hl.fl", t1});
+ query(false, new Object[] {"q", "*:*", "rows", 100});
}
// test debugging
@@ -371,7 +688,11 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
handle.put("debug", UNORDERED);
handle.put("time", SKIPVAL);
handle.put("track", SKIP);
- query(false, new Object[] {"q","now their fox sat had put","fl","*,score",CommonParams.DEBUG_QUERY, "true"});
+ query(
+ false,
+ new Object[] {
+ "q", "now their fox sat had put", "fl", "*,score", CommonParams.DEBUG_QUERY, "true"
+ });
query(false, new Object[] {"q", "id_i1:[1 TO 5]", CommonParams.DEBUG_QUERY, "true"});
query(false, new Object[] {"q", "id_i1:[1 TO 5]", CommonParams.DEBUG, CommonParams.TIMING});
query(false, new Object[] {"q", "id_i1:[1 TO 5]", CommonParams.DEBUG, CommonParams.RESULTS});
@@ -380,12 +701,16 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
// try add commitWithin
long before = cloudClient.query(new SolrQuery("*:*")).getResults().getNumFound();
for (SolrClient client : clients) {
- assertEquals("unexpected pre-commitWithin document count on node: " + ((HttpSolrClient)client).getBaseURL(), before, client.query(new SolrQuery("*:*")).getResults().getNumFound());
+ assertEquals(
+ "unexpected pre-commitWithin document count on node: "
+ + ((HttpSolrClient) client).getBaseURL(),
+ before,
+ client.query(new SolrQuery("*:*")).getResults().getNumFound());
}
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("commitWithin", 10);
- add(cloudClient, params , getDoc("id", 300), getDoc("id", 301));
+ add(cloudClient, params, getDoc("id", 300), getDoc("id", 301));
newSearcherHook.waitForSearcher(DEFAULT_COLLECTION, 2, 20000, false);
@@ -414,7 +739,6 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
assertSliceCounts("deleteByQuery commitWithin did not work", before, dColl);
-
// TODO: This test currently fails because debug info is obtained only
// on shards with matches.
// query("q","matchesnothing","fl","*,score", "debugQuery", "true");
@@ -462,7 +786,6 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
break;
default:
fail("No case for facet '" + ff.getName() + "'");
-
}
}
}
@@ -480,7 +803,9 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
String title = docs.get(0).getFieldValue(tsort).toString();
for (SolrDocument doc : docs) {
- assertTrue("Docs should be back in sorted order, descending", title.compareTo(doc.getFieldValue(tsort).toString()) >= 0);
+ assertTrue(
+ "Docs should be back in sorted order, descending",
+ title.compareTo(doc.getFieldValue(tsort).toString()) >= 0);
title = doc.getFieldValue(tsort).toString();
}
}
@@ -496,7 +821,8 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
if (grpCmd.getName().equals(tsort) == false) continue;
for (Group grp : grpCmd.getValues()) {
long count = grp.getResult().getNumFound();
- if (grp.getGroupValue() == null) continue; // Don't count the groups without an entry as the numnber is variable
+ if (grp.getGroupValue() == null)
+ continue; // Don't count the groups without an entry as the numnber is variable
switch (grp.getGroupValue()) {
case "all the kings horses and all the kings men":
case "An eye for eye only ends up making the whole world blind.":
@@ -506,24 +832,31 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
case "now is the time for all good men":
case "this too shall pass":
case "to come to the aid of their country.":
- assertEquals("Should have exactly one facet count for field " + grpCmd.getName(), 1, count);
+ assertEquals(
+ "Should have exactly one facet count for field " + grpCmd.getName(), 1, count);
break;
case "the quick fox jumped over the lazy dog":
assertEquals("Should have 5 docs for the lazy dog", 5, count);
break;
default:
fail("No case for facet '" + grpCmd.getName() + "'");
-
}
}
}
}
private void testTokenizedGrouping() throws Exception {
- SolrException ex = expectThrows(SolrException.class, () -> {
- query(false, new String[]{"q", "*:*", "group", "true", "group.field", t1});
- });
- assertTrue("Expected error from server that SortableTextFields are required", ex.getMessage().contains("Sorting on a tokenized field that is not a SortableTextField is not supported in cloud mode"));
+ SolrException ex =
+ expectThrows(
+ SolrException.class,
+ () -> {
+ query(false, new String[] {"q", "*:*", "group", "true", "group.field", t1});
+ });
+ assertTrue(
+ "Expected error from server that SortableTextFields are required",
+ ex.getMessage()
+ .contains(
+ "Sorting on a tokenized field that is not a SortableTextField is not supported in cloud mode"));
}
private void assertSliceCounts(String msg, long expected, DocCollection dColl) throws Exception {
@@ -543,19 +876,25 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
throws Exception {
AtomicLong total = new AtomicLong(-1);
try {
- getCommonCloudSolrClient().getZkStateReader().waitForState(DEFAULT_COLLECTION, waitMillis, TimeUnit.MILLISECONDS, (n, c) -> {
- long docTotal;
- try {
- docTotal = checkSlicesSameCounts(c);
- } catch (SolrServerException | IOException e) {
- throw new RuntimeException(e);
- }
- total.set(docTotal);
- if (docTotal == expectedNumFound) {
- return true;
- }
- return false;
- });
+ getCommonCloudSolrClient()
+ .getZkStateReader()
+ .waitForState(
+ DEFAULT_COLLECTION,
+ waitMillis,
+ TimeUnit.MILLISECONDS,
+ (n, c) -> {
+ long docTotal;
+ try {
+ docTotal = checkSlicesSameCounts(c);
+ } catch (SolrServerException | IOException e) {
+ throw new RuntimeException(e);
+ }
+ total.set(docTotal);
+ if (docTotal == expectedNumFound) {
+ return true;
+ }
+ return false;
+ });
} catch (TimeoutException | InterruptedException e) {
}
@@ -564,7 +903,10 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
// This should be redundant, but it caught a test error after all.
for (SolrClient client : clients) {
- assertEquals(failureMessage, expectedNumFound, client.query(new SolrQuery("*:*")).getResults().getNumFound());
+ assertEquals(
+ failureMessage,
+ expectedNumFound,
+ client.query(new SolrQuery("*:*")).getResults().getNumFound());
}
}
@@ -596,7 +938,7 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
private void testShardParamVariations() throws Exception {
SolrQuery query = new SolrQuery("*:*");
- Map<String,Long> shardCounts = new HashMap<>();
+ Map<String, Long> shardCounts = new HashMap<>();
for (String shard : shardToJetty.keySet()) {
// every client should give the same numDocs for this shard
@@ -606,16 +948,16 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
for (SolrClient client : solrclients) {
query.set("shards", shard);
long numDocs = client.query(query).getResults().getNumFound();
- assertTrue("numDocs < 0 for shard "+shard+" via "+client,
- 0 <= numDocs);
+ assertTrue("numDocs < 0 for shard " + shard + " via " + client, 0 <= numDocs);
if (!shardCounts.containsKey(shard)) {
shardCounts.put(shard, numDocs);
}
- assertEquals("inconsitent numDocs for shard "+shard+" via "+client,
- shardCounts.get(shard).longValue(), numDocs);
+ assertEquals(
+ "inconsitent numDocs for shard " + shard + " via " + client,
+ shardCounts.get(shard).longValue(),
+ numDocs);
- List<CloudJettyRunner> replicaJetties
- = new ArrayList<>(shardToJetty.get(shard));
+ List<CloudJettyRunner> replicaJetties = new ArrayList<>(shardToJetty.get(shard));
Collections.shuffle(replicaJetties, random());
// each replica should also give the same numDocs
@@ -630,22 +972,27 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
}
numDocs = client.query(query).getResults().getNumFound();
- assertTrue("numDocs < 0 for replica "+replica+" via "+client,
- 0 <= numDocs);
- assertEquals("inconsitent numDocs for shard "+shard+
- " in replica "+replica+" via "+client,
- shardCounts.get(shard).longValue(), numDocs);
+ assertTrue("numDocs < 0 for replica " + replica + " via " + client, 0 <= numDocs);
+ assertEquals(
+ "inconsitent numDocs for shard "
+ + shard
+ + " in replica "
+ + replica
+ + " via "
+ + client,
+ shardCounts.get(shard).longValue(),
+ numDocs);
}
// any combination of replica alternatives should give same numDocs
String replicas = String.join("|", replicaAlts);
query.set("shards", replicas);
numDocs = client.query(query).getResults().getNumFound();
- assertTrue("numDocs < 0 for replicas "+replicas+" via "+client,
- 0 <= numDocs);
- assertEquals("inconsitent numDocs for replicas "+replicas+
- " via "+client,
- shardCounts.get(shard).longValue(), numDocs);
+ assertTrue("numDocs < 0 for replicas " + replicas + " via " + client, 0 <= numDocs);
+ assertEquals(
+ "inconsitent numDocs for replicas " + replicas + " via " + client,
+ shardCounts.get(shard).longValue(),
+ numDocs);
}
}
@@ -653,7 +1000,7 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
// query those shards or which client we use
long randomShardCountsExpected = 0;
ArrayList<String> randomShards = new ArrayList<>(shardCounts.size());
- for (Map.Entry<String,Long> shardData : shardCounts.entrySet()) {
+ for (Map.Entry<String, Long> shardData : shardCounts.entrySet()) {
if (random().nextBoolean() || randomShards.size() < 2) {
String shard = shardData.getKey();
randomShardCountsExpected += shardData.getValue();
@@ -676,9 +1023,10 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
String randShards = String.join(",", randomShards);
query.set("shards", randShards);
for (SolrClient client : this.clients) {
- assertEquals("numDocs for "+randShards+" via "+client,
- randomShardCountsExpected,
- client.query(query).getResults().getNumFound());
+ assertEquals(
+ "numDocs for " + randShards + " via " + client,
+ randomShardCountsExpected,
+ client.query(query).getResults().getNumFound());
}
// total num docs must match sum of every shard's numDocs
@@ -688,13 +1036,12 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
totalShardNumDocs += c;
}
for (SolrClient client : clients) {
- assertEquals("sum of shard numDocs on client: " + client,
- totalShardNumDocs,
- client.query(query).getResults().getNumFound());
+ assertEquals(
+ "sum of shard numDocs on client: " + client,
+ totalShardNumDocs,
+ client.query(query).getResults().getNumFound());
}
- assertTrue("total numDocs <= 0, WTF? Test is useless",
- 0 < totalShardNumDocs);
-
+ assertTrue("total numDocs <= 0, WTF? Test is useless", 0 < totalShardNumDocs);
}
private void testStopAndStartCoresInOneInstance() throws Exception {
@@ -702,13 +1049,19 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
try (final HttpSolrClient httpSolrClient = (HttpSolrClient) jetty.newClient(15000, 60000)) {
ThreadPoolExecutor executor = null;
try {
- executor = new ExecutorUtil.MDCAwareThreadPoolExecutor(0, Integer.MAX_VALUE,
- 5, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),
- new SolrNamedThreadFactory("testExecutor"));
+ executor =
+ new ExecutorUtil.MDCAwareThreadPoolExecutor(
+ 0,
+ Integer.MAX_VALUE,
+ 5,
+ TimeUnit.SECONDS,
+ new SynchronousQueue<Runnable>(),
+ new SolrNamedThreadFactory("testExecutor"));
int cnt = 3;
// create the cores
- createCollectionInOneInstance(httpSolrClient, jetty.getNodeName(), executor, "multiunload2", 1, cnt);
+ createCollectionInOneInstance(
+ httpSolrClient, jetty.getNodeName(), executor, "multiunload2", 1, cnt);
} finally {
if (executor != null) {
ExecutorUtil.shutdownAndAwaitTermination(executor);
@@ -729,56 +1082,74 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
}
printLayout();
-
}
- /**
- * Create a collection in single node
- */
- protected void createCollectionInOneInstance(final SolrClient client, String nodeName,
- ThreadPoolExecutor executor, final String collection,
- final int numShards, int numReplicas) {
+ /** Create a collection in single node */
+ protected void createCollectionInOneInstance(
+ final SolrClient client,
+ String nodeName,
+ ThreadPoolExecutor executor,
+ final String collection,
+ final int numShards,
+ int numReplicas) {
assertNotNull(nodeName);
try {
- assertEquals(0, CollectionAdminRequest.createCollection(collection, "conf1", numShards, 1)
- .setCreateNodeSet("")
- .process(client).getStatus());
+ assertEquals(
+ 0,
+ CollectionAdminRequest.createCollection(collection, "conf1", numShards, 1)
+ .setCreateNodeSet("")
+ .process(client)
+ .getStatus());
} catch (SolrServerException | IOException e) {
throw new RuntimeException(e);
}
for (int i = 0; i < numReplicas; i++) {
final int freezeI = i;
- executor.execute(() -> {
- try {
- assertTrue(CollectionAdminRequest.addReplicaToShard(collection, "shard"+((freezeI%numShards)+1))
- .setCoreName(collection + freezeI)
- .setNode(nodeName).process(client).isSuccess());
- } catch (SolrServerException | IOException e) {
- throw new RuntimeException(e);
- }
- });
+ executor.execute(
+ () -> {
+ try {
+ assertTrue(
+ CollectionAdminRequest.addReplicaToShard(
+ collection, "shard" + ((freezeI % numShards) + 1))
+ .setCoreName(collection + freezeI)
+ .setNode(nodeName)
+ .process(client)
+ .isSuccess());
+ } catch (SolrServerException | IOException e) {
+ throw new RuntimeException(e);
+ }
+ });
}
}
protected String getBaseUrl(SolrClient client) {
- String url2 = ((HttpSolrClient) client).getBaseURL()
- .substring(
- 0,
- ((HttpSolrClient) client).getBaseURL().length()
- - DEFAULT_COLLECTION.length() -1);
+ String url2 =
+ ((HttpSolrClient) client)
+ .getBaseURL()
+ .substring(
+ 0,
+ ((HttpSolrClient) client).getBaseURL().length() - DEFAULT_COLLECTION.length() - 1);
return url2;
}
@Override
- protected CollectionAdminResponse createCollection(Map<String, List<Integer>> collectionInfos,
- String collectionName, String configSetName, int numShards, int numReplicas, SolrClient client, String createNodeSetStr) throws SolrServerException, IOException {
+ protected CollectionAdminResponse createCollection(
+ Map<String, List<Integer>> collectionInfos,
+ String collectionName,
+ String configSetName,
+ int numShards,
+ int numReplicas,
+ SolrClient client,
+ String createNodeSetStr)
+ throws SolrServerException, IOException {
// TODO: Use CollectionAdminRequest for this test
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionAction.CREATE.toString());
params.set(CollectionHandlingUtils.NUM_SLICES, numShards);
params.set(ZkStateReader.REPLICATION_FACTOR, numReplicas);
- if (createNodeSetStr != null) params.set(CollectionHandlingUtils.CREATE_NODE_SET, createNodeSetStr);
+ if (createNodeSetStr != null)
+ params.set(CollectionHandlingUtils.CREATE_NODE_SET, createNodeSetStr);
int clientIndex = clients.size() > 1 ? random().nextInt(2) : 0;
List<Integer> list = new ArrayList<>();
@@ -794,10 +1165,14 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
CollectionAdminResponse res = new CollectionAdminResponse();
if (client == null) {
- final String baseUrl = ((HttpSolrClient) clients.get(clientIndex)).getBaseURL().substring(
- 0,
- ((HttpSolrClient) clients.get(clientIndex)).getBaseURL().length()
- - DEFAULT_COLLECTION.length() - 1);
+ final String baseUrl =
+ ((HttpSolrClient) clients.get(clientIndex))
+ .getBaseURL()
+ .substring(
+ 0,
+ ((HttpSolrClient) clients.get(clientIndex)).getBaseURL().length()
+ - DEFAULT_COLLECTION.length()
+ - 1);
try (SolrClient aClient = createNewSolrClient("", baseUrl)) {
res.setResponse(aClient.request(request));
@@ -818,12 +1193,11 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
}
/**
- * Expects a RegexReplaceProcessorFactories in the chain which will
- * "double up" the values in two (stored) string fields.
- * <p>
- * If the values are "double-doubled" or "not-doubled" then we know
- * the processor was not run the appropriate number of times
- * </p>
+ * Expects a RegexReplaceProcessorFactories in the chain which will "double up" the values in two
+ * (stored) string fields.
+ *
+ * <p>If the values are "double-doubled" or "not-doubled" then we know the processor was not run
+ * the appropriate number of times
*/
private void testUpdateProcessorsRunOnlyOnce(final String chain) throws Exception {
@@ -851,26 +1225,29 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
for (int i = 1; i < numLoops; i++) {
final String query = id + ":" + i;
QueryResponse qres = queryServer(new SolrQuery(query));
- assertEquals(chain + ": query failed: " + query,
- 0, qres.getStatus());
- assertEquals(chain + ": didn't find correct # docs with query: " + query,
- 1, qres.getResults().getNumFound());
+ assertEquals(chain + ": query failed: " + query, 0, qres.getStatus());
+ assertEquals(
+ chain + ": didn't find correct # docs with query: " + query,
+ 1,
+ qres.getResults().getNumFound());
SolrDocument doc = qres.getResults().get(0);
for (String field : new String[] {fieldA, fieldB}) {
- assertEquals(chain + ": doc#" + i+ " has wrong value for " + field,
- expected, doc.getFirstValue(field));
+ assertEquals(
+ chain + ": doc#" + i + " has wrong value for " + field,
+ expected,
+ doc.getFirstValue(field));
}
}
-
}
- // cloud level test mainly needed just to make sure that versions and errors are propagated correctly
+ // cloud level test mainly needed just to make sure that versions and errors are propagated
+ // correctly
private void doOptimisticLockingAndUpdating() throws Exception {
log.info("### STARTING doOptimisticLockingAndUpdating");
printLayout();
- final SolrInputDocument sd = sdoc("id", 1000, "_version_", -1);
+ final SolrInputDocument sd = sdoc("id", 1000, "_version_", -1);
indexDoc(sd);
ignoreException("version conflict");
@@ -882,18 +1259,18 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
// TODO: test deletes. SolrJ needs a good way to pass version for delete...
- final SolrInputDocument sd2 = sdoc("id", 1000, "foo_i",5);
+ final SolrInputDocument sd2 = sdoc("id", 1000, "foo_i", 5);
clients.get(0).add(sd2);
List<Integer> expected = new ArrayList<>();
int val = 0;
for (SolrClient client : clients) {
val += 10;
- client.add(sdoc("id", 1000, "val_i", map("add",val), "foo_i",val));
+ client.add(sdoc("id", 1000, "val_i", map("add", val), "foo_i", val));
expected.add(val);
}
- QueryRequest qr = new QueryRequest(params("qt", "/get", "id","1000"));
+ QueryRequest qr = new QueryRequest(params("qt", "/get", "id", "1000"));
for (SolrClient client : clients) {
val += 10;
NamedList<?> rsp = client.request(qr);
@@ -902,25 +1279,25 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
}
}
- private void testNumberOfCommitsWithCommitAfterAdd()
- throws SolrServerException, IOException {
+ private void testNumberOfCommitsWithCommitAfterAdd() throws SolrServerException, IOException {
log.info("### STARTING testNumberOfCommitsWithCommitAfterAdd");
long startCommits = getNumCommits((HttpSolrClient) clients.get(0));
-
- NamedList<Object> result = clients.get(0).request(
- new StreamingUpdateRequest("/update",
- getFile("books_numeric_ids.csv").toPath(), "application/csv")
- .setCommitWithin(900000)
- .setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true));
+ NamedList<Object> result =
+ clients
+ .get(0)
+ .request(
+ new StreamingUpdateRequest(
+ "/update", getFile("books_numeric_ids.csv").toPath(), "application/csv")
+ .setCommitWithin(900000)
+ .setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true));
long endCommits = getNumCommits((HttpSolrClient) clients.get(0));
assertEquals(startCommits + 1L, endCommits);
}
- private Long getNumCommits(HttpSolrClient sourceClient) throws
- SolrServerException, IOException {
+ private Long getNumCommits(HttpSolrClient sourceClient) throws SolrServerException, IOException {
// construct the /admin/metrics URL
URL url = new URL(sourceClient.getBaseURL());
String path = url.getPath().substring(1);
@@ -930,7 +1307,8 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
urlString = urlString.substring(0, urlString.length() - collection.length() - 1);
try (HttpSolrClient client = getHttpSolrClient(urlString, 15000, 60000)) {
ModifiableSolrParams params = new ModifiableSolrParams();
- //params.set("qt", "/admin/metrics?prefix=UPDATE.updateHandler&registry=solr.core." + collection);
+ // params.set("qt", "/admin/metrics?prefix=UPDATE.updateHandler&registry=solr.core." +
+ // collection);
params.set("qt", "/admin/metrics");
params.set("prefix", "UPDATE.updateHandler");
params.set("registry", "solr.core." + collection);
@@ -940,28 +1318,30 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
NamedList<?> metrics = (NamedList<?>) resp.get("metrics");
NamedList<?> uhandlerCat = (NamedList<?>) metrics.getVal(0);
@SuppressWarnings({"unchecked"})
- Map<String,Object> commits = (Map<String,Object>) uhandlerCat.get("UPDATE.updateHandler.commits");
+ Map<String, Object> commits =
+ (Map<String, Object>) uhandlerCat.get("UPDATE.updateHandler.commits");
return (Long) commits.get("count");
}
}
private void testANewCollectionInOneInstanceWithManualShardAssignement() throws Exception {
log.info("### STARTING testANewCollectionInOneInstanceWithManualShardAssignement");
- assertEquals(0, CollectionAdminRequest.createCollection(oneInstanceCollection2, "conf1", 2, 2)
- .setCreateNodeSet("")
- .process(cloudClient).getStatus());
+ assertEquals(
+ 0,
+ CollectionAdminRequest.createCollection(oneInstanceCollection2, "conf1", 2, 2)
+ .setCreateNodeSet("")
+ .process(cloudClient)
+ .getStatus());
List<SolrClient> collectionClients = new ArrayList<>();
for (int i = 0; i < 4; i++) {
- CollectionAdminResponse resp = CollectionAdminRequest
- .addReplicaToShard(oneInstanceCollection2, "shard" + ((i%2)+1))
- .setNode(jettys.get(0).getNodeName())
- .process(cloudClient);
+ CollectionAdminResponse resp =
+ CollectionAdminRequest.addReplicaToShard(oneInstanceCollection2, "shard" + ((i % 2) + 1))
+ .setNode(jettys.get(0).getNodeName())
+ .process(cloudClient);
for (String coreName : resp.getCollectionCoresStatus().keySet()) {
collectionClients.add(createNewSolrClient(coreName, jettys.get(0).getBaseUrl().toString()));
}
-
-
}
SolrClient client1 = collectionClients.get(0);
@@ -969,13 +1349,13 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
SolrClient client3 = collectionClients.get(2);
SolrClient client4 = collectionClients.get(3);
-
// no one should be recovering
- waitForRecoveriesToFinish(oneInstanceCollection2, getCommonCloudSolrClient().getZkStateReader(), false, true);
+ waitForRecoveriesToFinish(
+ oneInstanceCollection2, getCommonCloudSolrClient().getZkStateReader(), false, true);
assertAllActive(oneInstanceCollection2, getCommonCloudSolrClient().getZkStateReader());
- //printLayout();
+ // printLayout();
// TODO: enable when we don't falsely get slice1...
// solrj.getZkStateReader().getLeaderUrl(oneInstanceCollection2, "slice1", 30000);
@@ -996,76 +1376,90 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
query.set("distrib", true);
long allDocs = getCommonCloudSolrClient().query(query).getResults().getNumFound();
-// System.out.println("1:" + oneDocs);
-// System.out.println("2:" + twoDocs);
-// System.out.println("3:" + threeDocs);
-// System.out.println("4:" + fourDocs);
-// System.out.println("All Docs:" + allDocs);
+ // System.out.println("1:" + oneDocs);
+ // System.out.println("2:" + twoDocs);
+ // System.out.println("3:" + threeDocs);
+ // System.out.println("4:" + fourDocs);
+ // System.out.println("All Docs:" + allDocs);
-// assertEquals(oneDocs, threeDocs);
-// assertEquals(twoDocs, fourDocs);
-// assertNotSame(oneDocs, twoDocs);
+ // assertEquals(oneDocs, threeDocs);
+ // assertEquals(twoDocs, fourDocs);
+ // assertNotSame(oneDocs, twoDocs);
assertEquals(3, allDocs);
// we added a role of none on these creates - check for it
ZkStateReader zkStateReader = getCommonCloudSolrClient().getZkStateReader();
zkStateReader.forceUpdateCollection(oneInstanceCollection2);
- Map<String,Slice> slices = zkStateReader.getClusterState().getCollection(oneInstanceCollection2).getSlicesMap();
+ Map<String, Slice> slices =
+ zkStateReader.getClusterState().getCollection(oneInstanceCollection2).getSlicesMap();
assertNotNull(slices);
- ZkCoreNodeProps props = new ZkCoreNodeProps(getCommonCloudSolrClient().getZkStateReader().getClusterState()
- .getCollection(oneInstanceCollection2).getLeader("shard1"));
+ ZkCoreNodeProps props =
+ new ZkCoreNodeProps(
+ getCommonCloudSolrClient()
+ .getZkStateReader()
+ .getClusterState()
+ .getCollection(oneInstanceCollection2)
+ .getLeader("shard1"));
// now test that unloading a core gets us a new leader
- try (HttpSolrClient unloadClient = getHttpSolrClient(jettys.get(0).getBaseUrl().toString(), 15000, 60000)) {
+ try (HttpSolrClient unloadClient =
+ getHttpSolrClient(jettys.get(0).getBaseUrl().toString(), 15000, 60000)) {
Unload unloadCmd = new Unload(true);
unloadCmd.setCoreName(props.getCoreName());
String leader = props.getCoreUrl();
- testExecutor.execute(new Runnable() {
-
- @Override
- public void run() {
- try {
- unloadClient.request(unloadCmd);
- } catch (SolrServerException e) {
- throw new RuntimeException(e);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- });
+ testExecutor.execute(
+ new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ unloadClient.request(unloadCmd);
+ } catch (SolrServerException e) {
+ throw new RuntimeException(e);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ });
try {
- getCommonCloudSolrClient().getZkStateReader().waitForState(oneInstanceCollection2, 20000, TimeUnit.MILLISECONDS, (n, c) -> {
-
-
- try {
- if (leader.equals(zkStateReader.getLeaderUrl(oneInstanceCollection2, "shard1", 10000))) {
- return false;
- }
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- return true;
- });
+ getCommonCloudSolrClient()
+ .getZkStateReader()
+ .waitForState(
+ oneInstanceCollection2,
+ 20000,
+ TimeUnit.MILLISECONDS,
+ (n, c) -> {
+ try {
+ if (leader.equals(
+ zkStateReader.getLeaderUrl(oneInstanceCollection2, "shard1", 10000))) {
+ return false;
+ }
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ return true;
+ });
} catch (TimeoutException | InterruptedException e) {
fail("Leader never changed");
}
}
IOUtils.close(collectionClients);
-
}
private void testSearchByCollectionName() throws SolrServerException, IOException {
log.info("### STARTING testSearchByCollectionName");
SolrClient client = clients.get(0);
- final String baseUrl = ((HttpSolrClient) client).getBaseURL().substring(
- 0,
- ((HttpSolrClient) client).getBaseURL().length()
- - DEFAULT_COLLECTION.length() - 1);
+ final String baseUrl =
+ ((HttpSolrClient) client)
+ .getBaseURL()
+ .substring(
+ 0,
+ ((HttpSolrClient) client).getBaseURL().length() - DEFAULT_COLLECTION.length() - 1);
// the cores each have different names, but if we add the collection name to the url
// we should get mapped to the right core
@@ -1079,10 +1473,12 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
private void testUpdateByCollectionName() throws SolrServerException, IOException {
log.info("### STARTING testUpdateByCollectionName");
SolrClient client = clients.get(0);
- final String baseUrl = ((HttpSolrClient) client).getBaseURL().substring(
- 0,
- ((HttpSolrClient) client).getBaseURL().length()
- - DEFAULT_COLLECTION.length() - 1);
+ final String baseUrl =
+ ((HttpSolrClient) client)
+ .getBaseURL()
+ .substring(
+ 0,
+ ((HttpSolrClient) client).getBaseURL().length() - DEFAULT_COLLECTION.length() - 1);
// the cores each have different names, but if we add the collection name to the url
// we should get mapped to the right core
@@ -1094,9 +1490,10 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
private void testANewCollectionInOneInstance() throws Exception {
log.info("### STARTING testANewCollectionInOneInstance");
- CollectionAdminResponse response = CollectionAdminRequest.createCollection(oneInstanceCollection, "conf1", 2, 2)
- .setCreateNodeSet(jettys.get(0).getNodeName())
- .process(cloudClient);
+ CollectionAdminResponse response =
+ CollectionAdminRequest.createCollection(oneInstanceCollection, "conf1", 2, 2)
+ .setCreateNodeSet(jettys.get(0).getNodeName())
+ .process(cloudClient);
assertEquals(0, response.getStatus());
List<SolrClient> collectionClients = new ArrayList<>();
for (String coreName : response.getCollectionCoresStatus().keySet()) {
@@ -1108,7 +1505,8 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
SolrClient client3 = collectionClients.get(2);
SolrClient client4 = collectionClients.get(3);
- waitForRecoveriesToFinish(oneInstanceCollection, getCommonCloudSolrClient().getZkStateReader(), false);
+ waitForRecoveriesToFinish(
+ oneInstanceCollection, getCommonCloudSolrClient().getZkStateReader(), false);
assertAllActive(oneInstanceCollection, getCommonCloudSolrClient().getZkStateReader());
client2.add(getDoc(id, "1"));
@@ -1127,56 +1525,58 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
query.set("distrib", true);
long allDocs = getCommonCloudSolrClient().query(query).getResults().getNumFound();
-// System.out.println("1:" + oneDocs);
-// System.out.println("2:" + twoDocs);
-// System.out.println("3:" + threeDocs);
-// System.out.println("4:" + fourDocs);
-// System.out.println("All Docs:" + allDocs);
+ // System.out.println("1:" + oneDocs);
+ // System.out.println("2:" + twoDocs);
+ // System.out.println("3:" + threeDocs);
+ // System.out.println("4:" + fourDocs);
+ // System.out.println("All Docs:" + allDocs);
assertEquals(3, allDocs);
IOUtils.close(collectionClients);
-
}
- private void createCollection(String collection,
- List<SolrClient> collectionClients, String baseUrl, int num) {
+ private void createCollection(
+ String collection, List<SolrClient> collectionClients, String baseUrl, int num) {
createSolrCore(collection, collectionClients, baseUrl, num, null);
}
- private void createSolrCore(final String collection,
- List<SolrClient> collectionClients, final String baseUrl, final int num,
+ private void createSolrCore(
+ final String collection,
+ List<SolrClient> collectionClients,
+ final String baseUrl,
+ final int num,
final String shardId) {
- Callable<Object> call = () -> {
- try (HttpSolrClient client = getHttpSolrClient(baseUrl)) {
- // client.setConnectionTimeout(15000);
- Create createCmd = new Create();
- createCmd.setRoles("none");
- createCmd.setCoreName(collection + num);
- createCmd.setCollection(collection);
-
- if (random().nextBoolean()) {
- // sometimes we use an explicit core node name
- createCmd.setCoreNodeName("anode" + nodeCounter.incrementAndGet());
- }
+ Callable<Object> call =
+ () -> {
+ try (HttpSolrClient client = getHttpSolrClient(baseUrl)) {
+ // client.setConnectionTimeout(15000);
+ Create createCmd = new Create();
+ createCmd.setRoles("none");
+ createCmd.setCoreName(collection + num);
+ createCmd.setCollection(collection);
+
+ if (random().nextBoolean()) {
+ // sometimes we use an explicit core node name
+ createCmd.setCoreNodeName("anode" + nodeCounter.incrementAndGet());
+ }
- if (shardId == null) {
- createCmd.setNumShards(2);
- }
- createCmd.setDataDir(getDataDir(createTempDir(collection).toFile().getAbsolutePath()));
- if (shardId != null) {
- createCmd.setShardId(shardId);
- }
- client.request(createCmd);
- } catch (Exception e) {
- e.printStackTrace();
- //fail
- }
- return null;
- };
+ if (shardId == null) {
+ createCmd.setNumShards(2);
+ }
+ createCmd.setDataDir(getDataDir(createTempDir(collection).toFile().getAbsolutePath()));
+ if (shardId != null) {
+ createCmd.setShardId(shardId);
+ }
+ client.request(createCmd);
+ } catch (Exception e) {
+ e.printStackTrace();
+ // fail
+ }
+ return null;
+ };
pending.add(completionService.submit(call));
-
collectionClients.add(createNewSolrClient(collection + num, baseUrl));
}
@@ -1210,15 +1610,24 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
otherCollectionClients.get("collection3").get(0).commit();
getCommonCloudSolrClient().setDefaultCollection("collection1");
- long collection1Docs = getCommonCloudSolrClient().query(new SolrQuery("*:*")).getResults()
- .getNumFound();
-
- long collection2Docs = otherCollectionClients.get("collection2").get(0)
- .query(new SolrQuery("*:*")).getResults().getNumFound();
-
- long collection3Docs = otherCollectionClients.get("collection3").get(0)
- .query(new SolrQuery("*:*")).getResults().getNumFound();
-
+ long collection1Docs =
+ getCommonCloudSolrClient().query(new SolrQuery("*:*")).getResults().getNumFound();
+
+ long collection2Docs =
+ otherCollectionClients
+ .get("collection2")
+ .get(0)
+ .query(new SolrQuery("*:*"))
+ .getResults()
+ .getNumFound();
+
+ long collection3Docs =
+ otherCollectionClients
+ .get("collection3")
+ .get(0)
+ .query(new SolrQuery("*:*"))
+ .getResults()
+ .getNumFound();
SolrQuery query = new SolrQuery("*:*");
query.set("collection", "collection2,collection3");
@@ -1249,7 +1658,8 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
assertEquals(collection3Docs, collection2Docs - 1);
}
- protected void indexDoc(String collection, SolrInputDocument doc) throws IOException, SolrServerException {
+ protected void indexDoc(String collection, SolrInputDocument doc)
+ throws IOException, SolrServerException {
List<SolrClient> clients = otherCollectionClients.get(collection);
int which = (doc.getField(id).toString().hashCode() & 0x7fffffff) % clients.size();
SolrClient client = clients.get(which);
@@ -1259,33 +1669,37 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
@SuppressWarnings({"unchecked"})
private void createNewCollection(final String collection) throws InterruptedException {
try {
- assertEquals(0, CollectionAdminRequest
- .createCollection(collection, "conf1", 2, 1)
- .setCreateNodeSet("")
- .process(cloudClient).getStatus());
+ assertEquals(
+ 0,
+ CollectionAdminRequest.createCollection(collection, "conf1", 2, 1)
+ .setCreateNodeSet("")
+ .process(cloudClient)
+ .getStatus());
} catch (Exception e) {
e.printStackTrace();
- //fails
+ // fails
}
final List<SolrClient> collectionClients = new ArrayList<>();
otherCollectionClients.put(collection, collectionClients);
- int unique = 0 ;
+ int unique = 0;
for (final JettySolrRunner runner : jettys) {
unique++;
final int frozeUnique = unique;
- Callable<Object> call = () -> {
-
- try {
- assertTrue(CollectionAdminRequest
- .addReplicaToShard(collection, "shard"+ ((frozeUnique%2)+1))
- .setNode(runner.getNodeName())
- .process(cloudClient).isSuccess());
- } catch (Exception e) {
- e.printStackTrace();
- //fails
- }
- return null;
- };
+ Callable<Object> call =
+ () -> {
+ try {
+ assertTrue(
+ CollectionAdminRequest.addReplicaToShard(
+ collection, "shard" + ((frozeUnique % 2) + 1))
+ .setNode(runner.getNodeName())
+ .process(cloudClient)
+ .isSuccess());
+ } catch (Exception e) {
+ e.printStackTrace();
+ // fails
+ }
+ return null;
+ };
collectionClients.add(createNewSolrClient(collection, runner.getBaseUrl().toString()));
pending.add(completionService.submit(call));
@@ -1304,32 +1718,32 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
HttpSolrClient client = getHttpSolrClient(baseUrl + "/" + collection);
return client;
- }
- catch (Exception ex) {
+ } catch (Exception ex) {
throw new RuntimeException(ex);
}
}
- protected SolrClient createNewSolrClient(String collection, String baseUrl, int connectionTimeoutMillis, int socketTimeoutMillis) {
+ protected SolrClient createNewSolrClient(
+ String collection, String baseUrl, int connectionTimeoutMillis, int socketTimeoutMillis) {
try {
// setup the server...
- HttpSolrClient client = getHttpSolrClient(baseUrl + "/" + collection, connectionTimeoutMillis, socketTimeoutMillis);
+ HttpSolrClient client =
+ getHttpSolrClient(
+ baseUrl + "/" + collection, connectionTimeoutMillis, socketTimeoutMillis);
return client;
- }
- catch (Exception ex) {
+ } catch (Exception ex) {
throw new RuntimeException(ex);
}
}
@Override
- protected QueryResponse queryServer(ModifiableSolrParams params) throws SolrServerException, IOException {
+ protected QueryResponse queryServer(ModifiableSolrParams params)
+ throws SolrServerException, IOException {
- if (r.nextBoolean())
- return super.queryServer(params);
+ if (r.nextBoolean()) return super.queryServer(params);
- if (r.nextBoolean())
- params.set("collection",DEFAULT_COLLECTION);
+ if (r.nextBoolean()) params.set("collection", DEFAULT_COLLECTION);
QueryResponse rsp = getCommonCloudSolrClient().query(params);
return rsp;
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractChaosMonkeyNothingIsSafeTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractChaosMonkeyNothingIsSafeTestBase.java
index 48facc9aa91..5f1326266cb 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractChaosMonkeyNothingIsSafeTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractChaosMonkeyNothingIsSafeTestBase.java
@@ -21,7 +21,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
-
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.common.SolrInputDocument;
@@ -30,16 +29,18 @@ import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
-public abstract class AbstractChaosMonkeyNothingIsSafeTestBase extends AbstractFullDistribZkTestBase {
+public abstract class AbstractChaosMonkeyNothingIsSafeTestBase
+ extends AbstractFullDistribZkTestBase {
private static final int FAIL_TOLERANCE = 100;
- private static final Integer RUN_LENGTH = Integer.parseInt(System.getProperty("solr.tests.cloud.cm.runlength", "-1"));
+ private static final Integer RUN_LENGTH =
+ Integer.parseInt(System.getProperty("solr.tests.cloud.cm.runlength", "-1"));
private final boolean onlyLeaderIndexes = random().nextBoolean();
@BeforeClass
public static void beforeSuperClass() {
- schemaString = "schema15.xml"; // we need a string id
+ schemaString = "schema15.xml"; // we need a string id
System.setProperty("solr.autoCommit.maxTime", "15000");
System.clearProperty("solr.httpclient.retries");
System.clearProperty("solr.retries.on.forward");
@@ -53,16 +54,14 @@ public abstract class AbstractChaosMonkeyNothingIsSafeTestBase extends AbstractF
clearErrorHook();
}
-
-
@Override
protected void destroyServers() throws Exception {
super.destroyServers();
}
- protected static final String[] fieldNames = new String[]{"f_i", "f_f", "f_d", "f_l", "f_dt"};
- protected static final RandVal[] randVals = new RandVal[]{rint, rfloat, rdouble, rlong, rdate};
+ protected static final String[] fieldNames = new String[] {"f_i", "f_f", "f_d", "f_l", "f_dt"};
+ protected static final RandVal[] randVals = new RandVal[] {rint, rfloat, rdouble, rlong, rdate};
private int clientSoTimeout = 60000;
@@ -82,7 +81,7 @@ public abstract class AbstractChaosMonkeyNothingIsSafeTestBase extends AbstractF
public void distribSetUp() throws Exception {
super.distribSetUp();
// can help to hide this when testing and looking at logs
- //ignoreException("shard update error");
+ // ignoreException("shard update error");
useFactory("solr.StandardDirectoryFactory");
}
@@ -111,16 +110,15 @@ public abstract class AbstractChaosMonkeyNothingIsSafeTestBase extends AbstractF
}
fixShardCount(numShards);
-
// TODO: we only do this sometimes so that we can sometimes compare against control,
// it's currently hard to know what requests failed when using ConcurrentSolrUpdateServer
runFullThrottle = random().nextBoolean();
-
}
@Override
protected boolean useTlogReplicas() {
- return false; // TODO: tlog replicas makes commits take way to long due to what is likely a bug and it's TestInjection use
+ return false; // TODO: tlog replicas makes commits take way to long due to what is likely a bug
+ // and it's TestInjection use
}
@Override
@@ -129,7 +127,8 @@ public abstract class AbstractChaosMonkeyNothingIsSafeTestBase extends AbstractF
}
protected CloudSolrClient createCloudClient(String defaultCollection, int socketTimeout) {
- CloudSolrClient client = getCloudSolrClient(zkServer.getZkAddress(), random().nextBoolean(), 30000, socketTimeout);
+ CloudSolrClient client =
+ getCloudSolrClient(zkServer.getZkAddress(), random().nextBoolean(), 30000, socketTimeout);
if (defaultCollection != null) client.setDefaultCollection(defaultCollection);
return client;
}
@@ -142,14 +141,14 @@ public abstract class AbstractChaosMonkeyNothingIsSafeTestBase extends AbstractF
clientSoTimeout = 5000;
boolean testSuccessful = false;
- try (CloudSolrClient ourCloudClient = createCloudClient(DEFAULT_COLLECTION)) {
+ try (CloudSolrClient ourCloudClient = createCloudClient(DEFAULT_COLLECTION)) {
handle.clear();
handle.put("timestamp", SKIPVAL);
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
// make sure we have leaders for each shard
for (int j = 1; j < sliceCount; j++) {
zkStateReader.getLeaderRetry(DEFAULT_COLLECTION, "shard" + j, 10000);
- } // make sure we again have leaders for each shard
+ } // make sure we again have leaders for each shard
waitForRecoveriesToFinish(false);
@@ -162,7 +161,8 @@ public abstract class AbstractChaosMonkeyNothingIsSafeTestBase extends AbstractF
int threadCount = TEST_NIGHTLY ? 3 : 1;
int i = 0;
for (i = 0; i < threadCount; i++) {
- StoppableIndexingThread indexThread = new StoppableIndexingThread(controlClient, cloudClient, Integer.toString(i), true);
+ StoppableIndexingThread indexThread =
+ new StoppableIndexingThread(controlClient, cloudClient, Integer.toString(i), true);
threads.add(indexThread);
indexTreads.add(indexThread);
indexThread.start();
@@ -178,7 +178,14 @@ public abstract class AbstractChaosMonkeyNothingIsSafeTestBase extends AbstractF
if (runFullThrottle) {
ftIndexThread =
- new FullThrottleStoppableIndexingThread(cloudClient.getHttpClient(),controlClient, cloudClient, clients, "ft1", true, this.clientSoTimeout);
+ new FullThrottleStoppableIndexingThread(
+ cloudClient.getHttpClient(),
+ controlClient,
+ cloudClient,
+ clients,
+ "ft1",
+ true,
+ this.clientSoTimeout);
ftIndexThread.start();
}
@@ -190,8 +197,8 @@ public abstract class AbstractChaosMonkeyNothingIsSafeTestBase extends AbstractF
} else {
int[] runTimes;
if (TEST_NIGHTLY) {
- runTimes = new int[] {5000, 6000, 10000, 15000, 25000, 30000,
- 30000, 45000, 90000, 120000};
+ runTimes =
+ new int[] {5000, 6000, 10000, 15000, 25000, 30000, 30000, 45000, 90000, 120000};
} else {
runTimes = new int[] {5000, 7000, 15000};
}
@@ -206,7 +213,6 @@ public abstract class AbstractChaosMonkeyNothingIsSafeTestBase extends AbstractF
// ideally this should go into chaosMonkey
restartZk(1000 * (5 + random().nextInt(4)));
-
if (runFullThrottle) {
ftIndexThread.safeStop();
}
@@ -243,14 +249,19 @@ public abstract class AbstractChaosMonkeyNothingIsSafeTestBase extends AbstractF
// we expect full throttle fails, but cloud client should not easily fail
for (StoppableThread indexThread : threads) {
- if (indexThread instanceof StoppableIndexingThread && !(indexThread instanceof FullThrottleStoppableIndexingThread)) {
+ if (indexThread instanceof StoppableIndexingThread
+ && !(indexThread instanceof FullThrottleStoppableIndexingThread)) {
int failCount = ((StoppableIndexingThread) indexThread).getFailCount();
- assertFalse("There were too many update fails (" + failCount + " > " + FAIL_TOLERANCE
- + ") - we expect it can happen, but shouldn't easily", failCount > FAIL_TOLERANCE);
+ assertFalse(
+ "There were too many update fails ("
+ + failCount
+ + " > "
+ + FAIL_TOLERANCE
+ + ") - we expect it can happen, but shouldn't easily",
+ failCount > FAIL_TOLERANCE);
}
}
-
waitForThingsToLevelOut(20, TimeUnit.SECONDS);
commit();
@@ -261,20 +272,21 @@ public abstract class AbstractChaosMonkeyNothingIsSafeTestBase extends AbstractF
// have request fails
checkShardConsistency(!runFullThrottle, true, addFails, deleteFails);
- long ctrlDocs = controlClient.query(new SolrQuery("*:*")).getResults()
- .getNumFound();
+ long ctrlDocs = controlClient.query(new SolrQuery("*:*")).getResults().getNumFound();
// ensure we have added more than 0 docs
- long cloudClientDocs = cloudClient.query(new SolrQuery("*:*"))
- .getResults().getNumFound();
+ long cloudClientDocs = cloudClient.query(new SolrQuery("*:*")).getResults().getNumFound();
assertTrue("Found " + ctrlDocs + " control docs", cloudClientDocs > 0);
- if (VERBOSE) System.out.println("control docs:"
- + controlClient.query(new SolrQuery("*:*")).getResults()
- .getNumFound() + "\n\n");
+ if (VERBOSE)
+ System.out.println(
+ "control docs:"
+ + controlClient.query(new SolrQuery("*:*")).getResults().getNumFound()
+ + "\n\n");
- // try and make a collection to make sure the overseer has survived the expiration and session loss
+ // try and make a collection to make sure the overseer has survived the expiration and session
+ // loss
// sometimes we restart zookeeper as well
if (random().nextBoolean()) {
@@ -282,9 +294,7 @@ public abstract class AbstractChaosMonkeyNothingIsSafeTestBase extends AbstractF
}
try (CloudSolrClient client = createCloudClient("collection1", 30000)) {
- createCollection(null, "testcollection",
- 1, 1, client, null, "conf1");
-
+ createCollection(null, "testcollection", 1, 1, client, null, "conf1");
}
List<Integer> numShardsNumReplicas = new ArrayList<>(2);
numShardsNumReplicas.add(1);
@@ -301,7 +311,7 @@ public abstract class AbstractChaosMonkeyNothingIsSafeTestBase extends AbstractF
private Set<String> getAddFails(List<StoppableIndexingThread> threads) {
Set<String> addFails = new HashSet<String>();
- for (StoppableIndexingThread thread : threads) {
+ for (StoppableIndexingThread thread : threads) {
addFails.addAll(thread.getAddFails());
}
return addFails;
@@ -309,7 +319,7 @@ public abstract class AbstractChaosMonkeyNothingIsSafeTestBase extends AbstractF
private Set<String> getDeleteFails(List<StoppableIndexingThread> threads) {
Set<String> deleteFails = new HashSet<String>();
- for (StoppableIndexingThread thread : threads) {
+ for (StoppableIndexingThread thread : threads) {
deleteFails.addAll(thread.getDeleteFails());
}
return deleteFails;
@@ -321,5 +331,4 @@ public abstract class AbstractChaosMonkeyNothingIsSafeTestBase extends AbstractF
SolrInputDocument doc = getDoc(fields);
indexDoc(doc);
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractChaosMonkeySafeLeaderTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractChaosMonkeySafeLeaderTestBase.java
index 0078b98783b..3d9ba2f2c9c 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractChaosMonkeySafeLeaderTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractChaosMonkeySafeLeaderTestBase.java
@@ -20,7 +20,6 @@ package org.apache.solr.cloud;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
-
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
@@ -30,11 +29,12 @@ import org.junit.BeforeClass;
import org.junit.Test;
public abstract class AbstractChaosMonkeySafeLeaderTestBase extends AbstractFullDistribZkTestBase {
- private static final Integer RUN_LENGTH = Integer.parseInt(System.getProperty("solr.tests.cloud.cm.runlength", "-1"));
+ private static final Integer RUN_LENGTH =
+ Integer.parseInt(System.getProperty("solr.tests.cloud.cm.runlength", "-1"));
@BeforeClass
public static void beforeSuperClass() {
- schemaString = "schema15.xml"; // we need a string id
+ schemaString = "schema15.xml"; // we need a string id
System.setProperty("solr.autoCommit.maxTime", "15000");
System.clearProperty("solr.httpclient.retries");
System.clearProperty("solr.retries.on.forward");
@@ -48,8 +48,8 @@ public abstract class AbstractChaosMonkeySafeLeaderTestBase extends AbstractFull
clearErrorHook();
}
- protected static final String[] fieldNames = new String[]{"f_i", "f_f", "f_d", "f_l", "f_dt"};
- protected static final RandVal[] randVals = new RandVal[]{rint, rfloat, rdouble, rlong, rdate};
+ protected static final String[] fieldNames = new String[] {"f_i", "f_f", "f_d", "f_l", "f_dt"};
+ protected static final RandVal[] randVals = new RandVal[] {rint, rfloat, rdouble, rlong, rdate};
public String[] getFieldNames() {
return fieldNames;
@@ -60,6 +60,7 @@ public abstract class AbstractChaosMonkeySafeLeaderTestBase extends AbstractFull
}
protected abstract String getDirectoryFactory();
+
@Override
public void distribSetUp() throws Exception {
useFactory(getDirectoryFactory());
@@ -109,7 +110,15 @@ public abstract class AbstractChaosMonkeySafeLeaderTestBase extends AbstractFull
}
for (int i = 0; i < threadCount; i++) {
- StoppableIndexingThread indexThread = new StoppableIndexingThread(controlClient, cloudClient, Integer.toString(i), true, maxUpdates, batchSize, pauseBetweenUpdates); // random().nextInt(999) + 1
+ StoppableIndexingThread indexThread =
+ new StoppableIndexingThread(
+ controlClient,
+ cloudClient,
+ Integer.toString(i),
+ true,
+ maxUpdates,
+ batchSize,
+ pauseBetweenUpdates); // random().nextInt(999) + 1
threads.add(indexThread);
indexThread.start();
}
@@ -122,8 +131,8 @@ public abstract class AbstractChaosMonkeySafeLeaderTestBase extends AbstractFull
} else {
int[] runTimes;
if (TEST_NIGHTLY) {
- runTimes = new int[] {5000, 6000, 10000, 15000, 25000, 30000,
- 30000, 45000, 90000, 120000};
+ runTimes =
+ new int[] {5000, 6000, 10000, 15000, 25000, 30000, 30000, 45000, 90000, 120000};
} else {
runTimes = new int[] {5000, 7000, 15000};
}
@@ -163,9 +172,14 @@ public abstract class AbstractChaosMonkeySafeLeaderTestBase extends AbstractFull
checkShardConsistency(batchSize == 1, true);
- if (VERBOSE) System.out.println("control docs:" + controlClient.query(new SolrQuery("*:*")).getResults().getNumFound() + "\n\n");
+ if (VERBOSE)
+ System.out.println(
+ "control docs:"
+ + controlClient.query(new SolrQuery("*:*")).getResults().getNumFound()
+ + "\n\n");
- // try and make a collection to make sure the overseer has survived the expiration and session loss
+ // try and make a collection to make sure the overseer has survived the expiration and session
+ // loss
// sometimes we restart zookeeper as well
if (random().nextBoolean()) {
@@ -176,12 +190,11 @@ public abstract class AbstractChaosMonkeySafeLeaderTestBase extends AbstractFull
try (CloudSolrClient client = createCloudClient("collection1")) {
createCollection(null, "testcollection", 1, 1, client, null, "conf1");
-
}
List<Integer> numShardsNumReplicas = new ArrayList<>(2);
numShardsNumReplicas.add(1);
numShardsNumReplicas.add(1);
- checkForCollection("testcollection",numShardsNumReplicas, null);
+ checkForCollection("testcollection", numShardsNumReplicas, null);
}
private void tryDelete() throws Exception {
@@ -207,5 +220,4 @@ public abstract class AbstractChaosMonkeySafeLeaderTestBase extends AbstractFull
addFields(doc, "rnd_b", true);
indexDoc(doc);
}
-
-}
\ No newline at end of file
+}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java
index cdb975c5719..21bbdaf55c0 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java
@@ -16,6 +16,9 @@
*/
package org.apache.solr.cloud;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.concurrent.TimeUnit.SECONDS;
+
import java.io.File;
import java.lang.invoke.MethodHandles;
import java.nio.file.Path;
@@ -23,7 +26,6 @@ import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
-
import org.apache.commons.io.FileUtils;
import org.apache.solr.BaseDistributedSearchTestCase;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
@@ -44,9 +46,6 @@ import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
-import static java.util.concurrent.TimeUnit.SECONDS;
-
public abstract class AbstractDistribZkTestBase extends BaseDistributedSearchTestCase {
private static final String REMOVE_VERSION_FIELD = "remove.version.field";
@@ -62,7 +61,7 @@ public abstract class AbstractDistribZkTestBase extends BaseDistributedSearchTes
@BeforeClass
public static void beforeThisClass() throws Exception {
// Only For Manual Testing: this will force an fs based dir factory
- //useFactory(null);
+ // useFactory(null);
}
@Override
@@ -77,7 +76,8 @@ public abstract class AbstractDistribZkTestBase extends BaseDistributedSearchTes
System.setProperty(ENABLE_UPDATE_LOG, "true");
System.setProperty(REMOVE_VERSION_FIELD, "true");
System.setProperty(ZOOKEEPER_FORCE_SYNC, "false");
- System.setProperty(MockDirectoryFactory.SOLR_TESTS_ALLOW_READING_FILES_STILL_OPEN_FOR_WRITE, "true");
+ System.setProperty(
+ MockDirectoryFactory.SOLR_TESTS_ALLOW_READING_FILES_STILL_OPEN_FOR_WRITE, "true");
String schema = getCloudSchemaFile();
if (schema == null) schema = "schema.xml";
@@ -99,21 +99,23 @@ public abstract class AbstractDistribZkTestBase extends BaseDistributedSearchTes
@Override
protected void createServers(int numShards) throws Exception {
// give everyone there own solrhome
- File controlHome = new File(new File(getSolrHome()).getParentFile(), "control" + homeCount.incrementAndGet());
+ File controlHome =
+ new File(new File(getSolrHome()).getParentFile(), "control" + homeCount.incrementAndGet());
FileUtils.copyDirectory(new File(getSolrHome()), controlHome);
setupJettySolrHome(controlHome);
- controlJetty = createJetty(controlHome, null); // let the shardId default to shard1
+ controlJetty = createJetty(controlHome, null); // let the shardId default to shard1
controlJetty.start();
controlClient = createNewSolrClient(controlJetty.getLocalPort());
- assertTrue(CollectionAdminRequest
- .createCollection("control_collection", 1, 1)
- .setCreateNodeSet(controlJetty.getNodeName())
- .process(controlClient).isSuccess());
+ assertTrue(
+ CollectionAdminRequest.createCollection("control_collection", 1, 1)
+ .setCreateNodeSet(controlJetty.getNodeName())
+ .process(controlClient)
+ .isSuccess());
- ZkStateReader zkStateReader = jettys.get(0).getCoreContainer().getZkController()
- .getZkStateReader();
+ ZkStateReader zkStateReader =
+ jettys.get(0).getCoreContainer().getZkController().getZkStateReader();
waitForRecoveriesToFinish("control_collection", zkStateReader, false, true, 15);
@@ -121,7 +123,8 @@ public abstract class AbstractDistribZkTestBase extends BaseDistributedSearchTes
for (int i = 1; i <= numShards; i++) {
if (sb.length() > 0) sb.append(',');
// give everyone there own solrhome
- File jettyHome = new File(new File(getSolrHome()).getParentFile(), "jetty" + homeCount.incrementAndGet());
+ File jettyHome =
+ new File(new File(getSolrHome()).getParentFile(), "jetty" + homeCount.incrementAndGet());
setupJettySolrHome(jettyHome);
JettySolrRunner j = createJetty(jettyHome, null, "shard" + (i + 2));
j.start();
@@ -131,66 +134,90 @@ public abstract class AbstractDistribZkTestBase extends BaseDistributedSearchTes
}
shards = sb.toString();
-
}
- protected void waitForRecoveriesToFinish(String collection, ZkStateReader zkStateReader, boolean verbose)
- throws Exception {
+ protected void waitForRecoveriesToFinish(
+ String collection, ZkStateReader zkStateReader, boolean verbose) throws Exception {
waitForRecoveriesToFinish(collection, zkStateReader, verbose, true);
}
- protected void waitForRecoveriesToFinish(String collection, ZkStateReader zkStateReader, boolean verbose, boolean failOnTimeout)
+ protected void waitForRecoveriesToFinish(
+ String collection, ZkStateReader zkStateReader, boolean verbose, boolean failOnTimeout)
throws Exception {
waitForRecoveriesToFinish(collection, zkStateReader, verbose, failOnTimeout, 330, SECONDS);
}
- public static void waitForRecoveriesToFinish(String collection,
- ZkStateReader zkStateReader, boolean verbose, boolean failOnTimeout, long timeoutSeconds)
+ public static void waitForRecoveriesToFinish(
+ String collection,
+ ZkStateReader zkStateReader,
+ boolean verbose,
+ boolean failOnTimeout,
+ long timeoutSeconds)
throws Exception {
- waitForRecoveriesToFinish(collection, zkStateReader, verbose, failOnTimeout, timeoutSeconds, SECONDS);
+ waitForRecoveriesToFinish(
+ collection, zkStateReader, verbose, failOnTimeout, timeoutSeconds, SECONDS);
}
- public static void waitForRecoveriesToFinish(String collection,
- ZkStateReader zkStateReader, boolean verbose, boolean failOnTimeout, long timeout, TimeUnit unit)
- throws Exception {
- log.info("Wait for recoveries to finish - collection:{} failOnTimeout:{} timeout:{}{}",
- collection, failOnTimeout, timeout, unit);
+ public static void waitForRecoveriesToFinish(
+ String collection,
+ ZkStateReader zkStateReader,
+ boolean verbose,
+ boolean failOnTimeout,
+ long timeout,
+ TimeUnit unit)
+ throws Exception {
+ log.info(
+ "Wait for recoveries to finish - collection:{} failOnTimeout:{} timeout:{}{}",
+ collection,
+ failOnTimeout,
+ timeout,
+ unit);
try {
- zkStateReader.waitForState(collection, timeout, unit, (liveNodes, docCollection) -> {
- if (docCollection == null)
- return false;
- boolean sawLiveRecovering = false;
-
- Map<String,Slice> slices = docCollection.getSlicesMap();
- assertNotNull("Could not find collection:" + collection, slices);
- for (Map.Entry<String,Slice> entry : slices.entrySet()) {
- Slice slice = entry.getValue();
- if (slice.getState() == Slice.State.CONSTRUCTION) { // similar to replica recovering; pretend its the same
- // thing
- if (verbose) System.out.println("Found a slice in construction state; will wait.");
- sawLiveRecovering = true;
- }
- Map<String,Replica> shards = slice.getReplicasMap();
- for (Map.Entry<String,Replica> shard : shards.entrySet()) {
- if (verbose) System.out.println("replica:" + shard.getValue().getName() + " rstate:"
- + shard.getValue().getStr(ZkStateReader.STATE_PROP)
- + " live:"
- + liveNodes.contains(shard.getValue().getNodeName()));
- final Replica.State state = shard.getValue().getState();
- if ((state == Replica.State.RECOVERING || state == Replica.State.DOWN
- || state == Replica.State.RECOVERY_FAILED)
- && liveNodes.contains(shard.getValue().getStr(ZkStateReader.NODE_NAME_PROP))) {
+ zkStateReader.waitForState(
+ collection,
+ timeout,
+ unit,
+ (liveNodes, docCollection) -> {
+ if (docCollection == null) return false;
+ boolean sawLiveRecovering = false;
+
+ Map<String, Slice> slices = docCollection.getSlicesMap();
+ assertNotNull("Could not find collection:" + collection, slices);
+ for (Map.Entry<String, Slice> entry : slices.entrySet()) {
+ Slice slice = entry.getValue();
+ if (slice.getState()
+ == Slice.State
+ .CONSTRUCTION) { // similar to replica recovering; pretend its the same
+ // thing
+ if (verbose) System.out.println("Found a slice in construction state; will wait.");
+ sawLiveRecovering = true;
+ }
+ Map<String, Replica> shards = slice.getReplicasMap();
+ for (Map.Entry<String, Replica> shard : shards.entrySet()) {
+ if (verbose)
+ System.out.println(
+ "replica:"
+ + shard.getValue().getName()
+ + " rstate:"
+ + shard.getValue().getStr(ZkStateReader.STATE_PROP)
+ + " live:"
+ + liveNodes.contains(shard.getValue().getNodeName()));
+ final Replica.State state = shard.getValue().getState();
+ if ((state == Replica.State.RECOVERING
+ || state == Replica.State.DOWN
+ || state == Replica.State.RECOVERY_FAILED)
+ && liveNodes.contains(shard.getValue().getStr(ZkStateReader.NODE_NAME_PROP))) {
+ return false;
+ }
+ }
+ }
+ if (!sawLiveRecovering) {
+ if (verbose) System.out.println("no one is recoverying");
+ return true;
+ } else {
return false;
}
- }
- }
- if (!sawLiveRecovering) {
- if (verbose) System.out.println("no one is recoverying");
- return true;
- } else {
- return false;
- }
- });
+ });
} catch (TimeoutException | InterruptedException e) {
Diagnostics.logThreadDumps("Gave up waiting for recovery to finish. THREAD DUMP:");
zkStateReader.getZkClient().printLayoutToStream(System.out);
@@ -200,18 +227,22 @@ public abstract class AbstractDistribZkTestBase extends BaseDistributedSearchTes
log.info("Recoveries finished - collection:{}", collection);
}
-
- public static void waitForCollectionToDisappear(String collection,
- ZkStateReader zkStateReader, boolean failOnTimeout, int timeoutSeconds)
+ public static void waitForCollectionToDisappear(
+ String collection, ZkStateReader zkStateReader, boolean failOnTimeout, int timeoutSeconds)
throws Exception {
- log.info("Wait for collection to disappear - collection: {} failOnTimeout:{} timeout (sec):{}"
- , collection, failOnTimeout, timeoutSeconds);
-
- zkStateReader.waitForState(collection, timeoutSeconds, TimeUnit.SECONDS, (docCollection) -> docCollection == null);
+ log.info(
+ "Wait for collection to disappear - collection: {} failOnTimeout:{} timeout (sec):{}",
+ collection,
+ failOnTimeout,
+ timeoutSeconds);
+
+ zkStateReader.waitForState(
+ collection, timeoutSeconds, TimeUnit.SECONDS, (docCollection) -> docCollection == null);
log.info("Collection has disappeared - collection:{}", collection);
}
- static void waitForNewLeader(CloudSolrClient cloudClient, String shardName, Replica oldLeader, TimeOut timeOut)
+ static void waitForNewLeader(
+ CloudSolrClient cloudClient, String shardName, Replica oldLeader, TimeOut timeOut)
throws Exception {
log.info("Will wait for a node to become leader for {} secs", timeOut.timeLeft(SECONDS));
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
@@ -221,10 +252,15 @@ public abstract class AbstractDistribZkTestBase extends BaseDistributedSearchTes
ClusterState clusterState = zkStateReader.getClusterState();
DocCollection coll = clusterState.getCollection("collection1");
Slice slice = coll.getSlice(shardName);
- if (slice.getLeader() != null && !slice.getLeader().equals(oldLeader) && slice.getLeader().getState() == Replica.State.ACTIVE) {
+ if (slice.getLeader() != null
+ && !slice.getLeader().equals(oldLeader)
+ && slice.getLeader().getState() == Replica.State.ACTIVE) {
if (log.isInfoEnabled()) {
- log.info("Old leader {}, new leader {}. New leader got elected in {} ms"
- , oldLeader, slice.getLeader(), timeOut.timeElapsed(MILLISECONDS));
+ log.info(
+ "Old leader {}, new leader {}. New leader got elected in {} ms",
+ oldLeader,
+ slice.getLeader(),
+ timeOut.timeElapsed(MILLISECONDS));
}
break;
}
@@ -232,61 +268,92 @@ public abstract class AbstractDistribZkTestBase extends BaseDistributedSearchTes
if (timeOut.hasTimedOut()) {
Diagnostics.logThreadDumps("Could not find new leader in specified timeout");
zkStateReader.getZkClient().printLayoutToStream(System.out);
- fail("Could not find new leader even after waiting for " + timeOut.timeElapsed(MILLISECONDS) + "ms");
+ fail(
+ "Could not find new leader even after waiting for "
+ + timeOut.timeElapsed(MILLISECONDS)
+ + "ms");
}
Thread.sleep(100);
}
- zkStateReader.waitForState("collection1", timeOut.timeLeft(SECONDS), TimeUnit.SECONDS, (docCollection) -> {
- if (docCollection == null)
- return false;
-
- Slice slice = docCollection.getSlice(shardName);
- if (slice != null && slice.getLeader() != null && !slice.getLeader().equals(oldLeader) && slice.getLeader().getState() == Replica.State.ACTIVE) {
- if (log.isInfoEnabled()) {
- log.info("Old leader {}, new leader {}. New leader got elected in {} ms"
- , oldLeader, slice.getLeader(), timeOut.timeElapsed(MILLISECONDS));
- }
- return true;
- }
- return false;
- });
+ zkStateReader.waitForState(
+ "collection1",
+ timeOut.timeLeft(SECONDS),
+ TimeUnit.SECONDS,
+ (docCollection) -> {
+ if (docCollection == null) return false;
+
+ Slice slice = docCollection.getSlice(shardName);
+ if (slice != null
+ && slice.getLeader() != null
+ && !slice.getLeader().equals(oldLeader)
+ && slice.getLeader().getState() == Replica.State.ACTIVE) {
+ if (log.isInfoEnabled()) {
+ log.info(
+ "Old leader {}, new leader {}. New leader got elected in {} ms",
+ oldLeader,
+ slice.getLeader(),
+ timeOut.timeElapsed(MILLISECONDS));
+ }
+ return true;
+ }
+ return false;
+ });
}
- public static void verifyReplicaStatus(ZkStateReader reader, String collection, String shard, String coreNodeName,
- Replica.State expectedState) throws InterruptedException, TimeoutException {
+ public static void verifyReplicaStatus(
+ ZkStateReader reader,
+ String collection,
+ String shard,
+ String coreNodeName,
+ Replica.State expectedState)
+ throws InterruptedException, TimeoutException {
log.info("verifyReplicaStatus ({}) shard={} coreNodeName={}", collection, shard, coreNodeName);
- reader.waitForState(collection, 15000, TimeUnit.MILLISECONDS,
- (collectionState) -> collectionState != null && collectionState.getSlice(shard) != null
- && collectionState.getSlice(shard).getReplicasMap().get(coreNodeName) != null
- && collectionState.getSlice(shard).getReplicasMap().get(coreNodeName).getState() == expectedState);
+ reader.waitForState(
+ collection,
+ 15000,
+ TimeUnit.MILLISECONDS,
+ (collectionState) ->
+ collectionState != null
+ && collectionState.getSlice(shard) != null
+ && collectionState.getSlice(shard).getReplicasMap().get(coreNodeName) != null
+ && collectionState.getSlice(shard).getReplicasMap().get(coreNodeName).getState()
+ == expectedState);
}
protected static void assertAllActive(String collection, ZkStateReader zkStateReader)
throws KeeperException, InterruptedException {
- zkStateReader.forceUpdateCollection(collection);
- ClusterState clusterState = zkStateReader.getClusterState();
- final DocCollection docCollection = clusterState.getCollectionOrNull(collection);
- if (docCollection == null || docCollection.getSlices() == null) {
- throw new IllegalArgumentException("Cannot find collection:" + collection);
- }
+ zkStateReader.forceUpdateCollection(collection);
+ ClusterState clusterState = zkStateReader.getClusterState();
+ final DocCollection docCollection = clusterState.getCollectionOrNull(collection);
+ if (docCollection == null || docCollection.getSlices() == null) {
+ throw new IllegalArgumentException("Cannot find collection:" + collection);
+ }
- Map<String,Slice> slices = docCollection.getSlicesMap();
- for (Map.Entry<String,Slice> entry : slices.entrySet()) {
- Slice slice = entry.getValue();
- if (slice.getState() != Slice.State.ACTIVE) {
- fail("Not all shards are ACTIVE - found a shard " + slice.getName() + " that is: " + slice.getState());
- }
- Map<String,Replica> shards = slice.getReplicasMap();
- for (Map.Entry<String,Replica> shard : shards.entrySet()) {
- Replica replica = shard.getValue();
- if (replica.getState() != Replica.State.ACTIVE) {
- fail("Not all replicas are ACTIVE - found a replica " + replica.getName() + " that is: " + replica.getState());
- }
+ Map<String, Slice> slices = docCollection.getSlicesMap();
+ for (Map.Entry<String, Slice> entry : slices.entrySet()) {
+ Slice slice = entry.getValue();
+ if (slice.getState() != Slice.State.ACTIVE) {
+ fail(
+ "Not all shards are ACTIVE - found a shard "
+ + slice.getName()
+ + " that is: "
+ + slice.getState());
+ }
+ Map<String, Replica> shards = slice.getReplicasMap();
+ for (Map.Entry<String, Replica> shard : shards.entrySet()) {
+ Replica replica = shard.getValue();
+ if (replica.getState() != Replica.State.ACTIVE) {
+ fail(
+ "Not all replicas are ACTIVE - found a replica "
+ + replica.getName()
+ + " that is: "
+ + replica.getState());
}
}
+ }
}
@Override
@@ -309,10 +376,9 @@ public abstract class AbstractDistribZkTestBase extends BaseDistributedSearchTes
System.clearProperty("solr.test.sys.prop1");
System.clearProperty("solr.test.sys.prop2");
System.clearProperty(ZOOKEEPER_FORCE_SYNC);
- System.clearProperty(MockDirectoryFactory.SOLR_TESTS_ALLOW_READING_FILES_STILL_OPEN_FOR_WRITE);
-
+ System.clearProperty(
+ MockDirectoryFactory.SOLR_TESTS_ALLOW_READING_FILES_STILL_OPEN_FOR_WRITE);
}
-
}
}
@@ -331,25 +397,28 @@ public abstract class AbstractDistribZkTestBase extends BaseDistributedSearchTes
zkServer.run(false);
}
-
// Copy a configset up from some path on the local machine to ZK.
// Example usage:
//
// copyConfigUp(TEST_PATH().resolve("configsets"), "cloud-minimal", "configset-name", zk_address);
- static protected void copyConfigUp(Path configSetDir, String srcConfigSet, String dstConfigName, String zkAddr) throws Exception {
- String[] args = new String[]{
- "-confname", dstConfigName,
- "-confdir", srcConfigSet,
- "-zkHost", zkAddr,
- "-configsetsDir", configSetDir.toString(),
- };
+ protected static void copyConfigUp(
+ Path configSetDir, String srcConfigSet, String dstConfigName, String zkAddr)
+ throws Exception {
+ String[] args =
+ new String[] {
+ "-confname", dstConfigName,
+ "-confdir", srcConfigSet,
+ "-zkHost", zkAddr,
+ "-configsetsDir", configSetDir.toString(),
+ };
SolrCLI.ConfigSetUploadTool tool = new SolrCLI.ConfigSetUploadTool();
- int res = tool.runTool(SolrCLI.processCommandLineArgs(tool.getName(), SolrCLI.joinCommonAndToolOptions(tool.getOptions()), args));
+ int res =
+ tool.runTool(
+ SolrCLI.processCommandLineArgs(
+ tool.getName(), SolrCLI.joinCommonAndToolOptions(tool.getOptions()), args));
assertEquals("Tool should have returned 0 for success, returned: " + res, res, 0);
-
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
index 65c948dc074..a462be344ec 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
@@ -43,7 +43,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
-
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
@@ -110,18 +109,16 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * TODO: we should still test this works as a custom update chain as well as
- * what we test now - the default update chain
+ * TODO: we should still test this works as a custom update chain as well as what we test now - the
+ * default update chain
*/
@Slow
public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTestBase {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@BeforeClass
- public static void beforeFullSolrCloudTest() {
+ public static void beforeFullSolrCloudTest() {}
- }
-
@Before
public void beforeTest() {
cloudInit = false;
@@ -140,20 +137,22 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
String missingField = "ignore_exception__missing_but_valid_field_t";
protected int sliceCount;
- protected volatile CloudSolrClient controlClientCloud; // cloud version of the control client
+ protected volatile CloudSolrClient controlClientCloud; // cloud version of the control client
protected volatile CloudSolrClient cloudClient;
protected final List<SolrClient> coreClients = Collections.synchronizedList(new ArrayList<>());
-
- protected final List<CloudJettyRunner> cloudJettys = Collections.synchronizedList(new ArrayList<>());
- protected final Map<String,List<CloudJettyRunner>> shardToJetty = new ConcurrentHashMap<>();
+
+ protected final List<CloudJettyRunner> cloudJettys =
+ Collections.synchronizedList(new ArrayList<>());
+ protected final Map<String, List<CloudJettyRunner>> shardToJetty = new ConcurrentHashMap<>();
private AtomicInteger jettyIntCntr = new AtomicInteger(0);
protected volatile ChaosMonkey chaosMonkey;
- protected Map<String,CloudJettyRunner> shardToLeaderJetty = new ConcurrentHashMap<>();
+ protected Map<String, CloudJettyRunner> shardToLeaderJetty = new ConcurrentHashMap<>();
private static volatile boolean cloudInit;
protected volatile boolean useJettyDataDir = true;
- private final List<RestTestHarness> restTestHarnesses = Collections.synchronizedList(new ArrayList<>());
+ private final List<RestTestHarness> restTestHarnesses =
+ Collections.synchronizedList(new ArrayList<>());
public static class CloudJettyRunner {
public JettySolrRunner jetty;
@@ -162,6 +161,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
public String url;
public CloudSolrServerClient client;
public ZkNodeProps info;
+
@Override
public int hashCode() {
final int prime = 31;
@@ -169,6 +169,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
result = prime * result + ((url == null) ? 0 : url.hashCode());
return result;
}
+
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
@@ -180,6 +181,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
} else if (!url.equals(other.url)) return false;
return true;
}
+
@Override
public String toString() {
return "CloudJettyRunner [url=" + url + "]";
@@ -193,7 +195,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
public ZkNodeProps info;
public CloudSolrServerClient() {}
-
+
public CloudSolrServerClient(SolrClient client) {
this.solrClient = client;
}
@@ -221,21 +223,22 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
} else if (!solrClient.equals(other.solrClient)) return false;
return true;
}
-
}
protected static void setErrorHook() {
- SolrCmdDistributor.testing_errorHook = new Diagnostics.Callable() {
- @Override
- public void call(Object... data) {
- Exception e = (Exception) data[0];
- if (e == null) return;
- String msg = e.getMessage();
- if (msg != null && msg.contains("Timeout")) {
- Diagnostics.logThreadDumps("REQUESTING THREAD DUMP DUE TO TIMEOUT: " + e.getMessage());
- }
- }
- };
+ SolrCmdDistributor.testing_errorHook =
+ new Diagnostics.Callable() {
+ @Override
+ public void call(Object... data) {
+ Exception e = (Exception) data[0];
+ if (e == null) return;
+ String msg = e.getMessage();
+ if (msg != null && msg.contains("Timeout")) {
+ Diagnostics.logThreadDumps(
+ "REQUESTING THREAD DUMP DUE TO TIMEOUT: " + e.getMessage());
+ }
+ }
+ };
}
protected static void clearErrorHook() {
@@ -246,9 +249,9 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
public void distribSetUp() throws Exception {
super.distribSetUp();
// ignoreException(".*");
-
+
cloudInit = false;
-
+
if (sliceCount > 0) {
System.setProperty("numShards", Integer.toString(sliceCount));
} else {
@@ -257,16 +260,27 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
if (isSSLMode()) {
System.clearProperty(URL_SCHEME);
- try (ZkStateReader zkStateReader = new ZkStateReader(zkServer.getZkAddress(),
- AbstractZkTestCase.TIMEOUT, AbstractZkTestCase.TIMEOUT)) {
+ try (ZkStateReader zkStateReader =
+ new ZkStateReader(
+ zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT, AbstractZkTestCase.TIMEOUT)) {
try {
- zkStateReader.getZkClient().create(ZkStateReader.CLUSTER_PROPS,
- Utils.toJSON(Collections.singletonMap(URL_SCHEME, HTTPS)),
- CreateMode.PERSISTENT, true);
+ zkStateReader
+ .getZkClient()
+ .create(
+ ZkStateReader.CLUSTER_PROPS,
+ Utils.toJSON(Collections.singletonMap(URL_SCHEME, HTTPS)),
+ CreateMode.PERSISTENT,
+ true);
} catch (KeeperException.NodeExistsException e) {
- ZkNodeProps props = ZkNodeProps.load(zkStateReader.getZkClient().getData(ZkStateReader.CLUSTER_PROPS,
- null, null, true));
- zkStateReader.getZkClient().setData(ZkStateReader.CLUSTER_PROPS, Utils.toJSON(props.plus(URL_SCHEME, HTTPS)), true);
+ ZkNodeProps props =
+ ZkNodeProps.load(
+ zkStateReader
+ .getZkClient()
+ .getData(ZkStateReader.CLUSTER_PROPS, null, null, true));
+ zkStateReader
+ .getZkClient()
+ .setData(
+ ZkStateReader.CLUSTER_PROPS, Utils.toJSON(props.plus(URL_SCHEME, HTTPS)), true);
}
}
}
@@ -304,23 +318,25 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
}
protected void initCloud() throws Exception {
- assert(cloudInit == false);
+ assert (cloudInit == false);
cloudInit = true;
cloudClient = createCloudClient(DEFAULT_COLLECTION);
cloudClient.connect();
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
- chaosMonkey = new ChaosMonkey(zkServer, zkStateReader, DEFAULT_COLLECTION,
- shardToJetty, shardToLeaderJetty);
+ chaosMonkey =
+ new ChaosMonkey(
+ zkServer, zkStateReader, DEFAULT_COLLECTION, shardToJetty, shardToLeaderJetty);
}
protected boolean useTlogReplicas() {
return false;
}
-
+
protected CloudSolrClient createCloudClient(String defaultCollection) {
- CloudSolrClient client = getCloudSolrClient(zkServer.getZkAddress(), random().nextBoolean(), 30000, 120000);
+ CloudSolrClient client =
+ getCloudSolrClient(zkServer.getZkAddress(), random().nextBoolean(), 30000, 120000);
if (defaultCollection != null) client.setDefaultCollection(defaultCollection);
return client;
}
@@ -329,19 +345,22 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
protected void createServers(int numServers) throws Exception {
File controlJettyDir = createTempDir("control").toFile();
setupJettySolrHome(controlJettyDir);
- controlJetty = createJetty(controlJettyDir, useJettyDataDir ? getDataDir(testDir
- + "/control/data") : null);
+ controlJetty =
+ createJetty(
+ controlJettyDir, useJettyDataDir ? getDataDir(testDir + "/control/data") : null);
controlJetty.start();
try (CloudSolrClient client = createCloudClient("control_collection")) {
- assertEquals(0, CollectionAdminRequest
- .createCollection("control_collection", "conf1", 1, 1)
- .setCreateNodeSet(controlJetty.getNodeName())
- .process(client).getStatus());
+ assertEquals(
+ 0,
+ CollectionAdminRequest.createCollection("control_collection", "conf1", 1, 1)
+ .setCreateNodeSet(controlJetty.getNodeName())
+ .process(client)
+ .getStatus());
waitForActiveReplicaCount(client, "control_collection", 1);
}
-
- controlClient = new HttpSolrClient.Builder(controlJetty.getBaseUrl() + "/control_collection").build();
+ controlClient =
+ new HttpSolrClient.Builder(controlJetty.getBaseUrl() + "/control_collection").build();
if (sliceCount <= 0) {
// for now, just create the cloud client for the control if we don't
// create the normal cloud client.
@@ -357,27 +376,34 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
initCloud();
createJettys(numServers);
-
}
- public static void waitForCollection(ZkStateReader reader, String collection, int slices) throws Exception {
+ public static void waitForCollection(ZkStateReader reader, String collection, int slices)
+ throws Exception {
log.info("waitForCollection ({}): slices={}", collection, slices);
// wait until shards have started registering...
int cnt = 30;
while (!reader.getClusterState().hasCollection(collection)) {
if (cnt == 0) {
- throw new RuntimeException("timeout waiting for collection in cluster state: collection=" + collection);
+ throw new RuntimeException(
+ "timeout waiting for collection in cluster state: collection=" + collection);
}
cnt--;
Thread.sleep(500);
}
cnt = 30;
-
+
while (reader.getClusterState().getCollection(collection).getSlices().size() < slices) {
if (cnt == 0) {
- throw new RuntimeException("timeout waiting for collection shards to come up: collection="+collection
- + ", slices.expected="+slices+ " slices.actual= " + reader.getClusterState().getCollection(collection).getSlices().size()
- + " slices : "+ reader.getClusterState().getCollection(collection).getSlices() );
+ throw new RuntimeException(
+ "timeout waiting for collection shards to come up: collection="
+ + collection
+ + ", slices.expected="
+ + slices
+ + " slices.actual= "
+ + reader.getClusterState().getCollection(collection).getSlices().size()
+ + " slices : "
+ + reader.getClusterState().getCollection(collection).getSlices());
}
cnt--;
Thread.sleep(500);
@@ -387,8 +413,10 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
protected List<JettySolrRunner> createJettys(int numJettys) throws Exception {
List<JettySolrRunner> jettys = Collections.synchronizedList(new ArrayList<>());
List<SolrClient> clients = Collections.synchronizedList(new ArrayList<>());
- List<CollectionAdminRequest<CollectionAdminResponse>> createReplicaRequests = Collections.synchronizedList(new ArrayList<>());
- List<CollectionAdminRequest<CollectionAdminResponse>> createPullReplicaRequests = Collections.synchronizedList(new ArrayList<>());
+ List<CollectionAdminRequest<CollectionAdminResponse>> createReplicaRequests =
+ Collections.synchronizedList(new ArrayList<>());
+ List<CollectionAdminRequest<CollectionAdminResponse>> createPullReplicaRequests =
+ Collections.synchronizedList(new ArrayList<>());
StringBuilder sb = new StringBuilder();
// HACK: Don't be fooled by the replication factor of '1'...
@@ -397,24 +425,33 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
// This allows this method to create a collection with numShards == sliceCount,
// but no actual cores ... yet. The actual replicas are added later (once the actual
// jetty instances are started)
- assertEquals(0, CollectionAdminRequest
- .createCollection(DEFAULT_COLLECTION, "conf1", sliceCount, 1) // not real rep factor!
- .setCreateNodeSet("") // empty node set prevents creation of cores
- .process(cloudClient).getStatus());
-
- cloudClient.waitForState(DEFAULT_COLLECTION, 30, TimeUnit.SECONDS,
- // expect sliceCount active shards, but no active replicas
- SolrCloudTestCase.activeClusterShape(sliceCount, 0));
-
- ExecutorService customThreadPool = ExecutorUtil.newMDCAwareCachedThreadPool(new SolrNamedThreadFactory("closeThreadPool"));
+ assertEquals(
+ 0,
+ CollectionAdminRequest.createCollection(
+ DEFAULT_COLLECTION, "conf1", sliceCount, 1) // not real rep factor!
+ .setCreateNodeSet("") // empty node set prevents creation of cores
+ .process(cloudClient)
+ .getStatus());
+
+ cloudClient.waitForState(
+ DEFAULT_COLLECTION,
+ 30,
+ TimeUnit.SECONDS,
+ // expect sliceCount active shards, but no active replicas
+ SolrCloudTestCase.activeClusterShape(sliceCount, 0));
+
+ ExecutorService customThreadPool =
+ ExecutorUtil.newMDCAwareCachedThreadPool(new SolrNamedThreadFactory("closeThreadPool"));
int numOtherReplicas = numJettys - getPullReplicaCount() * sliceCount;
if (log.isInfoEnabled()) {
- log.info("Creating jetty instances pullReplicaCount={} numOtherReplicas={}"
- , getPullReplicaCount(), numOtherReplicas);
+ log.info(
+ "Creating jetty instances pullReplicaCount={} numOtherReplicas={}",
+ getPullReplicaCount(),
+ numOtherReplicas);
}
-
+
int addedReplicas = 0;
for (int i = 1; i <= numJettys; i++) {
if (sb.length() > 0) sb.append(',');
@@ -429,140 +466,180 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
numOtherReplicas--;
if (useTlogReplicas()) {
if (log.isInfoEnabled()) {
- log.info("create jetty {} in directory {} of type {} in shard {}"
- , i, jettyDir, Replica.Type.TLOG, ((currentI % sliceCount) + 1)); // nowarn
+ log.info(
+ "create jetty {} in directory {} of type {} in shard {}",
+ i,
+ jettyDir,
+ Replica.Type.TLOG,
+ ((currentI % sliceCount) + 1)); // nowarn
}
- customThreadPool.submit(() -> {
- try {
- JettySolrRunner j = createJetty(jettyDir, useJettyDataDir ? getDataDir(testDir + "/jetty"
- + cnt) : null, null, "solrconfig.xml", null, Replica.Type.TLOG);
- j.start();
- jettys.add(j);
- waitForLiveNode(j);
-
- createReplicaRequests.add(CollectionAdminRequest
- .addReplicaToShard(DEFAULT_COLLECTION, "shard" + ((currentI % sliceCount) + 1))
- .setNode(j.getNodeName())
- .setType(Replica.Type.TLOG));
-
- coreClients.add(createNewSolrClient(coreName, j.getLocalPort()));
- SolrClient client = createNewSolrClient(j.getLocalPort());
- clients.add(client);
-
- } catch (IOException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- });
+ customThreadPool.submit(
+ () -> {
+ try {
+ JettySolrRunner j =
+ createJetty(
+ jettyDir,
+ useJettyDataDir ? getDataDir(testDir + "/jetty" + cnt) : null,
+ null,
+ "solrconfig.xml",
+ null,
+ Replica.Type.TLOG);
+ j.start();
+ jettys.add(j);
+ waitForLiveNode(j);
+
+ createReplicaRequests.add(
+ CollectionAdminRequest.addReplicaToShard(
+ DEFAULT_COLLECTION, "shard" + ((currentI % sliceCount) + 1))
+ .setNode(j.getNodeName())
+ .setType(Replica.Type.TLOG));
+
+ coreClients.add(createNewSolrClient(coreName, j.getLocalPort()));
+ SolrClient client = createNewSolrClient(j.getLocalPort());
+ clients.add(client);
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+ });
addedReplicas++;
} else {
if (log.isInfoEnabled()) {
- log.info("create jetty {} in directory {} of type {} for shard{}"
- , i, jettyDir, Replica.Type.NRT, ((currentI % sliceCount) + 1)); // nowarn
+ log.info(
+ "create jetty {} in directory {} of type {} for shard{}",
+ i,
+ jettyDir,
+ Replica.Type.NRT,
+ ((currentI % sliceCount) + 1)); // nowarn
}
-
- customThreadPool.submit(() -> {
- try {
- JettySolrRunner j = createJetty(jettyDir, useJettyDataDir ? getDataDir(testDir + "/jetty"
- + cnt) : null, null, "solrconfig.xml", null, null);
- j.start();
- jettys.add(j);
- waitForLiveNode(j);
- createReplicaRequests.add(CollectionAdminRequest
- .addReplicaToShard(DEFAULT_COLLECTION, "shard"+((currentI%sliceCount)+1))
- .setNode(j.getNodeName())
- .setType(Replica.Type.NRT));
- coreClients.add(createNewSolrClient(coreName, j.getLocalPort()));
- SolrClient client = createNewSolrClient(j.getLocalPort());
- clients.add(client);
- } catch (IOException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- });
-
+
+ customThreadPool.submit(
+ () -> {
+ try {
+ JettySolrRunner j =
+ createJetty(
+ jettyDir,
+ useJettyDataDir ? getDataDir(testDir + "/jetty" + cnt) : null,
+ null,
+ "solrconfig.xml",
+ null,
+ null);
+ j.start();
+ jettys.add(j);
+ waitForLiveNode(j);
+ createReplicaRequests.add(
+ CollectionAdminRequest.addReplicaToShard(
+ DEFAULT_COLLECTION, "shard" + ((currentI % sliceCount) + 1))
+ .setNode(j.getNodeName())
+ .setType(Replica.Type.NRT));
+ coreClients.add(createNewSolrClient(coreName, j.getLocalPort()));
+ SolrClient client = createNewSolrClient(j.getLocalPort());
+ clients.add(client);
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+ });
+
addedReplicas++;
}
} else {
- log.info("create jetty {} in directory {} of type {} for shard{}", i, jettyDir, Replica.Type.PULL, ((currentI % sliceCount) + 1)); // nowarn
- customThreadPool.submit(() -> {
- try {
- JettySolrRunner j = createJetty(jettyDir, useJettyDataDir ? getDataDir(testDir + "/jetty"
- + cnt) : null, null, "solrconfig.xml", null, Replica.Type.PULL);
- j.start();
- jettys.add(j);
- waitForLiveNode(j);
- createPullReplicaRequests.add(CollectionAdminRequest
- .addReplicaToShard(DEFAULT_COLLECTION, "shard"+((currentI%sliceCount)+1))
- .setNode(j.getNodeName())
- .setType(Replica.Type.PULL));
- coreClients.add(createNewSolrClient(coreName, j.getLocalPort()));
- SolrClient client = createNewSolrClient(j.getLocalPort());
- clients.add(client);
- } catch (IOException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- });
+ log.info(
+ "create jetty {} in directory {} of type {} for shard{}",
+ i,
+ jettyDir,
+ Replica.Type.PULL,
+ ((currentI % sliceCount) + 1)); // nowarn
+ customThreadPool.submit(
+ () -> {
+ try {
+ JettySolrRunner j =
+ createJetty(
+ jettyDir,
+ useJettyDataDir ? getDataDir(testDir + "/jetty" + cnt) : null,
+ null,
+ "solrconfig.xml",
+ null,
+ Replica.Type.PULL);
+ j.start();
+ jettys.add(j);
+ waitForLiveNode(j);
+ createPullReplicaRequests.add(
+ CollectionAdminRequest.addReplicaToShard(
+ DEFAULT_COLLECTION, "shard" + ((currentI % sliceCount) + 1))
+ .setNode(j.getNodeName())
+ .setType(Replica.Type.PULL));
+ coreClients.add(createNewSolrClient(coreName, j.getLocalPort()));
+ SolrClient client = createNewSolrClient(j.getLocalPort());
+ clients.add(client);
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+ });
addedReplicas++;
}
-
}
-
+
ExecutorUtil.shutdownAndAwaitTermination(customThreadPool);
-
- customThreadPool = ExecutorUtil.newMDCAwareCachedThreadPool(new SolrNamedThreadFactory("createReplicaRequests"));
-
+
+ customThreadPool =
+ ExecutorUtil.newMDCAwareCachedThreadPool(
+ new SolrNamedThreadFactory("createReplicaRequests"));
+
for (CollectionAdminRequest<CollectionAdminResponse> r : createReplicaRequests) {
- customThreadPool.submit(() -> {
- CollectionAdminResponse response;
- try {
- response = r.process(cloudClient);
- } catch (SolrServerException | IOException e) {
- throw new RuntimeException(e);
- }
+ customThreadPool.submit(
+ () -> {
+ CollectionAdminResponse response;
+ try {
+ response = r.process(cloudClient);
+ } catch (SolrServerException | IOException e) {
+ throw new RuntimeException(e);
+ }
- assertTrue(response.isSuccess());
- String coreName = response.getCollectionCoresStatus().keySet().iterator().next();
- });
+ assertTrue(response.isSuccess());
+ String coreName = response.getCollectionCoresStatus().keySet().iterator().next();
+ });
}
-
+
ExecutorUtil.shutdownAndAwaitTermination(customThreadPool);
-
- customThreadPool = ExecutorUtil
- .newMDCAwareCachedThreadPool(new SolrNamedThreadFactory("createPullReplicaRequests"));
+
+ customThreadPool =
+ ExecutorUtil.newMDCAwareCachedThreadPool(
+ new SolrNamedThreadFactory("createPullReplicaRequests"));
for (CollectionAdminRequest<CollectionAdminResponse> r : createPullReplicaRequests) {
- customThreadPool.submit(() -> {
- CollectionAdminResponse response;
- try {
- response = r.process(cloudClient);
- } catch (SolrServerException | IOException e) {
- throw new RuntimeException(e);
- }
+ customThreadPool.submit(
+ () -> {
+ CollectionAdminResponse response;
+ try {
+ response = r.process(cloudClient);
+ } catch (SolrServerException | IOException e) {
+ throw new RuntimeException(e);
+ }
- assertTrue(response.isSuccess());
- String coreName = response.getCollectionCoresStatus().keySet().iterator().next();
- });
+ assertTrue(response.isSuccess());
+ String coreName = response.getCollectionCoresStatus().keySet().iterator().next();
+ });
}
-
+
ExecutorUtil.shutdownAndAwaitTermination(customThreadPool);
-
+
waitForActiveReplicaCount(cloudClient, DEFAULT_COLLECTION, addedReplicas);
this.jettys.addAll(jettys);
this.clients.addAll(clients);
-
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
// make sure we have a leader for each shard
for (int i = 1; i <= sliceCount; i++) {
@@ -590,53 +667,69 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
if (log.isInfoEnabled()) {
log.info("waitForLiveNode: {}", j.getNodeName());
}
- cloudClient.getZkStateReader().waitForLiveNodes(30, TimeUnit.SECONDS, SolrCloudTestCase.containsLiveNode(j.getNodeName()));
+ cloudClient
+ .getZkStateReader()
+ .waitForLiveNodes(
+ 30, TimeUnit.SECONDS, SolrCloudTestCase.containsLiveNode(j.getNodeName()));
}
- protected void waitForActiveReplicaCount(CloudSolrClient client, String collection, int expectedNumReplicas) throws TimeoutException, NotInClusterStateException {
- log.info("Waiting to see {} active replicas in collection: {}", expectedNumReplicas, collection);
+ protected void waitForActiveReplicaCount(
+ CloudSolrClient client, String collection, int expectedNumReplicas)
+ throws TimeoutException, NotInClusterStateException {
+ log.info(
+ "Waiting to see {} active replicas in collection: {}", expectedNumReplicas, collection);
AtomicInteger nReplicas = new AtomicInteger();
try {
- client.getZkStateReader().waitForState(collection, 30, TimeUnit.SECONDS, (liveNodes, collectionState) -> {
- if (collectionState == null) {
- return false;
- }
- int activeReplicas = 0;
- for (Slice slice : collectionState) {
- for (Replica replica : slice) {
- if (replica.isActive(liveNodes)) {
- activeReplicas++;
- }
- }
- }
- nReplicas.set(activeReplicas);
- return (activeReplicas == expectedNumReplicas);
- });
+ client
+ .getZkStateReader()
+ .waitForState(
+ collection,
+ 30,
+ TimeUnit.SECONDS,
+ (liveNodes, collectionState) -> {
+ if (collectionState == null) {
+ return false;
+ }
+ int activeReplicas = 0;
+ for (Slice slice : collectionState) {
+ for (Replica replica : slice) {
+ if (replica.isActive(liveNodes)) {
+ activeReplicas++;
+ }
+ }
+ }
+ nReplicas.set(activeReplicas);
+ return (activeReplicas == expectedNumReplicas);
+ });
} catch (TimeoutException | InterruptedException e) {
try {
printLayout();
} catch (Exception e1) {
throw new RuntimeException(e1);
}
- throw new NotInClusterStateException(ErrorCode.SERVER_ERROR,
- "Number of replicas in the state does not match what we set:" + nReplicas + " vs " + expectedNumReplicas);
+ throw new NotInClusterStateException(
+ ErrorCode.SERVER_ERROR,
+ "Number of replicas in the state does not match what we set:"
+ + nReplicas
+ + " vs "
+ + expectedNumReplicas);
}
}
-
protected int getPullReplicaCount() {
return 0;
}
- /**
- * Total number of replicas for all shards as indicated by the cluster state, regardless of status.
+ /**
+ * Total number of replicas for all shards as indicated by the cluster state, regardless of
+ * status.
*
- * @deprecated This method is virtually useless as it does not consider the status of either
- * the shard or replica, nor wether the node hosting each replica is alive.
+ * @deprecated This method is virtually useless as it does not consider the status of either the
+ * shard or replica, nor wether the node hosting each replica is alive.
*/
@Deprecated
protected int getTotalReplicas(DocCollection c, String collection) {
- if (c == null) return 0; // support for when collection hasn't been created yet
+ if (c == null) return 0; // support for when collection hasn't been created yet
int cnt = 0;
for (Slice slices : c.getSlices()) {
cnt += slices.getReplicas().size();
@@ -644,23 +737,25 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
return cnt;
}
- public JettySolrRunner createJetty(String dataDir, String ulogDir, String shardList,
- String solrConfigOverride) throws Exception {
+ public JettySolrRunner createJetty(
+ String dataDir, String ulogDir, String shardList, String solrConfigOverride)
+ throws Exception {
- JettyConfig jettyconfig = JettyConfig.builder()
- .setContext(context)
- .stopAtShutdown(false)
- .withServlets(getExtraServlets())
- .withFilters(getExtraRequestFilters())
- .withSSLConfig(sslConfig.buildServerSSLConfig())
- .build();
+ JettyConfig jettyconfig =
+ JettyConfig.builder()
+ .setContext(context)
+ .stopAtShutdown(false)
+ .withServlets(getExtraServlets())
+ .withFilters(getExtraRequestFilters())
+ .withSSLConfig(sslConfig.buildServerSSLConfig())
+ .build();
Properties props = new Properties();
props.setProperty("solr.data.dir", getDataDir(dataDir));
props.setProperty("shards", shardList);
props.setProperty("solr.ulog.dir", ulogDir);
props.setProperty("solrconfig", solrConfigOverride);
-
+
JettySolrRunner jetty = new JettySolrRunner(getSolrHome(), props, jettyconfig);
jetty.start();
@@ -668,71 +763,82 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
return jetty;
}
- public final JettySolrRunner createJetty(File solrHome, String dataDir, String shardList, String solrConfigOverride, String schemaOverride) throws Exception {
+ public final JettySolrRunner createJetty(
+ File solrHome,
+ String dataDir,
+ String shardList,
+ String solrConfigOverride,
+ String schemaOverride)
+ throws Exception {
return createJetty(solrHome, dataDir, shardList, solrConfigOverride, schemaOverride, null);
}
- public JettySolrRunner createJetty(File solrHome, String dataDir, String shardList, String solrConfigOverride, String schemaOverride, Replica.Type replicaType) throws Exception {
+ public JettySolrRunner createJetty(
+ File solrHome,
+ String dataDir,
+ String shardList,
+ String solrConfigOverride,
+ String schemaOverride,
+ Replica.Type replicaType)
+ throws Exception {
// randomly test a relative solr.home path
if (random().nextBoolean()) {
solrHome = getRelativeSolrHomePath(solrHome);
}
- JettyConfig jettyconfig = JettyConfig.builder()
- .setContext(context)
- .stopAtShutdown(false)
- .withServlets(getExtraServlets())
- .withFilters(getExtraRequestFilters())
- .withSSLConfig(sslConfig.buildServerSSLConfig())
- .build();
+ JettyConfig jettyconfig =
+ JettyConfig.builder()
+ .setContext(context)
+ .stopAtShutdown(false)
+ .withServlets(getExtraServlets())
+ .withFilters(getExtraRequestFilters())
+ .withSSLConfig(sslConfig.buildServerSSLConfig())
+ .build();
Properties props = new Properties();
- if (solrConfigOverride != null)
- props.setProperty("solrconfig", solrConfigOverride);
- if (schemaOverride != null)
- props.setProperty("schema", schemaOverride);
- if (shardList != null)
- props.setProperty("shards", shardList);
- if (dataDir != null)
- props.setProperty("solr.data.dir", getDataDir(dataDir));
+ if (solrConfigOverride != null) props.setProperty("solrconfig", solrConfigOverride);
+ if (schemaOverride != null) props.setProperty("schema", schemaOverride);
+ if (shardList != null) props.setProperty("shards", shardList);
+ if (dataDir != null) props.setProperty("solr.data.dir", getDataDir(dataDir));
if (replicaType != null) {
props.setProperty("replicaType", replicaType.toString());
} else if (random().nextBoolean()) {
props.setProperty("replicaType", Replica.Type.NRT.toString());
}
props.setProperty("coreRootDirectory", solrHome.toPath().resolve("cores").toString());
-
+
JettySolrRunner jetty = new JettySolrRunner(solrHome.getPath(), props, jettyconfig);
return jetty;
}
/**
- * Creates a JettySolrRunner with a socket proxy sitting infront of the Jetty server,
- * which gives us the ability to simulate network partitions without having to fuss
- * with IPTables.
+ * Creates a JettySolrRunner with a socket proxy sitting infront of the Jetty server, which gives
+ * us the ability to simulate network partitions without having to fuss with IPTables.
*/
- public JettySolrRunner createProxiedJetty(File solrHome, String dataDir,
- String shardList, String solrConfigOverride, String schemaOverride, Replica.Type replicaType)
+ public JettySolrRunner createProxiedJetty(
+ File solrHome,
+ String dataDir,
+ String shardList,
+ String solrConfigOverride,
+ String schemaOverride,
+ Replica.Type replicaType)
throws Exception {
- JettyConfig jettyconfig = JettyConfig.builder()
- .setContext(context)
- .stopAtShutdown(false)
- .withServlets(getExtraServlets())
- .withFilters(getExtraRequestFilters())
- .withSSLConfig(sslConfig.buildServerSSLConfig())
- .build();
+ JettyConfig jettyconfig =
+ JettyConfig.builder()
+ .setContext(context)
+ .stopAtShutdown(false)
+ .withServlets(getExtraServlets())
+ .withFilters(getExtraRequestFilters())
+ .withSSLConfig(sslConfig.buildServerSSLConfig())
+ .build();
Properties props = new Properties();
- if (solrConfigOverride != null)
- props.setProperty("solrconfig", solrConfigOverride);
- if (schemaOverride != null)
- props.setProperty("schema", schemaOverride);
- if (shardList != null)
- props.setProperty("shards", shardList);
- if (dataDir != null)
- props.setProperty("solr.data.dir", getDataDir(dataDir));
+ if (solrConfigOverride != null) props.setProperty("solrconfig", solrConfigOverride);
+ if (schemaOverride != null) props.setProperty("schema", schemaOverride);
+ if (shardList != null) props.setProperty("shards", shardList);
+ if (dataDir != null) props.setProperty("solr.data.dir", getDataDir(dataDir));
if (replicaType != null) {
props.setProperty("replicaType", replicaType.toString());
} else if (random().nextBoolean()) {
@@ -747,9 +853,8 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
protected int getReplicaPort(Replica replica) {
String replicaNode = replica.getNodeName();
- String tmp = replicaNode.substring(replicaNode.indexOf(':')+1);
- if (tmp.indexOf('_') != -1)
- tmp = tmp.substring(0,tmp.indexOf('_'));
+ String tmp = replicaNode.substring(replicaNode.indexOf(':') + 1);
+ if (tmp.indexOf('_') != -1) tmp = tmp.substring(0, tmp.indexOf('_'));
return Integer.parseInt(tmp);
}
@@ -768,8 +873,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
}
}
- if (theJetty == null)
- fail("Not able to find JettySolrRunner for port: "+port);
+ if (theJetty == null) fail("Not able to find JettySolrRunner for port: " + port);
return theJetty;
}
@@ -780,13 +884,15 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
List<JettySolrRunner> runners = new ArrayList<>(jettys);
runners.add(controlJetty);
-
+
for (JettySolrRunner j : runners) {
- if (replicaBaseUrl.replaceAll("/$", "").equals(j.getProxyBaseUrl().toExternalForm().replaceAll("/$", ""))) {
+ if (replicaBaseUrl
+ .replaceAll("/$", "")
+ .equals(j.getProxyBaseUrl().toExternalForm().replaceAll("/$", ""))) {
return j.getProxy();
}
}
-
+
printLayout();
fail("No proxy found for " + replicaBaseUrl + "!");
@@ -796,29 +902,33 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
private File getRelativeSolrHomePath(File solrHome) {
final Path solrHomePath = solrHome.toPath();
final Path curDirPath = new File("").getAbsoluteFile().toPath();
-
+
if (!solrHomePath.getRoot().equals(curDirPath.getRoot())) {
// root of current directory and solrHome are not the same, therefore cannot relativize
return solrHome;
}
-
+
final Path root = solrHomePath.getRoot();
-
+
// relativize current directory to root: /tmp/foo -> /tmp/foo/../..
- final File relativizedCurDir = new File(curDirPath.toFile(), curDirPath.relativize(root).toString());
-
+ final File relativizedCurDir =
+ new File(curDirPath.toFile(), curDirPath.relativize(root).toString());
+
// exclude the root from solrHome: /tmp/foo/solrHome -> tmp/foo/solrHome
final Path solrHomeRelativeToRoot = root.relativize(solrHomePath);
-
+
// create the relative solrHome: /tmp/foo/../../tmp/foo/solrHome
return new File(relativizedCurDir, solrHomeRelativeToRoot.toString()).getAbsoluteFile();
}
-
- protected void updateMappingsFromZk(List<JettySolrRunner> jettys, List<SolrClient> clients) throws Exception {
+
+ protected void updateMappingsFromZk(List<JettySolrRunner> jettys, List<SolrClient> clients)
+ throws Exception {
updateMappingsFromZk(jettys, clients, false);
}
-
- protected void updateMappingsFromZk(List<JettySolrRunner> jettys, List<SolrClient> clients, boolean allowOverSharding) throws Exception {
+
+ protected void updateMappingsFromZk(
+ List<JettySolrRunner> jettys, List<SolrClient> clients, boolean allowOverSharding)
+ throws Exception {
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
zkStateReader.forceUpdateCollection(DEFAULT_COLLECTION);
cloudJettys.clear();
@@ -829,13 +939,12 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
List<CloudSolrServerClient> theClients = new ArrayList<>();
for (SolrClient client : clients) {
- // find info for this client in zk
+ // find info for this client in zk
nextClient:
// we find out state by simply matching ports...
for (Slice slice : coll.getSlices()) {
for (Replica replica : slice.getReplicas()) {
- int port = new URI(((HttpSolrClient) client).getBaseURL())
- .getPort();
+ int port = new URI(((HttpSolrClient) client).getBaseURL()).getPort();
if (replica.getBaseUrl().contains(":" + port)) {
CloudSolrServerClient csc = new CloudSolrServerClient();
@@ -844,7 +953,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
csc.shardName = replica.getStr(ZkStateReader.NODE_NAME_PROP);
csc.info = replica;
- theClients .add(csc);
+ theClients.add(csc);
break nextClient;
}
@@ -860,8 +969,8 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
nextJetty:
for (Slice slice : coll.getSlices()) {
- Set<Entry<String,Replica>> entries = slice.getReplicasMap().entrySet();
- for (Entry<String,Replica> entry : entries) {
+ Set<Entry<String, Replica>> entries = slice.getReplicasMap().entrySet();
+ for (Entry<String, Replica> entry : entries) {
Replica replica = entry.getValue();
if (replica.getBaseUrl().contains(":" + port)) {
List<CloudJettyRunner> list = shardToJetty.get(slice.getName());
@@ -896,11 +1005,14 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
// check that things look right
List<CloudJettyRunner> jetties = shardToJetty.get(slice.getName());
if (!allowOverSharding) {
- assertNotNull("Test setup problem: We found no jetties for shard: "
- + slice.getName() + " just:" + shardToJetty.keySet(), jetties);
-
- assertEquals("slice:" + slice.getName(), slice.getReplicas().size(),
- jetties.size());
+ assertNotNull(
+ "Test setup problem: We found no jetties for shard: "
+ + slice.getName()
+ + " just:"
+ + shardToJetty.keySet(),
+ jetties);
+
+ assertEquals("slice:" + slice.getName(), slice.getReplicas().size(), jetties.size());
}
}
}
@@ -930,24 +1042,38 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
}
}
- protected int sendDocsWithRetry(List<SolrInputDocument> batch, int minRf, int maxRetries, int waitBeforeRetry) throws Exception {
- return sendDocsWithRetry(cloudClient, cloudClient.getDefaultCollection(), batch, minRf, maxRetries, waitBeforeRetry);
+ protected int sendDocsWithRetry(
+ List<SolrInputDocument> batch, int minRf, int maxRetries, int waitBeforeRetry)
+ throws Exception {
+ return sendDocsWithRetry(
+ cloudClient, cloudClient.getDefaultCollection(), batch, minRf, maxRetries, waitBeforeRetry);
}
@SuppressWarnings("rawtypes")
- protected static int sendDocsWithRetry(CloudSolrClient cloudClient, String collection, List<SolrInputDocument> batch, int minRf, int maxRetries, int waitBeforeRetry) throws Exception {
+ protected static int sendDocsWithRetry(
+ CloudSolrClient cloudClient,
+ String collection,
+ List<SolrInputDocument> batch,
+ int minRf,
+ int maxRetries,
+ int waitBeforeRetry)
+ throws Exception {
UpdateRequest up = new UpdateRequest();
up.add(batch);
NamedList resp = null;
int numRetries = 0;
- while(true) {
+ while (true) {
try {
resp = cloudClient.request(up, collection);
- return cloudClient.getMinAchievedReplicationFactor(cloudClient.getDefaultCollection(), resp);
+ return cloudClient.getMinAchievedReplicationFactor(
+ cloudClient.getDefaultCollection(), resp);
} catch (Exception exc) {
Throwable rootCause = SolrException.getRootCause(exc);
if (++numRetries <= maxRetries) {
- log.warn("ERROR: {} ... Sleeping for {} seconds before re-try ...", rootCause, waitBeforeRetry);
+ log.warn(
+ "ERROR: {} ... Sleeping for {} seconds before re-try ...",
+ rootCause,
+ waitBeforeRetry);
Thread.sleep(waitBeforeRetry * 1000L);
} else {
log.error("No more retries available! Add batch failed due to: {}", rootCause);
@@ -958,8 +1084,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
}
@Override
- protected void indexDoc(SolrInputDocument doc) throws IOException,
- SolrServerException {
+ protected void indexDoc(SolrInputDocument doc) throws IOException, SolrServerException {
UpdateRequest req = new UpdateRequest();
req.add(doc);
@@ -989,25 +1114,22 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
}
@Override
- protected void index_specific(int serverNumber, Object... fields)
- throws Exception {
+ protected void index_specific(int serverNumber, Object... fields) throws Exception {
SolrInputDocument doc = new SolrInputDocument();
for (int i = 0; i < fields.length; i += 2) {
doc.addField((String) (fields[i]), fields[i + 1]);
}
controlClient.add(doc);
-
- HttpSolrClient client = (HttpSolrClient) clients
- .get(serverNumber);
+
+ HttpSolrClient client = (HttpSolrClient) clients.get(serverNumber);
UpdateRequest ureq = new UpdateRequest();
ureq.add(doc);
// ureq.setParam("update.chain", DISTRIB_UPDATE_CHAIN);
ureq.process(client);
}
-
- protected void index_specific(SolrClient client, Object... fields)
- throws Exception {
+
+ protected void index_specific(SolrClient client, Object... fields) throws Exception {
SolrInputDocument doc = new SolrInputDocument();
for (int i = 0; i < fields.length; i += 2) {
doc.addField((String) (fields[i]), fields[i + 1]);
@@ -1021,7 +1143,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
// add to control second in case adding to shards fails
controlClient.add(doc);
}
-
+
protected ZkCoreNodeProps getLeaderUrlFromZk(String collection, String slice) {
ClusterState clusterState = getCommonCloudSolrClient().getZkStateReader().getClusterState();
final DocCollection docCollection = clusterState.getCollectionOrNull(collection);
@@ -1037,28 +1159,25 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
cloudClient.deleteByQuery(q);
/***
- for (SolrServer client : clients) {
- UpdateRequest ureq = new UpdateRequest();
- // ureq.setParam("update.chain", DISTRIB_UPDATE_CHAIN);
- ureq.deleteByQuery(q).process(client);
- }
+ * for (SolrServer client : clients) {
+ * UpdateRequest ureq = new UpdateRequest();
+ * // ureq.setParam("update.chain", DISTRIB_UPDATE_CHAIN);
+ * ureq.deleteByQuery(q).process(client);
+ * }
***/
- }// serial commit...
+ } // serial commit...
- protected void waitForRecoveriesToFinish(boolean verbose)
- throws Exception {
+ protected void waitForRecoveriesToFinish(boolean verbose) throws Exception {
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
super.waitForRecoveriesToFinish(DEFAULT_COLLECTION, zkStateReader, verbose);
}
- protected void waitForRecoveriesToFinish(String collection, boolean verbose)
- throws Exception {
+ protected void waitForRecoveriesToFinish(String collection, boolean verbose) throws Exception {
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
super.waitForRecoveriesToFinish(collection, zkStateReader, verbose);
}
- protected void waitForRecoveriesToFinish(boolean verbose, long timeoutSeconds)
- throws Exception {
+ protected void waitForRecoveriesToFinish(boolean verbose, long timeoutSeconds) throws Exception {
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
waitForRecoveriesToFinish(DEFAULT_COLLECTION, zkStateReader, verbose, true, timeoutSeconds);
}
@@ -1069,18 +1188,16 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
query("q", "*:*", "sort", "n_tl1 desc");
- handle.put("response", UNORDERED); // get?ids=a,b,c requests are unordered
+ handle.put("response", UNORDERED); // get?ids=a,b,c requests are unordered
String ids = "987654";
- for (int i=0; i<20; i++) {
- query("qt","/get", "id",Integer.toString(i));
- query("qt","/get", "ids",Integer.toString(i));
+ for (int i = 0; i < 20; i++) {
+ query("qt", "/get", "id", Integer.toString(i));
+ query("qt", "/get", "ids", Integer.toString(i));
ids = ids + ',' + Integer.toString(i);
- query("qt","/get", "ids",ids);
+ query("qt", "/get", "ids", ids);
}
handle.remove("response");
-
-
// random value sort
for (String f : fieldNames) {
query("q", "*:*", "sort", f + " desc");
@@ -1092,17 +1209,17 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
query("q", "*:*", "sort", i1 + " asc");
query("q", "*:*", "sort", i1 + " desc", "fl", "*,score");
query("q", "*:*", "sort", "n_tl1 asc", "fl", "score"); // test legacy
- // behavior -
- // "score"=="*,score"
+ // behavior -
+ // "score"=="*,score"
query("q", "*:*", "sort", "n_tl1 desc");
handle.put("maxScore", SKIPVAL);
- query("q", "{!func}" + i1);// does not expect maxScore. So if it comes
- // ,ignore it.
- // JavaBinCodec.writeSolrDocumentList()
+ query("q", "{!func}" + i1); // does not expect maxScore. So if it comes
+ // ,ignore it.
+ // JavaBinCodec.writeSolrDocumentList()
// is agnostic of request params.
handle.remove("maxScore");
query("q", "{!func}" + i1, "fl", "*,score"); // even scores should match
- // exactly here
+ // exactly here
handle.put("highlighting", UNORDERED);
handle.put("response", UNORDERED);
@@ -1111,7 +1228,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
query("q", "quick");
query("q", "all", "fl", "id", "start", "0");
query("q", "all", "fl", "foofoofoo", "start", "0"); // no fields in returned
- // docs
+ // docs
query("q", "all", "fl", "id", "start", "100");
handle.put("score", SKIPVAL);
@@ -1119,55 +1236,149 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
query("q", "all", "fl", "*,score", "start", "1");
query("q", "all", "fl", "*,score", "start", "100");
- query("q", "now their fox sat had put", "fl", "*,score", "hl", "true",
- "hl.fl", t1);
+ query("q", "now their fox sat had put", "fl", "*,score", "hl", "true", "hl.fl", t1);
- query("q", "now their fox sat had put", "fl", "foofoofoo", "hl", "true",
- "hl.fl", t1);
+ query("q", "now their fox sat had put", "fl", "foofoofoo", "hl", "true", "hl.fl", t1);
query("q", "matchesnothing", "fl", "*,score");
query("q", "*:*", "rows", 100, "facet", "true", "facet.field", t1);
- query("q", "*:*", "rows", 100, "facet", "true", "facet.field", t1,
- "facet.limit", -1, "facet.sort", "count");
- query("q", "*:*", "rows", 100, "facet", "true", "facet.field", t1,
- "facet.limit", -1, "facet.sort", "count", "facet.mincount", 2);
- query("q", "*:*", "rows", 100, "facet", "true", "facet.field", t1,
- "facet.limit", -1, "facet.sort", "index");
- query("q", "*:*", "rows", 100, "facet", "true", "facet.field", t1,
- "facet.limit", -1, "facet.sort", "index", "facet.mincount", 2);
- query("q", "*:*", "rows", 100, "facet", "true", "facet.field", t1,
- "facet.limit", 1);
- query("q", "*:*", "rows", 100, "facet", "true", "facet.query", "quick",
- "facet.query", "all", "facet.query", "*:*");
- query("q", "*:*", "rows", 100, "facet", "true", "facet.field", t1,
- "facet.offset", 1);
- query("q", "*:*", "rows", 100, "facet", "true", "facet.field", t1,
- "facet.mincount", 2);
+ query(
+ "q",
+ "*:*",
+ "rows",
+ 100,
+ "facet",
+ "true",
+ "facet.field",
+ t1,
+ "facet.limit",
+ -1,
+ "facet.sort",
+ "count");
+ query(
+ "q",
+ "*:*",
+ "rows",
+ 100,
+ "facet",
+ "true",
+ "facet.field",
+ t1,
+ "facet.limit",
+ -1,
+ "facet.sort",
+ "count",
+ "facet.mincount",
+ 2);
+ query(
+ "q",
+ "*:*",
+ "rows",
+ 100,
+ "facet",
+ "true",
+ "facet.field",
+ t1,
+ "facet.limit",
+ -1,
+ "facet.sort",
+ "index");
+ query(
+ "q",
+ "*:*",
+ "rows",
+ 100,
+ "facet",
+ "true",
+ "facet.field",
+ t1,
+ "facet.limit",
+ -1,
+ "facet.sort",
+ "index",
+ "facet.mincount",
+ 2);
+ query("q", "*:*", "rows", 100, "facet", "true", "facet.field", t1, "facet.limit", 1);
+ query(
+ "q",
+ "*:*",
+ "rows",
+ 100,
+ "facet",
+ "true",
+ "facet.query",
+ "quick",
+ "facet.query",
+ "all",
+ "facet.query",
+ "*:*");
+ query("q", "*:*", "rows", 100, "facet", "true", "facet.field", t1, "facet.offset", 1);
+ query("q", "*:*", "rows", 100, "facet", "true", "facet.field", t1, "facet.mincount", 2);
// test faceting multiple things at once
- query("q", "*:*", "rows", 100, "facet", "true", "facet.query", "quick",
- "facet.query", "all", "facet.query", "*:*", "facet.field", t1);
+ query(
+ "q",
+ "*:*",
+ "rows",
+ 100,
+ "facet",
+ "true",
+ "facet.query",
+ "quick",
+ "facet.query",
+ "all",
+ "facet.query",
+ "*:*",
+ "facet.field",
+ t1);
// test filter tagging, facet exclusion, and naming (multi-select facet
// support)
- query("q", "*:*", "rows", 100, "facet", "true", "facet.query",
- "{!key=myquick}quick", "facet.query", "{!key=myall ex=a}all",
- "facet.query", "*:*", "facet.field", "{!key=mykey ex=a}" + t1,
- "facet.field", "{!key=other ex=b}" + t1, "facet.field",
- "{!key=again ex=a,b}" + t1, "facet.field", t1, "fq",
- "{!tag=a}id:[1 TO 7]", "fq", "{!tag=b}id:[3 TO 9]");
- query("q", "*:*", "facet", "true", "facet.field",
- "{!ex=t1}SubjectTerms_mfacet", "fq",
- "{!tag=t1}SubjectTerms_mfacet:(test 1)", "facet.limit", "10",
- "facet.mincount", "1");
+ query(
+ "q",
+ "*:*",
+ "rows",
+ 100,
+ "facet",
+ "true",
+ "facet.query",
+ "{!key=myquick}quick",
+ "facet.query",
+ "{!key=myall ex=a}all",
+ "facet.query",
+ "*:*",
+ "facet.field",
+ "{!key=mykey ex=a}" + t1,
+ "facet.field",
+ "{!key=other ex=b}" + t1,
+ "facet.field",
+ "{!key=again ex=a,b}" + t1,
+ "facet.field",
+ t1,
+ "fq",
+ "{!tag=a}id:[1 TO 7]",
+ "fq",
+ "{!tag=b}id:[3 TO 9]");
+ query(
+ "q",
+ "*:*",
+ "facet",
+ "true",
+ "facet.field",
+ "{!ex=t1}SubjectTerms_mfacet",
+ "fq",
+ "{!tag=t1}SubjectTerms_mfacet:(test 1)",
+ "facet.limit",
+ "10",
+ "facet.mincount",
+ "1");
// test field that is valid in schema but missing in all shards
- query("q", "*:*", "rows", 100, "facet", "true", "facet.field",
- missingField, "facet.mincount", 2);
+ query(
+ "q", "*:*", "rows", 100, "facet", "true", "facet.field", missingField, "facet.mincount", 2);
// test field that is valid in schema and missing in some shards
- query("q", "*:*", "rows", 100, "facet", "true", "facet.field", oddField,
- "facet.mincount", 2);
+ query("q", "*:*", "rows", 100, "facet", "true", "facet.field", oddField, "facet.mincount", 2);
query("q", "*:*", "sort", i1 + " desc", "stats", "true", "stats.field", i1);
@@ -1177,12 +1388,33 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
// and hence
// we turn of that checking.
handle.put("facet_fields", SKIPVAL);
- query("q", "*:*", "rows", 0, "facet", "true", "facet.field", t1,
- "facet.limit", 5, "facet.shard.limit", 5);
+ query(
+ "q",
+ "*:*",
+ "rows",
+ 0,
+ "facet",
+ "true",
+ "facet.field",
+ t1,
+ "facet.limit",
+ 5,
+ "facet.shard.limit",
+ 5);
// check a complex key name
- query("q", "*:*", "rows", 0, "facet", "true", "facet.field",
- "{!key='a b/c \\' \\} foo'}" + t1, "facet.limit", 5,
- "facet.shard.limit", 5);
+ query(
+ "q",
+ "*:*",
+ "rows",
+ 0,
+ "facet",
+ "true",
+ "facet.field",
+ "{!key='a b/c \\' \\} foo'}" + t1,
+ "facet.limit",
+ 5,
+ "facet.shard.limit",
+ 5);
handle.remove("facet_fields");
query("q", "*:*", "sort", "n_tl1 desc");
@@ -1204,30 +1436,25 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
protected void indexAbunchOfDocs() throws Exception {
indexr(id, 2, i1, 50, t1, "to come to the aid of their country.");
- indexr(id, 3, i1, 2, t1, "how now brown cow");
- indexr(id, 4, i1, -100, t1,
- "the quick fox jumped over the lazy dog");
- indexr(id, 5, i1, 500, t1,
- "the quick fox jumped way over the lazy dog");
+ indexr(id, 3, i1, 2, t1, "how now brown cow");
+ indexr(id, 4, i1, -100, t1, "the quick fox jumped over the lazy dog");
+ indexr(id, 5, i1, 500, t1, "the quick fox jumped way over the lazy dog");
indexr(id, 6, i1, -600, t1, "humpty dumpy sat on a wall");
indexr(id, 7, i1, 123, t1, "humpty dumpy had a great fall");
- indexr(id, 8, i1, 876, t1,
- "all the kings horses and all the kings men");
+ indexr(id, 8, i1, 876, t1, "all the kings horses and all the kings men");
indexr(id, 9, i1, 7, t1, "couldn't put humpty together again");
indexr(id, 10, i1, 4321, t1, "this too shall pass");
- indexr(id, 11, i1, -987, t1,
- "An eye for eye only ends up making the whole world blind.");
- indexr(id, 12, i1, 379, t1,
- "Great works are performed, not by strength, but by perseverance.");
- indexr(id, 13, i1, 232, t1, "no eggs on wall, lesson learned",
- oddField, "odd man out");
-
- indexr(id, 14, "SubjectTerms_mfacet", new String[] {"mathematical models",
- "mathematical analysis"});
- indexr(id, 15, "SubjectTerms_mfacet", new String[] {"test 1", "test 2",
- "test3"});
- indexr(id, 16, "SubjectTerms_mfacet", new String[] {"test 1", "test 2",
- "test3"});
+ indexr(id, 11, i1, -987, t1, "An eye for eye only ends up making the whole world blind.");
+ indexr(id, 12, i1, 379, t1, "Great works are performed, not by strength, but by perseverance.");
+ indexr(id, 13, i1, 232, t1, "no eggs on wall, lesson learned", oddField, "odd man out");
+
+ indexr(
+ id,
+ 14,
+ "SubjectTerms_mfacet",
+ new String[] {"mathematical models", "mathematical analysis"});
+ indexr(id, 15, "SubjectTerms_mfacet", new String[] {"test 1", "test 2", "test3"});
+ indexr(id, 16, "SubjectTerms_mfacet", new String[] {"test 1", "test 2", "test3"});
String[] vals = new String[100];
for (int i = 0; i < 100; i++) {
vals[i] = "test " + i;
@@ -1240,13 +1467,12 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
}
/**
- * Executes a query against each live and active replica of the specified shard
- * and aserts that the results are identical.
+ * Executes a query against each live and active replica of the specified shard and aserts that
+ * the results are identical.
*
* @see #queryAndCompare
*/
- public QueryResponse queryAndCompareReplicas(SolrParams params, String shard)
- throws Exception {
+ public QueryResponse queryAndCompareReplicas(SolrParams params, String shard) throws Exception {
ArrayList<SolrClient> shardClients = new ArrayList<>(7);
@@ -1255,11 +1481,11 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
List<CloudJettyRunner> solrJetties = shardToJetty.get(shard);
assertNotNull("no jetties found for shard: " + shard, solrJetties);
-
for (CloudJettyRunner cjetty : solrJetties) {
ZkNodeProps props = cjetty.info;
String nodeName = props.getStr(ZkStateReader.NODE_NAME_PROP);
- boolean active = Replica.State.getState(props.getStr(ZkStateReader.STATE_PROP)) == Replica.State.ACTIVE;
+ boolean active =
+ Replica.State.getState(props.getStr(ZkStateReader.STATE_PROP)) == Replica.State.ACTIVE;
boolean live = zkStateReader.getClusterState().liveNodesContain(nodeName);
if (active && live) {
shardClients.add(cjetty.client.solrClient);
@@ -1269,11 +1495,11 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
}
/**
- * For each Shard, executes a query against each live and active replica of that shard
- * and asserts that the results are identical for each replica of the same shard.
- * Because results are not compared between replicas of different shards, this method
- * should be safe for comparing the results of any query, even if it contains
- * "distrib=false", because the replicas should all be identical.
+ * For each Shard, executes a query against each live and active replica of that shard and asserts
+ * that the results are identical for each replica of the same shard. Because results are not
+ * compared between replicas of different shards, this method should be safe for comparing the
+ * results of any query, even if it contains "distrib=false", because the replicas should all be
+ * identical.
*
* @see AbstractFullDistribZkTestBase#queryAndCompareReplicas(SolrParams, String)
*/
@@ -1287,28 +1513,25 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
}
/**
- * Returns a non-null string if replicas within the same shard do not have a
- * consistent number of documents.
+ * Returns a non-null string if replicas within the same shard do not have a consistent number of
+ * documents.
*/
protected void checkShardConsistency(String shard) throws Exception {
checkShardConsistency(shard, false, false);
}
/**
- * Returns a non-null string if replicas within the same shard do not have a
- * consistent number of documents.
- * If expectFailure==false, the exact differences found will be logged since
- * this would be an unexpected failure.
- * verbose causes extra debugging into to be displayed, even if everything is
- * consistent.
+ * Returns a non-null string if replicas within the same shard do not have a consistent number of
+ * documents. If expectFailure==false, the exact differences found will be logged since this would
+ * be an unexpected failure. verbose causes extra debugging into to be displayed, even if
+ * everything is consistent.
*/
protected String checkShardConsistency(String shard, boolean expectFailure, boolean verbose)
throws Exception {
List<CloudJettyRunner> solrJetties = shardToJetty.get(shard);
if (solrJetties == null) {
- throw new RuntimeException("shard not found:" + shard + " keys:"
- + shardToJetty.keySet());
+ throw new RuntimeException("shard not found:" + shard + " keys:" + shardToJetty.keySet());
}
long num = -1;
long lastNum = -1;
@@ -1317,10 +1540,14 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
int cnt = 0;
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
assertEquals(
- "The client count does not match up with the shard count for slice:"
- + shard,
- zkStateReader.getClusterState().getCollection(DEFAULT_COLLECTION).getSlice(shard)
- .getReplicasMap().size(), solrJetties.size());
+ "The client count does not match up with the shard count for slice:" + shard,
+ zkStateReader
+ .getClusterState()
+ .getCollection(DEFAULT_COLLECTION)
+ .getSlice(shard)
+ .getReplicasMap()
+ .size(),
+ solrJetties.size());
CloudJettyRunner lastJetty = null;
for (CloudJettyRunner cjetty : solrJetties) {
@@ -1329,11 +1556,20 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
if (verbose) System.err.println("PROPS:" + props);
try {
- SolrParams query = params("q","*:*", "rows","0", "distrib","false", "tests","checkShardConsistency"); // "tests" is just a tag that won't do anything except be echoed in logs
+ SolrParams query =
+ params(
+ "q",
+ "*:*",
+ "rows",
+ "0",
+ "distrib",
+ "false",
+ "tests",
+ "checkShardConsistency"); // "tests" is just a tag that won't do anything except be
+ // echoed in logs
num = cjetty.client.solrClient.query(query).getResults().getNumFound();
} catch (SolrException | SolrServerException e) {
- if (verbose) System.err.println("error contacting client: "
- + e.getMessage() + "\n");
+ if (verbose) System.err.println("error contacting client: " + e.getMessage() + "\n");
continue;
}
@@ -1345,34 +1581,42 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
if (verbose) System.err.println(" live:" + live);
if (verbose) System.err.println(" num:" + num + "\n");
- boolean active = Replica.State.getState(props.getStr(ZkStateReader.STATE_PROP)) == Replica.State.ACTIVE;
+ boolean active =
+ Replica.State.getState(props.getStr(ZkStateReader.STATE_PROP)) == Replica.State.ACTIVE;
if (active && live) {
if (lastNum > -1 && lastNum != num && failMessage == null) {
- failMessage = shard + " is not consistent. Got " + lastNum + " from " + lastJetty.url + " (previous client)"
- + " and got " + num + " from " + cjetty.url;
+ failMessage =
+ shard
+ + " is not consistent. Got "
+ + lastNum
+ + " from "
+ + lastJetty.url
+ + " (previous client)"
+ + " and got "
+ + num
+ + " from "
+ + cjetty.url;
if (!expectFailure || verbose) {
System.err.println("######" + failMessage);
SolrQuery query = new SolrQuery("*:*");
query.set("distrib", false);
- query.set("fl","id,_version_");
- query.set("rows","100000");
- query.set("sort","id asc");
- query.set("tests","checkShardConsistency/showDiff");
+ query.set("fl", "id,_version_");
+ query.set("rows", "100000");
+ query.set("sort", "id asc");
+ query.set("tests", "checkShardConsistency/showDiff");
SolrDocumentList lst1 = lastJetty.client.solrClient.query(query).getResults();
SolrDocumentList lst2 = cjetty.client.solrClient.query(query).getResults();
CloudInspectUtil.showDiff(lst1, lst2, lastJetty.url, cjetty.url);
}
-
}
lastNum = num;
lastJetty = cjetty;
}
}
return failMessage;
-
}
public void showCounts() {
@@ -1386,17 +1630,23 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
System.err.println("PROPS:" + props);
try {
- SolrParams query = params("q", "*:*", "rows", "0", "distrib",
- "false", "tests", "checkShardConsistency"); // "tests" is just a
- // tag that won't do
- // anything except be
- // echoed in logs
- long num = cjetty.client.solrClient.query(query).getResults()
- .getNumFound();
+ SolrParams query =
+ params(
+ "q",
+ "*:*",
+ "rows",
+ "0",
+ "distrib",
+ "false",
+ "tests",
+ "checkShardConsistency"); // "tests" is just a
+ // tag that won't do
+ // anything except be
+ // echoed in logs
+ long num = cjetty.client.solrClient.query(query).getResults().getNumFound();
System.err.println("DOCS:" + num);
} catch (SolrServerException | SolrException | IOException e) {
- System.err.println("error contacting client: " + e.getMessage()
- + "\n");
+ System.err.println("error contacting client: " + e.getMessage() + "\n");
continue;
}
boolean live = false;
@@ -1406,7 +1656,6 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
live = true;
}
System.err.println(" live:" + live);
-
}
}
}
@@ -1426,15 +1675,16 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
CoreContainer cores = jetty.jetty.getCoreContainer();
for (SolrCore core : cores.getCores()) {
((DirectUpdateHandler2) core.getUpdateHandler())
- .getSoftCommitTracker().setTimeUpperBound(time);
+ .getSoftCommitTracker()
+ .setTimeUpperBound(time);
}
}
}
}
/* Checks both shard replcia consistency and against the control shard.
- * The test will be failed if differences are found.
- */
+ * The test will be failed if differences are found.
+ */
protected void checkShardConsistency() throws Exception {
checkShardConsistency(true, false);
}
@@ -1442,15 +1692,15 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
/* Checks shard consistency and optionally checks against the control shard.
* The test will be failed if differences are found.
*/
- protected void checkShardConsistency(boolean checkVsControl, boolean verbose)
- throws Exception {
+ protected void checkShardConsistency(boolean checkVsControl, boolean verbose) throws Exception {
checkShardConsistency(checkVsControl, verbose, null, null);
}
/* Checks shard consistency and optionally checks against the control shard.
* The test will be failed if differences are found.
*/
- protected void checkShardConsistency(boolean checkVsControl, boolean verbose, Set<String> addFails, Set<String> deleteFails)
+ protected void checkShardConsistency(
+ boolean checkVsControl, boolean verbose, Set<String> addFails, Set<String> deleteFails)
throws Exception {
updateMappingsFromZk(jettys, coreClients, true);
@@ -1470,7 +1720,14 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
if (!checkVsControl) return;
- SolrParams q = params("q","*:*","rows","0", "tests","checkShardConsistency(vsControl)"); // add a tag to aid in debugging via logs
+ SolrParams q =
+ params(
+ "q",
+ "*:*",
+ "rows",
+ "0",
+ "tests",
+ "checkShardConsistency(vsControl)"); // add a tag to aid in debugging via logs
SolrDocumentList controlDocList = controlClient.query(q).getResults();
long controlDocs = controlDocList.getNumFound();
@@ -1478,7 +1735,6 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
SolrDocumentList cloudDocList = cloudClient.query(q).getResults();
long cloudClientDocs = cloudDocList.getNumFound();
-
// now check that the right # are on each shard
theShards = shardToJetty.keySet();
int cnt = 0;
@@ -1489,15 +1745,16 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
CloudJettyRunner cjetty = shardToJetty.get(s).get(i);
ZkNodeProps props = cjetty.info;
SolrClient client = cjetty.client.solrClient;
- boolean active = Replica.State.getState(props.getStr(ZkStateReader.STATE_PROP)) == Replica.State.ACTIVE;
+ boolean active =
+ Replica.State.getState(props.getStr(ZkStateReader.STATE_PROP))
+ == Replica.State.ACTIVE;
if (active) {
SolrQuery query = new SolrQuery("*:*");
query.set("distrib", false);
long results = client.query(query).getResults().getNumFound();
- if (verbose) System.err.println(new ZkCoreNodeProps(props)
- .getCoreUrl() + " : " + results);
- if (verbose) System.err.println("shard:"
- + props.getStr(ZkStateReader.SHARD_ID_PROP));
+ if (verbose)
+ System.err.println(new ZkCoreNodeProps(props).getCoreUrl() + " : " + results);
+ if (verbose) System.err.println("shard:" + props.getStr(ZkStateReader.SHARD_ID_PROP));
cnt += results;
break;
}
@@ -1510,18 +1767,24 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
}
}
-
if (controlDocs != cnt || cloudClientDocs != controlDocs) {
- String msg = "document count mismatch. control=" + controlDocs + " sum(shards)="+ cnt + " cloudClient="+cloudClientDocs;
+ String msg =
+ "document count mismatch. control="
+ + controlDocs
+ + " sum(shards)="
+ + cnt
+ + " cloudClient="
+ + cloudClientDocs;
log.error(msg);
- boolean shouldFail = CloudInspectUtil.compareResults(controlClient, cloudClient, addFails, deleteFails);
+ boolean shouldFail =
+ CloudInspectUtil.compareResults(controlClient, cloudClient, addFails, deleteFails);
if (shouldFail) {
fail(msg);
}
}
}
-
+
protected SolrClient getClient(String nodeName) {
for (CloudJettyRunner cjetty : cloudJettys) {
CloudSolrServerClient client = cjetty.client;
@@ -1536,17 +1799,19 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
// TODO: as we create the clients, we should build a map from shard to
// node/client
// and node/client to shard?
- if (verbose) System.err.println("control docs:"
- + controlClient.query(new SolrQuery("*:*")).getResults().getNumFound()
- + "\n\n");
- long controlCount = controlClient.query(new SolrQuery("*:*")).getResults()
- .getNumFound();
+ if (verbose)
+ System.err.println(
+ "control docs:"
+ + controlClient.query(new SolrQuery("*:*")).getResults().getNumFound()
+ + "\n\n");
+ long controlCount = controlClient.query(new SolrQuery("*:*")).getResults().getNumFound();
// do some really inefficient mapping...
- Map<String,Slice> slices = null;
+ Map<String, Slice> slices = null;
ClusterState clusterState;
- try (ZkStateReader zk = new ZkStateReader(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT,
- AbstractZkTestCase.TIMEOUT)) {
+ try (ZkStateReader zk =
+ new ZkStateReader(
+ zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT, AbstractZkTestCase.TIMEOUT)) {
zk.createClusterStateWatchersAndUpdate();
clusterState = zk.getClusterState();
final DocCollection docCollection = clusterState.getCollectionOrNull(DEFAULT_COLLECTION);
@@ -1554,18 +1819,20 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
}
if (slices == null) {
- throw new RuntimeException("Could not find collection "
- + DEFAULT_COLLECTION + " in " + clusterState.getCollectionsMap().keySet());
+ throw new RuntimeException(
+ "Could not find collection "
+ + DEFAULT_COLLECTION
+ + " in "
+ + clusterState.getCollectionsMap().keySet());
}
for (CloudJettyRunner cjetty : cloudJettys) {
CloudSolrServerClient client = cjetty.client;
- for (Map.Entry<String,Slice> slice : slices.entrySet()) {
- Map<String,Replica> theShards = slice.getValue().getReplicasMap();
- for (Map.Entry<String,Replica> shard : theShards.entrySet()) {
- String shardName = new URI(
- ((HttpSolrClient) client.solrClient).getBaseURL()).getPort()
- + "_solr_";
+ for (Map.Entry<String, Slice> slice : slices.entrySet()) {
+ Map<String, Replica> theShards = slice.getValue().getReplicasMap();
+ for (Map.Entry<String, Replica> shard : theShards.entrySet()) {
+ String shardName =
+ new URI(((HttpSolrClient) client.solrClient).getBaseURL()).getPort() + "_solr_";
if (verbose && shard.getKey().endsWith(shardName)) {
System.err.println("shard:" + slice.getKey());
System.err.println(shard.getValue());
@@ -1574,9 +1841,12 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
}
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
long count = 0;
- final Replica.State currentState = Replica.State.getState(cjetty.info.getStr(ZkStateReader.STATE_PROP));
+ final Replica.State currentState =
+ Replica.State.getState(cjetty.info.getStr(ZkStateReader.STATE_PROP));
if (currentState == Replica.State.ACTIVE
- && zkStateReader.getClusterState().liveNodesContain(cjetty.info.getStr(ZkStateReader.NODE_NAME_PROP))) {
+ && zkStateReader
+ .getClusterState()
+ .liveNodesContain(cjetty.info.getStr(ZkStateReader.NODE_NAME_PROP))) {
SolrQuery query = new SolrQuery("*:*");
query.set("distrib", false);
count = client.solrClient.query(query).getResults().getNumFound();
@@ -1584,11 +1854,15 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
if (verbose) System.err.println("client docs:" + count + "\n\n");
}
- if (verbose) System.err.println("control docs:"
- + controlClient.query(new SolrQuery("*:*")).getResults().getNumFound()
- + "\n\n");
+ if (verbose)
+ System.err.println(
+ "control docs:"
+ + controlClient.query(new SolrQuery("*:*")).getResults().getNumFound()
+ + "\n\n");
SolrQuery query = new SolrQuery("*:*");
- assertEquals("Doc Counts do not add up", controlCount,
+ assertEquals(
+ "Doc Counts do not add up",
+ controlCount,
cloudClient.query(query).getResults().getNumFound());
}
@@ -1601,10 +1875,11 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
return cloudClient.query(params);
}
- static abstract class StoppableThread extends Thread {
+ abstract static class StoppableThread extends Thread {
public StoppableThread(String name) {
super(name);
}
+
public abstract void safeStop();
}
@@ -1646,7 +1921,6 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
} while (retry);
}
-
public void waitForNoShardInconsistency() throws Exception {
log.info("Wait for no shard inconsistency");
int cnt = 0;
@@ -1668,7 +1942,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
failMessage = checkShardConsistency(shard, true, true);
} catch (Exception e) {
// we might hit a node we just stopped
- failMessage="hit exception:" + e.getMessage();
+ failMessage = "hit exception:" + e.getMessage();
}
}
@@ -1685,7 +1959,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
}
void doQuery(String expectedDocs, String... queryParams) throws Exception {
- Set<String> expectedIds = new HashSet<>( StrUtils.splitSmart(expectedDocs, ",", true) );
+ Set<String> expectedIds = new HashSet<>(StrUtils.splitSmart(expectedDocs, ",", true));
QueryResponse rsp = cloudClient.query(params(queryParams));
Set<String> obtainedIds = new HashSet<>();
@@ -1702,9 +1976,8 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
if (VERBOSE || printLayoutOnTearDown) {
super.printLayout();
}
-
+
closeRestTestHarnesses(); // TODO: close here or later?
-
} finally {
super.distribTearDown();
@@ -1713,27 +1986,32 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
System.clearProperty("numShards");
}
}
-
+
@Override
protected void destroyServers() throws Exception {
- ExecutorService customThreadPool = ExecutorUtil.newMDCAwareCachedThreadPool(new SolrNamedThreadFactory("closeThreadPool"));
-
+ ExecutorService customThreadPool =
+ ExecutorUtil.newMDCAwareCachedThreadPool(new SolrNamedThreadFactory("closeThreadPool"));
+
customThreadPool.submit(() -> IOUtils.closeQuietly(commonCloudSolrClient));
-
+
customThreadPool.submit(() -> IOUtils.closeQuietly(controlClient));
-
- customThreadPool.submit(() -> coreClients.parallelStream().forEach(c -> {
- IOUtils.closeQuietly(c);
- }));
+
+ customThreadPool.submit(
+ () ->
+ coreClients.parallelStream()
+ .forEach(
+ c -> {
+ IOUtils.closeQuietly(c);
+ }));
customThreadPool.submit(() -> IOUtils.closeQuietly(controlClientCloud));
customThreadPool.submit(() -> IOUtils.closeQuietly(cloudClient));
ExecutorUtil.shutdownAndAwaitTermination(customThreadPool);
-
+
coreClients.clear();
-
+
super.destroyServers();
}
@@ -1743,32 +2021,49 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
cloudClient.commit();
}
- protected CollectionAdminResponse createCollection(String collectionName, String configSetName, int numShards, int replicationFactor) throws SolrServerException, IOException, InterruptedException, TimeoutException {
- return createCollection(null, collectionName, configSetName, numShards, replicationFactor, null, null);
+ protected CollectionAdminResponse createCollection(
+ String collectionName, String configSetName, int numShards, int replicationFactor)
+ throws SolrServerException, IOException, InterruptedException, TimeoutException {
+ return createCollection(
+ null, collectionName, configSetName, numShards, replicationFactor, null, null);
}
- protected CollectionAdminResponse createCollection(Map<String,List<Integer>> collectionInfos, String collectionName, Map<String,Object> collectionProps, SolrClient client) throws SolrServerException, IOException, InterruptedException, TimeoutException{
+ protected CollectionAdminResponse createCollection(
+ Map<String, List<Integer>> collectionInfos,
+ String collectionName,
+ Map<String, Object> collectionProps,
+ SolrClient client)
+ throws SolrServerException, IOException, InterruptedException, TimeoutException {
return createCollection(collectionInfos, collectionName, collectionProps, client, "conf1");
}
// TODO: Use CollectionAdminRequest#createCollection() instead of a raw request
- protected CollectionAdminResponse createCollection(Map<String, List<Integer>> collectionInfos, String collectionName, Map<String, Object> collectionProps, SolrClient client, String confSetName) throws SolrServerException, IOException, InterruptedException, TimeoutException{
+ protected CollectionAdminResponse createCollection(
+ Map<String, List<Integer>> collectionInfos,
+ String collectionName,
+ Map<String, Object> collectionProps,
+ SolrClient client,
+ String confSetName)
+ throws SolrServerException, IOException, InterruptedException, TimeoutException {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionAction.CREATE.toString());
for (Map.Entry<String, Object> entry : collectionProps.entrySet()) {
- if(entry.getValue() !=null) params.set(entry.getKey(), String.valueOf(entry.getValue()));
+ if (entry.getValue() != null) params.set(entry.getKey(), String.valueOf(entry.getValue()));
}
Integer numShards = (Integer) collectionProps.get(CollectionHandlingUtils.NUM_SLICES);
- if(numShards==null){
+ if (numShards == null) {
String shardNames = (String) collectionProps.get(CollectionHandlingUtils.SHARDS_PROP);
- numShards = StrUtils.splitSmart(shardNames,',').size();
+ numShards = StrUtils.splitSmart(shardNames, ',').size();
}
Integer numNrtReplicas = (Integer) collectionProps.get(ZkStateReader.NRT_REPLICAS);
if (numNrtReplicas == null) {
numNrtReplicas = (Integer) collectionProps.get(ZkStateReader.REPLICATION_FACTOR);
}
- if(numNrtReplicas == null){
- numNrtReplicas = (Integer) CollectionHandlingUtils.COLLECTION_PROPS_AND_DEFAULTS.get(ZkStateReader.REPLICATION_FACTOR);
+ if (numNrtReplicas == null) {
+ numNrtReplicas =
+ (Integer)
+ CollectionHandlingUtils.COLLECTION_PROPS_AND_DEFAULTS.get(
+ ZkStateReader.REPLICATION_FACTOR);
}
if (numNrtReplicas == null) {
numNrtReplicas = Integer.valueOf(0);
@@ -1808,54 +2103,85 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
} else {
res.setResponse(client.request(request));
}
-
+
try {
- cloudClient.waitForState(collectionName, 30, TimeUnit.SECONDS, SolrCloudTestCase.activeClusterShape(numShards,
- numShards * (numNrtReplicas + numTlogReplicas + numPullReplicas)));
+ cloudClient.waitForState(
+ collectionName,
+ 30,
+ TimeUnit.SECONDS,
+ SolrCloudTestCase.activeClusterShape(
+ numShards, numShards * (numNrtReplicas + numTlogReplicas + numPullReplicas)));
} catch (TimeoutException e) {
- throw new RuntimeException("Timeout waiting for " + numShards + " shards and " + (numNrtReplicas + numTlogReplicas + numPullReplicas) + " replicas.", e);
+ throw new RuntimeException(
+ "Timeout waiting for "
+ + numShards
+ + " shards and "
+ + (numNrtReplicas + numTlogReplicas + numPullReplicas)
+ + " replicas.",
+ e);
}
return res;
}
+ protected CollectionAdminResponse createCollection(
+ Map<String, List<Integer>> collectionInfos,
+ String collectionName,
+ String configSetName,
+ int numShards,
+ int replicationFactor,
+ SolrClient client,
+ String createNodeSetStr)
+ throws SolrServerException, IOException, InterruptedException, TimeoutException {
- protected CollectionAdminResponse createCollection(Map<String,List<Integer>> collectionInfos,
- String collectionName, String configSetName, int numShards, int replicationFactor, SolrClient client, String createNodeSetStr) throws SolrServerException, IOException, InterruptedException, TimeoutException {
-
- int numNrtReplicas = useTlogReplicas()?0:replicationFactor;
- int numTlogReplicas = useTlogReplicas()?replicationFactor:0;
- return createCollection(collectionInfos, collectionName,
+ int numNrtReplicas = useTlogReplicas() ? 0 : replicationFactor;
+ int numTlogReplicas = useTlogReplicas() ? replicationFactor : 0;
+ return createCollection(
+ collectionInfos,
+ collectionName,
Utils.makeMap(
CollectionHandlingUtils.NUM_SLICES, numShards,
ZkStateReader.NRT_REPLICAS, numNrtReplicas,
ZkStateReader.TLOG_REPLICAS, numTlogReplicas,
ZkStateReader.PULL_REPLICAS, getPullReplicaCount(),
CollectionHandlingUtils.CREATE_NODE_SET, createNodeSetStr),
- client, configSetName);
- }
-
- protected CollectionAdminResponse createCollection(Map<String, List<Integer>> collectionInfos,
- String collectionName, int numShards, int replicationFactor, SolrClient client, String createNodeSetStr, String configName) throws SolrServerException, IOException, InterruptedException, TimeoutException {
+ client,
+ configSetName);
+ }
+
+ protected CollectionAdminResponse createCollection(
+ Map<String, List<Integer>> collectionInfos,
+ String collectionName,
+ int numShards,
+ int replicationFactor,
+ SolrClient client,
+ String createNodeSetStr,
+ String configName)
+ throws SolrServerException, IOException, InterruptedException, TimeoutException {
- int numNrtReplicas = useTlogReplicas()?0:replicationFactor;
- int numTlogReplicas = useTlogReplicas()?replicationFactor:0;
- return createCollection(collectionInfos, collectionName,
+ int numNrtReplicas = useTlogReplicas() ? 0 : replicationFactor;
+ int numTlogReplicas = useTlogReplicas() ? replicationFactor : 0;
+ return createCollection(
+ collectionInfos,
+ collectionName,
Utils.makeMap(
CollectionHandlingUtils.NUM_SLICES, numShards,
ZkStateReader.NRT_REPLICAS, numNrtReplicas,
ZkStateReader.TLOG_REPLICAS, numTlogReplicas,
ZkStateReader.PULL_REPLICAS, getPullReplicaCount(),
CollectionHandlingUtils.CREATE_NODE_SET, createNodeSetStr),
- client, configName);
+ client,
+ configName);
}
@Override
protected SolrClient createNewSolrClient(int port) {
return createNewSolrClient(DEFAULT_COLLECTION, port);
}
-
- protected SolrClient createNewSolrClient(int port, int connectionTimeoutMillis, int socketTimeoutMillis) {
- return createNewSolrClient(DEFAULT_COLLECTION, port, connectionTimeoutMillis, socketTimeoutMillis);
+
+ protected SolrClient createNewSolrClient(
+ int port, int connectionTimeoutMillis, int socketTimeoutMillis) {
+ return createNewSolrClient(
+ DEFAULT_COLLECTION, port, connectionTimeoutMillis, socketTimeoutMillis);
}
protected SolrClient createNewSolrClient(String coreName, int port) {
@@ -1869,8 +2195,9 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
throw new RuntimeException(ex);
}
}
-
- protected SolrClient createNewSolrClient(String coreName, int port, int connectionTimeoutMillis, int socketTimeoutMillis) {
+
+ protected SolrClient createNewSolrClient(
+ String coreName, int port, int connectionTimeoutMillis, int socketTimeoutMillis) {
try {
// setup the server...
String baseUrl = buildUrl(port);
@@ -1881,22 +2208,22 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
throw new RuntimeException(ex);
}
}
-
+
protected SolrClient createNewSolrClient(String collection, String baseUrl) {
try {
// setup the server...
- HttpSolrClient client = getHttpSolrClient(baseUrl + "/" + collection, DEFAULT_CONNECTION_TIMEOUT, 60000);
+ HttpSolrClient client =
+ getHttpSolrClient(baseUrl + "/" + collection, DEFAULT_CONNECTION_TIMEOUT, 60000);
return client;
- }
- catch (Exception ex) {
+ } catch (Exception ex) {
throw new RuntimeException(ex);
}
}
-
+
protected String getBaseUrl(HttpSolrClient client) {
- return client .getBaseURL().substring(
- 0, client.getBaseURL().length()
- - DEFAULT_COLLECTION.length() - 1);
+ return client
+ .getBaseURL()
+ .substring(0, client.getBaseURL().length() - DEFAULT_COLLECTION.length() - 1);
}
public static SolrInputDocument getDoc(Object... fields) throws Exception {
@@ -1905,50 +2232,73 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
return doc;
}
- private String checkCollectionExpectations(String collectionName, List<Integer> numShardsNumReplicaList, List<String> nodesAllowedToRunShards) {
+ private String checkCollectionExpectations(
+ String collectionName,
+ List<Integer> numShardsNumReplicaList,
+ List<String> nodesAllowedToRunShards) {
ClusterState clusterState = getCommonCloudSolrClient().getZkStateReader().getClusterState();
-
+
int expectedSlices = numShardsNumReplicaList.get(0);
- // The Math.min thing is here, because we expect replication-factor to be reduced to if there are not enough live nodes to spread all shards of a collection over different nodes
+ // The Math.min thing is here, because we expect replication-factor to be reduced to if there
+ // are not enough live nodes to spread all shards of a collection over different nodes
int expectedShardsPerSlice = numShardsNumReplicaList.get(1);
int expectedTotalShards = expectedSlices * expectedShardsPerSlice;
-// Map<String,DocCollection> collections = clusterState
-// .getCollectionStates();
- if (clusterState.hasCollection(collectionName)) {
- Map<String,Slice> slices = clusterState.getCollection(collectionName).getSlicesMap();
- // did we find expectedSlices slices/shards?
+ // Map<String,DocCollection> collections = clusterState
+ // .getCollectionStates();
+ if (clusterState.hasCollection(collectionName)) {
+ Map<String, Slice> slices = clusterState.getCollection(collectionName).getSlicesMap();
+ // did we find expectedSlices slices/shards?
if (slices.size() != expectedSlices) {
- return "Found new collection " + collectionName + ", but mismatch on number of slices. Expected: " + expectedSlices + ", actual: " + slices.size();
+ return "Found new collection "
+ + collectionName
+ + ", but mismatch on number of slices. Expected: "
+ + expectedSlices
+ + ", actual: "
+ + slices.size();
}
int totalShards = 0;
for (String sliceName : slices.keySet()) {
for (Replica replica : slices.get(sliceName).getReplicas()) {
- if (nodesAllowedToRunShards != null && !nodesAllowedToRunShards.contains(replica.getStr(ZkStateReader.NODE_NAME_PROP))) {
- return "Shard " + replica.getName() + " created on node " + replica.getNodeName() + " not allowed to run shards for the created collection " + collectionName;
+ if (nodesAllowedToRunShards != null
+ && !nodesAllowedToRunShards.contains(replica.getStr(ZkStateReader.NODE_NAME_PROP))) {
+ return "Shard "
+ + replica.getName()
+ + " created on node "
+ + replica.getNodeName()
+ + " not allowed to run shards for the created collection "
+ + collectionName;
}
}
totalShards += slices.get(sliceName).getReplicas().size();
}
if (totalShards != expectedTotalShards) {
- return "Found new collection " + collectionName + " with correct number of slices, but mismatch on number of shards. Expected: " + expectedTotalShards + ", actual: " + totalShards;
- }
+ return "Found new collection "
+ + collectionName
+ + " with correct number of slices, but mismatch on number of shards. Expected: "
+ + expectedTotalShards
+ + ", actual: "
+ + totalShards;
+ }
return null;
} else {
return "Could not find new collection " + collectionName;
}
}
- protected void checkForCollection(String collectionName,
+ protected void checkForCollection(
+ String collectionName,
List<Integer> numShardsNumReplicaList,
- List<String> nodesAllowedToRunShards) throws Exception {
+ List<String> nodesAllowedToRunShards)
+ throws Exception {
// check for an expectedSlices new collection - we poll the state
final TimeOut timeout = new TimeOut(120, TimeUnit.SECONDS, TimeSource.NANO_TIME);
boolean success = false;
String checkResult = "Didnt get to perform a single check";
- while (! timeout.hasTimedOut()) {
- checkResult = checkCollectionExpectations(collectionName,
- numShardsNumReplicaList, nodesAllowedToRunShards);
+ while (!timeout.hasTimedOut()) {
+ checkResult =
+ checkCollectionExpectations(
+ collectionName, numShardsNumReplicaList, nodesAllowedToRunShards);
if (checkResult == null) {
success = true;
break;
@@ -1960,19 +2310,21 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
fail(checkResult);
}
}
-
+
private CloudSolrClient commonCloudSolrClient;
-
+
protected CloudSolrClient getCommonCloudSolrClient() {
synchronized (this) {
if (commonCloudSolrClient == null) {
- commonCloudSolrClient = getCloudSolrClient(zkServer.getZkAddress(),
- random().nextBoolean(), 5000, 120000);
+ commonCloudSolrClient =
+ getCloudSolrClient(zkServer.getZkAddress(), random().nextBoolean(), 5000, 120000);
commonCloudSolrClient.setDefaultCollection(DEFAULT_COLLECTION);
commonCloudSolrClient.connect();
if (log.isInfoEnabled()) {
- log.info("Created commonCloudSolrClient with updatesToLeaders={} and parallelUpdates={}",
- commonCloudSolrClient.isUpdatesToLeaders(), commonCloudSolrClient.isParallelUpdates());
+ log.info(
+ "Created commonCloudSolrClient with updatesToLeaders={} and parallelUpdates={}",
+ commonCloudSolrClient.isUpdatesToLeaders(),
+ commonCloudSolrClient.isParallelUpdates());
}
}
}
@@ -1980,17 +2332,18 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
}
public static String getUrlFromZk(ClusterState clusterState, String collection) {
- Map<String,Slice> slices = clusterState.getCollection(collection).getSlicesMap();
+ Map<String, Slice> slices = clusterState.getCollection(collection).getSlicesMap();
if (slices == null) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Could not find collection:" + collection);
+ throw new SolrException(
+ SolrException.ErrorCode.BAD_REQUEST, "Could not find collection:" + collection);
}
- for (Map.Entry<String,Slice> entry : slices.entrySet()) {
+ for (Map.Entry<String, Slice> entry : slices.entrySet()) {
Slice slice = entry.getValue();
- Map<String,Replica> shards = slice.getReplicasMap();
- Set<Map.Entry<String,Replica>> shardEntries = shards.entrySet();
- for (Map.Entry<String,Replica> shardEntry : shardEntries) {
+ Map<String, Replica> shards = slice.getReplicasMap();
+ Set<Map.Entry<String, Replica>> shardEntries = shards.entrySet();
+ for (Map.Entry<String, Replica> shardEntry : shardEntries) {
final ZkNodeProps node = shardEntry.getValue();
final String nodeName = node.getStr(ZkStateReader.NODE_NAME_PROP);
if (clusterState.liveNodesContain(nodeName)) {
@@ -2002,12 +2355,11 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
throw new RuntimeException("Could not find a live node for collection:" + collection);
}
- public static void waitForNon403or404or503(HttpSolrClient collectionClient)
- throws Exception {
+ public static void waitForNon403or404or503(HttpSolrClient collectionClient) throws Exception {
SolrException exp = null;
final TimeOut timeout = new TimeOut(30, TimeUnit.SECONDS, TimeSource.NANO_TIME);
- while (! timeout.hasTimedOut()) {
+ while (!timeout.hasTimedOut()) {
boolean missing = false;
try {
@@ -2025,29 +2377,36 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
Thread.sleep(50);
}
- fail("Could not find the new collection - " + exp.code() + " : " + collectionClient.getBaseURL());
+ fail(
+ "Could not find the new collection - "
+ + exp.code()
+ + " : "
+ + collectionClient.getBaseURL());
}
- protected void createCollection(String collName,
- CloudSolrClient client,
- int replicationFactor ,
- int numShards ) throws Exception {
- int numNrtReplicas = useTlogReplicas()?0:replicationFactor;
- int numTlogReplicas = useTlogReplicas()?replicationFactor:0;
- Map<String, Object> props = Map.of(
- ZkStateReader.NRT_REPLICAS, numNrtReplicas,
- ZkStateReader.TLOG_REPLICAS, numTlogReplicas,
- ZkStateReader.PULL_REPLICAS, getPullReplicaCount(),
- CollectionHandlingUtils.NUM_SLICES, numShards);
- Map<String,List<Integer>> collectionInfos = new HashMap<>();
+ protected void createCollection(
+ String collName, CloudSolrClient client, int replicationFactor, int numShards)
+ throws Exception {
+ int numNrtReplicas = useTlogReplicas() ? 0 : replicationFactor;
+ int numTlogReplicas = useTlogReplicas() ? replicationFactor : 0;
+ Map<String, Object> props =
+ Map.of(
+ ZkStateReader.NRT_REPLICAS, numNrtReplicas,
+ ZkStateReader.TLOG_REPLICAS, numTlogReplicas,
+ ZkStateReader.PULL_REPLICAS, getPullReplicaCount(),
+ CollectionHandlingUtils.NUM_SLICES, numShards);
+ Map<String, List<Integer>> collectionInfos = new HashMap<>();
createCollection(collectionInfos, collName, props, client);
}
- protected void createCollectionRetry(String testCollectionName, String configSetName, int numShards, int replicationFactor)
+ protected void createCollectionRetry(
+ String testCollectionName, String configSetName, int numShards, int replicationFactor)
throws SolrServerException, IOException, InterruptedException, TimeoutException {
- CollectionAdminResponse resp = createCollection(testCollectionName, configSetName, numShards, replicationFactor);
+ CollectionAdminResponse resp =
+ createCollection(testCollectionName, configSetName, numShards, replicationFactor);
if (resp.getResponse().get("failure") != null) {
- CollectionAdminRequest.Delete req = CollectionAdminRequest.deleteCollection(testCollectionName);
+ CollectionAdminRequest.Delete req =
+ CollectionAdminRequest.deleteCollection(testCollectionName);
req.process(cloudClient);
resp = createCollection(testCollectionName, configSetName, numShards, replicationFactor);
@@ -2058,31 +2417,42 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
}
}
- protected Replica getShardLeader(String testCollectionName, String shardId, int timeoutSecs) throws Exception {
+ protected Replica getShardLeader(String testCollectionName, String shardId, int timeoutSecs)
+ throws Exception {
Replica leader = null;
long timeout = System.nanoTime() + TimeUnit.NANOSECONDS.convert(timeoutSecs, TimeUnit.SECONDS);
while (System.nanoTime() < timeout) {
Replica tmp = null;
try {
tmp = cloudClient.getZkStateReader().getLeaderRetry(testCollectionName, shardId);
- } catch (Exception exc) {}
+ } catch (Exception exc) {
+ }
if (tmp != null && "active".equals(tmp.getStr(ZkStateReader.STATE_PROP))) {
leader = tmp;
break;
}
Thread.sleep(1000);
}
- assertNotNull("Could not find active leader for " + shardId + " of " +
- testCollectionName + " after "+timeoutSecs+" secs; clusterState: " +
- printClusterStateInfo(testCollectionName), leader);
+ assertNotNull(
+ "Could not find active leader for "
+ + shardId
+ + " of "
+ + testCollectionName
+ + " after "
+ + timeoutSecs
+ + " secs; clusterState: "
+ + printClusterStateInfo(testCollectionName),
+ leader);
return leader;
}
- protected List<Replica> ensureAllReplicasAreActive(String testCollectionName, String shardId, int shards, int rf, int maxWaitSecs) throws Exception {
+ protected List<Replica> ensureAllReplicasAreActive(
+ String testCollectionName, String shardId, int shards, int rf, int maxWaitSecs)
+ throws Exception {
final RTimer timer = new RTimer();
- Map<String,Replica> notLeaders = new HashMap<>();
+ Map<String, Replica> notLeaders = new HashMap<>();
ZkStateReader zkr = cloudClient.getZkStateReader();
zkr.forceUpdateCollection(testCollectionName); // force the state to be fresh
@@ -2094,54 +2464,70 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
long waitMs = 0L;
long maxWaitMs = maxWaitSecs * 1000L;
Replica leader = null;
- ZkShardTerms zkShardTerms = new ZkShardTerms(testCollectionName, shardId, cloudClient.getZkStateReader().getZkClient());
+ ZkShardTerms zkShardTerms =
+ new ZkShardTerms(testCollectionName, shardId, cloudClient.getZkStateReader().getZkClient());
while (waitMs < maxWaitMs && !allReplicasUp) {
cs = cloudClient.getZkStateReader().getClusterState();
assertNotNull(cs);
final DocCollection docCollection = cs.getCollectionOrNull(testCollectionName);
assertNotNull("No collection found for " + testCollectionName, docCollection);
Slice shard = docCollection.getSlice(shardId);
- assertNotNull("No Slice for "+shardId, shard);
+ assertNotNull("No Slice for " + shardId, shard);
allReplicasUp = true; // assume true
Collection<Replica> replicas = shard.getReplicas();
- assertTrue("Did not find correct number of replicas. Expected:" + rf + " Found:" + replicas.size(), replicas.size() == rf);
-
+ assertTrue(
+ "Did not find correct number of replicas. Expected:" + rf + " Found:" + replicas.size(),
+ replicas.size() == rf);
+
leader = shard.getLeader();
assertNotNull(leader);
if (log.isInfoEnabled()) {
- log.info("Found {} replicas and leader on {} for {} in {}"
- , replicas.size(), leader.getNodeName(), shardId, testCollectionName);
+ log.info(
+ "Found {} replicas and leader on {} for {} in {}",
+ replicas.size(),
+ leader.getNodeName(),
+ shardId,
+ testCollectionName);
}
// ensure all replicas are "active" and identify the non-leader replica
for (Replica replica : replicas) {
- if (!zkShardTerms.canBecomeLeader(replica.getName()) ||
- replica.getState() != Replica.State.ACTIVE) {
+ if (!zkShardTerms.canBecomeLeader(replica.getName())
+ || replica.getState() != Replica.State.ACTIVE) {
if (log.isInfoEnabled()) {
log.info("Replica {} is currently {}", replica.getName(), replica.getState());
}
allReplicasUp = false;
}
- if (!leader.equals(replica))
- notLeaders.put(replica.getName(), replica);
+ if (!leader.equals(replica)) notLeaders.put(replica.getName(), replica);
}
if (!allReplicasUp) {
try {
Thread.sleep(500L);
- } catch (Exception ignoreMe) {}
+ } catch (Exception ignoreMe) {
+ }
waitMs += 500L;
}
} // end while
zkShardTerms.close();
if (!allReplicasUp)
- fail("Didn't see all replicas for shard "+shardId+" in "+testCollectionName+
- " come up within " + maxWaitMs + " ms! ClusterState: " + printClusterStateInfo());
+ fail(
+ "Didn't see all replicas for shard "
+ + shardId
+ + " in "
+ + testCollectionName
+ + " come up within "
+ + maxWaitMs
+ + " ms! ClusterState: "
+ + printClusterStateInfo());
if (notLeaders.isEmpty())
- fail("Didn't isolate any replicas that are not the leader! ClusterState: " + printClusterStateInfo());
+ fail(
+ "Didn't isolate any replicas that are not the leader! ClusterState: "
+ + printClusterStateInfo());
if (log.isInfoEnabled()) {
log.info("Took {} ms to see all replicas become active.", timer.getTime());
@@ -2162,7 +2548,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
if (collection != null) {
cs = clusterState.getCollection(collection).toString();
} else {
- Map<String,DocCollection> map = clusterState.getCollectionsMap();
+ Map<String, DocCollection> map = clusterState.getCollectionsMap();
CharArr out = new CharArr();
new JSONWriter(out, 2).write(map);
cs = out.toString();
@@ -2205,23 +2591,30 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
}
return reloadedOk;
}
-
- protected void logReplicaTypesReplicationInfo(String collectionName, ZkStateReader zkStateReader) throws KeeperException, InterruptedException, IOException {
+ protected void logReplicaTypesReplicationInfo(String collectionName, ZkStateReader zkStateReader)
+ throws KeeperException, InterruptedException, IOException {
log.info("## Collecting extra Replica.Type information of the cluster");
zkStateReader.updateLiveNodes();
StringBuilder builder = new StringBuilder();
zkStateReader.forceUpdateCollection(collectionName);
DocCollection collection = zkStateReader.getClusterState().getCollection(collectionName);
- for(Slice s:collection.getSlices()) {
+ for (Slice s : collection.getSlices()) {
Replica leader = s.getLeader();
- for (Replica r:s.getReplicas()) {
+ for (Replica r : s.getReplicas()) {
if (!r.isActive(zkStateReader.getClusterState().getLiveNodes())) {
- builder.append(String.format(Locale.ROOT, "Replica %s not in liveNodes or is not active%s", r.getName(), System.lineSeparator()));
+ builder.append(
+ String.format(
+ Locale.ROOT,
+ "Replica %s not in liveNodes or is not active%s",
+ r.getName(),
+ System.lineSeparator()));
continue;
}
if (r.equals(leader)) {
- builder.append(String.format(Locale.ROOT, "Replica %s is leader%s", r.getName(), System.lineSeparator()));
+ builder.append(
+ String.format(
+ Locale.ROOT, "Replica %s is leader%s", r.getName(), System.lineSeparator()));
}
logReplicationDetails(r, builder);
}
@@ -2229,19 +2622,23 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
log.info("Summary of the cluster: {}", builder);
}
- protected void waitForReplicationFromReplicas(String collectionName, ZkStateReader zkStateReader, TimeOut timeout) throws KeeperException, InterruptedException, IOException {
+ protected void waitForReplicationFromReplicas(
+ String collectionName, ZkStateReader zkStateReader, TimeOut timeout)
+ throws KeeperException, InterruptedException, IOException {
log.info("waitForReplicationFromReplicas: {}", collectionName);
zkStateReader.forceUpdateCollection(collectionName);
DocCollection collection = zkStateReader.getClusterState().getCollection(collectionName);
Map<String, CoreContainer> containers = new HashMap<>();
- for (JettySolrRunner runner:jettys) {
+ for (JettySolrRunner runner : jettys) {
if (!runner.isRunning()) {
continue;
}
containers.put(runner.getNodeName(), runner.getCoreContainer());
}
- for(Slice s:collection.getSlices()) {
- Replica leader = zkStateReader.getLeaderRetry(collectionName, s.getName(), (int)timeout.timeLeft(TimeUnit.MILLISECONDS));
+ for (Slice s : collection.getSlices()) {
+ Replica leader =
+ zkStateReader.getLeaderRetry(
+ collectionName, s.getName(), (int) timeout.timeLeft(TimeUnit.MILLISECONDS));
long leaderIndexVersion = -1;
while (!timeout.hasTimedOut()) {
leaderIndexVersion = getIndexVersion(leader);
@@ -2253,30 +2650,43 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
if (timeout.hasTimedOut()) {
fail("Unable to get leader indexVersion");
}
- for (Replica pullReplica:s.getReplicas(EnumSet.of(Replica.Type.PULL,Replica.Type.TLOG))) {
+ for (Replica pullReplica : s.getReplicas(EnumSet.of(Replica.Type.PULL, Replica.Type.TLOG))) {
if (!zkStateReader.getClusterState().liveNodesContain(pullReplica.getNodeName())) {
continue;
}
while (true) {
- long replicaIndexVersion = getIndexVersion(pullReplica);
+ long replicaIndexVersion = getIndexVersion(pullReplica);
if (leaderIndexVersion == replicaIndexVersion) {
if (log.isInfoEnabled()) {
- log.info("Leader replica's version ({}) in sync with replica({}): {} == {}"
- , leader.getName(), pullReplica.getName(), leaderIndexVersion, replicaIndexVersion);
+ log.info(
+ "Leader replica's version ({}) in sync with replica({}): {} == {}",
+ leader.getName(),
+ pullReplica.getName(),
+ leaderIndexVersion,
+ replicaIndexVersion);
}
-
+
// Make sure the host is serving the correct version
- try (SolrCore core = containers.get(pullReplica.getNodeName()).getCore(pullReplica.getCoreName())) {
+ try (SolrCore core =
+ containers.get(pullReplica.getNodeName()).getCore(pullReplica.getCoreName())) {
RefCounted<SolrIndexSearcher> ref = core.getRegisteredSearcher();
try {
SolrIndexSearcher searcher = ref.get();
- String servingVersion = searcher.getIndexReader().getIndexCommit().getUserData().get(SolrIndexWriter.COMMIT_TIME_MSEC_KEY);
+ String servingVersion =
+ searcher
+ .getIndexReader()
+ .getIndexCommit()
+ .getUserData()
+ .get(SolrIndexWriter.COMMIT_TIME_MSEC_KEY);
if (Long.parseLong(servingVersion) == replicaIndexVersion) {
break;
} else {
if (log.isInfoEnabled()) {
- log.info("Replica {} has the correct version replicated, but the searcher is not ready yet. Replicated version: {}, Serving version: {}"
- , pullReplica.getName(), replicaIndexVersion, servingVersion);
+ log.info(
+ "Replica {} has the correct version replicated, but the searcher is not ready yet. Replicated version: {}, Serving version: {}",
+ pullReplica.getName(),
+ replicaIndexVersion,
+ servingVersion);
}
}
} finally {
@@ -2286,17 +2696,31 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
} else {
if (timeout.hasTimedOut()) {
logReplicaTypesReplicationInfo(collectionName, zkStateReader);
- fail(String.format(Locale.ROOT, "Timed out waiting for replica %s (%d) to replicate from leader %s (%d)", pullReplica.getName(), replicaIndexVersion, leader.getName(), leaderIndexVersion));
+ fail(
+ String.format(
+ Locale.ROOT,
+ "Timed out waiting for replica %s (%d) to replicate from leader %s (%d)",
+ pullReplica.getName(),
+ replicaIndexVersion,
+ leader.getName(),
+ leaderIndexVersion));
}
if (leaderIndexVersion > replicaIndexVersion) {
if (log.isInfoEnabled()) {
- log.info("{} version is {} and leader's is {}, will wait for replication"
- , pullReplica.getName(), replicaIndexVersion, leaderIndexVersion);
+ log.info(
+ "{} version is {} and leader's is {}, will wait for replication",
+ pullReplica.getName(),
+ replicaIndexVersion,
+ leaderIndexVersion);
}
} else {
if (log.isInfoEnabled()) {
- log.info("Leader replica's version ({}) is lower than pull replica({}): {} < {}"
- , leader.getName(), pullReplica.getName(), leaderIndexVersion, replicaIndexVersion);
+ log.info(
+ "Leader replica's version ({}) is lower than pull replica({}): {} < {}",
+ leader.getName(),
+ pullReplica.getName(),
+ leaderIndexVersion,
+ replicaIndexVersion);
}
}
}
@@ -2305,14 +2729,14 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
}
}
}
-
+
protected void waitForAllWarmingSearchers() throws InterruptedException {
log.info("waitForAllWarmingSearchers");
- for (JettySolrRunner jetty:jettys) {
+ for (JettySolrRunner jetty : jettys) {
if (!jetty.isRunning()) {
continue;
}
- for (SolrCore core:jetty.getCoreContainer().getCores()) {
+ for (SolrCore core : jetty.getCoreContainer().getCores()) {
waitForWarming(core);
}
}
@@ -2326,18 +2750,31 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
try {
QueryResponse response = client.query(params);
@SuppressWarnings("unchecked")
- List<NamedList<Object>> commits = (List<NamedList<Object>>)response.getResponse().get(ReplicationHandler.CMD_SHOW_COMMITS);
- Collections.max(commits, (a,b)->((Long)a.get("indexVersion")).compareTo((Long)b.get("indexVersion")));
- return (long) Collections.max(commits, (a,b)->((Long)a.get("indexVersion")).compareTo((Long)b.get("indexVersion"))).get("indexVersion");
+ List<NamedList<Object>> commits =
+ (List<NamedList<Object>>)
+ response.getResponse().get(ReplicationHandler.CMD_SHOW_COMMITS);
+ Collections.max(
+ commits,
+ (a, b) -> ((Long) a.get("indexVersion")).compareTo((Long) b.get("indexVersion")));
+ return (long)
+ Collections.max(
+ commits,
+ (a, b) ->
+ ((Long) a.get("indexVersion")).compareTo((Long) b.get("indexVersion")))
+ .get("indexVersion");
} catch (SolrServerException e) {
- log.warn("Exception getting version from {}, will return an invalid version to retry.", replica.getName(), e);
+ log.warn(
+ "Exception getting version from {}, will return an invalid version to retry.",
+ replica.getName(),
+ e);
return -1;
}
}
}
-
- /**
+
+ /**
* Logs a WARN if collection can't be deleted, but does not fail or throw an exception
+ *
* @return true if success, else false
*/
protected static boolean attemptCollectionDelete(CloudSolrClient client, String collectionName) {
@@ -2359,19 +2796,26 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
params.set(ReplicationHandler.COMMAND, ReplicationHandler.CMD_DETAILS);
try {
QueryResponse response = client.query(params);
- builder.append(String.format(Locale.ROOT, "%s: %s%s", replica.getName(), response.getResponse(), System.lineSeparator()));
+ builder.append(
+ String.format(
+ Locale.ROOT,
+ "%s: %s%s",
+ replica.getName(),
+ response.getResponse(),
+ System.lineSeparator()));
} catch (SolrServerException e) {
log.warn("Unable to ger replication details for replica {}", replica.getName(), e);
}
}
}
- public static RequestStatusState getRequestStateAfterCompletion(String requestId, int waitForSeconds, SolrClient client)
+ public static RequestStatusState getRequestStateAfterCompletion(
+ String requestId, int waitForSeconds, SolrClient client)
throws IOException, SolrServerException {
RequestStatusState state = null;
final TimeOut timeout = new TimeOut(waitForSeconds, TimeUnit.SECONDS, TimeSource.NANO_TIME);
- while (!timeout.hasTimedOut()) {
+ while (!timeout.hasTimedOut()) {
state = getRequestState(requestId, client);
if (state == RequestStatusState.COMPLETED || state == RequestStatusState.FAILED) {
return state;
@@ -2380,18 +2824,21 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
- throw new RuntimeException("Interrupted whie waiting for request completion. Last state seen: " + state, e);
+ throw new RuntimeException(
+ "Interrupted whie waiting for request completion. Last state seen: " + state, e);
}
}
return state;
}
- static RequestStatusState getRequestState(int requestId, SolrClient client) throws IOException, SolrServerException {
+ static RequestStatusState getRequestState(int requestId, SolrClient client)
+ throws IOException, SolrServerException {
return getRequestState(String.valueOf(requestId), client);
}
- static RequestStatusState getRequestState(String requestId, SolrClient client) throws IOException, SolrServerException {
+ static RequestStatusState getRequestState(String requestId, SolrClient client)
+ throws IOException, SolrServerException {
CollectionAdminResponse response = getStatusResponse(requestId, client);
@SuppressWarnings({"rawtypes"})
@@ -2399,7 +2846,8 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
return RequestStatusState.fromKey((String) innerResponse.get("state"));
}
- static CollectionAdminResponse getStatusResponse(String requestId, SolrClient client) throws SolrServerException, IOException {
+ static CollectionAdminResponse getStatusResponse(String requestId, SolrClient client)
+ throws SolrServerException, IOException {
return CollectionAdminRequest.requestStatus(requestId).process(client);
}
@@ -2427,5 +2875,4 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
protected void forAllRestTestHarnesses(Consumer<RestTestHarness> op) {
restTestHarnesses.forEach(op);
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractMoveReplicaTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractMoveReplicaTestBase.java
index ba893ff236a..97ebe7470db 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractMoveReplicaTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractMoveReplicaTestBase.java
@@ -25,7 +25,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
-
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
@@ -70,11 +69,15 @@ public abstract class AbstractMoveReplicaTestBase extends SolrCloudTestCase {
.configure();
// If Collection API is distributed let's not wait for Overseer.
- if (isCollectionApiDistributed = new CollectionAdminRequest.RequestApiDistributedProcessing().process(cluster.getSolrClient()).getIsCollectionApiDistributed()) {
+ if (isCollectionApiDistributed =
+ new CollectionAdminRequest.RequestApiDistributedProcessing()
+ .process(cluster.getSolrClient())
+ .getIsCollectionApiDistributed()) {
return;
}
- NamedList<Object> overSeerStatus = cluster.getSolrClient().request(CollectionAdminRequest.getOverseerStatus());
+ NamedList<Object> overSeerStatus =
+ cluster.getSolrClient().request(CollectionAdminRequest.getOverseerStatus());
JettySolrRunner overseerJetty = null;
String overseerLeader = (String) overSeerStatus.get("leader");
for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {
@@ -98,7 +101,6 @@ public abstract class AbstractMoveReplicaTestBase extends SolrCloudTestCase {
}
@Test
- // commented out on: 17-Feb-2019 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // annotated on: 24-Dec-2018
public void test() throws Exception {
String coll = getTestClass().getSimpleName() + "_coll_" + inPlaceMove;
if (log.isInfoEnabled()) {
@@ -110,7 +112,9 @@ public abstract class AbstractMoveReplicaTestBase extends SolrCloudTestCase {
// random create tlog or pull type replicas with nrt
boolean isTlog = random().nextBoolean();
- CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(coll, "conf1", 2, 1, isTlog ? 1 : 0, !isTlog ? 1 : 0);
+ CollectionAdminRequest.Create create =
+ CollectionAdminRequest.createCollection(
+ coll, "conf1", 2, 1, isTlog ? 1 : 0, !isTlog ? 1 : 0);
cloudClient.request(create);
addDocs(coll, 100);
@@ -128,20 +132,24 @@ public abstract class AbstractMoveReplicaTestBase extends SolrCloudTestCase {
}
assertNotNull(targetNode);
String shardId = null;
- for (Slice slice : cloudClient.getZkStateReader().getClusterState().getCollection(coll).getSlices()) {
+ for (Slice slice :
+ cloudClient.getZkStateReader().getClusterState().getCollection(coll).getSlices()) {
if (slice.getReplicas().contains(replica)) {
shardId = slice.getName();
}
}
- int sourceNumCores = getNumOfCores(cloudClient, replica.getNodeName(), coll, replica.getType().name());
+ int sourceNumCores =
+ getNumOfCores(cloudClient, replica.getNodeName(), coll, replica.getType().name());
int targetNumCores = getNumOfCores(cloudClient, targetNode, coll, replica.getType().name());
- CollectionAdminRequest.MoveReplica moveReplica = createMoveReplicaRequest(coll, replica, targetNode);
+ CollectionAdminRequest.MoveReplica moveReplica =
+ createMoveReplicaRequest(coll, replica, targetNode);
moveReplica.setInPlaceMove(inPlaceMove);
String asyncId = IdUtils.randomId();
moveReplica.processAsync(asyncId, cloudClient);
- CollectionAdminRequest.RequestStatus requestStatus = CollectionAdminRequest.requestStatus(asyncId);
+ CollectionAdminRequest.RequestStatus requestStatus =
+ CollectionAdminRequest.requestStatus(asyncId);
// wait for async request success
boolean success = false;
for (int i = 0; i < 200; i++) {
@@ -154,8 +162,14 @@ public abstract class AbstractMoveReplicaTestBase extends SolrCloudTestCase {
Thread.sleep(500);
}
assertTrue(success);
- assertEquals("should be one less core on the source node!", sourceNumCores - 1, getNumOfCores(cloudClient, replica.getNodeName(), coll, replica.getType().name()));
- assertEquals("should be one more core on target node!", targetNumCores + 1, getNumOfCores(cloudClient, targetNode, coll, replica.getType().name()));
+ assertEquals(
+ "should be one less core on the source node!",
+ sourceNumCores - 1,
+ getNumOfCores(cloudClient, replica.getNodeName(), coll, replica.getType().name()));
+ assertEquals(
+ "should be one more core on target node!",
+ targetNumCores + 1,
+ getNumOfCores(cloudClient, targetNode, coll, replica.getType().name()));
// wait for recovery
boolean recovered = false;
for (int i = 0; i < 300; i++) {
@@ -194,7 +208,8 @@ public abstract class AbstractMoveReplicaTestBase extends SolrCloudTestCase {
}
assertTrue("replica never fully recovered", recovered);
- assertEquals(100, cluster.getSolrClient().query(coll, new SolrQuery("*:*")).getResults().getNumFound());
+ assertEquals(
+ 100, cluster.getSolrClient().query(coll, new SolrQuery("*:*")).getResults().getNumFound());
moveReplica = createMoveReplicaRequest(coll, replica, targetNode, shardId);
moveReplica.setInPlaceMove(inPlaceMove);
@@ -236,15 +251,11 @@ public abstract class AbstractMoveReplicaTestBase extends SolrCloudTestCase {
}
assertTrue("replica never fully recovered", recovered);
- assertEquals(100, cluster.getSolrClient().query(coll, new SolrQuery("*:*")).getResults().getNumFound());
+ assertEquals(
+ 100, cluster.getSolrClient().query(coll, new SolrQuery("*:*")).getResults().getNumFound());
}
- //Commented out 5-Dec-2017
- // @AwaitsFix(bugUrl = "https://issues.apache.org/jira/browse/SOLR-11458")
@Test
- // 12-Jun-2018 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // 17-Mar-2018 This JIRA is fixed, but this test still fails
- //17-Aug-2018 commented @LuceneTestCase.BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // 2-Aug-2018
- // commented out on: 17-Feb-2019 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // annotated on: 24-Dec-2018
public void testFailedMove() throws Exception {
String coll = getTestClass().getSimpleName() + "_failed_coll_" + inPlaceMove;
int REPLICATION = 2;
@@ -253,12 +264,15 @@ public abstract class AbstractMoveReplicaTestBase extends SolrCloudTestCase {
// random create tlog or pull type replicas with nrt
boolean isTlog = random().nextBoolean();
- CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(coll, "conf1", 2, 1, isTlog ? 1 : 0, !isTlog ? 1 : 0);
+ CollectionAdminRequest.Create create =
+ CollectionAdminRequest.createCollection(
+ coll, "conf1", 2, 1, isTlog ? 1 : 0, !isTlog ? 1 : 0);
cloudClient.request(create);
addDocs(coll, 100);
- NamedList<Object> overSeerStatus = cluster.getSolrClient().request(CollectionAdminRequest.getOverseerStatus());
+ NamedList<Object> overSeerStatus =
+ cluster.getSolrClient().request(CollectionAdminRequest.getOverseerStatus());
String overseerLeader = (String) overSeerStatus.get("leader");
// don't kill overseer in this test
@@ -273,13 +287,15 @@ public abstract class AbstractMoveReplicaTestBase extends SolrCloudTestCase {
Collections.shuffle(l, random());
String targetNode = null;
for (String node : liveNodes) {
- if (!replica.getNodeName().equals(node) && (isCollectionApiDistributed || !overseerLeader.equals(node))) {
+ if (!replica.getNodeName().equals(node)
+ && (isCollectionApiDistributed || !overseerLeader.equals(node))) {
targetNode = node;
break;
}
}
assertNotNull(targetNode);
- CollectionAdminRequest.MoveReplica moveReplica = createMoveReplicaRequest(coll, replica, targetNode);
+ CollectionAdminRequest.MoveReplica moveReplica =
+ createMoveReplicaRequest(coll, replica, targetNode);
moveReplica.setInPlaceMove(inPlaceMove);
// start moving
String asyncId = IdUtils.randomId();
@@ -292,12 +308,14 @@ public abstract class AbstractMoveReplicaTestBase extends SolrCloudTestCase {
break;
}
}
- CollectionAdminRequest.RequestStatus requestStatus = CollectionAdminRequest.requestStatus(asyncId);
+ CollectionAdminRequest.RequestStatus requestStatus =
+ CollectionAdminRequest.requestStatus(asyncId);
// wait for async request success
boolean success = true;
for (int i = 0; i < 200; i++) {
CollectionAdminRequest.RequestStatusResponse rsp = requestStatus.process(cloudClient);
- assertNotSame(rsp.getRequestStatus().toString(), rsp.getRequestStatus(), RequestStatusState.COMPLETED);
+ assertNotSame(
+ rsp.getRequestStatus().toString(), rsp.getRequestStatus(), RequestStatusState.COMPLETED);
if (rsp.getRequestStatus() == RequestStatusState.FAILED) {
success = false;
break;
@@ -307,35 +325,50 @@ public abstract class AbstractMoveReplicaTestBase extends SolrCloudTestCase {
assertFalse(success);
if (log.isInfoEnabled()) {
- log.info("--- current collection state: {}", cloudClient.getZkStateReader().getClusterState().getCollection(coll));
+ log.info(
+ "--- current collection state: {}",
+ cloudClient.getZkStateReader().getClusterState().getCollection(coll));
}
- assertEquals(100, cluster.getSolrClient().query(coll, new SolrQuery("*:*")).getResults().getNumFound());
+ assertEquals(
+ 100, cluster.getSolrClient().query(coll, new SolrQuery("*:*")).getResults().getNumFound());
}
- private CollectionAdminRequest.MoveReplica createMoveReplicaRequest(String coll, Replica replica, String targetNode, String shardId) {
+ private CollectionAdminRequest.MoveReplica createMoveReplicaRequest(
+ String coll, Replica replica, String targetNode, String shardId) {
return new CollectionAdminRequest.MoveReplica(coll, shardId, targetNode, replica.getNodeName());
}
- private CollectionAdminRequest.MoveReplica createMoveReplicaRequest(String coll, Replica replica, String targetNode) {
+ private CollectionAdminRequest.MoveReplica createMoveReplicaRequest(
+ String coll, Replica replica, String targetNode) {
return new CollectionAdminRequest.MoveReplica(coll, replica.getName(), targetNode);
}
private Replica getRandomReplica(String coll, CloudSolrClient cloudClient) {
- List<Replica> replicas = cloudClient.getZkStateReader().getClusterState().getCollection(coll).getReplicas();
+ List<Replica> replicas =
+ cloudClient.getZkStateReader().getClusterState().getCollection(coll).getReplicas();
Collections.shuffle(replicas, random());
return replicas.get(0);
}
- private void checkNumOfCores(CloudSolrClient cloudClient, String nodeName, String collectionName, int expectedCores) throws IOException, SolrServerException {
- assertEquals(nodeName + " does not have expected number of cores", expectedCores, getNumOfCores(cloudClient, nodeName, collectionName));
+ private void checkNumOfCores(
+ CloudSolrClient cloudClient, String nodeName, String collectionName, int expectedCores)
+ throws IOException, SolrServerException {
+ assertEquals(
+ nodeName + " does not have expected number of cores",
+ expectedCores,
+ getNumOfCores(cloudClient, nodeName, collectionName));
}
- private int getNumOfCores(CloudSolrClient cloudClient, String nodeName, String collectionName) throws IOException, SolrServerException {
+ private int getNumOfCores(CloudSolrClient cloudClient, String nodeName, String collectionName)
+ throws IOException, SolrServerException {
return getNumOfCores(cloudClient, nodeName, collectionName, null);
}
- private int getNumOfCores(CloudSolrClient cloudClient, String nodeName, String collectionName, String replicaType) throws IOException, SolrServerException {
- try (HttpSolrClient coreclient = getHttpSolrClient(cloudClient.getZkStateReader().getBaseUrlForNodeName(nodeName))) {
+ private int getNumOfCores(
+ CloudSolrClient cloudClient, String nodeName, String collectionName, String replicaType)
+ throws IOException, SolrServerException {
+ try (HttpSolrClient coreclient =
+ getHttpSolrClient(cloudClient.getZkStateReader().getBaseUrlForNodeName(nodeName))) {
CoreAdminResponse status = CoreAdminRequest.getStatus(null, coreclient);
if (status.getCoreStatus().size() == 0) {
return 0;
@@ -347,13 +380,15 @@ public abstract class AbstractMoveReplicaTestBase extends SolrCloudTestCase {
int size = 0;
for (Map.Entry<String, NamedList<Object>> stringNamedListEntry : status.getCoreStatus()) {
if (collectionName != null) {
- String coll = (String) stringNamedListEntry.getValue().findRecursive("cloud", "collection");
+ String coll =
+ (String) stringNamedListEntry.getValue().findRecursive("cloud", "collection");
if (!collectionName.equals(coll)) {
continue;
}
}
if (replicaType != null) {
- String type = (String) stringNamedListEntry.getValue().findRecursive("cloud", "replicaType");
+ String type =
+ (String) stringNamedListEntry.getValue().findRecursive("cloud", "replicaType");
if (!replicaType.equals(type)) {
continue;
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractRecoveryZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractRecoveryZkTestBase.java
index 388980ec2bd..e4dc3d55a43 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractRecoveryZkTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractRecoveryZkTestBase.java
@@ -20,7 +20,6 @@ import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
-
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
@@ -43,9 +42,7 @@ public abstract class AbstractRecoveryZkTestBase extends SolrCloudTestCase {
@BeforeClass
public static void setupCluster() throws Exception {
- configureCluster(2)
- .addConfig("conf", configset("cloud-minimal"))
- .configure();
+ configureCluster(2).addConfig("conf", configset("cloud-minimal")).configure();
}
private final List<StoppableIndexingThread> threads = new ArrayList<>();
@@ -62,14 +59,14 @@ public abstract class AbstractRecoveryZkTestBase extends SolrCloudTestCase {
}
@Test
- //commented 2-Aug-2018 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // 28-June-2018
public void test() throws Exception {
final String collection = "recoverytest";
CollectionAdminRequest.createCollection(collection, "conf", 1, 2)
.process(cluster.getSolrClient());
- waitForState("Expected a collection with one shard and two replicas", collection, clusterShape(1, 2));
+ waitForState(
+ "Expected a collection with one shard and two replicas", collection, clusterShape(1, 2));
cluster.getSolrClient().setDefaultCollection(collection);
// start a couple indexing threads
@@ -85,13 +82,13 @@ public abstract class AbstractRecoveryZkTestBase extends SolrCloudTestCase {
}
log.info("Indexing {} documents", maxDoc);
- final StoppableIndexingThread indexThread
- = new StoppableIndexingThread(null, cluster.getSolrClient(), "1", true, maxDoc, 1, true);
+ final StoppableIndexingThread indexThread =
+ new StoppableIndexingThread(null, cluster.getSolrClient(), "1", true, maxDoc, 1, true);
threads.add(indexThread);
indexThread.start();
- final StoppableIndexingThread indexThread2
- = new StoppableIndexingThread(null, cluster.getSolrClient(), "2", true, maxDoc, 1, true);
+ final StoppableIndexingThread indexThread2 =
+ new StoppableIndexingThread(null, cluster.getSolrClient(), "2", true, maxDoc, 1, true);
threads.add(indexThread2);
indexThread2.start();
@@ -123,15 +120,13 @@ public abstract class AbstractRecoveryZkTestBase extends SolrCloudTestCase {
indexThread.join();
indexThread2.join();
- new UpdateRequest()
- .commit(cluster.getSolrClient(), collection);
+ new UpdateRequest().commit(cluster.getSolrClient(), collection);
cluster.getSolrClient().waitForState(collection, 120, TimeUnit.SECONDS, clusterShape(1, 2));
// test that leader and replica have same doc count
state = getCollectionState(collection);
assertShardConsistency(state.getSlice("shard1"), true);
-
}
private void assertShardConsistency(Slice shard, boolean expectDocs) throws Exception {
@@ -139,18 +134,20 @@ public abstract class AbstractRecoveryZkTestBase extends SolrCloudTestCase {
long[] numCounts = new long[replicas.size()];
int i = 0;
for (Replica replica : replicas) {
- try (HttpSolrClient client = new HttpSolrClient.Builder(replica.getCoreUrl())
- .withHttpClient(cluster.getSolrClient().getHttpClient()).build()) {
- numCounts[i] = client.query(new SolrQuery("*:*").add("distrib", "false")).getResults().getNumFound();
+ try (HttpSolrClient client =
+ new HttpSolrClient.Builder(replica.getCoreUrl())
+ .withHttpClient(cluster.getSolrClient().getHttpClient())
+ .build()) {
+ numCounts[i] =
+ client.query(new SolrQuery("*:*").add("distrib", "false")).getResults().getNumFound();
i++;
}
}
for (int j = 1; j < replicas.size(); j++) {
if (numCounts[j] != numCounts[j - 1])
- fail("Mismatch in counts between replicas"); // TODO improve this!
+ fail("Mismatch in counts between replicas"); // TODO improve this!
if (numCounts[j] == 0 && expectDocs)
fail("Expected docs on shard " + shard.getName() + " but found none");
}
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractRestartWhileUpdatingTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractRestartWhileUpdatingTestBase.java
index a1e508cf209..9cb768310cd 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractRestartWhileUpdatingTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractRestartWhileUpdatingTestBase.java
@@ -20,7 +20,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
-
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.common.SolrInputDocument;
import org.junit.AfterClass;
@@ -29,7 +28,7 @@ import org.junit.Test;
public abstract class AbstractRestartWhileUpdatingTestBase extends AbstractFullDistribZkTestBase {
- //private static final String DISTRIB_UPDATE_CHAIN = "distrib-update-chain";
+ // private static final String DISTRIB_UPDATE_CHAIN = "distrib-update-chain";
private List<StoppableIndexingThread> threads;
private volatile boolean stopExpire = false;
@@ -38,12 +37,12 @@ public abstract class AbstractRestartWhileUpdatingTestBase extends AbstractFullD
super();
sliceCount = 1;
fixShardCount(3);
- schemaString = "schema15.xml"; // we need a string id
+ schemaString = "schema15.xml"; // we need a string id
useFactory("solr.StandardDirectoryFactory");
}
- public static String[] fieldNames = new String[]{"f_i", "f_f", "f_d", "f_l", "f_dt"};
- public static RandVal[] randVals = new RandVal[]{rint, rfloat, rdouble, rlong, rdate};
+ public static String[] fieldNames = new String[] {"f_i", "f_f", "f_d", "f_l", "f_dt"};
+ public static RandVal[] randVals = new RandVal[] {rint, rfloat, rdouble, rlong, rdate};
protected String[] getFieldNames() {
return fieldNames;
@@ -69,7 +68,6 @@ public abstract class AbstractRestartWhileUpdatingTestBase extends AbstractFullD
System.clearProperty("solr.autoSoftCommit.maxTime");
}
-
@Test
public void test() throws Exception {
handle.clear();
@@ -79,46 +77,48 @@ public abstract class AbstractRestartWhileUpdatingTestBase extends AbstractFullD
int[] maxDocList = new int[] {5000, 10000};
-
int maxDoc = maxDocList[random().nextInt(maxDocList.length - 1)];
int numThreads = random().nextInt(4) + 1;
threads = new ArrayList<>(numThreads);
- Thread expireThread = new Thread("expireThread") {
- public void run() {
- while (!stopExpire) {
- try {
- Thread.sleep(random().nextInt(15000));
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
+ Thread expireThread =
+ new Thread("expireThread") {
+ public void run() {
+ while (!stopExpire) {
+ try {
+ Thread.sleep(random().nextInt(15000));
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+
+ // try {
+ // chaosMonkey.expireRandomSession();
+ // } catch (KeeperException e) {
+ // throw new RuntimeException(e);
+ // } catch (InterruptedException e) {
+ // throw new RuntimeException(e);
+ // }
+ }
}
+ };
-// try {
-// chaosMonkey.expireRandomSession();
-// } catch (KeeperException e) {
-// throw new RuntimeException(e);
-// } catch (InterruptedException e) {
-// throw new RuntimeException(e);
-// }
- }
- }
- };
-
-// Currently unused
-// expireThread.start();
+ // Currently unused
+ // expireThread.start();
StoppableIndexingThread indexThread;
for (int i = 0; i < numThreads; i++) {
- indexThread = new StoppableIndexingThread(controlClient, cloudClient, Integer.toString(i), true, maxDoc, 1, true);
+ indexThread =
+ new StoppableIndexingThread(
+ controlClient, cloudClient, Integer.toString(i), true, maxDoc, 1, true);
threads.add(indexThread);
indexThread.start();
}
Thread.sleep(2000);
- int restartTimes = 1;//random().nextInt(4) + 1;;
+ int restartTimes = 1; // random().nextInt(4) + 1;;
for (int i = 0; i < restartTimes; i++) {
Thread.sleep(random().nextInt(30000));
stopAndStartAllReplicas();
@@ -167,12 +167,10 @@ public abstract class AbstractRestartWhileUpdatingTestBase extends AbstractFullD
}
@Override
- protected void indexDoc(SolrInputDocument doc) throws IOException,
- SolrServerException {
+ protected void indexDoc(SolrInputDocument doc) throws IOException, SolrServerException {
cloudClient.add(doc);
}
-
@Override
public void distribTearDown() throws Exception {
// make sure threads have been stopped...
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractSyncSliceTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractSyncSliceTestBase.java
index 4cfa67ed7f0..9b3a14e56df 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractSyncSliceTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractSyncSliceTestBase.java
@@ -16,6 +16,13 @@
*/
package org.apache.solr.cloud;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
@@ -31,18 +38,7 @@ import org.apache.solr.common.params.CollectionParams.CollectionAction;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.junit.Test;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
-/**
- * Test sync phase that occurs when Leader goes down and a new Leader is
- * elected.
- */
+/** Test sync phase that occurs when Leader goes down and a new Leader is elected. */
public abstract class AbstractSyncSliceTestBase extends AbstractFullDistribZkTestBase {
private boolean success = false;
@@ -62,156 +58,155 @@ public abstract class AbstractSyncSliceTestBase extends AbstractFullDistribZkTes
@Test
public void test() throws Exception {
-
+
handle.clear();
handle.put("timestamp", SKIPVAL);
-
+
waitForThingsToLevelOut(30, TimeUnit.SECONDS);
del("*:*");
List<CloudJettyRunner> skipServers = new ArrayList<>();
int docId = 0;
- indexDoc(skipServers, id, docId++, i1, 50, tlong, 50, t1,
- "to come to the aid of their country.");
-
- indexDoc(skipServers, id, docId++, i1, 50, tlong, 50, t1,
- "old haven was blue.");
-
+ indexDoc(
+ skipServers, id, docId++, i1, 50, tlong, 50, t1, "to come to the aid of their country.");
+
+ indexDoc(skipServers, id, docId++, i1, 50, tlong, 50, t1, "old haven was blue.");
+
skipServers.add(shardToJetty.get("shard1").get(1));
-
- indexDoc(skipServers, id, docId++, i1, 50, tlong, 50, t1,
- "but the song was fancy.");
-
+
+ indexDoc(skipServers, id, docId++, i1, 50, tlong, 50, t1, "but the song was fancy.");
+
skipServers.add(shardToJetty.get("shard1").get(2));
-
- indexDoc(skipServers, id,docId++, i1, 50, tlong, 50, t1,
- "under the moon and over the lake");
-
+
+ indexDoc(skipServers, id, docId++, i1, 50, tlong, 50, t1, "under the moon and over the lake");
+
commit();
-
+
waitForRecoveriesToFinish(false);
// shard should be inconsistent
String shardFailMessage = checkShardConsistency("shard1", true, false);
assertNotNull(shardFailMessage);
-
+
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionAction.SYNCSHARD.toString());
params.set("collection", "collection1");
params.set("shard", "shard1");
QueryRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
-
- String baseUrl = ((HttpSolrClient) shardToJetty.get("shard1").get(2).client.solrClient)
- .getBaseURL();
+
+ String baseUrl =
+ ((HttpSolrClient) shardToJetty.get("shard1").get(2).client.solrClient).getBaseURL();
baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length());
-
+
// we only set the connect timeout, not so timeout
try (HttpSolrClient baseClient = getHttpSolrClient(baseUrl, 30000)) {
baseClient.request(request);
}
waitForThingsToLevelOut(15, TimeUnit.SECONDS);
-
+
checkShardConsistency(false, true);
-
+
long cloudClientDocs = cloudClient.query(new SolrQuery("*:*")).getResults().getNumFound();
assertEquals(4, cloudClientDocs);
-
-
+
// kill the leader - new leader could have all the docs or be missing one
CloudJettyRunner leaderJetty = shardToLeaderJetty.get("shard1");
-
+
skipServers = getRandomOtherJetty(leaderJetty, null); // but not the leader
-
+
// this doc won't be on one node
- indexDoc(skipServers, id, docId++, i1, 50, tlong, 50, t1,
- "to come to the aid of their country.");
+ indexDoc(
+ skipServers, id, docId++, i1, 50, tlong, 50, t1, "to come to the aid of their country.");
commit();
-
-
+
Set<CloudJettyRunner> jetties = new HashSet<>();
jetties.addAll(shardToJetty.get("shard1"));
jetties.remove(leaderJetty);
assertEquals(getShardCount() - 1, jetties.size());
-
+
leaderJetty.jetty.stop();
-
+
Thread.sleep(3000);
-
+
waitForNoShardInconsistency();
-
+
Thread.sleep(1000);
-
+
checkShardConsistency(false, true);
-
+
cloudClientDocs = cloudClient.query(new SolrQuery("*:*")).getResults().getNumFound();
assertEquals(5, cloudClientDocs);
-
+
CloudJettyRunner deadJetty = leaderJetty;
-
+
// let's get the latest leader
while (deadJetty == leaderJetty) {
updateMappingsFromZk(this.jettys, this.clients);
leaderJetty = shardToLeaderJetty.get("shard1");
}
-
+
// bring back dead node
deadJetty.jetty.start(); // he is not the leader anymore
-
+
waitTillAllNodesActive();
-
+
skipServers = getRandomOtherJetty(leaderJetty, deadJetty);
- skipServers.addAll( getRandomOtherJetty(leaderJetty, deadJetty));
- // skip list should be
-
-// System.out.println("leader:" + leaderJetty.url);
-// System.out.println("dead:" + deadJetty.url);
-// System.out.println("skip list:" + skipServers);
-
+ skipServers.addAll(getRandomOtherJetty(leaderJetty, deadJetty));
+ // skip list should be
+
+ // System.out.println("leader:" + leaderJetty.url);
+ // System.out.println("dead:" + deadJetty.url);
+ // System.out.println("skip list:" + skipServers);
+
// we are skipping 2 nodes
assertEquals(2, skipServers.size());
-
+
// more docs than can peer sync
for (int i = 0; i < 300; i++) {
- indexDoc(skipServers, id, docId++, i1, 50, tlong, 50, t1,
- "to come to the aid of their country.");
+ indexDoc(
+ skipServers, id, docId++, i1, 50, tlong, 50, t1, "to come to the aid of their country.");
}
-
+
commit();
-
+
Thread.sleep(1000);
-
+
waitForRecoveriesToFinish(false);
-
+
// shard should be inconsistent
shardFailMessage = waitTillInconsistent();
assertNotNull(
"Test Setup Failure: shard1 should have just been set up to be inconsistent - but it's still consistent. Leader:"
- + leaderJetty.url + " Dead Guy:" + deadJetty.url + "skip list:" + skipServers, shardFailMessage);
-
+ + leaderJetty.url
+ + " Dead Guy:"
+ + deadJetty.url
+ + "skip list:"
+ + skipServers,
+ shardFailMessage);
+
// good place to test compareResults
boolean shouldFail = CloudInspectUtil.compareResults(controlClient, cloudClient);
assertTrue("A test that compareResults is working correctly failed", shouldFail);
-
+
jetties = new HashSet<>();
jetties.addAll(shardToJetty.get("shard1"));
jetties.remove(leaderJetty);
assertEquals(getShardCount() - 1, jetties.size());
-
// kill the current leader
leaderJetty.jetty.stop();
-
+
waitForNoShardInconsistency();
checkShardConsistency(true, true);
-
+
success = true;
}
private void waitTillAllNodesActive() throws Exception {
- for (int i = 0; i < 60; i++) {
+ for (int i = 0; i < 60; i++) {
Thread.sleep(3000);
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
ClusterState clusterState = zkStateReader.getClusterState();
@@ -220,7 +215,8 @@ public abstract class AbstractSyncSliceTestBase extends AbstractFullDistribZkTes
Collection<Replica> replicas = slice.getReplicas();
boolean allActive = true;
for (Replica replica : replicas) {
- if (!clusterState.liveNodesContain(replica.getNodeName()) || replica.getState() != Replica.State.ACTIVE) {
+ if (!clusterState.liveNodesContain(replica.getNodeName())
+ || replica.getState() != Replica.State.ACTIVE) {
allActive = false;
break;
}
@@ -235,12 +231,12 @@ public abstract class AbstractSyncSliceTestBase extends AbstractFullDistribZkTes
private String waitTillInconsistent() throws Exception, InterruptedException {
String shardFailMessage = null;
-
+
shardFailMessage = pollConsistency(shardFailMessage, 0);
shardFailMessage = pollConsistency(shardFailMessage, 3000);
shardFailMessage = pollConsistency(shardFailMessage, 5000);
shardFailMessage = pollConsistency(shardFailMessage, 15000);
-
+
return shardFailMessage;
}
@@ -258,8 +254,9 @@ public abstract class AbstractSyncSliceTestBase extends AbstractFullDistribZkTes
}
return shardFailMessage;
}
-
- private List<CloudJettyRunner> getRandomOtherJetty(CloudJettyRunner leader, CloudJettyRunner down) {
+
+ private List<CloudJettyRunner> getRandomOtherJetty(
+ CloudJettyRunner leader, CloudJettyRunner down) {
List<CloudJettyRunner> skipServers = new ArrayList<>();
List<CloudJettyRunner> candidates = new ArrayList<>();
candidates.addAll(shardToJetty.get("shard1"));
@@ -267,25 +264,25 @@ public abstract class AbstractSyncSliceTestBase extends AbstractFullDistribZkTes
if (leader != null) {
candidates.remove(leader);
}
-
+
if (down != null) {
candidates.remove(down);
}
-
+
CloudJettyRunner cjetty = candidates.get(random().nextInt(candidates.size()));
skipServers.add(cjetty);
return skipServers;
}
-
- protected void indexDoc(List<CloudJettyRunner> skipServers, Object... fields) throws IOException,
- SolrServerException {
+
+ protected void indexDoc(List<CloudJettyRunner> skipServers, Object... fields)
+ throws IOException, SolrServerException {
SolrInputDocument doc = new SolrInputDocument();
-
+
addFields(doc, fields);
addFields(doc, "rnd_b", true);
-
+
controlClient.add(doc);
-
+
UpdateRequest ureq = new UpdateRequest();
ureq.add(doc);
ModifiableSolrParams params = new ModifiableSolrParams();
@@ -295,7 +292,7 @@ public abstract class AbstractSyncSliceTestBase extends AbstractFullDistribZkTes
ureq.setParams(params);
ureq.process(cloudClient);
}
-
+
// skip the randoms - they can deadlock...
@Override
protected void indexr(Object... fields) throws Exception {
@@ -304,5 +301,4 @@ public abstract class AbstractSyncSliceTestBase extends AbstractFullDistribZkTes
addFields(doc, "rnd_b", true);
indexDoc(doc);
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractTlogReplayBufferedWhileIndexingTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractTlogReplayBufferedWhileIndexingTestBase.java
index 16aaf838047..55447f63b49 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractTlogReplayBufferedWhileIndexingTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractTlogReplayBufferedWhileIndexingTestBase.java
@@ -20,7 +20,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
-
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.common.SolrInputDocument;
@@ -29,7 +28,8 @@ import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
-public abstract class AbstractTlogReplayBufferedWhileIndexingTestBase extends AbstractFullDistribZkTestBase {
+public abstract class AbstractTlogReplayBufferedWhileIndexingTestBase
+ extends AbstractFullDistribZkTestBase {
private List<StoppableIndexingThread> threads;
@@ -37,7 +37,7 @@ public abstract class AbstractTlogReplayBufferedWhileIndexingTestBase extends Ab
super();
sliceCount = 1;
fixShardCount(2);
- schemaString = "schema15.xml"; // we need a string id
+ schemaString = "schema15.xml"; // we need a string id
}
@BeforeClass
@@ -78,7 +78,15 @@ public abstract class AbstractTlogReplayBufferedWhileIndexingTestBase extends Ab
for (int i = 0; i < numThreads; i++) {
boolean pauseBetweenUpdates = random().nextBoolean();
int batchSize = random().nextInt(4) + 1;
- indexThread = new StoppableIndexingThread(controlClient, cloudClient, Integer.toString(i), true, 900, batchSize, pauseBetweenUpdates);
+ indexThread =
+ new StoppableIndexingThread(
+ controlClient,
+ cloudClient,
+ Integer.toString(i),
+ true,
+ 900,
+ batchSize,
+ pauseBetweenUpdates);
threads.add(indexThread);
indexThread.start();
}
@@ -89,7 +97,8 @@ public abstract class AbstractTlogReplayBufferedWhileIndexingTestBase extends Ab
Thread.sleep(45000);
- waitForThingsToLevelOut(); // we can insert random update delays, so this can take a while, especially when beasting this test
+ waitForThingsToLevelOut(); // we can insert random update delays, so this can take a while,
+ // especially when beasting this test
Thread.sleep(2000);
@@ -102,16 +111,13 @@ public abstract class AbstractTlogReplayBufferedWhileIndexingTestBase extends Ab
waitForThingsToLevelOut(30, TimeUnit.SECONDS);
checkShardConsistency(false, false);
-
}
@Override
- protected void indexDoc(SolrInputDocument doc) throws IOException,
- SolrServerException {
+ protected void indexDoc(SolrInputDocument doc) throws IOException, SolrServerException {
cloudClient.add(doc);
}
-
@Override
public void distribTearDown() throws Exception {
// make sure threads have been stopped...
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractUnloadDistributedZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractUnloadDistributedZkTestBase.java
index de068bbf640..3a509dd0108 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractUnloadDistributedZkTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractUnloadDistributedZkTestBase.java
@@ -16,6 +16,15 @@
*/
package org.apache.solr.cloud;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Random;
+import java.util.Set;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
@@ -30,30 +39,20 @@ import org.apache.solr.common.cloud.ZkCoreNodeProps;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.ExecutorUtil;
+import org.apache.solr.common.util.SolrNamedThreadFactory;
import org.apache.solr.common.util.TimeSource;
import org.apache.solr.core.SolrCore;
-import org.apache.solr.common.util.SolrNamedThreadFactory;
import org.apache.solr.core.SolrPaths;
import org.apache.solr.util.TestInjection;
import org.apache.solr.util.TimeOut;
import org.junit.Test;
-
-import java.io.IOException;
-import java.nio.file.Path;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Random;
-import java.util.Set;
-import java.util.concurrent.SynchronousQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
/**
- * This test simply does a bunch of basic things in solrcloud mode and asserts things
- * work as expected.
+ * This test simply does a bunch of basic things in solrcloud mode and asserts things work as
+ * expected.
*/
-public abstract class AbstractUnloadDistributedZkTestBase extends AbstractBasicDistributedZkTestBase {
+public abstract class AbstractUnloadDistributedZkTestBase
+ extends AbstractBasicDistributedZkTestBase {
public AbstractUnloadDistributedZkTestBase() {
super();
}
@@ -64,30 +63,47 @@ public abstract class AbstractUnloadDistributedZkTestBase extends AbstractBasicD
@Test
public void test() throws Exception {
- jettys.forEach(j -> {
- Set<Path> allowPath = j.getCoreContainer().getAllowPaths();
- allowPath.clear();
- allowPath.add(SolrPaths.ALL_PATH); // Allow non-standard core instance path
- });
+ jettys.forEach(
+ j -> {
+ Set<Path> allowPath = j.getCoreContainer().getAllowPaths();
+ allowPath.clear();
+ allowPath.add(SolrPaths.ALL_PATH); // Allow non-standard core instance path
+ });
testCoreUnloadAndLeaders(); // long
testUnloadLotsOfCores(); // long
testUnloadShardAndCollection();
}
- private void checkCoreNamePresenceAndSliceCount(String collectionName, String coreName,
- boolean shouldBePresent, int expectedSliceCount) throws Exception {
+ private void checkCoreNamePresenceAndSliceCount(
+ String collectionName, String coreName, boolean shouldBePresent, int expectedSliceCount)
+ throws Exception {
final TimeOut timeout = new TimeOut(45, TimeUnit.SECONDS, TimeSource.NANO_TIME);
Boolean isPresent = null; // null meaning "don't know"
while (null == isPresent || shouldBePresent != isPresent) {
- final DocCollection docCollection = getCommonCloudSolrClient().getZkStateReader().getClusterState().getCollectionOrNull(collectionName);
- final Collection<Slice> slices = (docCollection != null) ? docCollection.getSlices() : Collections.emptyList();
+ final DocCollection docCollection =
+ getCommonCloudSolrClient()
+ .getZkStateReader()
+ .getClusterState()
+ .getCollectionOrNull(collectionName);
+ final Collection<Slice> slices =
+ (docCollection != null) ? docCollection.getSlices() : Collections.emptyList();
if (timeout.hasTimedOut()) {
printLayout();
- fail("checkCoreNamePresenceAndSliceCount failed:"
- +" collection="+collectionName+" CoreName="+coreName
- +" shouldBePresent="+shouldBePresent+" isPresent="+isPresent
- +" expectedSliceCount="+expectedSliceCount+" actualSliceCount="+slices.size());
+ fail(
+ "checkCoreNamePresenceAndSliceCount failed:"
+ + " collection="
+ + collectionName
+ + " CoreName="
+ + coreName
+ + " shouldBePresent="
+ + shouldBePresent
+ + " isPresent="
+ + isPresent
+ + " expectedSliceCount="
+ + expectedSliceCount
+ + " actualSliceCount="
+ + slices.size());
}
if (expectedSliceCount == slices.size()) {
isPresent = false;
@@ -103,27 +119,33 @@ public abstract class AbstractUnloadDistributedZkTestBase extends AbstractBasicD
}
}
- private void testUnloadShardAndCollection() throws Exception{
+ private void testUnloadShardAndCollection() throws Exception {
final int numShards = 2;
final String collection = "test_unload_shard_and_collection";
- final String coreName1 = collection+"_1";
- final String coreName2 = collection+"_2";
-
- assertEquals(0, CollectionAdminRequest.createCollection(collection, "conf1", numShards, 1)
- .setCreateNodeSet("")
- .process(cloudClient).getStatus());
- assertTrue(CollectionAdminRequest.addReplicaToShard(collection, "shard1")
- .setCoreName(coreName1)
- .setNode(jettys.get(0).getNodeName())
- .process(cloudClient).isSuccess());
-
- assertTrue(CollectionAdminRequest.addReplicaToShard(collection, "shard2")
- .setCoreName(coreName2)
- .setNode(jettys.get(0).getNodeName())
- .process(cloudClient).isSuccess());
-
+ final String coreName1 = collection + "_1";
+ final String coreName2 = collection + "_2";
+
+ assertEquals(
+ 0,
+ CollectionAdminRequest.createCollection(collection, "conf1", numShards, 1)
+ .setCreateNodeSet("")
+ .process(cloudClient)
+ .getStatus());
+ assertTrue(
+ CollectionAdminRequest.addReplicaToShard(collection, "shard1")
+ .setCoreName(coreName1)
+ .setNode(jettys.get(0).getNodeName())
+ .process(cloudClient)
+ .isSuccess());
+
+ assertTrue(
+ CollectionAdminRequest.addReplicaToShard(collection, "shard2")
+ .setCoreName(coreName2)
+ .setNode(jettys.get(0).getNodeName())
+ .process(cloudClient)
+ .isSuccess());
// does not mean they are active and up yet :*
waitForRecoveriesToFinish(collection, false);
@@ -139,18 +161,29 @@ public abstract class AbstractUnloadDistributedZkTestBase extends AbstractBasicD
adminClient.request(unloadCmd);
// there should still be two shards (as of SOLR-5209)
- checkCoreNamePresenceAndSliceCount(collection, unloadCmdCoreName1, false /* shouldBePresent */, numShards /* expectedSliceCount */);
+ checkCoreNamePresenceAndSliceCount(
+ collection,
+ unloadCmdCoreName1,
+ false /* shouldBePresent */,
+ numShards /* expectedSliceCount */);
// now unload one of the other
unloadCmd = new Unload(false);
unloadCmd.setCoreName(unloadCmdCoreName2);
adminClient.request(unloadCmd);
- checkCoreNamePresenceAndSliceCount(collection, unloadCmdCoreName2, false /* shouldBePresent */, numShards /* expectedSliceCount */);
+ checkCoreNamePresenceAndSliceCount(
+ collection,
+ unloadCmdCoreName2,
+ false /* shouldBePresent */,
+ numShards /* expectedSliceCount */);
}
- //printLayout();
- // the collection should still be present (as of SOLR-5209 replica removal does not cascade to remove the slice and collection)
- assertTrue("No longer found collection "+collection, getCommonCloudSolrClient().getZkStateReader().getClusterState().hasCollection(collection));
+ // printLayout();
+ // the collection should still be present (as of SOLR-5209 replica removal does not cascade to
+ // remove the slice and collection)
+ assertTrue(
+ "No longer found collection " + collection,
+ getCommonCloudSolrClient().getZkStateReader().getClusterState().hasCollection(collection));
}
protected SolrCore getFirstCore(String collection, JettySolrRunner jetty) {
@@ -169,24 +202,28 @@ public abstract class AbstractUnloadDistributedZkTestBase extends AbstractBasicD
private void testCoreUnloadAndLeaders() throws Exception {
JettySolrRunner jetty1 = jettys.get(0);
- assertEquals(0, CollectionAdminRequest
- .createCollection("unloadcollection", "conf1", 1,1)
- .setCreateNodeSet(jetty1.getNodeName())
- .process(cloudClient).getStatus());
+ assertEquals(
+ 0,
+ CollectionAdminRequest.createCollection("unloadcollection", "conf1", 1, 1)
+ .setCreateNodeSet(jetty1.getNodeName())
+ .process(cloudClient)
+ .getStatus());
ZkStateReader zkStateReader = getCommonCloudSolrClient().getZkStateReader();
zkStateReader.forceUpdateCollection("unloadcollection");
- int slices = zkStateReader.getClusterState().getCollection("unloadcollection").getSlices().size();
+ int slices =
+ zkStateReader.getClusterState().getCollection("unloadcollection").getSlices().size();
assertEquals(1, slices);
SolrCore solrCore = getFirstCore("unloadcollection", jetty1);
String core1DataDir = solrCore.getDataDir();
- assertTrue(CollectionAdminRequest
- .addReplicaToShard("unloadcollection", "shard1")
- .setCoreName("unloadcollection_shard1_replica2")
- .setNode(jettys.get(1).getNodeName())
- .process(cloudClient).isSuccess());
+ assertTrue(
+ CollectionAdminRequest.addReplicaToShard("unloadcollection", "shard1")
+ .setCoreName("unloadcollection_shard1_replica2")
+ .setNode(jettys.get(1).getNodeName())
+ .process(cloudClient)
+ .isSuccess());
zkStateReader.forceUpdateCollection("unloadcollection");
slices = zkStateReader.getClusterState().getCollection("unloadcollection").getSlices().size();
assertEquals(1, slices);
@@ -200,12 +237,12 @@ public abstract class AbstractUnloadDistributedZkTestBase extends AbstractBasicD
try (HttpSolrClient collectionClient = getHttpSolrClient(leaderProps.getCoreUrl())) {
// lets try and use the solrj client to index and retrieve a couple
// documents
- SolrInputDocument doc1 = getDoc(id, 6, i1, -600, tlong, 600, t1,
- "humpty dumpy sat on a wall");
- SolrInputDocument doc2 = getDoc(id, 7, i1, -600, tlong, 600, t1,
- "humpty dumpy3 sat on a walls");
- SolrInputDocument doc3 = getDoc(id, 8, i1, -600, tlong, 600, t1,
- "humpty dumpy2 sat on a walled");
+ SolrInputDocument doc1 =
+ getDoc(id, 6, i1, -600, tlong, 600, t1, "humpty dumpy sat on a wall");
+ SolrInputDocument doc2 =
+ getDoc(id, 7, i1, -600, tlong, 600, t1, "humpty dumpy3 sat on a walls");
+ SolrInputDocument doc3 =
+ getDoc(id, 8, i1, -600, tlong, 600, t1, "humpty dumpy2 sat on a walled");
collectionClient.add(doc1);
collectionClient.add(doc2);
collectionClient.add(doc3);
@@ -213,31 +250,35 @@ public abstract class AbstractUnloadDistributedZkTestBase extends AbstractBasicD
}
}
- assertTrue(CollectionAdminRequest
- .addReplicaToShard("unloadcollection", "shard1")
- .setCoreName("unloadcollection_shard1_replica3")
- .setNode(jettys.get(2).getNodeName())
- .process(cloudClient).isSuccess());
+ assertTrue(
+ CollectionAdminRequest.addReplicaToShard("unloadcollection", "shard1")
+ .setCoreName("unloadcollection_shard1_replica3")
+ .setNode(jettys.get(2).getNodeName())
+ .process(cloudClient)
+ .isSuccess());
waitForRecoveriesToFinish("unloadcollection", zkStateReader, false);
// so that we start with some versions when we reload...
TestInjection.skipIndexWriterCommitOnClose = true;
- try (HttpSolrClient addClient = getHttpSolrClient(jettys.get(2).getBaseUrl() + "/unloadcollection_shard1_replica3", 30000)) {
+ try (HttpSolrClient addClient =
+ getHttpSolrClient(
+ jettys.get(2).getBaseUrl() + "/unloadcollection_shard1_replica3", 30000)) {
// add a few docs
for (int x = 20; x < 100; x++) {
- SolrInputDocument doc1 = getDoc(id, x, i1, -600, tlong, 600, t1,
- "humpty dumpy sat on a wall");
+ SolrInputDocument doc1 =
+ getDoc(id, x, i1, -600, tlong, 600, t1, "humpty dumpy sat on a wall");
addClient.add(doc1);
}
}
// don't commit so they remain in the tran log
- //collectionClient.commit();
+ // collectionClient.commit();
// unload the leader
- try (HttpSolrClient collectionClient = getHttpSolrClient(leaderProps.getBaseUrl(), 15000, 30000)) {
+ try (HttpSolrClient collectionClient =
+ getHttpSolrClient(leaderProps.getBaseUrl(), 15000, 30000)) {
Unload unloadCmd = new Unload(false);
unloadCmd.setCoreName(leaderProps.getCoreName());
@@ -245,11 +286,13 @@ public abstract class AbstractUnloadDistributedZkTestBase extends AbstractBasicD
collectionClient.request(unloadCmd);
}
-// Thread.currentThread().sleep(500);
-// printLayout();
+ // Thread.currentThread().sleep(500);
+ // printLayout();
int tries = 50;
- while (leaderProps.getCoreUrl().equals(zkStateReader.getLeaderUrl("unloadcollection", "shard1", 15000))) {
+ while (leaderProps
+ .getCoreUrl()
+ .equals(zkStateReader.getLeaderUrl("unloadcollection", "shard1", 15000))) {
Thread.sleep(100);
if (tries-- == 0) {
fail("Leader never changed");
@@ -259,34 +302,40 @@ public abstract class AbstractUnloadDistributedZkTestBase extends AbstractBasicD
// ensure there is a leader
zkStateReader.getLeaderRetry("unloadcollection", "shard1", 15000);
- try (HttpSolrClient addClient = getHttpSolrClient(jettys.get(1).getBaseUrl() + "/unloadcollection_shard1_replica2", 30000, 90000)) {
+ try (HttpSolrClient addClient =
+ getHttpSolrClient(
+ jettys.get(1).getBaseUrl() + "/unloadcollection_shard1_replica2", 30000, 90000)) {
// add a few docs while the leader is down
for (int x = 101; x < 200; x++) {
- SolrInputDocument doc1 = getDoc(id, x, i1, -600, tlong, 600, t1,
- "humpty dumpy sat on a wall");
+ SolrInputDocument doc1 =
+ getDoc(id, x, i1, -600, tlong, 600, t1, "humpty dumpy sat on a wall");
addClient.add(doc1);
}
}
- assertTrue(CollectionAdminRequest
- .addReplicaToShard("unloadcollection", "shard1")
- .setCoreName("unloadcollection_shard1_replica4")
- .setNode(jettys.get(3).getNodeName())
- .process(cloudClient).isSuccess());
+ assertTrue(
+ CollectionAdminRequest.addReplicaToShard("unloadcollection", "shard1")
+ .setCoreName("unloadcollection_shard1_replica4")
+ .setNode(jettys.get(3).getNodeName())
+ .process(cloudClient)
+ .isSuccess());
waitForRecoveriesToFinish("unloadcollection", zkStateReader, false);
// unload the leader again
leaderProps = getLeaderUrlFromZk("unloadcollection", "shard1");
- try (HttpSolrClient collectionClient = getHttpSolrClient(leaderProps.getBaseUrl(), 15000, 30000)) {
+ try (HttpSolrClient collectionClient =
+ getHttpSolrClient(leaderProps.getBaseUrl(), 15000, 30000)) {
Unload unloadCmd = new Unload(false);
unloadCmd.setCoreName(leaderProps.getCoreName());
collectionClient.request(unloadCmd);
}
tries = 50;
- while (leaderProps.getCoreUrl().equals(zkStateReader.getLeaderUrl("unloadcollection", "shard1", 15000))) {
+ while (leaderProps
+ .getCoreUrl()
+ .equals(zkStateReader.getLeaderUrl("unloadcollection", "shard1", 15000))) {
Thread.sleep(100);
if (tries-- == 0) {
fail("Leader never changed");
@@ -296,32 +345,39 @@ public abstract class AbstractUnloadDistributedZkTestBase extends AbstractBasicD
zkStateReader.getLeaderRetry("unloadcollection", "shard1", 15000);
TestInjection.skipIndexWriterCommitOnClose = false; // set this back
- assertTrue(CollectionAdminRequest
- .addReplicaToShard("unloadcollection", "shard1")
- .setCoreName(leaderProps.getCoreName())
- .setDataDir(core1DataDir)
- .setNode(leaderProps.getNodeName())
- .process(cloudClient).isSuccess());
+ assertTrue(
+ CollectionAdminRequest.addReplicaToShard("unloadcollection", "shard1")
+ .setCoreName(leaderProps.getCoreName())
+ .setDataDir(core1DataDir)
+ .setNode(leaderProps.getNodeName())
+ .process(cloudClient)
+ .isSuccess());
waitForRecoveriesToFinish("unloadcollection", zkStateReader, false);
long found1, found3;
- try (HttpSolrClient adminClient = getHttpSolrClient(jettys.get(1).getBaseUrl() + "/unloadcollection_shard1_replica2", 15000, 30000)) {
+ try (HttpSolrClient adminClient =
+ getHttpSolrClient(
+ jettys.get(1).getBaseUrl() + "/unloadcollection_shard1_replica2", 15000, 30000)) {
adminClient.commit();
SolrQuery q = new SolrQuery("*:*");
q.set("distrib", false);
found1 = adminClient.query(q).getResults().getNumFound();
}
- try (HttpSolrClient adminClient = getHttpSolrClient(jettys.get(2).getBaseUrl() + "/unloadcollection_shard1_replica3", 15000, 30000)) {
+ try (HttpSolrClient adminClient =
+ getHttpSolrClient(
+ jettys.get(2).getBaseUrl() + "/unloadcollection_shard1_replica3", 15000, 30000)) {
adminClient.commit();
SolrQuery q = new SolrQuery("*:*");
q.set("distrib", false);
found3 = adminClient.query(q).getResults().getNumFound();
}
- try (HttpSolrClient adminClient = getHttpSolrClient(jettys.get(3).getBaseUrl() + "/unloadcollection_shard1_replica4", 15000, 30000)) {
+ try (HttpSolrClient adminClient =
+ getHttpSolrClient(
+ jettys.get(3).getBaseUrl() + "/unloadcollection_shard1_replica4", 15000, 30000)) {
adminClient.commit();
SolrQuery q = new SolrQuery("*:*");
q.set("distrib", false);
@@ -337,31 +393,43 @@ public abstract class AbstractUnloadDistributedZkTestBase extends AbstractBasicD
JettySolrRunner jetty = jettys.get(0);
try (final HttpSolrClient adminClient = (HttpSolrClient) jetty.newClient(15000, 60000)) {
int numReplicas = atLeast(3);
- ThreadPoolExecutor executor = new ExecutorUtil.MDCAwareThreadPoolExecutor(0, Integer.MAX_VALUE,
- 5, TimeUnit.SECONDS, new SynchronousQueue<>(),
- new SolrNamedThreadFactory("testExecutor"));
+ ThreadPoolExecutor executor =
+ new ExecutorUtil.MDCAwareThreadPoolExecutor(
+ 0,
+ Integer.MAX_VALUE,
+ 5,
+ TimeUnit.SECONDS,
+ new SynchronousQueue<>(),
+ new SolrNamedThreadFactory("testExecutor"));
try {
// create the cores
- createCollectionInOneInstance(adminClient, jetty.getNodeName(), executor, "multiunload", 2, numReplicas);
+ createCollectionInOneInstance(
+ adminClient, jetty.getNodeName(), executor, "multiunload", 2, numReplicas);
} finally {
ExecutorUtil.shutdownAndAwaitTermination(executor);
}
- executor = new ExecutorUtil.MDCAwareThreadPoolExecutor(0, Integer.MAX_VALUE, 5,
- TimeUnit.SECONDS, new SynchronousQueue<>(),
- new SolrNamedThreadFactory("testExecutor"));
+ executor =
+ new ExecutorUtil.MDCAwareThreadPoolExecutor(
+ 0,
+ Integer.MAX_VALUE,
+ 5,
+ TimeUnit.SECONDS,
+ new SynchronousQueue<>(),
+ new SolrNamedThreadFactory("testExecutor"));
try {
for (int j = 0; j < numReplicas; j++) {
final int freezeJ = j;
- executor.execute(() -> {
- Unload unloadCmd = new Unload(true);
- unloadCmd.setCoreName("multiunload" + freezeJ);
- try {
- adminClient.request(unloadCmd);
- } catch (SolrServerException | IOException e) {
- throw new RuntimeException(e);
- }
- });
+ executor.execute(
+ () -> {
+ Unload unloadCmd = new Unload(true);
+ unloadCmd.setCoreName("multiunload" + freezeJ);
+ try {
+ adminClient.request(unloadCmd);
+ } catch (SolrServerException | IOException e) {
+ throw new RuntimeException(e);
+ }
+ });
Thread.sleep(random().nextInt(50));
}
} finally {
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractVMParamsZkACLAndCredentialsProvidersTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractVMParamsZkACLAndCredentialsProvidersTestBase.java
index 415c2e91945..35247b5b3a5 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractVMParamsZkACLAndCredentialsProvidersTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractVMParamsZkACLAndCredentialsProvidersTestBase.java
@@ -25,7 +25,6 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.Properties;
-
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.cloud.SecurityAwareZkACLProvider;
import org.apache.solr.common.cloud.SolrZkClient;
@@ -40,25 +39,25 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AbstractVMParamsZkACLAndCredentialsProvidersTestBase extends SolrTestCaseJ4 {
-
+
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
+
private static final Charset DATA_ENCODING = StandardCharsets.UTF_8;
-
+
protected ZkTestServer zkServer;
-
+
protected Path zkDir;
-
+
@BeforeClass
public static void beforeClass() {
System.setProperty("solrcloud.skip.autorecovery", "true");
}
-
+
@AfterClass
public static void afterClass() throws InterruptedException {
System.clearProperty("solrcloud.skip.autorecovery");
}
-
+
@Override
public void setUp() throws Exception {
super.setUp();
@@ -66,61 +65,82 @@ public class AbstractVMParamsZkACLAndCredentialsProvidersTestBase extends SolrTe
log.info("####SETUP_START {}", getTestName());
}
createTempDir();
-
+
zkDir = createTempDir().resolve("zookeeper/server1/data");
log.info("ZooKeeper dataDir:{}", zkDir);
zkServer = new ZkTestServer(zkDir);
zkServer.run(false);
-
+
System.setProperty("zkHost", zkServer.getZkAddress());
setSecuritySystemProperties();
- SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(),
- AbstractZkTestCase.TIMEOUT, AbstractZkTestCase.TIMEOUT, null, null, null);
+ SolrZkClient zkClient =
+ new SolrZkClient(
+ zkServer.getZkHost(),
+ AbstractZkTestCase.TIMEOUT,
+ AbstractZkTestCase.TIMEOUT,
+ null,
+ null,
+ null);
zkClient.makePath("/solr", false, true);
zkClient.close();
zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT);
- zkClient.create("/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false);
- zkClient.makePath("/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false);
-
- zkClient.create(SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false);
+ zkClient.create(
+ "/protectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false);
+ zkClient.makePath(
+ "/protectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false);
+
+ zkClient.create(
+ SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH,
+ "content".getBytes(DATA_ENCODING),
+ CreateMode.PERSISTENT,
+ false);
zkClient.close();
-
+
clearSecuritySystemProperties();
zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT);
- // Currently no credentials on ZK connection, because those same VM-params are used for adding ACLs, and here we want
- // no (or completely open) ACLs added. Therefore hack your way into being authorized for creating anyway
- zkClient.getSolrZooKeeper().addAuthInfo("digest", ("connectAndAllACLUsername:connectAndAllACLPassword")
- .getBytes(StandardCharsets.UTF_8));
- zkClient.create("/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false);
- zkClient.makePath("/unprotectedMakePathNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false);
+ // Currently no credentials on ZK connection, because those same VM-params are used for adding
+ // ACLs, and here we want
+ // no (or completely open) ACLs added. Therefore hack your way into being authorized for
+ // creating anyway
+ zkClient
+ .getSolrZooKeeper()
+ .addAuthInfo(
+ "digest",
+ ("connectAndAllACLUsername:connectAndAllACLPassword").getBytes(StandardCharsets.UTF_8));
+ zkClient.create(
+ "/unprotectedCreateNode", "content".getBytes(DATA_ENCODING), CreateMode.PERSISTENT, false);
+ zkClient.makePath(
+ "/unprotectedMakePathNode",
+ "content".getBytes(DATA_ENCODING),
+ CreateMode.PERSISTENT,
+ false);
zkClient.close();
if (log.isInfoEnabled()) {
log.info("####SETUP_END {}", getTestName());
}
}
-
+
@Override
public void tearDown() throws Exception {
zkServer.shutdown();
-
+
clearSecuritySystemProperties();
-
+
super.tearDown();
}
-
+
@Test
public void testNoCredentials() throws Exception {
useNoCredentials();
- try (SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) {
- doTest(zkClient,
- false, false, false, false, false,
- false, false, false, false, false);
+ try (SolrZkClient zkClient =
+ new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) {
+ doTest(zkClient, false, false, false, false, false, false, false, false, false, false);
}
}
@@ -128,10 +148,9 @@ public class AbstractVMParamsZkACLAndCredentialsProvidersTestBase extends SolrTe
public void testWrongCredentials() throws Exception {
useWrongCredentials();
- try (SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) {
- doTest(zkClient,
- false, false, false, false, false,
- false, false, false, false, false);
+ try (SolrZkClient zkClient =
+ new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) {
+ doTest(zkClient, false, false, false, false, false, false, false, false, false, false);
}
}
@@ -139,21 +158,19 @@ public class AbstractVMParamsZkACLAndCredentialsProvidersTestBase extends SolrTe
public void testAllCredentials() throws Exception {
useAllCredentials();
- try (SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) {
- doTest(zkClient,
- true, true, true, true, true,
- true, true, true, true, true);
+ try (SolrZkClient zkClient =
+ new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) {
+ doTest(zkClient, true, true, true, true, true, true, true, true, true, true);
}
}
-
+
@Test
public void testReadonlyCredentials() throws Exception {
useReadonlyCredentials();
- try (SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) {
- doTest(zkClient,
- true, true, false, false, false,
- false, false, false, false, false);
+ try (SolrZkClient zkClient =
+ new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) {
+ doTest(zkClient, true, true, false, false, false, false, false, false, false, false);
}
}
@@ -161,10 +178,9 @@ public class AbstractVMParamsZkACLAndCredentialsProvidersTestBase extends SolrTe
public void testReadonlyCredentialsFromFile() throws Exception {
useReadonlyCredentialsFromFile();
- try (SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) {
- doTest(zkClient,
- true, true, false, false, false,
- false, false, false, false, false);
+ try (SolrZkClient zkClient =
+ new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) {
+ doTest(zkClient, true, true, false, false, false, false, false, false, false, false);
}
}
@@ -172,65 +188,104 @@ public class AbstractVMParamsZkACLAndCredentialsProvidersTestBase extends SolrTe
public void testAllCredentialsFromFile() throws Exception {
useAllCredentialsFromFile();
- try (SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) {
- doTest(zkClient,
- true, true, true, true, true,
- true, true, true, true, true);
+ try (SolrZkClient zkClient =
+ new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) {
+ doTest(zkClient, true, true, true, true, true, true, true, true, true, true);
}
}
@Test
public void testRepairACL() throws Exception {
clearSecuritySystemProperties();
- try (SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) {
- // Currently no credentials on ZK connection, because those same VM-params are used for adding ACLs, and here we want
- // no (or completely open) ACLs added. Therefore hack your way into being authorized for creating anyway
- zkClient.getSolrZooKeeper().addAuthInfo("digest", ("connectAndAllACLUsername:connectAndAllACLPassword")
- .getBytes(StandardCharsets.UTF_8));
-
- zkClient.create("/security.json", "{}".getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT, false);
+ try (SolrZkClient zkClient =
+ new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) {
+ // Currently no credentials on ZK connection, because those same VM-params are used for adding
+ // ACLs, and here we want
+ // no (or completely open) ACLs added. Therefore hack your way into being authorized for
+ // creating anyway
+ zkClient
+ .getSolrZooKeeper()
+ .addAuthInfo(
+ "digest",
+ ("connectAndAllACLUsername:connectAndAllACLPassword")
+ .getBytes(StandardCharsets.UTF_8));
+
+ zkClient.create(
+ "/security.json", "{}".getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT, false);
assertEquals(OPEN_ACL_UNSAFE, zkClient.getACL("/security.json", null, false));
}
setSecuritySystemProperties();
- try (SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) {
+ try (SolrZkClient zkClient =
+ new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) {
ZkController.createClusterZkNodes(zkClient);
assertNotEquals(OPEN_ACL_UNSAFE, zkClient.getACL("/security.json", null, false));
}
useReadonlyCredentials();
- try (SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) {
- NoAuthException e = assertThrows(NoAuthException.class, () -> zkClient.getData("/security.json", null, null, false));
+ try (SolrZkClient zkClient =
+ new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT)) {
+ NoAuthException e =
+ assertThrows(
+ NoAuthException.class, () -> zkClient.getData("/security.json", null, null, false));
assertEquals("/security.json", e.getPath());
}
}
-
+
public static void doTest(
SolrZkClient zkClient,
- boolean getData, boolean list, boolean create, boolean setData, boolean delete,
- boolean secureGet, boolean secureList, boolean secureCreate, boolean secureSet, boolean secureDelete) throws Exception {
+ boolean getData,
+ boolean list,
+ boolean create,
+ boolean setData,
+ boolean delete,
+ boolean secureGet,
+ boolean secureList,
+ boolean secureCreate,
+ boolean secureSet,
+ boolean secureDelete)
+ throws Exception {
doTest(zkClient, "/protectedCreateNode", getData, list, create, setData, delete);
doTest(zkClient, "/protectedMakePathNode", getData, list, create, setData, delete);
doTest(zkClient, "/unprotectedCreateNode", true, true, true, true, delete);
doTest(zkClient, "/unprotectedMakePathNode", true, true, true, true, delete);
- doTest(zkClient, SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH, secureGet, secureList, secureCreate, secureSet, secureDelete);
+ doTest(
+ zkClient,
+ SecurityAwareZkACLProvider.SECURITY_ZNODE_PATH,
+ secureGet,
+ secureList,
+ secureCreate,
+ secureSet,
+ secureDelete);
}
-
- protected static void doTest(SolrZkClient zkClient, String path, boolean getData, boolean list, boolean create, boolean setData, boolean delete) throws Exception {
+
+ protected static void doTest(
+ SolrZkClient zkClient,
+ String path,
+ boolean getData,
+ boolean list,
+ boolean create,
+ boolean setData,
+ boolean delete)
+ throws Exception {
doTest(getData, () -> zkClient.getData(path, null, null, false));
doTest(list, () -> zkClient.getChildren(path, null, false));
- doTest(create, () -> {
- zkClient.create(path + "/subnode", null, CreateMode.PERSISTENT, false);
- zkClient.delete(path + "/subnode", -1, false);
- });
- doTest(create, () -> {
- zkClient.makePath(path + "/subnode/subsubnode", false);
- zkClient.delete(path + "/subnode/subsubnode", -1, false);
- zkClient.delete(path + "/subnode", -1, false);
- });
-
- doTest(setData, () -> zkClient.setData(path, (byte[])null, false));
+ doTest(
+ create,
+ () -> {
+ zkClient.create(path + "/subnode", null, CreateMode.PERSISTENT, false);
+ zkClient.delete(path + "/subnode", -1, false);
+ });
+ doTest(
+ create,
+ () -> {
+ zkClient.makePath(path + "/subnode/subsubnode", false);
+ zkClient.delete(path + "/subnode/subsubnode", -1, false);
+ zkClient.delete(path + "/subnode", -1, false);
+ });
+
+ doTest(setData, () -> zkClient.setData(path, (byte[]) null, false));
// Actually about the ACLs on /solr, but that is protected
doTest(delete, () -> zkClient.delete(path, -1, false));
@@ -247,33 +302,57 @@ public class AbstractVMParamsZkACLAndCredentialsProvidersTestBase extends SolrTe
expectThrows(NoAuthException.class, action::run);
}
}
-
+
private void useNoCredentials() {
clearSecuritySystemProperties();
}
-
+
private void useWrongCredentials() {
clearSecuritySystemProperties();
-
- System.setProperty(SolrZkClient.ZK_CRED_PROVIDER_CLASS_NAME_VM_PARAM_NAME, VMParamsSingleSetCredentialsDigestZkCredentialsProvider.class.getName());
- System.setProperty(VMParamsSingleSetCredentialsDigestZkCredentialsProvider.DEFAULT_DIGEST_USERNAME_VM_PARAM_NAME, "connectAndAllACLUsername");
- System.setProperty(VMParamsSingleSetCredentialsDigestZkCredentialsProvider.DEFAULT_DIGEST_PASSWORD_VM_PARAM_NAME, "connectAndAllACLPasswordWrong");
+
+ System.setProperty(
+ SolrZkClient.ZK_CRED_PROVIDER_CLASS_NAME_VM_PARAM_NAME,
+ VMParamsSingleSetCredentialsDigestZkCredentialsProvider.class.getName());
+ System.setProperty(
+ VMParamsSingleSetCredentialsDigestZkCredentialsProvider
+ .DEFAULT_DIGEST_USERNAME_VM_PARAM_NAME,
+ "connectAndAllACLUsername");
+ System.setProperty(
+ VMParamsSingleSetCredentialsDigestZkCredentialsProvider
+ .DEFAULT_DIGEST_PASSWORD_VM_PARAM_NAME,
+ "connectAndAllACLPasswordWrong");
}
-
+
private void useAllCredentials() {
clearSecuritySystemProperties();
-
- System.setProperty(SolrZkClient.ZK_CRED_PROVIDER_CLASS_NAME_VM_PARAM_NAME, VMParamsSingleSetCredentialsDigestZkCredentialsProvider.class.getName());
- System.setProperty(VMParamsSingleSetCredentialsDigestZkCredentialsProvider.DEFAULT_DIGEST_USERNAME_VM_PARAM_NAME, "connectAndAllACLUsername");
- System.setProperty(VMParamsSingleSetCredentialsDigestZkCredentialsProvider.DEFAULT_DIGEST_PASSWORD_VM_PARAM_NAME, "connectAndAllACLPassword");
+
+ System.setProperty(
+ SolrZkClient.ZK_CRED_PROVIDER_CLASS_NAME_VM_PARAM_NAME,
+ VMParamsSingleSetCredentialsDigestZkCredentialsProvider.class.getName());
+ System.setProperty(
+ VMParamsSingleSetCredentialsDigestZkCredentialsProvider
+ .DEFAULT_DIGEST_USERNAME_VM_PARAM_NAME,
+ "connectAndAllACLUsername");
+ System.setProperty(
+ VMParamsSingleSetCredentialsDigestZkCredentialsProvider
+ .DEFAULT_DIGEST_PASSWORD_VM_PARAM_NAME,
+ "connectAndAllACLPassword");
}
-
+
private void useReadonlyCredentials() {
clearSecuritySystemProperties();
- System.setProperty(SolrZkClient.ZK_CRED_PROVIDER_CLASS_NAME_VM_PARAM_NAME, VMParamsSingleSetCredentialsDigestZkCredentialsProvider.class.getName());
- System.setProperty(VMParamsSingleSetCredentialsDigestZkCredentialsProvider.DEFAULT_DIGEST_USERNAME_VM_PARAM_NAME, "readonlyACLUsername");
- System.setProperty(VMParamsSingleSetCredentialsDigestZkCredentialsProvider.DEFAULT_DIGEST_PASSWORD_VM_PARAM_NAME, "readonlyACLPassword");
+ System.setProperty(
+ SolrZkClient.ZK_CRED_PROVIDER_CLASS_NAME_VM_PARAM_NAME,
+ VMParamsSingleSetCredentialsDigestZkCredentialsProvider.class.getName());
+ System.setProperty(
+ VMParamsSingleSetCredentialsDigestZkCredentialsProvider
+ .DEFAULT_DIGEST_USERNAME_VM_PARAM_NAME,
+ "readonlyACLUsername");
+ System.setProperty(
+ VMParamsSingleSetCredentialsDigestZkCredentialsProvider
+ .DEFAULT_DIGEST_PASSWORD_VM_PARAM_NAME,
+ "readonlyACLPassword");
}
private void useReadonlyCredentialsFromFile() throws IOException {
@@ -287,11 +366,19 @@ public class AbstractVMParamsZkACLAndCredentialsProvidersTestBase extends SolrTe
private void useCredentialsFromFile(String username, String password) throws IOException {
clearSecuritySystemProperties();
- System.setProperty(SolrZkClient.ZK_CRED_PROVIDER_CLASS_NAME_VM_PARAM_NAME, VMParamsSingleSetCredentialsDigestZkCredentialsProvider.class.getName());
+ System.setProperty(
+ SolrZkClient.ZK_CRED_PROVIDER_CLASS_NAME_VM_PARAM_NAME,
+ VMParamsSingleSetCredentialsDigestZkCredentialsProvider.class.getName());
Properties props = new Properties();
- props.setProperty(VMParamsSingleSetCredentialsDigestZkCredentialsProvider.DEFAULT_DIGEST_USERNAME_VM_PARAM_NAME, username);
- props.setProperty(VMParamsSingleSetCredentialsDigestZkCredentialsProvider.DEFAULT_DIGEST_PASSWORD_VM_PARAM_NAME, password);
+ props.setProperty(
+ VMParamsSingleSetCredentialsDigestZkCredentialsProvider
+ .DEFAULT_DIGEST_USERNAME_VM_PARAM_NAME,
+ username);
+ props.setProperty(
+ VMParamsSingleSetCredentialsDigestZkCredentialsProvider
+ .DEFAULT_DIGEST_PASSWORD_VM_PARAM_NAME,
+ password);
saveCredentialsFile(props);
}
@@ -300,26 +387,48 @@ public class AbstractVMParamsZkACLAndCredentialsProvidersTestBase extends SolrTe
try (FileWriter w = new FileWriter(tmp.toFile(), StandardCharsets.UTF_8)) {
props.store(w, "test");
}
- System.setProperty(VMParamsSingleSetCredentialsDigestZkCredentialsProvider.DEFAULT_DIGEST_FILE_VM_PARAM_NAME, tmp.toAbsolutePath().toString());
+ System.setProperty(
+ VMParamsSingleSetCredentialsDigestZkCredentialsProvider.DEFAULT_DIGEST_FILE_VM_PARAM_NAME,
+ tmp.toAbsolutePath().toString());
}
-
+
private void setSecuritySystemProperties() {
- System.setProperty(SolrZkClient.ZK_ACL_PROVIDER_CLASS_NAME_VM_PARAM_NAME, VMParamsAllAndReadonlyDigestZkACLProvider.class.getName());
- System.setProperty(SolrZkClient.ZK_CRED_PROVIDER_CLASS_NAME_VM_PARAM_NAME, VMParamsSingleSetCredentialsDigestZkCredentialsProvider.class.getName());
- System.setProperty(VMParamsSingleSetCredentialsDigestZkCredentialsProvider.DEFAULT_DIGEST_USERNAME_VM_PARAM_NAME, "connectAndAllACLUsername");
- System.setProperty(VMParamsSingleSetCredentialsDigestZkCredentialsProvider.DEFAULT_DIGEST_PASSWORD_VM_PARAM_NAME, "connectAndAllACLPassword");
- System.setProperty(VMParamsAllAndReadonlyDigestZkACLProvider.DEFAULT_DIGEST_READONLY_USERNAME_VM_PARAM_NAME, "readonlyACLUsername");
- System.setProperty(VMParamsAllAndReadonlyDigestZkACLProvider.DEFAULT_DIGEST_READONLY_PASSWORD_VM_PARAM_NAME, "readonlyACLPassword");
+ System.setProperty(
+ SolrZkClient.ZK_ACL_PROVIDER_CLASS_NAME_VM_PARAM_NAME,
+ VMParamsAllAndReadonlyDigestZkACLProvider.class.getName());
+ System.setProperty(
+ SolrZkClient.ZK_CRED_PROVIDER_CLASS_NAME_VM_PARAM_NAME,
+ VMParamsSingleSetCredentialsDigestZkCredentialsProvider.class.getName());
+ System.setProperty(
+ VMParamsSingleSetCredentialsDigestZkCredentialsProvider
+ .DEFAULT_DIGEST_USERNAME_VM_PARAM_NAME,
+ "connectAndAllACLUsername");
+ System.setProperty(
+ VMParamsSingleSetCredentialsDigestZkCredentialsProvider
+ .DEFAULT_DIGEST_PASSWORD_VM_PARAM_NAME,
+ "connectAndAllACLPassword");
+ System.setProperty(
+ VMParamsAllAndReadonlyDigestZkACLProvider.DEFAULT_DIGEST_READONLY_USERNAME_VM_PARAM_NAME,
+ "readonlyACLUsername");
+ System.setProperty(
+ VMParamsAllAndReadonlyDigestZkACLProvider.DEFAULT_DIGEST_READONLY_PASSWORD_VM_PARAM_NAME,
+ "readonlyACLPassword");
}
-
+
private void clearSecuritySystemProperties() {
System.clearProperty(SolrZkClient.ZK_ACL_PROVIDER_CLASS_NAME_VM_PARAM_NAME);
System.clearProperty(SolrZkClient.ZK_CRED_PROVIDER_CLASS_NAME_VM_PARAM_NAME);
- System.clearProperty(VMParamsSingleSetCredentialsDigestZkCredentialsProvider.DEFAULT_DIGEST_USERNAME_VM_PARAM_NAME);
- System.clearProperty(VMParamsSingleSetCredentialsDigestZkCredentialsProvider.DEFAULT_DIGEST_PASSWORD_VM_PARAM_NAME);
- System.clearProperty(VMParamsAllAndReadonlyDigestZkACLProvider.DEFAULT_DIGEST_READONLY_USERNAME_VM_PARAM_NAME);
- System.clearProperty(VMParamsAllAndReadonlyDigestZkACLProvider.DEFAULT_DIGEST_READONLY_PASSWORD_VM_PARAM_NAME);
- System.clearProperty(VMParamsSingleSetCredentialsDigestZkCredentialsProvider.DEFAULT_DIGEST_FILE_VM_PARAM_NAME);
+ System.clearProperty(
+ VMParamsSingleSetCredentialsDigestZkCredentialsProvider
+ .DEFAULT_DIGEST_USERNAME_VM_PARAM_NAME);
+ System.clearProperty(
+ VMParamsSingleSetCredentialsDigestZkCredentialsProvider
+ .DEFAULT_DIGEST_PASSWORD_VM_PARAM_NAME);
+ System.clearProperty(
+ VMParamsAllAndReadonlyDigestZkACLProvider.DEFAULT_DIGEST_READONLY_USERNAME_VM_PARAM_NAME);
+ System.clearProperty(
+ VMParamsAllAndReadonlyDigestZkACLProvider.DEFAULT_DIGEST_READONLY_PASSWORD_VM_PARAM_NAME);
+ System.clearProperty(
+ VMParamsSingleSetCredentialsDigestZkCredentialsProvider.DEFAULT_DIGEST_FILE_VM_PARAM_NAME);
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractZkTestCase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractZkTestCase.java
index 646270be9f0..029de293589 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractZkTestCase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractZkTestCase.java
@@ -18,24 +18,22 @@ package org.apache.solr.cloud;
import java.lang.invoke.MethodHandles;
import java.nio.file.Path;
-
import org.apache.solr.SolrTestCaseJ4;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- * Base test class for ZooKeeper tests.
- */
+/** Base test class for ZooKeeper tests. */
public abstract class AbstractZkTestCase extends SolrTestCaseJ4 {
private static final String ZOOKEEPER_FORCE_SYNC = "zookeeper.forceSync";
-
+
public static final int TIMEOUT = 45000;
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public static Path SOLRHOME;
+
static {
try {
SOLRHOME = SolrTestCaseJ4.TEST_PATH();
@@ -46,35 +44,31 @@ public abstract class AbstractZkTestCase extends SolrTestCaseJ4 {
}
}
- protected volatile static ZkTestServer zkServer;
-
- protected volatile static Path zkDir;
+ protected static volatile ZkTestServer zkServer;
+ protected static volatile Path zkDir;
@BeforeClass
public static void azt_beforeClass() throws Exception {
zkDir = createTempDir("zkData");
zkServer = new ZkTestServer(zkDir);
zkServer.run();
-
+
System.setProperty("solrcloud.skip.autorecovery", "true");
System.setProperty("zkHost", zkServer.getZkAddress());
System.setProperty("jetty.port", "0000");
System.setProperty(ZOOKEEPER_FORCE_SYNC, "false");
-
- zkServer.buildZooKeeper(SOLRHOME,
- "solrconfig.xml", "schema.xml");
+
+ zkServer.buildZooKeeper(SOLRHOME, "solrconfig.xml", "schema.xml");
initCore("solrconfig.xml", "schema.xml");
}
-
-
@Override
public void tearDown() throws Exception {
super.tearDown();
}
-
+
@AfterClass
public static void azt_afterClass() throws Exception {
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java b/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java
index 60b4ec02925..020445142c9 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java
@@ -28,7 +28,6 @@ import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
-
import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.cloud.AbstractFullDistribZkTestBase.CloudJettyRunner;
@@ -40,10 +39,10 @@ import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.cloud.ZkNodeProps;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.util.ExecutorUtil;
+import org.apache.solr.common.util.SolrNamedThreadFactory;
import org.apache.solr.common.util.TimeSource;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrCore;
-import org.apache.solr.common.util.SolrNamedThreadFactory;
import org.apache.solr.util.RTimer;
import org.apache.solr.util.TestInjection;
import org.apache.solr.util.TimeOut;
@@ -53,27 +52,33 @@ import org.slf4j.LoggerFactory;
/**
* The monkey can stop random or specific jetties used with SolrCloud.
- *
- * It can also run in a background thread and start and stop jetties
- * randomly.
- * TODO: expire multiple sessions / connectionloss at once
- * TODO: kill multiple jetties at once
- * TODO: ? add random headhunter mode that always kills the leader
- * TODO: chaosmonkey should be able to do cluster stop/start tests
+ *
+ * <p>It can also run in a background thread and start and stop jetties randomly.
+ *
+ * <p>TODO: expire multiple sessions / connectionloss at once
+ *
+ * <p>TODO: kill multiple jetties at once
+ *
+ * <p>TODO: ? add random headhunter mode that always kills the leader
+ *
+ * <p>TODO: chaosmonkey should be able to do cluster stop/start tests
*/
public class ChaosMonkey {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
+
private static final int NO_STOP_WARN_TIME = 60;
private static final int CONLOSS_PERCENT = 10; // 0 - 10 = 0 - 100%
private static final int EXPIRE_PERCENT = 10; // 0 - 10 = 0 - 100%
- private Map<String,List<CloudJettyRunner>> shardToJetty;
-
- private static final Boolean MONKEY_ENABLED = Boolean.valueOf(System.getProperty("solr.tests.cloud.cm.enabled", "true"));
- // NOTE: CONN_LOSS and EXP are currently being set to "false" intentionally here. Remove the default value once we know tests pass reliably under those conditions
- private static final String CONN_LOSS = System.getProperty("solr.tests.cloud.cm.connloss", "false");
+ private Map<String, List<CloudJettyRunner>> shardToJetty;
+
+ private static final Boolean MONKEY_ENABLED =
+ Boolean.valueOf(System.getProperty("solr.tests.cloud.cm.enabled", "true"));
+ // NOTE: CONN_LOSS and EXP are currently being set to "false" intentionally here. Remove the
+ // default value once we know tests pass reliably under those conditions
+ private static final String CONN_LOSS =
+ System.getProperty("solr.tests.cloud.cm.connloss", "false");
private static final String EXP = System.getProperty("solr.tests.cloud.cm.exp", "false");
-
+
private ZkTestServer zkServer;
private ZkStateReader zkStateReader;
private String collection;
@@ -82,41 +87,46 @@ public class ChaosMonkey {
private AtomicInteger starts = new AtomicInteger();
private AtomicInteger expires = new AtomicInteger();
private AtomicInteger connloss = new AtomicInteger();
-
+
private boolean expireSessions;
private boolean causeConnectionLoss;
private boolean aggressivelyKillLeaders;
- private Map<String,CloudJettyRunner> shardToLeaderJetty;
+ private Map<String, CloudJettyRunner> shardToLeaderJetty;
private volatile RTimer runTimer;
-
+
private List<CloudJettyRunner> deadPool = new ArrayList<>();
private Thread monkeyThread;
/**
- * Our own Random, seeded from LuceneTestCase on init, so that we can produce a consistent sequence
- * of random chaos regardless of if/how othe threads access the test randomness in other threads
+ * Our own Random, seeded from LuceneTestCase on init, so that we can produce a consistent
+ * sequence of random chaos regardless of if/how othe threads access the test randomness in other
+ * threads
+ *
* @see LuceneTestCase#random()
*/
private final Random chaosRandom;
-
- public ChaosMonkey(ZkTestServer zkServer, ZkStateReader zkStateReader,
- String collection, Map<String,List<CloudJettyRunner>> shardToJetty,
- Map<String,CloudJettyRunner> shardToLeaderJetty) {
+
+ public ChaosMonkey(
+ ZkTestServer zkServer,
+ ZkStateReader zkStateReader,
+ String collection,
+ Map<String, List<CloudJettyRunner>> shardToJetty,
+ Map<String, CloudJettyRunner> shardToLeaderJetty) {
this.shardToJetty = shardToJetty;
this.shardToLeaderJetty = shardToLeaderJetty;
this.zkServer = zkServer;
this.zkStateReader = zkStateReader;
this.collection = collection;
this.chaosRandom = new Random(LuceneTestCase.random().nextLong());
-
+
if (!MONKEY_ENABLED) {
monkeyLog("The Monkey is Disabled and will not run");
return;
}
-
+
if (EXP != null) {
- expireSessions = Boolean.parseBoolean(EXP);
+ expireSessions = Boolean.parseBoolean(EXP);
} else {
expireSessions = chaosRandom.nextBoolean();
}
@@ -125,38 +135,38 @@ public class ChaosMonkey {
} else {
causeConnectionLoss = chaosRandom.nextBoolean();
}
-
-
- monkeyLog("init - expire sessions:" + expireSessions
- + " cause connection loss:" + causeConnectionLoss);
+
+ monkeyLog(
+ "init - expire sessions:"
+ + expireSessions
+ + " cause connection loss:"
+ + causeConnectionLoss);
}
-
+
// TODO: expire all clients at once?
public void expireSession(final JettySolrRunner jetty) {
CoreContainer cores = jetty.getCoreContainer();
if (cores != null) {
monkeyLog("expire session for " + jetty.getLocalPort() + " !");
causeConnectionLoss(jetty);
- long sessionId = cores.getZkController().getZkClient()
- .getSolrZooKeeper().getSessionId();
+ long sessionId = cores.getZkController().getZkClient().getSolrZooKeeper().getSessionId();
zkServer.expire(sessionId);
}
-
}
-
+
public void expireRandomSession() throws KeeperException, InterruptedException {
String sliceName = getRandomSlice();
-
+
CloudJettyRunner jetty = getRandomJetty(sliceName, aggressivelyKillLeaders);
if (jetty != null) {
expireSession(jetty.jetty);
expires.incrementAndGet();
}
}
-
+
public void randomConnectionLoss() throws KeeperException, InterruptedException {
monkeyLog("Will cause connection loss!");
-
+
String sliceName = getRandomSlice();
CloudJettyRunner jetty = getRandomJetty(sliceName, aggressivelyKillLeaders);
if (jetty != null) {
@@ -164,7 +174,7 @@ public class ChaosMonkey {
connloss.incrementAndGet();
}
}
-
+
public static void causeConnectionLoss(JettySolrRunner jetty) {
CoreContainer cores = jetty.getCoreContainer();
if (cores != null) {
@@ -192,23 +202,25 @@ public class ChaosMonkey {
List<CloudJettyRunner> jetties = shardToJetty.get(key);
for (CloudJettyRunner jetty : jetties) {
Thread.sleep(pauseBetweenMs);
- Thread thread = new Thread(() -> {
- try {
- stopJetty(jetty);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }, "ChaosMonkey");
+ Thread thread =
+ new Thread(
+ () -> {
+ try {
+ stopJetty(jetty);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ },
+ "ChaosMonkey");
jettyThreads.add(thread);
thread.start();
-
}
}
for (Thread thread : jettyThreads) {
thread.join();
}
}
-
+
public void startAll() throws Exception {
Set<String> keys = shardToJetty.keySet();
for (String key : keys) {
@@ -218,14 +230,14 @@ public class ChaosMonkey {
}
}
}
-
+
public void stopShard(String slice) throws Exception {
List<CloudJettyRunner> jetties = shardToJetty.get(slice);
for (CloudJettyRunner jetty : jetties) {
stopJetty(jetty);
}
}
-
+
public void stopShardExcept(String slice, String shardName) throws Exception {
List<CloudJettyRunner> jetties = shardToJetty.get(slice);
for (CloudJettyRunner jetty : jetties) {
@@ -234,18 +246,18 @@ public class ChaosMonkey {
}
}
}
-
+
public JettySolrRunner getShard(String slice, int index) throws Exception {
JettySolrRunner jetty = shardToJetty.get(slice).get(index).jetty;
return jetty;
}
-
+
public CloudJettyRunner stopRandomShard() throws Exception {
String sliceName = getRandomSlice();
-
+
return stopRandomShard(sliceName);
}
-
+
public CloudJettyRunner stopRandomShard(String slice) throws Exception {
CloudJettyRunner cjetty = getRandomJetty(slice, aggressivelyKillLeaders);
if (cjetty != null) {
@@ -253,24 +265,24 @@ public class ChaosMonkey {
}
return cjetty;
}
-
-
+
public CloudJettyRunner killRandomShard() throws Exception {
// add all the shards to a list
String sliceName = getRandomSlice();
-
+
return killRandomShard(sliceName);
}
private String getRandomSlice() {
- Map<String,Slice> slices = zkStateReader.getClusterState().getCollection(collection).getSlicesMap();
-
+ Map<String, Slice> slices =
+ zkStateReader.getClusterState().getCollection(collection).getSlicesMap();
+
List<String> sliceKeyList = new ArrayList<>(slices.size());
sliceKeyList.addAll(slices.keySet());
String sliceName = sliceKeyList.get(chaosRandom.nextInt(sliceKeyList.size()));
return sliceName;
}
-
+
public CloudJettyRunner killRandomShard(String slice) throws Exception {
CloudJettyRunner cjetty = getRandomJetty(slice, aggressivelyKillLeaders);
if (cjetty != null) {
@@ -278,56 +290,58 @@ public class ChaosMonkey {
}
return cjetty;
}
-
- public CloudJettyRunner getRandomJetty(String slice, boolean aggressivelyKillLeaders) throws KeeperException, InterruptedException {
-
+
+ public CloudJettyRunner getRandomJetty(String slice, boolean aggressivelyKillLeaders)
+ throws KeeperException, InterruptedException {
+
int numActive = 0;
-
+
numActive = checkIfKillIsLegal(slice, numActive);
-
+
// TODO: stale state makes this a tough call
if (numActive < 2) {
// we cannot kill anyone
monkeyLog("only one active node in shard - monkey cannot kill :(");
return null;
}
-
+
// let's check the deadpool count
int numRunning = getNumRunning(slice);
-
+
if (numRunning < 2) {
// we cannot kill anyone
monkeyLog("only one active node in shard - monkey cannot kill :(");
return null;
}
-
+
if (numActive == 2) {
// we are careful
Thread.sleep(1000);
-
+
numActive = checkIfKillIsLegal(slice, numActive);
-
+
if (numActive < 2) {
// we cannot kill anyone
monkeyLog("only one active node in shard - monkey cannot kill :(");
return null;
}
-
+
numRunning = getNumRunning(slice);
-
+
if (numRunning < 2) {
// we cannot kill anyone
monkeyLog("only one active node in shard - monkey cannot kill :(");
return null;
}
}
-
+
boolean canKillIndexer = canKillIndexer(slice);
-
+
if (!canKillIndexer) {
- monkeyLog("Number of indexer nodes (nrt or tlog replicas) is not enough to kill one of them, Will only choose a pull replica to kill");
+ monkeyLog(
+ "Number of indexer nodes (nrt or tlog replicas) is not enough to kill one of them, Will only choose a pull replica to kill");
}
-
+
int chance = chaosRandom.nextInt(10);
CloudJettyRunner cjetty = null;
if (chance <= 5 && aggressivelyKillLeaders && canKillIndexer) {
@@ -344,11 +358,12 @@ public class ChaosMonkey {
if (canKillIndexer || getTypeForJetty(slice, cjetty) == Replica.Type.PULL) {
break;
} else if (attempt > 20) {
- monkeyLog("Can't kill indexer nodes (nrt or tlog replicas) and couldn't find a random pull node after 20 attempts - monkey cannot kill :(");
+ monkeyLog(
+ "Can't kill indexer nodes (nrt or tlog replicas) and couldn't find a random pull node after 20 attempts - monkey cannot kill :(");
return null;
}
}
-
+
ZkNodeProps leader = null;
try {
leader = zkStateReader.getLeaderRetry(collection, slice);
@@ -368,13 +383,13 @@ public class ChaosMonkey {
return null;
}
- boolean isLeader = leader.getStr(ZkStateReader.NODE_NAME_PROP).equals(cjetty.nodeName)
- || rtIsLeader;
+ boolean isLeader =
+ leader.getStr(ZkStateReader.NODE_NAME_PROP).equals(cjetty.nodeName) || rtIsLeader;
if (!aggressivelyKillLeaders && isLeader) {
// we don't kill leaders...
monkeyLog("abort! I don't kill leaders");
return null;
- }
+ }
}
if (cjetty.jetty.getLocalPort() == -1) {
@@ -382,10 +397,11 @@ public class ChaosMonkey {
monkeyLog("abort! This guy is already dead");
return null;
}
-
- //System.out.println("num active:" + numActive + " for " + slice + " sac:" + jetty.getLocalPort());
+
+ // System.out.println("num active:" + numActive + " for " + slice + " sac:" +
+ // jetty.getLocalPort());
monkeyLog("chose a victim! " + cjetty.jetty.getLocalPort());
-
+
return cjetty;
}
@@ -401,12 +417,13 @@ public class ChaosMonkey {
private Type getTypeForJetty(String sliceName, CloudJettyRunner cjetty) {
DocCollection docCollection = zkStateReader.getClusterState().getCollection(collection);
-
+
Slice slice = docCollection.getSlice(sliceName);
-
+
ZkNodeProps props = slice.getReplicasMap().get(cjetty.coreNodeName);
if (props == null) {
- throw new RuntimeException("shard name " + cjetty.coreNodeName + " not found in " + slice.getReplicasMap().keySet());
+ throw new RuntimeException(
+ "shard name " + cjetty.coreNodeName + " not found in " + slice.getReplicasMap().keySet());
}
return Replica.Type.valueOf(props.getStr(ZkStateReader.REPLICA_TYPE));
}
@@ -414,26 +431,31 @@ public class ChaosMonkey {
private boolean canKillIndexer(String sliceName) throws KeeperException, InterruptedException {
int numIndexersFoundInShard = 0;
for (CloudJettyRunner cloudJetty : shardToJetty.get(sliceName)) {
-
+
// get latest cloud state
zkStateReader.forceUpdateCollection(collection);
-
+
DocCollection docCollection = zkStateReader.getClusterState().getCollection(collection);
-
+
Slice slice = docCollection.getSlice(sliceName);
-
+
ZkNodeProps props = slice.getReplicasMap().get(cloudJetty.coreNodeName);
if (props == null) {
- throw new RuntimeException("shard name " + cloudJetty.coreNodeName + " not found in " + slice.getReplicasMap().keySet());
+ throw new RuntimeException(
+ "shard name "
+ + cloudJetty.coreNodeName
+ + " not found in "
+ + slice.getReplicasMap().keySet());
}
-
+
final Replica.State state = Replica.State.getState(props.getStr(ZkStateReader.STATE_PROP));
- final Replica.Type replicaType = Replica.Type.valueOf(props.getStr(ZkStateReader.REPLICA_TYPE));
+ final Replica.Type replicaType =
+ Replica.Type.valueOf(props.getStr(ZkStateReader.REPLICA_TYPE));
final String nodeName = props.getStr(ZkStateReader.NODE_NAME_PROP);
-
+
if (cloudJetty.jetty.isRunning()
&& state == Replica.State.ACTIVE
- && (replicaType == Replica.Type.TLOG || replicaType == Replica.Type.NRT)
+ && (replicaType == Replica.Type.TLOG || replicaType == Replica.Type.NRT)
&& zkStateReader.getClusterState().liveNodesContain(nodeName)) {
numIndexersFoundInShard++;
}
@@ -441,24 +463,29 @@ public class ChaosMonkey {
return numIndexersFoundInShard > 1;
}
- private int checkIfKillIsLegal(String sliceName, int numActive) throws KeeperException, InterruptedException {
+ private int checkIfKillIsLegal(String sliceName, int numActive)
+ throws KeeperException, InterruptedException {
for (CloudJettyRunner cloudJetty : shardToJetty.get(sliceName)) {
-
+
// get latest cloud state
zkStateReader.forceUpdateCollection(collection);
-
+
DocCollection docCollection = zkStateReader.getClusterState().getCollection(collection);
-
+
Slice slice = docCollection.getSlice(sliceName);
-
+
ZkNodeProps props = slice.getReplicasMap().get(cloudJetty.coreNodeName);
if (props == null) {
- throw new RuntimeException("shard name " + cloudJetty.coreNodeName + " not found in " + slice.getReplicasMap().keySet());
+ throw new RuntimeException(
+ "shard name "
+ + cloudJetty.coreNodeName
+ + " not found in "
+ + slice.getReplicasMap().keySet());
}
-
+
final Replica.State state = Replica.State.getState(props.getStr(ZkStateReader.STATE_PROP));
final String nodeName = props.getStr(ZkStateReader.NODE_NAME_PROP);
-
+
if (cloudJetty.jetty.isRunning()
&& state == Replica.State.ACTIVE
&& zkStateReader.getClusterState().liveNodesContain(nodeName)) {
@@ -467,7 +494,7 @@ public class ChaosMonkey {
}
return numActive;
}
-
+
// synchronously starts and stops shards randomly, unless there is only one
// active shard up for a slice or if there is one active and others recovering
public void startTheMonkey(boolean killLeaders, final int roundPauseUpperLimit) {
@@ -476,8 +503,7 @@ public class ChaosMonkey {
return;
}
monkeyLog("starting");
-
-
+
if (chaosRandom.nextBoolean()) {
monkeyLog("Jetty will not commit on close");
TestInjection.skipIndexWriterCommitOnClose = true;
@@ -486,39 +512,51 @@ public class ChaosMonkey {
this.aggressivelyKillLeaders = killLeaders;
runTimer = new RTimer();
// TODO: when kill leaders is on, lets kill a higher percentage of leaders
-
+
stop = false;
- monkeyThread = new Thread(() -> {
- while (!stop) {
- try {
+ monkeyThread =
+ new Thread(
+ () -> {
+ while (!stop) {
+ try {
- Thread.sleep(chaosRandom.nextInt(roundPauseUpperLimit));
+ Thread.sleep(chaosRandom.nextInt(roundPauseUpperLimit));
- causeSomeChaos();
+ causeSomeChaos();
- } catch (InterruptedException e) {
- //
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- monkeyLog("finished");
- monkeyLog("I ran for " + runTimer.getTime() / 1000 + "s. I stopped " + stops + " and I started " + starts
- + ". I also expired " + expires.get() + " and caused " + connloss
- + " connection losses");
- }, "ChaosMonkey");
+ } catch (InterruptedException e) {
+ //
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ monkeyLog("finished");
+ monkeyLog(
+ "I ran for "
+ + runTimer.getTime() / 1000
+ + "s. I stopped "
+ + stops
+ + " and I started "
+ + starts
+ + ". I also expired "
+ + expires.get()
+ + " and caused "
+ + connloss
+ + " connection losses");
+ },
+ "ChaosMonkey");
monkeyThread.start();
}
-
+
public static void monkeyLog(String msg) {
log.info("monkey: {}", msg);
}
-
- public static void monkeyLog(String msg, Object...logParams) {
+
+ public static void monkeyLog(String msg, Object... logParams) {
log.info("monkey: {}", msg, logParams);
}
-
+
public void stopTheMonkey() {
stop = true;
try {
@@ -529,15 +567,16 @@ public class ChaosMonkey {
runTimer.stop();
TestInjection.skipIndexWriterCommitOnClose = false;
- double runtime = runTimer.getTime()/1000.0f;
+ double runtime = runTimer.getTime() / 1000.0f;
if (runtime > NO_STOP_WARN_TIME && stops.get() == 0) {
- LuceneTestCase.fail("The Monkey ran for over " + NO_STOP_WARN_TIME +" seconds and no jetties were stopped - this is worth investigating!");
+ LuceneTestCase.fail(
+ "The Monkey ran for over "
+ + NO_STOP_WARN_TIME
+ + " seconds and no jetties were stopped - this is worth investigating!");
}
}
- /**
- * causes some randomly selected chaos
- */
+ /** causes some randomly selected chaos */
public void causeSomeChaos() throws Exception {
if (chaosRandom.nextBoolean()) {
if (!deadPool.isEmpty()) {
@@ -552,17 +591,17 @@ public class ChaosMonkey {
return;
}
}
-
+
int rnd = chaosRandom.nextInt(10);
-
+
if (expireSessions && rnd < EXPIRE_PERCENT) {
expireRandomSession();
- }
-
+ }
+
if (causeConnectionLoss && rnd < CONLOSS_PERCENT) {
randomConnectionLoss();
}
-
+
CloudJettyRunner cjetty;
if (chaosRandom.nextBoolean()) {
cjetty = stopRandomShard();
@@ -575,61 +614,69 @@ public class ChaosMonkey {
deadPool.add(cjetty);
}
}
-
+
public int getStarts() {
return starts.get();
}
public static void stop(List<JettySolrRunner> jettys) throws Exception {
- ExecutorService executor = new ExecutorUtil.MDCAwareThreadPoolExecutor(
- 0,
- Integer.MAX_VALUE,
- 15, TimeUnit.SECONDS,
- new SynchronousQueue<>(),
- new SolrNamedThreadFactory("ChaosMonkey"),
- false);
+ ExecutorService executor =
+ new ExecutorUtil.MDCAwareThreadPoolExecutor(
+ 0,
+ Integer.MAX_VALUE,
+ 15,
+ TimeUnit.SECONDS,
+ new SynchronousQueue<>(),
+ new SolrNamedThreadFactory("ChaosMonkey"),
+ false);
for (JettySolrRunner jetty : jettys) {
- executor.submit(() -> {
- try {
- jetty.stop();
- } catch (Exception e) {
- log.error("error stopping jetty", e);
- throw new RuntimeException(e);
- }
- });
+ executor.submit(
+ () -> {
+ try {
+ jetty.stop();
+ } catch (Exception e) {
+ log.error("error stopping jetty", e);
+ throw new RuntimeException(e);
+ }
+ });
}
ExecutorUtil.shutdownAndAwaitTermination(executor);
}
public static void start(List<JettySolrRunner> jettys) throws Exception {
- ExecutorService executor = new ExecutorUtil.MDCAwareThreadPoolExecutor(
- 0,
- Integer.MAX_VALUE,
- 15, TimeUnit.SECONDS,
- new SynchronousQueue<>(),
- new SolrNamedThreadFactory("ChaosMonkey"),
- false);
+ ExecutorService executor =
+ new ExecutorUtil.MDCAwareThreadPoolExecutor(
+ 0,
+ Integer.MAX_VALUE,
+ 15,
+ TimeUnit.SECONDS,
+ new SynchronousQueue<>(),
+ new SolrNamedThreadFactory("ChaosMonkey"),
+ false);
for (JettySolrRunner jetty : jettys) {
- executor.submit(() -> {
- try {
- jetty.start();
- } catch (Exception e) {
- log.error("error starting jetty", e);
- throw new RuntimeException(e);
- }
- });
+ executor.submit(
+ () -> {
+ try {
+ jetty.start();
+ } catch (Exception e) {
+ log.error("error starting jetty", e);
+ throw new RuntimeException(e);
+ }
+ });
}
ExecutorUtil.shutdownAndAwaitTermination(executor);
}
/**
- * You can call this method to wait while the ChaosMonkey is running, it waits approximately the specified time, and periodically
- * logs the status of the collection
+ * You can call this method to wait while the ChaosMonkey is running, it waits approximately the
+ * specified time, and periodically logs the status of the collection
+ *
* @param runLength The time in ms to wait
* @param collectionName The main collection being used for the ChaosMonkey
* @param zkStateReader current state reader
*/
- public static void wait(long runLength, String collectionName, ZkStateReader zkStateReader) throws InterruptedException {
+ public static void wait(long runLength, String collectionName, ZkStateReader zkStateReader)
+ throws InterruptedException {
TimeOut t = new TimeOut(runLength, TimeUnit.MILLISECONDS, TimeSource.NANO_TIME);
while (!t.hasTimedOut()) {
Thread.sleep(Math.min(1000, t.timeLeft(TimeUnit.MILLISECONDS)));
@@ -637,7 +684,8 @@ public class ChaosMonkey {
}
}
- private static void logCollectionStateSummary(String collectionName, ZkStateReader zkStateReader) {
+ private static void logCollectionStateSummary(
+ String collectionName, ZkStateReader zkStateReader) {
Pattern portPattern = Pattern.compile(".*:([0-9]*).*");
DocCollection docCollection = zkStateReader.getClusterState().getCollection(collectionName);
if (docCollection == null) {
@@ -645,15 +693,23 @@ public class ChaosMonkey {
}
StringBuilder builder = new StringBuilder();
builder.append("Collection status: {");
- for (Slice slice:docCollection.getSlices()) {
+ for (Slice slice : docCollection.getSlices()) {
builder.append(slice.getName()).append(": {");
- for (Replica replica:slice.getReplicas()) {
+ for (Replica replica : slice.getReplicas()) {
log.info("{}", replica);
java.util.regex.Matcher m = portPattern.matcher(replica.getBaseUrl());
m.find();
String jettyPort = m.group(1);
- builder.append(String.format(Locale.ROOT, "%s(%s): {state: %s, type: %s, leader: %s, Live: %s}, ",
- replica.getName(), jettyPort, replica.getState(), replica.getType(), (replica.get("leader")!= null), zkStateReader.getClusterState().liveNodesContain(replica.getNodeName())));
+ builder.append(
+ String.format(
+ Locale.ROOT,
+ "%s(%s): {state: %s, type: %s, leader: %s, Live: %s}, ",
+ replica.getName(),
+ jettyPort,
+ replica.getState(),
+ replica.getType(),
+ (replica.get("leader") != null),
+ zkStateReader.getClusterState().liveNodesContain(replica.getNodeName())));
}
if (slice.getReplicas().size() > 0) {
builder.setLength(builder.length() - 2);
@@ -666,5 +722,4 @@ public class ChaosMonkey {
builder.append("}");
monkeyLog(builder.toString());
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/CloudInspectUtil.java b/solr/test-framework/src/java/org/apache/solr/cloud/CloudInspectUtil.java
index fe8a5b8fc16..fbf5c52ddf2 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/CloudInspectUtil.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/CloudInspectUtil.java
@@ -16,6 +16,12 @@
*/
package org.apache.solr.cloud;
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest;
@@ -26,87 +32,92 @@ import org.apache.solr.common.params.SolrParams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.lang.invoke.MethodHandles;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
public class CloudInspectUtil {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
+
/**
- * When a and b are known to be different, this method tells if the difference
- * is legal given the adds and deletes that failed from b.
- *
+ * When a and b are known to be different, this method tells if the difference is legal given the
+ * adds and deletes that failed from b.
+ *
* @param a first list of docs
* @param b second list of docs
* @param aName label for first list of docs
- * @param bName label for second list of docs
+ * @param bName label for second list of docs
* @param bAddFails null or list of the ids of adds that failed for b
* @param bDeleteFails null or list of the ids of deletes that failed for b
* @return true if the difference in a and b is legal
*/
- public static boolean checkIfDiffIsLegal(SolrDocumentList a,
- SolrDocumentList b, String aName, String bName, Set<String> bAddFails,
+ public static boolean checkIfDiffIsLegal(
+ SolrDocumentList a,
+ SolrDocumentList b,
+ String aName,
+ String bName,
+ Set<String> bAddFails,
Set<String> bDeleteFails) {
boolean legal = true;
-
+
@SuppressWarnings({"rawtypes"})
Set<Map> setA = new HashSet<>();
for (SolrDocument sdoc : a) {
setA.add(new HashMap<>(sdoc));
}
-
+
@SuppressWarnings({"rawtypes"})
Set<Map> setB = new HashSet<>();
for (SolrDocument sdoc : b) {
setB.add(new HashMap<>(sdoc));
}
-
+
@SuppressWarnings({"rawtypes"})
Set<Map> onlyInA = new HashSet<>(setA);
onlyInA.removeAll(setB);
@SuppressWarnings({"rawtypes"})
Set<Map> onlyInB = new HashSet<>(setB);
onlyInB.removeAll(setA);
-
+
if (onlyInA.size() == 0 && onlyInB.size() == 0) {
throw new IllegalArgumentException("No difference between list a and b");
}
-
+
System.err.println("###### Only in " + aName + ": " + onlyInA);
System.err.println("###### Only in " + bName + ": " + onlyInB);
-
- for (@SuppressWarnings({"rawtypes"})Map doc : onlyInA) {
+
+ for (@SuppressWarnings({"rawtypes"}) Map doc : onlyInA) {
if (bAddFails == null || !bAddFails.contains(doc.get("id"))) {
legal = false;
// System.err.println("###### Only in " + aName + ": " + doc.get("id"));
} else {
- System.err.println("###### Only in " + aName + ": " + doc.get("id")
- + ", but this is expected because we found an add fail for "
- + doc.get("id"));
+ System.err.println(
+ "###### Only in "
+ + aName
+ + ": "
+ + doc.get("id")
+ + ", but this is expected because we found an add fail for "
+ + doc.get("id"));
}
}
-
- for (@SuppressWarnings({"rawtypes"})Map doc : onlyInB) {
+
+ for (@SuppressWarnings({"rawtypes"}) Map doc : onlyInB) {
if (bDeleteFails == null || !bDeleteFails.contains(doc.get("id"))) {
legal = false;
// System.err.println("###### Only in " + bName + ": " + doc.get("id"));
} else {
- System.err.println("###### Only in " + bName + ": " + doc.get("id")
- + ", but this is expected because we found a delete fail for "
- + doc.get("id"));
+ System.err.println(
+ "###### Only in "
+ + bName
+ + ": "
+ + doc.get("id")
+ + ", but this is expected because we found a delete fail for "
+ + doc.get("id"));
}
}
-
+
return legal;
}
-
+
/**
* Shows the difference between two lists of documents.
- *
+ *
* @param a the first list
* @param b the second list
* @param aName label for the first list
@@ -114,41 +125,41 @@ public class CloudInspectUtil {
* @return the documents only in list a
*/
@SuppressWarnings({"unchecked", "rawtypes"})
- public static Set<Map> showDiff(SolrDocumentList a, SolrDocumentList b,
- String aName, String bName) {
+ public static Set<Map> showDiff(
+ SolrDocumentList a, SolrDocumentList b, String aName, String bName) {
System.err.println("######" + aName + ": " + toStr(a, 10));
System.err.println("######" + bName + ": " + toStr(b, 10));
System.err.println("###### sizes=" + a.size() + "," + b.size());
-
+
Set<Map> setA = new HashSet<>();
for (SolrDocument sdoc : a) {
setA.add(new HashMap(sdoc));
}
-
+
Set<Map> setB = new HashSet<>();
for (SolrDocument sdoc : b) {
setB.add(new HashMap(sdoc));
}
-
+
Set<Map> onlyInA = new HashSet<>(setA);
onlyInA.removeAll(setB);
Set<Map> onlyInB = new HashSet<>(setB);
onlyInB.removeAll(setA);
-
+
if (onlyInA.size() > 0) {
System.err.println("###### Only in " + aName + ": " + onlyInA);
}
if (onlyInB.size() > 0) {
System.err.println("###### Only in " + bName + ": " + onlyInB);
}
-
+
onlyInA.addAll(onlyInB);
return onlyInA;
}
-
+
private static String toStr(SolrDocumentList lst, int maxSz) {
if (lst.size() <= maxSz) return lst.toString();
-
+
StringBuilder sb = new StringBuilder("SolrDocumentList[sz=" + lst.size());
if (lst.size() != lst.getNumFound()) {
sb.append(" numFound=").append(lst.getNumFound());
@@ -157,39 +168,58 @@ public class CloudInspectUtil {
sb.append(lst.subList(0, maxSz / 2).toString());
sb.append(" , [...] , ");
sb.append(lst.subList(lst.size() - maxSz / 2, lst.size()).toString());
-
+
return sb.toString();
}
-
/**
* Compares the results of the control and cloud clients.
- *
+ *
* @return true if the compared results are illegal.
*/
public static boolean compareResults(SolrClient controlClient, SolrClient cloudClient)
throws SolrServerException, IOException {
return compareResults(controlClient, cloudClient, null, null);
}
-
+
/**
* Compares the results of the control and cloud clients.
- *
+ *
* @return true if the compared results are illegal.
*/
- public static boolean compareResults(SolrClient controlClient, SolrClient cloudClient, Set<String> addFails, Set<String> deleteFails)
+ public static boolean compareResults(
+ SolrClient controlClient,
+ SolrClient cloudClient,
+ Set<String> addFails,
+ Set<String> deleteFails)
throws SolrServerException, IOException {
-
- SolrParams q = SolrTestCaseJ4.params("q","*:*","rows","0", "tests","checkShardConsistency(vsControl)"); // add a tag to aid in debugging via logs
+
+ SolrParams q =
+ SolrTestCaseJ4.params(
+ "q",
+ "*:*",
+ "rows",
+ "0",
+ "tests",
+ "checkShardConsistency(vsControl)"); // add a tag to aid in debugging via logs
SolrDocumentList controlDocList = controlClient.query(q).getResults();
long controlDocs = controlDocList.getNumFound();
SolrDocumentList cloudDocList = cloudClient.query(q).getResults();
long cloudClientDocs = cloudDocList.getNumFound();
-
+
// re-execute the query getting ids
- q = SolrTestCaseJ4.params("q", "*:*", "rows", "100000", "fl", "id", "tests", "checkShardConsistency(vsControl)/getIds"); // add a tag to aid in debugging via logs
+ q =
+ SolrTestCaseJ4.params(
+ "q",
+ "*:*",
+ "rows",
+ "100000",
+ "fl",
+ "id",
+ "tests",
+ "checkShardConsistency(vsControl)/getIds"); // add a tag to aid in debugging via logs
controlDocList = controlClient.query(q).getResults();
if (controlDocs != controlDocList.getNumFound()) {
log.error("Something changed! control now {}", controlDocList.getNumFound());
@@ -201,16 +231,22 @@ public class CloudInspectUtil {
}
if (controlDocs != cloudClientDocs && (addFails != null || deleteFails != null)) {
- boolean legal = CloudInspectUtil.checkIfDiffIsLegal(controlDocList, cloudDocList,
- "controlDocList", "cloudDocList", addFails, deleteFails);
+ boolean legal =
+ CloudInspectUtil.checkIfDiffIsLegal(
+ controlDocList,
+ cloudDocList,
+ "controlDocList",
+ "cloudDocList",
+ addFails,
+ deleteFails);
if (legal) {
return false;
}
}
-
+
@SuppressWarnings({"rawtypes"})
- Set<Map> differences = CloudInspectUtil.showDiff(controlDocList, cloudDocList,
- "controlDocList", "cloudDocList");
+ Set<Map> differences =
+ CloudInspectUtil.showDiff(controlDocList, cloudDocList, "controlDocList", "cloudDocList");
try {
// get versions for the mismatched ids
@@ -219,7 +255,7 @@ public class CloudInspectUtil {
// use filter() to allow being parsed as 'terms in set' query instead of a (weighted/scored)
// BooleanQuery so we don't trip too many boolean clauses
StringBuilder ids = new StringBuilder("filter(id:(");
- for (@SuppressWarnings({"rawtypes"})Map doc : differences) {
+ for (@SuppressWarnings({"rawtypes"}) Map doc : differences) {
ids.append(" ").append(doc.get("id"));
foundId = true;
}
@@ -227,9 +263,18 @@ public class CloudInspectUtil {
if (foundId) {
// get versions for those ids that don't match
- q = SolrTestCaseJ4.params("q", ids.toString(), "rows", "100000", "fl", "id,_version_",
- "sort", "id asc", "tests",
- "checkShardConsistency(vsControl)/getVers"); // add a tag to aid in
+ q =
+ SolrTestCaseJ4.params(
+ "q",
+ ids.toString(),
+ "rows",
+ "100000",
+ "fl",
+ "id,_version_",
+ "sort",
+ "id asc",
+ "tests",
+ "checkShardConsistency(vsControl)/getVers"); // add a tag to aid in
// debugging via logs
// use POST, the ids in the query above is constructed and could be huge
@@ -246,5 +291,4 @@ public class CloudInspectUtil {
return true;
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/ConfigRequest.java b/solr/test-framework/src/java/org/apache/solr/cloud/ConfigRequest.java
index 45f7604bbfd..92007134082 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/ConfigRequest.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/ConfigRequest.java
@@ -25,9 +25,8 @@ import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.SolrParams;
/**
- * A class for making a request to the config handler. Tests can use this
- * e.g. to add custom components, handlers, parsers, etc. to an otherwise
- * generic configset.
+ * A class for making a request to the config handler. Tests can use this e.g. to add custom
+ * components, handlers, parsers, etc. to an otherwise generic configset.
*/
@SuppressWarnings({"rawtypes"})
public class ConfigRequest extends SolrRequest {
@@ -46,7 +45,9 @@ public class ConfigRequest extends SolrRequest {
@Override
public RequestWriter.ContentWriter getContentWriter(String expectedType) {
- return message == null? null: new RequestWriter.StringPayloadContentWriter(message, CommonParams.JSON_MIME);
+ return message == null
+ ? null
+ : new RequestWriter.StringPayloadContentWriter(message, CommonParams.JSON_MIME);
}
@Override
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/FullThrottleStoppableIndexingThread.java b/solr/test-framework/src/java/org/apache/solr/cloud/FullThrottleStoppableIndexingThread.java
index a3a81c53cb6..5226ecf5170 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/FullThrottleStoppableIndexingThread.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/FullThrottleStoppableIndexingThread.java
@@ -22,7 +22,6 @@ import java.net.ConnectException;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
-
import org.apache.http.client.HttpClient;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.client.solrj.SolrClient;
@@ -34,35 +33,42 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
class FullThrottleStoppableIndexingThread extends StoppableIndexingThread {
-
+
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- /**
- *
- */
+ /** */
private final HttpClient httpClient;
+
private volatile boolean stop = false;
int clientIndex = 0;
private ConcurrentUpdateSolrClient cusc;
private List<SolrClient> clients;
private AtomicInteger fails = new AtomicInteger();
-
- public FullThrottleStoppableIndexingThread(HttpClient httpClient, SolrClient controlClient, CloudSolrClient cloudClient, List<SolrClient> clients,
- String id, boolean doDeletes, int clientSoTimeout) {
+
+ public FullThrottleStoppableIndexingThread(
+ HttpClient httpClient,
+ SolrClient controlClient,
+ CloudSolrClient cloudClient,
+ List<SolrClient> clients,
+ String id,
+ boolean doDeletes,
+ int clientSoTimeout) {
super(controlClient, cloudClient, id, doDeletes);
setName("FullThrottleStopableIndexingThread");
setDaemon(true);
this.clients = clients;
this.httpClient = httpClient;
- cusc = new ErrorLoggingConcurrentUpdateSolrClient.Builder(((HttpSolrClient) clients.get(0)).getBaseURL())
- .withHttpClient(httpClient)
- .withQueueSize(8)
- .withThreadCount(2)
- .withConnectionTimeout(10000)
- .withSocketTimeout(clientSoTimeout)
- .build();
+ cusc =
+ new ErrorLoggingConcurrentUpdateSolrClient.Builder(
+ ((HttpSolrClient) clients.get(0)).getBaseURL())
+ .withHttpClient(httpClient)
+ .withQueueSize(8)
+ .withThreadCount(2)
+ .withConnectionTimeout(10000)
+ .withSocketTimeout(clientSoTimeout)
+ .build();
}
-
+
@Override
public void run() {
int i = 0;
@@ -72,7 +78,7 @@ class FullThrottleStoppableIndexingThread extends StoppableIndexingThread {
while (true && !stop) {
String id = this.id + "-" + i;
++i;
-
+
if (doDeletes && LuceneTestCase.random().nextBoolean() && deletes.size() > 0) {
String delete = deletes.remove(0);
try {
@@ -83,28 +89,27 @@ class FullThrottleStoppableIndexingThread extends StoppableIndexingThread {
fails.incrementAndGet();
}
}
-
+
try {
numAdds++;
- if (numAdds > (LuceneTestCase.TEST_NIGHTLY ? 4002 : 197))
- continue;
- SolrInputDocument doc = AbstractFullDistribZkTestBase.getDoc(
- "id",
- id,
- i1,
- 50,
- t1,
- "Saxon heptarchies that used to rip around so in old times and raise Cain. My, you ought to seen old Henry the Eight when he was in bloom. He WAS a blossom. He used to marry a new wife every day, and chop off her head next morning. And he would do it just as indifferent as if ");
+ if (numAdds > (LuceneTestCase.TEST_NIGHTLY ? 4002 : 197)) continue;
+ SolrInputDocument doc =
+ AbstractFullDistribZkTestBase.getDoc(
+ "id",
+ id,
+ i1,
+ 50,
+ t1,
+ "Saxon heptarchies that used to rip around so in old times and raise Cain. My, you ought to seen old Henry the Eight when he was in bloom. He WAS a blossom. He used to marry a new wife every day, and chop off her head next morning. And he would do it just as indifferent as if ");
cusc.add(doc);
} catch (Exception e) {
changeUrlOnError(e);
fails.incrementAndGet();
}
-
+
if (doDeletes && LuceneTestCase.random().nextBoolean()) {
deletes.add(id);
}
-
}
log.info("FT added docs:{} with {} fails deletes:{}", numAdds, fails, numDeletes);
@@ -117,14 +122,16 @@ class FullThrottleStoppableIndexingThread extends StoppableIndexingThread {
clientIndex = 0;
}
cusc.shutdownNow();
- cusc = new ErrorLoggingConcurrentUpdateSolrClient.Builder(((HttpSolrClient) clients.get(clientIndex)).getBaseURL())
- .withHttpClient(httpClient)
- .withQueueSize(30)
- .withThreadCount(3)
- .build();
+ cusc =
+ new ErrorLoggingConcurrentUpdateSolrClient.Builder(
+ ((HttpSolrClient) clients.get(clientIndex)).getBaseURL())
+ .withHttpClient(httpClient)
+ .withQueueSize(30)
+ .withThreadCount(3)
+ .build();
}
}
-
+
@Override
public void safeStop() {
stop = true;
@@ -135,44 +142,42 @@ class FullThrottleStoppableIndexingThread extends StoppableIndexingThread {
} finally {
cusc.shutdownNow();
}
-
}
@Override
public int getFailCount() {
return fails.get();
}
-
+
@Override
public Set<String> getAddFails() {
throw new UnsupportedOperationException();
}
-
+
@Override
public Set<String> getDeleteFails() {
throw new UnsupportedOperationException();
}
-
+
static class ErrorLoggingConcurrentUpdateSolrClient extends ConcurrentUpdateSolrClient {
public ErrorLoggingConcurrentUpdateSolrClient(Builder builder) {
super(builder);
}
-
+
@Override
public void handleError(Throwable ex) {
log.warn("cusc error", ex);
}
-
+
static class Builder extends ConcurrentUpdateSolrClient.Builder {
public Builder(String baseSolrUrl) {
super(baseSolrUrl);
}
-
+
public ErrorLoggingConcurrentUpdateSolrClient build() {
return new ErrorLoggingConcurrentUpdateSolrClient(this);
}
}
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/IpTables.java b/solr/test-framework/src/java/org/apache/solr/cloud/IpTables.java
index 7e73f6acc56..33678bd09aa 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/IpTables.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/IpTables.java
@@ -21,42 +21,36 @@ import java.lang.invoke.MethodHandles;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- * To use, tests must be able to run iptables, eg sudo chmod u+s iptables
- */
+/** To use, tests must be able to run iptables, eg sudo chmod u+s iptables */
public class IpTables {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
+
private static final boolean ENABLED = Boolean.getBoolean("solr.tests.use.iptables");
-
- private static final Set<Integer> BLOCK_PORTS = Collections.synchronizedSet(new HashSet<Integer>());
-
+
+ private static final Set<Integer> BLOCK_PORTS =
+ Collections.synchronizedSet(new HashSet<Integer>());
+
public static void blockPort(int port) throws IOException, InterruptedException {
if (ENABLED) {
log.info("Block port with iptables: {}", port);
BLOCK_PORTS.add(port);
- runCmd(("iptables -A INPUT -p tcp --dport " + port + " -j DROP")
- .split("\\s"));
- runCmd(("iptables -A OUTPUT -p tcp --dport " + port + " -j DROP")
- .split("\\s"));
+ runCmd(("iptables -A INPUT -p tcp --dport " + port + " -j DROP").split("\\s"));
+ runCmd(("iptables -A OUTPUT -p tcp --dport " + port + " -j DROP").split("\\s"));
}
}
-
+
public static void unblockPort(int port) throws IOException, InterruptedException {
if (ENABLED && BLOCK_PORTS.contains(port)) {
log.info("Unblock port with iptables: {}", port);
- runCmd(("iptables -D INPUT -p tcp --dport " + port + " -j DROP")
- .split("\\s"));
- runCmd(("iptables -D OUTPUT -p tcp --dport " + port + " -j DROP")
- .split("\\s"));
+ runCmd(("iptables -D INPUT -p tcp --dport " + port + " -j DROP").split("\\s"));
+ runCmd(("iptables -D OUTPUT -p tcp --dport " + port + " -j DROP").split("\\s"));
BLOCK_PORTS.remove(port);
}
}
-
+
public static void unblockAllPorts() throws IOException, InterruptedException {
if (ENABLED) {
log.info("Unblocking any ports previously blocked with iptables...");
@@ -66,11 +60,12 @@ public class IpTables {
}
}
}
-
+
private static void runCmd(String... cmd) throws IOException, InterruptedException {
final int exitCode = new ProcessBuilder(cmd).inheritIO().start().waitFor();
if (exitCode != 0) {
- throw new IOException("iptables process did not exit successfully, exit code was: " + exitCode);
+ throw new IOException(
+ "iptables process did not exit successfully, exit code was: " + exitCode);
}
}
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java b/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java
index 8eb9dd4cd70..8ea16920564 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java
@@ -16,6 +16,9 @@
*/
package org.apache.solr.cloud;
+import static org.apache.solr.core.ConfigSetProperties.DEFAULT_FILENAME;
+
+import com.codahale.metrics.MetricRegistry;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
@@ -36,9 +39,7 @@ import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
-
import javax.servlet.Filter;
-
import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.embedded.JettyConfig;
@@ -63,60 +64,58 @@ import org.eclipse.jetty.servlet.ServletHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.codahale.metrics.MetricRegistry;
-
-import static org.apache.solr.core.ConfigSetProperties.DEFAULT_FILENAME;
-
-/**
- * "Mini" SolrCloud cluster to be used for testing
- */
+/** "Mini" SolrCloud cluster to be used for testing */
public class MiniSolrCloudCluster {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
+
public static final String TEST_URL_ALLOW_LIST = SolrTestCaseJ4.TEST_URL_ALLOW_LIST;
public static final int DEFAULT_TIMEOUT = 30;
- public static final String DEFAULT_CLOUD_SOLR_XML = "<solr>\n" +
- "\n" +
- " <str name=\"shareSchema\">${shareSchema:false}</str>\n" +
- " <str name=\"allowPaths\">${solr.allowPaths:}</str>\n" +
- " <str name=\"configSetBaseDir\">${configSetBaseDir:configsets}</str>\n" +
- " <str name=\"coreRootDirectory\">${coreRootDirectory:.}</str>\n" +
- " <str name=\"collectionsHandler\">${collectionsHandler:solr.CollectionsHandler}</str>\n" +
- " <str name=\"allowUrls\">${"+ TEST_URL_ALLOW_LIST +":}</str>\n" +
- "\n" +
- " <shardHandlerFactory name=\"shardHandlerFactory\" class=\"HttpShardHandlerFactory\">\n" +
- " <str name=\"urlScheme\">${urlScheme:}</str>\n" +
- " <int name=\"socketTimeout\">${socketTimeout:90000}</int>\n" +
- " <int name=\"connTimeout\">${connTimeout:15000}</int>\n" +
- " </shardHandlerFactory>\n" +
- "\n" +
- " <solrcloud>\n" +
- " <str name=\"host\">127.0.0.1</str>\n" +
- " <int name=\"hostPort\">${hostPort:8983}</int>\n" +
- " <str name=\"hostContext\">${hostContext:solr}</str>\n" +
- " <int name=\"zkClientTimeout\">${solr.zkclienttimeout:30000}</int>\n" +
- " <bool name=\"genericCoreNodeNames\">${genericCoreNodeNames:true}</bool>\n" +
- " <int name=\"leaderVoteWait\">${leaderVoteWait:10000}</int>\n" +
- " <int name=\"distribUpdateConnTimeout\">${distribUpdateConnTimeout:45000}</int>\n" +
- " <int name=\"distribUpdateSoTimeout\">${distribUpdateSoTimeout:340000}</int>\n" +
- " <str name=\"zkCredentialsProvider\">${zkCredentialsProvider:org.apache.solr.common.cloud.DefaultZkCredentialsProvider}</str> \n" +
- " <str name=\"zkACLProvider\">${zkACLProvider:org.apache.solr.common.cloud.DefaultZkACLProvider}</str> \n" +
- " <str name=\"pkiHandlerPrivateKeyPath\">${pkiHandlerPrivateKeyPath:cryptokeys/priv_key512_pkcs8.pem}</str> \n" +
- " <str name=\"pkiHandlerPublicKeyPath\">${pkiHandlerPublicKeyPath:cryptokeys/pub_key512.der}</str> \n" +
- " <str name=\"distributedClusterStateUpdates\">${solr.distributedClusterStateUpdates:false}</str> \n" +
- " <str name=\"distributedCollectionConfigSetExecution\">${solr.distributedCollectionConfigSetExecution:false}</str> \n" +
- " </solrcloud>\n" +
- // NOTE: this turns off the metrics collection unless overridden by a sysprop
- " <metrics enabled=\"${metricsEnabled:false}\">\n" +
- " <reporter name=\"default\" class=\"org.apache.solr.metrics.reporters.SolrJmxReporter\">\n" +
- " <str name=\"rootName\">solr_${hostPort:8983}</str>\n" +
- " </reporter>\n" +
- " </metrics>\n" +
- " \n" +
- "</solr>\n";
+ public static final String DEFAULT_CLOUD_SOLR_XML =
+ "<solr>\n"
+ + "\n"
+ + " <str name=\"shareSchema\">${shareSchema:false}</str>\n"
+ + " <str name=\"allowPaths\">${solr.allowPaths:}</str>\n"
+ + " <str name=\"configSetBaseDir\">${configSetBaseDir:configsets}</str>\n"
+ + " <str name=\"coreRootDirectory\">${coreRootDirectory:.}</str>\n"
+ + " <str name=\"collectionsHandler\">${collectionsHandler:solr.CollectionsHandler}</str>\n"
+ + " <str name=\"allowUrls\">${"
+ + TEST_URL_ALLOW_LIST
+ + ":}</str>\n"
+ + "\n"
+ + " <shardHandlerFactory name=\"shardHandlerFactory\" class=\"HttpShardHandlerFactory\">\n"
+ + " <str name=\"urlScheme\">${urlScheme:}</str>\n"
+ + " <int name=\"socketTimeout\">${socketTimeout:90000}</int>\n"
+ + " <int name=\"connTimeout\">${connTimeout:15000}</int>\n"
+ + " </shardHandlerFactory>\n"
+ + "\n"
+ + " <solrcloud>\n"
+ + " <str name=\"host\">127.0.0.1</str>\n"
+ + " <int name=\"hostPort\">${hostPort:8983}</int>\n"
+ + " <str name=\"hostContext\">${hostContext:solr}</str>\n"
+ + " <int name=\"zkClientTimeout\">${solr.zkclienttimeout:30000}</int>\n"
+ + " <bool name=\"genericCoreNodeNames\">${genericCoreNodeNames:true}</bool>\n"
+ + " <int name=\"leaderVoteWait\">${leaderVoteWait:10000}</int>\n"
+ + " <int name=\"distribUpdateConnTimeout\">${distribUpdateConnTimeout:45000}</int>\n"
+ + " <int name=\"distribUpdateSoTimeout\">${distribUpdateSoTimeout:340000}</int>\n"
+ + " <str name=\"zkCredentialsProvider\">${zkCredentialsProvider:org.apache.solr.common.cloud.DefaultZkCredentialsProvider}</str> \n"
+ + " <str name=\"zkACLProvider\">${zkACLProvider:org.apache.solr.common.cloud.DefaultZkACLProvider}</str> \n"
+ + " <str name=\"pkiHandlerPrivateKeyPath\">${pkiHandlerPrivateKeyPath:cryptokeys/priv_key512_pkcs8.pem}</str> \n"
+ + " <str name=\"pkiHandlerPublicKeyPath\">${pkiHandlerPublicKeyPath:cryptokeys/pub_key512.der}</str> \n"
+ + " <str name=\"distributedClusterStateUpdates\">${solr.distributedClusterStateUpdates:false}</str> \n"
+ + " <str name=\"distributedCollectionConfigSetExecution\">${solr.distributedCollectionConfigSetExecution:false}</str> \n"
+ + " </solrcloud>\n"
+ +
+ // NOTE: this turns off the metrics collection unless overridden by a sysprop
+ " <metrics enabled=\"${metricsEnabled:false}\">\n"
+ + " <reporter name=\"default\" class=\"org.apache.solr.metrics.reporters.SolrJmxReporter\">\n"
+ + " <str name=\"rootName\">solr_${hostPort:8983}</str>\n"
+ + " </reporter>\n"
+ + " </metrics>\n"
+ + " \n"
+ + "</solr>\n";
private final Object startupWait = new Object();
private volatile ZkTestServer zkServer; // non-final due to injectChaos()
@@ -129,17 +128,16 @@ public class MiniSolrCloudCluster {
private final AtomicInteger nodeIds = new AtomicInteger();
-
/**
* Create a MiniSolrCloudCluster with default solr.xml
*
* @param numServers number of Solr servers to start
* @param baseDir base directory that the mini cluster should be run from
* @param jettyConfig Jetty configuration
- *
* @throws Exception if there was an error starting the cluster
*/
- public MiniSolrCloudCluster(int numServers, Path baseDir, JettyConfig jettyConfig) throws Exception {
+ public MiniSolrCloudCluster(int numServers, Path baseDir, JettyConfig jettyConfig)
+ throws Exception {
this(numServers, baseDir, DEFAULT_CLOUD_SOLR_XML, jettyConfig, null, false);
}
@@ -152,12 +150,16 @@ public class MiniSolrCloudCluster {
* @param solrXml solr.xml file to be uploaded to ZooKeeper
* @param extraServlets Extra servlets to be started by Jetty
* @param extraRequestFilters extra filters to be started by Jetty
- *
* @throws Exception if there was an error starting the cluster
*/
- public MiniSolrCloudCluster(int numServers, String hostContext, Path baseDir, String solrXml,
+ public MiniSolrCloudCluster(
+ int numServers,
+ String hostContext,
+ Path baseDir,
+ String solrXml,
SortedMap<ServletHolder, String> extraServlets,
- SortedMap<Class<? extends Filter>, String> extraRequestFilters) throws Exception {
+ SortedMap<Class<? extends Filter>, String> extraRequestFilters)
+ throws Exception {
this(numServers, hostContext, baseDir, solrXml, extraServlets, extraRequestFilters, null);
}
@@ -171,19 +173,27 @@ public class MiniSolrCloudCluster {
* @param extraServlets Extra servlets to be started by Jetty
* @param extraRequestFilters extra filters to be started by Jetty
* @param sslConfig SSL configuration
- *
* @throws Exception if there was an error starting the cluster
*/
- public MiniSolrCloudCluster(int numServers, String hostContext, Path baseDir, String solrXml,
+ public MiniSolrCloudCluster(
+ int numServers,
+ String hostContext,
+ Path baseDir,
+ String solrXml,
SortedMap<ServletHolder, String> extraServlets,
SortedMap<Class<? extends Filter>, String> extraRequestFilters,
- SSLConfig sslConfig) throws Exception {
- this(numServers, baseDir, solrXml, JettyConfig.builder()
- .setContext(hostContext)
- .withSSLConfig(sslConfig)
- .withFilters(extraRequestFilters)
- .withServlets(extraServlets)
- .build());
+ SSLConfig sslConfig)
+ throws Exception {
+ this(
+ numServers,
+ baseDir,
+ solrXml,
+ JettyConfig.builder()
+ .setContext(hostContext)
+ .withSSLConfig(sslConfig)
+ .withFilters(extraRequestFilters)
+ .withServlets(extraServlets)
+ .build());
}
/**
@@ -193,10 +203,10 @@ public class MiniSolrCloudCluster {
* @param baseDir base directory that the mini cluster should be run from
* @param solrXml solr.xml file to be uploaded to ZooKeeper
* @param jettyConfig Jetty configuration
- *
* @throws Exception if there was an error starting the cluster
*/
- public MiniSolrCloudCluster(int numServers, Path baseDir, String solrXml, JettyConfig jettyConfig) throws Exception {
+ public MiniSolrCloudCluster(int numServers, Path baseDir, String solrXml, JettyConfig jettyConfig)
+ throws Exception {
this(numServers, baseDir, solrXml, jettyConfig, null, false);
}
@@ -207,53 +217,76 @@ public class MiniSolrCloudCluster {
* @param baseDir base directory that the mini cluster should be run from
* @param solrXml solr.xml file to be uploaded to ZooKeeper
* @param jettyConfig Jetty configuration
- * @param zkTestServer ZkTestServer to use. If null, one will be created
- *
+ * @param zkTestServer ZkTestServer to use. If null, one will be created
* @throws Exception if there was an error starting the cluster
*/
- public MiniSolrCloudCluster(int numServers, Path baseDir, String solrXml, JettyConfig jettyConfig,
- ZkTestServer zkTestServer, boolean formatZkServer) throws Exception {
+ public MiniSolrCloudCluster(
+ int numServers,
+ Path baseDir,
+ String solrXml,
+ JettyConfig jettyConfig,
+ ZkTestServer zkTestServer,
+ boolean formatZkServer)
+ throws Exception {
this(numServers, baseDir, solrXml, jettyConfig, zkTestServer, Optional.empty(), formatZkServer);
}
/**
- * Create a MiniSolrCloudCluster.
- * Note - this constructor visibility is changed to package protected so as to
- * discourage its usage. Ideally *new* functionality should use {@linkplain SolrCloudTestCase}
- * to configure any additional parameters.
+ * Create a MiniSolrCloudCluster. Note - this constructor visibility is changed to package
+ * protected so as to discourage its usage. Ideally *new* functionality should use {@linkplain
+ * SolrCloudTestCase} to configure any additional parameters.
*
* @param numServers number of Solr servers to start
* @param baseDir base directory that the mini cluster should be run from
* @param solrXml solr.xml file to be uploaded to ZooKeeper
* @param jettyConfig Jetty configuration
- * @param zkTestServer ZkTestServer to use. If null, one will be created
+ * @param zkTestServer ZkTestServer to use. If null, one will be created
* @param securityJson A string representation of security.json file (optional).
- *
* @throws Exception if there was an error starting the cluster
*/
- MiniSolrCloudCluster(int numServers, Path baseDir, String solrXml, JettyConfig jettyConfig,
- ZkTestServer zkTestServer, Optional<String> securityJson, boolean formatZkServer) throws Exception {
- this(numServers, baseDir, solrXml, jettyConfig,
- zkTestServer,securityJson, false, formatZkServer);
- }
+ MiniSolrCloudCluster(
+ int numServers,
+ Path baseDir,
+ String solrXml,
+ JettyConfig jettyConfig,
+ ZkTestServer zkTestServer,
+ Optional<String> securityJson,
+ boolean formatZkServer)
+ throws Exception {
+ this(
+ numServers,
+ baseDir,
+ solrXml,
+ jettyConfig,
+ zkTestServer,
+ securityJson,
+ false,
+ formatZkServer);
+ }
/**
- * Create a MiniSolrCloudCluster.
- * Note - this constructor visibility is changed to package protected so as to
- * discourage its usage. Ideally *new* functionality should use {@linkplain SolrCloudTestCase}
- * to configure any additional parameters.
+ * Create a MiniSolrCloudCluster. Note - this constructor visibility is changed to package
+ * protected so as to discourage its usage. Ideally *new* functionality should use {@linkplain
+ * SolrCloudTestCase} to configure any additional parameters.
*
* @param numServers number of Solr servers to start
* @param baseDir base directory that the mini cluster should be run from
* @param solrXml solr.xml file to be uploaded to ZooKeeper
* @param jettyConfig Jetty configuration
- * @param zkTestServer ZkTestServer to use. If null, one will be created
+ * @param zkTestServer ZkTestServer to use. If null, one will be created
* @param securityJson A string representation of security.json file (optional).
* @param trackJettyMetrics supply jetties with metrics registry
- *
* @throws Exception if there was an error starting the cluster
*/
- MiniSolrCloudCluster(int numServers, Path baseDir, String solrXml, JettyConfig jettyConfig,
- ZkTestServer zkTestServer, Optional<String> securityJson, boolean trackJettyMetrics, boolean formatZkServer) throws Exception {
+ MiniSolrCloudCluster(
+ int numServers,
+ Path baseDir,
+ String solrXml,
+ JettyConfig jettyConfig,
+ ZkTestServer zkTestServer,
+ Optional<String> securityJson,
+ boolean trackJettyMetrics,
+ boolean formatZkServer)
+ throws Exception {
Objects.requireNonNull(securityJson);
this.baseDir = Objects.requireNonNull(baseDir);
@@ -279,48 +312,53 @@ public class MiniSolrCloudCluster {
}
this.zkServer = zkTestServer;
- try (SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT)) {
+ try (SolrZkClient zkClient =
+ new SolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT)) {
if (!zkClient.exists("/solr/solr.xml", true)) {
zkClient.makePath("/solr/solr.xml", solrXml.getBytes(Charset.defaultCharset()), true);
if (jettyConfig.sslConfig != null && jettyConfig.sslConfig.isSSLMode()) {
- zkClient.makePath("/solr" + ZkStateReader.CLUSTER_PROPS, "{'urlScheme':'https'}".getBytes(StandardCharsets.UTF_8), true);
+ zkClient.makePath(
+ "/solr" + ZkStateReader.CLUSTER_PROPS,
+ "{'urlScheme':'https'}".getBytes(StandardCharsets.UTF_8),
+ true);
}
if (securityJson.isPresent()) { // configure Solr security
- zkClient.makePath("/solr/security.json", securityJson.get().getBytes(Charset.defaultCharset()), true);
+ zkClient.makePath(
+ "/solr/security.json", securityJson.get().getBytes(Charset.defaultCharset()), true);
}
}
}
-
+
List<Callable<JettySolrRunner>> startups = new ArrayList<>(numServers);
for (int i = 0; i < numServers; ++i) {
startups.add(() -> startJettySolrRunner(newNodeName(), jettyConfig.context, jettyConfig));
}
- final ExecutorService executorLauncher = ExecutorUtil.newMDCAwareCachedThreadPool(new SolrNamedThreadFactory("jetty-launcher"));
+ final ExecutorService executorLauncher =
+ ExecutorUtil.newMDCAwareCachedThreadPool(new SolrNamedThreadFactory("jetty-launcher"));
Collection<Future<JettySolrRunner>> futures = executorLauncher.invokeAll(startups);
ExecutorUtil.shutdownAndAwaitTermination(executorLauncher);
Exception startupError = checkForExceptions("Error starting up MiniSolrCloudCluster", futures);
if (startupError != null) {
try {
this.shutdown();
- }
- catch (Throwable t) {
+ } catch (Throwable t) {
startupError.addSuppressed(t);
}
throw startupError;
}
solrClient = buildSolrClient();
-
+
if (numServers > 0) {
waitForAllNodes(numServers, 60);
}
-
}
- private void waitForAllNodes(int numServers, int timeoutSeconds) throws IOException, InterruptedException, TimeoutException {
+ private void waitForAllNodes(int numServers, int timeoutSeconds)
+ throws IOException, InterruptedException, TimeoutException {
log.info("waitForAllNodes: numServers={}", numServers);
-
+
int numRunning;
if (timeoutSeconds == 0) {
@@ -331,8 +369,11 @@ public class MiniSolrCloudCluster {
synchronized (startupWait) {
while (numServers != (numRunning = numRunningJetty(getJettySolrRunners()))) {
if (timeout.hasTimedOut()) {
- throw new IllegalStateException("giving up waiting for all jetty instances to be running. numServers=" + numServers
- + " numRunning=" + numRunning);
+ throw new IllegalStateException(
+ "giving up waiting for all jetty instances to be running. numServers="
+ + numServers
+ + " numRunning="
+ + numRunning);
}
startupWait.wait(500);
}
@@ -343,14 +384,15 @@ public class MiniSolrCloudCluster {
}
private int numRunningJetty(List<JettySolrRunner> runners) {
- int numRunning = 0;
- for (JettySolrRunner jsr : runners) {
- if (jsr.isRunning()) numRunning++;
- }
- return numRunning;
+ int numRunning = 0;
+ for (JettySolrRunner jsr : runners) {
+ if (jsr.isRunning()) numRunning++;
+ }
+ return numRunning;
}
- public void waitForNode(JettySolrRunner jetty, int timeoutSeconds) throws InterruptedException, TimeoutException {
+ public void waitForNode(JettySolrRunner jetty, int timeoutSeconds)
+ throws InterruptedException, TimeoutException {
String nodeName = jetty.getNodeName();
if (nodeName == null) {
throw new IllegalArgumentException("Cannot wait for Jetty with null node name");
@@ -359,23 +401,23 @@ public class MiniSolrCloudCluster {
ZkStateReader reader = getSolrClient().getZkStateReader();
- reader.waitForLiveNodes(timeoutSeconds, TimeUnit.SECONDS, (o, n) -> n != null && n.contains(nodeName));
+ reader.waitForLiveNodes(
+ timeoutSeconds, TimeUnit.SECONDS, (o, n) -> n != null && n.contains(nodeName));
}
/**
- * This method wait till all Solr JVMs ( Jettys ) are running . It waits up to the timeout (in seconds) for the JVMs to
- * be up before throwing IllegalStateException. This is called automatically on cluster startup and so is only needed
- * when starting additional Jetty instances.
+ * This method wait till all Solr JVMs ( Jettys ) are running . It waits up to the timeout (in
+ * seconds) for the JVMs to be up before throwing IllegalStateException. This is called
+ * automatically on cluster startup and so is only needed when starting additional Jetty
+ * instances.
*
- * @param timeout
- * number of seconds to wait before throwing an IllegalStateException
- * @throws IOException
- * if there was an error communicating with ZooKeeper
- * @throws InterruptedException
- * if the calling thread is interrupted during the wait operation
+ * @param timeout number of seconds to wait before throwing an IllegalStateException
+ * @throws IOException if there was an error communicating with ZooKeeper
+ * @throws InterruptedException if the calling thread is interrupted during the wait operation
* @throws TimeoutException on timeout before all nodes being ready
*/
- public void waitForAllNodes(int timeout) throws IOException, InterruptedException, TimeoutException {
+ public void waitForAllNodes(int timeout)
+ throws IOException, InterruptedException, TimeoutException {
waitForAllNodes(jettys.size(), timeout);
}
@@ -417,13 +459,14 @@ public class MiniSolrCloudCluster {
* @param hostContext context path of Solr servers used by Jetty
* @param extraServlets Extra servlets to be started by Jetty
* @param extraRequestFilters extra filters to be started by Jetty
- *
* @return new Solr instance
- *
*/
- public JettySolrRunner startJettySolrRunner(String name, String hostContext,
+ public JettySolrRunner startJettySolrRunner(
+ String name,
+ String hostContext,
SortedMap<ServletHolder, String> extraServlets,
- SortedMap<Class<? extends Filter>, String> extraRequestFilters) throws Exception {
+ SortedMap<Class<? extends Filter>, String> extraRequestFilters)
+ throws Exception {
return startJettySolrRunner(name, hostContext, extraServlets, extraRequestFilters, null);
}
@@ -434,17 +477,23 @@ public class MiniSolrCloudCluster {
* @param extraServlets Extra servlets to be started by Jetty
* @param extraRequestFilters extra filters to be started by Jetty
* @param sslConfig SSL configuration
- *
* @return new Solr instance
*/
- public JettySolrRunner startJettySolrRunner(String name, String hostContext,
+ public JettySolrRunner startJettySolrRunner(
+ String name,
+ String hostContext,
SortedMap<ServletHolder, String> extraServlets,
- SortedMap<Class<? extends Filter>, String> extraRequestFilters, SSLConfig sslConfig) throws Exception {
- return startJettySolrRunner(name, hostContext, JettyConfig.builder()
- .withServlets(extraServlets)
- .withFilters(extraRequestFilters)
- .withSSLConfig(sslConfig)
- .build());
+ SortedMap<Class<? extends Filter>, String> extraRequestFilters,
+ SSLConfig sslConfig)
+ throws Exception {
+ return startJettySolrRunner(
+ name,
+ hostContext,
+ JettyConfig.builder()
+ .withServlets(extraServlets)
+ .withFilters(extraRequestFilters)
+ .withSSLConfig(sslConfig)
+ .build());
}
public JettySolrRunner getJettySolrRunner(int index) {
@@ -456,11 +505,12 @@ public class MiniSolrCloudCluster {
*
* @param name the instance name
* @param hostContext the context to run on
- * @param config a JettyConfig for the instance's {@link org.apache.solr.client.solrj.embedded.JettySolrRunner}
- *
+ * @param config a JettyConfig for the instance's {@link
+ * org.apache.solr.client.solrj.embedded.JettySolrRunner}
* @return a JettySolrRunner
*/
- public JettySolrRunner startJettySolrRunner(String name, String hostContext, JettyConfig config) throws Exception {
+ public JettySolrRunner startJettySolrRunner(String name, String hostContext, JettyConfig config)
+ throws Exception {
// tell solr node to look in zookeeper for solr.xml
final Properties nodeProps = new Properties();
nodeProps.setProperty("zkHost", zkServer.getZkAddress());
@@ -468,9 +518,10 @@ public class MiniSolrCloudCluster {
Path runnerPath = createInstancePath(name);
String context = getHostContextSuitableForServletContext(hostContext);
JettyConfig newConfig = JettyConfig.builder(config).setContext(context).build();
- JettySolrRunner jetty = !trackJettyMetrics
- ? new JettySolrRunner(runnerPath.toString(), nodeProps, newConfig)
- : new JettySolrRunnerWithMetrics(runnerPath.toString(), nodeProps, newConfig);
+ JettySolrRunner jetty =
+ !trackJettyMetrics
+ ? new JettySolrRunner(runnerPath.toString(), nodeProps, newConfig)
+ : new JettySolrRunnerWithMetrics(runnerPath.toString(), nodeProps, newConfig);
jetty.start();
jettys.add(jetty);
synchronized (startupWait) {
@@ -478,7 +529,7 @@ public class MiniSolrCloudCluster {
}
return jetty;
}
-
+
/**
* Start a new Solr instance, using the default config
*
@@ -490,6 +541,7 @@ public class MiniSolrCloudCluster {
/**
* Stop a Solr instance
+ *
* @param index the index of node in collection returned by {@link #getJettySolrRunners()}
* @return the shut down node
*/
@@ -502,6 +554,7 @@ public class MiniSolrCloudCluster {
/**
* Add a previously stopped node back to the cluster
+ *
* @param jetty a {@link JettySolrRunner} previously returned by {@link #stopJettySolrRunner(int)}
* @return the started node
* @throws Exception on error
@@ -514,6 +567,7 @@ public class MiniSolrCloudCluster {
/**
* Stop the given Solr instance. It will be removed from the cluster's list of running instances.
+ *
* @param jetty a {@link JettySolrRunner} to be stopped
* @return the same {@link JettySolrRunner} instance provided to this method
* @throws Exception on error
@@ -526,13 +580,22 @@ public class MiniSolrCloudCluster {
/**
* Upload a config set
+ *
* @param configDir a path to the config set to upload
* @param configName the name to give the configset
*/
public void uploadConfigSet(Path configDir, String configName) throws IOException {
- try(SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(),
- AbstractZkTestCase.TIMEOUT, AbstractZkTestCase.TIMEOUT, null)) {
- ZkMaintenanceUtils.uploadToZK(zkClient, configDir, ZkMaintenanceUtils.CONFIGS_ZKNODE + "/" + configName, ZkMaintenanceUtils.UPLOAD_FILENAME_EXCLUDE_PATTERN);
+ try (SolrZkClient zkClient =
+ new SolrZkClient(
+ zkServer.getZkAddress(),
+ AbstractZkTestCase.TIMEOUT,
+ AbstractZkTestCase.TIMEOUT,
+ null)) {
+ ZkMaintenanceUtils.uploadToZK(
+ zkClient,
+ configDir,
+ ZkMaintenanceUtils.CONFIGS_ZKNODE + "/" + configName,
+ ZkMaintenanceUtils.UPLOAD_FILENAME_EXCLUDE_PATTERN);
}
}
@@ -540,43 +603,49 @@ public class MiniSolrCloudCluster {
public void deleteAllCollections() throws Exception {
try (ZkStateReader reader = new ZkStateReader(solrClient.getZkStateReader().getZkClient())) {
final CountDownLatch latch = new CountDownLatch(1);
- reader.registerCloudCollectionsListener(new CloudCollectionsListener() {
-
- @Override
- public void onChange(Set<String> oldCollections, Set<String> newCollections) {
- if (newCollections != null && newCollections.size() == 0) {
- latch.countDown();
- }
- }
- });
-
+ reader.registerCloudCollectionsListener(
+ new CloudCollectionsListener() {
+
+ @Override
+ public void onChange(Set<String> oldCollections, Set<String> newCollections) {
+ if (newCollections != null && newCollections.size() == 0) {
+ latch.countDown();
+ }
+ }
+ });
+
reader.createClusterStateWatchersAndUpdate(); // up to date aliases & collections
reader.aliasesManager.applyModificationAndExportToZk(aliases -> Aliases.EMPTY);
for (String collection : reader.getClusterState().getCollectionStates().keySet()) {
CollectionAdminRequest.deleteCollection(collection).process(solrClient);
}
-
+
boolean success = latch.await(60, TimeUnit.SECONDS);
if (!success) {
- throw new IllegalStateException("Still waiting to see all collections removed from clusterstate.");
+ throw new IllegalStateException(
+ "Still waiting to see all collections removed from clusterstate.");
}
-
+
for (String collection : reader.getClusterState().getCollectionStates().keySet()) {
- reader.waitForState(collection, 15, TimeUnit.SECONDS, (collectionState) -> collectionState == null ? true : false);
+ reader.waitForState(
+ collection,
+ 15,
+ TimeUnit.SECONDS,
+ (collectionState) -> collectionState == null ? true : false);
}
-
- }
-
- // may be deleted, but may not be gone yet - we only wait to not see it in ZK, not for core unloads
+ }
+
+ // may be deleted, but may not be gone yet - we only wait to not see it in ZK, not for core
+ // unloads
TimeOut timeout = new TimeOut(30, TimeUnit.SECONDS, TimeSource.NANO_TIME);
while (true) {
-
- if( timeout.hasTimedOut() ) {
+
+ if (timeout.hasTimedOut()) {
throw new TimeoutException("Timed out waiting for all collections to be fully removed.");
}
-
+
boolean allContainersEmpty = true;
- for(JettySolrRunner jetty : jettys) {
+ for (JettySolrRunner jetty : jettys) {
CoreContainer cc = jetty.getCoreContainer();
if (cc != null && cc.getCores().size() != 0) {
allContainersEmpty = false;
@@ -586,12 +655,12 @@ public class MiniSolrCloudCluster {
break;
}
}
-
}
-
+
public void deleteAllConfigSets() throws Exception {
- List<String> configSetNames = new ConfigSetAdminRequest.List().process(solrClient).getConfigSets();
+ List<String> configSetNames =
+ new ConfigSetAdminRequest.List().process(solrClient).getConfigSets();
for (String configSet : configSetNames) {
if (configSet.equals("_default")) {
@@ -599,30 +668,33 @@ public class MiniSolrCloudCluster {
}
try {
// cleanup any property before removing the configset
- getZkClient().delete(ZkConfigSetService.CONFIGS_ZKNODE + "/" + configSet + "/" + DEFAULT_FILENAME, -1, true);
- } catch (KeeperException.NoNodeException nne) { }
- new ConfigSetAdminRequest.Delete()
- .setConfigSetName(configSet)
- .process(solrClient);
+ getZkClient()
+ .delete(
+ ZkConfigSetService.CONFIGS_ZKNODE + "/" + configSet + "/" + DEFAULT_FILENAME,
+ -1,
+ true);
+ } catch (KeeperException.NoNodeException nne) {
+ }
+ new ConfigSetAdminRequest.Delete().setConfigSetName(configSet).process(solrClient);
}
}
- /**
- * Shut down the cluster, including all Solr nodes and ZooKeeper
- */
+ /** Shut down the cluster, including all Solr nodes and ZooKeeper */
public void shutdown() throws Exception {
try {
-
+
IOUtils.closeQuietly(solrClient);
List<Callable<JettySolrRunner>> shutdowns = new ArrayList<>(jettys.size());
for (final JettySolrRunner jetty : jettys) {
shutdowns.add(() -> stopJettySolrRunner(jetty));
}
jettys.clear();
- final ExecutorService executorCloser = ExecutorUtil.newMDCAwareCachedThreadPool(new SolrNamedThreadFactory("jetty-closer"));
+ final ExecutorService executorCloser =
+ ExecutorUtil.newMDCAwareCachedThreadPool(new SolrNamedThreadFactory("jetty-closer"));
Collection<Future<JettySolrRunner>> futures = executorCloser.invokeAll(shutdowns);
ExecutorUtil.shutdownAndAwaitTermination(executorCloser);
- Exception shutdownError = checkForExceptions("Error shutting down MiniSolrCloudCluster", futures);
+ Exception shutdownError =
+ checkForExceptions("Error shutting down MiniSolrCloudCluster", futures);
if (shutdownError != null) {
throw shutdownError;
}
@@ -646,9 +718,11 @@ public class MiniSolrCloudCluster {
}
/**
- * Set data in zk without exposing caller to the ZK API, i.e. tests won't need to include Zookeeper dependencies
+ * Set data in zk without exposing caller to the ZK API, i.e. tests won't need to include
+ * Zookeeper dependencies
*/
- public void zkSetData(String path, byte[] data, boolean retryOnConnLoss) throws InterruptedException {
+ public void zkSetData(String path, byte[] data, boolean retryOnConnLoss)
+ throws InterruptedException {
try {
getZkClient().setData(path, data, -1, retryOnConnLoss);
} catch (KeeperException e) {
@@ -657,29 +731,31 @@ public class MiniSolrCloudCluster {
}
protected CloudSolrClient buildSolrClient() {
- return new CloudSolrClient.Builder(Collections.singletonList(getZkServer().getZkAddress()), Optional.empty())
- .withSocketTimeout(90000).withConnectionTimeout(15000).build(); // we choose 90 because we run in some harsh envs
+ return new CloudSolrClient.Builder(
+ Collections.singletonList(getZkServer().getZkAddress()), Optional.empty())
+ .withSocketTimeout(90000)
+ .withConnectionTimeout(15000)
+ .build(); // we choose 90 because we run in some harsh envs
}
private static String getHostContextSuitableForServletContext(String ctx) {
if (ctx == null || "".equals(ctx)) ctx = "/solr";
- if (ctx.endsWith("/")) ctx = ctx.substring(0,ctx.length()-1);
+ if (ctx.endsWith("/")) ctx = ctx.substring(0, ctx.length() - 1);
if (!ctx.startsWith("/")) ctx = "/" + ctx;
return ctx;
}
- private Exception checkForExceptions(String message, Collection<Future<JettySolrRunner>> futures) throws InterruptedException {
+ private Exception checkForExceptions(String message, Collection<Future<JettySolrRunner>> futures)
+ throws InterruptedException {
Exception parsed = new Exception(message);
boolean ok = true;
for (Future<JettySolrRunner> future : futures) {
try {
future.get();
- }
- catch (ExecutionException e) {
+ } catch (ExecutionException e) {
parsed.addSuppressed(e.getCause());
ok = false;
- }
- catch (InterruptedException e) {
+ } catch (InterruptedException e) {
Thread.interrupted();
throw e;
}
@@ -687,21 +763,17 @@ public class MiniSolrCloudCluster {
return ok ? null : parsed;
}
- /**
- * Return the jetty that a particular replica resides on
- */
+ /** Return the jetty that a particular replica resides on */
public JettySolrRunner getReplicaJetty(Replica replica) {
for (JettySolrRunner jetty : jettys) {
if (jetty.isStopped()) continue;
- if (replica.getCoreUrl().startsWith(jetty.getBaseUrl().toString()))
- return jetty;
+ if (replica.getCoreUrl().startsWith(jetty.getBaseUrl().toString())) return jetty;
}
- throw new IllegalArgumentException("Cannot find Jetty for a replica with core url " + replica.getCoreUrl());
+ throw new IllegalArgumentException(
+ "Cannot find Jetty for a replica with core url " + replica.getCoreUrl());
}
- /**
- * Make the zookeeper session on a particular jetty expire
- */
+ /** Make the zookeeper session on a particular jetty expire */
public void expireZkSession(JettySolrRunner jetty) {
CoreContainer cores = jetty.getCoreContainer();
if (cores != null) {
@@ -762,29 +834,40 @@ public class MiniSolrCloudCluster {
}
throw new SolrException(ErrorCode.NOT_FOUND, "No open Overseer found");
}
-
- public void waitForActiveCollection(String collection, long wait, TimeUnit unit, int shards, int totalReplicas) {
+
+ public void waitForActiveCollection(
+ String collection, long wait, TimeUnit unit, int shards, int totalReplicas) {
log.info("waitForActiveCollection: {}", collection);
CollectionStatePredicate predicate = expectedShardsAndActiveReplicas(shards, totalReplicas);
AtomicReference<DocCollection> state = new AtomicReference<>();
AtomicReference<Set<String>> liveNodesLastSeen = new AtomicReference<>();
try {
- getSolrClient().waitForState(collection, wait, unit, (n, c) -> {
- state.set(c);
- liveNodesLastSeen.set(n);
-
- return predicate.matches(n, c);
- });
+ getSolrClient()
+ .waitForState(
+ collection,
+ wait,
+ unit,
+ (n, c) -> {
+ state.set(c);
+ liveNodesLastSeen.set(n);
+
+ return predicate.matches(n, c);
+ });
} catch (TimeoutException | InterruptedException e) {
- throw new RuntimeException("Failed while waiting for active collection" + "\n" + e.getMessage() + "\nLive Nodes: " + Arrays.toString(liveNodesLastSeen.get().toArray())
- + "\nLast available state: " + state.get());
+ throw new RuntimeException(
+ "Failed while waiting for active collection"
+ + "\n"
+ + e.getMessage()
+ + "\nLive Nodes: "
+ + Arrays.toString(liveNodesLastSeen.get().toArray())
+ + "\nLast available state: "
+ + state.get());
}
-
}
public void waitForActiveCollection(String collection, int shards, int totalReplicas) {
- waitForActiveCollection(collection, 30, TimeUnit.SECONDS, shards, totalReplicas);
+ waitForActiveCollection(collection, 30, TimeUnit.SECONDS, shards, totalReplicas);
}
public void waitForActiveCollection(String collection, long wait, TimeUnit unit) {
@@ -794,27 +877,37 @@ public class MiniSolrCloudCluster {
AtomicReference<DocCollection> state = new AtomicReference<>();
AtomicReference<Set<String>> liveNodesLastSeen = new AtomicReference<>();
try {
- getSolrClient().waitForState(collection, wait, unit, (n, c) -> {
- state.set(c);
- liveNodesLastSeen.set(n);
-
- return predicate.matches(n, c);
- });
+ getSolrClient()
+ .waitForState(
+ collection,
+ wait,
+ unit,
+ (n, c) -> {
+ state.set(c);
+ liveNodesLastSeen.set(n);
+
+ return predicate.matches(n, c);
+ });
} catch (TimeoutException | InterruptedException e) {
- throw new RuntimeException("Failed while waiting for active collection" + "\n" + e.getMessage() + "\nLive Nodes: " + Arrays.toString(liveNodesLastSeen.get().toArray())
- + "\nLast available state: " + state.get());
+ throw new RuntimeException(
+ "Failed while waiting for active collection"
+ + "\n"
+ + e.getMessage()
+ + "\nLive Nodes: "
+ + Arrays.toString(liveNodesLastSeen.get().toArray())
+ + "\nLast available state: "
+ + state.get());
}
-
}
-
- public static CollectionStatePredicate expectedShardsAndActiveReplicas(int expectedShards, int expectedReplicas) {
+
+ public static CollectionStatePredicate expectedShardsAndActiveReplicas(
+ int expectedShards, int expectedReplicas) {
return (liveNodes, collectionState) -> {
- if (collectionState == null)
- return false;
+ if (collectionState == null) return false;
if (collectionState.getSlices().size() != expectedShards) {
return false;
}
-
+
int activeReplicas = 0;
for (Slice slice : collectionState) {
for (Replica replica : slice) {
@@ -833,9 +926,7 @@ public class MiniSolrCloudCluster {
public static CollectionStatePredicate expectedActive() {
return (liveNodes, collectionState) -> {
- if (collectionState == null)
- return false;
-
+ if (collectionState == null) return false;
for (Slice slice : collectionState) {
for (Replica replica : slice) {
@@ -860,7 +951,7 @@ public class MiniSolrCloudCluster {
ZkStateReader reader = getSolrClient().getZkStateReader();
try {
- reader.waitForLiveNodes(15, TimeUnit.SECONDS, (o, n) -> ! n.contains(nodeName));
+ reader.waitForLiveNodes(15, TimeUnit.SECONDS, (o, n) -> !n.contains(nodeName));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new SolrException(ErrorCode.SERVER_ERROR, "interrupted", e);
@@ -878,8 +969,10 @@ public class MiniSolrCloudCluster {
jetty.dumpCoresInfo(pw);
}
}
-
- /** @lucene.experimental */
+
+ /**
+ * @lucene.experimental
+ */
public static final class JettySolrRunnerWithMetrics extends JettySolrRunner {
public JettySolrRunnerWithMetrics(String solrHome, Properties nodeProps, JettyConfig config) {
super(solrHome, nodeProps, config);
@@ -890,32 +983,31 @@ public class MiniSolrCloudCluster {
@Override
protected HandlerWrapper injectJettyHandlers(HandlerWrapper chain) {
metricRegistry = new MetricRegistry();
- com.codahale.metrics.jetty9.InstrumentedHandler metrics
- = new com.codahale.metrics.jetty9.InstrumentedHandler(
- metricRegistry);
+ com.codahale.metrics.jetty9.InstrumentedHandler metrics =
+ new com.codahale.metrics.jetty9.InstrumentedHandler(metricRegistry);
metrics.setHandler(chain);
return metrics;
}
- /** @return optional subj. It may be null, if it's not yet created. */
+ /**
+ * @return optional subj. It may be null, if it's not yet created.
+ */
public MetricRegistry getMetricRegistry() {
return metricRegistry;
}
}
-
private static class Config {
final String name;
final Path path;
+
private Config(String name, Path path) {
this.name = name;
this.path = path;
}
}
- /**
- * Builder class for a MiniSolrCloudCluster
- */
+ /** Builder class for a MiniSolrCloudCluster */
public static class Builder {
private final int nodeCount;
@@ -936,7 +1028,7 @@ public class MiniSolrCloudCluster {
* Create a builder
*
* @param nodeCount the number of nodes in the cluster
- * @param baseDir a base directory for the cluster
+ * @param baseDir a base directory for the cluster
*/
public Builder(int nodeCount, Path baseDir) {
this.nodeCount = nodeCount;
@@ -944,29 +1036,24 @@ public class MiniSolrCloudCluster {
jettyConfigBuilder = JettyConfig.builder().setContext("/solr");
if (SolrTestCaseJ4.sslConfig != null) {
- jettyConfigBuilder = jettyConfigBuilder.withSSLConfig(SolrTestCaseJ4.sslConfig.buildServerSSLConfig());
+ jettyConfigBuilder =
+ jettyConfigBuilder.withSSLConfig(SolrTestCaseJ4.sslConfig.buildServerSSLConfig());
}
}
- /**
- * Use a JettyConfig.Builder to configure the cluster's jetty servers
- */
+ /** Use a JettyConfig.Builder to configure the cluster's jetty servers */
public Builder withJettyConfig(Consumer<JettyConfig.Builder> fun) {
fun.accept(jettyConfigBuilder);
return this;
}
- /**
- * Use the provided string as solr.xml content
- */
+ /** Use the provided string as solr.xml content */
public Builder withSolrXml(String solrXml) {
this.solrxml = solrXml;
return this;
}
- /**
- * Read solr.xml from the provided path
- */
+ /** Read solr.xml from the provided path */
public Builder withSolrXml(Path solrXml) {
try {
this.solrxml = new String(Files.readAllBytes(solrXml), Charset.defaultCharset());
@@ -984,7 +1071,8 @@ public class MiniSolrCloudCluster {
*/
public Builder withSecurityJson(Path securityJson) {
try {
- this.securityJson = Optional.of(new String(Files.readAllBytes(securityJson), Charset.defaultCharset()));
+ this.securityJson =
+ Optional.of(new String(Files.readAllBytes(securityJson), Charset.defaultCharset()));
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -1014,32 +1102,34 @@ public class MiniSolrCloudCluster {
}
/**
- * <p>This method makes the MiniSolrCloudCluster use the "other" Collection API execution strategy than it normally
- * would. When some test classes call this method (and some don't) we make sure that a run of multiple tests with a
- * single seed will exercise both code lines (distributed and Overseer based Collection API) so regressions can be
- * spotted faster.</p>
+ * This method makes the MiniSolrCloudCluster use the "other" Collection API execution strategy
+ * than it normally would. When some test classes call this method (and some don't) we make sure
+ * that a run of multiple tests with a single seed will exercise both code lines (distributed
+ * and Overseer based Collection API) so regressions can be spotted faster.
*
- * <p> The real need is for a few tests covering reasonable use cases to call this method. If you're adding a new test,
- * you don't have to call it (but it's ok if you do).</p>
+ * <p>The real need is for a few tests covering reasonable use cases to call this method. If
+ * you're adding a new test, you don't have to call it (but it's ok if you do).
*/
public Builder useOtherCollectionConfigSetExecution() {
// Switch from Overseer to distributed Collection execution and vice versa
useDistributedCollectionConfigSetExecution = !useDistributedCollectionConfigSetExecution;
- // Reverse distributed cluster state updates as well if possible (state can't be Overseer based if Collections API is distributed)
- useDistributedClusterStateUpdate = !useDistributedClusterStateUpdate || useDistributedCollectionConfigSetExecution;
+ // Reverse distributed cluster state updates as well if possible (state can't be Overseer
+ // based if Collections API is distributed)
+ useDistributedClusterStateUpdate =
+ !useDistributedClusterStateUpdate || useDistributedCollectionConfigSetExecution;
return this;
}
/**
- * Force the cluster Collection and config state API execution as well as the cluster state update strategy to be
- * either Overseer based or distributed. <b>This method can be useful when debugging tests</b> failing in only one
- * of the two modes to have all local runs exhibit the issue, as well obviously for tests that are not compatible
- * with one of the two modes.
- * <p>
- * If this method is not called, the strategy being used will be random if the configuration passed to the cluster
- * ({@code solr.xml} equivalent) contains a placeholder similar to:
- * <pre>
- * {@code
+ * Force the cluster Collection and config state API execution as well as the cluster state
+ * update strategy to be either Overseer based or distributed. <b>This method can be useful when
+ * debugging tests</b> failing in only one of the two modes to have all local runs exhibit the
+ * issue, as well obviously for tests that are not compatible with one of the two modes.
+ *
+ * <p>If this method is not called, the strategy being used will be random if the configuration
+ * passed to the cluster ({@code solr.xml} equivalent) contains a placeholder similar to:
+ *
+ * <pre>{@code
* <solrcloud>
* ....
* <str name="distributedClusterStateUpdates">${solr.distributedClusterStateUpdates:false}</str>
@@ -1047,20 +1137,25 @@ public class MiniSolrCloudCluster {
* ....
* </solrcloud>
* }</pre>
- * For an example of a configuration supporting this setting, see {@link MiniSolrCloudCluster#DEFAULT_CLOUD_SOLR_XML}.
- * When a test sets a different {@code solr.xml} config (using {@link #withSolrXml}), if the config does not contain
- * the placeholder, the strategy will be defined by the values assigned to {@code useDistributedClusterStateUpdates}
- * and {@code useDistributedCollectionConfigSetExecution} in {@link org.apache.solr.core.CloudConfig.CloudConfigBuilder}.
*
- * @param distributedCollectionConfigSetApi When {@code true}, Collection and Config Set API commands are executed
- * in a distributed way by nodes. When {@code false}, they are executed by
- * Overseer.
- * @param distributedClusterStateUpdates When {@code true}, cluster state updates are handled in a distributed
- * way by nodes. When {@code false}, cluster state updates are handled by
- * Overseer.<p> If {@code distributedCollectionConfigSetApi} is {@code
- * true} then this parameter must be {@code true}.
+ * For an example of a configuration supporting this setting, see {@link
+ * MiniSolrCloudCluster#DEFAULT_CLOUD_SOLR_XML}. When a test sets a different {@code solr.xml}
+ * config (using {@link #withSolrXml}), if the config does not contain the placeholder, the
+ * strategy will be defined by the values assigned to {@code useDistributedClusterStateUpdates}
+ * and {@code useDistributedCollectionConfigSetExecution} in {@link
+ * org.apache.solr.core.CloudConfig.CloudConfigBuilder}.
+ *
+ * @param distributedCollectionConfigSetApi When {@code true}, Collection and Config Set API
+ * commands are executed in a distributed way by nodes. When {@code false}, they are
+ * executed by Overseer.
+ * @param distributedClusterStateUpdates When {@code true}, cluster state updates are handled in
+ * a distributed way by nodes. When {@code false}, cluster state updates are handled by
+ * Overseer.
+ * <p>If {@code distributedCollectionConfigSetApi} is {@code true} then this parameter must
+ * be {@code true}.
*/
- public Builder withDistributedClusterStateUpdates(boolean distributedCollectionConfigSetApi, boolean distributedClusterStateUpdates) {
+ public Builder withDistributedClusterStateUpdates(
+ boolean distributedCollectionConfigSetApi, boolean distributedClusterStateUpdates) {
useDistributedCollectionConfigSetExecution = distributedCollectionConfigSetApi;
useDistributedClusterStateUpdate = distributedClusterStateUpdates;
return this;
@@ -1069,7 +1164,7 @@ public class MiniSolrCloudCluster {
/**
* Set a cluster property
*
- * @param propertyName the property name
+ * @param propertyName the property name
* @param propertyValue the property value
*/
public Builder withProperty(String propertyName, String propertyValue) {
@@ -1102,25 +1197,43 @@ public class MiniSolrCloudCluster {
* @throws Exception if an error occurs on startup
*/
public MiniSolrCloudCluster build() throws Exception {
- // Two lines below will have an impact on how the MiniSolrCloudCluster and therefore the test run if the config being
- // used in the test does have the appropriate placeholders. See for example DEFAULT_CLOUD_SOLR_XML in MiniSolrCloudCluster.
+ // Two lines below will have an impact on how the MiniSolrCloudCluster and therefore the test
+ // run if the config being
+ // used in the test does have the appropriate placeholders. See for example
+ // DEFAULT_CLOUD_SOLR_XML in MiniSolrCloudCluster.
// Hard coding values here will impact such tests.
- // To hard code behavior for tests not having these placeholders - and for SolrCloud as well for that matter! -
- // change the values assigned to useDistributedClusterStateUpdates and useDistributedCollectionConfigSetExecution in
- // org.apache.solr.core.CloudConfig.CloudConfigBuilder. Do not forget then to revert before commit!
- System.setProperty("solr.distributedCollectionConfigSetExecution", Boolean.toString(useDistributedCollectionConfigSetExecution));
- System.setProperty("solr.distributedClusterStateUpdates", Boolean.toString(useDistributedClusterStateUpdate));
+ // To hard code behavior for tests not having these placeholders - and for SolrCloud as well
+ // for that matter! -
+ // change the values assigned to useDistributedClusterStateUpdates and
+ // useDistributedCollectionConfigSetExecution in
+ // org.apache.solr.core.CloudConfig.CloudConfigBuilder. Do not forget then to revert before
+ // commit!
+ System.setProperty(
+ "solr.distributedCollectionConfigSetExecution",
+ Boolean.toString(useDistributedCollectionConfigSetExecution));
+ System.setProperty(
+ "solr.distributedClusterStateUpdates",
+ Boolean.toString(useDistributedClusterStateUpdate));
JettyConfig jettyConfig = jettyConfigBuilder.build();
- MiniSolrCloudCluster cluster = new MiniSolrCloudCluster(nodeCount, baseDir, solrxml, jettyConfig,
- null, securityJson, trackJettyMetrics, formatZkServer);
+ MiniSolrCloudCluster cluster =
+ new MiniSolrCloudCluster(
+ nodeCount,
+ baseDir,
+ solrxml,
+ jettyConfig,
+ null,
+ securityJson,
+ trackJettyMetrics,
+ formatZkServer);
CloudSolrClient client = cluster.getSolrClient();
for (Config config : configs) {
cluster.uploadConfigSet(config.path, config.name);
}
if (clusterProperties.size() > 0) {
- ClusterProperties props = new ClusterProperties(cluster.getSolrClient().getZkStateReader().getZkClient());
+ ClusterProperties props =
+ new ClusterProperties(cluster.getSolrClient().getZkStateReader().getZkClient());
for (Map.Entry<String, Object> entry : clusterProperties.entrySet()) {
props.setClusterProperty(entry.getKey(), entry.getValue());
}
@@ -1130,13 +1243,15 @@ public class MiniSolrCloudCluster {
public Builder withDefaultClusterProperty(String key, String value) {
@SuppressWarnings({"unchecked"})
- HashMap<String, Object> defaults = (HashMap<String, Object>) this.clusterProperties.get(CollectionAdminParams.DEFAULTS);
+ HashMap<String, Object> defaults =
+ (HashMap<String, Object>) this.clusterProperties.get(CollectionAdminParams.DEFAULTS);
if (defaults == null) {
defaults = new HashMap<>();
this.clusterProperties.put(CollectionAdminParams.DEFAULTS, defaults);
}
@SuppressWarnings({"unchecked"})
- HashMap<String, Object> cluster = (HashMap<String, Object>) defaults.get(CollectionAdminParams.CLUSTER);
+ HashMap<String, Object> cluster =
+ (HashMap<String, Object>) defaults.get(CollectionAdminParams.CLUSTER);
if (cluster == null) {
cluster = new HashMap<>();
defaults.put(CollectionAdminParams.CLUSTER, cluster);
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/MockSolrZkClient.java b/solr/test-framework/src/java/org/apache/solr/cloud/MockSolrZkClient.java
index 28996a315a5..9ab12d46854 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/MockSolrZkClient.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/MockSolrZkClient.java
@@ -27,18 +27,18 @@ public class MockSolrZkClient extends SolrZkClient {
public MockSolrZkClient() {
super();
}
-
+
@Override
public Boolean exists(final String path, boolean retryOnConnLoss)
throws KeeperException, InterruptedException {
-
+
return false;
}
-
+
@Override
- public byte[] getData(final String path, final Watcher watcher, final Stat stat, boolean retryOnConnLoss)
+ public byte[] getData(
+ final String path, final Watcher watcher, final Stat stat, boolean retryOnConnLoss)
throws KeeperException, InterruptedException {
return null;
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/MockZkStateReader.java b/solr/test-framework/src/java/org/apache/solr/cloud/MockZkStateReader.java
index 2f73792d92b..7375d3212f2 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/MockZkStateReader.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/MockZkStateReader.java
@@ -17,7 +17,6 @@
package org.apache.solr.cloud;
import java.util.Set;
-
import org.apache.solr.common.cloud.ClusterState;
import org.apache.solr.common.cloud.DocCollectionWatcher;
import org.apache.solr.common.cloud.ZkStateReader;
@@ -32,8 +31,8 @@ public class MockZkStateReader extends ZkStateReader {
this.clusterState = clusterState;
this.collections = collections;
}
-
- public Set<String> getAllCollections(){
+
+ public Set<String> getAllCollections() {
return collections;
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/MultiSolrCloudTestCase.java b/solr/test-framework/src/java/org/apache/solr/cloud/MultiSolrCloudTestCase.java
index 3746f2dbc92..1b62e0b5726 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/MultiSolrCloudTestCase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/MultiSolrCloudTestCase.java
@@ -20,7 +20,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Function;
-
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.junit.AfterClass;
@@ -28,39 +27,42 @@ import org.junit.AfterClass;
/**
* Base class for tests that require more than one SolrCloud
*
- * Derived tests should call {@link #doSetupClusters(String[], Function, BiConsumer)} in a {@code BeforeClass}
- * static method. This configures and starts the {@link MiniSolrCloudCluster} instances, available
- * via the {@code clusterId2cluster} variable. The clusters' shutdown is handled automatically.
+ * <p>Derived tests should call {@link #doSetupClusters(String[], Function, BiConsumer)} in a {@code
+ * BeforeClass} static method. This configures and starts the {@link MiniSolrCloudCluster}
+ * instances, available via the {@code clusterId2cluster} variable. The clusters' shutdown is
+ * handled automatically.
*/
public abstract class MultiSolrCloudTestCase extends SolrTestCaseJ4 {
- protected static Map<String,MiniSolrCloudCluster> clusterId2cluster = new HashMap<String,MiniSolrCloudCluster>();
+ protected static Map<String, MiniSolrCloudCluster> clusterId2cluster =
+ new HashMap<String, MiniSolrCloudCluster>();
- protected static abstract class DefaultClusterCreateFunction implements Function<String,MiniSolrCloudCluster> {
+ protected abstract static class DefaultClusterCreateFunction
+ implements Function<String, MiniSolrCloudCluster> {
- public DefaultClusterCreateFunction() {
- }
+ public DefaultClusterCreateFunction() {}
protected abstract int nodesPerCluster(String clusterId);
@Override
public MiniSolrCloudCluster apply(String clusterId) {
try {
- final MiniSolrCloudCluster cluster = new MiniSolrCloudCluster.Builder(nodesPerCluster(clusterId), createTempDir())
- .addConfig("conf", configset("cloud-dynamic"))
- .build();
+ final MiniSolrCloudCluster cluster =
+ new MiniSolrCloudCluster.Builder(nodesPerCluster(clusterId), createTempDir())
+ .addConfig("conf", configset("cloud-dynamic"))
+ .build();
return cluster;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
-
}
- protected static abstract class DefaultClusterInitFunction implements BiConsumer<String,MiniSolrCloudCluster> {
+ protected abstract static class DefaultClusterInitFunction
+ implements BiConsumer<String, MiniSolrCloudCluster> {
- final private int numShards;
- final private int numReplicas;
+ private final int numShards;
+ private final int numReplicas;
public DefaultClusterInitFunction(int numShards, int numReplicas) {
this.numShards = numShards;
@@ -69,24 +71,29 @@ public abstract class MultiSolrCloudTestCase extends SolrTestCaseJ4 {
protected void doAccept(String collection, MiniSolrCloudCluster cluster) {
try {
- CollectionAdminRequest
- .createCollection(collection, "conf", numShards, numReplicas)
- .processAndWait(cluster.getSolrClient(), SolrCloudTestCase.DEFAULT_TIMEOUT);
-
- AbstractDistribZkTestBase.waitForRecoveriesToFinish(collection, cluster.getSolrClient().getZkStateReader(), false, true, SolrCloudTestCase.DEFAULT_TIMEOUT);
+ CollectionAdminRequest.createCollection(collection, "conf", numShards, numReplicas)
+ .processAndWait(cluster.getSolrClient(), SolrCloudTestCase.DEFAULT_TIMEOUT);
+
+ AbstractDistribZkTestBase.waitForRecoveriesToFinish(
+ collection,
+ cluster.getSolrClient().getZkStateReader(),
+ false,
+ true,
+ SolrCloudTestCase.DEFAULT_TIMEOUT);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
-
}
- protected static void doSetupClusters(final String[] clusterIds,
- final Function<String,MiniSolrCloudCluster> createFunc,
- final BiConsumer<String,MiniSolrCloudCluster> initFunc) throws Exception {
+ protected static void doSetupClusters(
+ final String[] clusterIds,
+ final Function<String, MiniSolrCloudCluster> createFunc,
+ final BiConsumer<String, MiniSolrCloudCluster> initFunc)
+ throws Exception {
for (final String clusterId : clusterIds) {
- assertFalse("duplicate clusterId "+clusterId, clusterId2cluster.containsKey(clusterId));
+ assertFalse("duplicate clusterId " + clusterId, clusterId2cluster.containsKey(clusterId));
MiniSolrCloudCluster cluster = createFunc.apply(clusterId);
initFunc.accept(clusterId, cluster);
clusterId2cluster.put(clusterId, cluster);
@@ -100,5 +107,4 @@ public abstract class MultiSolrCloudTestCase extends SolrTestCaseJ4 {
}
clusterId2cluster.clear();
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudAuthTestCase.java b/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudAuthTestCase.java
index b8ff1e8f5e0..fd9ad2d9f99 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudAuthTestCase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudAuthTestCase.java
@@ -17,6 +17,13 @@
package org.apache.solr.cloud;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.Metric;
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.Timer;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
@@ -28,12 +35,6 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Predicate;
-
-import com.codahale.metrics.Counter;
-import com.codahale.metrics.Meter;
-import com.codahale.metrics.Metric;
-import com.codahale.metrics.MetricRegistry;
-import com.codahale.metrics.Timer;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
@@ -49,25 +50,41 @@ import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static java.nio.charset.StandardCharsets.UTF_8;
-
/**
- * Base test class for cloud tests wanting to track authentication metrics.
- * The assertions provided by this base class require a *minimum* count, not exact count from metrics.
- * Warning: Make sure that your test case does not break when beasting.
+ * Base test class for cloud tests wanting to track authentication metrics. The assertions provided
+ * by this base class require a *minimum* count, not exact count from metrics. Warning: Make sure
+ * that your test case does not break when beasting.
*/
public class SolrCloudAuthTestCase extends SolrCloudTestCase {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- private static final List<String> AUTH_METRICS_KEYS = Arrays.asList("errors", "requests", "authenticated",
- "passThrough", "failWrongCredentials", "failMissingCredentials", "requestTimes", "totalTime");
+ private static final List<String> AUTH_METRICS_KEYS =
+ Arrays.asList(
+ "errors",
+ "requests",
+ "authenticated",
+ "passThrough",
+ "failWrongCredentials",
+ "failMissingCredentials",
+ "requestTimes",
+ "totalTime");
private static final List<String> AUTH_METRICS_METER_KEYS = Arrays.asList("errors", "count");
- private static final List<String> AUTH_METRICS_TIMER_KEYS = Collections.singletonList("requestTimes");
+ private static final List<String> AUTH_METRICS_TIMER_KEYS =
+ Collections.singletonList("requestTimes");
private static final String METRICS_PREFIX_PKI = "SECURITY./authentication/pki.";
private static final String METRICS_PREFIX = "SECURITY./authentication.";
+
@SuppressWarnings({"rawtypes"})
public static final Predicate NOT_NULL_PREDICATE = o -> o != null;
+
private static final List<String> AUDIT_METRICS_KEYS = Arrays.asList("count");
- private static final List<String> AUTH_METRICS_TO_COMPARE = Arrays.asList("requests", "authenticated", "passThrough", "failWrongCredentials", "failMissingCredentials", "errors");
+ private static final List<String> AUTH_METRICS_TO_COMPARE =
+ Arrays.asList(
+ "requests",
+ "authenticated",
+ "passThrough",
+ "failWrongCredentials",
+ "failMissingCredentials",
+ "errors");
private static final List<String> AUDIT_METRICS_TO_COMPARE = Arrays.asList("count");
@BeforeClass
@@ -78,50 +95,94 @@ public class SolrCloudAuthTestCase extends SolrCloudTestCase {
@AfterClass
public static void disableMetrics() {
System.clearProperty("metricsEnabled");
-
}
- /**
- * Used to check metric counts for PKI auth
- */
- protected void assertPkiAuthMetricsMinimums(int requests, int authenticated, int passThrough, int failWrongCredentials, int failMissingCredentials, int errors) throws InterruptedException {
- assertAuthMetricsMinimums(METRICS_PREFIX_PKI, requests, authenticated, passThrough, failWrongCredentials, failMissingCredentials, errors);
+ /** Used to check metric counts for PKI auth */
+ protected void assertPkiAuthMetricsMinimums(
+ int requests,
+ int authenticated,
+ int passThrough,
+ int failWrongCredentials,
+ int failMissingCredentials,
+ int errors)
+ throws InterruptedException {
+ assertAuthMetricsMinimums(
+ METRICS_PREFIX_PKI,
+ requests,
+ authenticated,
+ passThrough,
+ failWrongCredentials,
+ failMissingCredentials,
+ errors);
}
-
+
/**
* Used to check metric counts for the AuthPlugin in use (except PKI)
- *
- * TODO: many of these params have to be under specified - this should wait a bit to see the desired params and timeout
+ *
+ * <p>TODO: many of these params have to be under specified - this should wait a bit to see the
+ * desired params and timeout
*/
- protected void assertAuthMetricsMinimums(int requests, int authenticated, int passThrough, int failWrongCredentials, int failMissingCredentials, int errors) throws InterruptedException {
- assertAuthMetricsMinimums(METRICS_PREFIX, requests, authenticated, passThrough, failWrongCredentials, failMissingCredentials, errors);
+ protected void assertAuthMetricsMinimums(
+ int requests,
+ int authenticated,
+ int passThrough,
+ int failWrongCredentials,
+ int failMissingCredentials,
+ int errors)
+ throws InterruptedException {
+ assertAuthMetricsMinimums(
+ METRICS_PREFIX,
+ requests,
+ authenticated,
+ passThrough,
+ failWrongCredentials,
+ failMissingCredentials,
+ errors);
}
/**
* Common test method to be able to check security from any authentication plugin
+ *
* @param cluster the MiniSolrCloudCluster to fetch metrics from
- * @param prefix the metrics key prefix, currently "SECURITY./authentication." for basic auth and "SECURITY./authentication/pki." for PKI
+ * @param prefix the metrics key prefix, currently "SECURITY./authentication." for basic auth and
+ * "SECURITY./authentication/pki." for PKI
* @param keys what keys to examine
*/
- Map<String,Long> countSecurityMetrics(MiniSolrCloudCluster cluster, String prefix, List<String> keys) {
+ Map<String, Long> countSecurityMetrics(
+ MiniSolrCloudCluster cluster, String prefix, List<String> keys) {
List<Map<String, Metric>> metrics = new ArrayList<>();
- cluster.getJettySolrRunners().forEach(r -> {
- MetricRegistry registry = r.getCoreContainer().getMetricManager().registry("solr.node");
- assertNotNull(registry);
- metrics.add(registry.getMetrics());
- });
+ cluster
+ .getJettySolrRunners()
+ .forEach(
+ r -> {
+ MetricRegistry registry =
+ r.getCoreContainer().getMetricManager().registry("solr.node");
+ assertNotNull(registry);
+ metrics.add(registry.getMetrics());
+ });
- Map<String,Long> counts = new HashMap<>();
- keys.forEach(k -> {
- counts.put(k, sumCount(prefix, k, metrics));
- });
+ Map<String, Long> counts = new HashMap<>();
+ keys.forEach(
+ k -> {
+ counts.put(k, sumCount(prefix, k, metrics));
+ });
return counts;
- }
-
+ }
+
/**
* Common test method to be able to check auth metrics from any authentication plugin
- * @param prefix the metrics key prefix, currently "SECURITY./authentication." for basic auth and "SECURITY./authentication/pki." for PKI
+ *
+ * @param prefix the metrics key prefix, currently "SECURITY./authentication." for basic auth and
+ * "SECURITY./authentication/pki." for PKI
*/
- private void assertAuthMetricsMinimums(String prefix, int requests, int authenticated, int passThrough, int failWrongCredentials, int failMissingCredentials, int errors) throws InterruptedException {
+ private void assertAuthMetricsMinimums(
+ String prefix,
+ int requests,
+ int authenticated,
+ int passThrough,
+ int failWrongCredentials,
+ int failMissingCredentials,
+ int errors)
+ throws InterruptedException {
Map<String, Long> expectedCounts = new HashMap<>();
expectedCounts.put("requests", (long) requests);
expectedCounts.put("authenticated", (long) authenticated);
@@ -132,12 +193,18 @@ public class SolrCloudAuthTestCase extends SolrCloudTestCase {
final Map<String, Long> counts = countSecurityMetrics(cluster, prefix, AUTH_METRICS_KEYS);
final boolean success = isMetricsEqualOrLarger(AUTH_METRICS_TO_COMPARE, expectedCounts, counts);
-
- assertTrue("Expected metric minimums for prefix " + prefix + ": " + expectedCounts +
- ", but got: " + counts + "(Possible cause is delay in loading modified " +
- "security.json; see SOLR-13464 for test work around)",
- success);
-
+
+ assertTrue(
+ "Expected metric minimums for prefix "
+ + prefix
+ + ": "
+ + expectedCounts
+ + ", but got: "
+ + counts
+ + "(Possible cause is delay in loading modified "
+ + "security.json; see SOLR-13464 for test work around)",
+ success);
+
if (counts.get("requests") > 0) {
assertTrue("requestTimes count not > 1", counts.get("requestTimes") > 1);
assertTrue("totalTime not > 0", counts.get("totalTime") > 0);
@@ -146,9 +213,13 @@ public class SolrCloudAuthTestCase extends SolrCloudTestCase {
/**
* Common test method to be able to check audit metrics
- * @param className the class name to be used for composing prefix, e.g. "SECURITY./auditlogging/SolrLogAuditLoggerPlugin"
+ *
+ * @param className the class name to be used for composing prefix, e.g.
+ * "SECURITY./auditlogging/SolrLogAuditLoggerPlugin"
*/
- protected void assertAuditMetricsMinimums(MiniSolrCloudCluster cluster, String className, int count, int errors) throws InterruptedException {
+ protected void assertAuditMetricsMinimums(
+ MiniSolrCloudCluster cluster, String className, int count, int errors)
+ throws InterruptedException {
String prefix = "SECURITY./auditlogging." + className + ".";
Map<String, Long> expectedCounts = new HashMap<>();
expectedCounts.put("count", (long) count);
@@ -161,41 +232,62 @@ public class SolrCloudAuthTestCase extends SolrCloudTestCase {
counts = countSecurityMetrics(cluster, prefix, AUDIT_METRICS_KEYS);
success = isMetricsEqualOrLarger(AUDIT_METRICS_TO_COMPARE, expectedCounts, counts);
}
-
- assertTrue("Expected metric minimums for prefix " + prefix + ": " + expectedCounts + ", but got: " + counts, success);
+
+ assertTrue(
+ "Expected metric minimums for prefix "
+ + prefix
+ + ": "
+ + expectedCounts
+ + ", but got: "
+ + counts,
+ success);
}
-
- private boolean isMetricsEqualOrLarger(List<String> metricsToCompare, Map<String, Long> expectedCounts, Map<String, Long> actualCounts) {
+
+ private boolean isMetricsEqualOrLarger(
+ List<String> metricsToCompare,
+ Map<String, Long> expectedCounts,
+ Map<String, Long> actualCounts) {
return metricsToCompare.stream()
.allMatch(k -> actualCounts.get(k).intValue() >= expectedCounts.get(k).intValue());
}
// Have to sum the metrics from all three shards/nodes
private long sumCount(String prefix, String key, List<Map<String, Metric>> metrics) {
- assertTrue("Metric " + prefix + key + " does not exist", metrics.get(0).containsKey(prefix + key));
+ assertTrue(
+ "Metric " + prefix + key + " does not exist", metrics.get(0).containsKey(prefix + key));
if (AUTH_METRICS_METER_KEYS.contains(key))
- return metrics.stream().mapToLong(l -> ((Meter)l.get(prefix + key)).getCount()).sum();
+ return metrics.stream().mapToLong(l -> ((Meter) l.get(prefix + key)).getCount()).sum();
else if (AUTH_METRICS_TIMER_KEYS.contains(key))
- return (long) ((long) 1000 * metrics.stream().mapToDouble(l -> ((Timer)l.get(prefix + key)).getMeanRate()).average().orElse(0.0d));
- else
- return metrics.stream().mapToLong(l -> ((Counter)l.get(prefix + key)).getCount()).sum();
- }
-
- public static void verifySecurityStatus(HttpClient cl, String url, String objPath,
- Object expected, int count) throws Exception {
- verifySecurityStatus(cl, url, objPath, expected, count, (String)null);
+ return (long)
+ ((long) 1000
+ * metrics.stream()
+ .mapToDouble(l -> ((Timer) l.get(prefix + key)).getMeanRate())
+ .average()
+ .orElse(0.0d));
+ else return metrics.stream().mapToLong(l -> ((Counter) l.get(prefix + key)).getCount()).sum();
}
+ public static void verifySecurityStatus(
+ HttpClient cl, String url, String objPath, Object expected, int count) throws Exception {
+ verifySecurityStatus(cl, url, objPath, expected, count, (String) null);
+ }
- public static void verifySecurityStatus(HttpClient cl, String url, String objPath,
- Object expected, int count, String user, String pwd)
+ public static void verifySecurityStatus(
+ HttpClient cl,
+ String url,
+ String objPath,
+ Object expected,
+ int count,
+ String user,
+ String pwd)
throws Exception {
verifySecurityStatus(cl, url, objPath, expected, count, makeBasicAuthHeader(user, pwd));
}
@SuppressWarnings({"unchecked"})
- protected static void verifySecurityStatus(HttpClient cl, String url, String objPath,
- Object expected, int count, String authHeader) throws IOException, InterruptedException {
+ protected static void verifySecurityStatus(
+ HttpClient cl, String url, String objPath, Object expected, int count, String authHeader)
+ throws IOException, InterruptedException {
boolean success = false;
String s = null;
List<String> hierarchy = StrUtils.splitSmart(objPath, '/');
@@ -240,24 +332,22 @@ public class SolrCloudAuthTestCase extends SolrCloudTestCase {
}
/**
- * This helper method can be used by tests to monitor the current state of either
- * <code>"authentication"</code> or <code>"authorization"</code> plugins in use each
- * node of the current cluster.
- * <p>
- * This can be useful in a {@link TimeOut#waitFor} loop to monitor a cluster and "wait for"
- * A change in security settings to affect all nodes by comparing the objects in the current
- * Map with the one in use prior to executing some test command. (providing a work around
- * for the security user experienence limitations identified in
- * <a href="https://issues.apache.org/jira/browse/SOLR-13464">SOLR-13464</a> )
- * </p>
- *
- * @param url A REST url (or any arbitrary String) ending in
- * <code>"authentication"</code> or <code>"authorization"</code> used to specify the type of
- * plugins to introspect
+ * This helper method can be used by tests to monitor the current state of either <code>
+ * "authentication"</code> or <code>"authorization"</code> plugins in use each node of the current
+ * cluster.
+ *
+ * <p>This can be useful in a {@link TimeOut#waitFor} loop to monitor a cluster and "wait for" A
+ * change in security settings to affect all nodes by comparing the objects in the current Map
+ * with the one in use prior to executing some test command. (providing a work around for the
+ * security user experienence limitations identified in <a
+ * href="https://issues.apache.org/jira/browse/SOLR-13464">SOLR-13464</a> )
+ *
+ * @param url A REST url (or any arbitrary String) ending in <code>"authentication"</code> or
+ * <code>"authorization"</code> used to specify the type of plugins to introspect
* @return A Map from <code>nodeName</code> to auth plugin
*/
- public static Map<String,Object> getAuthPluginsInUseForCluster(String url) {
- Map<String,Object> plugins = new HashMap<>();
+ public static Map<String, Object> getAuthPluginsInUseForCluster(String url) {
+ Map<String, Object> plugins = new HashMap<>();
if (url.endsWith("authentication")) {
for (JettySolrRunner r : cluster.getJettySolrRunners()) {
plugins.put(r.getNodeName(), r.getCoreContainer().getAuthenticationPlugin());
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java b/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java
index 42e7b0d92f1..a78fb72d700 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
@@ -29,7 +29,6 @@ import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Predicate;
-
import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrRequest;
@@ -53,10 +52,11 @@ import org.slf4j.LoggerFactory;
/**
* Base class for SolrCloud tests
- * <p>
- * Derived tests should call {@link #configureCluster(int)} in a {@code BeforeClass}
- * static method or {@code Before} setUp method. This configures and starts a {@link MiniSolrCloudCluster}, available
- * via the {@code cluster} variable. Cluster shutdown is handled automatically if using {@code BeforeClass}.
+ *
+ * <p>Derived tests should call {@link #configureCluster(int)} in a {@code BeforeClass} static
+ * method or {@code Before} setUp method. This configures and starts a {@link MiniSolrCloudCluster},
+ * available via the {@code cluster} variable. Cluster shutdown is handled automatically if using
+ * {@code BeforeClass}.
*
* <pre>
* <code>
@@ -72,37 +72,40 @@ import org.slf4j.LoggerFactory;
public class SolrCloudTestCase extends SolrTestCaseJ4 {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- public static final Boolean USE_PER_REPLICA_STATE = Boolean.parseBoolean(System.getProperty("use.per-replica", "false"));
+ public static final Boolean USE_PER_REPLICA_STATE =
+ Boolean.parseBoolean(System.getProperty("use.per-replica", "false"));
- public static final int DEFAULT_TIMEOUT = 45; // this is an important timeout for test stability - can't be too short
+ // this is an important timeout for test stability - can't be too short
+ public static final int DEFAULT_TIMEOUT = 45;
- /**
- * The cluster
- */
+ /** The cluster */
protected static volatile MiniSolrCloudCluster cluster;
protected static SolrZkClient zkClient() {
ZkStateReader reader = cluster.getSolrClient().getZkStateReader();
- if (reader == null)
- cluster.getSolrClient().connect();
+ if (reader == null) cluster.getSolrClient().connect();
return cluster.getSolrClient().getZkStateReader().getZkClient();
}
/**
* Call this to configure a cluster of n nodes.
- * <p>
- * NB you must call {@link MiniSolrCloudCluster.Builder#configure()} to start the cluster
+ *
+ * <p>NB you must call {@link MiniSolrCloudCluster.Builder#configure()} to start the cluster
*
* @param nodeCount the number of nodes
*/
protected static MiniSolrCloudCluster.Builder configureCluster(int nodeCount) {
- // 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)
+ // 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)
boolean useDistributedCollectionConfigSetExecution = LuceneTestCase.random().nextInt(2) == 0;
- boolean useDistributedClusterStateUpdate = useDistributedCollectionConfigSetExecution || LuceneTestCase.random().nextInt(2) == 0;
- return new MiniSolrCloudCluster.Builder(nodeCount, createTempDir()).withDistributedClusterStateUpdates(useDistributedCollectionConfigSetExecution, useDistributedClusterStateUpdate);
+ boolean useDistributedClusterStateUpdate =
+ useDistributedCollectionConfigSetExecution || LuceneTestCase.random().nextInt(2) == 0;
+ return new MiniSolrCloudCluster.Builder(nodeCount, createTempDir())
+ .withDistributedClusterStateUpdates(
+ useDistributedCollectionConfigSetExecution, useDistributedClusterStateUpdate);
}
@AfterClass
@@ -117,44 +120,63 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
}
@Before
- public void checkClusterConfiguration() {
-
- }
+ public void checkClusterConfiguration() {}
/* Cluster helper methods ************************************/
- /**
- * Get the collection state for a particular collection
- */
+ /** Get the collection state for a particular collection */
protected static DocCollection getCollectionState(String collectionName) {
- return cluster.getSolrClient().getZkStateReader().getClusterState().getCollection(collectionName);
+ return cluster
+ .getSolrClient()
+ .getZkStateReader()
+ .getClusterState()
+ .getCollection(collectionName);
}
- protected static void waitForState(String message, String collection, CollectionStatePredicate predicate) {
+ protected static void waitForState(
+ String message, String collection, CollectionStatePredicate predicate) {
waitForState(message, collection, predicate, DEFAULT_TIMEOUT, TimeUnit.SECONDS);
}
/**
* Wait for a particular collection state to appear in the cluster client's state reader
- * <p>
- * This is a convenience method using the {@link #DEFAULT_TIMEOUT}
*
- * @param message a message to report on failure
+ * <p>This is a convenience method using the {@link #DEFAULT_TIMEOUT}
+ *
+ * @param message a message to report on failure
* @param collection the collection to watch
- * @param predicate a predicate to match against the collection state
+ * @param predicate a predicate to match against the collection state
*/
- protected static void waitForState(String message, String collection, CollectionStatePredicate predicate, int timeout, TimeUnit timeUnit) {
+ protected static void waitForState(
+ String message,
+ String collection,
+ CollectionStatePredicate predicate,
+ int timeout,
+ TimeUnit timeUnit) {
log.info("waitForState ({}): {}", collection, message);
AtomicReference<DocCollection> state = new AtomicReference<>();
AtomicReference<Set<String>> liveNodesLastSeen = new AtomicReference<>();
try {
- cluster.getSolrClient().waitForState(collection, timeout, timeUnit, (n, c) -> {
- state.set(c);
- liveNodesLastSeen.set(n);
- return predicate.matches(n, c);
- });
+ cluster
+ .getSolrClient()
+ .waitForState(
+ collection,
+ timeout,
+ timeUnit,
+ (n, c) -> {
+ state.set(c);
+ liveNodesLastSeen.set(n);
+ return predicate.matches(n, c);
+ });
} catch (Exception e) {
- fail(message + "\n" + e.getMessage() + "\nLive Nodes: " + Arrays.toString(liveNodesLastSeen.get().toArray()) + "\nLast available state: " + state.get());
+ fail(
+ message
+ + "\n"
+ + e.getMessage()
+ + "\nLive Nodes: "
+ + Arrays.toString(liveNodesLastSeen.get().toArray())
+ + "\nLast available state: "
+ + state.get());
}
}
@@ -164,10 +186,8 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
*/
public static CollectionStatePredicate clusterShape(int expectedShards, int expectedReplicas) {
return (liveNodes, collectionState) -> {
- if (collectionState == null)
- return false;
- if (collectionState.getSlices().size() != expectedShards)
- return false;
+ if (collectionState == null) return false;
+ if (collectionState.getSlices().size() != expectedShards) return false;
return compareActiveReplicaCountsForShards(expectedReplicas, liveNodes, collectionState);
};
}
@@ -176,15 +196,17 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
* Return a {@link CollectionStatePredicate} that returns true if a collection has the expected
* number of active shards and active replicas
*/
- public static CollectionStatePredicate activeClusterShape(int expectedShards, int expectedReplicas) {
+ public static CollectionStatePredicate activeClusterShape(
+ int expectedShards, int expectedReplicas) {
return (liveNodes, collectionState) -> {
- if (collectionState == null)
- return false;
+ if (collectionState == null) return false;
if (log.isInfoEnabled()) {
- log.info("active slice count: {} expected: {}", collectionState.getActiveSlices().size(), expectedShards);
+ log.info(
+ "active slice count: {} expected: {}",
+ collectionState.getActiveSlices().size(),
+ expectedShards);
}
- if (collectionState.getActiveSlices().size() != expectedShards)
- return false;
+ if (collectionState.getActiveSlices().size() != expectedShards) return false;
return compareActiveReplicaCountsForShards(expectedReplicas, liveNodes, collectionState);
};
}
@@ -214,7 +236,8 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
};
}
- private static boolean compareActiveReplicaCountsForShards(int expectedReplicas, Set<String> liveNodes, DocCollection collectionState) {
+ private static boolean compareActiveReplicaCountsForShards(
+ int expectedReplicas, Set<String> liveNodes, DocCollection collectionState) {
int activeReplicas = 0;
for (Slice slice : collectionState) {
for (Replica replica : slice) {
@@ -224,26 +247,24 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
}
}
- log.info("active replica count: {} expected replica count: {}", activeReplicas, expectedReplicas);
+ log.info(
+ "active replica count: {} expected replica count: {}", activeReplicas, expectedReplicas);
return activeReplicas == expectedReplicas;
-
}
- /**
- * Get a (reproducibly) random shard from a {@link DocCollection}
- */
+ /** Get a (reproducibly) random shard from a {@link DocCollection} */
protected static Slice getRandomShard(DocCollection collection) {
List<Slice> shards = new ArrayList<>(collection.getActiveSlices());
if (shards.size() == 0)
- fail("Couldn't get random shard for collection as it has no shards!\n" + collection.toString());
+ fail(
+ "Couldn't get random shard for collection as it has no shards!\n"
+ + collection.toString());
Collections.shuffle(shards, random());
return shards.get(0);
}
- /**
- * Get a (reproducibly) random replica from a {@link Slice}
- */
+ /** Get a (reproducibly) random replica from a {@link Slice} */
protected static Replica getRandomReplica(Slice slice) {
List<Replica> replicas = new ArrayList<>(slice.getReplicas());
if (replicas.size() == 0)
@@ -252,36 +273,40 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
return replicas.get(0);
}
- /**
- * Get a (reproducibly) random replica from a {@link Slice} matching a predicate
- */
+ /** Get a (reproducibly) random replica from a {@link Slice} matching a predicate */
protected static Replica getRandomReplica(Slice slice, Predicate<Replica> matchPredicate) {
List<Replica> replicas = new ArrayList<>(slice.getReplicas());
if (replicas.size() == 0)
fail("Couldn't get random replica from shard as it has no replicas!\n" + slice.toString());
Collections.shuffle(replicas, random());
for (Replica replica : replicas) {
- if (matchPredicate.test(replica))
- return replica;
+ if (matchPredicate.test(replica)) return replica;
}
fail("Couldn't get random replica that matched conditions\n" + slice.toString());
- return null; // just to keep the compiler happy - fail will always throw an Exception
+ return null; // just to keep the compiler happy - fail will always throw an Exception
}
/**
* Get the {@link CoreStatus} data for a {@link Replica}
- * <p>
- * This assumes that the replica is hosted on a live node.
+ *
+ * <p>This assumes that the replica is hosted on a live node.
*/
- protected static CoreStatus getCoreStatus(Replica replica) throws IOException, SolrServerException {
+ protected static CoreStatus getCoreStatus(Replica replica)
+ throws IOException, SolrServerException {
JettySolrRunner jetty = cluster.getReplicaJetty(replica);
- try (HttpSolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString(), cluster.getSolrClient().getHttpClient())) {
+ try (HttpSolrClient client =
+ getHttpSolrClient(jetty.getBaseUrl().toString(), cluster.getSolrClient().getHttpClient())) {
return CoreAdminRequest.getCoreStatus(replica.getCoreName(), client);
}
}
@SuppressWarnings({"rawtypes"})
- protected NamedList waitForResponse(Predicate<NamedList> predicate, SolrRequest request, int intervalInMillis, int numRetries, String messageOnFail) {
+ protected NamedList waitForResponse(
+ Predicate<NamedList> predicate,
+ SolrRequest request,
+ int intervalInMillis,
+ int numRetries,
+ String messageOnFail) {
log.info("waitForResponse: {}", request);
int i = 0;
for (; i < numRetries; i++) {
@@ -300,8 +325,8 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
}
/**
- * Ensure that the given number of solr instances are running. If less instances are found then new instances are
- * started. If extra instances are found then they are stopped.
+ * Ensure that the given number of solr instances are running. If less instances are found then
+ * new instances are started. If extra instances are found then they are stopped.
*
* @param nodeCount the number of Solr instances that should be running at the end of this method
* @throws Exception on error
@@ -338,8 +363,9 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
// info returned from the query doesn't. Oh well. We will include both, just in case
replicaTypeMap.put(coreUrl, replica.getType().toString());
if (coreUrl.endsWith("/")) {
- replicaTypeMap.put(coreUrl.substring(0, coreUrl.length() - 1), replica.getType().toString());
- }else {
+ replicaTypeMap.put(
+ coreUrl.substring(0, coreUrl.length() - 1), replica.getType().toString());
+ } else {
replicaTypeMap.put(coreUrl + "/", replica.getType().toString());
}
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/StoppableCommitThread.java b/solr/test-framework/src/java/org/apache/solr/cloud/StoppableCommitThread.java
index 17b3eb6cd69..3a0edb84a64 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/StoppableCommitThread.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/StoppableCommitThread.java
@@ -18,7 +18,6 @@ package org.apache.solr.cloud;
import java.lang.invoke.MethodHandles;
import java.util.concurrent.atomic.AtomicInteger;
-
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.cloud.AbstractFullDistribZkTestBase.StoppableThread;
import org.slf4j.Logger;
@@ -26,7 +25,7 @@ import org.slf4j.LoggerFactory;
public class StoppableCommitThread extends StoppableThread {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
+
private final SolrClient cloudClient;
private final long timeBetweenCommitsMs;
private final boolean softCommits;
@@ -34,13 +33,14 @@ public class StoppableCommitThread extends StoppableThread {
private final AtomicInteger numCommits = new AtomicInteger(0);
private final AtomicInteger numFails = new AtomicInteger(0);
- public StoppableCommitThread(SolrClient cloudClient, long timeBetweenCommitsMs, boolean softCommits) {
+ public StoppableCommitThread(
+ SolrClient cloudClient, long timeBetweenCommitsMs, boolean softCommits) {
super("StoppableCommitThread");
this.cloudClient = cloudClient;
this.timeBetweenCommitsMs = timeBetweenCommitsMs;
this.softCommits = softCommits;
}
-
+
@Override
public void run() {
log.debug("StoppableCommitThread started");
@@ -59,7 +59,10 @@ public class StoppableCommitThread extends StoppableThread {
}
}
if (log.isInfoEnabled()) {
- log.info("StoppableCommitThread finished. Committed {} times. Failed {} times.", numCommits.get(), numFails.get());
+ log.info(
+ "StoppableCommitThread finished. Committed {} times. Failed {} times.",
+ numCommits.get(),
+ numFails.get());
}
}
@@ -67,5 +70,4 @@ public class StoppableCommitThread extends StoppableThread {
public void safeStop() {
this.stop = true;
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/StoppableIndexingThread.java b/solr/test-framework/src/java/org/apache/solr/cloud/StoppableIndexingThread.java
index 0385d734dcc..9126d5a2b47 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/StoppableIndexingThread.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/StoppableIndexingThread.java
@@ -21,7 +21,6 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.request.UpdateRequest;
@@ -44,12 +43,20 @@ public class StoppableIndexingThread extends AbstractFullDistribZkTestBase.Stopp
private List<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
private int batchSize;
private boolean pauseBetweenUpdates;
-
- public StoppableIndexingThread(SolrClient controlClient, SolrClient cloudClient, String id, boolean doDeletes) {
+
+ public StoppableIndexingThread(
+ SolrClient controlClient, SolrClient cloudClient, String id, boolean doDeletes) {
this(controlClient, cloudClient, id, doDeletes, -1, 1, true);
}
-
- public StoppableIndexingThread(SolrClient controlClient, SolrClient cloudClient, String id, boolean doDeletes, int numCycles, int batchSize, boolean pauseBetweenUpdates) {
+
+ public StoppableIndexingThread(
+ SolrClient controlClient,
+ SolrClient cloudClient,
+ String id,
+ boolean doDeletes,
+ int numCycles,
+ int batchSize,
+ boolean pauseBetweenUpdates) {
super("StoppableIndexingThread");
this.controlClient = controlClient;
this.cloudClient = cloudClient;
@@ -60,14 +67,14 @@ public class StoppableIndexingThread extends AbstractFullDistribZkTestBase.Stopp
this.pauseBetweenUpdates = pauseBetweenUpdates;
setDaemon(true);
}
-
+
@Override
public void run() {
int i = 0;
int numDone = 0;
numDeletes = 0;
numAdds = 0;
-
+
while (true && !stop) {
if (numCycles != -1) {
if (numDone > numCycles) {
@@ -78,7 +85,7 @@ public class StoppableIndexingThread extends AbstractFullDistribZkTestBase.Stopp
String id = this.id + "-" + i;
++i;
boolean addFailed = false;
-
+
if (doDeletes && AbstractFullDistribZkTestBase.random().nextBoolean() && deletes.size() > 0) {
String deleteId = deletes.remove(0);
try {
@@ -89,7 +96,7 @@ public class StoppableIndexingThread extends AbstractFullDistribZkTestBase.Stopp
req.setParam("CONTROL", "TRUE");
req.process(controlClient);
}
-
+
cloudClient.deleteById(deleteId);
} catch (Exception e) {
System.err.println("REQUEST FAILED for id=" + deleteId);
@@ -101,17 +108,16 @@ public class StoppableIndexingThread extends AbstractFullDistribZkTestBase.Stopp
deleteFails.add(deleteId);
}
}
-
+
try {
numAdds++;
SolrInputDocument doc = new SolrInputDocument();
- addFields(doc, "id", id, i1, 50, t1,
- "to come to the aid of their country.");
+ addFields(doc, "id", id, i1, 50, t1, "to come to the aid of their country.");
addFields(doc, "rnd_b", true);
-
+
docs.add(doc);
-
- if (docs.size() >= batchSize) {
+
+ if (docs.size() >= batchSize) {
indexDocs(docs);
docs.clear();
}
@@ -125,11 +131,11 @@ public class StoppableIndexingThread extends AbstractFullDistribZkTestBase.Stopp
}
addFails.add(id);
}
-
+
if (!addFailed && doDeletes && AbstractFullDistribZkTestBase.random().nextBoolean()) {
deletes.add(id);
}
-
+
if (docs.size() > 0 && pauseBetweenUpdates) {
try {
Thread.sleep(AbstractFullDistribZkTestBase.random().nextInt(500) + 50);
@@ -138,49 +144,54 @@ public class StoppableIndexingThread extends AbstractFullDistribZkTestBase.Stopp
}
}
}
-
- System.err.println("added docs:" + numAdds + " with " + (addFails.size() + deleteFails.size()) + " fails"
- + " deletes:" + numDeletes);
+
+ System.err.println(
+ "added docs:"
+ + numAdds
+ + " with "
+ + (addFails.size() + deleteFails.size())
+ + " fails"
+ + " deletes:"
+ + numDeletes);
}
-
+
@Override
public void safeStop() {
stop = true;
}
-
+
public Set<String> getAddFails() {
return addFails;
}
-
+
public Set<String> getDeleteFails() {
return deleteFails;
}
-
+
public int getFailCount() {
return addFails.size() + deleteFails.size();
}
-
+
protected void addFields(SolrInputDocument doc, Object... fields) {
for (int i = 0; i < fields.length; i += 2) {
doc.addField((String) (fields[i]), fields[i + 1]);
}
}
-
- protected void indexDocs(List<SolrInputDocument> docs) throws IOException,
- SolrServerException {
-
+
+ protected void indexDocs(List<SolrInputDocument> docs) throws IOException, SolrServerException {
+
if (controlClient != null) {
UpdateRequest req = new UpdateRequest();
req.add(docs);
req.setParam("CONTROL", "TRUE");
req.process(controlClient);
}
-
+
UpdateRequest ureq = new UpdateRequest();
ureq.add(docs);
ureq.process(cloudClient);
}
-
+
public int getNumDeletes() {
return numDeletes;
}
@@ -188,5 +199,4 @@ public class StoppableIndexingThread extends AbstractFullDistribZkTestBase.Stopp
public int getNumAdds() {
return numAdds;
}
-
-}
\ No newline at end of file
+}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/StoppableSearchThread.java b/solr/test-framework/src/java/org/apache/solr/cloud/StoppableSearchThread.java
index 7e55231dd43..ec590989c3f 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/StoppableSearchThread.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/StoppableSearchThread.java
@@ -17,10 +17,8 @@
package org.apache.solr.cloud;
import java.lang.invoke.MethodHandles;
-
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
-
import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
@@ -34,7 +32,7 @@ class StoppableSearchThread extends AbstractFullDistribZkTestBase.StoppableThrea
private final CloudSolrClient cloudClient;
private volatile boolean stop = false;
protected final AtomicInteger queryFails = new AtomicInteger();
- private String[] QUERIES = new String[] {"to come","their country","aid","co*"};
+ private String[] QUERIES = new String[] {"to come", "their country", "aid", "co*"};
public StoppableSearchThread(CloudSolrClient cloudClient) {
super("StoppableSearchThread");
@@ -50,7 +48,7 @@ class StoppableSearchThread extends AbstractFullDistribZkTestBase.StoppableThrea
while (!stop) {
numSearches++;
try {
- //to come to the aid of their country.
+ // to come to the aid of their country.
cloudClient.query(new SolrQuery(QUERIES[random.nextInt(QUERIES.length)]));
} catch (Exception e) {
System.err.println("QUERY REQUEST FAILED:");
@@ -79,5 +77,4 @@ class StoppableSearchThread extends AbstractFullDistribZkTestBase.StoppableThrea
public int getFails() {
return queryFails.get();
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.java b/solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.java
index dcdbfdb9cbf..ed6d8badb63 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/ZkTestServer.java
@@ -17,7 +17,28 @@
package org.apache.solr.cloud;
import com.google.common.util.concurrent.AtomicLongMap;
-
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.lang.invoke.MethodHandles;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import javax.management.JMException;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.cloud.ZkNodeProps;
@@ -45,34 +66,12 @@ import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.management.JMException;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.lang.invoke.MethodHandles;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.net.UnknownHostException;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicReference;
-
public class ZkTestServer {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public static Path SOLRHOME;
+
static {
try {
SOLRHOME = SolrTestCaseJ4.TEST_PATH();
@@ -95,7 +94,8 @@ public class ZkTestServer {
private volatile Thread zooThread;
private volatile int theTickTime = TICK_TIME;
- // SOLR-12101 - provide defaults to avoid max timeout 20 enforced by our server instance when tick time is 1000
+ // SOLR-12101 - provide defaults to avoid max timeout 20 enforced by our server instance when tick
+ // time is 1000
private volatile int maxSessionTimeout = 90000;
private volatile int minSessionTimeout = 3000;
@@ -104,7 +104,7 @@ public class ZkTestServer {
private volatile ZKDatabase zkDb;
- static public enum LimitViolationAction {
+ public static enum LimitViolationAction {
IGNORE,
REPORT,
FAIL,
@@ -117,8 +117,7 @@ public class ZkTestServer {
private volatile LimitViolationAction violationReportAction = LimitViolationAction.REPORT;
private volatile WatchLimiter limiter = new WatchLimiter(1, LimitViolationAction.IGNORE);
- protected void initializeAndRun(String[] args) throws ConfigException,
- IOException {
+ protected void initializeAndRun(String[] args) throws ConfigException, IOException {
try {
ManagedUtil.registerLog4jMBeans();
} catch (JMException e) {
@@ -141,7 +140,7 @@ public class ZkTestServer {
private volatile LimitViolationAction action;
private AtomicLongMap<String> counters = AtomicLongMap.create();
- private ConcurrentHashMap<String,Long> maxCounters = new ConcurrentHashMap<>();
+ private ConcurrentHashMap<String, Long> maxCounters = new ConcurrentHashMap<>();
WatchLimit(long limit, String desc, LimitViolationAction action) {
this.limit = limit;
@@ -166,8 +165,16 @@ public class ZkTestServer {
maxCounters.put(key, count);
}
if (count > limit && action != LimitViolationAction.IGNORE) {
- String msg = "Number of watches created in parallel for data: " + key +
- ", type: " + desc + " exceeds limit (" + count + " > " + limit + ")";
+ String msg =
+ "Number of watches created in parallel for data: "
+ + key
+ + ", type: "
+ + desc
+ + " exceeds limit ("
+ + count
+ + " > "
+ + limit
+ + ")";
log.warn("{}", msg);
if (action == LimitViolationAction.FAIL) throw new AssertionError(msg);
}
@@ -183,13 +190,16 @@ public class ZkTestServer {
private String reportLimitViolations() {
String[] maxKeys = maxCounters.keySet().toArray(new String[maxCounters.size()]);
- Arrays.sort(maxKeys, new Comparator<String>() {
- private final Comparator<Long> valComp = Comparator.<Long>naturalOrder().reversed();
- @Override
- public int compare(String o1, String o2) {
- return valComp.compare(maxCounters.get(o1), maxCounters.get(o2));
- }
- });
+ Arrays.sort(
+ maxKeys,
+ new Comparator<String>() {
+ private final Comparator<Long> valComp = Comparator.<Long>naturalOrder().reversed();
+
+ @Override
+ public int compare(String o1, String o2) {
+ return valComp.compare(maxCounters.get(o1), maxCounters.get(o2));
+ }
+ });
StringBuilder sb = new StringBuilder();
boolean first = true;
@@ -211,7 +221,7 @@ public class ZkTestServer {
WatchLimit dataLimit;
WatchLimit childrenLimit;
- private WatchLimiter (long limit, LimitViolationAction action) {
+ private WatchLimiter(long limit, LimitViolationAction action) {
statLimit = new WatchLimit(limit, "create/delete", action);
dataLimit = new WatchLimit(limit, "data", action);
childrenLimit = new WatchLimit(limit, "children", action);
@@ -230,9 +240,9 @@ public class ZkTestServer {
}
public String reportLimitViolations() {
- return statLimit.reportLimitViolations() +
- dataLimit.reportLimitViolations() +
- childrenLimit.reportLimitViolations();
+ return statLimit.reportLimitViolations()
+ + dataLimit.reportLimitViolations()
+ + childrenLimit.reportLimitViolations();
}
private void updateForFire(WatchedEvent event) {
@@ -269,19 +279,22 @@ public class ZkTestServer {
}
@Override
- public Stat statNode(String path, ServerCnxn serverCnxn) throws KeeperException.NoNodeException {
+ public Stat statNode(String path, ServerCnxn serverCnxn)
+ throws KeeperException.NoNodeException {
limiter.statLimit.updateForWatch(path, serverCnxn);
return super.statNode(path, serverCnxn);
}
@Override
- public byte[] getData(String path, Stat stat, Watcher watcher) throws KeeperException.NoNodeException {
+ public byte[] getData(String path, Stat stat, Watcher watcher)
+ throws KeeperException.NoNodeException {
limiter.dataLimit.updateForWatch(path, watcher);
return super.getData(path, stat, watcher);
}
@Override
- public List<String> getChildren(String path, Stat stat, Watcher watcher) throws KeeperException.NoNodeException {
+ public List<String> getChildren(String path, Stat stat, Watcher watcher)
+ throws KeeperException.NoNodeException {
limiter.childrenLimit.updateForWatch(path, watcher);
return super.getChildren(path, stat, watcher);
}
@@ -289,6 +302,7 @@ public class ZkTestServer {
/**
* Run from a ServerConfig.
+ *
* @param config ServerConfig to use.
* @throws IOException If there is a low-level I/O error.
*/
@@ -299,21 +313,26 @@ public class ZkTestServer {
// ZooKeeper maintains a static collection of AuthenticationProviders, so
// we make sure the SASL provider is loaded so that it can be used in
// subsequent tests.
- System.setProperty("zookeeper.authProvider.1",
- "org.apache.zookeeper.server.auth.SASLAuthenticationProvider");
+ System.setProperty(
+ "zookeeper.authProvider.1",
+ "org.apache.zookeeper.server.auth.SASLAuthenticationProvider");
// Note that this thread isn't going to be doing anything else,
// so rather than spawning another thread, we will just call
// run() in this thread.
// create a file logger url from the command line args
FileTxnSnapLog ftxn = new FileTxnSnapLog(config.getDataLogDir(), config.getDataDir());
- zooKeeperServer = new ZooKeeperServer(ftxn, config.getTickTime(),
- config.getMinSessionTimeout(), config.getMaxSessionTimeout(),
- config.getClientPortListenBacklog(),
- new TestZKDatabase(ftxn, limiter), "");
+ zooKeeperServer =
+ new ZooKeeperServer(
+ ftxn,
+ config.getTickTime(),
+ config.getMinSessionTimeout(),
+ config.getMaxSessionTimeout(),
+ config.getClientPortListenBacklog(),
+ new TestZKDatabase(ftxn, limiter),
+ "");
cnxnFactory = new NIOServerCnxnFactory();
- cnxnFactory.configure(config.getClientPortAddress(),
- config.getMaxClientCnxns());
+ cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns());
cnxnFactory.startup(zooKeeperServer);
cnxnFactory.join();
@@ -334,6 +353,7 @@ public class ZkTestServer {
/**
* Shutdown the serving instance
+ *
* @throws IOException If there is a low-level I/O error.
*/
protected void shutdown() throws IOException {
@@ -447,6 +467,7 @@ public class ZkTestServer {
/**
* Get a connection string for this server with a given chroot
+ *
* @param chroot the chroot
* @return the connection string
*/
@@ -459,6 +480,7 @@ public class ZkTestServer {
/**
* Check that a path exists in this server
+ *
* @param path the path to check
* @throws IOException if an IO exception occurs
*/
@@ -476,22 +498,23 @@ public class ZkTestServer {
}
public void expire(final long sessionId) {
- zkServer.zooKeeperServer.expire(new Session() {
- @Override
- public long getSessionId() {
- return sessionId;
- }
+ zkServer.zooKeeperServer.expire(
+ new Session() {
+ @Override
+ public long getSessionId() {
+ return sessionId;
+ }
- @Override
- public int getTimeout() {
- return 4000;
- }
+ @Override
+ public int getTimeout() {
+ return 4000;
+ }
- @Override
- public boolean isClosing() {
- return false;
- }
- });
+ @Override
+ public boolean isClosing() {
+ return false;
+ }
+ });
}
public ZKDatabase getZKDatabase() {
@@ -516,43 +539,47 @@ public class ZkTestServer {
}
Thread parentThread = Thread.currentThread();
// we don't call super.distribSetUp
- zooThread = new Thread("ZkTestServer Run Thread") {
-
- @Override
- public void run() {
- ServerConfig config = new ServerConfig() {
-
- {
- setClientPort(ZkTestServer.this.clientPort);
- this.dataDir = zkDir.toFile();
- this.dataLogDir = zkDir.toFile();
- this.tickTime = theTickTime;
- this.maxSessionTimeout = ZkTestServer.this.maxSessionTimeout;
- this.minSessionTimeout = ZkTestServer.this.minSessionTimeout;
- }
-
- public void setClientPort(int clientPort) {
- if (clientPortAddress != null) {
- try {
- this.clientPortAddress = new InetSocketAddress(
- InetAddress.getByName(clientPortAddress.getHostName()), clientPort);
- } catch (UnknownHostException e) {
- throw new RuntimeException(e);
- }
- } else {
- this.clientPortAddress = new InetSocketAddress(clientPort);
+ zooThread =
+ new Thread("ZkTestServer Run Thread") {
+
+ @Override
+ public void run() {
+ ServerConfig config =
+ new ServerConfig() {
+
+ {
+ setClientPort(ZkTestServer.this.clientPort);
+ this.dataDir = zkDir.toFile();
+ this.dataLogDir = zkDir.toFile();
+ this.tickTime = theTickTime;
+ this.maxSessionTimeout = ZkTestServer.this.maxSessionTimeout;
+ this.minSessionTimeout = ZkTestServer.this.minSessionTimeout;
+ }
+
+ public void setClientPort(int clientPort) {
+ if (clientPortAddress != null) {
+ try {
+ this.clientPortAddress =
+ new InetSocketAddress(
+ InetAddress.getByName(clientPortAddress.getHostName()),
+ clientPort);
+ } catch (UnknownHostException e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ this.clientPortAddress = new InetSocketAddress(clientPort);
+ }
+ log.info("client port: {}", this.clientPortAddress);
+ }
+ };
+ try {
+ zkServer.runFromConfig(config);
+ } catch (Throwable t) {
+ zooError.set(t);
+ parentThread.interrupt();
}
- log.info("client port: {}", this.clientPortAddress);
}
};
- try {
- zkServer.runFromConfig(config);
- } catch (Throwable t) {
- zooError.set(t);
- parentThread.interrupt();
- }
- }
- };
ObjectReleaseTracker.track(zooThread);
zooThread.start();
@@ -605,7 +632,7 @@ public class ZkTestServer {
try {
zkServer.shutdown();
} catch (Exception e) {
- log.error("Exception shutting down ZooKeeper Test Server",e);
+ log.error("Exception shutting down ZooKeeper Test Server", e);
}
if (zkDb != null) {
@@ -689,15 +716,13 @@ public class ZkTestServer {
/**
* Send the 4letterword
+ *
* @param host the destination host
* @param port the destination port
* @param cmd the 4letterword
* @return server response
-
*/
- public static String send4LetterWord(String host, int port, String cmd)
- throws IOException
- {
+ public static String send4LetterWord(String host, int port, String cmd) throws IOException {
log.info("connecting to {} {}", host, port);
BufferedReader reader = null;
try (Socket sock = new Socket(host, port)) {
@@ -707,8 +732,9 @@ public class ZkTestServer {
// this replicates NC - close the output stream before reading
sock.shutdownOutput();
- reader = new BufferedReader(
- new InputStreamReader(sock.getInputStream(), StandardCharsets.US_ASCII));
+ reader =
+ new BufferedReader(
+ new InputStreamReader(sock.getInputStream(), StandardCharsets.US_ASCII));
StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
@@ -775,24 +801,29 @@ public class ZkTestServer {
this.minSessionTimeout = minSessionTimeout;
}
- void buildZooKeeper(String config,
- String schema) throws Exception {
+ void buildZooKeeper(String config, String schema) throws Exception {
buildZooKeeper(SOLRHOME, config, schema);
}
- public static void putConfig(String confName, SolrZkClient zkClient, Path solrhome, final String name)
- throws Exception {
+ public static void putConfig(
+ String confName, SolrZkClient zkClient, Path solrhome, final String name) throws Exception {
putConfig(confName, zkClient, null, solrhome, name, name);
}
-
- public static void putConfig(String confName, SolrZkClient zkClient, Path solrhome, final String srcName,
- String destName) throws Exception {
- putConfig(confName, zkClient, null, solrhome, srcName, destName);
+ public static void putConfig(
+ String confName, SolrZkClient zkClient, Path solrhome, final String srcName, String destName)
+ throws Exception {
+ putConfig(confName, zkClient, null, solrhome, srcName, destName);
}
- public static void putConfig(String confName, SolrZkClient zkClient, String zkChroot, Path solrhome,
- final String srcName, String destName) throws Exception {
+ public static void putConfig(
+ String confName,
+ SolrZkClient zkClient,
+ String zkChroot,
+ Path solrhome,
+ final String srcName,
+ String destName)
+ throws Exception {
Path file = solrhome.resolve("collection1").resolve("conf").resolve(srcName);
if (!Files.exists(file)) {
if (log.isInfoEnabled()) {
@@ -814,26 +845,45 @@ public class ZkTestServer {
// static to share with distrib test
public void buildZooKeeper(Path solrhome, String config, String schema) throws Exception {
- Map<String,Object> props = new HashMap<>();
+ Map<String, Object> props = new HashMap<>();
props.put("configName", "conf1");
final ZkNodeProps zkProps = new ZkNodeProps(props);
-
List<Op> ops = new ArrayList<>(2);
String path = "/collections";
- ops.add(Op.create(path, null, chRootClient.getZkACLProvider().getACLsToAdd(path), CreateMode.PERSISTENT));
+ ops.add(
+ Op.create(
+ path, null, chRootClient.getZkACLProvider().getACLsToAdd(path), CreateMode.PERSISTENT));
path = "/collections/collection1";
- ops.add(Op.create(path, Utils.toJSON(zkProps), chRootClient.getZkACLProvider().getACLsToAdd(path), CreateMode.PERSISTENT));
+ ops.add(
+ Op.create(
+ path,
+ Utils.toJSON(zkProps),
+ chRootClient.getZkACLProvider().getACLsToAdd(path),
+ CreateMode.PERSISTENT));
path = "/collections/collection1/shards";
- ops.add(Op.create(path, null, chRootClient.getZkACLProvider().getACLsToAdd(path), CreateMode.PERSISTENT));
+ ops.add(
+ Op.create(
+ path, null, chRootClient.getZkACLProvider().getACLsToAdd(path), CreateMode.PERSISTENT));
path = "/collections/control_collection";
- ops.add(Op.create(path, Utils.toJSON(zkProps), chRootClient.getZkACLProvider().getACLsToAdd(path), CreateMode.PERSISTENT));
+ ops.add(
+ Op.create(
+ path,
+ Utils.toJSON(zkProps),
+ chRootClient.getZkACLProvider().getACLsToAdd(path),
+ CreateMode.PERSISTENT));
path = "/collections/control_collection/shards";
- ops.add(Op.create(path, null, chRootClient.getZkACLProvider().getACLsToAdd(path), CreateMode.PERSISTENT));
+ ops.add(
+ Op.create(
+ path, null, chRootClient.getZkACLProvider().getACLsToAdd(path), CreateMode.PERSISTENT));
path = "/configs";
- ops.add(Op.create(path, null, chRootClient.getZkACLProvider().getACLsToAdd(path), CreateMode.PERSISTENT));
+ ops.add(
+ Op.create(
+ path, null, chRootClient.getZkACLProvider().getACLsToAdd(path), CreateMode.PERSISTENT));
path = "/configs/conf1";
- ops.add(Op.create(path, null, chRootClient.getZkACLProvider().getACLsToAdd(path), CreateMode.PERSISTENT));
+ ops.add(
+ Op.create(
+ path, null, chRootClient.getZkACLProvider().getACLsToAdd(path), CreateMode.PERSISTENT));
chRootClient.multi(ops, true);
// for now, always upload the config and schema to the canonical names
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractBackupRepositoryTest.java b/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractBackupRepositoryTest.java
index dc5be1f8aec..9620fe9231c 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractBackupRepositoryTest.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractBackupRepositoryTest.java
@@ -18,6 +18,11 @@
package org.apache.solr.cloud.api.collections;
import com.google.common.collect.Lists;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.List;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
import org.apache.solr.SolrTestCaseJ4;
@@ -26,228 +31,227 @@ import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.backup.repository.BackupRepository;
import org.junit.Test;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.List;
-
public abstract class AbstractBackupRepositoryTest extends SolrTestCaseJ4 {
- private static final boolean IGNORE_NONEXISTENT = true;
- private static final boolean REPORT_NONEXISTENT = false;
+ private static final boolean IGNORE_NONEXISTENT = true;
+ private static final boolean REPORT_NONEXISTENT = false;
- protected abstract BackupRepository getRepository();
+ protected abstract BackupRepository getRepository();
- protected abstract URI getBaseUri() throws URISyntaxException;
+ protected abstract URI getBaseUri() throws URISyntaxException;
- /**
- * Provide a base {@link BackupRepository} configuration for use by any tests that call {@link BackupRepository#init(NamedList)} explicitly.
- *
- * Useful for setting configuration properties required for specific BackupRepository implementations.
- */
- protected NamedList<Object> getBaseBackupRepositoryConfiguration() {
- return new NamedList<>();
- }
+ /**
+ * Provide a base {@link BackupRepository} configuration for use by any tests that call {@link
+ * BackupRepository#init(NamedList)} explicitly.
+ *
+ * <p>Useful for setting configuration properties required for specific BackupRepository
+ * implementations.
+ */
+ protected NamedList<Object> getBaseBackupRepositoryConfiguration() {
+ return new NamedList<>();
+ }
- @Test
- public void testCanReadProvidedConfigValues() throws Exception {
- final NamedList<Object> config = getBaseBackupRepositoryConfiguration();
- config.add("configKey1", "configVal1");
- config.add("configKey2", "configVal2");
- config.add("location", "foo");
- try (BackupRepository repo = getRepository()) {
- repo.init(config);
- assertEquals("configVal1", repo.getConfigProperty("configKey1"));
- assertEquals("configVal2", repo.getConfigProperty("configKey2"));
- }
+ @Test
+ public void testCanReadProvidedConfigValues() throws Exception {
+ final NamedList<Object> config = getBaseBackupRepositoryConfiguration();
+ config.add("configKey1", "configVal1");
+ config.add("configKey2", "configVal2");
+ config.add("location", "foo");
+ try (BackupRepository repo = getRepository()) {
+ repo.init(config);
+ assertEquals("configVal1", repo.getConfigProperty("configKey1"));
+ assertEquals("configVal2", repo.getConfigProperty("configKey2"));
}
+ }
- @Test
- public void testCanChooseDefaultOrOverrideLocationValue() throws Exception {
- final NamedList<Object> config = getBaseBackupRepositoryConfiguration();
- config.add(CoreAdminParams.BACKUP_LOCATION, "someLocation");
- try (BackupRepository repo = getRepository()) {
- repo.init(config);
- assertEquals("someLocation", repo.getBackupLocation(null));
- assertEquals("someOverridingLocation", repo.getBackupLocation("someOverridingLocation"));
- }
+ @Test
+ public void testCanChooseDefaultOrOverrideLocationValue() throws Exception {
+ final NamedList<Object> config = getBaseBackupRepositoryConfiguration();
+ config.add(CoreAdminParams.BACKUP_LOCATION, "someLocation");
+ try (BackupRepository repo = getRepository()) {
+ repo.init(config);
+ assertEquals("someLocation", repo.getBackupLocation(null));
+ assertEquals("someOverridingLocation", repo.getBackupLocation("someOverridingLocation"));
}
+ }
+
+ @Test
+ public void testCanDetermineWhetherFilesAndDirectoriesExist() throws Exception {
+ try (BackupRepository repo = getRepository()) {
+ // Create 'emptyDir/', 'nonEmptyDir/', and 'nonEmptyDir/file.txt'
+ final URI emptyDirUri = repo.resolve(getBaseUri(), "emptyDir");
+ final URI nonEmptyDirUri = repo.resolve(getBaseUri(), "nonEmptyDir");
+ final URI nestedFileUri = repo.resolve(nonEmptyDirUri, "file.txt");
+ repo.createDirectory(emptyDirUri);
+ repo.createDirectory(nonEmptyDirUri);
+ addFile(repo, nestedFileUri);
- @Test
- public void testCanDetermineWhetherFilesAndDirectoriesExist() throws Exception {
- try (BackupRepository repo = getRepository()) {
- // Create 'emptyDir/', 'nonEmptyDir/', and 'nonEmptyDir/file.txt'
- final URI emptyDirUri = repo.resolve(getBaseUri(), "emptyDir");
- final URI nonEmptyDirUri = repo.resolve(getBaseUri(), "nonEmptyDir");
- final URI nestedFileUri = repo.resolve(nonEmptyDirUri, "file.txt");
- repo.createDirectory(emptyDirUri);
- repo.createDirectory(nonEmptyDirUri);
- addFile(repo, nestedFileUri);
-
- assertTrue(repo.exists(emptyDirUri));
- assertTrue(repo.exists(nonEmptyDirUri));
- assertTrue(repo.exists(nestedFileUri));
- final URI nonexistedDirUri = repo.resolve(getBaseUri(), "nonexistentDir");
- assertFalse(repo.exists(nonexistedDirUri));
- }
+ assertTrue(repo.exists(emptyDirUri));
+ assertTrue(repo.exists(nonEmptyDirUri));
+ assertTrue(repo.exists(nestedFileUri));
+ final URI nonexistedDirUri = repo.resolve(getBaseUri(), "nonexistentDir");
+ assertFalse(repo.exists(nonexistedDirUri));
}
+ }
+
+ @Test
+ public void testCanDistinguishBetweenFilesAndDirectories() throws Exception {
+ try (BackupRepository repo = getRepository()) {
+ final URI emptyDirUri = repo.resolve(getBaseUri(), "emptyDir");
+ final URI nonEmptyDirUri = repo.resolve(getBaseUri(), "nonEmptyDir");
+ final URI nestedFileUri = repo.resolve(nonEmptyDirUri, "file.txt");
+ repo.createDirectory(emptyDirUri);
+ repo.createDirectory(nonEmptyDirUri);
+ addFile(repo, nestedFileUri);
- @Test
- public void testCanDistinguishBetweenFilesAndDirectories() throws Exception {
- try (BackupRepository repo = getRepository()) {
- final URI emptyDirUri = repo.resolve(getBaseUri(), "emptyDir");
- final URI nonEmptyDirUri = repo.resolve(getBaseUri(), "nonEmptyDir");
- final URI nestedFileUri = repo.resolve(nonEmptyDirUri, "file.txt");
- repo.createDirectory(emptyDirUri);
- repo.createDirectory(nonEmptyDirUri);
- addFile(repo, nestedFileUri);
-
- assertEquals(BackupRepository.PathType.DIRECTORY, repo.getPathType(emptyDirUri));
- assertEquals(BackupRepository.PathType.DIRECTORY, repo.getPathType(nonEmptyDirUri));
- assertEquals(BackupRepository.PathType.FILE, repo.getPathType(nestedFileUri));
- }
+ assertEquals(BackupRepository.PathType.DIRECTORY, repo.getPathType(emptyDirUri));
+ assertEquals(BackupRepository.PathType.DIRECTORY, repo.getPathType(nonEmptyDirUri));
+ assertEquals(BackupRepository.PathType.FILE, repo.getPathType(nestedFileUri));
}
+ }
- @Test
- public void testArbitraryFileDataCanBeStoredAndRetrieved() throws Exception {
- // create a BR
- // store some binary data in a file
- // retrieve that binary data
- // validate that sent == retrieved
- try (BackupRepository repo = getRepository()) {
- final URI fileUri = repo.resolve(getBaseUri(), "file.txt");
- final byte[] storedBytes = new byte[] {'h', 'e', 'l', 'l', 'o'};
- try (final OutputStream os = repo.createOutput(fileUri)) {
- os.write(storedBytes);
- }
-
- final int expectedNumBytes = storedBytes.length;
- final byte[] retrievedBytes = new byte[expectedNumBytes];
- try (final IndexInput is = repo.openInput(getBaseUri(), "file.txt", new IOContext(IOContext.Context.READ))) {
- assertEquals(expectedNumBytes, is.length());
- is.readBytes(retrievedBytes, 0, expectedNumBytes);
- }
- assertArrayEquals(storedBytes, retrievedBytes);
- }
+ @Test
+ public void testArbitraryFileDataCanBeStoredAndRetrieved() throws Exception {
+ // create a BR
+ // store some binary data in a file
+ // retrieve that binary data
+ // validate that sent == retrieved
+ try (BackupRepository repo = getRepository()) {
+ final URI fileUri = repo.resolve(getBaseUri(), "file.txt");
+ final byte[] storedBytes = new byte[] {'h', 'e', 'l', 'l', 'o'};
+ try (final OutputStream os = repo.createOutput(fileUri)) {
+ os.write(storedBytes);
+ }
+
+ final int expectedNumBytes = storedBytes.length;
+ final byte[] retrievedBytes = new byte[expectedNumBytes];
+ try (final IndexInput is =
+ repo.openInput(getBaseUri(), "file.txt", new IOContext(IOContext.Context.READ))) {
+ assertEquals(expectedNumBytes, is.length());
+ is.readBytes(retrievedBytes, 0, expectedNumBytes);
+ }
+ assertArrayEquals(storedBytes, retrievedBytes);
}
+ }
+
+ // TODO JEGERLOW, create separate test for creation of nested directory when parent doesn't exist
+ @Test
+ public void testCanDeleteEmptyOrFullDirectories() throws Exception {
+ try (BackupRepository repo = getRepository()) {
+ // Test deletion of empty and full directories
+ final URI emptyDirUri = repo.resolve(getBaseUri(), "emptyDir");
+ final URI nonEmptyDirUri = repo.resolve(getBaseUri(), "nonEmptyDir");
+ final URI fileUri = repo.resolve(nonEmptyDirUri, "file.txt");
+ repo.createDirectory(emptyDirUri);
+ repo.createDirectory(nonEmptyDirUri);
+ addFile(repo, fileUri);
+ repo.deleteDirectory(emptyDirUri);
+ repo.deleteDirectory(nonEmptyDirUri);
+ assertFalse(repo.exists(emptyDirUri));
+ assertFalse(repo.exists(nonEmptyDirUri));
+ assertFalse(repo.exists(fileUri));
- // TODO JEGERLOW, create separate test for creation of nested directory when parent doesn't exist
- @Test
- public void testCanDeleteEmptyOrFullDirectories() throws Exception {
- try (BackupRepository repo = getRepository()) {
- // Test deletion of empty and full directories
- final URI emptyDirUri = repo.resolve(getBaseUri(), "emptyDir");
- final URI nonEmptyDirUri = repo.resolve(getBaseUri(), "nonEmptyDir");
- final URI fileUri = repo.resolve(nonEmptyDirUri, "file.txt");
- repo.createDirectory(emptyDirUri);
- repo.createDirectory(nonEmptyDirUri);
- addFile(repo, fileUri);
- repo.deleteDirectory(emptyDirUri);
- repo.deleteDirectory(nonEmptyDirUri);
- assertFalse(repo.exists(emptyDirUri));
- assertFalse(repo.exists(nonEmptyDirUri));
- assertFalse(repo.exists(fileUri));
-
- // Delete the middle directory in a deeply nested structure (/nest1/nest2/nest3/nest4)
- final URI level1DeeplyNestedUri = repo.resolve(getBaseUri(), "nest1");
- final URI level2DeeplyNestedUri = repo.resolve(level1DeeplyNestedUri, "nest2");
- final URI level3DeeplyNestedUri = repo.resolve(level2DeeplyNestedUri, "nest3");
- final URI level4DeeplyNestedUri = repo.resolve(level3DeeplyNestedUri, "nest4");
- repo.createDirectory(level1DeeplyNestedUri);
- repo.createDirectory(level2DeeplyNestedUri);
- repo.createDirectory(level3DeeplyNestedUri);
- repo.createDirectory(level4DeeplyNestedUri);
- repo.deleteDirectory(level3DeeplyNestedUri);
- assertTrue(repo.exists(level1DeeplyNestedUri));
- assertTrue(repo.exists(level2DeeplyNestedUri));
- assertFalse(repo.exists(level3DeeplyNestedUri));
- assertFalse(repo.exists(level4DeeplyNestedUri));
- }
+ // Delete the middle directory in a deeply nested structure (/nest1/nest2/nest3/nest4)
+ final URI level1DeeplyNestedUri = repo.resolve(getBaseUri(), "nest1");
+ final URI level2DeeplyNestedUri = repo.resolve(level1DeeplyNestedUri, "nest2");
+ final URI level3DeeplyNestedUri = repo.resolve(level2DeeplyNestedUri, "nest3");
+ final URI level4DeeplyNestedUri = repo.resolve(level3DeeplyNestedUri, "nest4");
+ repo.createDirectory(level1DeeplyNestedUri);
+ repo.createDirectory(level2DeeplyNestedUri);
+ repo.createDirectory(level3DeeplyNestedUri);
+ repo.createDirectory(level4DeeplyNestedUri);
+ repo.deleteDirectory(level3DeeplyNestedUri);
+ assertTrue(repo.exists(level1DeeplyNestedUri));
+ assertTrue(repo.exists(level2DeeplyNestedUri));
+ assertFalse(repo.exists(level3DeeplyNestedUri));
+ assertFalse(repo.exists(level4DeeplyNestedUri));
}
+ }
- @Test
- public void testDirectoryCreationFailsIfParentDoesntExist() throws Exception {
- try (BackupRepository repo = getRepository()) {
- final URI nonExistentParentUri = repo.resolve(getBaseUri(), "nonExistentParent");
- final URI nestedUri = repo.resolve(nonExistentParentUri, "childDirectoryToCreate");
+ @Test
+ public void testDirectoryCreationFailsIfParentDoesntExist() throws Exception {
+ try (BackupRepository repo = getRepository()) {
+ final URI nonExistentParentUri = repo.resolve(getBaseUri(), "nonExistentParent");
+ final URI nestedUri = repo.resolve(nonExistentParentUri, "childDirectoryToCreate");
- repo.createDirectory(nestedUri);
- }
+ repo.createDirectory(nestedUri);
}
+ }
- @Test
- public void testCanDeleteIndividualFiles() throws Exception {
- try (BackupRepository repo = getRepository()) {
- final URI file1Uri = repo.resolve(getBaseUri(), "file1.txt");
- final URI file2Uri = repo.resolve(getBaseUri(), "file2.txt");
- final URI file3Uri = repo.resolve(getBaseUri(), "file3.txt");
- addFile(repo, file1Uri);
- addFile(repo, file2Uri);
- addFile(repo, file3Uri);
-
- // Ensure nonexistent files are handled differently based on boolean flag param
- final URI nonexistentFileUri = repo.resolve(getBaseUri(), "file4.txt");
- assertFalse(repo.exists(nonexistentFileUri));
- repo.delete(getBaseUri(), Lists.newArrayList("file4.txt"), IGNORE_NONEXISTENT);
- expectThrows(IOException.class, () -> {
- repo.delete(getBaseUri(), Lists.newArrayList("file4.txt"), REPORT_NONEXISTENT);
- });
-
- // Delete existing files individually and in 'bulk'
- repo.delete(getBaseUri(), Lists.newArrayList("file1.txt"), REPORT_NONEXISTENT);
- repo.delete(getBaseUri(), Lists.newArrayList("file2.txt", "file3.txt"), REPORT_NONEXISTENT);
- assertFalse(repo.exists(file1Uri));
- assertFalse(repo.exists(file2Uri));
- assertFalse(repo.exists(file3Uri));
- }
+ @Test
+ public void testCanDeleteIndividualFiles() throws Exception {
+ try (BackupRepository repo = getRepository()) {
+ final URI file1Uri = repo.resolve(getBaseUri(), "file1.txt");
+ final URI file2Uri = repo.resolve(getBaseUri(), "file2.txt");
+ final URI file3Uri = repo.resolve(getBaseUri(), "file3.txt");
+ addFile(repo, file1Uri);
+ addFile(repo, file2Uri);
+ addFile(repo, file3Uri);
+
+ // Ensure nonexistent files are handled differently based on boolean flag param
+ final URI nonexistentFileUri = repo.resolve(getBaseUri(), "file4.txt");
+ assertFalse(repo.exists(nonexistentFileUri));
+ repo.delete(getBaseUri(), Lists.newArrayList("file4.txt"), IGNORE_NONEXISTENT);
+ expectThrows(
+ IOException.class,
+ () -> {
+ repo.delete(getBaseUri(), Lists.newArrayList("file4.txt"), REPORT_NONEXISTENT);
+ });
+
+ // Delete existing files individually and in 'bulk'
+ repo.delete(getBaseUri(), Lists.newArrayList("file1.txt"), REPORT_NONEXISTENT);
+ repo.delete(getBaseUri(), Lists.newArrayList("file2.txt", "file3.txt"), REPORT_NONEXISTENT);
+ assertFalse(repo.exists(file1Uri));
+ assertFalse(repo.exists(file2Uri));
+ assertFalse(repo.exists(file3Uri));
}
+ }
+
+ @Test
+ public void testCanListFullOrEmptyDirectories() throws Exception {
+ try (BackupRepository repo = getRepository()) {
+ final URI rootUri = repo.resolve(getBaseUri(), "containsOtherDirs");
+ final URI otherDir1Uri = repo.resolve(rootUri, "otherDir1");
+ final URI otherDir2Uri = repo.resolve(rootUri, "otherDir2");
+ final URI otherDir3Uri = repo.resolve(rootUri, "otherDir3");
+ final URI file1Uri = repo.resolve(otherDir3Uri, "file1.txt");
+ final URI file2Uri = repo.resolve(otherDir3Uri, "file2.txt");
+ repo.createDirectory(rootUri);
+ repo.createDirectory(otherDir1Uri);
+ repo.createDirectory(otherDir2Uri);
+ repo.createDirectory(otherDir3Uri);
+ addFile(repo, file1Uri);
+ addFile(repo, file2Uri);
+
+ final List<String> rootChildren = Lists.newArrayList(repo.listAll(rootUri));
+ assertEquals(3, rootChildren.size());
+ assertTrue(rootChildren.contains("otherDir1"));
+ assertTrue(rootChildren.contains("otherDir2"));
+ assertTrue(rootChildren.contains("otherDir3"));
+
+ final String[] otherDir2Children = repo.listAll(otherDir2Uri);
+ assertEquals(0, otherDir2Children.length);
- @Test
- public void testCanListFullOrEmptyDirectories() throws Exception {
- try (BackupRepository repo = getRepository()) {
- final URI rootUri = repo.resolve(getBaseUri(), "containsOtherDirs");
- final URI otherDir1Uri = repo.resolve(rootUri, "otherDir1");
- final URI otherDir2Uri = repo.resolve(rootUri, "otherDir2");
- final URI otherDir3Uri = repo.resolve(rootUri, "otherDir3");
- final URI file1Uri = repo.resolve(otherDir3Uri, "file1.txt");
- final URI file2Uri = repo.resolve(otherDir3Uri, "file2.txt");
- repo.createDirectory(rootUri);
- repo.createDirectory(otherDir1Uri);
- repo.createDirectory(otherDir2Uri);
- repo.createDirectory(otherDir3Uri);
- addFile(repo, file1Uri);
- addFile(repo, file2Uri);
-
- final List<String> rootChildren = Lists.newArrayList(repo.listAll(rootUri));
- assertEquals(3, rootChildren.size());
- assertTrue(rootChildren.contains("otherDir1"));
- assertTrue(rootChildren.contains("otherDir2"));
- assertTrue(rootChildren.contains("otherDir3"));
-
- final String[] otherDir2Children = repo.listAll(otherDir2Uri);
- assertEquals(0, otherDir2Children.length);
-
- final List<String> otherDir3Children = Lists.newArrayList(repo.listAll(otherDir3Uri));
- assertEquals(2, otherDir3Children.size());
- assertTrue(otherDir3Children.contains("file1.txt"));
- assertTrue(otherDir3Children.contains("file2.txt"));
- }
+ final List<String> otherDir3Children = Lists.newArrayList(repo.listAll(otherDir3Uri));
+ assertEquals(2, otherDir3Children.size());
+ assertTrue(otherDir3Children.contains("file1.txt"));
+ assertTrue(otherDir3Children.contains("file2.txt"));
}
+ }
- @Test
- public void testDirectoryExistsWithDirectoryUri() throws Exception {
- try (BackupRepository repo = getRepository()) {
- repo.createDirectory(getBaseUri());
- assertTrue(repo.exists(repo.createDirectoryURI(getBaseUri().toString())));
- }
+ @Test
+ public void testDirectoryExistsWithDirectoryUri() throws Exception {
+ try (BackupRepository repo = getRepository()) {
+ repo.createDirectory(getBaseUri());
+ assertTrue(repo.exists(repo.createDirectoryURI(getBaseUri().toString())));
}
+ }
- private void addFile(BackupRepository repo, URI file) throws IOException {
- try (OutputStream os = repo.createOutput(file)) {
- os.write(100);
- os.write(101);
- os.write(102);
- }
+ private void addFile(BackupRepository repo, URI file) throws IOException {
+ try (OutputStream os = repo.createOutput(file)) {
+ os.write(100);
+ os.write(101);
+ os.write(102);
}
+ }
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCloudBackupRestoreTestCase.java b/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCloudBackupRestoreTestCase.java
index 357531aa1ad..615ecebdc63 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCloudBackupRestoreTestCase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCloudBackupRestoreTestCase.java
@@ -16,6 +16,18 @@
*/
package org.apache.solr.cloud.api.collections;
+import static org.hamcrest.CoreMatchers.hasItem;
+import static org.hamcrest.CoreMatchers.not;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Random;
+import java.util.TreeMap;
import org.apache.lucene.util.TestUtil;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
@@ -40,29 +52,18 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.lang.invoke.MethodHandles;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Random;
-import java.util.TreeMap;
-
-import static org.hamcrest.CoreMatchers.hasItem;
-import static org.hamcrest.CoreMatchers.not;
-
/**
* Used to test the traditional (now deprecated) 'full-snapshot' method of backup/restoration.
*
- * For a similar test harness for incremental backup/restoration see {@link AbstractIncrementalBackupTest}
+ * <p>For a similar test harness for incremental backup/restoration see {@link
+ * AbstractIncrementalBackupTest}
*/
public abstract class AbstractCloudBackupRestoreTestCase extends SolrCloudTestCase {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- protected static final int NUM_SHARDS = 2;//granted we sometimes shard split to get more
- protected static final int NUM_SPLIT_SHARDS = 3; //We always split shard1 so total shards post split will be 3
+ protected static final int NUM_SHARDS = 2; // granted we sometimes shard split to get more
+ protected static final int NUM_SPLIT_SHARDS =
+ 3; // We always split shard1 so total shards post split will be 3
protected static final String BACKUPNAME_PREFIX = "mytestbackup";
int replFactor;
@@ -94,13 +95,11 @@ public abstract class AbstractCloudBackupRestoreTestCase extends SolrCloudTestCa
public abstract String getBackupRepoName();
/**
- * @return The absolute path for the backup location.
- * Could return null.
+ * @return The absolute path for the backup location. Could return null.
*/
public abstract String getBackupLocation();
-
- public String getCollectionName(){
+ public String getCollectionName() {
return getCollectionNamePrefix() + "_" + testSuffix;
}
@@ -118,17 +117,31 @@ public abstract class AbstractCloudBackupRestoreTestCase extends SolrCloudTestCa
numPullReplicas = TestUtil.nextInt(random(), 0, 1);
int backupReplFactor = replFactor + numPullReplicas + numTlogReplicas;
- CollectionAdminRequest.Create create = isImplicit ?
- // NOTE: use shard list with same # of shards as NUM_SHARDS; we assume this later
- CollectionAdminRequest.createCollectionWithImplicitRouter(getCollectionName(), "conf1", "shard1,shard2", replFactor, numTlogReplicas, numPullReplicas) :
- CollectionAdminRequest.createCollection(getCollectionName(), "conf1", NUM_SHARDS, replFactor, numTlogReplicas, numPullReplicas);
+ CollectionAdminRequest.Create create =
+ isImplicit
+ ?
+ // NOTE: use shard list with same # of shards as NUM_SHARDS; we assume this later
+ CollectionAdminRequest.createCollectionWithImplicitRouter(
+ getCollectionName(),
+ "conf1",
+ "shard1,shard2",
+ replFactor,
+ numTlogReplicas,
+ numPullReplicas)
+ : CollectionAdminRequest.createCollection(
+ getCollectionName(),
+ "conf1",
+ NUM_SHARDS,
+ replFactor,
+ numTlogReplicas,
+ numPullReplicas);
Properties coreProps = new Properties();
- coreProps.put("customKey", "customValue");//just to assert it survives the restoration
+ coreProps.put("customKey", "customValue"); // just to assert it survives the restoration
create.setProperties(coreProps);
- if (isImplicit) { //implicit router
+ if (isImplicit) { // implicit router
create.setRouterField("shard_s");
- } else {//composite id router
+ } else { // composite id router
if (random().nextBoolean()) {
create.setRouterField("shard_s");
}
@@ -142,7 +155,8 @@ public abstract class AbstractCloudBackupRestoreTestCase extends SolrCloudTestCa
if (doSplitShardOperation) {
// shard split the first shard
int prevActiveSliceCount = getActiveSliceCount(getCollectionName());
- CollectionAdminRequest.SplitShard splitShard = CollectionAdminRequest.splitShard(getCollectionName());
+ CollectionAdminRequest.SplitShard splitShard =
+ CollectionAdminRequest.splitShard(getCollectionName());
splitShard.setShardName("shard1");
splitShard.process(solrClient);
// wait until we see one more active slice...
@@ -150,7 +164,8 @@ public abstract class AbstractCloudBackupRestoreTestCase extends SolrCloudTestCa
assertTrue(i < 30);
Thread.sleep(500);
}
- // issue a hard commit. Split shard does a soft commit which isn't good enough for the backup/snapshooter to see
+ // issue a hard commit. Split shard does a soft commit which isn't good enough for the
+ // backup/snapshooter to see
solrClient.commit(getCollectionName());
}
@@ -167,26 +182,28 @@ public abstract class AbstractCloudBackupRestoreTestCase extends SolrCloudTestCa
numPullReplicas = TestUtil.nextInt(random(), 0, 1);
CollectionAdminRequest.Create create =
- CollectionAdminRequest.createCollection(getCollectionName(), "conf1", NUM_SHARDS, replFactor, numTlogReplicas, numPullReplicas);
+ CollectionAdminRequest.createCollection(
+ getCollectionName(), "conf1", NUM_SHARDS, replFactor, numTlogReplicas, numPullReplicas);
CloudSolrClient solrClient = cluster.getSolrClient();
create.process(solrClient);
indexDocs(getCollectionName(), false);
-
String backupLocation = getBackupLocation();
String backupName = BACKUPNAME_PREFIX + testSuffix;
- DocCollection backupCollection = solrClient.getZkStateReader().getClusterState().getCollection(getCollectionName());
+ DocCollection backupCollection =
+ solrClient.getZkStateReader().getClusterState().getCollection(getCollectionName());
log.info("Triggering Backup command");
{
- CollectionAdminRequest.Backup backup = CollectionAdminRequest.backupCollection(getCollectionName(), backupName)
- .setLocation(backupLocation)
- .setIncremental(false)
- .setRepositoryName(getBackupRepoName());
+ CollectionAdminRequest.Backup backup =
+ CollectionAdminRequest.backupCollection(getCollectionName(), backupName)
+ .setLocation(backupLocation)
+ .setIncremental(false)
+ .setRepositoryName(getBackupRepoName());
assertEquals(0, backup.process(solrClient).getStatus());
}
@@ -195,33 +212,45 @@ public abstract class AbstractCloudBackupRestoreTestCase extends SolrCloudTestCa
String restoreCollectionName = getCollectionName() + "_restored";
{
- CollectionAdminRequest.Restore restore = CollectionAdminRequest.restoreCollection(restoreCollectionName, backupName)
- .setLocation(backupLocation)
- .setRepositoryName(getBackupRepoName());
+ CollectionAdminRequest.Restore restore =
+ CollectionAdminRequest.restoreCollection(restoreCollectionName, backupName)
+ .setLocation(backupLocation)
+ .setRepositoryName(getBackupRepoName());
restore.setConfigName("confFaulty");
assertEquals(RequestStatusState.FAILED, restore.processAndWait(solrClient, 30));
- assertThat("Failed collection is still in the clusterstate: " + cluster.getSolrClient().getClusterStateProvider().getClusterState().getCollectionOrNull(restoreCollectionName),
- CollectionAdminRequest.listCollections(solrClient), not(hasItem(restoreCollectionName)));
+ assertThat(
+ "Failed collection is still in the clusterstate: "
+ + cluster
+ .getSolrClient()
+ .getClusterStateProvider()
+ .getClusterState()
+ .getCollectionOrNull(restoreCollectionName),
+ CollectionAdminRequest.listCollections(solrClient),
+ not(hasItem(restoreCollectionName)));
}
}
/**
- * This test validates the backup of collection configuration using
- * {@linkplain CollectionAdminParams#NO_INDEX_BACKUP_STRATEGY}.
+ * This test validates the backup of collection configuration using {@linkplain
+ * CollectionAdminParams#NO_INDEX_BACKUP_STRATEGY}.
*
* @param configName The config name for the collection to be backed up.
* @param collectionName The name of the collection to be backed up.
* @throws Exception in case of errors.
*/
protected void testConfigBackupOnly(String configName, String collectionName) throws Exception {
- // This is deliberately no-op since we want to run this test only for one of the backup repository
- // implementation (mainly to avoid redundant test execution). Currently HDFS backup repository test
+ // This is deliberately no-op since we want to run this test only for one of the backup
+ // repository
+ // implementation (mainly to avoid redundant test execution). Currently HDFS backup repository
+ // test
// implements this.
}
- // This test verifies the system behavior when the backup location cluster property is configured with an invalid
- // value for the specified repository (and the default backup location is not configured in solr.xml).
+ // This test verifies the system behavior when the backup location cluster property is configured
+ // with an invalid
+ // value for the specified repository (and the default backup location is not configured in
+ // solr.xml).
private void testInvalidPath(String collectionName) throws Exception {
// Execute this test only if the default backup location is NOT configured in solr.xml
if (getBackupLocation() == null) {
@@ -231,37 +260,51 @@ public abstract class AbstractCloudBackupRestoreTestCase extends SolrCloudTestCa
String backupName = "invalidbackuprequest";
CloudSolrClient solrClient = cluster.getSolrClient();
- ClusterProp req = CollectionAdminRequest.setClusterProperty(CoreAdminParams.BACKUP_LOCATION, "/location/does/not/exist");
+ ClusterProp req =
+ CollectionAdminRequest.setClusterProperty(
+ CoreAdminParams.BACKUP_LOCATION, "/location/does/not/exist");
assertEquals(0, req.process(solrClient).getStatus());
// Do not specify the backup location.
- CollectionAdminRequest.Backup backup = CollectionAdminRequest.backupCollection(collectionName, backupName)
- .setIncremental(false)
- .setRepositoryName(getBackupRepoName());
+ CollectionAdminRequest.Backup backup =
+ CollectionAdminRequest.backupCollection(collectionName, backupName)
+ .setIncremental(false)
+ .setRepositoryName(getBackupRepoName());
try {
backup.process(solrClient);
- fail("This request should have failed since the cluster property value for backup location property is invalid.");
+ fail(
+ "This request should have failed since the cluster property value for backup location property is invalid.");
} catch (SolrException ex) {
assertEquals(ErrorCode.SERVER_ERROR.code, ex.code());
}
String restoreCollectionName = collectionName + "_invalidrequest";
- CollectionAdminRequest.Restore restore = CollectionAdminRequest.restoreCollection(restoreCollectionName, backupName)
- .setRepositoryName(getBackupRepoName());
+ CollectionAdminRequest.Restore restore =
+ CollectionAdminRequest.restoreCollection(restoreCollectionName, backupName)
+ .setRepositoryName(getBackupRepoName());
try {
restore.process(solrClient);
- fail("This request should have failed since the cluster property value for backup location property is invalid.");
+ fail(
+ "This request should have failed since the cluster property value for backup location property is invalid.");
} catch (SolrException ex) {
assertEquals(ErrorCode.SERVER_ERROR.code, ex.code());
}
}
private int getActiveSliceCount(String collectionName) {
- return cluster.getSolrClient().getZkStateReader().getClusterState().getCollection(collectionName).getActiveSlices().size();
+ return cluster
+ .getSolrClient()
+ .getZkStateReader()
+ .getClusterState()
+ .getCollection(collectionName)
+ .getActiveSlices()
+ .size();
}
private int indexDocs(String collectionName, boolean useUUID) throws Exception {
- Random random = new Random(docsSeed);// use a constant seed for the whole test run so that we can easily re-index.
+ Random random =
+ new Random(
+ docsSeed); // use a constant seed for the whole test run so that we can easily re-index.
int numDocs = random.nextInt(100);
if (numDocs == 0) {
log.info("Indexing ZERO test docs");
@@ -269,7 +312,7 @@ public abstract class AbstractCloudBackupRestoreTestCase extends SolrCloudTestCa
}
List<SolrInputDocument> docs = new ArrayList<>(numDocs);
- for (int i=0; i<numDocs; i++) {
+ for (int i = 0; i < numDocs; i++) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", ((useUUID == true) ? java.util.UUID.randomUUID().toString() : i));
doc.addField("shard_s", "shard" + (1 + random.nextInt(NUM_SHARDS))); // for implicit router
@@ -277,7 +320,7 @@ public abstract class AbstractCloudBackupRestoreTestCase extends SolrCloudTestCa
}
CloudSolrClient client = cluster.getSolrClient();
- client.add(collectionName, docs); //batch
+ client.add(collectionName, docs); // batch
client.commit(collectionName);
log.info("Indexed {} docs to collection: {}", numDocs, collectionName);
@@ -290,7 +333,8 @@ public abstract class AbstractCloudBackupRestoreTestCase extends SolrCloudTestCa
String backupName = BACKUPNAME_PREFIX + testSuffix;
CloudSolrClient client = cluster.getSolrClient();
- DocCollection backupCollection = client.getZkStateReader().getClusterState().getCollection(collectionName);
+ DocCollection backupCollection =
+ client.getZkStateReader().getClusterState().getCollection(collectionName);
Map<String, Integer> origShardToDocCount = getShardToDocCountMap(client, backupCollection);
assert origShardToDocCount.isEmpty() == false;
@@ -298,14 +342,15 @@ public abstract class AbstractCloudBackupRestoreTestCase extends SolrCloudTestCa
log.info("Triggering Backup command");
{
- CollectionAdminRequest.Backup backup = CollectionAdminRequest.backupCollection(collectionName, backupName)
- .setIncremental(false)
- .setLocation(backupLocation)
- .setRepositoryName(getBackupRepoName());
+ CollectionAdminRequest.Backup backup =
+ CollectionAdminRequest.backupCollection(collectionName, backupName)
+ .setIncremental(false)
+ .setLocation(backupLocation)
+ .setRepositoryName(getBackupRepoName());
if (random().nextBoolean()) {
assertEquals(0, backup.process(client).getStatus());
} else {
- assertEquals(RequestStatusState.COMPLETED, backup.processAndWait(client, 30));//async
+ assertEquals(RequestStatusState.COMPLETED, backup.processAndWait(client, 30)); // async
}
}
@@ -318,7 +363,7 @@ public abstract class AbstractCloudBackupRestoreTestCase extends SolrCloudTestCa
int restoreTlogReplicas = numTlogReplicas;
int restorePullReplicas = numPullReplicas;
boolean setExternalReplicationFactor = false;
- if (random().nextBoolean()) { //Override replicationFactor / tLogReplicas / pullReplicas
+ if (random().nextBoolean()) { // Override replicationFactor / tLogReplicas / pullReplicas
setExternalReplicationFactor = true;
restoreTlogReplicas = TestUtil.nextInt(random(), 0, 1);
restoreReplcationFactor = TestUtil.nextInt(random(), 1, 2);
@@ -328,12 +373,13 @@ public abstract class AbstractCloudBackupRestoreTestCase extends SolrCloudTestCa
int restoreReplFactor = restoreReplcationFactor + restoreTlogReplicas + restorePullReplicas;
- CollectionAdminRequest.Restore restore = CollectionAdminRequest.restoreCollection(restoreCollectionName, backupName)
- .setLocation(backupLocation)
- .setRepositoryName(getBackupRepoName());
+ CollectionAdminRequest.Restore restore =
+ CollectionAdminRequest.restoreCollection(restoreCollectionName, backupName)
+ .setLocation(backupLocation)
+ .setRepositoryName(getBackupRepoName());
- //explicitly specify the replicationFactor/pullReplicas/nrtReplicas/tlogReplicas.
- if (setExternalReplicationFactor) {
+ // explicitly specify the replicationFactor/pullReplicas/nrtReplicas/tlogReplicas.
+ if (setExternalReplicationFactor) {
restore.setReplicationFactor(restoreReplcationFactor);
restore.setTlogReplicas(restoreTlogReplicas);
restore.setPullReplicas(restorePullReplicas);
@@ -343,26 +389,33 @@ public abstract class AbstractCloudBackupRestoreTestCase extends SolrCloudTestCa
restore.setCreateNodeSet(cluster.getJettySolrRunners().get(0).getNodeName());
restoreNodeSetSize = 1;
}
- final int restoreMaxShardsPerNode = (int) Math.ceil((restoreReplFactor * numShards/(double) restoreNodeSetSize));
+ final int restoreMaxShardsPerNode =
+ (int) Math.ceil((restoreReplFactor * numShards / (double) restoreNodeSetSize));
Properties props = new Properties();
props.setProperty("customKey", "customVal");
restore.setProperties(props);
- if (sameConfig==false) {
+ if (sameConfig == false) {
restore.setConfigName("customConfigName");
}
if (random().nextBoolean()) {
assertEquals(0, restore.process(client).getStatus());
} else {
- assertEquals(RequestStatusState.COMPLETED, restore.processAndWait(client, 60));//async
+ assertEquals(RequestStatusState.COMPLETED, restore.processAndWait(client, 60)); // async
}
AbstractDistribZkTestBase.waitForRecoveriesToFinish(
- restoreCollectionName, cluster.getSolrClient().getZkStateReader(), log.isDebugEnabled(), true, 30);
-
- //Check the number of results are the same
- DocCollection restoreCollection = client.getZkStateReader().getClusterState().getCollection(restoreCollectionName);
+ restoreCollectionName,
+ cluster.getSolrClient().getZkStateReader(),
+ log.isDebugEnabled(),
+ true,
+ 30);
+
+ // Check the number of results are the same
+ DocCollection restoreCollection =
+ client.getZkStateReader().getClusterState().getCollection(restoreCollectionName);
assertEquals(origShardToDocCount, getShardToDocCountMap(client, restoreCollection));
- //Re-index same docs (should be identical docs given same random seed) and test we have the same result. Helps
+ // Re-index same docs (should be identical docs given same random seed) and test we have the
+ // same result. Helps
// test we reconstituted the hash ranges / doc router.
if (!(restoreCollection.getRouter() instanceof ImplicitDocRouter) && random().nextBoolean()) {
indexDocs(restoreCollectionName, false);
@@ -372,32 +425,68 @@ public abstract class AbstractCloudBackupRestoreTestCase extends SolrCloudTestCa
assertEquals(sameConfig ? "conf1" : "customConfigName", restoreCollection.getConfigName());
Map<String, Integer> numReplicasByNodeName = new HashMap<>();
- restoreCollection.getReplicas().forEach(x -> {
- numReplicasByNodeName.put(x.getNodeName(), numReplicasByNodeName.getOrDefault(x.getNodeName(), 0) + 1);
- });
- numReplicasByNodeName.forEach((k, v) -> {
- assertTrue("Node " + k + " has " + v + " replicas. Expected num replicas : " + restoreMaxShardsPerNode
- + ". state: \n" + restoreCollection, v <= restoreMaxShardsPerNode);
- });
-
- assertEquals(restoreCollection.toString(), restoreReplcationFactor, restoreCollection.getReplicationFactor().intValue());
- assertEquals(restoreCollection.toString(), restoreReplcationFactor, restoreCollection.getNumNrtReplicas().intValue());
- assertEquals(restoreCollection.toString(), restorePullReplicas, restoreCollection.getNumPullReplicas().intValue());
- assertEquals(restoreCollection.toString(), restoreTlogReplicas, restoreCollection.getNumTlogReplicas().intValue());
-
- //SOLR-12605: Add more docs after restore is complete to see if they are getting added fine
- //explicitly querying the leaders. If we use CloudSolrClient there is no guarantee that we'll hit a nrtReplica
+ restoreCollection
+ .getReplicas()
+ .forEach(
+ x -> {
+ numReplicasByNodeName.put(
+ x.getNodeName(), numReplicasByNodeName.getOrDefault(x.getNodeName(), 0) + 1);
+ });
+ numReplicasByNodeName.forEach(
+ (k, v) -> {
+ assertTrue(
+ "Node "
+ + k
+ + " has "
+ + v
+ + " replicas. Expected num replicas : "
+ + restoreMaxShardsPerNode
+ + ". state: \n"
+ + restoreCollection,
+ v <= restoreMaxShardsPerNode);
+ });
+
+ assertEquals(
+ restoreCollection.toString(),
+ restoreReplcationFactor,
+ restoreCollection.getReplicationFactor().intValue());
+ assertEquals(
+ restoreCollection.toString(),
+ restoreReplcationFactor,
+ restoreCollection.getNumNrtReplicas().intValue());
+ assertEquals(
+ restoreCollection.toString(),
+ restorePullReplicas,
+ restoreCollection.getNumPullReplicas().intValue());
+ assertEquals(
+ restoreCollection.toString(),
+ restoreTlogReplicas,
+ restoreCollection.getNumTlogReplicas().intValue());
+
+ // SOLR-12605: Add more docs after restore is complete to see if they are getting added fine
+ // explicitly querying the leaders. If we use CloudSolrClient there is no guarantee that we'll
+ // hit a nrtReplica
{
- Map<String, Integer> restoredCollectionPerShardCount = getShardToDocCountMap(client, restoreCollection);
- long restoredCollectionDocCount = restoredCollectionPerShardCount.values().stream().mapToInt(Number::intValue).sum();
+ Map<String, Integer> restoredCollectionPerShardCount =
+ getShardToDocCountMap(client, restoreCollection);
+ long restoredCollectionDocCount =
+ restoredCollectionPerShardCount.values().stream().mapToInt(Number::intValue).sum();
int numberNewDocsIndexed = indexDocs(restoreCollectionName, true);
- Map<String, Integer> restoredCollectionPerShardCountAfterIndexing = getShardToDocCountMap(client, restoreCollection);
- int restoredCollectionFinalDocCount = restoredCollectionPerShardCountAfterIndexing.values().stream().mapToInt(Number::intValue).sum();
-
- log.info("Original doc count in restored collection:{} , number of newly added documents to the restored collection: {}"
- + ", after indexing: {}"
- , restoredCollectionDocCount, numberNewDocsIndexed, restoredCollectionFinalDocCount);
- assertEquals((restoredCollectionDocCount + numberNewDocsIndexed), restoredCollectionFinalDocCount);
+ Map<String, Integer> restoredCollectionPerShardCountAfterIndexing =
+ getShardToDocCountMap(client, restoreCollection);
+ int restoredCollectionFinalDocCount =
+ restoredCollectionPerShardCountAfterIndexing.values().stream()
+ .mapToInt(Number::intValue)
+ .sum();
+
+ log.info(
+ "Original doc count in restored collection:{} , number of newly added documents to the restored collection: {}"
+ + ", after indexing: {}",
+ restoredCollectionDocCount,
+ numberNewDocsIndexed,
+ restoredCollectionFinalDocCount);
+ assertEquals(
+ (restoredCollectionDocCount + numberNewDocsIndexed), restoredCollectionFinalDocCount);
}
// assert added core properties:
@@ -405,13 +494,20 @@ public abstract class AbstractCloudBackupRestoreTestCase extends SolrCloudTestCa
// TODO Find the applicable core.properties on the file system but how?
}
- public static Map<String, Integer> getShardToDocCountMap(CloudSolrClient client, DocCollection docCollection) throws SolrServerException, IOException {
- Map<String,Integer> shardToDocCount = new TreeMap<>();
+ public static Map<String, Integer> getShardToDocCountMap(
+ CloudSolrClient client, DocCollection docCollection) throws SolrServerException, IOException {
+ Map<String, Integer> shardToDocCount = new TreeMap<>();
for (Slice slice : docCollection.getActiveSlices()) {
String shardName = slice.getName();
- try (HttpSolrClient leaderClient = new HttpSolrClient.Builder(slice.getLeader().getCoreUrl()).withHttpClient(client.getHttpClient()).build()) {
- long docsInShard = leaderClient.query(new SolrQuery("*:*").setParam("distrib", "false"))
- .getResults().getNumFound();
+ try (HttpSolrClient leaderClient =
+ new HttpSolrClient.Builder(slice.getLeader().getCoreUrl())
+ .withHttpClient(client.getHttpClient())
+ .build()) {
+ long docsInShard =
+ leaderClient
+ .query(new SolrQuery("*:*").setParam("distrib", "false"))
+ .getResults()
+ .getNumFound();
shardToDocCount.put(shardName, (int) docsInShard);
}
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCollectionsAPIDistributedZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCollectionsAPIDistributedZkTestBase.java
index c7307dd19c5..63d303c8647 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCollectionsAPIDistributedZkTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractCollectionsAPIDistributedZkTestBase.java
@@ -16,9 +16,10 @@
*/
package org.apache.solr.cloud.api.collections;
-import javax.management.MBeanServer;
-import javax.management.MBeanServerFactory;
-import javax.management.ObjectName;
+import static org.apache.solr.common.cloud.ZkStateReader.CORE_NAME_PROP;
+import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR;
+
+import com.google.common.collect.ImmutableList;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.lang.management.ManagementFactory;
@@ -37,8 +38,9 @@ import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;
-
-import com.google.common.collect.ImmutableList;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.lucene.util.TestUtil;
import org.apache.solr.client.solrj.SolrQuery;
@@ -76,12 +78,7 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.apache.solr.common.cloud.ZkStateReader.CORE_NAME_PROP;
-import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR;
-
-/**
- * Tests the Cloud Collections API.
- */
+/** Tests the Cloud Collections API. */
@Slow
public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCloudTestCase {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@@ -103,7 +100,7 @@ public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCl
.withSolrXml(TEST_PATH().resolve("solr.xml"))
.configure();
}
-
+
@After
public void tearDownCluster() throws Exception {
try {
@@ -119,15 +116,19 @@ public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCl
public void testCreationAndDeletion() throws Exception {
String collectionName = "created_and_deleted";
- CollectionAdminRequest.createCollection(collectionName, "conf", 1, 1).process(cluster.getSolrClient());
- assertTrue(CollectionAdminRequest.listCollections(cluster.getSolrClient())
- .contains(collectionName));
+ CollectionAdminRequest.createCollection(collectionName, "conf", 1, 1)
+ .process(cluster.getSolrClient());
+ assertTrue(
+ CollectionAdminRequest.listCollections(cluster.getSolrClient()).contains(collectionName));
CollectionAdminRequest.deleteCollection(collectionName).process(cluster.getSolrClient());
- assertFalse(CollectionAdminRequest.listCollections(cluster.getSolrClient())
- .contains(collectionName));
+ assertFalse(
+ CollectionAdminRequest.listCollections(cluster.getSolrClient()).contains(collectionName));
- assertFalse(cluster.getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, true));
+ assertFalse(
+ cluster
+ .getZkClient()
+ .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, true));
}
@Test
@@ -137,38 +138,45 @@ public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCl
// manually create a collections zknode
cluster.getZkClient().makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, true);
- CollectionAdminRequest.deleteCollection(collectionName)
- .process(cluster.getSolrClient());
+ CollectionAdminRequest.deleteCollection(collectionName).process(cluster.getSolrClient());
- assertFalse(CollectionAdminRequest.listCollections(cluster.getSolrClient())
- .contains(collectionName));
-
- assertFalse(cluster.getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, true));
+ assertFalse(
+ CollectionAdminRequest.listCollections(cluster.getSolrClient()).contains(collectionName));
+
+ assertFalse(
+ cluster
+ .getZkClient()
+ .exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, true));
}
@Test
public void deletePartiallyCreatedCollection() throws Exception {
final String collectionName = "halfdeletedcollection";
- assertEquals(0, CollectionAdminRequest.createCollection(collectionName, "conf", 2, 1)
- .setCreateNodeSet("")
- .process(cluster.getSolrClient()).getStatus());
+ assertEquals(
+ 0,
+ CollectionAdminRequest.createCollection(collectionName, "conf", 2, 1)
+ .setCreateNodeSet("")
+ .process(cluster.getSolrClient())
+ .getStatus());
String dataDir = createTempDir().toFile().getAbsolutePath();
// create a core that simulates something left over from a partially-deleted collection
- assertTrue(CollectionAdminRequest
- .addReplicaToShard(collectionName, "shard1")
- .setDataDir(dataDir)
- .process(cluster.getSolrClient()).isSuccess());
+ assertTrue(
+ CollectionAdminRequest.addReplicaToShard(collectionName, "shard1")
+ .setDataDir(dataDir)
+ .process(cluster.getSolrClient())
+ .isSuccess());
- CollectionAdminRequest.deleteCollection(collectionName)
- .process(cluster.getSolrClient());
+ CollectionAdminRequest.deleteCollection(collectionName).process(cluster.getSolrClient());
- assertFalse(CollectionAdminRequest.listCollections(cluster.getSolrClient()).contains(collectionName));
+ assertFalse(
+ CollectionAdminRequest.listCollections(cluster.getSolrClient()).contains(collectionName));
CollectionAdminRequest.createCollection(collectionName, "conf", 2, 1)
.process(cluster.getSolrClient());
- assertTrue(CollectionAdminRequest.listCollections(cluster.getSolrClient()).contains(collectionName));
+ assertTrue(
+ CollectionAdminRequest.listCollections(cluster.getSolrClient()).contains(collectionName));
}
@Test
@@ -180,12 +188,14 @@ public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCl
// delete via API - should remove collections node
CollectionAdminRequest.deleteCollection(collectionName).process(cluster.getSolrClient());
- assertFalse(CollectionAdminRequest.listCollections(cluster.getSolrClient()).contains(collectionName));
-
+ assertFalse(
+ CollectionAdminRequest.listCollections(cluster.getSolrClient()).contains(collectionName));
+
// now creating that collection should work
CollectionAdminRequest.createCollection(collectionName, "conf", 2, 1)
.process(cluster.getSolrClient());
- assertTrue(CollectionAdminRequest.listCollections(cluster.getSolrClient()).contains(collectionName));
+ assertTrue(
+ CollectionAdminRequest.listCollections(cluster.getSolrClient()).contains(collectionName));
}
@Test
@@ -199,9 +209,11 @@ public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCl
final QueryRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
- expectThrows(Exception.class, () -> {
- cluster.getSolrClient().request(request);
- });
+ expectThrows(
+ Exception.class,
+ () -> {
+ cluster.getSolrClient().request(request);
+ });
}
@Test
@@ -213,9 +225,11 @@ public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCl
final QueryRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
- expectThrows(Exception.class, () -> {
- cluster.getSolrClient().request(request);
- });
+ expectThrows(
+ Exception.class,
+ () -> {
+ cluster.getSolrClient().request(request);
+ });
}
@Test
@@ -230,9 +244,11 @@ public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCl
final QueryRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
- expectThrows(Exception.class, () -> {
- cluster.getSolrClient().request(request);
- });
+ expectThrows(
+ Exception.class,
+ () -> {
+ cluster.getSolrClient().request(request);
+ });
}
@Test
@@ -246,9 +262,11 @@ public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCl
final QueryRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
- expectThrows(Exception.class, () -> {
- cluster.getSolrClient().request(request);
- });
+ expectThrows(
+ Exception.class,
+ () -> {
+ cluster.getSolrClient().request(request);
+ });
}
@Test
@@ -256,40 +274,55 @@ public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCl
String nn1 = cluster.getJettySolrRunner(0).getNodeName();
String nn2 = cluster.getJettySolrRunner(1).getNodeName();
- assertEquals(0, CollectionAdminRequest.createCollection("halfcollectionblocker", "conf", 1, 1)
- .setCreateNodeSet("")
- .process(cluster.getSolrClient()).getStatus());
- assertTrue(CollectionAdminRequest.addReplicaToShard("halfcollectionblocker", "shard1")
- .setNode(cluster.getJettySolrRunner(0).getNodeName())
- .setCoreName("halfcollection_shard1_replica_n1")
- .process(cluster.getSolrClient()).isSuccess());
-
- assertEquals(0, CollectionAdminRequest.createCollection("halfcollectionblocker2", "conf",1, 1)
- .setCreateNodeSet("")
- .process(cluster.getSolrClient()).getStatus());
- assertTrue(CollectionAdminRequest.addReplicaToShard("halfcollectionblocker2", "shard1")
- .setNode(cluster.getJettySolrRunner(1).getNodeName())
- .setCoreName("halfcollection_shard1_replica_n1")
- .process(cluster.getSolrClient()).isSuccess());
-
- expectThrows(BaseHttpSolrClient.RemoteSolrException.class, () -> {
- CollectionAdminRequest.createCollection("halfcollection", "conf", 1, 1)
- .setCreateNodeSet(nn1 + "," + nn2)
- .process(cluster.getSolrClient());
- });
+ assertEquals(
+ 0,
+ CollectionAdminRequest.createCollection("halfcollectionblocker", "conf", 1, 1)
+ .setCreateNodeSet("")
+ .process(cluster.getSolrClient())
+ .getStatus());
+ assertTrue(
+ CollectionAdminRequest.addReplicaToShard("halfcollectionblocker", "shard1")
+ .setNode(cluster.getJettySolrRunner(0).getNodeName())
+ .setCoreName("halfcollection_shard1_replica_n1")
+ .process(cluster.getSolrClient())
+ .isSuccess());
+
+ assertEquals(
+ 0,
+ CollectionAdminRequest.createCollection("halfcollectionblocker2", "conf", 1, 1)
+ .setCreateNodeSet("")
+ .process(cluster.getSolrClient())
+ .getStatus());
+ assertTrue(
+ CollectionAdminRequest.addReplicaToShard("halfcollectionblocker2", "shard1")
+ .setNode(cluster.getJettySolrRunner(1).getNodeName())
+ .setCoreName("halfcollection_shard1_replica_n1")
+ .process(cluster.getSolrClient())
+ .isSuccess());
+
+ expectThrows(
+ BaseHttpSolrClient.RemoteSolrException.class,
+ () -> {
+ CollectionAdminRequest.createCollection("halfcollection", "conf", 1, 1)
+ .setCreateNodeSet(nn1 + "," + nn2)
+ .process(cluster.getSolrClient());
+ });
}
@Test
public void testNoConfigSetExist() throws Exception {
- expectThrows(Exception.class, () -> {
- CollectionAdminRequest.createCollection("noconfig", "conf123", 1, 1)
- .process(cluster.getSolrClient());
- });
+ expectThrows(
+ Exception.class,
+ () -> {
+ CollectionAdminRequest.createCollection("noconfig", "conf123", 1, 1)
+ .process(cluster.getSolrClient());
+ });
TimeUnit.MILLISECONDS.sleep(1000);
// in both cases, the collection should have default to the core name
cluster.getSolrClient().getZkStateReader().forceUpdateCollection("noconfig");
- assertFalse(CollectionAdminRequest.listCollections(cluster.getSolrClient()).contains("noconfig"));
+ assertFalse(
+ CollectionAdminRequest.listCollections(cluster.getSolrClient()).contains("noconfig"));
}
@Test
@@ -297,7 +330,8 @@ public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCl
CollectionAdminRequest.createCollection("nodes_used_collection", "conf", 2, 2)
.process(cluster.getSolrClient());
- Set<String> liveNodes = cluster.getSolrClient().getZkStateReader().getClusterState().getLiveNodes();
+ Set<String> liveNodes =
+ cluster.getSolrClient().getZkStateReader().getClusterState().getLiveNodes();
List<String> createNodeList = new ArrayList<>(liveNodes);
@@ -314,21 +348,32 @@ public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCl
@Test
public void testDeleteNonExistentCollection() throws Exception {
- expectThrows(SolrException.class, () -> {
- CollectionAdminRequest.deleteCollection("unknown_collection").process(cluster.getSolrClient());
- });
+ expectThrows(
+ SolrException.class,
+ () -> {
+ CollectionAdminRequest.deleteCollection("unknown_collection")
+ .process(cluster.getSolrClient());
+ });
// create another collection should still work
CollectionAdminRequest.createCollection("acollectionafterbaddelete", "conf", 1, 2)
.process(cluster.getSolrClient());
- waitForState("Collection creation after a bad delete failed", "acollectionafterbaddelete",
+ waitForState(
+ "Collection creation after a bad delete failed",
+ "acollectionafterbaddelete",
(n, c) -> DocCollection.isFullyActive(n, c, 1, 2));
}
@Test
public void testSpecificConfigsets() throws Exception {
- CollectionAdminRequest.createCollection("withconfigset2", "conf2", 1, 1).process(cluster.getSolrClient());
- String configName = cluster.getSolrClient().getClusterStateProvider().getCollection("withconfigset2").getConfigName();
+ CollectionAdminRequest.createCollection("withconfigset2", "conf2", 1, 1)
+ .process(cluster.getSolrClient());
+ String configName =
+ cluster
+ .getSolrClient()
+ .getClusterStateProvider()
+ .getCollection("withconfigset2")
+ .getConfigName();
assertEquals("conf2", configName);
}
@@ -337,7 +382,8 @@ public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCl
JettySolrRunner jetty1 = cluster.getRandomJetty(random());
JettySolrRunner jetty2 = cluster.getRandomJetty(random());
- List<String> baseUrls = ImmutableList.of(jetty1.getBaseUrl().toString(), jetty2.getBaseUrl().toString());
+ List<String> baseUrls =
+ ImmutableList.of(jetty1.getBaseUrl().toString(), jetty2.getBaseUrl().toString());
CollectionAdminRequest.createCollection("nodeset_collection", "conf", 2, 1)
.setCreateNodeSet(baseUrls.get(0) + "," + baseUrls.get(1))
@@ -359,21 +405,18 @@ public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCl
}
@Test
- //28-June-2018 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028")
- // See: https://issues.apache.org/jira/browse/SOLR-12028 Tests cannot remove files on Windows machines occasionally
- // commented out on: 24-Dec-2018 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // added 09-Aug-2018 SOLR-12028
public void testCollectionsAPI() throws Exception {
// create new collections rapid fire
int cnt = random().nextInt(TEST_NIGHTLY ? 3 : 1) + 1;
CollectionAdminRequest.Create[] createRequests = new CollectionAdminRequest.Create[cnt];
-
+
class Coll {
String name;
int numShards;
int replicationFactor;
}
-
+
List<Coll> colls = new ArrayList<>();
for (int i = 0; i < cnt; i++) {
@@ -381,10 +424,11 @@ public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCl
int numShards = TestUtil.nextInt(random(), 0, cluster.getJettySolrRunners().size()) + 1;
int replicationFactor = TestUtil.nextInt(random(), 0, 3) + 1;
- createRequests[i]
- = CollectionAdminRequest.createCollection("awhollynewcollection_" + i, "conf2", numShards, replicationFactor);
+ createRequests[i] =
+ CollectionAdminRequest.createCollection(
+ "awhollynewcollection_" + i, "conf2", numShards, replicationFactor);
createRequests[i].processAsync(cluster.getSolrClient());
-
+
Coll coll = new Coll();
coll.name = "awhollynewcollection_" + i;
coll.numShards = numShards;
@@ -393,7 +437,8 @@ public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCl
}
for (Coll coll : colls) {
- cluster.waitForActiveCollection(coll.name, coll.numShards, coll.numShards * coll.replicationFactor);
+ cluster.waitForActiveCollection(
+ coll.name, coll.numShards, coll.numShards * coll.replicationFactor);
}
waitForStable(cnt, createRequests);
@@ -401,12 +446,13 @@ public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCl
for (int i = 0; i < cluster.getJettySolrRunners().size(); i++) {
checkInstanceDirs(cluster.getJettySolrRunner(i));
}
-
- String collectionName = createRequests[random().nextInt(createRequests.length)].getCollectionName();
-
+
+ String collectionName =
+ createRequests[random().nextInt(createRequests.length)].getCollectionName();
+
// TODO: we should not need this...beast test well when trying to fix
Thread.sleep(1000);
-
+
cluster.getSolrClient().getZkStateReader().forciblyRefreshAllClusterStateSlow();
new UpdateRequest()
@@ -418,43 +464,57 @@ public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCl
TimeOut timeOut = new TimeOut(10, TimeUnit.SECONDS, TimeSource.NANO_TIME);
while (!timeOut.hasTimedOut()) {
- numFound = cluster.getSolrClient().query(collectionName, new SolrQuery("*:*")).getResults().getNumFound();
+ numFound =
+ cluster
+ .getSolrClient()
+ .query(collectionName, new SolrQuery("*:*"))
+ .getResults()
+ .getNumFound();
if (numFound == 3) {
break;
}
Thread.sleep(500);
}
-
+
if (timeOut.hasTimedOut()) {
- fail("Timeout waiting to see 3 found, instead saw " + numFound + " for collection " + collectionName);
+ fail(
+ "Timeout waiting to see 3 found, instead saw "
+ + numFound
+ + " for collection "
+ + collectionName);
}
checkNoTwoShardsUseTheSameIndexDir();
}
- private void waitForStable(int cnt, CollectionAdminRequest.Create[] createRequests) throws InterruptedException {
+ private void waitForStable(int cnt, CollectionAdminRequest.Create[] createRequests)
+ throws InterruptedException {
for (int i = 0; i < cnt; i++) {
String collectionName = "awhollynewcollection_" + i;
final int j = i;
- waitForState("Expected to see collection " + collectionName, collectionName,
+ waitForState(
+ "Expected to see collection " + collectionName,
+ collectionName,
(n, c) -> {
CollectionAdminRequest.Create req = createRequests[j];
- return DocCollection.isFullyActive(n, c, req.getNumShards(), req.getReplicationFactor());
+ return DocCollection.isFullyActive(
+ n, c, req.getNumShards(), req.getReplicationFactor());
});
-
+
ZkStateReader zkStateReader = cluster.getSolrClient().getZkStateReader();
// make sure we have leaders for each shard
for (int z = 1; z < createRequests[j].getNumShards(); z++) {
zkStateReader.getLeaderRetry(collectionName, "shard" + z, 10000);
- } // make sure we again have leaders for each shard
+ } // make sure we again have leaders for each shard
}
}
@Test
public void testCollectionReload() throws Exception {
final String collectionName = "reloaded_collection";
- CollectionAdminRequest.createCollection(collectionName, "conf", 2, 2).process(cluster.getSolrClient());
+ CollectionAdminRequest.createCollection(collectionName, "conf", 2, 2)
+ .process(cluster.getSolrClient());
// get core open times
Map<String, Long> urlToTimeBefore = new HashMap<>();
@@ -474,25 +534,30 @@ public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCl
for (SolrCore core : theCores) {
// look for core props file
Path instancedir = core.getInstancePath();
- assertTrue("Could not find expected core.properties file", Files.exists(instancedir.resolve("core.properties")));
+ assertTrue(
+ "Could not find expected core.properties file",
+ Files.exists(instancedir.resolve("core.properties")));
Path expected = Paths.get(jetty.getSolrHome()).toAbsolutePath().resolve(core.getName());
- assertTrue("Expected: " + expected + "\nFrom core stats: " + instancedir, Files.isSameFile(expected, instancedir));
+ assertTrue(
+ "Expected: " + expected + "\nFrom core stats: " + instancedir,
+ Files.isSameFile(expected, instancedir));
}
}
- private boolean waitForReloads(String collectionName, Map<String,Long> urlToTimeBefore) throws SolrServerException, IOException {
+ private boolean waitForReloads(String collectionName, Map<String, Long> urlToTimeBefore)
+ throws SolrServerException, IOException {
TimeOut timeout = new TimeOut(45, TimeUnit.SECONDS, TimeSource.NANO_TIME);
boolean allTimesAreCorrect = false;
- while (! timeout.hasTimedOut()) {
- Map<String,Long> urlToTimeAfter = new HashMap<>();
+ while (!timeout.hasTimedOut()) {
+ Map<String, Long> urlToTimeAfter = new HashMap<>();
collectStartTimes(collectionName, urlToTimeAfter);
-
+
boolean retry = false;
- Set<Entry<String,Long>> entries = urlToTimeBefore.entrySet();
- for (Entry<String,Long> entry : entries) {
+ Set<Entry<String, Long>> entries = urlToTimeBefore.entrySet();
+ for (Entry<String, Long> entry : entries) {
Long beforeTime = entry.getValue();
Long afterTime = urlToTimeAfter.get(entry.getKey());
assertNotNull(afterTime);
@@ -500,7 +565,6 @@ public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCl
retry = true;
break;
}
-
}
if (!retry) {
allTimesAreCorrect = true;
@@ -510,7 +574,7 @@ public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCl
return allTimesAreCorrect;
}
- private void collectStartTimes(String collectionName, Map<String,Long> urlToTime)
+ private void collectStartTimes(String collectionName, Map<String, Long> urlToTime)
throws SolrServerException, IOException {
DocCollection collectionState = getCollectionState(collectionName);
@@ -530,10 +594,10 @@ public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCl
throw new IllegalArgumentException("Could not find collection " + collectionName);
}
}
-
+
private void checkNoTwoShardsUseTheSameIndexDir() {
Map<String, Set<String>> indexDirToShardNamesMap = new HashMap<>();
-
+
List<MBeanServer> servers = new LinkedList<>();
servers.add(ManagementFactory.getPlatformMBeanServer());
servers.addAll(MBeanServerFactory.findMBeanServer(null));
@@ -544,8 +608,8 @@ public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCl
Map<String, String> props = mbean.getKeyPropertyList();
String category = props.get("category");
String name = props.get("name");
- if ((category != null && category.equals(Category.CORE.toString())) &&
- (name != null && name.equals("indexDir"))) {
+ if ((category != null && category.equals(Category.CORE.toString()))
+ && (name != null && name.equals("indexDir"))) {
String indexDir = server.getAttribute(mbean, "Value").toString();
String key = props.get("dom2") + "." + props.get("dom3") + "." + props.get("dom4");
if (!indexDirToShardNamesMap.containsKey(indexDir)) {
@@ -559,16 +623,20 @@ public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCl
}
}
}
-
+
assertTrue(
"Something is broken in the assert for no shards using the same indexDir - probably something was changed in the attributes published in the MBean of "
- + SolrCore.class.getSimpleName() + " : " + indexDirToShardNamesMap,
+ + SolrCore.class.getSimpleName()
+ + " : "
+ + indexDirToShardNamesMap,
indexDirToShardNamesMap.size() > 0);
- for (Entry<String,Set<String>> entry : indexDirToShardNamesMap.entrySet()) {
+ for (Entry<String, Set<String>> entry : indexDirToShardNamesMap.entrySet()) {
if (entry.getValue().size() > 1) {
- fail("We have shards using the same indexDir. E.g. shards "
- + entry.getValue().toString() + " all use indexDir "
- + entry.getKey());
+ fail(
+ "We have shards using the same indexDir. E.g. shards "
+ + entry.getValue().toString()
+ + " all use indexDir "
+ + entry.getKey());
}
}
}
@@ -581,22 +649,27 @@ public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCl
.process(cluster.getSolrClient());
cluster.waitForActiveCollection(collectionName, 2, 4);
- ArrayList<String> nodeList
- = new ArrayList<>(cluster.getSolrClient().getZkStateReader().getClusterState().getLiveNodes());
+ ArrayList<String> nodeList =
+ new ArrayList<>(
+ cluster.getSolrClient().getZkStateReader().getClusterState().getLiveNodes());
Collections.shuffle(nodeList, random());
- CollectionAdminResponse response = CollectionAdminRequest.addReplicaToShard(collectionName, "shard1")
- .setNode(nodeList.get(0))
- .process(cluster.getSolrClient());
+ CollectionAdminResponse response =
+ CollectionAdminRequest.addReplicaToShard(collectionName, "shard1")
+ .setNode(nodeList.get(0))
+ .process(cluster.getSolrClient());
Replica newReplica = grabNewReplica(response, getCollectionState(collectionName));
- assertEquals("Replica should be created on the right node",
- cluster.getSolrClient().getZkStateReader().getBaseUrlForNodeName(nodeList.get(0)), newReplica.getBaseUrl());
+ assertEquals(
+ "Replica should be created on the right node",
+ cluster.getSolrClient().getZkStateReader().getBaseUrlForNodeName(nodeList.get(0)),
+ newReplica.getBaseUrl());
Path instancePath = createTempDir();
- response = CollectionAdminRequest.addReplicaToShard(collectionName, "shard1")
- .withProperty(CoreAdminParams.INSTANCE_DIR, instancePath.toString())
- .process(cluster.getSolrClient());
+ response =
+ CollectionAdminRequest.addReplicaToShard(collectionName, "shard1")
+ .withProperty(CoreAdminParams.INSTANCE_DIR, instancePath.toString())
+ .process(cluster.getSolrClient());
newReplica = grabNewReplica(response, getCollectionState(collectionName));
assertNotNull(newReplica);
@@ -607,36 +680,47 @@ public abstract class AbstractCollectionsAPIDistributedZkTestBase extends SolrCl
assertEquals(instanceDirStr, instancePath.toString());
}
- //Test to make sure we can't create another replica with an existing core_name of that collection
+ // Test to make sure we can't create another replica with an existing core_name of that
+ // collection
String coreName = newReplica.getStr(CORE_NAME_PROP);
- SolrException e = expectThrows(SolrException.class, () -> {
- ModifiableSolrParams params = new ModifiableSolrParams();
- params.set("action", "addreplica");
- params.set("collection", collectionName);
- params.set("shard", "shard1");
- params.set("name", coreName);
- QueryRequest request = new QueryRequest(params);
- request.setPath("/admin/collections");
- cluster.getSolrClient().request(request);
- });
-
- assertTrue(e.getMessage().contains("Another replica with the same core name already exists for this collection"));
-
- // Check that specifying property.name works. DO NOT remove this when the "name" property is deprecated
+ SolrException e =
+ expectThrows(
+ SolrException.class,
+ () -> {
+ ModifiableSolrParams params = new ModifiableSolrParams();
+ params.set("action", "addreplica");
+ params.set("collection", collectionName);
+ params.set("shard", "shard1");
+ params.set("name", coreName);
+ QueryRequest request = new QueryRequest(params);
+ request.setPath("/admin/collections");
+ cluster.getSolrClient().request(request);
+ });
+
+ assertTrue(
+ e.getMessage()
+ .contains(
+ "Another replica with the same core name already exists for this collection"));
+
+ // Check that specifying property.name works. DO NOT remove this when the "name" property is
+ // deprecated
// for ADDREPLICA, this is "property.name". See SOLR-7132
- response = CollectionAdminRequest.addReplicaToShard(collectionName, "shard1")
- .withProperty(CoreAdminParams.NAME, "propertyDotName")
- .process(cluster.getSolrClient());
+ response =
+ CollectionAdminRequest.addReplicaToShard(collectionName, "shard1")
+ .withProperty(CoreAdminParams.NAME, "propertyDotName")
+ .process(cluster.getSolrClient());
newReplica = grabNewReplica(response, getCollectionState(collectionName));
- assertEquals("'core' should be 'propertyDotName' ", "propertyDotName", newReplica.getStr("core"));
+ assertEquals(
+ "'core' should be 'propertyDotName' ", "propertyDotName", newReplica.getStr("core"));
}
private Replica grabNewReplica(CollectionAdminResponse response, DocCollection docCollection) {
String replicaName = response.getCollectionCoresStatus().keySet().iterator().next();
- Optional<Replica> optional = docCollection.getReplicas().stream()
- .filter(replica -> replicaName.equals(replica.getCoreName()))
- .findAny();
+ Optional<Replica> optional =
+ docCollection.getReplicas().stream()
+ .filter(replica -> replicaName.equals(replica.getCoreName()))
+ .findAny();
if (optional.isPresent()) {
return optional.get();
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractIncrementalBackupTest.java b/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractIncrementalBackupTest.java
index 2c7b84418bc..15e1582cf7d 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractIncrementalBackupTest.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/AbstractIncrementalBackupTest.java
@@ -17,6 +17,29 @@
package org.apache.solr.cloud.api.collections;
+import static org.apache.solr.core.TrackingBackupRepository.copiedFiles;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.invoke.MethodHandles;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Random;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.index.IndexCommit;
import org.apache.lucene.store.Directory;
@@ -53,548 +76,595 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.lang.invoke.MethodHandles;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Random;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import static org.apache.solr.core.TrackingBackupRepository.copiedFiles;
-
/**
- * Used to test the incremental method of backup/restoration (as opposed to the deprecated 'full snapshot' method).
+ * Used to test the incremental method of backup/restoration (as opposed to the deprecated 'full
+ * snapshot' method).
*
- * For a similar test harness for snapshot backup/restoration see {@link AbstractCloudBackupRestoreTestCase}
+ * <p>For a similar test harness for snapshot backup/restoration see {@link
+ * AbstractCloudBackupRestoreTestCase}
*/
public abstract class AbstractIncrementalBackupTest extends SolrCloudTestCase {
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
- private static long docsSeed; // see indexDocs()
- protected static final int NUM_SHARDS = 2;//granted we sometimes shard split to get more
- protected static final int REPL_FACTOR = 2;
- protected static final String BACKUPNAME_PREFIX = "mytestbackup";
- protected static final String BACKUP_REPO_NAME = "trackingBackupRepository";
-
- protected String testSuffix = "test1";
-
- @BeforeClass
- public static void createCluster() throws Exception {
- docsSeed = random().nextLong();
- System.setProperty("solr.directoryFactory", "solr.StandardDirectoryFactory");
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ private static long docsSeed; // see indexDocs()
+ protected static final int NUM_SHARDS = 2; // granted we sometimes shard split to get more
+ protected static final int REPL_FACTOR = 2;
+ protected static final String BACKUPNAME_PREFIX = "mytestbackup";
+ protected static final String BACKUP_REPO_NAME = "trackingBackupRepository";
+
+ protected String testSuffix = "test1";
+
+ @BeforeClass
+ public static void createCluster() throws Exception {
+ docsSeed = random().nextLong();
+ System.setProperty("solr.directoryFactory", "solr.StandardDirectoryFactory");
+ }
+
+ @Before
+ public void setUpTrackingRepo() {
+ TrackingBackupRepository.clear();
+ }
+
+ /**
+ * @return The name of the collection to use.
+ */
+ public abstract String getCollectionNamePrefix();
+
+ public String getCollectionName() {
+ return getCollectionNamePrefix() + "_" + testSuffix;
+ }
+
+ public void setTestSuffix(String testSuffix) {
+ this.testSuffix = testSuffix;
+ }
+
+ /**
+ * @return The absolute path for the backup location. Could return null.
+ */
+ public abstract String getBackupLocation();
+
+ @Test
+ public void testSimple() throws Exception {
+ setTestSuffix("testbackupincsimple");
+ final String backupCollectionName = getCollectionName();
+ final String restoreCollectionName = backupCollectionName + "_restore";
+
+ CloudSolrClient solrClient = cluster.getSolrClient();
+
+ CollectionAdminRequest.createCollection(backupCollectionName, "conf1", NUM_SHARDS, 1)
+ .process(solrClient);
+ int totalIndexedDocs = indexDocs(backupCollectionName, true);
+ String backupName = BACKUPNAME_PREFIX + testSuffix;
+ try (BackupRepository repository =
+ cluster.getJettySolrRunner(0).getCoreContainer().newBackupRepository(BACKUP_REPO_NAME)) {
+ String backupLocation = repository.getBackupLocation(getBackupLocation());
+ long t = System.nanoTime();
+ int expectedDocsForFirstBackup = totalIndexedDocs;
+ CollectionAdminRequest.backupCollection(backupCollectionName, backupName)
+ .setLocation(backupLocation)
+ .setIncremental(true)
+ .setRepositoryName(BACKUP_REPO_NAME)
+ .processAndWait(cluster.getSolrClient(), 100);
+ long timeTaken = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t);
+ log.info("Created backup with {} docs, took {}ms", totalIndexedDocs, timeTaken);
+ totalIndexedDocs += indexDocs(backupCollectionName, true);
+
+ t = System.nanoTime();
+ CollectionAdminRequest.backupCollection(backupCollectionName, backupName)
+ .setLocation(backupLocation)
+ .setIncremental(true)
+ .setRepositoryName(BACKUP_REPO_NAME)
+ .processAndWait(cluster.getSolrClient(), 100);
+ timeTaken = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t);
+ long numFound =
+ cluster
+ .getSolrClient()
+ .query(backupCollectionName, new SolrQuery("*:*"))
+ .getResults()
+ .getNumFound();
+ log.info("Created backup with {} docs, took {}ms", numFound, timeTaken);
+
+ t = System.nanoTime();
+ randomlyPrecreateRestoreCollection(restoreCollectionName, "conf1", NUM_SHARDS, 1);
+ CollectionAdminRequest.restoreCollection(restoreCollectionName, backupName)
+ .setBackupId(0)
+ .setLocation(backupLocation)
+ .setRepositoryName(BACKUP_REPO_NAME)
+ .processAndWait(solrClient, 500);
+ timeTaken = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t);
+ log.info("Restored from backup, took {}ms", timeTaken);
+ t = System.nanoTime();
+ AbstractDistribZkTestBase.waitForRecoveriesToFinish(
+ restoreCollectionName,
+ cluster.getSolrClient().getZkStateReader(),
+ log.isDebugEnabled(),
+ false,
+ 3);
+ timeTaken = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t);
+ log.info("Restored collection healthy, took {}ms", timeTaken);
+ numFound =
+ cluster
+ .getSolrClient()
+ .query(restoreCollectionName, new SolrQuery("*:*"))
+ .getResults()
+ .getNumFound();
+ assertEquals(expectedDocsForFirstBackup, numFound);
}
-
- @Before
- public void setUpTrackingRepo() {
- TrackingBackupRepository.clear();
+ }
+
+ @Test
+ public void testRestoreToOriginalCollection() throws Exception {
+ setTestSuffix("testbackuprestoretooriginal");
+ final String backupCollectionName = getCollectionName();
+ final String backupName = BACKUPNAME_PREFIX + testSuffix;
+
+ // Bootstrap the backup collection with seed docs
+ CollectionAdminRequest.createCollection(backupCollectionName, "conf1", NUM_SHARDS, REPL_FACTOR)
+ .process(cluster.getSolrClient());
+ final int firstBatchNumDocs = indexDocs(backupCollectionName, true);
+
+ // Backup and immediately add more docs to the collection
+ try (BackupRepository repository =
+ cluster.getJettySolrRunner(0).getCoreContainer().newBackupRepository(BACKUP_REPO_NAME)) {
+ final String backupLocation = repository.getBackupLocation(getBackupLocation());
+ final RequestStatusState result =
+ CollectionAdminRequest.backupCollection(backupCollectionName, backupName)
+ .setLocation(backupLocation)
+ .setRepositoryName(BACKUP_REPO_NAME)
+ .processAndWait(cluster.getSolrClient(), 10 * 1000);
+ assertEquals(RequestStatusState.COMPLETED, result);
}
-
- /**
- * @return The name of the collection to use.
- */
- public abstract String getCollectionNamePrefix();
-
- public String getCollectionName(){
- return getCollectionNamePrefix() + "_" + testSuffix;
+ final int secondBatchNumDocs = indexDocs(backupCollectionName, true);
+ final int maxDocs = secondBatchNumDocs + firstBatchNumDocs;
+ assertEquals(maxDocs, getNumDocsInCollection(backupCollectionName));
+
+ // Restore original docs and validate that doc count is correct
+ try (BackupRepository repository =
+ cluster.getJettySolrRunner(0).getCoreContainer().newBackupRepository(BACKUP_REPO_NAME)) {
+ final String backupLocation = repository.getBackupLocation(getBackupLocation());
+ final RequestStatusState result =
+ CollectionAdminRequest.restoreCollection(backupCollectionName, backupName)
+ .setLocation(backupLocation)
+ .setRepositoryName(BACKUP_REPO_NAME)
+ .processAndWait(cluster.getSolrClient(), 20 * 1000);
+ assertEquals(RequestStatusState.COMPLETED, result);
}
-
- public void setTestSuffix(String testSuffix) {
- this.testSuffix = testSuffix;
- }
-
- /**
- * @return The absolute path for the backup location.
- * Could return null.
- */
- public abstract String getBackupLocation();
-
- @Test
- public void testSimple() throws Exception {
- setTestSuffix("testbackupincsimple");
- final String backupCollectionName = getCollectionName();
- final String restoreCollectionName = backupCollectionName + "_restore";
-
- CloudSolrClient solrClient = cluster.getSolrClient();
-
- CollectionAdminRequest
- .createCollection(backupCollectionName, "conf1", NUM_SHARDS, 1)
- .process(solrClient);
- int totalIndexedDocs = indexDocs(backupCollectionName, true);
- String backupName = BACKUPNAME_PREFIX + testSuffix;
- try (BackupRepository repository = cluster.getJettySolrRunner(0).getCoreContainer()
- .newBackupRepository(BACKUP_REPO_NAME)) {
- String backupLocation = repository.getBackupLocation(getBackupLocation());
- long t = System.nanoTime();
- int expectedDocsForFirstBackup = totalIndexedDocs;
- CollectionAdminRequest.backupCollection(backupCollectionName, backupName)
- .setLocation(backupLocation)
- .setIncremental(true)
- .setRepositoryName(BACKUP_REPO_NAME)
- .processAndWait(cluster.getSolrClient(), 100);
- long timeTaken = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t);
- log.info("Created backup with {} docs, took {}ms", totalIndexedDocs, timeTaken);
- totalIndexedDocs += indexDocs(backupCollectionName, true);
-
- t = System.nanoTime();
- CollectionAdminRequest.backupCollection(backupCollectionName, backupName)
- .setLocation(backupLocation)
- .setIncremental(true)
- .setRepositoryName(BACKUP_REPO_NAME)
- .processAndWait(cluster.getSolrClient(), 100);
- timeTaken = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t);
- long numFound = cluster.getSolrClient().query(backupCollectionName,
- new SolrQuery("*:*")).getResults().getNumFound();
- log.info("Created backup with {} docs, took {}ms", numFound, timeTaken);
-
- t = System.nanoTime();
- randomlyPrecreateRestoreCollection(restoreCollectionName, "conf1", NUM_SHARDS, 1);
- CollectionAdminRequest.restoreCollection(restoreCollectionName, backupName)
- .setBackupId(0)
- .setLocation(backupLocation)
- .setRepositoryName(BACKUP_REPO_NAME)
- .processAndWait(solrClient, 500);
- timeTaken = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t);
- log.info("Restored from backup, took {}ms", timeTaken);
- t = System.nanoTime();
- AbstractDistribZkTestBase.waitForRecoveriesToFinish(
- restoreCollectionName, cluster.getSolrClient().getZkStateReader(), log.isDebugEnabled(), false, 3);
- timeTaken = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t);
- log.info("Restored collection healthy, took {}ms", timeTaken);
- numFound = cluster.getSolrClient().query(restoreCollectionName,
- new SolrQuery("*:*")).getResults().getNumFound();
- assertEquals(expectedDocsForFirstBackup, numFound);
+ assertEquals(firstBatchNumDocs, getNumDocsInCollection(backupCollectionName));
+ }
+
+ @Test
+ @Slow
+ @SuppressWarnings("rawtypes")
+ public void testBackupIncremental() throws Exception {
+ setTestSuffix("testbackupinc");
+ CloudSolrClient solrClient = cluster.getSolrClient();
+
+ CollectionAdminRequest.createCollection(getCollectionName(), "conf1", NUM_SHARDS, REPL_FACTOR)
+ .process(solrClient);
+
+ indexDocs(getCollectionName(), false);
+
+ String backupName = BACKUPNAME_PREFIX + testSuffix;
+ try (BackupRepository repository =
+ cluster.getJettySolrRunner(0).getCoreContainer().newBackupRepository(BACKUP_REPO_NAME)) {
+ String backupLocation = repository.getBackupLocation(getBackupLocation());
+ URI fullBackupLocationURI =
+ repository.resolveDirectory(
+ repository.createDirectoryURI(backupLocation), backupName, getCollectionName());
+ BackupFilePaths backupPaths = new BackupFilePaths(repository, fullBackupLocationURI);
+ IncrementalBackupVerifier verifier =
+ new IncrementalBackupVerifier(
+ repository, backupLocation, backupName, getCollectionName(), 3);
+
+ backupRestoreThenCheck(solrClient, verifier);
+ indexDocs(getCollectionName(), false);
+ backupRestoreThenCheck(solrClient, verifier);
+
+ // adding more commits to trigger merging segments
+ for (int i = 0; i < 15; i++) {
+ indexDocs(getCollectionName(), 5, false);
+ }
+
+ backupRestoreThenCheck(solrClient, verifier);
+ indexDocs(getCollectionName(), false);
+ backupRestoreThenCheck(solrClient, verifier);
+
+ // test list backups
+ CollectionAdminResponse resp =
+ CollectionAdminRequest.listBackup(backupName)
+ .setBackupLocation(backupLocation)
+ .setBackupRepository(BACKUP_REPO_NAME)
+ .process(cluster.getSolrClient());
+ ArrayList backups = (ArrayList) resp.getResponse().get("backups");
+ assertEquals(3, backups.size());
+
+ // test delete backups
+ resp =
+ CollectionAdminRequest.deleteBackupByRecency(backupName, 4)
+ .setRepositoryName(BACKUP_REPO_NAME)
+ .setLocation(backupLocation)
+ .process(cluster.getSolrClient());
+ assertEquals(null, resp.getResponse().get("deleted"));
+
+ resp =
+ CollectionAdminRequest.deleteBackupByRecency(backupName, 3)
+ .setRepositoryName(BACKUP_REPO_NAME)
+ .setLocation(backupLocation)
+ .process(cluster.getSolrClient());
+ assertEquals(null, resp.getResponse().get("deleted"));
+
+ resp =
+ CollectionAdminRequest.deleteBackupByRecency(backupName, 2)
+ .setRepositoryName(BACKUP_REPO_NAME)
+ .setLocation(backupLocation)
+ .process(cluster.getSolrClient());
+ assertEquals(1, resp.getResponse()._get("deleted[0]/backupId", null));
+
+ resp =
+ CollectionAdminRequest.deleteBackupById(backupName, 3)
+ .setRepositoryName(BACKUP_REPO_NAME)
+ .setLocation(backupLocation)
+ .process(cluster.getSolrClient());
+ assertEquals(3, resp.getResponse()._get("deleted[0]/backupId", null));
+
+ simpleRestoreAndCheckDocCount(solrClient, backupLocation, backupName);
+
+ // test purge backups
+ // purging first since there may corrupted files were uploaded
+ resp =
+ CollectionAdminRequest.deleteBackupPurgeUnusedFiles(backupName)
+ .setRepositoryName(BACKUP_REPO_NAME)
+ .setLocation(backupLocation)
+ .process(cluster.getSolrClient());
+
+ addDummyFileToIndex(repository, backupPaths.getIndexDir(), "dummy-files-1");
+ addDummyFileToIndex(repository, backupPaths.getIndexDir(), "dummy-files-2");
+ resp =
+ CollectionAdminRequest.deleteBackupPurgeUnusedFiles(backupName)
+ .setRepositoryName(BACKUP_REPO_NAME)
+ .setLocation(backupLocation)
+ .process(cluster.getSolrClient());
+ assertEquals(2, ((NamedList) resp.getResponse().get("deleted")).get("numIndexFiles"));
+
+ new UpdateRequest().deleteByQuery("*:*").commit(cluster.getSolrClient(), getCollectionName());
+ indexDocs(getCollectionName(), false);
+ // corrupt index files
+ corruptIndexFiles();
+ try {
+ log.info("Create backup after corrupt index files");
+ CollectionAdminRequest.Backup backup =
+ CollectionAdminRequest.backupCollection(getCollectionName(), backupName)
+ .setLocation(backupLocation)
+ .setIncremental(true)
+ .setMaxNumberBackupPoints(3)
+ .setRepositoryName(BACKUP_REPO_NAME);
+ if (random().nextBoolean()) {
+ RequestStatusState state = backup.processAndWait(cluster.getSolrClient(), 1000);
+ if (state != RequestStatusState.FAILED) {
+ fail("This backup should be failed");
+ }
+ } else {
+ CollectionAdminResponse rsp = backup.process(cluster.getSolrClient());
+ fail("This backup should be failed");
}
+ } catch (Exception e) {
+ // expected
+ e.printStackTrace();
+ }
}
-
- @Test
- public void testRestoreToOriginalCollection() throws Exception {
- setTestSuffix("testbackuprestoretooriginal");
- final String backupCollectionName = getCollectionName();
- final String backupName = BACKUPNAME_PREFIX + testSuffix;
-
- // Bootstrap the backup collection with seed docs
- CollectionAdminRequest
- .createCollection(backupCollectionName, "conf1", NUM_SHARDS, REPL_FACTOR)
- .process(cluster.getSolrClient());
- final int firstBatchNumDocs = indexDocs(backupCollectionName, true);
-
- // Backup and immediately add more docs to the collection
- try (BackupRepository repository = cluster.getJettySolrRunner(0).getCoreContainer()
- .newBackupRepository(BACKUP_REPO_NAME)) {
- final String backupLocation = repository.getBackupLocation(getBackupLocation());
- final RequestStatusState result = CollectionAdminRequest.backupCollection(backupCollectionName, backupName)
- .setLocation(backupLocation)
- .setRepositoryName(BACKUP_REPO_NAME)
- .processAndWait(cluster.getSolrClient(), 10 * 1000);
- assertEquals(RequestStatusState.COMPLETED, result);
- }
- final int secondBatchNumDocs = indexDocs(backupCollectionName, true);
- final int maxDocs = secondBatchNumDocs + firstBatchNumDocs;
- assertEquals(maxDocs, getNumDocsInCollection(backupCollectionName));
-
- // Restore original docs and validate that doc count is correct
- try (BackupRepository repository = cluster.getJettySolrRunner(0).getCoreContainer()
- .newBackupRepository(BACKUP_REPO_NAME)) {
- final String backupLocation = repository.getBackupLocation(getBackupLocation());
- final RequestStatusState result = CollectionAdminRequest.restoreCollection(backupCollectionName, backupName)
- .setLocation(backupLocation)
- .setRepositoryName(BACKUP_REPO_NAME)
- .processAndWait(cluster.getSolrClient(), 20 * 1000);
- assertEquals(RequestStatusState.COMPLETED, result);
- }
- assertEquals(firstBatchNumDocs, getNumDocsInCollection(backupCollectionName));
-
+ }
+
+ protected void corruptIndexFiles() throws IOException {
+ Collection<Slice> slices = getCollectionState(getCollectionName()).getSlices();
+ Slice slice = slices.iterator().next();
+ JettySolrRunner leaderNode = cluster.getReplicaJetty(slice.getLeader());
+
+ SolrCore solrCore = leaderNode.getCoreContainer().getCore(slice.getLeader().getCoreName());
+ Set<String> fileNames =
+ new HashSet<>(solrCore.getDeletionPolicy().getLatestCommit().getFileNames());
+ File indexFolder = new File(solrCore.getIndexDir());
+ File fileGetCorrupted =
+ Stream.of(Objects.requireNonNull(indexFolder.listFiles()))
+ .filter(x -> fileNames.contains(x.getName()))
+ .findAny()
+ .get();
+ try (FileInputStream fis = new FileInputStream(fileGetCorrupted)) {
+ byte[] contents = fis.readAllBytes();
+ contents[contents.length - CodecUtil.footerLength() - 1] += 1;
+ contents[contents.length - CodecUtil.footerLength() - 2] += 1;
+ contents[contents.length - CodecUtil.footerLength() - 3] += 1;
+ contents[contents.length - CodecUtil.footerLength() - 4] += 1;
+ try (FileOutputStream fos = new FileOutputStream(fileGetCorrupted)) {
+ fos.write(contents);
+ }
+ } finally {
+ solrCore.close();
}
-
- @Test
- @Slow
- @SuppressWarnings("rawtypes")
- public void testBackupIncremental() throws Exception {
- setTestSuffix("testbackupinc");
- CloudSolrClient solrClient = cluster.getSolrClient();
-
- CollectionAdminRequest
- .createCollection(getCollectionName(), "conf1", NUM_SHARDS, REPL_FACTOR)
- .process(solrClient);
-
- indexDocs(getCollectionName(), false);
-
- String backupName = BACKUPNAME_PREFIX + testSuffix;
- try (BackupRepository repository = cluster.getJettySolrRunner(0).getCoreContainer()
- .newBackupRepository(BACKUP_REPO_NAME)) {
- String backupLocation = repository.getBackupLocation(getBackupLocation());
- URI fullBackupLocationURI = repository.resolveDirectory(repository.createDirectoryURI(backupLocation), backupName, getCollectionName());
- BackupFilePaths backupPaths = new BackupFilePaths(repository, fullBackupLocationURI);
- IncrementalBackupVerifier verifier = new IncrementalBackupVerifier(repository, backupLocation, backupName, getCollectionName(), 3);
-
- backupRestoreThenCheck(solrClient, verifier);
- indexDocs(getCollectionName(), false);
- backupRestoreThenCheck(solrClient, verifier);
-
- // adding more commits to trigger merging segments
- for (int i = 0; i < 15; i++) {
- indexDocs(getCollectionName(), 5,false);
- }
-
- backupRestoreThenCheck(solrClient, verifier);
- indexDocs(getCollectionName(), false);
- backupRestoreThenCheck(solrClient, verifier);
-
- // test list backups
- CollectionAdminResponse resp =
- CollectionAdminRequest.listBackup(backupName)
- .setBackupLocation(backupLocation)
- .setBackupRepository(BACKUP_REPO_NAME)
- .process(cluster.getSolrClient());
- ArrayList backups = (ArrayList) resp.getResponse().get("backups");
- assertEquals(3, backups.size());
-
- // test delete backups
- resp = CollectionAdminRequest.deleteBackupByRecency(backupName, 4)
- .setRepositoryName(BACKUP_REPO_NAME)
- .setLocation(backupLocation)
- .process(cluster.getSolrClient());
- assertEquals(null, resp.getResponse().get("deleted"));
-
- resp = CollectionAdminRequest.deleteBackupByRecency(backupName, 3)
- .setRepositoryName(BACKUP_REPO_NAME)
- .setLocation(backupLocation)
- .process(cluster.getSolrClient());
- assertEquals(null, resp.getResponse().get("deleted"));
-
- resp = CollectionAdminRequest.deleteBackupByRecency(backupName, 2)
- .setRepositoryName(BACKUP_REPO_NAME)
- .setLocation(backupLocation)
- .process(cluster.getSolrClient());
- assertEquals(1, resp.getResponse()._get("deleted[0]/backupId", null));
-
- resp = CollectionAdminRequest.deleteBackupById(backupName, 3)
- .setRepositoryName(BACKUP_REPO_NAME)
- .setLocation(backupLocation)
- .process(cluster.getSolrClient());
- assertEquals(3, resp.getResponse()._get("deleted[0]/backupId", null));
-
-
- simpleRestoreAndCheckDocCount(solrClient, backupLocation, backupName);
-
- // test purge backups
- // purging first since there may corrupted files were uploaded
- resp = CollectionAdminRequest.deleteBackupPurgeUnusedFiles(backupName)
- .setRepositoryName(BACKUP_REPO_NAME)
- .setLocation(backupLocation)
- .process(cluster.getSolrClient());
-
- addDummyFileToIndex(repository, backupPaths.getIndexDir(), "dummy-files-1");
- addDummyFileToIndex(repository, backupPaths.getIndexDir(), "dummy-files-2");
- resp = CollectionAdminRequest.deleteBackupPurgeUnusedFiles(backupName)
- .setRepositoryName(BACKUP_REPO_NAME)
- .setLocation(backupLocation)
- .process(cluster.getSolrClient());
- assertEquals(2, ((NamedList)resp.getResponse().get("deleted")).get("numIndexFiles"));
-
- new UpdateRequest()
- .deleteByQuery("*:*")
- .commit(cluster.getSolrClient(), getCollectionName());
- indexDocs(getCollectionName(), false);
- // corrupt index files
- corruptIndexFiles();
- try {
- log.info("Create backup after corrupt index files");
- CollectionAdminRequest.Backup backup = CollectionAdminRequest.backupCollection(getCollectionName(), backupName)
- .setLocation(backupLocation)
- .setIncremental(true)
- .setMaxNumberBackupPoints(3)
- .setRepositoryName(BACKUP_REPO_NAME);
- if (random().nextBoolean()) {
- RequestStatusState state = backup.processAndWait(cluster.getSolrClient(), 1000);
- if (state != RequestStatusState.FAILED) {
- fail("This backup should be failed");
- }
- } else {
- CollectionAdminResponse rsp = backup.process(cluster.getSolrClient());
- fail("This backup should be failed");
- }
- } catch (Exception e) {
- // expected
- e.printStackTrace();
- }
- }
+ }
+
+ private void addDummyFileToIndex(BackupRepository repository, URI indexDir, String fileName)
+ throws IOException {
+ try (OutputStream os = repository.createOutput(repository.resolve(indexDir, fileName))) {
+ os.write(100);
+ os.write(101);
+ os.write(102);
}
-
- protected void corruptIndexFiles() throws IOException {
- Collection<Slice> slices = getCollectionState(getCollectionName()).getSlices();
- Slice slice = slices.iterator().next();
- JettySolrRunner leaderNode = cluster.getReplicaJetty(slice.getLeader());
-
- SolrCore solrCore = leaderNode.getCoreContainer().getCore(slice.getLeader().getCoreName());
- Set<String> fileNames = new HashSet<>(solrCore.getDeletionPolicy().getLatestCommit().getFileNames());
- File indexFolder = new File(solrCore.getIndexDir());
- File fileGetCorrupted = Stream.of(Objects.requireNonNull(indexFolder.listFiles()))
- .filter(x -> fileNames.contains(x.getName()))
- .findAny().get();
- try (FileInputStream fis = new FileInputStream(fileGetCorrupted)){
- byte[] contents = fis.readAllBytes();
- contents[contents.length - CodecUtil.footerLength() - 1] += 1;
- contents[contents.length - CodecUtil.footerLength() - 2] += 1;
- contents[contents.length - CodecUtil.footerLength() - 3] += 1;
- contents[contents.length - CodecUtil.footerLength() - 4] += 1;
- try (FileOutputStream fos = new FileOutputStream(fileGetCorrupted)) {
- fos.write(contents);
- }
- } finally {
- solrCore.close();
- }
+ }
+
+ private void backupRestoreThenCheck(
+ CloudSolrClient solrClient, IncrementalBackupVerifier verifier) throws Exception {
+ verifier.incrementalBackupThenVerify();
+
+ if (random().nextBoolean())
+ simpleRestoreAndCheckDocCount(solrClient, verifier.backupLocation, verifier.backupName);
+ }
+
+ private void simpleRestoreAndCheckDocCount(
+ CloudSolrClient solrClient, String backupLocation, String backupName) throws Exception {
+ Map<String, Integer> origShardToDocCount =
+ AbstractCloudBackupRestoreTestCase.getShardToDocCountMap(
+ solrClient, getCollectionState(getCollectionName()));
+
+ String restoreCollectionName = getCollectionName() + "_restored";
+
+ randomlyPrecreateRestoreCollection(restoreCollectionName, "conf1", NUM_SHARDS, REPL_FACTOR);
+ CollectionAdminRequest.restoreCollection(restoreCollectionName, backupName)
+ .setLocation(backupLocation)
+ .setRepositoryName(BACKUP_REPO_NAME)
+ .process(solrClient);
+
+ AbstractDistribZkTestBase.waitForRecoveriesToFinish(
+ restoreCollectionName,
+ cluster.getSolrClient().getZkStateReader(),
+ log.isDebugEnabled(),
+ true,
+ 30);
+
+ // check num docs are the same
+ assertEquals(
+ origShardToDocCount,
+ AbstractCloudBackupRestoreTestCase.getShardToDocCountMap(
+ solrClient, getCollectionState(restoreCollectionName)));
+
+ // this methods may get invoked multiple times, collection must be cleanup
+ CollectionAdminRequest.deleteCollection(restoreCollectionName).process(solrClient);
+ }
+
+ private void indexDocs(String collectionName, int numDocs, boolean useUUID) throws Exception {
+ Random random = new Random(docsSeed);
+
+ List<SolrInputDocument> docs = new ArrayList<>(numDocs);
+ for (int i = 0; i < numDocs; i++) {
+ SolrInputDocument doc = new SolrInputDocument();
+ doc.addField("id", (useUUID ? java.util.UUID.randomUUID().toString() : i));
+ doc.addField("shard_s", "shard" + (1 + random.nextInt(NUM_SHARDS))); // for implicit router
+ docs.add(doc);
}
- private void addDummyFileToIndex(BackupRepository repository, URI indexDir, String fileName) throws IOException {
- try (OutputStream os = repository.createOutput(repository.resolve(indexDir, fileName))){
- os.write(100);
- os.write(101);
- os.write(102);
- }
+ CloudSolrClient client = cluster.getSolrClient();
+ client.add(collectionName, docs); // batch
+ client.commit(collectionName);
+
+ log.info("Indexed {} docs to collection: {}", numDocs, collectionName);
+ }
+
+ private int indexDocs(String collectionName, boolean useUUID) throws Exception {
+ Random random =
+ new Random(
+ docsSeed); // use a constant seed for the whole test run so that we can easily re-index.
+ int numDocs = random.nextInt(100) + 5;
+ indexDocs(collectionName, numDocs, useUUID);
+ return numDocs;
+ }
+
+ private void randomlyPrecreateRestoreCollection(
+ String restoreCollectionName, String configName, int numShards, int numReplicas)
+ throws Exception {
+ if (random().nextBoolean()) {
+ CollectionAdminRequest.createCollection(
+ restoreCollectionName, configName, numShards, numReplicas)
+ .process(cluster.getSolrClient());
+ cluster.waitForActiveCollection(restoreCollectionName, numShards, numShards * numReplicas);
}
-
- private void backupRestoreThenCheck(CloudSolrClient solrClient,
- IncrementalBackupVerifier verifier) throws Exception {
- verifier.incrementalBackupThenVerify();
-
- if( random().nextBoolean() )
- simpleRestoreAndCheckDocCount(solrClient, verifier.backupLocation, verifier.backupName);
+ }
+
+ private long getNumDocsInCollection(String collectionName) throws Exception {
+ return new QueryRequest(new SolrQuery("*:*"))
+ .process(cluster.getSolrClient(), collectionName)
+ .getResults()
+ .getNumFound();
+ }
+
+ private class IncrementalBackupVerifier {
+ private BackupRepository repository;
+ private URI backupURI;
+ private String backupLocation;
+ private String backupName;
+ private BackupFilePaths incBackupFiles;
+
+ private Map<String, Collection<String>> lastShardCommitToBackupFiles = new HashMap<>();
+ // the first generation after calling backup is zero
+ private int numBackup = -1;
+ private int maxNumberOfBackupToKeep = 4;
+
+ IncrementalBackupVerifier(
+ BackupRepository repository,
+ String backupLocation,
+ String backupName,
+ String collection,
+ int maxNumberOfBackupToKeep) {
+ this.repository = repository;
+ this.backupLocation = backupLocation;
+ this.backupURI =
+ repository.resolveDirectory(repository.createURI(backupLocation), backupName, collection);
+ this.incBackupFiles = new BackupFilePaths(repository, this.backupURI);
+ this.backupName = backupName;
+ this.maxNumberOfBackupToKeep = maxNumberOfBackupToKeep;
}
- private void simpleRestoreAndCheckDocCount(CloudSolrClient solrClient, String backupLocation, String backupName) throws Exception{
- Map<String, Integer> origShardToDocCount = AbstractCloudBackupRestoreTestCase.getShardToDocCountMap(solrClient, getCollectionState(getCollectionName()));
-
- String restoreCollectionName = getCollectionName() + "_restored";
-
- randomlyPrecreateRestoreCollection(restoreCollectionName, "conf1", NUM_SHARDS, REPL_FACTOR);
- CollectionAdminRequest.restoreCollection(restoreCollectionName, backupName)
- .setLocation(backupLocation)
- .setRepositoryName(BACKUP_REPO_NAME)
- .process(solrClient);
-
- AbstractDistribZkTestBase.waitForRecoveriesToFinish(
- restoreCollectionName, cluster.getSolrClient().getZkStateReader(), log.isDebugEnabled(), true, 30);
-
- // check num docs are the same
- assertEquals(origShardToDocCount, AbstractCloudBackupRestoreTestCase.getShardToDocCountMap(solrClient, getCollectionState(restoreCollectionName)));
-
- // this methods may get invoked multiple times, collection must be cleanup
- CollectionAdminRequest.deleteCollection(restoreCollectionName).process(solrClient);
- }
-
-
- private void indexDocs(String collectionName, int numDocs, boolean useUUID) throws Exception {
- Random random = new Random(docsSeed);
-
- List<SolrInputDocument> docs = new ArrayList<>(numDocs);
- for (int i=0; i<numDocs; i++) {
- SolrInputDocument doc = new SolrInputDocument();
- doc.addField("id", (useUUID ? java.util.UUID.randomUUID().toString() : i));
- doc.addField("shard_s", "shard" + (1 + random.nextInt(NUM_SHARDS))); // for implicit router
- docs.add(doc);
+ @SuppressWarnings("rawtypes")
+ private void backupThenWait() throws SolrServerException, IOException {
+ CollectionAdminRequest.Backup backup =
+ CollectionAdminRequest.backupCollection(getCollectionName(), backupName)
+ .setLocation(backupLocation)
+ .setIncremental(true)
+ .setMaxNumberBackupPoints(maxNumberOfBackupToKeep)
+ .setRepositoryName(BACKUP_REPO_NAME);
+ if (random().nextBoolean()) {
+ try {
+ RequestStatusState state = backup.processAndWait(cluster.getSolrClient(), 1000);
+ assertEquals(RequestStatusState.COMPLETED, state);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
}
-
- CloudSolrClient client = cluster.getSolrClient();
- client.add(collectionName, docs); //batch
- client.commit(collectionName);
-
- log.info("Indexed {} docs to collection: {}", numDocs, collectionName);
+ numBackup++;
+ } else {
+ CollectionAdminResponse rsp = backup.process(cluster.getSolrClient());
+ assertEquals(0, rsp.getStatus());
+ NamedList resp = (NamedList) rsp.getResponse().get("response");
+ numBackup++;
+ assertEquals(numBackup, resp.get("backupId"));
+ ;
+ }
}
- private int indexDocs(String collectionName, boolean useUUID) throws Exception {
- Random random = new Random(docsSeed);// use a constant seed for the whole test run so that we can easily re-index.
- int numDocs = random.nextInt(100) + 5;
- indexDocs(collectionName, numDocs, useUUID);
- return numDocs;
+ void incrementalBackupThenVerify() throws IOException, SolrServerException {
+ int numCopiedFiles = copiedFiles().size();
+ backupThenWait();
+ List<URI> newFilesCopiedOver = copiedFiles().subList(numCopiedFiles, copiedFiles().size());
+ verify(newFilesCopiedOver);
}
- private void randomlyPrecreateRestoreCollection(String restoreCollectionName, String configName, int numShards, int numReplicas) throws Exception {
- if (random().nextBoolean()) {
- CollectionAdminRequest.createCollection(restoreCollectionName, configName, numShards, numReplicas)
- .process(cluster.getSolrClient());
- cluster.waitForActiveCollection(restoreCollectionName, numShards, numShards*numReplicas);
- }
+ ShardBackupMetadata getLastShardBackupId(String shardName) throws IOException {
+ ShardBackupId shardBackupId =
+ BackupProperties.readFromLatest(repository, backupURI)
+ .flatMap(bp -> bp.getShardBackupIdFor(shardName))
+ .get();
+ return ShardBackupMetadata.from(
+ repository,
+ new BackupFilePaths(repository, backupURI).getShardBackupMetadataDir(),
+ shardBackupId);
}
- private long getNumDocsInCollection(String collectionName) throws Exception {
- return new QueryRequest(new SolrQuery("*:*")).process(cluster.getSolrClient(), collectionName).getResults().getNumFound();
+ private void assertIndexInputEquals(IndexInput in1, IndexInput in2) throws IOException {
+ assertEquals(in1.length(), in2.length());
+ for (int i = 0; i < in1.length(); i++) {
+ assertEquals(in1.readByte(), in2.readByte());
+ }
}
- private class IncrementalBackupVerifier {
- private BackupRepository repository;
- private URI backupURI;
- private String backupLocation;
- private String backupName;
- private BackupFilePaths incBackupFiles;
-
- private Map<String, Collection<String>> lastShardCommitToBackupFiles = new HashMap<>();
- // the first generation after calling backup is zero
- private int numBackup = -1;
- private int maxNumberOfBackupToKeep = 4;
-
- IncrementalBackupVerifier(BackupRepository repository, String backupLocation,
- String backupName, String collection, int maxNumberOfBackupToKeep) {
- this.repository = repository;
- this.backupLocation = backupLocation;
- this.backupURI = repository.resolveDirectory(repository.createURI(backupLocation), backupName, collection);
- this.incBackupFiles = new BackupFilePaths(repository, this.backupURI);
- this.backupName = backupName;
- this.maxNumberOfBackupToKeep = maxNumberOfBackupToKeep;
- }
-
- @SuppressWarnings("rawtypes")
- private void backupThenWait() throws SolrServerException, IOException {
- CollectionAdminRequest.Backup backup = CollectionAdminRequest.backupCollection(getCollectionName(), backupName)
- .setLocation(backupLocation)
- .setIncremental(true)
- .setMaxNumberBackupPoints(maxNumberOfBackupToKeep)
- .setRepositoryName(BACKUP_REPO_NAME);
- if (random().nextBoolean()) {
- try {
- RequestStatusState state = backup.processAndWait(cluster.getSolrClient(), 1000);
- assertEquals(RequestStatusState.COMPLETED, state);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- numBackup++;
- } else {
- CollectionAdminResponse rsp = backup.process(cluster.getSolrClient());
- assertEquals(0, rsp.getStatus());
- NamedList resp = (NamedList) rsp.getResponse().get("response");
- numBackup++;
- assertEquals(numBackup, resp.get("backupId"));;
- }
- }
-
- void incrementalBackupThenVerify() throws IOException, SolrServerException {
- int numCopiedFiles = copiedFiles().size();
- backupThenWait();
- List<URI> newFilesCopiedOver = copiedFiles().subList(numCopiedFiles, copiedFiles().size());
- verify(newFilesCopiedOver);
- }
-
- ShardBackupMetadata getLastShardBackupId(String shardName) throws IOException {
- ShardBackupId shardBackupId = BackupProperties
- .readFromLatest(repository, backupURI)
- .flatMap(bp -> bp.getShardBackupIdFor(shardName))
- .get();
- return ShardBackupMetadata.from(repository, new BackupFilePaths(repository, backupURI).getShardBackupMetadataDir(), shardBackupId);
- }
-
- private void assertIndexInputEquals(IndexInput in1, IndexInput in2) throws IOException {
- assertEquals(in1.length(), in2.length());
- for (int i = 0; i < in1.length(); i++) {
- assertEquals(in1.readByte(), in2.readByte());
- }
- }
-
- private void assertFolderAreSame(URI uri1, URI uri2) throws IOException {
- String[] files1 = repository.listAll(uri1);
- String[] files2 = repository.listAll(uri2);
- Arrays.sort(files1);
- Arrays.sort(files2);
-
- assertArrayEquals(files1, files2);
-
- for (int i = 0; i < files1.length; i++) {
- URI file1Uri = repository.resolve(uri1, files1[i]);
- URI file2Uri = repository.resolve(uri2, files2[i]);
- assertEquals(repository.getPathType(file1Uri), repository.getPathType(file2Uri));
- if (repository.getPathType(file1Uri) == BackupRepository.PathType.DIRECTORY) {
- assertFolderAreSame(file1Uri, file2Uri);
- } else {
- try (IndexInput in1 = repository.openInput(uri1, files1[i], IOContext.READONCE);
- IndexInput in2 = repository.openInput(uri1, files1[i], IOContext.READONCE)) {
- assertIndexInputEquals(in1, in2);
- }
- }
- }
+ private void assertFolderAreSame(URI uri1, URI uri2) throws IOException {
+ String[] files1 = repository.listAll(uri1);
+ String[] files2 = repository.listAll(uri2);
+ Arrays.sort(files1);
+ Arrays.sort(files2);
+
+ assertArrayEquals(files1, files2);
+
+ for (int i = 0; i < files1.length; i++) {
+ URI file1Uri = repository.resolve(uri1, files1[i]);
+ URI file2Uri = repository.resolve(uri2, files2[i]);
+ assertEquals(repository.getPathType(file1Uri), repository.getPathType(file2Uri));
+ if (repository.getPathType(file1Uri) == BackupRepository.PathType.DIRECTORY) {
+ assertFolderAreSame(file1Uri, file2Uri);
+ } else {
+ try (IndexInput in1 = repository.openInput(uri1, files1[i], IOContext.READONCE);
+ IndexInput in2 = repository.openInput(uri1, files1[i], IOContext.READONCE)) {
+ assertIndexInputEquals(in1, in2);
+ }
}
+ }
+ }
- public void verify(List<URI> newFilesCopiedOver) throws IOException {
- //Verify zk files are reuploaded to a appropriate each time a backup is called
- //TODO make a little change to zk files and make sure that backed up files match with zk data
- BackupId prevBackupId = new BackupId(Math.max(0, numBackup - 1));
-
- URI backupPropertiesFile = repository.resolve(backupURI, "backup_"+numBackup+".properties");
- URI zkBackupFolder = repository.resolve(backupURI, "zk_backup_"+numBackup);
- assertTrue(repository.exists(backupPropertiesFile));
- assertTrue(repository.exists(zkBackupFolder));
- assertFolderAreSame(repository.resolveDirectory(backupURI, BackupFilePaths.getZkStateDir(prevBackupId)), zkBackupFolder);
-
- // verify indexes file
- for(Slice slice : getCollectionState(getCollectionName()).getSlices()) {
- Replica leader = slice.getLeader();
- final ShardBackupMetadata shardBackupMetadata = getLastShardBackupId(slice.getName());
- assertNotNull(shardBackupMetadata);
-
- try (SolrCore solrCore = cluster.getReplicaJetty(leader).getCoreContainer().getCore(leader.getCoreName())) {
- Directory dir = solrCore.getDirectoryFactory().get(solrCore.getIndexDir(), DirectoryFactory.DirContext.DEFAULT, solrCore.getSolrConfig().indexConfig.lockType);
- try {
- URI indexDir = incBackupFiles.getIndexDir();
- IndexCommit lastCommit = solrCore.getDeletionPolicy().getLatestCommit();
-
- Collection<String> newBackupFiles = newIndexFilesComparedToLastBackup(slice.getName(), lastCommit).stream()
- .map(indexFile -> {
- Optional<ShardBackupMetadata.BackedFile> backedFile = shardBackupMetadata.getFile(indexFile);
- assertTrue(backedFile.isPresent());
- return backedFile.get().uniqueFileName;
- })
- .collect(Collectors.toList());
-
- lastCommit.getFileNames().forEach(
- f -> {
- Optional<ShardBackupMetadata.BackedFile> backedFile = shardBackupMetadata.getFile(f);
- assertTrue(backedFile.isPresent());
- String uniqueFileName = backedFile.get().uniqueFileName;
-
- if (newBackupFiles.contains(uniqueFileName)) {
- assertTrue(newFilesCopiedOver.contains(repository.resolve(indexDir, uniqueFileName)));
- }
-
- try {
- Checksum localChecksum = repository.checksum(dir, f);
- Checksum remoteChecksum = backedFile.get().fileChecksum;
- assertEquals(localChecksum.checksum, remoteChecksum.checksum);
- assertEquals(localChecksum.size, remoteChecksum.size);
- } catch (IOException e) {
- throw new AssertionError(e);
- }
- }
- );
-
- assertEquals("Incremental backup stored more files than needed", lastCommit.getFileNames().size(), shardBackupMetadata.listOriginalFileNames().size());
- } finally {
- solrCore.getDirectoryFactory().release(dir);
- }
- }
- }
+ public void verify(List<URI> newFilesCopiedOver) throws IOException {
+ // Verify zk files are reuploaded to a appropriate each time a backup is called
+ // TODO make a little change to zk files and make sure that backed up files match with zk data
+ BackupId prevBackupId = new BackupId(Math.max(0, numBackup - 1));
+
+ URI backupPropertiesFile =
+ repository.resolve(backupURI, "backup_" + numBackup + ".properties");
+ URI zkBackupFolder = repository.resolve(backupURI, "zk_backup_" + numBackup);
+ assertTrue(repository.exists(backupPropertiesFile));
+ assertTrue(repository.exists(zkBackupFolder));
+ assertFolderAreSame(
+ repository.resolveDirectory(backupURI, BackupFilePaths.getZkStateDir(prevBackupId)),
+ zkBackupFolder);
+
+ // verify indexes file
+ for (Slice slice : getCollectionState(getCollectionName()).getSlices()) {
+ Replica leader = slice.getLeader();
+ final ShardBackupMetadata shardBackupMetadata = getLastShardBackupId(slice.getName());
+ assertNotNull(shardBackupMetadata);
+
+ try (SolrCore solrCore =
+ cluster.getReplicaJetty(leader).getCoreContainer().getCore(leader.getCoreName())) {
+ Directory dir =
+ solrCore
+ .getDirectoryFactory()
+ .get(
+ solrCore.getIndexDir(),
+ DirectoryFactory.DirContext.DEFAULT,
+ solrCore.getSolrConfig().indexConfig.lockType);
+ try {
+ URI indexDir = incBackupFiles.getIndexDir();
+ IndexCommit lastCommit = solrCore.getDeletionPolicy().getLatestCommit();
+
+ Collection<String> newBackupFiles =
+ newIndexFilesComparedToLastBackup(slice.getName(), lastCommit).stream()
+ .map(
+ indexFile -> {
+ Optional<ShardBackupMetadata.BackedFile> backedFile =
+ shardBackupMetadata.getFile(indexFile);
+ assertTrue(backedFile.isPresent());
+ return backedFile.get().uniqueFileName;
+ })
+ .collect(Collectors.toList());
+
+ lastCommit
+ .getFileNames()
+ .forEach(
+ f -> {
+ Optional<ShardBackupMetadata.BackedFile> backedFile =
+ shardBackupMetadata.getFile(f);
+ assertTrue(backedFile.isPresent());
+ String uniqueFileName = backedFile.get().uniqueFileName;
+
+ if (newBackupFiles.contains(uniqueFileName)) {
+ assertTrue(
+ newFilesCopiedOver.contains(
+ repository.resolve(indexDir, uniqueFileName)));
+ }
+
+ try {
+ Checksum localChecksum = repository.checksum(dir, f);
+ Checksum remoteChecksum = backedFile.get().fileChecksum;
+ assertEquals(localChecksum.checksum, remoteChecksum.checksum);
+ assertEquals(localChecksum.size, remoteChecksum.size);
+ } catch (IOException e) {
+ throw new AssertionError(e);
+ }
+ });
+
+ assertEquals(
+ "Incremental backup stored more files than needed",
+ lastCommit.getFileNames().size(),
+ shardBackupMetadata.listOriginalFileNames().size());
+ } finally {
+ solrCore.getDirectoryFactory().release(dir);
+ }
}
+ }
+ }
- private Collection<String> newIndexFilesComparedToLastBackup(String shardName, IndexCommit currentCommit) throws IOException {
- Collection<String> oldFiles = lastShardCommitToBackupFiles.put(shardName, currentCommit.getFileNames());
- if (oldFiles == null)
- oldFiles = new ArrayList<>();
+ private Collection<String> newIndexFilesComparedToLastBackup(
+ String shardName, IndexCommit currentCommit) throws IOException {
+ Collection<String> oldFiles =
+ lastShardCommitToBackupFiles.put(shardName, currentCommit.getFileNames());
+ if (oldFiles == null) oldFiles = new ArrayList<>();
- List<String> newFiles = new ArrayList<>(currentCommit.getFileNames());
- newFiles.removeAll(oldFiles);
- return newFiles;
- }
+ List<String> newFiles = new ArrayList<>(currentCommit.getFileNames());
+ newFiles.removeAll(oldFiles);
+ return newFiles;
}
+ }
}
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/package-info.java b/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/package-info.java
index e0047cef9af..071898b53c9 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/package-info.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/api/collections/package-info.java
@@ -15,7 +15,5 @@
* limitations under the License.
*/
-/**
- * Test framework classes for collection APIs
- */
-package org.apache.solr.cloud.api.collections;
\ No newline at end of file
+/** Test framework classes for collection APIs */
+package org.apache.solr.cloud.api.collections;
diff --git a/solr/test-framework/src/java/org/apache/solr/core/AbstractBadConfigTestBase.java b/solr/test-framework/src/java/org/apache/solr/core/AbstractBadConfigTestBase.java
index 1fa1c58da59..adeebea71c3 100644
--- a/solr/test-framework/src/java/org/apache/solr/core/AbstractBadConfigTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/core/AbstractBadConfigTestBase.java
@@ -16,57 +16,53 @@
*/
package org.apache.solr.core;
-import org.apache.solr.SolrTestCaseJ4;
-
import java.util.Map;
import java.util.regex.Pattern;
+import org.apache.solr.SolrTestCaseJ4;
public abstract class AbstractBadConfigTestBase extends SolrTestCaseJ4 {
/**
- * Given a solrconfig.xml file name, a schema file name, and an
- * expected errString, asserts that initializing a core with these
- * files causes an error matching the specified errString ot be thrown.
+ * Given a solrconfig.xml file name, a schema file name, and an expected errString, asserts that
+ * initializing a core with these files causes an error matching the specified errString ot be
+ * thrown.
*/
- protected final void assertConfigs(final String solrconfigFile,
- final String schemaFile,
- final String errString)
+ protected final void assertConfigs(
+ final String solrconfigFile, final String schemaFile, final String errString)
throws Exception {
assertConfigs(solrconfigFile, schemaFile, null, errString);
}
- /**
- * Given a solrconfig.xml file name, a schema file name, a solr home directory,
- * and an expected errString, asserts that initializing a core with these
- * files causes an error matching the specified errString ot be thrown.
- */
- protected final void assertConfigs(final String solrconfigFile,
- final String schemaFile,
- final String solrHome,
- final String errString)
- throws Exception {
+ /**
+ * Given a solrconfig.xml file name, a schema file name, a solr home directory, and an expected
+ * errString, asserts that initializing a core with these files causes an error matching the
+ * specified errString ot be thrown.
+ */
+ protected final void assertConfigs(
+ final String solrconfigFile,
+ final String schemaFile,
+ final String solrHome,
+ final String errString)
+ throws Exception {
ignoreException(Pattern.quote(errString));
try {
if (null == solrHome) {
- initCore( solrconfigFile, schemaFile );
+ initCore(solrconfigFile, schemaFile);
} else {
- initCore( solrconfigFile, schemaFile, solrHome );
+ initCore(solrconfigFile, schemaFile, solrHome);
}
CoreContainer cc = h.getCoreContainer();
- for (Map.Entry<String, CoreContainer.CoreLoadFailure> entry : cc.getCoreInitFailures().entrySet()) {
- if (matches(entry.getValue().exception, errString))
- return;
+ for (Map.Entry<String, CoreContainer.CoreLoadFailure> entry :
+ cc.getCoreInitFailures().entrySet()) {
+ if (matches(entry.getValue().exception, errString)) return;
}
- }
- catch (Exception e) {
- if (matches(e, errString))
- return;
+ } catch (Exception e) {
+ if (matches(e, errString)) return;
throw e;
- }
- finally {
+ } finally {
deleteCore();
resetExceptionIgnores();
}
@@ -75,10 +71,8 @@ public abstract class AbstractBadConfigTestBase extends SolrTestCaseJ4 {
private static boolean matches(Exception e, String errString) {
for (Throwable t = e; t != null; t = t.getCause()) {
- if (t.getMessage() != null && -1 != t.getMessage().indexOf(errString))
- return true;
+ if (t.getMessage() != null && -1 != t.getMessage().indexOf(errString)) return true;
}
return false;
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/core/MockDirectoryFactory.java b/solr/test-framework/src/java/org/apache/solr/core/MockDirectoryFactory.java
index 07e1d0d14c6..643561abbd5 100644
--- a/solr/test-framework/src/java/org/apache/solr/core/MockDirectoryFactory.java
+++ b/solr/test-framework/src/java/org/apache/solr/core/MockDirectoryFactory.java
@@ -18,7 +18,6 @@ package org.apache.solr.core;
import java.io.File;
import java.io.IOException;
-
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.LockFactory;
import org.apache.lucene.store.MockDirectoryWrapper;
@@ -27,15 +26,17 @@ import org.apache.lucene.store.NoLockFactory;
import org.apache.lucene.store.TrackingDirectoryWrapper;
import org.apache.lucene.util.LuceneTestCase;
-/**
- * Opens a directory with {@link LuceneTestCase#newDirectory()}
- */
+/** Opens a directory with {@link LuceneTestCase#newDirectory()} */
public class MockDirectoryFactory extends EphemeralDirectoryFactory {
-
- public static final String SOLR_TESTS_ALLOW_READING_FILES_STILL_OPEN_FOR_WRITE = "solr.tests.allow_reading_files_still_open_for_write";
- public static final String SOLR_TESTS_USING_MOCK_DIRECTORY_WRAPPER = "solr.tests.using_mock_directory_wrapper";
- private boolean allowReadingFilesStillOpenForWrite = Boolean.getBoolean(SOLR_TESTS_ALLOW_READING_FILES_STILL_OPEN_FOR_WRITE);
- private boolean useMockDirectoryWrapper = Boolean.getBoolean(SOLR_TESTS_USING_MOCK_DIRECTORY_WRAPPER);
+
+ public static final String SOLR_TESTS_ALLOW_READING_FILES_STILL_OPEN_FOR_WRITE =
+ "solr.tests.allow_reading_files_still_open_for_write";
+ public static final String SOLR_TESTS_USING_MOCK_DIRECTORY_WRAPPER =
+ "solr.tests.using_mock_directory_wrapper";
+ private boolean allowReadingFilesStillOpenForWrite =
+ Boolean.getBoolean(SOLR_TESTS_ALLOW_READING_FILES_STILL_OPEN_FOR_WRITE);
+ private boolean useMockDirectoryWrapper =
+ Boolean.getBoolean(SOLR_TESTS_USING_MOCK_DIRECTORY_WRAPPER);
@Override
protected LockFactory createLockFactory(String rawLockType) throws IOException {
@@ -43,54 +44,54 @@ public class MockDirectoryFactory extends EphemeralDirectoryFactory {
}
@Override
- protected Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException {
+ protected Directory create(String path, LockFactory lockFactory, DirContext dirContext)
+ throws IOException {
Directory dir;
if (useMockDirectoryWrapper) dir = LuceneTestCase.newMockDirectory();
else dir = LuceneTestCase.newDirectory(); // we ignore the given lock factory
-
+
Directory cdir = reduce(dir);
cdir = reduce(cdir);
cdir = reduce(cdir);
-
+
if (cdir instanceof MockDirectoryWrapper) {
MockDirectoryWrapper mockDirWrapper = (MockDirectoryWrapper) cdir;
-
+
// we can't currently do this check because of how
// Solr has to reboot a new Directory sometimes when replicating
// or rolling back - the old directory is closed and the following
// test assumes it can open an IndexWriter when that happens - we
- // have a new Directory for the same dir and still an open IW at
+ // have a new Directory for the same dir and still an open IW at
// this point
mockDirWrapper.setAssertNoUnrefencedFilesOnClose(false);
-
+
// ram dirs in cores that are restarted end up empty
// and check index fails
mockDirWrapper.setCheckIndexOnClose(false);
-
+
if (allowReadingFilesStillOpenForWrite) {
mockDirWrapper.setAllowReadingFilesStillOpenForWrite(true);
}
}
-
+
return dir;
}
private Directory reduce(Directory dir) {
Directory cdir = dir;
if (dir instanceof NRTCachingDirectory) {
- cdir = ((NRTCachingDirectory)dir).getDelegate();
+ cdir = ((NRTCachingDirectory) dir).getDelegate();
}
if (cdir instanceof TrackingDirectoryWrapper) {
- cdir = ((TrackingDirectoryWrapper)dir).getDelegate();
+ cdir = ((TrackingDirectoryWrapper) dir).getDelegate();
}
return cdir;
}
-
+
@Override
public boolean isAbsolute(String path) {
// TODO: kind of a hack - we don't know what the delegate is, so
// we treat it as file based since this works on most ephem impls
return new File(path).isAbsolute();
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/core/MockFSDirectoryFactory.java b/solr/test-framework/src/java/org/apache/solr/core/MockFSDirectoryFactory.java
index 0592294f361..1265b4606a9 100644
--- a/solr/test-framework/src/java/org/apache/solr/core/MockFSDirectoryFactory.java
+++ b/solr/test-framework/src/java/org/apache/solr/core/MockFSDirectoryFactory.java
@@ -19,7 +19,6 @@ package org.apache.solr.core;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
-
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.LockFactory;
import org.apache.lucene.store.MockDirectoryWrapper;
@@ -27,44 +26,43 @@ import org.apache.lucene.store.NRTCachingDirectory;
import org.apache.lucene.store.TrackingDirectoryWrapper;
import org.apache.lucene.util.LuceneTestCase;
-/**
- * Opens a directory with {@link LuceneTestCase#newFSDirectory(Path)}
- */
+/** Opens a directory with {@link LuceneTestCase#newFSDirectory(Path)} */
public class MockFSDirectoryFactory extends StandardDirectoryFactory {
@Override
- public Directory create(String path, LockFactory lockFactory, DirContext dirContext) throws IOException {
+ public Directory create(String path, LockFactory lockFactory, DirContext dirContext)
+ throws IOException {
Directory dir = LuceneTestCase.newFSDirectory(Path.of(path), lockFactory);
// we can't currently do this check because of how
// Solr has to reboot a new Directory sometimes when replicating
// or rolling back - the old directory is closed and the following
// test assumes it can open an IndexWriter when that happens - we
- // have a new Directory for the same dir and still an open IW at
+ // have a new Directory for the same dir and still an open IW at
// this point
-
+
Directory cdir = reduce(dir);
cdir = reduce(cdir);
cdir = reduce(cdir);
-
+
if (cdir instanceof MockDirectoryWrapper) {
- ((MockDirectoryWrapper)cdir).setAssertNoUnrefencedFilesOnClose(false);
+ ((MockDirectoryWrapper) cdir).setAssertNoUnrefencedFilesOnClose(false);
}
return dir;
}
-
+
@Override
public boolean isAbsolute(String path) {
// TODO: kind of a hack - we don't know what the delegate is, so
// we treat it as file based since this works on most ephem impls
return new File(path).isAbsolute();
}
-
+
private Directory reduce(Directory dir) {
Directory cdir = dir;
if (dir instanceof NRTCachingDirectory) {
- cdir = ((NRTCachingDirectory)dir).getDelegate();
+ cdir = ((NRTCachingDirectory) dir).getDelegate();
} else if (dir instanceof TrackingDirectoryWrapper) {
- cdir = ((TrackingDirectoryWrapper)dir).getDelegate();
+ cdir = ((TrackingDirectoryWrapper) dir).getDelegate();
}
return cdir;
}
diff --git a/solr/test-framework/src/java/org/apache/solr/core/MockQuerySenderListenerReqHandler.java b/solr/test-framework/src/java/org/apache/solr/core/MockQuerySenderListenerReqHandler.java
index 4970f47f775..f70cdc59cbd 100644
--- a/solr/test-framework/src/java/org/apache/solr/core/MockQuerySenderListenerReqHandler.java
+++ b/solr/test-framework/src/java/org/apache/solr/core/MockQuerySenderListenerReqHandler.java
@@ -16,20 +16,15 @@
*/
package org.apache.solr.core;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.solr.common.util.NamedList;
import org.apache.solr.handler.RequestHandlerBase;
import org.apache.solr.metrics.SolrMetricsContext;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
-import org.apache.solr.common.util.NamedList;
import org.apache.solr.security.AuthorizationContext;
-import java.util.concurrent.atomic.AtomicInteger;
-
-
-/**
- *
- *
- **/
+/** */
public class MockQuerySenderListenerReqHandler extends RequestHandlerBase {
public SolrQueryRequest req;
public SolrQueryResponse rsp;
@@ -45,7 +40,8 @@ public class MockQuerySenderListenerReqHandler extends RequestHandlerBase {
@Override
public void initializeMetrics(SolrMetricsContext parentContext, String scope) {
super.initializeMetrics(parentContext, scope);
- solrMetricsContext.gauge(() -> initCounter.intValue(), true, "initCount", getCategory().toString(), scope);
+ solrMetricsContext.gauge(
+ () -> initCounter.intValue(), true, "initCount", getCategory().toString(), scope);
}
@Override
diff --git a/solr/test-framework/src/java/org/apache/solr/core/TrackingBackupRepository.java b/solr/test-framework/src/java/org/apache/solr/core/TrackingBackupRepository.java
index 248fdc62b91..309306356b8 100644
--- a/solr/test-framework/src/java/org/apache/solr/core/TrackingBackupRepository.java
+++ b/solr/test-framework/src/java/org/apache/solr/core/TrackingBackupRepository.java
@@ -24,7 +24,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
-
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
@@ -34,117 +33,119 @@ import org.apache.solr.core.backup.repository.BackupRepository;
import org.apache.solr.core.backup.repository.BackupRepositoryFactory;
public class TrackingBackupRepository implements BackupRepository {
- private static final List<URI> COPIED_FILES = Collections.synchronizedList(new ArrayList<>());
-
- private BackupRepository delegate;
-
- @Override
- public <T> T getConfigProperty(String name) {
- return delegate.getConfigProperty(name);
- }
-
- @Override
- public URI createURI(String path) {
- return delegate.createURI(path);
- }
-
- @Override
- public URI createDirectoryURI(String path) {
- return delegate.createDirectoryURI(path);
- }
-
- @Override
- public URI resolve(URI baseUri, String... pathComponents) {
- return delegate.resolve(baseUri, pathComponents);
- }
-
- @Override
- public URI resolveDirectory(URI baseUri, String... pathComponents) {
- return delegate.resolveDirectory(baseUri, pathComponents);
- }
-
- @Override
- public boolean exists(URI path) throws IOException {
- return delegate.exists(path);
- }
-
- @Override
- public PathType getPathType(URI path) throws IOException {
- return delegate.getPathType(path);
- }
-
- @Override
- public String[] listAll(URI path) throws IOException {
- return delegate.listAll(path);
- }
-
- @Override
- public IndexInput openInput(URI dirPath, String fileName, IOContext ctx) throws IOException {
- return delegate.openInput(dirPath, fileName, ctx);
- }
-
- @Override
- public OutputStream createOutput(URI path) throws IOException {
- return delegate.createOutput(path);
- }
-
- @Override
- public void createDirectory(URI path) throws IOException {
- delegate.createDirectory(path);
- }
-
- @Override
- public void deleteDirectory(URI path) throws IOException {
- delegate.deleteDirectory(path);
- }
-
- @Override
- public void copyIndexFileFrom(Directory sourceDir, String sourceFileName, URI destDir, String destFileName) throws IOException {
- COPIED_FILES.add(delegate.resolve(destDir, destFileName));
- delegate.copyIndexFileFrom(sourceDir, sourceFileName, destDir, destFileName);
- }
-
- @Override
- public void close() throws IOException {
- delegate.close();
- }
-
-
- @Override
- public void delete(URI path, Collection<String> files, boolean ignoreNoSuchFileException) throws IOException {
- delegate.delete(path, files, ignoreNoSuchFileException);
- }
-
- @Override
- public Checksum checksum(Directory dir, String fileName) throws IOException {
- return delegate.checksum(dir, fileName);
- }
-
- @Override
- public void init(NamedList<?> args) {
- BackupRepositoryFactory factory = (BackupRepositoryFactory) args.get("factory");
- SolrResourceLoader loader = (SolrResourceLoader) args.get("loader");
- String repoName = (String) args.get("delegateRepoName");
-
- this.delegate = factory.newInstance(loader, repoName);
- }
-
- /**
- * @return list of files were copied by using {@link #copyFileFrom(Directory, String, URI)}
- */
- public static List<URI> copiedFiles() {
- return new ArrayList<>(COPIED_FILES);
- }
-
- /**
- * Clear all tracking data
- */
- public static void clear() {
- COPIED_FILES.clear();
- }
-
- @Override
- public void copyIndexFileTo(URI sourceRepo, String sourceFileName, Directory dest, String destFileName) throws IOException {
- delegate.copyIndexFileTo(sourceRepo, sourceFileName, dest, destFileName);
- }
+ private static final List<URI> COPIED_FILES = Collections.synchronizedList(new ArrayList<>());
+
+ private BackupRepository delegate;
+
+ @Override
+ public <T> T getConfigProperty(String name) {
+ return delegate.getConfigProperty(name);
+ }
+
+ @Override
+ public URI createURI(String path) {
+ return delegate.createURI(path);
+ }
+
+ @Override
+ public URI createDirectoryURI(String path) {
+ return delegate.createDirectoryURI(path);
+ }
+
+ @Override
+ public URI resolve(URI baseUri, String... pathComponents) {
+ return delegate.resolve(baseUri, pathComponents);
+ }
+
+ @Override
+ public URI resolveDirectory(URI baseUri, String... pathComponents) {
+ return delegate.resolveDirectory(baseUri, pathComponents);
+ }
+
+ @Override
+ public boolean exists(URI path) throws IOException {
+ return delegate.exists(path);
+ }
+
+ @Override
+ public PathType getPathType(URI path) throws IOException {
+ return delegate.getPathType(path);
+ }
+
+ @Override
+ public String[] listAll(URI path) throws IOException {
+ return delegate.listAll(path);
+ }
+
+ @Override
+ public IndexInput openInput(URI dirPath, String fileName, IOContext ctx) throws IOException {
+ return delegate.openInput(dirPath, fileName, ctx);
+ }
+
+ @Override
+ public OutputStream createOutput(URI path) throws IOException {
+ return delegate.createOutput(path);
+ }
+
+ @Override
+ public void createDirectory(URI path) throws IOException {
+ delegate.createDirectory(path);
+ }
+
+ @Override
+ public void deleteDirectory(URI path) throws IOException {
+ delegate.deleteDirectory(path);
+ }
+
+ @Override
+ public void copyIndexFileFrom(
+ Directory sourceDir, String sourceFileName, URI destDir, String destFileName)
+ throws IOException {
+ COPIED_FILES.add(delegate.resolve(destDir, destFileName));
+ delegate.copyIndexFileFrom(sourceDir, sourceFileName, destDir, destFileName);
+ }
+
+ @Override
+ public void close() throws IOException {
+ delegate.close();
+ }
+
+ @Override
+ public void delete(URI path, Collection<String> files, boolean ignoreNoSuchFileException)
+ throws IOException {
+ delegate.delete(path, files, ignoreNoSuchFileException);
+ }
+
+ @Override
+ public Checksum checksum(Directory dir, String fileName) throws IOException {
+ return delegate.checksum(dir, fileName);
+ }
+
+ @Override
+ public void init(NamedList<?> args) {
+ BackupRepositoryFactory factory = (BackupRepositoryFactory) args.get("factory");
+ SolrResourceLoader loader = (SolrResourceLoader) args.get("loader");
+ String repoName = (String) args.get("delegateRepoName");
+
+ this.delegate = factory.newInstance(loader, repoName);
+ }
+
+ /**
+ * @return list of files were copied by using {@link #copyFileFrom(Directory, String, URI)}
+ */
+ public static List<URI> copiedFiles() {
+ return new ArrayList<>(COPIED_FILES);
+ }
+
+ /** Clear all tracking data */
+ public static void clear() {
+ COPIED_FILES.clear();
+ }
+
+ @Override
+ public void copyIndexFileTo(
+ URI sourceRepo, String sourceFileName, Directory dest, String destFileName)
+ throws IOException {
+ delegate.copyIndexFileTo(sourceRepo, sourceFileName, dest, destFileName);
+ }
}
diff --git a/solr/test-framework/src/java/org/apache/solr/handler/BackupRestoreUtils.java b/solr/test-framework/src/java/org/apache/solr/handler/BackupRestoreUtils.java
index ae8ace4c53e..79119b61dd8 100644
--- a/solr/test-framework/src/java/org/apache/solr/handler/BackupRestoreUtils.java
+++ b/solr/test-framework/src/java/org/apache/solr/handler/BackupRestoreUtils.java
@@ -25,7 +25,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
-
import org.apache.commons.io.IOUtils;
import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCase;
@@ -41,10 +40,13 @@ public class BackupRestoreUtils extends SolrTestCase {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- public static int indexDocs(SolrClient leaderClient, String collectionName, long docsSeed) throws IOException, SolrServerException {
+ public static int indexDocs(SolrClient leaderClient, String collectionName, long docsSeed)
+ throws IOException, SolrServerException {
leaderClient.deleteByQuery(collectionName, "*:*");
- Random random = new Random(docsSeed);// use a constant seed for the whole test run so that we can easily re-index.
+ Random random =
+ new Random(
+ docsSeed); // use a constant seed for the whole test run so that we can easily re-index.
int nDocs = TestUtil.nextInt(random, 1, 100);
log.info("Indexing {} test docs", nDocs);
@@ -61,7 +63,8 @@ public class BackupRestoreUtils extends SolrTestCase {
return nDocs;
}
- public static void verifyDocs(int nDocs, SolrClient leaderClient, String collectionName) throws SolrServerException, IOException {
+ public static void verifyDocs(int nDocs, SolrClient leaderClient, String collectionName)
+ throws SolrServerException, IOException {
ModifiableSolrParams queryParams = new ModifiableSolrParams();
queryParams.set("q", "*:*");
QueryResponse response = leaderClient.query(collectionName, queryParams);
@@ -70,14 +73,16 @@ public class BackupRestoreUtils extends SolrTestCase {
assertEquals(nDocs, response.getResults().getNumFound());
}
- public static void runCoreAdminCommand(String baseUrl, String coreName, String action, Map<String,String> params) throws IOException {
+ public static void runCoreAdminCommand(
+ String baseUrl, String coreName, String action, Map<String, String> params)
+ throws IOException {
StringBuilder builder = new StringBuilder();
builder.append(baseUrl);
builder.append("/admin/cores?action=");
builder.append(action);
builder.append("&core=");
builder.append(coreName);
- for (Map.Entry<String,String> p : params.entrySet()) {
+ for (Map.Entry<String, String> p : params.entrySet()) {
builder.append("&");
builder.append(p.getKey());
builder.append("=");
@@ -87,8 +92,20 @@ public class BackupRestoreUtils extends SolrTestCase {
executeHttpRequest(leaderUrl);
}
- public static void runReplicationHandlerCommand(String baseUrl, String coreName, String action, String repoName, String backupName) throws IOException {
- String leaderUrl = baseUrl + "/" + coreName + ReplicationHandler.PATH + "?command=" + action + "&repository="+repoName+"&name="+backupName;
+ public static void runReplicationHandlerCommand(
+ String baseUrl, String coreName, String action, String repoName, String backupName)
+ throws IOException {
+ String leaderUrl =
+ baseUrl
+ + "/"
+ + coreName
+ + ReplicationHandler.PATH
+ + "?command="
+ + action
+ + "&repository="
+ + repoName
+ + "&name="
+ + backupName;
executeHttpRequest(leaderUrl);
}
diff --git a/solr/test-framework/src/java/org/apache/solr/handler/BackupStatusChecker.java b/solr/test-framework/src/java/org/apache/solr/handler/BackupStatusChecker.java
index 1db896811a2..05c7a8b26fa 100644
--- a/solr/test-framework/src/java/org/apache/solr/handler/BackupStatusChecker.java
+++ b/solr/test-framework/src/java/org/apache/solr/handler/BackupStatusChecker.java
@@ -16,36 +16,30 @@
*/
package org.apache.solr.handler;
+import static org.apache.lucene.util.LuceneTestCase.assertNotNull;
+import static org.apache.lucene.util.LuceneTestCase.assertNull;
+import static org.apache.lucene.util.LuceneTestCase.assertTrue;
+import static org.apache.solr.SolrTestCaseJ4.params;
+
import java.lang.invoke.MethodHandles;
import java.util.concurrent.TimeUnit;
-
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.request.GenericSolrRequest;
import org.apache.solr.client.solrj.response.SimpleSolrResponse;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.TimeSource;
import org.apache.solr.util.TimeOut;
-
-import static org.apache.solr.SolrTestCaseJ4.params;
-
-import static org.apache.lucene.util.LuceneTestCase.assertNotNull;
-import static org.apache.lucene.util.LuceneTestCase.assertNull;
-import static org.apache.lucene.util.LuceneTestCase.assertTrue;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- * Helper class for validating when the replication handler has finished a backup.
- *
- */
+/** Helper class for validating when the replication handler has finished a backup. */
public final class BackupStatusChecker {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
+
final SolrClient client;
final String path;
- /**
+ /**
* @param client the client to use in all requests, will not be closed
* @param path the path to use for accessing the /replication handle when using the client
*/
@@ -53,10 +47,10 @@ public final class BackupStatusChecker {
this.client = client;
this.path = path;
}
-
- /**
- * Defaults to a path of <code>/replication</code>
- * (ie: assumes client is configured with a core specific solr URL).
+
+ /**
+ * Defaults to a path of <code>/replication</code> (ie: assumes client is configured with a core
+ * specific solr URL).
*
* @see #BackupStatusChecker(SolrClient,String)
*/
@@ -66,31 +60,33 @@ public final class BackupStatusChecker {
/**
* Convinience wrapper
+ *
* @see #waitForBackupSuccess(String,TimeOut)
*/
- public String waitForBackupSuccess(final String backupName, final int timeLimitInSeconds) throws Exception {
- return waitForBackupSuccess(backupName,
- new TimeOut(timeLimitInSeconds, TimeUnit.SECONDS, TimeSource.NANO_TIME));
+ public String waitForBackupSuccess(final String backupName, final int timeLimitInSeconds)
+ throws Exception {
+ return waitForBackupSuccess(
+ backupName, new TimeOut(timeLimitInSeconds, TimeUnit.SECONDS, TimeSource.NANO_TIME));
}
-
+
/**
* Polls the replication handler's status until the it reports that the specified backupName is
- * completed as a <code>"success"</code> (in which case the method returns the directoryName of the backup)
- * or either <code>"exception"</code> is reported or the <code>timeOut</code> expires
+ * completed as a <code>"success"</code> (in which case the method returns the directoryName of
+ * the backup) or either <code>"exception"</code> is reported or the <code>timeOut</code> expires
* (in either case an assertion is thrown)
- *
- * <p>
- * <b>NOTE:</b> this method is <em>NOT</em> suitable/safe to use in a test where multiple backups are
- * being taken/deleted concurrently, because the replication handler API provides no reliable way to check
- * the results of a specific backup before the results of another backup may overwrite them internally.
- * </p>
- *
+ *
+ * <p><b>NOTE:</b> this method is <em>NOT</em> suitable/safe to use in a test where multiple
+ * backups are being taken/deleted concurrently, because the replication handler API provides no
+ * reliable way to check the results of a specific backup before the results of another backup may
+ * overwrite them internally.
+ *
* @param backupName to look for
* @param timeOut limiting how long we wait
* @return the (new) directoryName of the specified backup
* @see #checkBackupSuccess(String)
*/
- public String waitForBackupSuccess(final String backupName, final TimeOut timeOut) throws Exception {
+ public String waitForBackupSuccess(final String backupName, final TimeOut timeOut)
+ throws Exception {
assertNotNull("backupName must not be null", backupName);
while (!timeOut.hasTimedOut()) {
final String newDirName = checkBackupSuccess(backupName);
@@ -99,148 +95,150 @@ public final class BackupStatusChecker {
}
timeOut.sleep(50);
}
-
+
// total TimeOut elapsed, so one last check or fail whole test.
final String newDirName = checkBackupSuccess(backupName);
- assertNotNull(backupName + " did not succeed before the TimeOut elapsed",
- newDirName);
+ assertNotNull(backupName + " did not succeed before the TimeOut elapsed", newDirName);
return newDirName;
}
-
+
/**
* Convinience wrapper
+ *
* @see #waitForDifferentBackupDir(String,TimeOut)
*/
- public String waitForDifferentBackupDir(final String directoryName,
- final int timeLimitInSeconds) throws Exception {
-
- return waitForDifferentBackupDir(directoryName,
- new TimeOut(timeLimitInSeconds, TimeUnit.SECONDS, TimeSource.NANO_TIME));
+ public String waitForDifferentBackupDir(final String directoryName, final int timeLimitInSeconds)
+ throws Exception {
+
+ return waitForDifferentBackupDir(
+ directoryName, new TimeOut(timeLimitInSeconds, TimeUnit.SECONDS, TimeSource.NANO_TIME));
}
-
+
/**
* Polls the replication handler's status until the it reports that <em>any</em> backup has
- * completed as a <code>"success"</code> with a different <code>"directoryName"</code> then the
- * one specified (in which case the method returns the new directoryName) or either an
- * <code>"exception"</code> is reported or the <code>timeOut</code> expires
- * (in either case an assertion is thrown)
+ * completed as a <code>"success"</code> with a different <code>"directoryName"</code> then the
+ * one specified (in which case the method returns the new directoryName) or either an <code>
+ * "exception"</code> is reported or the <code>timeOut</code> expires (in either case an assertion
+ * is thrown)
+ *
+ * <p><b>NOTE:</b> this method is <em>NOT</em> suitable/safe to use in a test where multiple
+ * backups are being taken/deleted concurrently, because the replication handler API provides no
+ * reliable way to determine if the the most recently reported status to the a particular backup
+ * request.
*
- * <p>
- * <b>NOTE:</b> this method is <em>NOT</em> suitable/safe to use in a test where multiple backups are
- * being taken/deleted concurrently, because the replication handler API provides no reliable way to determine
- * if the the most recently reported status to the a particular backup request.
- * </p>
- *
* @param directoryName to compare to, may be null
* @param timeOut limiting how long we wait
* @return the (new) directoryName of the latests successful backup
* @see #checkBackupSuccess()
*/
- public String waitForDifferentBackupDir(final String directoryName, final TimeOut timeOut) throws Exception {
+ public String waitForDifferentBackupDir(final String directoryName, final TimeOut timeOut)
+ throws Exception {
while (!timeOut.hasTimedOut()) {
final String newDirName = checkBackupSuccess();
- if (null != newDirName && ! newDirName.equals(directoryName)) {
+ if (null != newDirName && !newDirName.equals(directoryName)) {
return newDirName;
}
timeOut.sleep(50);
}
-
+
// total TimeOut elapsed, so one last check or fail whole test...
final String newDirName = checkBackupSuccess();
- assertTrue("No successful backup with different directoryName then "
- + directoryName + " before TimeOut elapsed",
- (null != newDirName && ! newDirName.equals(directoryName)));
+ assertTrue(
+ "No successful backup with different directoryName then "
+ + directoryName
+ + " before TimeOut elapsed",
+ (null != newDirName && !newDirName.equals(directoryName)));
return newDirName;
}
-
+
/**
- * Does a single check of the replication handler's status to determine if the mostrecently
- * completed backup was a success.
- * Throws a test assertion failure if any <code>"exception"</code> message is ever encountered
- * (The Replication Handler API does not make it possible to know <em>which</em> backup
- * this exception was related to)
+ * Does a single check of the replication handler's status to determine if the mostrecently
+ * completed backup was a success. Throws a test assertion failure if any <code>"exception"</code>
+ * message is ever encountered (The Replication Handler API does not make it possible to know
+ * <em>which</em> backup this exception was related to)
*
- * <p>
- * <b>NOTE:</b> this method is <em>NOT</em> suitable/safe to use in a test where multiple backups are
- * being taken/deleted concurrently, because the replication handler API provides no reliable way to determine
- * if the the most recently reported status to the a particular backup request.
- * </p>
+ * <p><b>NOTE:</b> this method is <em>NOT</em> suitable/safe to use in a test where multiple
+ * backups are being taken/deleted concurrently, because the replication handler API provides no
+ * reliable way to determine if the the most recently reported status to the a particular backup
+ * request.
*
- * @return the "directoryName" of the backup if the response indicates that a is completed successfully, otherwise null
+ * @return the "directoryName" of the backup if the response indicates that a is completed
+ * successfully, otherwise null
*/
public String checkBackupSuccess() throws Exception {
return _checkBackupSuccess(null);
}
-
+
/**
- * Does a single check of the replication handler's status to determine if the specified name matches
- * the most recently completed backup, and if that backup was a success.
- * Throws a test assertion failure if any <code>"exception"</code> message is ever encountered
- * (The Replication Handler API does not make it possible to know <em>which</em> backup
- * this exception was related to)
+ * Does a single check of the replication handler's status to determine if the specified name
+ * matches the most recently completed backup, and if that backup was a success. Throws a test
+ * assertion failure if any <code>"exception"</code> message is ever encountered (The Replication
+ * Handler API does not make it possible to know <em>which</em> backup this exception was related
+ * to)
*
- * @return the "directoryName" of the backup if the response indicates that the specified backupName is completed successfully, otherwise null
+ * @return the "directoryName" of the backup if the response indicates that the specified
+ * backupName is completed successfully, otherwise null
* @see #waitForBackupSuccess(String,TimeOut)
*/
public String checkBackupSuccess(final String backupName) throws Exception {
assertNotNull("backupName must not be null", backupName);
return _checkBackupSuccess(backupName);
}
-
- /**
- * Helper method that works with either named or unnamemed backups
- */
+
+ /** Helper method that works with either named or unnamemed backups */
private String _checkBackupSuccess(final String backupName) throws Exception {
final String label = (null == backupName ? "latest backup" : backupName);
- final SimpleSolrResponse rsp = new GenericSolrRequest(GenericSolrRequest.METHOD.GET, path,
- params("command", "details")).process(client);
+ final SimpleSolrResponse rsp =
+ new GenericSolrRequest(GenericSolrRequest.METHOD.GET, path, params("command", "details"))
+ .process(client);
final NamedList<?> data = rsp.getResponse();
log.info("Checking Status of {}: {}", label, data);
@SuppressWarnings({"unchecked"})
- final NamedList<String> backupData = (NamedList<String>) data.findRecursive("details","backup");
+ final NamedList<String> backupData =
+ (NamedList<String>) data.findRecursive("details", "backup");
if (null == backupData) {
// no backup has finished yet
return null;
}
-
+
final Object exception = backupData.get("exception");
assertNull("Backup failure: " + label, exception);
if ("success".equals(backupData.get("status"))
- && (null == backupName || backupName.equals(backupData.get("snapshotName"))) ) {
+ && (null == backupName || backupName.equals(backupData.get("snapshotName")))) {
assert null != backupData.get("directoryName");
return backupData.get("directoryName");
}
return null;
}
-
-
/**
* Convinience wrapper
+ *
* @see #waitForBackupDeletionSuccess(String,TimeOut)
*/
- public void waitForBackupDeletionSuccess(final String backupName, final int timeLimitInSeconds) throws Exception {
- waitForBackupDeletionSuccess(backupName,
- new TimeOut(timeLimitInSeconds, TimeUnit.SECONDS, TimeSource.NANO_TIME));
+ public void waitForBackupDeletionSuccess(final String backupName, final int timeLimitInSeconds)
+ throws Exception {
+ waitForBackupDeletionSuccess(
+ backupName, new TimeOut(timeLimitInSeconds, TimeUnit.SECONDS, TimeSource.NANO_TIME));
}
-
+
/**
* Polls the replication handler's status until the it reports that the specified backupName is
- * deleted or either <code>"Unable to delete"</code> status is reported or the <code>timeOut</code> expires
- * (in either case an assertion is thrown)
- *
- * <p>
- * <b>NOTE:</b> this method is <em>NOT</em> suitable/safe to use in a test where multiple backups are
- * being taken/deleted concurrently, because the replication handler API provides no reliable way to check
- * the results of a specific backup before the results of another backup may overwrite them internally.
- * </p>
- *
+ * deleted or either <code>"Unable to delete"</code> status is reported or the <code>timeOut
+ * </code> expires (in either case an assertion is thrown)
+ *
+ * <p><b>NOTE:</b> this method is <em>NOT</em> suitable/safe to use in a test where multiple
+ * backups are being taken/deleted concurrently, because the replication handler API provides no
+ * reliable way to check the results of a specific backup before the results of another backup may
+ * overwrite them internally.
+ *
* @param backupName to look for in status
* @param timeOut limiting how long we wait
* @see #checkBackupSuccess(String)
*/
- public void waitForBackupDeletionSuccess(final String backupName, final TimeOut timeOut) throws Exception {
+ public void waitForBackupDeletionSuccess(final String backupName, final TimeOut timeOut)
+ throws Exception {
assertNotNull("backumpName must not be null", backupName);
while (!timeOut.hasTimedOut()) {
if (checkBackupDeletionSuccess(backupName)) {
@@ -248,38 +246,41 @@ public final class BackupStatusChecker {
}
timeOut.sleep(50);
}
-
+
// total TimeOut elapsed, so one last check or fail whole test.
- assertTrue(backupName + " was not reported as deleted before the TimeOut elapsed",
- checkBackupDeletionSuccess(backupName));
+ assertTrue(
+ backupName + " was not reported as deleted before the TimeOut elapsed",
+ checkBackupDeletionSuccess(backupName));
}
-
+
/**
- * Does a single check of the replication handler's status to determine if the specified name matches
- * the most recently deleted backup, and if deleting that backup was a success.
- * Throws a test assertion failure if the status is about this backupName but the starts message
- * with <code>"Unable to delete"</code>
+ * Does a single check of the replication handler's status to determine if the specified name
+ * matches the most recently deleted backup, and if deleting that backup was a success. Throws a
+ * test assertion failure if the status is about this backupName but the starts message with
+ * <code>"Unable to delete"</code>
*
* @return true if the replication status info indicates the backup was deleted, false otherwise
* @see #waitForBackupDeletionSuccess(String,TimeOut)
*/
public boolean checkBackupDeletionSuccess(final String backupName) throws Exception {
assertNotNull("backumpName must not be null", backupName);
- final SimpleSolrResponse rsp = new GenericSolrRequest(GenericSolrRequest.METHOD.GET, path,
- params("command", "details")).process(client);
+ final SimpleSolrResponse rsp =
+ new GenericSolrRequest(GenericSolrRequest.METHOD.GET, path, params("command", "details"))
+ .process(client);
final NamedList<?> data = rsp.getResponse();
log.info("Checking Deletion Status of {}: {}", backupName, data);
@SuppressWarnings({"unchecked"})
- final NamedList<String> backupData = (NamedList<String>) data.findRecursive("details","backup");
+ final NamedList<String> backupData =
+ (NamedList<String>) data.findRecursive("details", "backup");
if (null == backupData
|| null == backupData.get("status")
- || ! backupName.equals(backupData.get("snapshotName")) ) {
+ || !backupName.equals(backupData.get("snapshotName"))) {
// either no backup activity at all,
// or most recent activity isn't something we can infer anything from,
// or is not about the backup we care about...
return false;
}
-
+
final Object status = backupData.get("status");
if (status.toString().startsWith("Unable to delete")) {
// we already know backupData is about our backup
@@ -289,7 +290,7 @@ public final class BackupStatusChecker {
if ("success".equals(status) && null != backupData.get("snapshotDeletedAt")) {
return true; // backup done
}
-
+
// if we're still here then this status is about our backup, but doesn't seem to be a deletion
return false;
}
diff --git a/solr/test-framework/src/java/org/apache/solr/handler/TestRestoreCoreUtil.java b/solr/test-framework/src/java/org/apache/solr/handler/TestRestoreCoreUtil.java
index 210b2649026..477dfd153b1 100644
--- a/solr/test-framework/src/java/org/apache/solr/handler/TestRestoreCoreUtil.java
+++ b/solr/test-framework/src/java/org/apache/solr/handler/TestRestoreCoreUtil.java
@@ -21,14 +21,18 @@ import java.io.InputStream;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
import org.apache.commons.io.IOUtils;
import org.junit.Assert;
public class TestRestoreCoreUtil {
- public static boolean fetchRestoreStatus (String baseUrl, String coreName) throws IOException {
- String leaderUrl = baseUrl + "/" + coreName +
- ReplicationHandler.PATH + "?wt=xml&command=" + ReplicationHandler.CMD_RESTORE_STATUS;
+ public static boolean fetchRestoreStatus(String baseUrl, String coreName) throws IOException {
+ String leaderUrl =
+ baseUrl
+ + "/"
+ + coreName
+ + ReplicationHandler.PATH
+ + "?wt=xml&command="
+ + ReplicationHandler.CMD_RESTORE_STATUS;
final Pattern pException = Pattern.compile("<str name=\"exception\">(.*?)</str>");
InputStream stream = null;
@@ -37,12 +41,12 @@ public class TestRestoreCoreUtil {
stream = url.openStream();
String response = IOUtils.toString(stream, "UTF-8");
Matcher matcher = pException.matcher(response);
- if(matcher.find()) {
+ if (matcher.find()) {
Assert.fail("Failed to complete restore action with exception " + matcher.group(1));
}
- if(response.contains("<str name=\"status\">success</str>")) {
+ if (response.contains("<str name=\"status\">success</str>")) {
return true;
- } else if (response.contains("<str name=\"status\">failed</str>")){
+ } else if (response.contains("<str name=\"status\">failed</str>")) {
Assert.fail("Restore Failed");
}
stream.close();
diff --git a/solr/test-framework/src/java/org/apache/solr/handler/component/DummyCustomParamSpellChecker.java b/solr/test-framework/src/java/org/apache/solr/handler/component/DummyCustomParamSpellChecker.java
index 10f7cc086b2..aa647814aa5 100644
--- a/solr/test-framework/src/java/org/apache/solr/handler/component/DummyCustomParamSpellChecker.java
+++ b/solr/test-framework/src/java/org/apache/solr/handler/component/DummyCustomParamSpellChecker.java
@@ -21,34 +21,27 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
-
import org.apache.solr.core.SolrCore;
import org.apache.solr.search.SolrIndexSearcher;
import org.apache.solr.spelling.SolrSpellChecker;
import org.apache.solr.spelling.SpellingOptions;
import org.apache.solr.spelling.SpellingResult;
import org.apache.solr.spelling.Token;
-/**
- * A Dummy SpellChecker for testing purposes
- *
- **/
+
+/** A Dummy SpellChecker for testing purposes */
public class DummyCustomParamSpellChecker extends SolrSpellChecker {
@Override
- public void reload(SolrCore core, SolrIndexSearcher searcher) throws IOException {
-
- }
+ public void reload(SolrCore core, SolrIndexSearcher searcher) throws IOException {}
@Override
- public void build(SolrCore core, SolrIndexSearcher searcher) throws IOException {
-
- }
+ public void build(SolrCore core, SolrIndexSearcher searcher) throws IOException {}
@Override
public SpellingResult getSuggestions(SpellingOptions options) throws IOException {
SpellingResult result = new SpellingResult();
- //just spit back out the results
+ // just spit back out the results
// sort the keys to make ordering predictable
Iterator<String> iterator = options.customParams.getParameterNamesIterator();
@@ -61,9 +54,9 @@ public class DummyCustomParamSpellChecker extends SolrSpellChecker {
int i = 0;
for (String name : lst) {
String value = options.customParams.get(name);
- result.add(new Token(name, i, i+1), Collections.singletonList(value));
+ result.add(new Token(name, i, i + 1), Collections.singletonList(value));
i += 2;
- }
+ }
return result;
}
}
diff --git a/solr/test-framework/src/java/org/apache/solr/handler/component/TrackingShardHandlerFactory.java b/solr/test-framework/src/java/org/apache/solr/handler/component/TrackingShardHandlerFactory.java
index 25437ff86c6..85dfe49bedd 100644
--- a/solr/test-framework/src/java/org/apache/solr/handler/component/TrackingShardHandlerFactory.java
+++ b/solr/test-framework/src/java/org/apache/solr/handler/component/TrackingShardHandlerFactory.java
@@ -23,7 +23,6 @@ import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
-
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.cloud.MiniSolrCloudCluster;
import org.apache.solr.common.cloud.DocCollection;
@@ -36,27 +35,27 @@ import org.apache.solr.common.util.StrUtils;
import org.apache.solr.core.CoreContainer;
/**
- * A ShardHandlerFactory that extends HttpShardHandlerFactory and
- * tracks requests made to nodes/shards such that interested parties
- * can watch such requests and make assertions inside tests
- * <p>
- * This is a test helper only and should *not* be used for production.
+ * A ShardHandlerFactory that extends HttpShardHandlerFactory and tracks requests made to
+ * nodes/shards such that interested parties can watch such requests and make assertions inside
+ * tests
+ *
+ * <p>This is a test helper only and should *not* be used for production.
*/
public class TrackingShardHandlerFactory extends HttpShardHandlerFactory {
private Queue<ShardRequestAndParams> queue;
/**
- * Set the tracking queue for this factory. All the ShardHandler instances
- * created from this factory will share the queue and call {@link java.util.Queue#offer(Object)}
- * with a {@link org.apache.solr.handler.component.TrackingShardHandlerFactory.ShardRequestAndParams}
- * instance whenever
- * {@link org.apache.solr.handler.component.ShardHandler#submit(ShardRequest, String, org.apache.solr.common.params.ModifiableSolrParams)}
- * is called before the request is actually submitted to the
- * wrapped {@link org.apache.solr.handler.component.HttpShardHandlerFactory} instance.
- * <p>
- * If a tracking queue is already set then this call will overwrite and replace the
- * previous queue with this one.
+ * Set the tracking queue for this factory. All the ShardHandler instances created from this
+ * factory will share the queue and call {@link java.util.Queue#offer(Object)} with a {@link
+ * org.apache.solr.handler.component.TrackingShardHandlerFactory.ShardRequestAndParams} instance
+ * whenever {@link org.apache.solr.handler.component.ShardHandler#submit(ShardRequest, String,
+ * org.apache.solr.common.params.ModifiableSolrParams)} is called before the request is actually
+ * submitted to the wrapped {@link org.apache.solr.handler.component.HttpShardHandlerFactory}
+ * instance.
+ *
+ * <p>If a tracking queue is already set then this call will overwrite and replace the previous
+ * queue with this one.
*
* @param queue the {@link java.util.Queue} to be used for tracking shard requests
*/
@@ -65,16 +64,15 @@ public class TrackingShardHandlerFactory extends HttpShardHandlerFactory {
}
/**
- * @return the {@link java.util.Queue} being used for tracking, null if none
- * has been set
+ * @return the {@link java.util.Queue} being used for tracking, null if none has been set
*/
public synchronized Queue<ShardRequestAndParams> getTrackingQueue() {
return queue;
}
/**
- * @return true if a tracking queue has been set through
- * {@link #setTrackingQueue(java.util.List, java.util.Queue)}, false otherwise
+ * @return true if a tracking queue has been set through {@link #setTrackingQueue(java.util.List,
+ * java.util.Queue)}, false otherwise
*/
public synchronized boolean isTracking() {
return queue != null;
@@ -130,13 +128,16 @@ public class TrackingShardHandlerFactory extends HttpShardHandlerFactory {
/**
* Sets the tracking queue for all nodes participating in this cluster. Once this method returns,
* all search and core admin requests distributed to shards will be submitted to the given queue.
- * <p>
- * This is equivalent to calling:
- * <code>TrackingShardHandlerFactory.setTrackingQueue(cluster.getJettySolrRunners(), queue)</code>
*
- * @see org.apache.solr.handler.component.TrackingShardHandlerFactory#setTrackingQueue(java.util.List, java.util.Queue)
+ * <p>This is equivalent to calling: <code>
+ * TrackingShardHandlerFactory.setTrackingQueue(cluster.getJettySolrRunners(), queue)</code>
+ *
+ * @see
+ * org.apache.solr.handler.component.TrackingShardHandlerFactory#setTrackingQueue(java.util.List,
+ * java.util.Queue)
*/
- public static void setTrackingQueue(MiniSolrCloudCluster cluster, Queue<ShardRequestAndParams> queue) {
+ public static void setTrackingQueue(
+ MiniSolrCloudCluster cluster, Queue<ShardRequestAndParams> queue) {
setTrackingQueue(cluster.getJettySolrRunners(), queue);
}
@@ -145,19 +146,21 @@ public class TrackingShardHandlerFactory extends HttpShardHandlerFactory {
* all search and core admin requests distributed to shards will be submitted to the given queue.
*
* @param runners a list of {@link org.apache.solr.client.solrj.embedded.JettySolrRunner} nodes
- * @param queue an implementation of {@link java.util.Queue} which
- * accepts {@link org.apache.solr.handler.component.TrackingShardHandlerFactory.ShardRequestAndParams}
- * instances
+ * @param queue an implementation of {@link java.util.Queue} which accepts {@link
+ * org.apache.solr.handler.component.TrackingShardHandlerFactory.ShardRequestAndParams}
+ * instances
*/
- public static void setTrackingQueue(List<JettySolrRunner> runners, Queue<ShardRequestAndParams> queue) {
+ public static void setTrackingQueue(
+ List<JettySolrRunner> runners, Queue<ShardRequestAndParams> queue) {
for (JettySolrRunner runner : runners) {
CoreContainer container = runner.getCoreContainer();
if (container != null) {
ShardHandlerFactory factory = container.getShardHandlerFactory();
- assert factory instanceof TrackingShardHandlerFactory : "not a TrackingShardHandlerFactory: "
- + factory.getClass();
+ assert factory instanceof TrackingShardHandlerFactory
+ : "not a TrackingShardHandlerFactory: " + factory.getClass();
@SuppressWarnings("resource")
- TrackingShardHandlerFactory trackingShardHandlerFactory = (TrackingShardHandlerFactory) factory;
+ TrackingShardHandlerFactory trackingShardHandlerFactory =
+ (TrackingShardHandlerFactory) factory;
trackingShardHandlerFactory.setTrackingQueue(queue);
}
}
@@ -176,18 +179,24 @@ public class TrackingShardHandlerFactory extends HttpShardHandlerFactory {
@Override
public String toString() {
- return "ShardRequestAndParams{" +
- "shard='" + shard + '\'' +
- ", sreq=" + sreq +
- ", params=" + params +
- '}';
+ return "ShardRequestAndParams{"
+ + "shard='"
+ + shard
+ + '\''
+ + ", sreq="
+ + sreq
+ + ", params="
+ + params
+ + '}';
}
}
/**
* A queue having helper methods to select requests by shard and purpose.
*
- * @see org.apache.solr.handler.component.TrackingShardHandlerFactory#setTrackingQueue(java.util.List, java.util.Queue)
+ * @see
+ * org.apache.solr.handler.component.TrackingShardHandlerFactory#setTrackingQueue(java.util.List,
+ * java.util.Queue)
*/
public static class RequestTrackingQueue extends LinkedList<ShardRequestAndParams> {
private final Map<String, List<ShardRequestAndParams>> requests = new ConcurrentHashMap<>();
@@ -209,18 +218,25 @@ public class TrackingShardHandlerFactory extends HttpShardHandlerFactory {
}
/**
- * Retrieve request recorded by this queue which were sent to given collection, shard and purpose
+ * Retrieve request recorded by this queue which were sent to given collection, shard and
+ * purpose
*
- * @param zkStateReader the {@link org.apache.solr.common.cloud.ZkStateReader} from which cluster state is read
+ * @param zkStateReader the {@link org.apache.solr.common.cloud.ZkStateReader} from which
+ * cluster state is read
* @param collectionName the given collection name for which requests have to be extracted
- * @param shardId the given shard name for which requests have to be extracted
- * @param purpose the shard purpose
- * @return instance of {@link org.apache.solr.handler.component.TrackingShardHandlerFactory.ShardRequestAndParams}
- * or null if none is found
- * @throws java.lang.RuntimeException if more than one request is found to the same shard with the same purpose
+ * @param shardId the given shard name for which requests have to be extracted
+ * @param purpose the shard purpose
+ * @return instance of {@link
+ * org.apache.solr.handler.component.TrackingShardHandlerFactory.ShardRequestAndParams} or
+ * null if none is found
+ * @throws java.lang.RuntimeException if more than one request is found to the same shard with
+ * the same purpose
*/
- public ShardRequestAndParams getShardRequestByPurpose(ZkStateReader zkStateReader, String collectionName, String shardId, int purpose) throws RuntimeException {
- List<TrackingShardHandlerFactory.ShardRequestAndParams> shardRequests = getShardRequests(zkStateReader, collectionName, shardId);
+ public ShardRequestAndParams getShardRequestByPurpose(
+ ZkStateReader zkStateReader, String collectionName, String shardId, int purpose)
+ throws RuntimeException {
+ List<TrackingShardHandlerFactory.ShardRequestAndParams> shardRequests =
+ getShardRequests(zkStateReader, collectionName, shardId);
List<TrackingShardHandlerFactory.ShardRequestAndParams> result = new ArrayList<>(1);
for (TrackingShardHandlerFactory.ShardRequestAndParams request : shardRequests) {
if ((request.sreq.purpose & purpose) != 0) {
@@ -228,7 +244,9 @@ public class TrackingShardHandlerFactory extends HttpShardHandlerFactory {
}
}
if (result.size() > 1) {
- throw new RuntimeException("Multiple requests to the same shard with the same purpose were found. Requests: " + result);
+ throw new RuntimeException(
+ "Multiple requests to the same shard with the same purpose were found. Requests: "
+ + result);
}
return result.isEmpty() ? null : result.get(0);
}
@@ -236,13 +254,16 @@ public class TrackingShardHandlerFactory extends HttpShardHandlerFactory {
/**
* Retrieve all requests recorded by this queue which were sent to given collection and shard
*
- * @param zkStateReader the {@link org.apache.solr.common.cloud.ZkStateReader} from which cluster state is read
+ * @param zkStateReader the {@link org.apache.solr.common.cloud.ZkStateReader} from which
+ * cluster state is read
* @param collectionName the given collection name for which requests have to be extracted
- * @param shardId the given shard name for which requests have to be extracted
- * @return a list of {@link org.apache.solr.handler.component.TrackingShardHandlerFactory.ShardRequestAndParams}
- * or empty list if none are found
+ * @param shardId the given shard name for which requests have to be extracted
+ * @return a list of {@link
+ * org.apache.solr.handler.component.TrackingShardHandlerFactory.ShardRequestAndParams} or
+ * empty list if none are found
*/
- public List<ShardRequestAndParams> getShardRequests(ZkStateReader zkStateReader, String collectionName, String shardId) {
+ public List<ShardRequestAndParams> getShardRequests(
+ ZkStateReader zkStateReader, String collectionName, String shardId) {
DocCollection collection = zkStateReader.getClusterState().getCollection(collectionName);
assert collection != null;
Slice slice = collection.getSlice(shardId);
@@ -264,8 +285,9 @@ public class TrackingShardHandlerFactory extends HttpShardHandlerFactory {
/**
* Retrieves all core admin requests distributed to nodes by Collection API commands
*
- * @return a list of {@link org.apache.solr.handler.component.TrackingShardHandlerFactory.ShardRequestAndParams}
- * or empty if none found
+ * @return a list of {@link
+ * org.apache.solr.handler.component.TrackingShardHandlerFactory.ShardRequestAndParams} or
+ * empty if none found
*/
public List<ShardRequestAndParams> getCoreAdminRequests() {
List<ShardRequestAndParams> results = new ArrayList<>();
@@ -281,11 +303,13 @@ public class TrackingShardHandlerFactory extends HttpShardHandlerFactory {
}
/**
- * Retrieves all requests recorded by this collection as a Map of shard address (string url)
- * to a list of {@link org.apache.solr.handler.component.TrackingShardHandlerFactory.ShardRequestAndParams}
+ * Retrieves all requests recorded by this collection as a Map of shard address (string url) to
+ * a list of {@link
+ * org.apache.solr.handler.component.TrackingShardHandlerFactory.ShardRequestAndParams}
*
- * @return a {@link java.util.concurrent.ConcurrentHashMap} of url strings to {@link org.apache.solr.handler.component.TrackingShardHandlerFactory.ShardRequestAndParams} objects
- * or empty map if none have been recorded
+ * @return a {@link java.util.concurrent.ConcurrentHashMap} of url strings to {@link
+ * org.apache.solr.handler.component.TrackingShardHandlerFactory.ShardRequestAndParams}
+ * objects or empty map if none have been recorded
*/
public Map<String, List<ShardRequestAndParams>> getAllRequests() {
return requests;
diff --git a/solr/test-framework/src/java/org/apache/solr/schema/MockExchangeRateProvider.java b/solr/test-framework/src/java/org/apache/solr/schema/MockExchangeRateProvider.java
index 2a05038805b..d1d58f0176b 100644
--- a/solr/test-framework/src/java/org/apache/solr/schema/MockExchangeRateProvider.java
+++ b/solr/test-framework/src/java/org/apache/solr/schema/MockExchangeRateProvider.java
@@ -15,20 +15,19 @@
* limitations under the License.
*/
package org.apache.solr.schema;
+
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-
import org.apache.lucene.util.ResourceLoader;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
-/**
- * Simple mock provider with fixed rates and some assertions
- */
+/** Simple mock provider with fixed rates and some assertions */
public class MockExchangeRateProvider implements ExchangeRateProvider {
- private static Map<String,Double> map = new HashMap<>();
+ private static Map<String, Double> map = new HashMap<>();
+
static {
map.put("USD,EUR", 0.8);
map.put("EUR,USD", 1.2);
@@ -40,15 +39,17 @@ public class MockExchangeRateProvider implements ExchangeRateProvider {
private boolean gotArgs = false;
private boolean gotLoader = false;
-
+
@Override
public double getExchangeRate(String sourceCurrencyCode, String targetCurrencyCode) {
-// System.out.println("***** getExchangeRate("+sourceCurrencyCode+targetCurrencyCode+")");
- if(sourceCurrencyCode.equals(targetCurrencyCode)) return 1.0;
+ // System.out.println("***** getExchangeRate("+sourceCurrencyCode+targetCurrencyCode+")");
+ if (sourceCurrencyCode.equals(targetCurrencyCode)) return 1.0;
- Double result = map.get(sourceCurrencyCode+","+targetCurrencyCode);
- if(result == null) {
- throw new SolrException(ErrorCode.NOT_FOUND, "No exchange rate found for the pair "+sourceCurrencyCode+","+targetCurrencyCode);
+ Double result = map.get(sourceCurrencyCode + "," + targetCurrencyCode);
+ if (result == null) {
+ throw new SolrException(
+ ErrorCode.NOT_FOUND,
+ "No exchange rate found for the pair " + sourceCurrencyCode + "," + targetCurrencyCode);
}
return result;
}
@@ -57,7 +58,7 @@ public class MockExchangeRateProvider implements ExchangeRateProvider {
public Set<String> listAvailableCurrencies() {
Set<String> currenciesPairs = map.keySet();
Set<String> returnSet;
-
+
returnSet = new HashSet<>();
for (String c : currenciesPairs) {
String[] pairs = c.split(",");
@@ -69,23 +70,22 @@ public class MockExchangeRateProvider implements ExchangeRateProvider {
@Override
public boolean reload() throws SolrException {
- assert(gotArgs == true);
- assert(gotLoader == true);
+ assert (gotArgs == true);
+ assert (gotLoader == true);
return true;
}
@Override
- public void init(Map<String,String> args) {
- assert(args.get("foo").equals("bar"));
+ public void init(Map<String, String> args) {
+ assert (args.get("foo").equals("bar"));
gotArgs = true;
args.remove("foo");
}
@Override
public void inform(ResourceLoader loader) throws SolrException {
- assert(loader != null);
+ assert (loader != null);
gotLoader = true;
- assert(gotArgs == true);
+ assert (gotArgs == true);
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/schema/SortableBinaryField.java b/solr/test-framework/src/java/org/apache/solr/schema/SortableBinaryField.java
index 90c92d07cc6..a49e66e53d3 100644
--- a/solr/test-framework/src/java/org/apache/solr/schema/SortableBinaryField.java
+++ b/solr/test-framework/src/java/org/apache/solr/schema/SortableBinaryField.java
@@ -20,7 +20,6 @@ import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-
import org.apache.lucene.document.SortedDocValuesField;
import org.apache.lucene.document.SortedSetDocValuesField;
import org.apache.lucene.index.IndexableField;
@@ -29,9 +28,7 @@ import org.apache.lucene.search.FieldComparatorSource;
import org.apache.lucene.search.SortField;
import org.apache.lucene.util.BytesRef;
-/**
- * Custom field representing a {@link BinaryField} that's sortable.
- */
+/** Custom field representing a {@link BinaryField} that's sortable. */
public class SortableBinaryField extends BinaryField {
@Override
@@ -45,8 +42,11 @@ public class SortableBinaryField extends BinaryField {
IndexableField storedField = createField(field, value);
fields.add(storedField);
ByteBuffer byteBuffer = toObject(storedField);
- BytesRef bytes = new BytesRef
- (byteBuffer.array(), byteBuffer.arrayOffset() + byteBuffer.position(), byteBuffer.remaining());
+ BytesRef bytes =
+ new BytesRef(
+ byteBuffer.array(),
+ byteBuffer.arrayOffset() + byteBuffer.position(),
+ byteBuffer.remaining());
if (field.multiValued()) {
fields.add(new SortedSetDocValuesField(field.getName(), bytes));
} else {
@@ -66,20 +66,27 @@ public class SortableBinaryField extends BinaryField {
private static class BinarySortField extends SortField {
public BinarySortField(final String field, final boolean reverse) {
- super(field, new FieldComparatorSource() {
- @Override
- public FieldComparator.TermOrdValComparator newComparator
- (final String fieldname, final int numHits, final int sortPos, final boolean reversed) {
- return new FieldComparator.TermOrdValComparator(numHits, fieldname);
- }}, reverse);
+ super(
+ field,
+ new FieldComparatorSource() {
+ @Override
+ public FieldComparator.TermOrdValComparator newComparator(
+ final String fieldname,
+ final int numHits,
+ final int sortPos,
+ final boolean reversed) {
+ return new FieldComparator.TermOrdValComparator(numHits, fieldname);
+ }
+ },
+ reverse);
}
}
-
+
@Override
public Object marshalSortValue(Object value) {
return marshalBase64SortValue(value);
}
-
+
@Override
public Object unmarshalSortValue(Object value) {
return unmarshalBase64SortValue(value);
diff --git a/solr/test-framework/src/java/org/apache/solr/search/FooQParserPlugin.java b/solr/test-framework/src/java/org/apache/solr/search/FooQParserPlugin.java
index 3c51a36a5a5..423ebad80e4 100644
--- a/solr/test-framework/src/java/org/apache/solr/search/FooQParserPlugin.java
+++ b/solr/test-framework/src/java/org/apache/solr/search/FooQParserPlugin.java
@@ -16,16 +16,16 @@
*/
package org.apache.solr.search;
-import org.apache.solr.common.params.SolrParams;
-import org.apache.solr.request.SolrQueryRequest;
+import org.apache.lucene.index.Term;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.index.Term;
-
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.request.SolrQueryRequest;
public class FooQParserPlugin extends QParserPlugin {
@Override
- public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
+ public QParser createParser(
+ String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
return new FooQParser(qstr, localParams, params, req);
}
}
@@ -37,6 +37,7 @@ class FooQParser extends QParser {
@Override
public Query parse() throws SyntaxError {
- return new TermQuery(new Term(localParams.get(QueryParsing.F), localParams.get(QueryParsing.V)));
+ return new TermQuery(
+ new Term(localParams.get(QueryParsing.F), localParams.get(QueryParsing.V)));
}
}
diff --git a/solr/test-framework/src/java/org/apache/solr/search/facet/DebugAgg.java b/solr/test-framework/src/java/org/apache/solr/search/facet/DebugAgg.java
index aefb6cd2686..b5c25e6a67d 100644
--- a/solr/test-framework/src/java/org/apache/solr/search/facet/DebugAgg.java
+++ b/solr/test-framework/src/java/org/apache/solr/search/facet/DebugAgg.java
@@ -20,7 +20,6 @@ package org.apache.solr.search.facet;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.IntFunction;
-
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.queries.function.ValueSource;
import org.apache.solr.common.params.SolrParams;
@@ -30,7 +29,6 @@ import org.apache.solr.search.FunctionQParser;
import org.apache.solr.search.SyntaxError;
import org.apache.solr.search.ValueSourceParser;
-
class DebugAgg extends AggValueSource {
public static AtomicLong parses = new AtomicLong(0);
@@ -41,8 +39,10 @@ class DebugAgg extends AggValueSource {
final String what = fp.hasMoreArguments() ? fp.parseId() : "wrap";
switch (what) {
- case "wrap": return new DebugAgg(fp);
- case "numShards": return new DebugAggNumShards();
+ case "wrap":
+ return new DebugAgg(fp);
+ case "numShards":
+ return new DebugAggNumShards();
default: /* No-Op */
}
throw new RuntimeException("No idea what to do with " + what);
@@ -50,20 +50,22 @@ class DebugAgg extends AggValueSource {
}
/**
- * This exposes the raw localparams used by the FunctionQParser, it does <b>NOT</b>
- * wrap them in defaults from the request
+ * This exposes the raw localparams used by the FunctionQParser, it does <b>NOT</b> wrap them in
+ * defaults from the request
*/
public final SolrParams localParams;
+
public final AggValueSource inner;
-
- public DebugAgg(FunctionQParser fp) throws SyntaxError {
+
+ public DebugAgg(FunctionQParser fp) throws SyntaxError {
super("debug");
this.localParams = fp.getLocalParams();
this.inner = fp.hasMoreArguments() ? fp.parseAgg(FunctionQParser.FLAG_IS_AGG) : new CountAgg();
}
@Override
- public SlotAcc createSlotAcc(FacetContext fcontext, long numDocs, int numSlots) throws IOException {
+ public SlotAcc createSlotAcc(FacetContext fcontext, long numDocs, int numSlots)
+ throws IOException {
return new Acc(fcontext, numDocs, numSlots, inner.createSlotAcc(fcontext, numDocs, numSlots));
}
@@ -99,14 +101,15 @@ class DebugAgg extends AggValueSource {
}
@Override
- public void collect(int doc, int slot, IntFunction<SlotContext> slotContext) throws IOException {
+ public void collect(int doc, int slot, IntFunction<SlotContext> slotContext)
+ throws IOException {
collectDocs.addAndGet(1);
sub.collect(doc, slot, slotContext);
}
-
@Override
- public int collect(DocSet docs, int slot, IntFunction<SlotContext> slotContext) throws IOException {
+ public int collect(DocSet docs, int slot, IntFunction<SlotContext> slotContext)
+ throws IOException {
collectDocSets.addAndGet(1);
return sub.collect(docs, slot, slotContext);
}
@@ -146,7 +149,7 @@ class DebugAgg extends AggValueSource {
@Override
public void setValues(SimpleOrderedMap<Object> bucket, int slotNum) throws IOException {
- sub.key = this.key; // TODO: Blech... this should be fixed
+ sub.key = this.key; // TODO: Blech... this should be fixed
sub.setValues(bucket, slotNum);
}
@@ -166,58 +169,57 @@ class DebugAgg extends AggValueSource {
public DebugAggNumShards() {
super("debugNumShards");
}
-
+
@Override
public SlotAcc createSlotAcc(FacetContext fcontext, long numDocs, int numSlots) {
return new NumShardsAcc(fcontext, numDocs, numSlots);
}
-
+
@Override
public int hashCode() {
return 0;
}
-
+
@Override
public String description() {
return "debug(numShards)";
}
-
+
public static class NumShardsAcc extends SlotAcc {
public NumShardsAcc(FacetContext fcontext, long numDocs, int numSlots) {
super(fcontext);
}
-
+
@Override
- public void collect(int doc, int slot, IntFunction<SlotContext> slotContext) throws IOException {
+ public void collect(int doc, int slot, IntFunction<SlotContext> slotContext)
+ throws IOException {
// No-Op
}
-
+
@Override
public int compare(int slotA, int slotB) {
return 0;
}
-
+
@Override
public Object getValue(int slotNum) throws IOException {
return 1L;
}
-
+
@Override
public void reset() throws IOException {
// No-Op
}
-
+
@Override
public void resize(Resizer resizer) {
// No-op
}
-
}
-
+
@Override
public FacetMerger createFacetMerger(Object prototype) {
return new FacetModule.FacetLongMerger();
}
-
}
}
diff --git a/solr/test-framework/src/java/org/apache/solr/search/function/NvlValueSourceParser.java b/solr/test-framework/src/java/org/apache/solr/search/function/NvlValueSourceParser.java
index e3bd6a817d1..04738682980 100644
--- a/solr/test-framework/src/java/org/apache/solr/search/function/NvlValueSourceParser.java
+++ b/solr/test-framework/src/java/org/apache/solr/search/function/NvlValueSourceParser.java
@@ -17,7 +17,6 @@
package org.apache.solr.search.function;
import java.io.IOException;
-
import org.apache.lucene.queries.function.FunctionValues;
import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.queries.function.valuesource.SimpleFloatFunction;
@@ -27,47 +26,43 @@ import org.apache.solr.search.SyntaxError;
import org.apache.solr.search.ValueSourceParser;
/**
- * A sample ValueSourceParser for testing. Approximates the oracle NVL function,
- * letting you substitute a value when a "null" is encountered. In this case,
- * null is approximated by a float value, since ValueSource always returns a
- * float, even if the field is undefined for a document.
- *
- * Initialization parameters:
- * - nvlFloatValue: float value to consider as "NULL" when seen in a field. defaults to 0.0f.
- *
- * Example:
- * nvl(vs,2) will return 2 if the vs is NULL (as defined by nvlFloatValue above) or the doc value otherwise
- *
+ * A sample ValueSourceParser for testing. Approximates the oracle NVL function, letting you
+ * substitute a value when a "null" is encountered. In this case, null is approximated by a float
+ * value, since ValueSource always returns a float, even if the field is undefined for a document.
+ *
+ * <p>Initialization parameters: - nvlFloatValue: float value to consider as "NULL" when seen in a
+ * field. defaults to 0.0f.
+ *
+ * <p>Example: nvl(vs,2) will return 2 if the vs is NULL (as defined by nvlFloatValue above) or the
+ * doc value otherwise
*/
public class NvlValueSourceParser extends ValueSourceParser {
-
- /**
- * Value to consider "null" when found in a ValueSource Defaults to 0.0
- */
- private float nvlFloatValue = 0.0f;
- @Override
- public ValueSource parse(FunctionQParser fp) throws SyntaxError {
- ValueSource source = fp.parseValueSource();
- final float nvl = fp.parseFloat();
+ /** Value to consider "null" when found in a ValueSource Defaults to 0.0 */
+ private float nvlFloatValue = 0.0f;
+
+ @Override
+ public ValueSource parse(FunctionQParser fp) throws SyntaxError {
+ ValueSource source = fp.parseValueSource();
+ final float nvl = fp.parseFloat();
- return new SimpleFloatFunction(source) {
- @Override
+ return new SimpleFloatFunction(source) {
+ @Override
protected String name() {
- return "nvl";
- }
+ return "nvl";
+ }
- @Override
- protected float func(int doc, FunctionValues vals) throws IOException {
- float v = vals.floatVal(doc);
- if (v == nvlFloatValue) {
- return nvl;
- } else {
- return v;
- }
+ @Override
+ protected float func(int doc, FunctionValues vals) throws IOException {
+ float v = vals.floatVal(doc);
+ if (v == nvlFloatValue) {
+ return nvl;
+ } else {
+ return v;
}
- };
- }
+ }
+ };
+ }
@Override
public void init(NamedList<?> args) {
diff --git a/solr/test-framework/src/java/org/apache/solr/spelling/SampleComparator.java b/solr/test-framework/src/java/org/apache/solr/spelling/SampleComparator.java
index 095edbb139a..14ebf5b70f3 100644
--- a/solr/test-framework/src/java/org/apache/solr/spelling/SampleComparator.java
+++ b/solr/test-framework/src/java/org/apache/solr/spelling/SampleComparator.java
@@ -15,21 +15,15 @@
* limitations under the License.
*/
package org.apache.solr.spelling;
-import org.apache.lucene.search.spell.SuggestWord;
import java.util.Comparator;
+import org.apache.lucene.search.spell.SuggestWord;
-
-/**
- * Comparator for testing purposes
- *
- **/
+/** Comparator for testing purposes */
public class SampleComparator implements Comparator<SuggestWord> {
-
@Override
public int compare(SuggestWord suggestWord, SuggestWord suggestWord1) {
return suggestWord.string.compareTo(suggestWord1.string);
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/update/processor/BufferingRequestProcessor.java b/solr/test-framework/src/java/org/apache/solr/update/processor/BufferingRequestProcessor.java
index 56b422909d2..68ceed9b289 100644
--- a/solr/test-framework/src/java/org/apache/solr/update/processor/BufferingRequestProcessor.java
+++ b/solr/test-framework/src/java/org/apache/solr/update/processor/BufferingRequestProcessor.java
@@ -19,46 +19,43 @@ package org.apache.solr.update.processor;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-
import org.apache.solr.update.AddUpdateCommand;
import org.apache.solr.update.CommitUpdateCommand;
import org.apache.solr.update.DeleteUpdateCommand;
import org.apache.solr.update.RollbackUpdateCommand;
-public class BufferingRequestProcessor extends UpdateRequestProcessor
-{
+public class BufferingRequestProcessor extends UpdateRequestProcessor {
public List<AddUpdateCommand> addCommands = new ArrayList<>();
public List<DeleteUpdateCommand> deleteCommands = new ArrayList<>();
public List<CommitUpdateCommand> commitCommands = new ArrayList<>();
public List<RollbackUpdateCommand> rollbackCommands = new ArrayList<>();
-
+
public BufferingRequestProcessor(UpdateRequestProcessor next) {
super(next);
}
-
+
@Override
public void processAdd(AddUpdateCommand cmd) throws IOException {
- addCommands.add( cmd );
+ addCommands.add(cmd);
}
@Override
public void processDelete(DeleteUpdateCommand cmd) throws IOException {
- deleteCommands.add( cmd );
+ deleteCommands.add(cmd);
}
@Override
public void processCommit(CommitUpdateCommand cmd) throws IOException {
- commitCommands.add( cmd );
+ commitCommands.add(cmd);
}
-
+
@Override
- public void processRollback(RollbackUpdateCommand cmd) throws IOException
- {
- rollbackCommands.add( cmd );
+ public void processRollback(RollbackUpdateCommand cmd) throws IOException {
+ rollbackCommands.add(cmd);
}
@Override
public void finish() throws IOException {
- // nothing?
+ // nothing?
}
}
diff --git a/solr/test-framework/src/java/org/apache/solr/update/processor/UpdateProcessorTestBase.java b/solr/test-framework/src/java/org/apache/solr/update/processor/UpdateProcessorTestBase.java
index 21c4972efea..97227e5e3a0 100644
--- a/solr/test-framework/src/java/org/apache/solr/update/processor/UpdateProcessorTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/update/processor/UpdateProcessorTestBase.java
@@ -16,46 +16,41 @@
*/
package org.apache.solr.update.processor;
+import java.io.IOException;
import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.common.params.SolrParams;
-import org.apache.solr.common.util.IOUtils;
-import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.SolrInputField;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.IOUtils;
import org.apache.solr.core.SolrCore;
-import org.apache.solr.request.SolrRequestInfo;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.request.SolrRequestInfo;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.update.AddUpdateCommand;
import org.apache.solr.update.CommitUpdateCommand;
import org.apache.solr.update.DeleteUpdateCommand;
-import java.io.IOException;
-
public class UpdateProcessorTestBase extends SolrTestCaseJ4 {
/**
- * Runs a document through the specified chain, and returns the final
- * document used when the chain is completed (NOTE: some chains may
- * modify the document in place
+ * Runs a document through the specified chain, and returns the final document used when the chain
+ * is completed (NOTE: some chains may modify the document in place
*/
- protected SolrInputDocument processAdd(final String chain,
- final SolrInputDocument docIn)
- throws IOException {
+ protected SolrInputDocument processAdd(final String chain, final SolrInputDocument docIn)
+ throws IOException {
return processAdd(chain, new ModifiableSolrParams(), docIn);
}
/**
- * Runs a document through the specified chain, and returns the final
- * document used when the chain is completed (NOTE: some chains may
- * modify the document in place
+ * Runs a document through the specified chain, and returns the final document used when the chain
+ * is completed (NOTE: some chains may modify the document in place
*/
- protected SolrInputDocument processAdd(final String chain,
- final SolrParams requestParams,
- final SolrInputDocument docIn)
- throws IOException {
+ protected SolrInputDocument processAdd(
+ final String chain, final SolrParams requestParams, final SolrInputDocument docIn)
+ throws IOException {
SolrCore core = h.getCore();
UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain);
@@ -91,7 +86,7 @@ public class UpdateProcessorTestBase extends SolrTestCaseJ4 {
SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams());
- CommitUpdateCommand cmd = new CommitUpdateCommand(req,false);
+ CommitUpdateCommand cmd = new CommitUpdateCommand(req, false);
UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
try {
processor.processCommit(cmd);
@@ -136,10 +131,7 @@ public class UpdateProcessorTestBase extends SolrTestCaseJ4 {
}
}
-
- /**
- * Convenience method for building up SolrInputDocuments
- */
+ /** Convenience method for building up SolrInputDocuments */
protected final SolrInputDocument doc(SolrInputField... fields) {
SolrInputDocument d = new SolrInputDocument();
for (SolrInputField f : fields) {
@@ -148,9 +140,7 @@ public class UpdateProcessorTestBase extends SolrTestCaseJ4 {
return d;
}
- /**
- * Convenience method for building up SolrInputFields
- */
+ /** Convenience method for building up SolrInputFields */
final SolrInputField field(String name, Object... values) {
SolrInputField f = new SolrInputField(name);
for (Object v : values) {
@@ -159,9 +149,7 @@ public class UpdateProcessorTestBase extends SolrTestCaseJ4 {
return f;
}
- /**
- * Convenience method for building up SolrInputFields with default boost
- */
+ /** Convenience method for building up SolrInputFields with default boost */
protected final SolrInputField f(String name, Object... values) {
return field(name, values);
}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/BadZookeeperThreadsFilter.java b/solr/test-framework/src/java/org/apache/solr/util/BadZookeeperThreadsFilter.java
index f9bd870819a..c04100d60a4 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/BadZookeeperThreadsFilter.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/BadZookeeperThreadsFilter.java
@@ -23,9 +23,11 @@ public class BadZookeeperThreadsFilter implements ThreadFilter {
@Override
public boolean reject(Thread t) {
String name = t.getName();
-
- StackTraceElement [] stack = t.getStackTrace();
- if (name.startsWith("Thread-") && stack.length > 1 && stack[stack.length - 2].getClassName().equals("org.apache.zookeeper.Login$1")) {
+
+ StackTraceElement[] stack = t.getStackTrace();
+ if (name.startsWith("Thread-")
+ && stack.length > 1
+ && stack[stack.length - 2].getClassName().equals("org.apache.zookeeper.Login$1")) {
return true; // see ZOOKEEPER-2100
}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/BaseTestHarness.java b/solr/test-framework/src/java/org/apache/solr/util/BaseTestHarness.java
index 2f825e33e99..91b411168c1 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/BaseTestHarness.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/BaseTestHarness.java
@@ -15,6 +15,12 @@
* limitations under the License.
*/
package org.apache.solr.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -22,18 +28,12 @@ import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.StandardCharsets;
-
import org.apache.solr.common.SolrException;
import org.apache.solr.common.util.XML;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
-abstract public class BaseTestHarness {
+public abstract class BaseTestHarness {
private static final ThreadLocal<DocumentBuilder> builderTL = new ThreadLocal<>();
private static final ThreadLocal<XPath> xpathTL = new ThreadLocal<>();
@@ -63,10 +63,8 @@ abstract public class BaseTestHarness {
}
}
-
/**
- * A helper method which validates a String against an array of XPath test
- * strings.
+ * A helper method which validates a String against an array of XPath test strings.
*
* @param xml The xml String to validate
* @param tests Array of XPath strings to test (in boolean mode) on the xml
@@ -75,12 +73,13 @@ abstract public class BaseTestHarness {
public static String validateXPath(String xml, String... tests)
throws XPathExpressionException, SAXException {
- if (tests==null || tests.length == 0) return null;
+ if (tests == null || tests.length == 0) return null;
Document document;
try {
- document = getXmlDocumentBuilder().parse(new ByteArrayInputStream
- (xml.getBytes(StandardCharsets.UTF_8)));
+ document =
+ getXmlDocumentBuilder()
+ .parse(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
} catch (UnsupportedEncodingException e1) {
throw new RuntimeException("Totally weird UTF-8 exception", e1);
} catch (IOException e2) {
@@ -88,7 +87,7 @@ abstract public class BaseTestHarness {
}
for (String xp : tests) {
- xp=xp.trim();
+ xp = xp.trim();
Boolean bool = (Boolean) getXpath().evaluate(xp, document, XPathConstants.BOOLEAN);
if (!bool) {
@@ -99,13 +98,14 @@ abstract public class BaseTestHarness {
}
public static Object evaluateXPath(String xml, String xpath, QName returnType)
- throws XPathExpressionException, SAXException {
+ throws XPathExpressionException, SAXException {
if (null == xpath) return null;
Document document;
try {
- document = getXmlDocumentBuilder().parse(new ByteArrayInputStream
- (xml.getBytes(StandardCharsets.UTF_8)));
+ document =
+ getXmlDocumentBuilder()
+ .parse(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
} catch (UnsupportedEncodingException e1) {
throw new RuntimeException("Totally weird UTF-8 exception", e1);
} catch (IOException e2) {
@@ -117,8 +117,7 @@ abstract public class BaseTestHarness {
}
/**
- * A helper that creates an xml &lt;doc&gt; containing all of the
- * fields and values specified
+ * A helper that creates an xml &lt;doc&gt; containing all of the fields and values specified
*
* @param fieldsAndValues 0 and Even numbered args are fields names odds are field values.
*/
@@ -127,20 +126,19 @@ abstract public class BaseTestHarness {
try {
StringWriter w = new StringWriter();
w.append("<doc>");
- for (int i = 0; i < fieldsAndValues.length; i+=2) {
- XML.writeXML(w, "field", fieldsAndValues[i + 1], "name",
- fieldsAndValues[i]);
+ for (int i = 0; i < fieldsAndValues.length; i += 2) {
+ XML.writeXML(w, "field", fieldsAndValues[i + 1], "name", fieldsAndValues[i]);
}
w.append("</doc>");
return w.toString();
} catch (IOException e) {
- throw new RuntimeException
- ("this should never happen with a StringWriter", e);
+ throw new RuntimeException("this should never happen with a StringWriter", e);
}
}
/**
* Generates a delete by query xml string
+ *
* @param q Query that has not already been xml escaped
* @param args The attributes of the delete tag
*/
@@ -149,14 +147,14 @@ abstract public class BaseTestHarness {
StringWriter r = new StringWriter();
XML.writeXML(r, "query", q);
return delete(r.getBuffer().toString(), args);
- } catch(IOException e) {
- throw new RuntimeException
- ("this should never happen with a StringWriter", e);
+ } catch (IOException e) {
+ throw new RuntimeException("this should never happen with a StringWriter", e);
}
}
/**
* Generates a delete by id xml string
+ *
* @param id ID that has not already been xml escaped
* @param args The attributes of the delete tag
*/
@@ -165,14 +163,14 @@ abstract public class BaseTestHarness {
StringWriter r = new StringWriter();
XML.writeXML(r, "id", id);
return delete(r.getBuffer().toString(), args);
- } catch(IOException e) {
- throw new RuntimeException
- ("this should never happen with a StringWriter", e);
+ } catch (IOException e) {
+ throw new RuntimeException("this should never happen with a StringWriter", e);
}
}
/**
* Generates a delete xml string
+ *
* @param val text that has not already been xml escaped
* @param args 0 and Even numbered args are params, Odd numbered args are XML escaped values.
*/
@@ -181,15 +179,13 @@ abstract public class BaseTestHarness {
StringWriter r = new StringWriter();
XML.writeUnescapedXML(r, "delete", val, (Object[]) args);
return r.getBuffer().toString();
- } catch(IOException e) {
- throw new RuntimeException
- ("this should never happen with a StringWriter", e);
+ } catch (IOException e) {
+ throw new RuntimeException("this should never happen with a StringWriter", e);
}
}
/**
- * Helper that returns an &lt;optimize&gt; String with
- * optional key/val pairs.
+ * Helper that returns an &lt;optimize&gt; String with optional key/val pairs.
*
* @param args 0 and Even numbered args are params, Odd numbered args are values.
*/
@@ -200,17 +196,15 @@ abstract public class BaseTestHarness {
public static String simpleTag(String tag, String... args) {
try {
StringWriter writer = new StringWriter();
- XML.writeXML(writer, tag, (String) null, (Object[])args);
+ XML.writeXML(writer, tag, (String) null, (Object[]) args);
return writer.getBuffer().toString();
} catch (IOException e) {
- throw new RuntimeException
- ("this should never happen with a StringWriter", e);
+ throw new RuntimeException("this should never happen with a StringWriter", e);
}
}
/**
- * Helper that returns an &lt;commit&gt; String with
- * optional key/val pairs.
+ * Helper that returns an &lt;commit&gt; String with optional key/val pairs.
*
* @param args 0 and Even numbered args are params, Odd numbered args are values.
*/
@@ -219,23 +213,23 @@ abstract public class BaseTestHarness {
}
/** Reloads the core */
- abstract public void reload() throws Exception;
+ public abstract void reload() throws Exception;
/**
- * Processes an "update" (add, commit or optimize) and
- * returns the response as a String.
- *
- * This method does NOT commit after the request.
+ * Processes an "update" (add, commit or optimize) and returns the response as a String.
+ *
+ * <p>This method does NOT commit after the request.
*
* @param xml The XML of the update
* @return The XML response to the update
*/
- abstract public String update(String xml);
+ public abstract String update(String xml);
/**
* Validates that an "update" (add, commit or optimize) results in success.
*
- * :TODO: currently only deals with one add/doc at a time, this will need changed if/when SOLR-2 is resolved
+ * <p>:TODO: currently only deals with one add/doc at a time, this will need changed if/when
+ * SOLR-2 is resolved
*
* @param xml The XML of the update
* @return null if successful, otherwise the XML response to the update
@@ -247,7 +241,8 @@ abstract public class BaseTestHarness {
/**
* Validates that an "update" (add, commit or optimize) results in success.
*
- * :TODO: currently only deals with one add/doc at a time, this will need changed if/when SOLR-2 is resolved
+ * <p>:TODO: currently only deals with one add/doc at a time, this will need changed if/when
+ * SOLR-2 is resolved
*
* @param xml The XML of the update
* @return null if successful, otherwise the XML response to the update
@@ -257,14 +252,15 @@ abstract public class BaseTestHarness {
return checkUpdateStatus(xml, "1");
} catch (SolrException e) {
// return ((SolrException)e).getMessage();
- return null; // success
+ return null; // success
}
}
/**
* Validates that an "update" (add, commit or optimize) results in success.
*
- * :TODO: currently only deals with one add/doc at a time, this will need changed if/when SOLR-2 is resolved
+ * <p>:TODO: currently only deals with one add/doc at a time, this will need changed if/when
+ * SOLR-2 is resolved
*
* @param xml The XML of the update
* @return null if successful, otherwise the XML response to the update
@@ -272,11 +268,10 @@ abstract public class BaseTestHarness {
public String checkUpdateStatus(String xml, String code) throws SAXException {
try {
String res = update(xml);
- String valid = validateXPath(res, "//int[@name='status']="+code );
+ String valid = validateXPath(res, "//int[@name='status']=" + code);
return (null == valid) ? null : res;
} catch (XPathExpressionException e) {
- throw new RuntimeException
- ("?!? static xpath has bug?", e);
+ throw new RuntimeException("?!? static xpath has bug?", e);
}
}
}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/DOMUtilTestBase.java b/solr/test-framework/src/java/org/apache/solr/util/DOMUtilTestBase.java
index 9858fed9aed..a864a08e79a 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/DOMUtilTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/DOMUtilTestBase.java
@@ -16,40 +16,38 @@
*/
package org.apache.solr.util;
-
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
-
import org.apache.solr.SolrTestCase;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
public abstract class DOMUtilTestBase extends SolrTestCase {
-
+
private DocumentBuilder builder;
private static final XPathFactory xpathFactory = XPathFactory.newInstance();
-
+
@Override
public void setUp() throws Exception {
super.setUp();
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
}
- public Node getNode( String xml, String path ) throws Exception {
- return getNode( getDocument(xml), path );
+ public Node getNode(String xml, String path) throws Exception {
+ return getNode(getDocument(xml), path);
}
-
- public Node getNode( Document doc, String path ) throws Exception {
+
+ public Node getNode(Document doc, String path) throws Exception {
XPath xpath = xpathFactory.newXPath();
- return (Node)xpath.evaluate(path, doc, XPathConstants.NODE);
+ return (Node) xpath.evaluate(path, doc, XPathConstants.NODE);
}
-
- public Document getDocument( String xml ) throws Exception {
+
+ public Document getDocument(String xml) throws Exception {
return builder.parse(new InputSource(new StringReader(xml)));
}
}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/DirectoryUtil.java b/solr/test-framework/src/java/org/apache/solr/util/DirectoryUtil.java
index 1758ff2d8fc..6a341dcecdd 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/DirectoryUtil.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/DirectoryUtil.java
@@ -28,30 +28,38 @@ public class DirectoryUtil {
/**
* Recursively copy the contents of one directory into another. For example:
+ *
* <pre>
* copyDirectory(Path.of("src"), Path.of("dst"))
* </pre>
- * will copy the contents of src directly into dst. This will not create a new "src" folder inside of dst.
+ *
+ * will copy the contents of src directly into dst. This will not create a new "src" folder inside
+ * of dst.
*/
- public static void copyDirectoryContents(final Path source, final Path destination) throws IOException {
+ public static void copyDirectoryContents(final Path source, final Path destination)
+ throws IOException {
assert source.getFileSystem().equals(destination.getFileSystem());
- Files.walkFileTree(source, new SimpleFileVisitor<>() {
- private Path resolveTarget(Path other) {
- return destination.resolve(source.relativize(other));
- }
+ Files.walkFileTree(
+ source,
+ new SimpleFileVisitor<>() {
+ private Path resolveTarget(Path other) {
+ return destination.resolve(source.relativize(other));
+ }
- @Override
- public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
- Files.createDirectories(resolveTarget(dir));
- return FileVisitResult.CONTINUE;
- }
+ @Override
+ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
+ throws IOException {
+ Files.createDirectories(resolveTarget(dir));
+ return FileVisitResult.CONTINUE;
+ }
- @Override
- public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
- Files.copy(file, resolveTarget(file));
- return FileVisitResult.CONTINUE;
- }
- });
+ @Override
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
+ throws IOException {
+ Files.copy(file, resolveTarget(file));
+ return FileVisitResult.CONTINUE;
+ }
+ });
}
}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/ErrorLogMuter.java b/solr/test-framework/src/java/org/apache/solr/util/ErrorLogMuter.java
index 10871be26d0..e9ab1b011f2 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/ErrorLogMuter.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/ErrorLogMuter.java
@@ -17,16 +17,13 @@
package org.apache.solr.util;
-import java.lang.invoke.MethodHandles;
import java.io.Closeable;
+import java.lang.invoke.MethodHandles;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import java.util.function.Predicate;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.apache.solr.common.util.SuppressForbidden;
-
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.core.Filter;
@@ -36,72 +33,91 @@ import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.LoggerConfig;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.message.Message;
+import org.apache.solr.common.util.SuppressForbidden;
/**
- * <p>
- * Helper code for "Muting" ERROR log messages that you expect as a result of the things you are testing,
- * so they aren't a distraction in test logs. Example usage...
- * </p>
- * <code>
+ * Helper code for "Muting" ERROR log messages that you expect as a result of the things you are
+ * testing, so they aren't a distraction in test logs. Example usage... <code>
* try (ErrorLogMuter errors = ErrorLogMuter.substring("nullfirst")) {
* assertQEx( "invalid query format",
* req( "q","id_i:1000", "sort", "nullfirst" ), 400 );
* assertEquals(1, errors.getCount());
* }
* </code>
- * <p>
- * ERROR messages are considered a match if their input matches either the message String, or the <code>toString</code> of an included
- * {@link Throwable}, or any of the recursive {@link Throwable#getCause}es of an included <code>Throwable</code>.
- * </p>
- * <p>
- * Matching ERROR messages are "muted" by filtering them out of the ROOT logger. Any Appenders attached to more specific
- * Loggers may still include these "muted" ERRROR messages.
- * </p>
+ *
+ * <p>ERROR messages are considered a match if their input matches either the message String, or the
+ * <code>toString</code> of an included {@link Throwable}, or any of the recursive {@link
+ * Throwable#getCause}es of an included <code>Throwable</code>.
+ *
+ * <p>Matching ERROR messages are "muted" by filtering them out of the ROOT logger. Any Appenders
+ * attached to more specific Loggers may still include these "muted" ERRROR messages.
*/
-@SuppressForbidden(reason="We need to use log4J2 classes directly to check that the ErrorLogMuter is working")
+@SuppressForbidden(
+ reason = "We need to use log4J2 classes directly to check that the ErrorLogMuter is working")
public final class ErrorLogMuter implements Closeable, AutoCloseable {
- // far easier to use FQN for our (one) slf4j Logger then to use a FQN every time we refe to log4j2 Logger
- private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); // nowarn_valid_logger
+ // far easier to use FQN for our (one) slf4j Logger then to use a FQN every time we refe to log4j2
+ // Logger
+ private static final org.slf4j.Logger log =
+ org.slf4j.LoggerFactory.getLogger(
+ MethodHandles.lookup().lookupClass()); // nowarn_valid_logger
- private final static LoggerContext CTX = LoggerContext.getContext(false);
-
- /** @see #createName */
- private final static AtomicInteger ID_GEN = new AtomicInteger(0);
+ private static final LoggerContext CTX = LoggerContext.getContext(false);
+
+ /**
+ * @see #createName
+ */
+ private static final AtomicInteger ID_GEN = new AtomicInteger(0);
/** generate a unique name for each muter to use in it's own lifecycle logging */
private static String createName(final String type) {
- return MethodHandles.lookup().lookupClass().getSimpleName() + "-" + type + "-" + ID_GEN.incrementAndGet();
+ return MethodHandles.lookup().lookupClass().getSimpleName()
+ + "-"
+ + type
+ + "-"
+ + ID_GEN.incrementAndGet();
}
/** Mutes ERROR log messages that contain the input as a substring */
- public static ErrorLogMuter substring(final String substr) {
+ public static ErrorLogMuter substring(final String substr) {
final String name = createName("substring");
log.info("Creating {} for ERROR logs containing the substring: {}", name, substr);
- return new ErrorLogMuter(name, (str) -> { return str.contains(substr); });
+ return new ErrorLogMuter(
+ name,
+ (str) -> {
+ return str.contains(substr);
+ });
}
-
- /**
- * Mutes ERROR log messages that <em>partially</em> match the specified regex.
+
+ /**
+ * Mutes ERROR log messages that <em>partially</em> match the specified regex.
+ *
* @see Matcher#find
*/
- public static ErrorLogMuter regex(final String regex) {
+ public static ErrorLogMuter regex(final String regex) {
return regex(Pattern.compile(regex));
}
- /**
- * Mutes ERROR log messages that <em>partially</em> match the specified regex.
+ /**
+ * Mutes ERROR log messages that <em>partially</em> match the specified regex.
+ *
* @see Matcher#find
*/
- public static ErrorLogMuter regex(final Pattern pat) {
+ public static ErrorLogMuter regex(final Pattern pat) {
final String name = createName("regex");
log.info("Creating {} for ERROR logs matching regex: {}", name, pat);
- return new ErrorLogMuter(name, (str) -> { return pat.matcher(str).find(); });
+ return new ErrorLogMuter(
+ name,
+ (str) -> {
+ return pat.matcher(str).find();
+ });
}
private final String name;
private final CountingFilter rootFilter;
private final AtomicBoolean closed = new AtomicBoolean(false);
- /** @see StringPredicateErrorOrThrowableFilter */
+ /**
+ * @see StringPredicateErrorOrThrowableFilter
+ */
private ErrorLogMuter(final String name, final Predicate<String> predicate) {
assert null != name;
assert null != predicate;
@@ -111,21 +127,21 @@ public final class ErrorLogMuter implements Closeable, AutoCloseable {
this.name = name;
this.rootFilter = new StringPredicateErrorOrThrowableFilter(predicate);
rootLoggerConfig.addFilter(this.rootFilter);
-
+
CTX.updateLoggers();
}
- /**
- * The number of ERROR messages muted (by this instance) so far in it's lifecycle.
- * This number may be less then the number of ERROR messages expected if multiple ErrorLogMuter
- * objects are in use which match the same ERROR log messages
+ /**
+ * The number of ERROR messages muted (by this instance) so far in it's lifecycle. This number may
+ * be less then the number of ERROR messages expected if multiple ErrorLogMuter objects are in use
+ * which match the same ERROR log messages
*/
public int getCount() {
return rootFilter.getCount();
}
-
+
public void close() {
- if (! closed.getAndSet(true)) { // Don't muck with log4j if we accidently get a double close
+ if (!closed.getAndSet(true)) { // Don't muck with log4j if we accidently get a double close
CTX.getConfiguration().getRootLogger().removeFilter(rootFilter);
CTX.updateLoggers();
if (log.isInfoEnabled()) {
@@ -134,31 +150,36 @@ public final class ErrorLogMuter implements Closeable, AutoCloseable {
}
}
- @SuppressForbidden(reason="We need to use log4J2 classes directly to check that the ErrorLogMuter is working")
+ @SuppressForbidden(
+ reason = "We need to use log4J2 classes directly to check that the ErrorLogMuter is working")
private static interface CountingFilter extends Filter {
/** The number of messages that have been filtered */
public int getCount();
}
-
+
/**
- * <p>
- * Given a String predicate, this filter DENY's log events that are at least as specific as <code>ERROR</code>, and have a message or
- * {@link Throwable#toString} that matches the predicate. When a Throwable is evaluated, the predicate is tested against the
- * <code>toString()</code> of all nested causes.
- * </p>
- * <p>
- * Any message that is not at least as specific as <code>ERROR</code>, or that the predicate does not match, are left NEUTRAL.
- * </p>
+ * Given a String predicate, this filter DENY's log events that are at least as specific as <code>
+ * ERROR</code>, and have a message or {@link Throwable#toString} that matches the predicate. When
+ * a Throwable is evaluated, the predicate is tested against the <code>toString()</code> of all
+ * nested causes.
+ *
+ * <p>Any message that is not at least as specific as <code>ERROR</code>, or that the predicate
+ * does not match, are left NEUTRAL.
*/
- @SuppressForbidden(reason="We need to use log4J2 classes directly to check that the ErrorLogMuter is working")
- private static final class StringPredicateErrorOrThrowableFilter extends AbstractFilter implements CountingFilter {
+ @SuppressForbidden(
+ reason = "We need to use log4J2 classes directly to check that the ErrorLogMuter is working")
+ private static final class StringPredicateErrorOrThrowableFilter extends AbstractFilter
+ implements CountingFilter {
// TODO: could probably refactor to share some code with LogListener
-
- // This could probably be implemented with a combination of "LevelRangeFilter" and "ConjunctionFilter" if "ConjunctionFilter" existed
- // Since it doesn't, we write our own more specialized impl instead of writing & combining multiple generalized versions
+
+ // This could probably be implemented with a combination of "LevelRangeFilter" and
+ // "ConjunctionFilter" if "ConjunctionFilter" existed
+ // Since it doesn't, we write our own more specialized impl instead of writing & combining
+ // multiple generalized versions
final Predicate<String> predicate;
final AtomicInteger count = new AtomicInteger(0);
+
public StringPredicateErrorOrThrowableFilter(final Predicate<String> predicate) {
super(Filter.Result.DENY, Filter.Result.NEUTRAL);
assert null != predicate;
@@ -169,11 +190,17 @@ public final class ErrorLogMuter implements Closeable, AutoCloseable {
return count.get();
}
- // NOTE: This is inspired by log4j's RegexFilter, but with an eye to being more "garbage-free" friendly
- // Oddly, StringMatchFilter does things differnetly and acts like it needs to (re?) format msgs when params are provided
- // Since RegexFilter has tests, and StringMatchFilter doesn't, we assume RegexFilter knows what it's doing...
+ // NOTE: This is inspired by log4j's RegexFilter, but with an eye to being more "garbage-free"
+ // friendly
+ // Oddly, StringMatchFilter does things differnetly and acts like it needs to (re?) format msgs
+ // when params are provided
+ // Since RegexFilter has tests, and StringMatchFilter doesn't, we assume RegexFilter knows what
+ // it's doing...
- /** The main logic of our filter: Evaluate predicate against log msg &amp; throwable msg(s) if and only if ERROR; else mismatch */
+ /**
+ * The main logic of our filter: Evaluate predicate against log msg &amp; throwable msg(s) if
+ * and only if ERROR; else mismatch
+ */
private Filter.Result doFilter(final Level level, final String msg, final Throwable throwable) {
if (level.isMoreSpecificThan(Level.ERROR)) {
if (null != msg && predicate.test(msg)) {
@@ -187,72 +214,150 @@ public final class ErrorLogMuter implements Closeable, AutoCloseable {
}
return getOnMismatch();
}
-
+
/** helper to be called by doFilter anytime it wants to return a "match" */
private Filter.Result matchAndCount() {
count.incrementAndGet();
return getOnMatch();
}
-
- public Result filter(Logger logger, Level level, Marker marker, String msg,
- Object... params) {
+
+ public Result filter(Logger logger, Level level, Marker marker, String msg, Object... params) {
return doFilter(level, msg, null);
}
- public Result filter(Logger logger, Level level, Marker marker, String msg,
- Object p0) {
+
+ public Result filter(Logger logger, Level level, Marker marker, String msg, Object p0) {
return doFilter(level, msg, null);
}
- public Result filter(Logger logger, Level level, Marker marker, String msg,
- Object p0, Object p1) {
+
+ public Result filter(
+ Logger logger, Level level, Marker marker, String msg, Object p0, Object p1) {
return doFilter(level, msg, null);
}
- public Result filter(Logger logger, Level level, Marker marker, String msg,
- Object p0, Object p1, Object p2) {
+
+ public Result filter(
+ Logger logger, Level level, Marker marker, String msg, Object p0, Object p1, Object p2) {
return doFilter(level, msg, null);
}
- public Result filter(Logger logger, Level level, Marker marker, String msg,
- Object p0, Object p1, Object p2, Object p3) {
+
+ public Result filter(
+ Logger logger,
+ Level level,
+ Marker marker,
+ String msg,
+ Object p0,
+ Object p1,
+ Object p2,
+ Object p3) {
return doFilter(level, msg, null);
}
- public Result filter(Logger logger, Level level, Marker marker, String msg,
- Object p0, Object p1, Object p2, Object p3, Object p4) {
+
+ public Result filter(
+ Logger logger,
+ Level level,
+ Marker marker,
+ String msg,
+ Object p0,
+ Object p1,
+ Object p2,
+ Object p3,
+ Object p4) {
return doFilter(level, msg, null);
}
- public Result filter(Logger logger, Level level, Marker marker, String msg,
- Object p0, Object p1, Object p2, Object p3, Object p4, Object p5) {
- return doFilter(level,msg, null);
+
+ public Result filter(
+ Logger logger,
+ Level level,
+ Marker marker,
+ String msg,
+ Object p0,
+ Object p1,
+ Object p2,
+ Object p3,
+ Object p4,
+ Object p5) {
+ return doFilter(level, msg, null);
}
- public Result filter(Logger logger, Level level, Marker marker, String msg,
- Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6) {
+
+ public Result filter(
+ Logger logger,
+ Level level,
+ Marker marker,
+ String msg,
+ Object p0,
+ Object p1,
+ Object p2,
+ Object p3,
+ Object p4,
+ Object p5,
+ Object p6) {
return doFilter(level, msg, null);
}
- public Result filter(Logger logger, Level level, Marker marker, String msg,
- Object p0, Object p1, Object p2, Object p3, Object p4,
- Object p5, Object p6, Object p7) {
+
+ public Result filter(
+ Logger logger,
+ Level level,
+ Marker marker,
+ String msg,
+ Object p0,
+ Object p1,
+ Object p2,
+ Object p3,
+ Object p4,
+ Object p5,
+ Object p6,
+ Object p7) {
return doFilter(level, msg, null);
}
- public Result filter(Logger logger, Level level, Marker marker, String msg,
- Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8) {
+
+ public Result filter(
+ Logger logger,
+ Level level,
+ Marker marker,
+ String msg,
+ Object p0,
+ Object p1,
+ Object p2,
+ Object p3,
+ Object p4,
+ Object p5,
+ Object p6,
+ Object p7,
+ Object p8) {
return doFilter(level, msg, null);
}
- public Result filter(Logger logger, Level level, Marker marker, String msg,
- Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8, Object p9) {
+
+ public Result filter(
+ Logger logger,
+ Level level,
+ Marker marker,
+ String msg,
+ Object p0,
+ Object p1,
+ Object p2,
+ Object p3,
+ Object p4,
+ Object p5,
+ Object p6,
+ Object p7,
+ Object p8,
+ Object p9) {
return doFilter(level, msg, null);
}
- public Result filter(Logger logger, Level level, Marker marker, Object msg,
- Throwable t) {
+
+ public Result filter(Logger logger, Level level, Marker marker, Object msg, Throwable t) {
return doFilter(level, null == msg ? null : msg.toString(), t);
}
- public Result filter(Logger logger, Level level, Marker marker, Message msg,
- Throwable t) {
+
+ public Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t) {
return doFilter(level, msg.getFormattedMessage(), t);
}
+
public Result filter(LogEvent event) {
- // NOTE: For our usage, we're not worried about needing to filter LogEvents rom remote JVMs with ThrowableProxy
+ // NOTE: For our usage, we're not worried about needing to filter LogEvents rom remote JVMs
+ // with ThrowableProxy
// stand ins for Throwabls that don't exist in our classloader...
- return doFilter(event.getLevel(),
- event.getMessage().getFormattedMessage(),
- event.getThrown());
+ return doFilter(
+ event.getLevel(), event.getMessage().getFormattedMessage(), event.getThrown());
}
}
}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/ExternalPaths.java b/solr/test-framework/src/java/org/apache/solr/util/ExternalPaths.java
index 7e619cb55c0..ca2e762e6a5 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/ExternalPaths.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/ExternalPaths.java
@@ -18,42 +18,48 @@ package org.apache.solr.util;
import java.io.File;
-
/**
- * Some tests need to reach outside the classpath to get certain resources (e.g. the example configuration).
- * This class provides some paths to allow them to do this.
+ * Some tests need to reach outside the classpath to get certain resources (e.g. the example
+ * configuration). This class provides some paths to allow them to do this.
+ *
* @lucene.internal
*/
public class ExternalPaths {
/**
- * <p>
- * The main directory path for the solr source being built if it can be determined. If it
- * can not be determined -- possily because the current context is a client code base
- * using hte test frameowrk -- then this variable will be null.
- * </p>
- * <p>
- * Note that all other static paths available in this class are derived from the source
- * home, and if it is null, those paths will just be relative to 'null' and may not be
- * meaningful.
+ * The main directory path for the solr source being built if it can be determined. If it can not
+ * be determined -- possily because the current context is a client code base using hte test
+ * frameowrk -- then this variable will be null.
+ *
+ * <p>Note that all other static paths available in this class are derived from the source home,
+ * and if it is null, those paths will just be relative to 'null' and may not be meaningful.
*/
public static final String SOURCE_HOME = determineSourceHome();
- /** @see #SOURCE_HOME */
+ /**
+ * @see #SOURCE_HOME
+ */
public static String WEBAPP_HOME = new File(SOURCE_HOME, "webapp/web").getAbsolutePath();
- /** @see #SOURCE_HOME */
+ /**
+ * @see #SOURCE_HOME
+ */
public static String DEFAULT_CONFIGSET =
new File(SOURCE_HOME, "server/solr/configsets/_default/conf").getAbsolutePath();
- /** @see #SOURCE_HOME */
+ /**
+ * @see #SOURCE_HOME
+ */
public static String TECHPRODUCTS_CONFIGSET =
- new File(SOURCE_HOME, "server/solr/configsets/sample_techproducts_configs/conf").getAbsolutePath();
+ new File(SOURCE_HOME, "server/solr/configsets/sample_techproducts_configs/conf")
+ .getAbsolutePath();
- /** @see #SOURCE_HOME */
+ /**
+ * @see #SOURCE_HOME
+ */
public static String SERVER_HOME = new File(SOURCE_HOME, "server/solr").getAbsolutePath();
/**
- * Ugly, ugly hack to determine the example home without depending on the CWD
- * this is needed for example/multicore tests which reside outside the classpath.
- * if the source home can't be determined, this method returns null.
+ * Ugly, ugly hack to determine the example home without depending on the CWD this is needed for
+ * example/multicore tests which reside outside the classpath. if the source home can't be
+ * determined, this method returns null.
*/
static String determineSourceHome() {
try {
@@ -64,7 +70,8 @@ public class ExternalPaths {
file = new File(ExternalPaths.class.getClassLoader().getResource("solr/conf").toURI());
}
} catch (Exception e) {
- // If there is no "solr/conf" in the classpath, fall back to searching from the current directory.
+ // If there is no "solr/conf" in the classpath, fall back to searching from the current
+ // directory.
file = new File(System.getProperty("tests.src.home", "."));
}
File base = file.getAbsoluteFile();
diff --git a/solr/test-framework/src/java/org/apache/solr/util/LogLevel.java b/solr/test-framework/src/java/org/apache/solr/util/LogLevel.java
index 0e488e7669f..af7451944e9 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/LogLevel.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/LogLevel.java
@@ -25,7 +25,6 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.HashMap;
import java.util.Map;
-
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration;
@@ -35,9 +34,8 @@ import org.apache.solr.common.util.SuppressForbidden;
/**
* Annotation specifying the log level for a particular test case or method
*
- * Log levels are set for different classes by passing a configuration string
- * to the annotation, like this:
- * <code>
+ * <p>Log levels are set for different classes by passing a configuration string to the annotation,
+ * like this: <code>
* {@literal @}LogLevel("org.apache.solr=DEBUG;org.apache.solr.core=INFO")
* </code>
*/
@@ -47,12 +45,10 @@ import org.apache.solr.common.util.SuppressForbidden;
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface LogLevel {
- /**
- * A log-level definition string
- */
+ /** A log-level definition string */
public String value();
- @SuppressForbidden(reason="Specific to Log4J2")
+ @SuppressForbidden(reason = "Specific to Log4J2")
public static class Configurer {
private static Map<String, Level> parseFrom(String input) {
@@ -81,33 +77,33 @@ public @interface LogLevel {
final Configuration config = ctx.getConfiguration();
final Map<String, Level> oldLevels = new HashMap<>();
- logLevels.forEach((loggerName, newLevel) -> {
- final LoggerConfig logConfig = config.getLoggerConfig(loggerName);
- if (loggerName.equals(logConfig.getName())) {
- // we have an existing LoggerConfig for this specific loggerName
- // record the existing 'old' level...
- oldLevels.put(loggerName, logConfig.getLevel());
- // ...and set the new one (or remove if null) ...
- if (null == newLevel) {
- config.removeLogger(loggerName);
- } else {
- logConfig.setLevel(newLevel);
- }
- } else {
- // there is no existing configuration for the exact loggerName, logConfig is some ancestor
- // record an 'old' level of 'null' to track the lack of any configured level...
- oldLevels.put(loggerName, null);
- // ...and now create a new logger config wih our new level
- final LoggerConfig newLoggerConfig = new LoggerConfig(loggerName, newLevel, true);
- config.addLogger(loggerName, newLoggerConfig);
- }
+ logLevels.forEach(
+ (loggerName, newLevel) -> {
+ final LoggerConfig logConfig = config.getLoggerConfig(loggerName);
+ if (loggerName.equals(logConfig.getName())) {
+ // we have an existing LoggerConfig for this specific loggerName
+ // record the existing 'old' level...
+ oldLevels.put(loggerName, logConfig.getLevel());
+ // ...and set the new one (or remove if null) ...
+ if (null == newLevel) {
+ config.removeLogger(loggerName);
+ } else {
+ logConfig.setLevel(newLevel);
+ }
+ } else {
+ // there is no existing configuration for the exact loggerName, logConfig is some
+ // ancestor record an 'old' level of 'null' to track the lack of any configured
+ // level...
+ oldLevels.put(loggerName, null);
+ // ...and now create a new logger config wih our new level
+ final LoggerConfig newLoggerConfig = new LoggerConfig(loggerName, newLevel, true);
+ config.addLogger(loggerName, newLoggerConfig);
+ }
- assert oldLevels.containsKey(loggerName);
- });
+ assert oldLevels.containsKey(loggerName);
+ });
ctx.updateLoggers();
return oldLevels;
}
-
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/LogListener.java b/solr/test-framework/src/java/org/apache/solr/util/LogListener.java
index 330edaf31bb..59434149ce1 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/LogListener.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/LogListener.java
@@ -16,20 +16,18 @@
*/
package org.apache.solr.util;
-import java.lang.invoke.MethodHandles;
-import java.io.Closeable;
+import static junit.framework.Assert.assertEquals;
+import java.io.Closeable;
+import java.lang.invoke.MethodHandles;
import java.util.Queue;
-import java.util.regex.Pattern;
-import java.util.function.Predicate;
-
import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
-
-import org.apache.solr.common.util.SuppressForbidden;
+import java.util.function.Predicate;
+import java.util.regex.Pattern;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.core.Filter;
@@ -37,29 +35,28 @@ import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.appender.AbstractAppender;
-import org.apache.logging.log4j.core.config.Property;
-import org.apache.logging.log4j.core.impl.MutableLogEvent;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;
+import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
+import org.apache.logging.log4j.core.impl.MutableLogEvent;
import org.apache.logging.log4j.message.Message;
-
-import static junit.framework.Assert.assertEquals;
+import org.apache.solr.common.util.SuppressForbidden;
/**
- * <p>
- * Helper code to listen for {@link LogEvent} messages (via a {@link Queue}) that you expect as a result of the things you are testing,
- * So you can make assertions about when a particular action should/shouldn't cause Solr to produce a particular Log message
- * </p>
- * <code>
+ * Helper code to listen for {@link LogEvent} messages (via a {@link Queue}) that you expect as a
+ * result of the things you are testing, So you can make assertions about when a particular action
+ * should/shouldn't cause Solr to produce a particular Log message
+ *
+ * <p><code>
* // simplest possible usage...
* // Listen for any erors from the SolrCore logger, and assert that there are none...
* try (LogListener errLog = LogListener.error(SolrCore.class)) {
* // ... some test code ...
- *
+ *
* assertEquals(0, errLog.getCount());
* }
- *
+ *
* // You can also use a substring or regex to restrict the messages that are considered,
* // and make assertions about the LogEvent's that match...
* try (LogListener secWarnLog = LogListener.warn("org.apache.solr.security").substring("PKI")) {
@@ -77,40 +74,46 @@ import static junit.framework.Assert.assertEquals;
* assertEquals("xyz", logEvent.getContextData().getValue("tid")); // check the MDC data
* }
* </code>
- *
- * <p>
- * Each <code>LogListener</code> captures &amp; queues matching Log events until it is {@link #close()}ed. By default the Queue is bounded
- * at a max capacity of 100. Regardless of what Queue is used, if a Log event can't be queued (due to capacity limiting), or if events
- * are still left in the Queue when the listener is closed, then the {@link #close()} method will cause a test failure.
- * </p>
*
- * <p>
- * Filtering methods such {@link #substring} and {@link #regex} can be used to restrict which Log events are recorded.
- * </p>
- *
- * <p>
- * Log messages are only recorded if they <em>strictly</em> match the Level specified, but the Logger "name" specified is matched
- * hierarchically against any child Loggers (ie: You must know exactly what Log Level you are interested in, but you can capture all
- * messages from the Loggers under a java package, or from inner classes of a single Logger)
- * </p>
+ * <p>Each <code>LogListener</code> captures &amp; queues matching Log events until it is {@link
+ * #close()}ed. By default the Queue is bounded at a max capacity of 100. Regardless of what Queue
+ * is used, if a Log event can't be queued (due to capacity limiting), or if events are still left
+ * in the Queue when the listener is closed, then the {@link #close()} method will cause a test
+ * failure.
*
- * <p>
- * <b>NOTE:</b> You Can <em>not</em> listen for ERROR messages from the root logger (<code>""</code>) If they are being "muted" by {@link ErrorLogMuter}.
- * </p>
+ * <p>Filtering methods such {@link #substring} and {@link #regex} can be used to restrict which Log
+ * events are recorded.
+ *
+ * <p>Log messages are only recorded if they <em>strictly</em> match the Level specified, but the
+ * Logger "name" specified is matched hierarchically against any child Loggers (ie: You must know
+ * exactly what Log Level you are interested in, but you can capture all messages from the Loggers
+ * under a java package, or from inner classes of a single Logger)
+ *
+ * <p><b>NOTE:</b> You Can <em>not</em> listen for ERROR messages from the root logger (<code>""
+ * </code>) If they are being "muted" by {@link ErrorLogMuter}.
*/
-@SuppressForbidden(reason="We need to use log4J2 classes directly")
+@SuppressForbidden(reason = "We need to use log4J2 classes directly")
public final class LogListener implements Closeable, AutoCloseable {
- // far easier to use FQN for our (one) slf4j Logger then to use a FQN every time we refe to log4j2 Logger
- private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); // nowarn_valid_logger
+ // far easier to use FQN for our (one) slf4j Logger then to use a FQN every time we refe to log4j2
+ // Logger
+ private static final org.slf4j.Logger log =
+ org.slf4j.LoggerFactory.getLogger(
+ MethodHandles.lookup().lookupClass()); // nowarn_valid_logger
+
+ private static final LoggerContext CTX = LoggerContext.getContext(false);
- private final static LoggerContext CTX = LoggerContext.getContext(false);
-
- /** @see #createName */
- private final static AtomicInteger ID_GEN = new AtomicInteger(0);
+ /**
+ * @see #createName
+ */
+ private static final AtomicInteger ID_GEN = new AtomicInteger(0);
/** generate a unique name for each instance to use in it's own lifecycle logging */
private static String createName(final Level level) {
- return MethodHandles.lookup().lookupClass().getSimpleName() + "-" + level + "-" + ID_GEN.incrementAndGet();
+ return MethodHandles.lookup().lookupClass().getSimpleName()
+ + "-"
+ + level
+ + "-"
+ + ID_GEN.incrementAndGet();
}
/** Listens for ERROR log messages at the ROOT logger */
@@ -125,7 +128,7 @@ public final class LogListener implements Closeable, AutoCloseable {
public static LogListener error(final String logger) {
return create(Level.ERROR, logger);
}
-
+
/** Listens for WARN log messages at the ROOT logger */
public static LogListener warn() {
return warn("");
@@ -138,7 +141,7 @@ public final class LogListener implements Closeable, AutoCloseable {
public static LogListener warn(final String logger) {
return create(Level.WARN, logger);
}
-
+
/** Listens for INFO log messages at the ROOT logger */
public static LogListener info() {
return info("");
@@ -154,14 +157,13 @@ public final class LogListener implements Closeable, AutoCloseable {
// TODO: more factories for other levels?
// TODO: no-arg factory variants that use "" -- simpler syntax for ROOT logger?
-
+
private static LogListener create(final Level level, final String logger) {
final String name = createName(level);
log.info("Creating {} for log messages from: {}", name, logger);
return new LogListener(name, logger, level);
}
-
private final String name;
private final String loggerName;
private final boolean removeLoggerConfigWhenDone;
@@ -169,7 +171,7 @@ public final class LogListener implements Closeable, AutoCloseable {
private final AtomicBoolean closed = new AtomicBoolean(false);
private final MutablePredicateFilter filter;
private final QueueAppender loggerAppender;
-
+
private LogListener(final String name, final String loggerName, final Level level) {
assert null != name;
assert null != loggerName;
@@ -177,134 +179,155 @@ public final class LogListener implements Closeable, AutoCloseable {
this.name = name;
this.loggerName = loggerName;
-
+
final Configuration config = CTX.getConfiguration();
-
- // This may match loggerName, or it may be the 'nearest parent' if nothing is explicitly configured for loggerName
+
+ // This may match loggerName, or it may be the 'nearest parent' if nothing is explicitly
+ // configured for loggerName
LoggerConfig loggerConfig = config.getLoggerConfig(loggerName);
- // if loggerConfig refers to our nearest parent logger, then we don't have an existing LoggerConfig for this specific loggerName
+ // if loggerConfig refers to our nearest parent logger, then we don't have an existing
+ // LoggerConfig for this specific loggerName
// so we have to add one (and remember to clean it up later)
- this.removeLoggerConfigWhenDone = ! loggerName.equals(loggerConfig.getName());
- if ( this.removeLoggerConfigWhenDone ) {
- // NOTE: By default inherit the same level as our existing "parent" level so we don't spam our parent (nor hide less specific messages)
+ this.removeLoggerConfigWhenDone = !loggerName.equals(loggerConfig.getName());
+ if (this.removeLoggerConfigWhenDone) {
+ // NOTE: By default inherit the same level as our existing "parent" level so we don't spam our
+ // parent (nor hide less specific messages)
loggerConfig = new LoggerConfig(loggerName, null, true);
config.addLogger(loggerName, loggerConfig);
}
-
- // Regardless of wether loggerConfig exactly matches loggerName, or is an ancestor, if it's level is (strictly) more specific
- // then our configured level, it will be impossible to listen for the events we want - so track the original level and modify as needed...
+
+ // Regardless of wether loggerConfig exactly matches loggerName, or is an ancestor, if it's
+ // level is (strictly) more specific
+ // then our configured level, it will be impossible to listen for the events we want - so track
+ // the original level and modify as needed...
// NOTE: can't use isMoreSpecificThan because it's not strict...
- this.resetLevelWhenDone = loggerConfig.getLevel().intLevel() < level.intLevel() ? loggerConfig.getLevel() : null;
- if ( null != this.resetLevelWhenDone ) {
- log.info("{} (temporarily) increasing level of {} to {} in order to record matching logs", this.name, this.loggerName, level);
+ this.resetLevelWhenDone =
+ loggerConfig.getLevel().intLevel() < level.intLevel() ? loggerConfig.getLevel() : null;
+ if (null != this.resetLevelWhenDone) {
+ log.info(
+ "{} (temporarily) increasing level of {} to {} in order to record matching logs",
+ this.name,
+ this.loggerName,
+ level);
loggerConfig.setLevel(level);
}
-
- // Note: we don't just pass our level to addAppender, because that would only require it be "as specifc"
- // we use a wrapper that requres an exact level match (and other predicates can be added to this filter later)...
+ // Note: we don't just pass our level to addAppender, because that would only require it be "as
+ // specifc"
+ // we use a wrapper that requres an exact level match (and other predicates can be added to this
+ // filter later)...
this.filter = new MutablePredicateFilter(level);
this.loggerAppender = new QueueAppender(name);
-
+
loggerConfig.addAppender(loggerAppender, level, filter);
CTX.updateLoggers();
}
-
public void close() {
- if (! closed.getAndSet(true)) { // Don't muck with log4j if we accidently get a double close
+ if (!closed.getAndSet(true)) { // Don't muck with log4j if we accidently get a double close
final LoggerConfig loggerConfig = CTX.getConfiguration().getLoggerConfig(loggerName);
loggerConfig.removeAppender(loggerAppender.getName());
- if ( null != resetLevelWhenDone ) {
+ if (null != resetLevelWhenDone) {
loggerConfig.setLevel(resetLevelWhenDone);
}
- if ( removeLoggerConfigWhenDone ) {
+ if (removeLoggerConfigWhenDone) {
CTX.getConfiguration().removeLogger(loggerName);
}
if (log.isInfoEnabled()) {
log.info("Closing {} after recording {} log messages", this.name, getCount());
}
- assertEquals(this.name + " processed log events that it could not record beause queue capacity was exceeded",
- 0, loggerAppender.getNumCapacityExceeded());
- assertEquals(this.name + " recorded log events which were not expected & removed from the queue by the test code",
- 0, loggerAppender.getQueue().size());
+ assertEquals(
+ this.name
+ + " processed log events that it could not record beause queue capacity was exceeded",
+ 0,
+ loggerAppender.getNumCapacityExceeded());
+ assertEquals(
+ this.name
+ + " recorded log events which were not expected & removed from the queue by the test code",
+ 0,
+ loggerAppender.getQueue().size());
}
}
/**
* Changes the queue that will be used to record any future events that match
+ *
* @see #getQueue
*/
public LogListener setQueue(Queue<LogEvent> queue) {
loggerAppender.setQueue(queue);
return this;
}
-
+
/**
- * Modifies this listener to filter the log events that are recorded to events that match the specified substring.
- *
- * <p>
- * Log events are considered a match if their input matches either the message String, or the <code>toString</code> of an included
- * {@link Throwable}, or any of the recursive {@link Throwable#getCause}es of an included <code>Throwable</code>.
- * </p>
- * <p>
- * At most one filtering method may be used
- * </p>
- */
+ * Modifies this listener to filter the log events that are recorded to events that match the
+ * specified substring.
+ *
+ * <p>Log events are considered a match if their input matches either the message String, or the
+ * <code>toString</code> of an included {@link Throwable}, or any of the recursive {@link
+ * Throwable#getCause}es of an included <code>Throwable</code>.
+ *
+ * <p>At most one filtering method may be used
+ */
public LogListener substring(final String substr) {
- setPredicate( (str) -> { return str.contains(substr); });
+ setPredicate(
+ (str) -> {
+ return str.contains(substr);
+ });
return this;
}
/**
- * Modifies this listener to filter the log events that are recorded to events that match the specified regex.
+ * Modifies this listener to filter the log events that are recorded to events that match the
+ * specified regex.
*
- * <p>
- * Log events are considered a match if their input matches either the message String, or the <code>toString</code> of an included
- * {@link Throwable}, or any of the recursive {@link Throwable#getCause}es of an included <code>Throwable</code>.
- * </p>
- * <p>
- * At most one filtering method may be used
- * </p>
+ * <p>Log events are considered a match if their input matches either the message String, or the
+ * <code>toString</code> of an included {@link Throwable}, or any of the recursive {@link
+ * Throwable#getCause}es of an included <code>Throwable</code>.
+ *
+ * <p>At most one filtering method may be used
*/
public LogListener regex(final Pattern pat) {
- setPredicate( (str) -> { return pat.matcher(str).find(); });
+ setPredicate(
+ (str) -> {
+ return pat.matcher(str).find();
+ });
return this;
}
/**
- * Modifies this listener to filter the log events that are recorded to events that match the specified regex.
+ * Modifies this listener to filter the log events that are recorded to events that match the
+ * specified regex.
+ *
+ * <p>Log events are considered a match if their input matches either the message String, or the
+ * <code>toString</code> of an included {@link Throwable}, or any of the recursive {@link
+ * Throwable#getCause}es of an included <code>Throwable</code>.
*
- * <p>
- * Log events are considered a match if their input matches either the message String, or the <code>toString</code> of an included
- * {@link Throwable}, or any of the recursive {@link Throwable#getCause}es of an included <code>Throwable</code>.
- * </p>
- * <p>
- * At most one filtering method may be used
- * </p>
+ * <p>At most one filtering method may be used
*/
public LogListener regex(final String regex) {
return regex(Pattern.compile(regex));
}
-
+
/**
* @see #regex
* @see #substring
* @see MutablePredicateFilter#predicate
*/
private void setPredicate(Predicate<String> predicate) {
- if ( ! this.filter.predicate.compareAndSet((Predicate<String>)null, predicate) ) {
- throw new IllegalStateException("At most one method to set a message predicate can be called on a LogListener");
+ if (!this.filter.predicate.compareAndSet((Predicate<String>) null, predicate)) {
+ throw new IllegalStateException(
+ "At most one method to set a message predicate can be called on a LogListener");
}
}
/**
- * Direct access to the Queue of Log events that have been recorded, for {@link Queue#poll}ing messages or any other inspection/manipulation.
- * <p>
- * If a Log event is ever processed but can not be added to this queue (because {@link Queue#offer} returns false) then
- * the {@link #close} method of this listener will fail the test.
- * </p>
+ * Direct access to the Queue of Log events that have been recorded, for {@link Queue#poll}ing
+ * messages or any other inspection/manipulation.
+ *
+ * <p>If a Log event is ever processed but can not be added to this queue (because {@link
+ * Queue#offer} returns false) then the {@link #close} method of this listener will fail the test.
*
* @see #setQueue
* @see #pollMessage
@@ -314,10 +337,12 @@ public final class LogListener implements Closeable, AutoCloseable {
}
/**
- * Convinience method for tests that want to assert things about the (formated) message string at the head of the queue,
- * w/o needing to know/call methods on the underlying {@link LogEvent} class.
+ * Convinience method for tests that want to assert things about the (formated) message string at
+ * the head of the queue, w/o needing to know/call methods on the underlying {@link LogEvent}
+ * class.
*
- * @return the formatted message string of head of the queue, or null if the queue was empty when polled.
+ * @return the formatted message string of head of the queue, or null if the queue was empty when
+ * polled.
* @see #getQueue
*/
public String pollMessage() {
@@ -326,26 +351,30 @@ public final class LogListener implements Closeable, AutoCloseable {
}
/**
- * The total number of Log events so far processed by this instance, regardless of wether they have already been
- * removed from the queue, or if they could not be added to the queue due to capacity restrictions.
+ * The total number of Log events so far processed by this instance, regardless of wether they
+ * have already been removed from the queue, or if they could not be added to the queue due to
+ * capacity restrictions.
*/
public int getCount() {
return loggerAppender.getCount();
}
-
+
/**
- * A Filter registered with the specified Logger to restrict what Log events we process in our {@link QueueAppender}
+ * A Filter registered with the specified Logger to restrict what Log events we process in our
+ * {@link QueueAppender}
*/
- @SuppressForbidden(reason="We need to use log4J2 classes directly")
- private static final class MutablePredicateFilter extends AbstractFilter {
+ @SuppressForbidden(reason = "We need to use log4J2 classes directly")
+ private static final class MutablePredicateFilter extends AbstractFilter {
// TODO: could probably refactor to share some code with ErrorLogMuter
- // This could probably be implemented with a combination of "LevelMatchFilter" and "ConjunctionFilter" if "ConjunctionFilter" existed
- // Since it doesn't, we write our own more specialized impl instead of writing & combining multiple generalized versions
+ // This could probably be implemented with a combination of "LevelMatchFilter" and
+ // "ConjunctionFilter" if "ConjunctionFilter" existed. Since it doesn't, we write our own more
+ // specialized impl instead of writing & combining multiple generalized versions
// may be mutated in main thread while background thread is actively logging
- public final AtomicReference<Predicate<String>> predicate = new AtomicReference<Predicate<String>>(null);
-
+ public final AtomicReference<Predicate<String>> predicate =
+ new AtomicReference<Predicate<String>>(null);
+
final Level level;
public MutablePredicateFilter(final Level level) {
@@ -354,11 +383,15 @@ public final class LogListener implements Closeable, AutoCloseable {
this.level = level;
}
- // NOTE: This is inspired by log4j's RegexFilter, but with an eye to being more "garbage-free" friendly
- // Oddly, StringMatchFilter does things differnetly and acts like it needs to (re?) format msgs when params are provided
- // Since RegexFilter has tests, and StringMatchFilter doesn't, we assume RegexFilter knows what it's doing...
+ // NOTE: This is inspired by log4j's RegexFilter, but with an eye to being more "garbage-free"
+ // friendly. Oddly, StringMatchFilter does things differently and acts like it needs to (re?)
+ // format msgs when params are provided. Since RegexFilter has tests, and StringMatchFilter
+ // doesn't, we assume RegexFilter knows what it's doing...
- /** The main logic of our filter: Evaluate predicate against log msg &amp; throwable msg(s) if and only if Level is correct; else mismatch */
+ /**
+ * The main logic of our filter: Evaluate predicate against log msg &amp; throwable msg(s) if
+ * and only if Level is correct; else mismatch
+ */
private Filter.Result doFilter(final Level level, final String msg, final Throwable throwable) {
if (level.equals(this.level)) {
final Predicate<String> pred = predicate.get(); // read from reference once
@@ -377,79 +410,159 @@ public final class LogListener implements Closeable, AutoCloseable {
}
return getOnMismatch();
}
-
- public Result filter(Logger logger, Level level, Marker marker, String msg,
- Object... params) {
+
+ public Result filter(Logger logger, Level level, Marker marker, String msg, Object... params) {
return doFilter(level, msg, null);
}
- public Result filter(Logger logger, Level level, Marker marker, String msg,
- Object p0) {
+
+ public Result filter(Logger logger, Level level, Marker marker, String msg, Object p0) {
return doFilter(level, msg, null);
}
- public Result filter(Logger logger, Level level, Marker marker, String msg,
- Object p0, Object p1) {
+
+ public Result filter(
+ Logger logger, Level level, Marker marker, String msg, Object p0, Object p1) {
return doFilter(level, msg, null);
}
- public Result filter(Logger logger, Level level, Marker marker, String msg,
- Object p0, Object p1, Object p2) {
+
+ public Result filter(
+ Logger logger, Level level, Marker marker, String msg, Object p0, Object p1, Object p2) {
return doFilter(level, msg, null);
}
- public Result filter(Logger logger, Level level, Marker marker, String msg,
- Object p0, Object p1, Object p2, Object p3) {
+
+ public Result filter(
+ Logger logger,
+ Level level,
+ Marker marker,
+ String msg,
+ Object p0,
+ Object p1,
+ Object p2,
+ Object p3) {
return doFilter(level, msg, null);
}
- public Result filter(Logger logger, Level level, Marker marker, String msg,
- Object p0, Object p1, Object p2, Object p3, Object p4) {
+
+ public Result filter(
+ Logger logger,
+ Level level,
+ Marker marker,
+ String msg,
+ Object p0,
+ Object p1,
+ Object p2,
+ Object p3,
+ Object p4) {
return doFilter(level, msg, null);
}
- public Result filter(Logger logger, Level level, Marker marker, String msg,
- Object p0, Object p1, Object p2, Object p3, Object p4, Object p5) {
- return doFilter(level,msg, null);
+
+ public Result filter(
+ Logger logger,
+ Level level,
+ Marker marker,
+ String msg,
+ Object p0,
+ Object p1,
+ Object p2,
+ Object p3,
+ Object p4,
+ Object p5) {
+ return doFilter(level, msg, null);
}
- public Result filter(Logger logger, Level level, Marker marker, String msg,
- Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6) {
+
+ public Result filter(
+ Logger logger,
+ Level level,
+ Marker marker,
+ String msg,
+ Object p0,
+ Object p1,
+ Object p2,
+ Object p3,
+ Object p4,
+ Object p5,
+ Object p6) {
return doFilter(level, msg, null);
}
- public Result filter(Logger logger, Level level, Marker marker, String msg,
- Object p0, Object p1, Object p2, Object p3, Object p4,
- Object p5, Object p6, Object p7) {
+
+ public Result filter(
+ Logger logger,
+ Level level,
+ Marker marker,
+ String msg,
+ Object p0,
+ Object p1,
+ Object p2,
+ Object p3,
+ Object p4,
+ Object p5,
+ Object p6,
+ Object p7) {
return doFilter(level, msg, null);
}
- public Result filter(Logger logger, Level level, Marker marker, String msg,
- Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8) {
+
+ public Result filter(
+ Logger logger,
+ Level level,
+ Marker marker,
+ String msg,
+ Object p0,
+ Object p1,
+ Object p2,
+ Object p3,
+ Object p4,
+ Object p5,
+ Object p6,
+ Object p7,
+ Object p8) {
return doFilter(level, msg, null);
}
- public Result filter(Logger logger, Level level, Marker marker, String msg,
- Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8, Object p9) {
+
+ public Result filter(
+ Logger logger,
+ Level level,
+ Marker marker,
+ String msg,
+ Object p0,
+ Object p1,
+ Object p2,
+ Object p3,
+ Object p4,
+ Object p5,
+ Object p6,
+ Object p7,
+ Object p8,
+ Object p9) {
return doFilter(level, msg, null);
}
- public Result filter(Logger logger, Level level, Marker marker, Object msg,
- Throwable t) {
+
+ public Result filter(Logger logger, Level level, Marker marker, Object msg, Throwable t) {
return doFilter(level, null == msg ? null : msg.toString(), t);
}
- public Result filter(Logger logger, Level level, Marker marker, Message msg,
- Throwable t) {
+
+ public Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t) {
return doFilter(level, msg.getFormattedMessage(), t);
}
+
public Result filter(LogEvent event) {
- // NOTE: For our usage, we're not worried about needing to filter LogEvents rom remote JVMs with ThrowableProxy
+ // NOTE: For our usage, we're not worried about needing to filter LogEvents rom remote JVMs
+ // with ThrowableProxy
// stand ins for Throwabls that don't exist in our classloader...
- return doFilter(event.getLevel(),
- event.getMessage().getFormattedMessage(),
- event.getThrown());
+ return doFilter(
+ event.getLevel(), event.getMessage().getFormattedMessage(), event.getThrown());
}
}
/**
- * An Appender registered with the specified Logger to record the Log events that match our {@link MutablePredicateFilter}
- *
- * By default, we use a BlockingQueue with a capacity=100
+ * An Appender registered with the specified Logger to record the Log events that match our {@link
+ * MutablePredicateFilter}
+ *
+ * <p>By default, we use a BlockingQueue with a capacity=100
*/
- @SuppressForbidden(reason="We need to use log4J2 classes directly")
+ @SuppressForbidden(reason = "We need to use log4J2 classes directly")
private static final class QueueAppender extends AbstractAppender {
-
+
// may be mutated in main thread while background thread is actively logging
- private final AtomicReference<Queue<LogEvent>> queue = new AtomicReference<>(new ArrayBlockingQueue<>(100));
+ private final AtomicReference<Queue<LogEvent>> queue =
+ new AtomicReference<>(new ArrayBlockingQueue<>(100));
final AtomicInteger count = new AtomicInteger(0);
final AtomicInteger capacityExceeded = new AtomicInteger(0);
@@ -458,54 +571,61 @@ public final class LogListener implements Closeable, AutoCloseable {
assert null != name;
this.start();
}
-
+
@Override
public void append(final LogEvent event) {
final Queue<LogEvent> q = queue.get(); // read from reference once
- final LogEvent memento = (event instanceof MutableLogEvent) ? ((MutableLogEvent) event).createMemento() : event;
+ final LogEvent memento =
+ (event instanceof MutableLogEvent) ? ((MutableLogEvent) event).createMemento() : event;
final int currentCount = count.incrementAndGet();
if (q.offer(memento)) {
if (log.isDebugEnabled()) {
- log.debug("{} recorded a log event (#{}; currentSize={})", this.getName(), currentCount, q.size());
+ log.debug(
+ "{} recorded a log event (#{}; currentSize={})",
+ this.getName(),
+ currentCount,
+ q.size());
}
} else {
final int currentCapacityExceeded = capacityExceeded.incrementAndGet();
if (log.isErrorEnabled()) {
- log.error("{} processed a log event which exceeded capacity and could not be recorded (#{}; currentSize={}; numTimesCapacityExceeded={})",
- this.getName(), currentCount, q.size(), currentCapacityExceeded);
+ log.error(
+ "{} processed a log event which exceeded capacity and could not be recorded (#{}; currentSize={}; numTimesCapacityExceeded={})",
+ this.getName(),
+ currentCount,
+ q.size(),
+ currentCapacityExceeded);
}
}
}
/**
- * The total number of LogEvents processed by this appender (not impacted by when/how changes are made to the queue)
+ * The total number of LogEvents processed by this appender (not impacted by when/how changes
+ * are made to the queue)
*/
public int getCount() {
return count.get();
}
-
+
/**
- * Returns the number of times this appender was unable to queue a LogEvent due to exceeding capacity
+ * Returns the number of times this appender was unable to queue a LogEvent due to exceeding
+ * capacity
+ *
* @see Queue#offer
*/
public int getNumCapacityExceeded() {
return capacityExceeded.get();
}
-
- /**
- * Changes the queue that will be used for any future events that are appended
- */
+
+ /** Changes the queue that will be used for any future events that are appended */
public void setQueue(final Queue<LogEvent> q) {
assert null != q;
this.queue.set(q);
}
-
- /**
- * Returns Raw access to the (current) queue
- */
+
+ /** Returns Raw access to the (current) queue */
public Queue<LogEvent> getQueue() {
return queue.get();
}
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/MockCoreContainer.java b/solr/test-framework/src/java/org/apache/solr/util/MockCoreContainer.java
index 324bcdf3918..0d97fd7af29 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/MockCoreContainer.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/MockCoreContainer.java
@@ -19,22 +19,20 @@ package org.apache.solr.util;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
-
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.CoreDescriptor;
-
public class MockCoreContainer extends CoreContainer {
public static class MockCoreDescriptor extends CoreDescriptor {
public MockCoreDescriptor() {
super("mock", Paths.get("path").toAbsolutePath(), Collections.emptyMap(), null, null);
}
}
-
+
public MockCoreContainer() {
super(new Object());
}
-
+
public Path getCoreRootDirectory() {
return Paths.get("coreroot");
}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/NotSecurePseudoRandomSpi.java b/solr/test-framework/src/java/org/apache/solr/util/NotSecurePseudoRandomSpi.java
index f77287efc9e..a5e0bc42a91 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/NotSecurePseudoRandomSpi.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/NotSecurePseudoRandomSpi.java
@@ -22,17 +22,14 @@ import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
/**
- * A mocked up instance of SecureRandom that just uses {@link Random} under the covers.
- * This is to prevent blocking issues that arise in platform default
- * SecureRandom instances due to too many instances / not enough random entropy.
- * Tests do not need secure SSL.
+ * A mocked up instance of SecureRandom that just uses {@link Random} under the covers. This is to
+ * prevent blocking issues that arise in platform default SecureRandom instances due to too many
+ * instances / not enough random entropy. Tests do not need secure SSL.
*/
public class NotSecurePseudoRandomSpi extends SecureRandomSpi {
@Override
- protected void engineSetSeed(byte[] seed) {
-
- }
+ protected void engineSetSeed(byte[] seed) {}
@Override
protected void engineNextBytes(byte[] bytes) {
@@ -45,15 +42,14 @@ public class NotSecurePseudoRandomSpi extends SecureRandomSpi {
}
/**
- * Helper method that can be used to fill an array with non-zero data.
- * (Attempted workarround of Solaris SSL Padding bug: SOLR-9068)
+ * Helper method that can be used to fill an array with non-zero data. (Attempted workarround of
+ * Solaris SSL Padding bug: SOLR-9068)
*/
private static final byte[] fillData(byte[] data) {
ThreadLocalRandom.current().nextBytes(data);
return data;
}
-
public NotSecurePseudoRandomSpi() {
super();
}
@@ -73,10 +69,14 @@ public class NotSecurePseudoRandomSpi extends SecureRandomSpi {
}
/** NOOP */
- public void setSeed(byte[] seed) { /* NOOP */ }
+ public void setSeed(byte[] seed) {
+ /* NOOP */
+ }
/** NOOP */
- public void setSeed(long seed) { /* NOOP */ }
+ public void setSeed(long seed) {
+ /* NOOP */
+ }
public void reseed() {
/* NOOP */
@@ -85,5 +85,4 @@ public class NotSecurePseudoRandomSpi extends SecureRandomSpi {
public void reseed(SecureRandomParameters params) {
/* NOOP */
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/QueryMatchers.java b/solr/test-framework/src/java/org/apache/solr/util/QueryMatchers.java
index 0506bcf8996..10b8db2c066 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/QueryMatchers.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/QueryMatchers.java
@@ -16,6 +16,10 @@
*/
package org.apache.solr.util;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.is;
+
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
@@ -29,14 +33,12 @@ import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeDiagnosingMatcher;
import org.hamcrest.internal.ReflectiveTypeFinder;
-import static org.hamcrest.Matchers.contains;
-import static org.hamcrest.Matchers.containsInAnyOrder;
-import static org.hamcrest.Matchers.is;
-
// TODO: This can be contributed to Lucene
public class QueryMatchers {
- private abstract static class SubTypeDiagnosingMatcher<Q extends Query> extends TypeSafeDiagnosingMatcher<Query> {
- private static final ReflectiveTypeFinder TYPE_FINDER = new ReflectiveTypeFinder("matchesExactType", 2, 0);
+ private abstract static class SubTypeDiagnosingMatcher<Q extends Query>
+ extends TypeSafeDiagnosingMatcher<Query> {
+ private static final ReflectiveTypeFinder TYPE_FINDER =
+ new ReflectiveTypeFinder("matchesExactType", 2, 0);
public SubTypeDiagnosingMatcher() {
super(TYPE_FINDER);
@@ -55,10 +57,12 @@ public class QueryMatchers {
private QueryMatchers() {}
/**
- * Matches is a Query object's toString result is equal to this query string.
- * A useful shortcut when constructing complex queries with deterministic string repr
- *<p>
- * Note: Do not use this in place of DisjunctionMaxQuery, but safe to use for the disjunct clauses
+ * Matches is a Query object's toString result is equal to this query string. A useful shortcut
+ * when constructing complex queries with deterministic string repr
+ *
+ * <p>Note: Do not use this in place of DisjunctionMaxQuery, but safe to use for the disjunct
+ * clauses
+ *
* @param query the query string to match against
*/
public static Matcher<Query> stringQuery(String query) {
@@ -110,6 +114,7 @@ public class QueryMatchers {
/**
* Create a phrase query matcher with a whitespace delimited sequence of terms
+ *
* @param field the field the phrase query should match against
* @param terms a whitespace delimited set of terms that should
*/
@@ -126,7 +131,8 @@ public class QueryMatchers {
return booleanClause(query, BooleanClause.Occur.MUST);
}
- public static Matcher<BooleanClause> booleanClause(Matcher<? extends Query> query, BooleanClause.Occur occur) {
+ public static Matcher<BooleanClause> booleanClause(
+ Matcher<? extends Query> query, BooleanClause.Occur occur) {
return new TypeSafeDiagnosingMatcher<BooleanClause>() {
@Override
protected boolean matchesSafely(BooleanClause item, Description mismatchDescription) {
@@ -146,7 +152,11 @@ public class QueryMatchers {
@Override
public void describeTo(Description description) {
- description.appendText(occur.toString()).appendText("(").appendDescriptionOf(query).appendText(")");
+ description
+ .appendText(occur.toString())
+ .appendText("(")
+ .appendDescriptionOf(query)
+ .appendText(")");
}
};
}
@@ -156,7 +166,8 @@ public class QueryMatchers {
return _booleanQuery(contains(booleanClause(q1, occur)));
}
- public static Matcher<Query> booleanQuery(Matcher<Query> q1, Matcher<Query> q2, BooleanClause.Occur occur) {
+ public static Matcher<Query> booleanQuery(
+ Matcher<Query> q1, Matcher<Query> q2, BooleanClause.Occur occur) {
return _booleanQuery(containsInAnyOrder(booleanClause(q1, occur), booleanClause(q2, occur)));
}
@@ -168,12 +179,15 @@ public class QueryMatchers {
return _booleanQuery(containsInAnyOrder(shouldClause(c1), shouldClause(c2)));
}
- public static Matcher<Query> booleanQuery(Matcher<Query> c1, Matcher<Query> c2, Matcher<Query> c3) {
+ public static Matcher<Query> booleanQuery(
+ Matcher<Query> c1, Matcher<Query> c2, Matcher<Query> c3) {
return _booleanQuery(containsInAnyOrder(shouldClause(c1), shouldClause(c2), shouldClause(c3)));
}
- public static Matcher<Query> booleanQuery(Matcher<Query> c1, Matcher<Query> c2, Matcher<Query> c3, Matcher<Query> c4) {
- return _booleanQuery(containsInAnyOrder(shouldClause(c1), shouldClause(c2), shouldClause(c3), shouldClause(c4)));
+ public static Matcher<Query> booleanQuery(
+ Matcher<Query> c1, Matcher<Query> c2, Matcher<Query> c3, Matcher<Query> c4) {
+ return _booleanQuery(
+ containsInAnyOrder(shouldClause(c1), shouldClause(c2), shouldClause(c3), shouldClause(c4)));
}
private static Matcher<Query> _booleanQuery(Matcher<Iterable<? extends BooleanClause>> matcher) {
@@ -189,8 +203,7 @@ public class QueryMatchers {
@Override
public void describeTo(Description description) {
- description.appendText("a BooleanQuery with ")
- .appendDescriptionOf(matcher);
+ description.appendText("a BooleanQuery with ").appendDescriptionOf(matcher);
}
};
}
@@ -203,18 +216,21 @@ public class QueryMatchers {
return disjunctionQuery(containsInAnyOrder(q1, q2));
}
- public static Matcher<Query> disjunctionOf(Matcher<Query> q1, Matcher<Query> q2, Matcher<Query> q3) {
+ public static Matcher<Query> disjunctionOf(
+ Matcher<Query> q1, Matcher<Query> q2, Matcher<Query> q3) {
return disjunctionQuery(containsInAnyOrder(q1, q2, q3));
}
- public static Matcher<Query> disjunctionOf(Matcher<Query> q1, Matcher<Query> q2, Matcher<Query> q3, Matcher<Query> q4) {
+ public static Matcher<Query> disjunctionOf(
+ Matcher<Query> q1, Matcher<Query> q2, Matcher<Query> q3, Matcher<Query> q4) {
return disjunctionQuery(containsInAnyOrder(q1, q2, q3, q4));
}
private static Matcher<Query> disjunctionQuery(Matcher<Iterable<? extends Query>> disjuncts) {
return new SubTypeDiagnosingMatcher<DisjunctionMaxQuery>() {
@Override
- protected boolean matchesExactType(DisjunctionMaxQuery item, Description mismatchDescription) {
+ protected boolean matchesExactType(
+ DisjunctionMaxQuery item, Description mismatchDescription) {
if (disjuncts.matches(item.getDisjuncts())) return true;
mismatchDescription.appendText("was a DisjunctionMaxQuery with ");
@@ -224,8 +240,7 @@ public class QueryMatchers {
@Override
public void describeTo(Description description) {
- description.appendText("a DisjunctionMaxQuery with ")
- .appendDescriptionOf(disjuncts);
+ description.appendText("a DisjunctionMaxQuery with ").appendDescriptionOf(disjuncts);
}
};
}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/RESTfulServerProvider.java b/solr/test-framework/src/java/org/apache/solr/util/RESTfulServerProvider.java
index d4da5d9a7f4..43dd29c16c2 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/RESTfulServerProvider.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/RESTfulServerProvider.java
@@ -15,6 +15,7 @@
* limitations under the License.
*/
package org.apache.solr.util;
+
public interface RESTfulServerProvider {
String getBaseURL();
}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/RandomForceMergePolicy.java b/solr/test-framework/src/java/org/apache/solr/util/RandomForceMergePolicy.java
index 92dc1300953..f100610880b 100755
--- a/solr/test-framework/src/java/org/apache/solr/util/RandomForceMergePolicy.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/RandomForceMergePolicy.java
@@ -21,17 +21,14 @@ import org.apache.lucene.index.MergePolicy;
import org.apache.lucene.util.LuceneTestCase;
/**
- * A {@link MergePolicy} with a no-arg constructor that proxies to a
- * {@link ForceMergePolicy} wrapped instance retrieved from
- * {@link LuceneTestCase#newMergePolicy}.
- * Solr tests utilizing the Lucene randomized test framework can refer
- * to this class in solrconfig.xml to get a fully randomized merge policy
- * that only returns forced merges.
+ * A {@link MergePolicy} with a no-arg constructor that proxies to a {@link ForceMergePolicy}
+ * wrapped instance retrieved from {@link LuceneTestCase#newMergePolicy}. Solr tests utilizing the
+ * Lucene randomized test framework can refer to this class in solrconfig.xml to get a fully
+ * randomized merge policy that only returns forced merges.
*/
public final class RandomForceMergePolicy extends RandomMergePolicy {
public RandomForceMergePolicy() {
super(new ForceMergePolicy(LuceneTestCase.newMergePolicy()));
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/RandomForceMergePolicyFactory.java b/solr/test-framework/src/java/org/apache/solr/util/RandomForceMergePolicyFactory.java
index b9bd3cbceae..3cd6c681001 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/RandomForceMergePolicyFactory.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/RandomForceMergePolicyFactory.java
@@ -25,7 +25,8 @@ import org.apache.solr.schema.IndexSchema;
/** A {@link MergePolicyFactory} for {@link RandomForceMergePolicy}. */
public final class RandomForceMergePolicyFactory extends MergePolicyFactory {
- public RandomForceMergePolicyFactory(SolrResourceLoader resourceLoader, MergePolicyFactoryArgs args, IndexSchema schema) {
+ public RandomForceMergePolicyFactory(
+ SolrResourceLoader resourceLoader, MergePolicyFactoryArgs args, IndexSchema schema) {
super(null, args, schema);
}
@@ -33,5 +34,4 @@ public final class RandomForceMergePolicyFactory extends MergePolicyFactory {
public MergePolicy getMergePolicy() {
return new RandomForceMergePolicy();
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/RandomMergePolicy.java b/solr/test-framework/src/java/org/apache/solr/util/RandomMergePolicy.java
index 89c0c55fc63..344add2aa56 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/RandomMergePolicy.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/RandomMergePolicy.java
@@ -17,22 +17,21 @@
package org.apache.solr.util;
import java.lang.invoke.MethodHandles;
-import org.apache.lucene.index.MergePolicy;
import org.apache.lucene.index.FilterMergePolicy;
+import org.apache.lucene.index.MergePolicy;
import org.apache.lucene.util.LuceneTestCase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * A {@link MergePolicy} with a no-arg constructor that proxies to an
- * instance retrieved from {@link LuceneTestCase#newMergePolicy}.
- * Solr tests utilizing the Lucene randomized test framework can refer
- * to this class in solrconfig.xml to get a fully randomized merge policy.
+ * A {@link MergePolicy} with a no-arg constructor that proxies to an instance retrieved from {@link
+ * LuceneTestCase#newMergePolicy}. Solr tests utilizing the Lucene randomized test framework can
+ * refer to this class in solrconfig.xml to get a fully randomized merge policy.
*/
public class RandomMergePolicy extends FilterMergePolicy {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
+
public RandomMergePolicy() {
this(LuceneTestCase.newMergePolicy());
}
@@ -43,5 +42,4 @@ public class RandomMergePolicy extends FilterMergePolicy {
log.info("RandomMergePolicy wrapping {}: {}", inner.getClass(), inner);
}
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/RandomMergePolicyFactory.java b/solr/test-framework/src/java/org/apache/solr/util/RandomMergePolicyFactory.java
index 907c95d60af..8e17590e7b5 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/RandomMergePolicyFactory.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/RandomMergePolicyFactory.java
@@ -31,5 +31,4 @@ public final class RandomMergePolicyFactory extends MergePolicyFactory {
public MergePolicy getMergePolicy() {
return new RandomMergePolicy();
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/RandomizeSSL.java b/solr/test-framework/src/java/org/apache/solr/util/RandomizeSSL.java
index 15d979cb824..c4afb5b5be9 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/RandomizeSSL.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/RandomizeSSL.java
@@ -22,15 +22,14 @@ import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
-
/**
- * Marker annotation indicating when SSL Randomization should be used for a test class, and if so what
- * the typical odds of using SSL should for that test class.
+ * Marker annotation indicating when SSL Randomization should be used for a test class, and if so
+ * what the typical odds of using SSL should for that test class.
+ *
* @see SSLRandomizer#getSSLRandomizerForClass
* @see SuppressSSL
*/
@@ -44,58 +43,59 @@ public @interface RandomizeSSL {
public static final double DEFAULT_ODDS = 0.2D;
/** Comment to inlcude when logging details of SSL randomization */
public String reason() default "";
- /**
- * Odds (as ratio relative to 1) that SSL should be selected in a typical run.
- * Must either be betwen 0.0 and 1.0 (inclusively) or NaN in which case a sensible should be used.
- * Actual Odds used for randomization may be higher depending on runner options such as
- * <code>tests.multiplier</code> or <code>tests.nightly</code>
+ /**
+ * Odds (as ratio relative to 1) that SSL should be selected in a typical run. Must either be
+ * betwen 0.0 and 1.0 (inclusively) or NaN in which case a sensible should be used. Actual Odds
+ * used for randomization may be higher depending on runner options such as <code>tests.multiplier
+ * </code> or <code>tests.nightly</code>
*
* @see #DEFAULT_ODDS
* @see LuceneTestCase#TEST_NIGHTLY
* @see LuceneTestCase#RANDOM_MULTIPLIER
*/
public double ssl() default Double.NaN;
- /**
- * Odds (as ratio relative to 1) that SSL should be selected in a typical run.
- * Must either be betwen 0.0 and 1.0 (inclusively) or NaN in which case the effective value of
- * {@link #ssl} should be used.
- * Actual Odds used for randomization may be higher depending on runner options such as
- * <code>tests.multiplier</code> or <code>tests.nightly</code>
- * <p>
- * NOTE: clientAuth is useless unless ssl is also in used, but we randomize it independently
- * just in case it might find bugs in our test/ssl client code (ie: attempting to use
- * SSL w/client cert to non-ssl servers)
- * </p>
+ /**
+ * Odds (as ratio relative to 1) that SSL should be selected in a typical run. Must either be
+ * betwen 0.0 and 1.0 (inclusively) or NaN in which case the effective value of {@link #ssl}
+ * should be used. Actual Odds used for randomization may be higher depending on runner options
+ * such as <code>tests.multiplier</code> or <code>tests.nightly</code>
+ *
+ * <p>NOTE: clientAuth is useless unless ssl is also in used, but we randomize it independently
+ * just in case it might find bugs in our test/ssl client code (ie: attempting to use SSL w/client
+ * cert to non-ssl servers)
+ *
* @see #DEFAULT_ODDS
* @see LuceneTestCase#TEST_NIGHTLY
* @see LuceneTestCase#RANDOM_MULTIPLIER
*/
public double clientAuth() default Double.NaN;
/**
- * A shorthand option for controlling both {@link #ssl} and {@link #clientAuth} with a single numeric
- * value, For example: <code>@RandomizeSSL(0.5)</code>.
+ * A shorthand option for controlling both {@link #ssl} and {@link #clientAuth} with a single
+ * numeric value, For example: <code>@RandomizeSSL(0.5)</code>.
*
- * Ignored if {@link #ssl} is set explicitly.
+ * <p>Ignored if {@link #ssl} is set explicitly.
*/
public double value() default Double.NaN;
/**
- * A simple data structure for encapsulating the effective values to be used when randomizing
- * SSL in a test, based on the configured values in the {@link RandomizeSSL} annotation.
+ * A simple data structure for encapsulating the effective values to be used when randomizing SSL
+ * in a test, based on the configured values in the {@link RandomizeSSL} annotation.
*/
public static final class SSLRandomizer {
public final double ssl;
public final double clientAuth;
public final String debug;
- /** @lucene.internal */
+ /**
+ * @lucene.internal
+ */
public SSLRandomizer(double ssl, double clientAuth, String debug) {
this.ssl = ssl;
this.clientAuth = clientAuth;
this.debug = debug;
}
- /**
- * Randomly produces an SSLTestConfig taking into account various factors
+ /**
+ * Randomly produces an SSLTestConfig taking into account various factors
*
* @see LuceneTestCase#TEST_NIGHTLY
* @see LuceneTestCase#RANDOM_MULTIPLIER
@@ -103,38 +103,48 @@ public @interface RandomizeSSL {
*/
public SSLTestConfig createSSLTestConfig() {
// even if we know SSL is disabled, always consume the same amount of randomness
- // that way all other test behavior should be consistent even if a user adds/removes @SuppressSSL
-
- final boolean useSSL = TestUtil.nextInt(LuceneTestCase.random(), 0, 999) <
- (int)(1000 * getEffectiveOdds(ssl, LuceneTestCase.TEST_NIGHTLY, LuceneTestCase.RANDOM_MULTIPLIER));
- final boolean useClientAuth = TestUtil.nextInt(LuceneTestCase.random(), 0, 999) <
- (int)(1000 * getEffectiveOdds(clientAuth, LuceneTestCase.TEST_NIGHTLY, LuceneTestCase.RANDOM_MULTIPLIER));
+ // that way all other test behavior should be consistent even if a user adds/removes
+ // @SuppressSSL
+
+ final boolean useSSL =
+ TestUtil.nextInt(LuceneTestCase.random(), 0, 999)
+ < (int)
+ (1000
+ * getEffectiveOdds(
+ ssl, LuceneTestCase.TEST_NIGHTLY, LuceneTestCase.RANDOM_MULTIPLIER));
+ final boolean useClientAuth =
+ TestUtil.nextInt(LuceneTestCase.random(), 0, 999)
+ < (int)
+ (1000
+ * getEffectiveOdds(
+ clientAuth,
+ LuceneTestCase.TEST_NIGHTLY,
+ LuceneTestCase.RANDOM_MULTIPLIER));
return new SSLTestConfig(useSSL, useClientAuth);
}
-
- /** @lucene.internal Public only for testing */
- public static double getEffectiveOdds(final double declaredOdds,
- final boolean nightly,
- final int multiplier) {
+
+ /**
+ * @lucene.internal Public only for testing
+ */
+ public static double getEffectiveOdds(
+ final double declaredOdds, final boolean nightly, final int multiplier) {
assert declaredOdds <= 1.0D;
assert 0.0D <= declaredOdds;
- if (declaredOdds == 0.0D || declaredOdds == 1.0D ) {
+ if (declaredOdds == 0.0D || declaredOdds == 1.0D) {
return declaredOdds;
}
-
+
assert 0 < multiplier;
-
+
// negate the odds so we can then divide it by our multipling factors
// to increase the final odds
- return 1.0D - ((1.0D - declaredOdds)
- / ((nightly ? 1.1D : 1.0D) * (1.0D + Math.log(multiplier))));
+ return 1.0D
+ - ((1.0D - declaredOdds) / ((nightly ? 1.1D : 1.0D) * (1.0D + Math.log(multiplier))));
}
-
- /**
- * Returns an SSLRandomizer suitable for the specified (test) class
- */
+
+ /** Returns an SSLRandomizer suitable for the specified (test) class */
public static final SSLRandomizer getSSLRandomizerForClass(Class<?> clazz) {
final SuppressSSL suppressSSL = clazz.getAnnotation(SuppressSSL.class);
@@ -148,25 +158,33 @@ public @interface RandomizeSSL {
}
final RandomizeSSL randomizeSSL = clazz.getAnnotation(RandomizeSSL.class);
-
+
if (null == randomizeSSL) {
- return new SSLRandomizer(0.0D, 0.0D, RandomizeSSL.class.getName() + " annotation not specified");
+ return new SSLRandomizer(
+ 0.0D, 0.0D, RandomizeSSL.class.getName() + " annotation not specified");
}
final double def = Double.isNaN(randomizeSSL.value()) ? DEFAULT_ODDS : randomizeSSL.value();
if (def < 0.0D || 1.0D < def) {
- throw new IllegalArgumentException
- (clazz.getName() + ": default value is not a ratio between 0 and 1: " + randomizeSSL.toString());
+ throw new IllegalArgumentException(
+ clazz.getName()
+ + ": default value is not a ratio between 0 and 1: "
+ + randomizeSSL.toString());
}
final double ssl = Double.isNaN(randomizeSSL.ssl()) ? def : randomizeSSL.ssl();
if (ssl < 0.0D || 1.0D < ssl) {
- throw new IllegalArgumentException
- (clazz.getName() + ": ssl value is not a ratio between 0 and 1: " + randomizeSSL.toString());
+ throw new IllegalArgumentException(
+ clazz.getName()
+ + ": ssl value is not a ratio between 0 and 1: "
+ + randomizeSSL.toString());
}
- final double clientAuth = Double.isNaN(randomizeSSL.clientAuth()) ? ssl : randomizeSSL.clientAuth();
+ final double clientAuth =
+ Double.isNaN(randomizeSSL.clientAuth()) ? ssl : randomizeSSL.clientAuth();
if (clientAuth < 0.0D || 1 < clientAuth) {
- throw new IllegalArgumentException
- (clazz.getName() + ": clientAuth value is not a ratio between 0 and 1: " + randomizeSSL.toString());
+ throw new IllegalArgumentException(
+ clazz.getName()
+ + ": clientAuth value is not a ratio between 0 and 1: "
+ + randomizeSSL.toString());
}
return new SSLRandomizer(ssl, clientAuth, randomizeSSL.toString());
}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/ReadOnlyCoresLocator.java b/solr/test-framework/src/java/org/apache/solr/util/ReadOnlyCoresLocator.java
index 3d11ff733de..29c9c41b0eb 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/ReadOnlyCoresLocator.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/ReadOnlyCoresLocator.java
@@ -46,5 +46,4 @@ public abstract class ReadOnlyCoresLocator implements CoresLocator {
public void swap(CoreContainer cc, CoreDescriptor cd1, CoreDescriptor cd2) {
// no-op
}
-
}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java b/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java
index f69aa3db56e..589698e3d0c 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java
@@ -15,6 +15,12 @@
* limitations under the License.
*/
package org.apache.solr.util;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+import java.util.Map;
+import java.util.SortedMap;
+import javax.xml.xpath.XPathExpressionException;
import org.apache.solr.JSONTestUtil;
import org.apache.solr.SolrJettyTestBase;
import org.apache.solr.common.SolrException;
@@ -27,12 +33,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
-import javax.xml.xpath.XPathExpressionException;
-import java.io.IOException;
-import java.lang.invoke.MethodHandles;
-import java.util.Map;
-import java.util.SortedMap;
-
public abstract class RestTestBase extends SolrJettyTestBase {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
protected static RestTestHarness restTestHarness;
@@ -46,41 +46,42 @@ public abstract class RestTestBase extends SolrJettyTestBase {
}
}
- public static void createJettyAndHarness
- (String solrHome, String configFile, String schemaFile, String context,
- boolean stopAtShutdown, SortedMap<ServletHolder,String> extraServlets) throws Exception {
+ public static void createJettyAndHarness(
+ String solrHome,
+ String configFile,
+ String schemaFile,
+ String context,
+ boolean stopAtShutdown,
+ SortedMap<ServletHolder, String> extraServlets)
+ throws Exception {
createAndStartJetty(solrHome, configFile, schemaFile, context, stopAtShutdown, extraServlets);
- restTestHarness = new RestTestHarness(() -> jetty.getBaseUrl().toString() + "/" + DEFAULT_TEST_CORENAME);
+ restTestHarness =
+ new RestTestHarness(() -> jetty.getBaseUrl().toString() + "/" + DEFAULT_TEST_CORENAME);
}
- /** Validates an update XML String is successful
- */
+ /** Validates an update XML String is successful */
public static void assertU(String update) {
assertU(null, update);
}
- /** Validates an update XML String is successful
- */
+ /** Validates an update XML String is successful */
public static void assertU(String message, String update) {
checkUpdateU(message, update, true);
}
- /** Validates an update XML String failed
- */
+ /** Validates an update XML String failed */
public static void assertFailedU(String update) {
assertFailedU(null, update);
}
- /** Validates an update XML String failed
- */
+ /** Validates an update XML String failed */
public static void assertFailedU(String message, String update) {
checkUpdateU(message, update, false);
}
- /** Checks the success or failure of an update message
- */
+ /** Checks the success or failure of an update message */
private static void checkUpdateU(String message, String update, boolean shouldSucceed) {
try {
String m = (null == message) ? "" : message + " ";
@@ -96,10 +97,10 @@ public abstract class RestTestBase extends SolrJettyTestBase {
}
}
- /**
+ /**
* Validates a query matches some XPath test expressions
- *
- * @param request a URL path with optional query params, e.g. "/schema/fields?fl=id,_version_"
+ *
+ * @param request a URL path with optional query params, e.g. "/schema/fields?fl=id,_version_"
*/
public static void assertQ(String request, String... tests) {
try {
@@ -113,7 +114,7 @@ public abstract class RestTestBase extends SolrJettyTestBase {
query = request.substring(queryStartPos + 1);
path = request.substring(0, queryStartPos);
}
- if ( ! query.matches(".*wt=schema\\.xml.*")) { // don't overwrite wt=schema.xml
+ if (!query.matches(".*wt=schema\\.xml.*")) { // don't overwrite wt=schema.xml
query = setParam(query, "wt", "xml");
}
request = path + '?' + setParam(query, "indent", "on");
@@ -135,7 +136,11 @@ public abstract class RestTestBase extends SolrJettyTestBase {
String results = TestHarness.validateXPath(response, tests);
if (null != results) {
- log.error("REQUEST FAILED: xpath={}\n\txml response was: {}\n\trequest was:{}", results, response, request);
+ log.error(
+ "REQUEST FAILED: xpath={}\n\txml response was: {}\n\trequest was:{}",
+ results,
+ response,
+ request);
fail(results);
}
@@ -148,9 +153,9 @@ public abstract class RestTestBase extends SolrJettyTestBase {
}
/**
- * Makes a query request and returns the JSON string response
+ * Makes a query request and returns the JSON string response
*
- * @param request a URL path with optional query params, e.g. "/schema/fields?fl=id,_version_"
+ * @param request a URL path with optional query params, e.g. "/schema/fields?fl=id,_version_"
*/
public static String JQ(String request) throws IOException {
request = setWtJsonAndIndent(request);
@@ -165,6 +170,7 @@ public abstract class RestTestBase extends SolrJettyTestBase {
/**
* Validates a query matches some JSON test expressions using the default double delta tolerance.
+ *
* @see org.apache.solr.JSONTestUtil#DEFAULT_DELTA
* @see #assertJQ(String,double,String...)
*/
@@ -173,15 +179,13 @@ public abstract class RestTestBase extends SolrJettyTestBase {
}
/**
- * Validates a query matches some JSON test expressions and closes the
- * query. The text expression is of the form path:JSON. To facilitate
- * easy embedding in Java strings, the JSON can have double quotes
- * replaced with single quotes.
- * <p>
- * Please use this with care: this makes it easy to match complete
- * structures, but doing so can result in fragile tests if you are
- * matching more than what you want to test.
- * </p>
+ * Validates a query matches some JSON test expressions and closes the query. The text expression
+ * is of the form path:JSON. To facilitate easy embedding in Java strings, the JSON can have
+ * double quotes replaced with single quotes.
+ *
+ * <p>Please use this with care: this makes it easy to match complete structures, but doing so can
+ * result in fragile tests if you are matching more than what you want to test.
+ *
* @param request a URL path with optional query params, e.g. "/schema/fields?fl=id,_version_"
* @param delta tolerance allowed in comparing float/double values
* @param tests JSON path expression + '==' + expected value
@@ -203,34 +207,32 @@ public abstract class RestTestBase extends SolrJettyTestBase {
}
}
-
/**
* Validates the response from a PUT request matches some JSON test expressions
- *
+ *
* @see org.apache.solr.JSONTestUtil#DEFAULT_DELTA
* @see #assertJQ(String,double,String...)
*/
- public static void assertJPut(String request, String content, String... tests) throws IOException {
+ public static void assertJPut(String request, String content, String... tests)
+ throws IOException {
assertJPut(request, content, JSONTestUtil.DEFAULT_DELTA, tests);
}
-
/**
- * Validates the response from a PUT request matches some JSON test expressions
- * and closes the query. The text expression is of the form path==JSON.
- * To facilitate easy embedding in Java strings, the JSON can have double
- * quotes replaced with single quotes.
- * <p>
- * Please use this with care: this makes it easy to match complete
- * structures, but doing so can result in fragile tests if you are
- * matching more than what you want to test.
- * </p>
+ * Validates the response from a PUT request matches some JSON test expressions and closes the
+ * query. The text expression is of the form path==JSON. To facilitate easy embedding in Java
+ * strings, the JSON can have double quotes replaced with single quotes.
+ *
+ * <p>Please use this with care: this makes it easy to match complete structures, but doing so can
+ * result in fragile tests if you are matching more than what you want to test.
+ *
* @param request a URL path with optional query params, e.g. "/schema/fields?fl=id,_version_"
* @param content The content to include with the PUT request
* @param delta tolerance allowed in comparing float/double values
* @param tests JSON path expression + '==' + expected value
*/
- public static void assertJPut(String request, String content, double delta, String... tests) throws IOException {
+ public static void assertJPut(String request, String content, double delta, String... tests)
+ throws IOException {
request = setWtJsonAndIndent(request);
String response;
@@ -247,19 +249,27 @@ public abstract class RestTestBase extends SolrJettyTestBase {
}
}
- private static void assertJsonMatches(String request, String response, String testJSON, double delta) throws IOException {
+ private static void assertJsonMatches(
+ String request, String response, String testJSON, double delta) throws IOException {
try {
String err = JSONTestUtil.match(response, testJSON, delta);
if (err != null) {
- log.error("query failed JSON validation. error: {}"
- + "\n expected: {}\n response: {}\n request: {}\n"
- , err, testJSON, response, request);
+ log.error(
+ "query failed JSON validation. error: {}"
+ + "\n expected: {}\n response: {}\n request: {}\n",
+ err,
+ testJSON,
+ response,
+ request);
fail(err);
}
} catch (IOException e) {
- log.error("JSON query validation threw an exception."
- +"\n expected: {}\n response: {}\n request: {}"
- , testJSON, response, request);
+ log.error(
+ "JSON query validation threw an exception."
+ + "\n expected: {}\n response: {}\n request: {}",
+ testJSON,
+ response,
+ request);
throw e;
}
}
@@ -274,23 +284,21 @@ public abstract class RestTestBase extends SolrJettyTestBase {
assertJPost(request, content, JSONTestUtil.DEFAULT_DELTA, tests);
}
-
/**
- * Validates the response from a PUT request matches some JSON test expressions
- * and closes the query. The text expression is of the form path==JSON.
- * To facilitate easy embedding in Java strings, the JSON can have double
- * quotes replaced with single quotes.
- * <p>
- * Please use this with care: this makes it easy to match complete
- * structures, but doing so can result in fragile tests if you are
- * matching more than what you want to test.
- * </p>
+ * Validates the response from a PUT request matches some JSON test expressions and closes the
+ * query. The text expression is of the form path==JSON. To facilitate easy embedding in Java
+ * strings, the JSON can have double quotes replaced with single quotes.
+ *
+ * <p>Please use this with care: this makes it easy to match complete structures, but doing so can
+ * result in fragile tests if you are matching more than what you want to test.
+ *
* @param request a URL path with optional query params, e.g. "/schema/fields?fl=id,_version_"
* @param content The content to include with the PUT request
* @param delta tolerance allowed in comparing float/double values
* @param tests JSON path expression + '==' + expected value
*/
- public static void assertJPost(String request, String content, double delta, String... tests) throws Exception {
+ public static void assertJPost(String request, String content, double delta, String... tests)
+ throws Exception {
request = setWtJsonAndIndent(request);
String response;
@@ -306,10 +314,11 @@ public abstract class RestTestBase extends SolrJettyTestBase {
assertJsonMatches(request, response, json(test), delta);
}
}
-
+
/**
- * Deletes a resource and then matches some JSON test expressions against the
- * response using the default double delta tolerance.
+ * Deletes a resource and then matches some JSON test expressions against the response using the
+ * default double delta tolerance.
+ *
* @see org.apache.solr.JSONTestUtil#DEFAULT_DELTA
* @see #assertJDelete(String,double,String...)
*/
@@ -318,8 +327,8 @@ public abstract class RestTestBase extends SolrJettyTestBase {
}
/**
- * Deletes a resource and then matches some JSON test expressions against the
- * response using the specified double delta tolerance.
+ * Deletes a resource and then matches some JSON test expressions against the response using the
+ * specified double delta tolerance.
*/
public static void assertJDelete(String request, double delta, String... tests) throws Exception {
request = setWtJsonAndIndent(request);
@@ -340,6 +349,7 @@ public abstract class RestTestBase extends SolrJettyTestBase {
/**
* Parse the request string and set wt=json&indent=on for json queries
+ *
* @param request the original request
* @return the new (possibly unmodified) request
*/
@@ -359,23 +369,24 @@ public abstract class RestTestBase extends SolrJettyTestBase {
return request;
}
-
/**
* Ensures that the given param is included in the query with the given value.
*
* <ol>
- * <li>If the param is already included with the given value, the request is returned unchanged.</li>
- * <li>If the param is not already included, it is added with the given value.</li>
- * <li>If the param is already included, but with a different value, the value is replaced with the given value.</li>
- * <li>If the param is already included multiple times, they are replaced with a single param with given value.</li>
+ * <li>If the param is already included with the given value, the request is returned unchanged.
+ * <li>If the param is not already included, it is added with the given value.
+ * <li>If the param is already included, but with a different value, the value is replaced with
+ * the given value.
+ * <li>If the param is already included multiple times, they are replaced with a single param
+ * with given value.
* </ol>
*
* The passed-in valueToSet should NOT be URL encoded, as it will be URL encoded by this method.
*
* @param query The query portion of a request URL, e.g. "wt=xml&indent=off&fl=id,_version_"
- * @param paramToSet The parameter name to insure the presence of in the returned request
+ * @param paramToSet The parameter name to insure the presence of in the returned request
* @param valueToSet The parameter value to insure in the returned request
- * @return The query with the given param set to the given value
+ * @return The query with the given param set to the given value
*/
private static String setParam(String query, String paramToSet, String valueToSet) {
if (null == valueToSet) {
@@ -407,11 +418,11 @@ public abstract class RestTestBase extends SolrJettyTestBase {
// More than one value for paramToSet on the request, or paramToSet's value is not valueToSet
// -> rebuild the query
boolean isFirst = true;
- for (Map.Entry<String,String[]> entry : requestParams.getMap().entrySet()) {
+ for (Map.Entry<String, String[]> entry : requestParams.getMap().entrySet()) {
String key = entry.getKey();
String[] valarr = entry.getValue();
- if ( ! key.equals(paramToSet)) {
+ if (!key.equals(paramToSet)) {
for (String val : valarr) {
builder.append(isFirst ? "" : '&');
isFirst = false;
@@ -427,4 +438,4 @@ public abstract class RestTestBase extends SolrJettyTestBase {
StrUtils.partialURLEncodeVal(builder, valueToSet);
return builder.toString();
}
-}
+}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/RestTestHarness.java b/solr/test-framework/src/java/org/apache/solr/util/RestTestHarness.java
index 21f0c116a8d..2433b421782 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/RestTestHarness.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/RestTestHarness.java
@@ -15,13 +15,13 @@
* limitations under the License.
*/
package org.apache.solr.util;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpressionException;
+
import java.io.Closeable;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
-
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
@@ -35,18 +35,15 @@ import org.apache.http.util.EntityUtils;
import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.common.params.ModifiableSolrParams;
-/**
- * Facilitates testing Solr's REST API via a provided embedded Jetty
- */
+/** Facilitates testing Solr's REST API via a provided embedded Jetty */
public class RestTestHarness extends BaseTestHarness implements Closeable {
private RESTfulServerProvider serverProvider;
- private CloseableHttpClient httpClient = HttpClientUtil.createClient(new
- ModifiableSolrParams());
-
+ private CloseableHttpClient httpClient = HttpClientUtil.createClient(new ModifiableSolrParams());
+
public RestTestHarness(RESTfulServerProvider serverProvider) {
this.serverProvider = serverProvider;
}
-
+
public String getBaseURL() {
return serverProvider.getBaseURL();
}
@@ -62,7 +59,7 @@ public class RestTestHarness extends BaseTestHarness implements Closeable {
public String getAdminURL() {
return getBaseURL().replace("/collection1", "");
}
-
+
/**
* Validates an XML "query" response against an array of XPath test strings
*
@@ -77,7 +74,6 @@ public class RestTestHarness extends BaseTestHarness implements Closeable {
return validateXPath(res, tests);
}
-
/**
* Validates an XML PUT response against an array of XPath test strings
*
@@ -94,10 +90,9 @@ public class RestTestHarness extends BaseTestHarness implements Closeable {
return validateXPath(res, tests);
}
-
/**
- * Processes a "query" using a URL path (with no context path) + optional query params,
- * e.g. "/schema/fields?indent=off"
+ * Processes a "query" using a URL path (with no context path) + optional query params, e.g.
+ * "/schema/fields?indent=off"
*
* @param request the URL path and optional query params
* @return The response to the query
@@ -112,18 +107,18 @@ public class RestTestHarness extends BaseTestHarness implements Closeable {
}
/**
- * Processes a PUT request using a URL path (with no context path) + optional query params,
- * e.g. "/schema/fields/newfield", PUTs the given content, and returns the response content.
- *
+ * Processes a PUT request using a URL path (with no context path) + optional query params, e.g.
+ * "/schema/fields/newfield", PUTs the given content, and returns the response content.
+ *
* @param request The URL path and optional query params
* @param content The content to include with the PUT request
* @return The response to the PUT request
*/
public String put(String request, String content) throws IOException {
HttpPut httpPut = new HttpPut(getBaseURL() + request);
- httpPut.setEntity(new StringEntity(content, ContentType.create(
- "application/json", StandardCharsets.UTF_8)));
-
+ httpPut.setEntity(
+ new StringEntity(content, ContentType.create("application/json", StandardCharsets.UTF_8)));
+
return getResponse(httpPut);
}
@@ -140,8 +135,8 @@ public class RestTestHarness extends BaseTestHarness implements Closeable {
}
/**
- * Processes a POST request using a URL path (with no context path) + optional query params,
- * e.g. "/schema/fields/newfield", PUTs the given content, and returns the response content.
+ * Processes a POST request using a URL path (with no context path) + optional query params, e.g.
+ * "/schema/fields/newfield", PUTs the given content, and returns the response content.
*
* @param request The URL path and optional query params
* @param content The content to include with the POST request
@@ -149,17 +144,16 @@ public class RestTestHarness extends BaseTestHarness implements Closeable {
*/
public String post(String request, String content) throws IOException {
HttpPost httpPost = new HttpPost(getBaseURL() + request);
- httpPost.setEntity(new StringEntity(content, ContentType.create(
- "application/json", StandardCharsets.UTF_8)));
-
+ httpPost.setEntity(
+ new StringEntity(content, ContentType.create("application/json", StandardCharsets.UTF_8)));
+
return getResponse(httpPost);
}
-
public String checkResponseStatus(String xml, String code) throws Exception {
try {
String response = query(xml);
- String valid = validateXPath(response, "//int[@name='status']="+code );
+ String valid = validateXPath(response, "//int[@name='status']=" + code);
return (null == valid) ? null : response;
} catch (XPathExpressionException e) {
throw new RuntimeException("?!? static xpath has bug?", e);
@@ -169,30 +163,30 @@ public class RestTestHarness extends BaseTestHarness implements Closeable {
public String checkAdminResponseStatus(String xml, String code) throws Exception {
try {
String response = adminQuery(xml);
- String valid = validateXPath(response, "//int[@name='status']="+code );
+ String valid = validateXPath(response, "//int[@name='status']=" + code);
return (null == valid) ? null : response;
} catch (XPathExpressionException e) {
throw new RuntimeException("?!? static xpath has bug?", e);
}
}
- /**
- * Reloads the first core listed in the response to the core admin handler STATUS command
- */
+ /** Reloads the first core listed in the response to the core admin handler STATUS command */
@Override
public void reload() throws Exception {
- String coreName = (String)evaluateXPath
- (adminQuery("/admin/cores?wt=xml&action=STATUS"),
- "//lst[@name='status']/lst[1]/str[@name='name']",
- XPathConstants.STRING);
- String xml = checkAdminResponseStatus("/admin/cores?wt=xml&action=RELOAD&core=" + coreName, "0");
+ String coreName =
+ (String)
+ evaluateXPath(
+ adminQuery("/admin/cores?wt=xml&action=STATUS"),
+ "//lst[@name='status']/lst[1]/str[@name='name']",
+ XPathConstants.STRING);
+ String xml =
+ checkAdminResponseStatus("/admin/cores?wt=xml&action=RELOAD&core=" + coreName, "0");
if (null != xml) {
throw new RuntimeException("RELOAD failed:\n" + xml);
}
}
/**
- * Processes an "update" (add, commit or optimize) and
- * returns the response as a String.
+ * Processes an "update" (add, commit or optimize) and returns the response as a String.
*
* @param xml The XML of the update
* @return The XML response to the update
@@ -206,13 +200,14 @@ public class RestTestHarness extends BaseTestHarness implements Closeable {
}
}
- /**
- * Executes the given request and returns the response.
- */
+ /** Executes the given request and returns the response. */
private String getResponse(HttpUriRequest request) throws IOException {
HttpEntity entity = null;
try {
- entity = httpClient.execute(request, HttpClientUtil.createNewHttpClientRequestContext()).getEntity();
+ entity =
+ httpClient
+ .execute(request, HttpClientUtil.createNewHttpClientRequestContext())
+ .getEntity();
return EntityUtils.toString(entity, StandardCharsets.UTF_8);
} finally {
EntityUtils.consumeQuietly(entity);
diff --git a/solr/test-framework/src/java/org/apache/solr/util/RevertDefaultThreadHandlerRule.java b/solr/test-framework/src/java/org/apache/solr/util/RevertDefaultThreadHandlerRule.java
index a6f95a5c1ac..89778e80ae9 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/RevertDefaultThreadHandlerRule.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/RevertDefaultThreadHandlerRule.java
@@ -16,19 +16,17 @@
*/
package org.apache.solr.util;
+import com.carrotsearch.randomizedtesting.rules.StatementAdapter;
import java.lang.Thread.UncaughtExceptionHandler;
import java.util.concurrent.atomic.AtomicBoolean;
-
import org.apache.zookeeper.server.NIOServerCnxnFactory;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
-import com.carrotsearch.randomizedtesting.rules.StatementAdapter;
-
public final class RevertDefaultThreadHandlerRule implements TestRule {
- private final static AtomicBoolean applied = new AtomicBoolean();
-
+ private static final AtomicBoolean applied = new AtomicBoolean();
+
@Override
public Statement apply(Statement s, Description d) {
return new StatementAdapter(s) {
@@ -43,7 +41,7 @@ public final class RevertDefaultThreadHandlerRule implements TestRule {
Class.forName(cl.getName(), true, cl.getClassLoader());
} finally {
if (p == Thread.getDefaultUncaughtExceptionHandler()) {
- // throw new RuntimeException("Zookeeper no longer resets default thread handler.");
+ // throw new RuntimeException("Zookeeper no longer resets default thread handler.");
}
Thread.setDefaultUncaughtExceptionHandler(p);
}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java b/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java
index 22b49afda4c..b07dc96359d 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/SSLTestConfig.java
@@ -16,19 +16,19 @@
*/
package org.apache.solr.util;
-import java.security.SecureRandomParameters;
-import java.util.concurrent.ThreadLocalRandom;
-import javax.net.ssl.SSLContext;
+import com.carrotsearch.randomizedtesting.RandomizedTest;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
+import java.security.SecureRandomParameters;
import java.security.SecureRandomSpi;
import java.security.UnrecoverableKeyException;
import java.util.Random;
+import java.util.concurrent.ThreadLocalRandom;
import java.util.regex.Pattern;
-
+import javax.net.ssl.SSLContext;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.socket.ConnectionSocketFactory;
@@ -46,15 +46,14 @@ import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.security.CertificateUtils;
import org.eclipse.jetty.util.ssl.SslContextFactory;
-import com.carrotsearch.randomizedtesting.RandomizedTest;
-
/**
- * An SSLConfig that provides {@link SSLConfig} and {@link SocketFactoryRegistryProvider} for both clients and servers
- * that supports reading key/trust store information directly from resource files provided with the
- * Solr test-framework classes
+ * An SSLConfig that provides {@link SSLConfig} and {@link SocketFactoryRegistryProvider} for both
+ * clients and servers that supports reading key/trust store information directly from resource
+ * files provided with the Solr test-framework classes
*/
public class SSLTestConfig {
- private static final String TEST_KEYSTORE_BOGUSHOST_RESOURCE = "SSLTestConfig.hostname-and-ip-missmatch.keystore";
+ private static final String TEST_KEYSTORE_BOGUSHOST_RESOURCE =
+ "SSLTestConfig.hostname-and-ip-missmatch.keystore";
private static final String TEST_KEYSTORE_LOCALHOST_RESOURCE = "SSLTestConfig.testing.keystore";
private static final String TEST_PASSWORD = "secret";
@@ -70,12 +69,11 @@ public class SSLTestConfig {
}
/**
- * Create an SSLTestConfig based on a few caller specified options,
- * implicitly assuming <code>checkPeerName=false</code>.
- * <p>
- * As needed, keystore/truststore information will be pulled from a hardcoded resource
- * file provided by the solr test-framework
- * </p>
+ * Create an SSLTestConfig based on a few caller specified options, implicitly assuming <code>
+ * checkPeerName=false</code>.
+ *
+ * <p>As needed, keystore/truststore information will be pulled from a hardcoded resource file
+ * provided by the solr test-framework
*
* @param useSSL - whether SSL should be required.
* @param clientAuth - whether client authentication should be required.
@@ -86,21 +84,23 @@ public class SSLTestConfig {
// NOTE: if any javadocs below change, update create-keystores.sh
/**
- * Create an SSLTestConfig based on a few caller specified options. As needed,
- * keystore/truststore information will be pulled from a hardcoded resource files provided
- * by the solr test-framework based on the value of <code>checkPeerName</code>:
+ * Create an SSLTestConfig based on a few caller specified options. As needed, keystore/truststore
+ * information will be pulled from a hardcoded resource files provided by the solr test-framework
+ * based on the value of <code>checkPeerName</code>:
+ *
* <ul>
- * <li><code>true</code> - A keystore resource file will be used that specifies
- * a CN of <code>localhost</code> and a SAN IP of <code>127.0.0.1</code>, to
- * ensure that all connections should be valid regardless of what machine runs the tests.</li>
- * <li><code>false</code> - A keystore resource file will be used that specifies
- * a bogus hostname in the CN and reserved IP as the SAN, since no (valid) tests using this
- * SSLTestConfig should care what CN/SAN are.</li>
+ * <li><code>true</code> - A keystore resource file will be used that specifies a CN of <code>
+ * localhost</code> and a SAN IP of <code>127.0.0.1</code>, to ensure that all connections
+ * should be valid regardless of what machine runs the tests.
+ * <li><code>false</code> - A keystore resource file will be used that specifies a bogus
+ * hostname in the CN and reserved IP as the SAN, since no (valid) tests using this
+ * SSLTestConfig should care what CN/SAN are.
* </ul>
*
* @param useSSL - whether SSL should be required.
* @param clientAuth - whether client authentication should be required.
- * @param checkPeerName - whether the client should validate the 'peer name' of the SSL Certificate (and which testing Cert should be used)
+ * @param checkPeerName - whether the client should validate the 'peer name' of the SSL
+ * Certificate (and which testing Cert should be used)
* @see HttpClientUtil#SYS_PROP_CHECK_PEER_NAME
*/
public SSLTestConfig(boolean useSSL, boolean clientAuth, boolean checkPeerName) {
@@ -112,12 +112,12 @@ public class SSLTestConfig {
assumeSslIsSafeToTest();
}
- final String resourceName = checkPeerName
- ? TEST_KEYSTORE_LOCALHOST_RESOURCE : TEST_KEYSTORE_BOGUSHOST_RESOURCE;
+ final String resourceName =
+ checkPeerName ? TEST_KEYSTORE_LOCALHOST_RESOURCE : TEST_KEYSTORE_BOGUSHOST_RESOURCE;
trustStore = keyStore = Resource.newClassPathResource(resourceName);
- if (null == keyStore || ! keyStore.exists() ) {
- throw new IllegalStateException("Unable to locate keystore resource file in classpath: "
- + resourceName);
+ if (null == keyStore || !keyStore.exists()) {
+ throw new IllegalStateException(
+ "Unable to locate keystore resource file in classpath: " + resourceName);
}
}
@@ -136,11 +136,11 @@ public class SSLTestConfig {
}
/**
- * Creates a {@link SocketFactoryRegistryProvider} for HTTP <b>clients</b> to use when communicating with servers
- * which have been configured based on the settings of this object. When {@link #isSSLMode} is true, this
- * <code>SocketFactoryRegistryProvider</code> will <i>only</i> support HTTPS (no HTTP scheme) using the
- * appropriate certs. When {@link #isSSLMode} is false, <i>only</i> HTTP (no HTTPS scheme) will be
- * supported.
+ * Creates a {@link SocketFactoryRegistryProvider} for HTTP <b>clients</b> to use when
+ * communicating with servers which have been configured based on the settings of this object.
+ * When {@link #isSSLMode} is true, this <code>SocketFactoryRegistryProvider</code> will
+ * <i>only</i> support HTTPS (no HTTP scheme) using the appropriate certs. When {@link #isSSLMode}
+ * is false, <i>only</i> HTTP (no HTTPS scheme) will be supported.
*/
public SocketFactoryRegistryProvider buildClientSocketFactoryRegistryProvider() {
if (isSSLMode()) {
@@ -153,27 +153,32 @@ public class SSLTestConfig {
}
/**
- * Builds a new SSLContext for HTTP <b>clients</b> to use when communicating with servers which have
- * been configured based on the settings of this object.
+ * Builds a new SSLContext for HTTP <b>clients</b> to use when communicating with servers which
+ * have been configured based on the settings of this object.
*
- * NOTE: Uses a completely insecure {@link SecureRandom} instance to prevent tests from blocking
- * due to lack of entropy, also explicitly allows the use of self-signed
- * certificates (since that's what is almost always used during testing).
+ * <p>NOTE: Uses a completely insecure {@link SecureRandom} instance to prevent tests from
+ * blocking due to lack of entropy, also explicitly allows the use of self-signed certificates
+ * (since that's what is almost always used during testing).
*/
- public SSLContext buildClientSSLContext() throws KeyManagementException,
- UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException {
+ public SSLContext buildClientSSLContext()
+ throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException,
+ KeyStoreException {
assert isSSLMode();
SSLContextBuilder builder = SSLContexts.custom();
builder.setSecureRandom(NotSecurePseudoRandom.INSTANCE);
-
- // NOTE: KeyStore & TrustStore are swapped because they are from configured from server perspective...
+
+ // NOTE: KeyStore & TrustStore are swapped because they are from configured from server
+ // perspective...
// we are a client - our keystore contains the keys the server trusts, and vice versa
- builder.loadTrustMaterial(buildKeyStore(keyStore, TEST_PASSWORD), new TrustSelfSignedStrategy()).build();
+ builder
+ .loadTrustMaterial(buildKeyStore(keyStore, TEST_PASSWORD), new TrustSelfSignedStrategy())
+ .build();
if (isClientAuthMode()) {
- builder.loadKeyMaterial(buildKeyStore(trustStore, TEST_PASSWORD), TEST_PASSWORD.toCharArray());
+ builder.loadKeyMaterial(
+ buildKeyStore(trustStore, TEST_PASSWORD), TEST_PASSWORD.toCharArray());
}
return builder.build();
@@ -190,8 +195,12 @@ public class SSLTestConfig {
SslContextFactory.Client factory = new SslContextFactory.Client(!checkPeerName);
try {
factory.setSslContext(buildClientSSLContext());
- } catch (KeyManagementException | UnrecoverableKeyException | NoSuchAlgorithmException | KeyStoreException e) {
- throw new IllegalStateException("Unable to setup https scheme for HTTPClient to test SSL.", e);
+ } catch (KeyManagementException
+ | UnrecoverableKeyException
+ | NoSuchAlgorithmException
+ | KeyStoreException e) {
+ throw new IllegalStateException(
+ "Unable to setup https scheme for HTTPClient to test SSL.", e);
}
return factory;
}
@@ -202,10 +211,9 @@ public class SSLTestConfig {
* Builds a new SSLContext for jetty servers which have been configured based on the settings of
* this object.
*
- * NOTE: Uses a completely insecure {@link SecureRandom} instance to prevent tests from blocking
- * due to lack of entropy, also explicitly allows the use of self-signed
- * certificates (since that's what is almost always used during testing).
- * almost always used during testing).
+ * <p>NOTE: Uses a completely insecure {@link SecureRandom} instance to prevent tests from
+ * blocking due to lack of entropy, also explicitly allows the use of self-signed certificates
+ * (since that's what is almost always used during testing). almost always used during testing).
*/
public SSLConfig buildServerSSLConfig() {
if (!isSSLMode()) {
@@ -220,11 +228,14 @@ public class SSLTestConfig {
SSLContextBuilder builder = SSLContexts.custom();
builder.setSecureRandom(NotSecurePseudoRandom.INSTANCE);
- builder.loadKeyMaterial(buildKeyStore(keyStore, TEST_PASSWORD), TEST_PASSWORD.toCharArray());
+ builder.loadKeyMaterial(
+ buildKeyStore(keyStore, TEST_PASSWORD), TEST_PASSWORD.toCharArray());
if (isClientAuthMode()) {
- builder.loadTrustMaterial(buildKeyStore(trustStore, TEST_PASSWORD), new TrustSelfSignedStrategy()).build();
-
+ builder
+ .loadTrustMaterial(
+ buildKeyStore(trustStore, TEST_PASSWORD), new TrustSelfSignedStrategy())
+ .build();
}
factory.setSslContext(builder.build());
} catch (Exception e) {
@@ -236,19 +247,18 @@ public class SSLTestConfig {
};
}
- /**
- * Constructs a KeyStore using the specified filename and password
- */
+ /** Constructs a KeyStore using the specified filename and password */
private static KeyStore buildKeyStore(Resource resource, String password) {
try {
return CertificateUtils.getKeyStore(resource, "JKS", null, password);
} catch (Exception ex) {
- throw new IllegalStateException("Unable to build KeyStore from resource: " + resource.getName(), ex);
+ throw new IllegalStateException(
+ "Unable to build KeyStore from resource: " + resource.getName(), ex);
}
}
- /**
- * Constructs a new SSLConnectionSocketFactory for HTTP <b>clients</b> to use when communicating
+ /**
+ * Constructs a new SSLConnectionSocketFactory for HTTP <b>clients</b> to use when communicating
* with servers which have been configured based on the settings of this object. Will return null
* unless {@link #isSSLMode} is true.
*/
@@ -260,49 +270,61 @@ public class SSLTestConfig {
try {
SSLContext sslContext = buildClientSSLContext();
if (checkPeerName == false) {
- sslConnectionFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
+ sslConnectionFactory =
+ new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
} else {
sslConnectionFactory = new SSLConnectionSocketFactory(sslContext);
}
- } catch (KeyManagementException | UnrecoverableKeyException | NoSuchAlgorithmException | KeyStoreException e) {
- throw new IllegalStateException("Unable to setup https scheme for HTTPClient to test SSL.", e);
+ } catch (KeyManagementException
+ | UnrecoverableKeyException
+ | NoSuchAlgorithmException
+ | KeyStoreException e) {
+ throw new IllegalStateException(
+ "Unable to setup https scheme for HTTPClient to test SSL.", e);
}
return sslConnectionFactory;
}
- /** A SocketFactoryRegistryProvider that only knows about SSL using a specified SSLConnectionSocketFactory */
+ /**
+ * A SocketFactoryRegistryProvider that only knows about SSL using a specified
+ * SSLConnectionSocketFactory
+ */
private static class SSLSocketFactoryRegistryProvider extends SocketFactoryRegistryProvider {
private final SSLConnectionSocketFactory sslConnectionFactory;
+
public SSLSocketFactoryRegistryProvider(SSLConnectionSocketFactory sslConnectionFactory) {
this.sslConnectionFactory = sslConnectionFactory;
}
+
@Override
public Registry<ConnectionSocketFactory> getSocketFactoryRegistry() {
return RegistryBuilder.<ConnectionSocketFactory>create()
- .register("https", sslConnectionFactory).build();
+ .register("https", sslConnectionFactory)
+ .build();
}
}
/** A SocketFactoryRegistryProvider that only knows about HTTP */
- private static final SocketFactoryRegistryProvider HTTP_ONLY_SCHEMA_PROVIDER = new SocketFactoryRegistryProvider() {
- @Override
- public Registry<ConnectionSocketFactory> getSocketFactoryRegistry() {
- return RegistryBuilder.<ConnectionSocketFactory>create()
- .register("http", PlainConnectionSocketFactory.getSocketFactory()).build();
- }
- };
+ private static final SocketFactoryRegistryProvider HTTP_ONLY_SCHEMA_PROVIDER =
+ new SocketFactoryRegistryProvider() {
+ @Override
+ public Registry<ConnectionSocketFactory> getSocketFactoryRegistry() {
+ return RegistryBuilder.<ConnectionSocketFactory>create()
+ .register("http", PlainConnectionSocketFactory.getSocketFactory())
+ .build();
+ }
+ };
/**
- * A mocked up instance of SecureRandom that just uses {@link Random} under the covers.
- * This is to prevent blocking issues that arise in platform default
- * SecureRandom instances due to too many instances / not enough random entropy.
- * Tests do not need secure SSL.
+ * A mocked up instance of SecureRandom that just uses {@link Random} under the covers. This is to
+ * prevent blocking issues that arise in platform default SecureRandom instances due to too many
+ * instances / not enough random entropy. Tests do not need secure SSL.
*/
private static class NotSecurePseudoRandom extends SecureRandom {
public static final SecureRandom INSTANCE = new NotSecurePseudoRandom();
/**
- * Helper method that can be used to fill an array with non-zero data.
- * (Attempted workarround of Solaris SSL Padding bug: SOLR-9068)
+ * Helper method that can be used to fill an array with non-zero data. (Attempted workarround of
+ * Solaris SSL Padding bug: SOLR-9068)
*/
private static final byte[] fillData(byte[] data) {
ThreadLocalRandom.current().nextBytes(data);
@@ -310,18 +332,21 @@ public class SSLTestConfig {
}
/** SPI Used to init all instances */
- private static final SecureRandomSpi NOT_SECURE_SPI = new SecureRandomSpi() {
- /** returns a new byte[] filled with static data */
- public byte[] engineGenerateSeed(int numBytes) {
- return fillData(new byte[numBytes]);
- }
- /** fills the byte[] with static data */
- public void engineNextBytes(byte[] bytes) {
- fillData(bytes);
- }
- /** NOOP */
- public void engineSetSeed(byte[] seed) { /* NOOP */ }
- };
+ private static final SecureRandomSpi NOT_SECURE_SPI =
+ new SecureRandomSpi() {
+ /** returns a new byte[] filled with static data */
+ public byte[] engineGenerateSeed(int numBytes) {
+ return fillData(new byte[numBytes]);
+ }
+ /** fills the byte[] with static data */
+ public void engineNextBytes(byte[] bytes) {
+ fillData(bytes);
+ }
+ /** NOOP */
+ public void engineSetSeed(byte[] seed) {
+ /* NOOP */
+ }
+ };
private NotSecurePseudoRandom() {
super(NOT_SECURE_SPI, null);
@@ -340,9 +365,13 @@ public class SSLTestConfig {
fillData(bytes);
}
/** NOOP */
- public void setSeed(byte[] seed) { /* NOOP */ }
+ public void setSeed(byte[] seed) {
+ /* NOOP */
+ }
/** NOOP */
- public void setSeed(long seed) { /* NOOP */ }
+ public void setSeed(long seed) {
+ /* NOOP */
+ }
public void reseed() {
/* NOOP */
@@ -351,27 +380,31 @@ public class SSLTestConfig {
public void reseed(SecureRandomParameters params) {
/* NOOP */
}
-
}
/**
* Helper method for sanity checking if it's safe to use SSL on this JVM
*
* @see <a href="https://issues.apache.org/jira/browse/SOLR-12988">SOLR-12988</a>
- * @throws org.junit.internal.AssumptionViolatedException if this JVM is known to have SSL problems
+ * @throws org.junit.internal.AssumptionViolatedException if this JVM is known to have SSL
+ * problems
*/
public static void assumeSslIsSafeToTest() {
- if (Constants.JVM_NAME.startsWith("OpenJDK") ||
- Constants.JVM_NAME.startsWith("Java HotSpot(TM)")) {
- RandomizedTest.assumeFalse("Test (or randomization for this seed) wants to use SSL, " +
- "but SSL is known to fail on your JVM: " +
- Constants.JVM_NAME + " / " + Constants.JVM_VERSION,
+ if (Constants.JVM_NAME.startsWith("OpenJDK")
+ || Constants.JVM_NAME.startsWith("Java HotSpot(TM)")) {
+ RandomizedTest.assumeFalse(
+ "Test (or randomization for this seed) wants to use SSL, "
+ + "but SSL is known to fail on your JVM: "
+ + Constants.JVM_NAME
+ + " / "
+ + Constants.JVM_VERSION,
isOpenJdkJvmVersionKnownToHaveProblems(Constants.JVM_VERSION));
}
}
/**
* package visibility for tests
+ *
* @see Constants#JVM_VERSION
* @lucene.internal
*/
@@ -379,18 +412,19 @@ public class SSLTestConfig {
// TODO: would be nice to replace with Runtime.Version once we don't have to
// worry about java8 support when backporting to branch_8x
return KNOWN_BAD_OPENJDK_JVMS.matcher(jvmVersion).matches();
-
}
- private static final Pattern KNOWN_BAD_OPENJDK_JVMS
- = Pattern.compile(// 11 to 11.0.2 were all definitely problematic
- // - https://bugs.openjdk.java.net/browse/JDK-8212885
- // - https://bugs.openjdk.java.net/browse/JDK-8213202
- "(^11(\\.0(\\.0|\\.1|\\.2)?)?($|(\\_|\\+|\\-).*$))|" +
- // early (pre-ea) "testing" builds of 11, 12, and 13 were also buggy
- // - https://bugs.openjdk.java.net/browse/JDK-8224829
- "(^(11|12|13).*-testing.*$)|" +
- // So far, all 13-ea builds (up to 13-ea-26) have been buggy
- // - https://bugs.openjdk.java.net/browse/JDK-8226338
- "(^13-ea.*$)"
- );
+
+ private static final Pattern KNOWN_BAD_OPENJDK_JVMS =
+ Pattern.compile( // 11 to 11.0.2 were all definitely problematic
+ // - https://bugs.openjdk.java.net/browse/JDK-8212885
+ // - https://bugs.openjdk.java.net/browse/JDK-8213202
+ "(^11(\\.0(\\.0|\\.1|\\.2)?)?($|(\\_|\\+|\\-).*$))|"
+ +
+ // early (pre-ea) "testing" builds of 11, 12, and 13 were also buggy
+ // - https://bugs.openjdk.java.net/browse/JDK-8224829
+ "(^(11|12|13).*-testing.*$)|"
+ +
+ // So far, all 13-ea builds (up to 13-ea-26) have been buggy
+ // - https://bugs.openjdk.java.net/browse/JDK-8226338
+ "(^13-ea.*$)");
}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/SolrTestNonSecureRandomProvider.java b/solr/test-framework/src/java/org/apache/solr/util/SolrTestNonSecureRandomProvider.java
index ee7ce7a8e76..ac9eed8b946 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/SolrTestNonSecureRandomProvider.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/SolrTestNonSecureRandomProvider.java
@@ -24,9 +24,7 @@ import java.security.Security;
public class SolrTestNonSecureRandomProvider extends Provider {
public SolrTestNonSecureRandomProvider() {
- super("SolrTestNonSecure",
- "1.0",
- "A Test only, non secure provider");
+ super("SolrTestNonSecure", "1.0", "A Test only, non secure provider");
put("SecureRandom.SHA1PRNG", NotSecurePseudoRandomSpi.class.getName());
put("SecureRandom.NativePRNG", NotSecurePseudoRandomSpi.class.getName());
put("SecureRandom.DRBG", NotSecurePseudoRandomSpi.class.getName());
@@ -41,39 +39,36 @@ public class SolrTestNonSecureRandomProvider extends Provider {
}
public static void injectProvider() {
- // Install our non secure solr test secure random provider
- Provider[] secureRandomProviders =
- Security.getProviders("SecureRandom.SHA1PRNG");
- if ((secureRandomProviders == null)
- || (secureRandomProviders.length < 1)
- || (!SolrTestNonSecureRandomProvider.class.equals(
- secureRandomProviders[0].getClass()))) {
- Security.insertProviderAt(new SolrTestNonSecureRandomProvider(), 1);
- }
+ // Install our non secure solr test secure random provider
+ Provider[] secureRandomProviders = Security.getProviders("SecureRandom.SHA1PRNG");
+ if ((secureRandomProviders == null)
+ || (secureRandomProviders.length < 1)
+ || (!SolrTestNonSecureRandomProvider.class.equals(secureRandomProviders[0].getClass()))) {
+ Security.insertProviderAt(new SolrTestNonSecureRandomProvider(), 1);
+ }
- // Assert that new SecureRandom() and
- // SecureRandom.getInstance("SHA1PRNG") return a SecureRandom backed
- // by our non secure test provider.
- SecureRandom rng1 = new SecureRandom();
- if (!SolrTestNonSecureRandomProvider.class.equals(
- rng1.getProvider().getClass())) {
- throw new SecurityException(
- "new SecureRandom() backed by wrong Provider: "
- + rng1.getProvider().getClass());
- }
+ // Assert that new SecureRandom() and
+ // SecureRandom.getInstance("SHA1PRNG") return a SecureRandom backed
+ // by our non secure test provider.
+ SecureRandom rng1 = new SecureRandom();
+ if (!SolrTestNonSecureRandomProvider.class.equals(rng1.getProvider().getClass())) {
+ throw new SecurityException(
+ "new SecureRandom() backed by wrong Provider: " + rng1.getProvider().getClass());
+ }
- boolean skipCheck = false;
- SecureRandom rng2 = null;
- try {
- rng2 = SecureRandom.getInstance("SHA1PRNG");
- } catch (NoSuchAlgorithmException e) {
- skipCheck = true;
- }
- if (!skipCheck && !SolrTestNonSecureRandomProvider.class.equals(
- rng2.getProvider().getClass())) {
- throw new SecurityException(
- "SecureRandom.getInstance(\"SHA1PRNG\") backed by wrong"
- + " Provider: " + rng2.getProvider().getClass());
- }
+ boolean skipCheck = false;
+ SecureRandom rng2 = null;
+ try {
+ rng2 = SecureRandom.getInstance("SHA1PRNG");
+ } catch (NoSuchAlgorithmException e) {
+ skipCheck = true;
+ }
+ if (!skipCheck
+ && !SolrTestNonSecureRandomProvider.class.equals(rng2.getProvider().getClass())) {
+ throw new SecurityException(
+ "SecureRandom.getInstance(\"SHA1PRNG\") backed by wrong"
+ + " Provider: "
+ + rng2.getProvider().getClass());
+ }
}
-}
\ No newline at end of file
+}
diff --git a/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java b/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java
index 67f7aebcefa..b0afecac2da 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java
@@ -16,6 +16,7 @@
*/
package org.apache.solr.util;
+import com.google.common.collect.ImmutableList;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringWriter;
@@ -25,8 +26,6 @@ import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-
-import com.google.common.collect.ImmutableList;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.common.SolrException;
@@ -60,26 +59,21 @@ import org.apache.solr.servlet.DirectSolrConnection;
import org.apache.solr.update.UpdateShardHandlerConfig;
/**
- * This class provides a simple harness that may be useful when
- * writing testcases.
- *
- * <p>
- * This class lives in the tests-framework source tree (and not in the test source
- * tree), so that it will be included with even the most minimal solr
- * distribution, in order to encourage plugin writers to create unit
- * tests for their plugins.
- *
+ * This class provides a simple harness that may be useful when writing testcases.
*
+ * <p>This class lives in the tests-framework source tree (and not in the test source tree), so that
+ * it will be included with even the most minimal solr distribution, in order to encourage plugin
+ * writers to create unit tests for their plugins.
*/
public class TestHarness extends BaseTestHarness {
public String coreName;
protected volatile CoreContainer container;
public UpdateRequestHandler updater;
-
+
/**
- * Creates a SolrConfig object for the specified coreName assuming it
- * follows the basic conventions of being a relative path in the solrHome
- * dir. (ie: <code>${solrHome}/${coreName}/conf/${confFile}</code>
+ * Creates a SolrConfig object for the specified coreName assuming it follows the basic
+ * conventions of being a relative path in the solrHome dir. (ie: <code>
+ * ${solrHome}/${coreName}/conf/${confFile}</code>
*/
public static SolrConfig createConfig(Path solrHome, String coreName, String confFile) {
// set some system properties for use by tests
@@ -91,9 +85,10 @@ public class TestHarness extends BaseTestHarness {
throw new RuntimeException(xany);
}
}
-
+
/**
- * Creates a SolrConfig object for the default test core using {@link #createConfig(Path,String,String)}
+ * Creates a SolrConfig object for the default test core using {@link
+ * #createConfig(Path,String,String)}
*/
public static SolrConfig createConfig(Path solrHome, String confFile) {
return createConfig(solrHome, SolrTestCaseJ4.DEFAULT_TEST_CORENAME, confFile);
@@ -105,47 +100,48 @@ public class TestHarness extends BaseTestHarness {
* @param solrConfig solronfig instance
* @param schemaFile schema filename
*/
- public TestHarness( String coreName,
- String dataDirectory,
- SolrConfig solrConfig,
- String schemaFile) {
- this( coreName, dataDirectory, solrConfig, IndexSchemaFactory.buildIndexSchema(schemaFile, solrConfig));
+ public TestHarness(
+ String coreName, String dataDirectory, SolrConfig solrConfig, String schemaFile) {
+ this(
+ coreName,
+ dataDirectory,
+ solrConfig,
+ IndexSchemaFactory.buildIndexSchema(schemaFile, solrConfig));
}
- /**
- * @param dataDirectory path for index data, will not be cleaned up
- * @param solrConfig solronfig instance
- * @param schemaFile schema filename
- */
- public TestHarness( String dataDirectory,
- SolrConfig solrConfig,
- String schemaFile) {
- this( dataDirectory, solrConfig, IndexSchemaFactory.buildIndexSchema(schemaFile, solrConfig));
- }
- /**
- * @param dataDirectory path for index data, will not be cleaned up
- * @param solrConfig solrconfig instance
- * @param indexSchema schema instance
- */
- public TestHarness( String dataDirectory,
- SolrConfig solrConfig,
- IndexSchema indexSchema) {
- this(SolrTestCaseJ4.DEFAULT_TEST_CORENAME, dataDirectory, solrConfig, indexSchema);
+ /**
+ * @param dataDirectory path for index data, will not be cleaned up
+ * @param solrConfig solronfig instance
+ * @param schemaFile schema filename
+ */
+ public TestHarness(String dataDirectory, SolrConfig solrConfig, String schemaFile) {
+ this(dataDirectory, solrConfig, IndexSchemaFactory.buildIndexSchema(schemaFile, solrConfig));
+ }
+ /**
+ * @param dataDirectory path for index data, will not be cleaned up
+ * @param solrConfig solrconfig instance
+ * @param indexSchema schema instance
+ */
+ public TestHarness(String dataDirectory, SolrConfig solrConfig, IndexSchema indexSchema) {
+ this(SolrTestCaseJ4.DEFAULT_TEST_CORENAME, dataDirectory, solrConfig, indexSchema);
}
- /**
- * Helper method to let us do some home sys prop check in delegated construtor.
- * in "real" code SolrDispatchFilter takes care of checking this sys prop when building NodeConfig/CoreContainer
+ /**
+ * Helper method to let us do some home sys prop check in delegated construtor. in "real" code
+ * SolrDispatchFilter takes care of checking this sys prop when building NodeConfig/CoreContainer
*/
private static Path checkAndReturnSolrHomeSysProp() {
final String SOLR_HOME = "solr.solr.home";
final String home = System.getProperty(SOLR_HOME);
if (null == home) {
- throw new IllegalStateException("This TestHarness constructor requires " + SOLR_HOME + " sys prop to be set by test first");
+ throw new IllegalStateException(
+ "This TestHarness constructor requires "
+ + SOLR_HOME
+ + " sys prop to be set by test first");
}
return Paths.get(home).toAbsolutePath().normalize();
}
-
+
/**
* @param coreName to initialize
* @param dataDir path for index data, will not be cleaned up
@@ -153,17 +149,20 @@ public class TestHarness extends BaseTestHarness {
* @param indexSchema schema resource name
*/
public TestHarness(String coreName, String dataDir, String solrConfig, String indexSchema) {
- this(buildTestNodeConfig(checkAndReturnSolrHomeSysProp()),
+ this(
+ buildTestNodeConfig(checkAndReturnSolrHomeSysProp()),
new TestCoresLocator(coreName, dataDir, solrConfig, indexSchema));
this.coreName = (coreName == null) ? SolrTestCaseJ4.DEFAULT_TEST_CORENAME : coreName;
}
- public TestHarness(String coreName, String dataDir, SolrConfig solrConfig, IndexSchema indexSchema) {
+ public TestHarness(
+ String coreName, String dataDir, SolrConfig solrConfig, IndexSchema indexSchema) {
this(coreName, dataDir, solrConfig.getResourceName(), indexSchema.getResourceName());
}
/**
* Create a TestHarness using a specific solr home directory and solr xml
+ *
* @param solrHome the solr home directory
* @param solrXml the text of a solrxml
*/
@@ -177,6 +176,7 @@ public class TestHarness extends BaseTestHarness {
/**
* Create a TestHarness using a specific config
+ *
* @param config the ConfigSolr to use
*/
public TestHarness(NodeConfig config, CoresLocator coresLocator) {
@@ -187,27 +187,33 @@ public class TestHarness extends BaseTestHarness {
}
public static NodeConfig buildTestNodeConfig(Path solrHome) {
- CloudConfig cloudConfig = (null == System.getProperty("zkHost"))
- ? null
- : new CloudConfig.CloudConfigBuilder(System.getProperty("host"),
- Integer.getInteger("hostPort", 8983),
- System.getProperty("hostContext", ""))
- .setZkClientTimeout(Integer.getInteger("zkClientTimeout", 30000))
- .setZkHost(System.getProperty("zkHost"))
- .build();
- UpdateShardHandlerConfig updateShardHandlerConfig = new UpdateShardHandlerConfig(
- HttpClientUtil.DEFAULT_MAXCONNECTIONS,
- HttpClientUtil.DEFAULT_MAXCONNECTIONSPERHOST,
- 30000, 30000,
- UpdateShardHandlerConfig.DEFAULT_METRICNAMESTRATEGY, UpdateShardHandlerConfig.DEFAULT_MAXRECOVERYTHREADS);
+ CloudConfig cloudConfig =
+ (null == System.getProperty("zkHost"))
+ ? null
+ : new CloudConfig.CloudConfigBuilder(
+ System.getProperty("host"),
+ Integer.getInteger("hostPort", 8983),
+ System.getProperty("hostContext", ""))
+ .setZkClientTimeout(Integer.getInteger("zkClientTimeout", 30000))
+ .setZkHost(System.getProperty("zkHost"))
+ .build();
+ UpdateShardHandlerConfig updateShardHandlerConfig =
+ new UpdateShardHandlerConfig(
+ HttpClientUtil.DEFAULT_MAXCONNECTIONS,
+ HttpClientUtil.DEFAULT_MAXCONNECTIONSPERHOST,
+ 30000,
+ 30000,
+ UpdateShardHandlerConfig.DEFAULT_METRICNAMESTRATEGY,
+ UpdateShardHandlerConfig.DEFAULT_MAXRECOVERYTHREADS);
// universal default metric reporter
- Map<String,Object> attributes = new HashMap<>();
+ Map<String, Object> attributes = new HashMap<>();
attributes.put("name", "default");
attributes.put("class", SolrJmxReporter.class.getName());
PluginInfo defaultPlugin = new PluginInfo("reporter", attributes);
- MetricsConfig metricsConfig = new MetricsConfig.MetricsConfigBuilder()
- .setMetricReporterPlugins(new PluginInfo[]{defaultPlugin})
- .build();
+ MetricsConfig metricsConfig =
+ new MetricsConfig.MetricsConfigBuilder()
+ .setMetricReporterPlugins(new PluginInfo[] {defaultPlugin})
+ .build();
return new NodeConfig.NodeConfigBuilder("testNode", solrHome)
.setUseSchemaCache(Boolean.getBoolean("shareSchema"))
@@ -233,54 +239,58 @@ public class TestHarness extends BaseTestHarness {
@Override
public List<CoreDescriptor> discover(CoreContainer cc) {
- return ImmutableList.of(new CoreDescriptor(coreName, cc.getCoreRootDirectory().resolve(coreName), cc,
- CoreDescriptor.CORE_DATADIR, dataDir,
- CoreDescriptor.CORE_CONFIG, solrConfig,
- CoreDescriptor.CORE_SCHEMA, schema,
- CoreDescriptor.CORE_COLLECTION, System.getProperty("collection", "collection1"),
- CoreDescriptor.CORE_SHARD, System.getProperty("shard", "shard1")));
+ return ImmutableList.of(
+ new CoreDescriptor(
+ coreName,
+ cc.getCoreRootDirectory().resolve(coreName),
+ cc,
+ CoreDescriptor.CORE_DATADIR,
+ dataDir,
+ CoreDescriptor.CORE_CONFIG,
+ solrConfig,
+ CoreDescriptor.CORE_SCHEMA,
+ schema,
+ CoreDescriptor.CORE_COLLECTION,
+ System.getProperty("collection", "collection1"),
+ CoreDescriptor.CORE_SHARD,
+ System.getProperty("shard", "shard1")));
}
-
}
-
+
public CoreContainer getCoreContainer() {
return container;
}
- /** Gets a core that does not have its refcount incremented (i.e. there is no need to
- * close when done). This is not MT safe in conjunction with reloads!
+ /**
+ * Gets a core that does not have its refcount incremented (i.e. there is no need to close when
+ * done). This is not MT safe in conjunction with reloads!
*/
public SolrCore getCore() {
// get the core & decrease its refcount:
// the container holds the core for the harness lifetime
SolrCore core = container.getCore(coreName);
- if (core != null)
- core.close();
+ if (core != null) core.close();
return core;
}
- /** Gets the core with its reference count incremented.
- * You must call core.close() when done!
- */
+ /** Gets the core with its reference count incremented. You must call core.close() when done! */
public SolrCore getCoreInc() {
return container.getCore(coreName);
}
-
public void reload() throws Exception {
container.reload(coreName);
}
/**
- * Processes an "update" (add, commit or optimize) and
- * returns the response as a String.
+ * Processes an "update" (add, commit or optimize) and returns the response as a String.
*
* @param xml The XML of the update
* @return The XML response to the update
*/
public String update(String xml) {
try (var mdcSnap = MDCSnapshot.create();
- SolrCore core = getCoreInc()) {
+ SolrCore core = getCoreInc()) {
assert null != mdcSnap; // prevent compiler warning of unused var
DirectSolrConnection connection = new DirectSolrConnection(core);
SolrRequestHandler handler = core.getRequestHandler("/update");
@@ -296,8 +306,7 @@ public class TestHarness extends BaseTestHarness {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
}
}
-
-
+
/**
* Validates a "query" response against an array of XPath test strings
*
@@ -307,13 +316,12 @@ public class TestHarness extends BaseTestHarness {
* @exception IOException if there is a problem writing the XML
* @see LocalSolrQueryRequest
*/
- public String validateQuery(SolrQueryRequest req, String... tests)
- throws Exception {
-
+ public String validateQuery(SolrQueryRequest req, String... tests) throws Exception {
+
String res = query(req);
return validateXPath(res, tests);
}
-
+
/**
* Processes a "query" using a user constructed SolrQueryRequest
*
@@ -328,7 +336,8 @@ public class TestHarness extends BaseTestHarness {
}
/**
- * Processes a "query" using a user constructed SolrQueryRequest, and closes the request at the end.
+ * Processes a "query" using a user constructed SolrQueryRequest, and closes the request at the
+ * end.
*
* @param handler the name of the request handler to process the request
* @param req the Query to process, will be closed.
@@ -343,7 +352,7 @@ public class TestHarness extends BaseTestHarness {
SolrCore core = req.getCore();
SolrQueryResponse rsp = new SolrQueryResponse();
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
- core.execute(core.getRequestHandler(handler),req,rsp);
+ core.execute(core.getRequestHandler(handler), req, rsp);
if (rsp.getException() != null) {
throw rsp.getException();
}
@@ -355,7 +364,7 @@ public class TestHarness extends BaseTestHarness {
return new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8);
} else {
StringWriter sw = new StringWriter(32000);
- responseWriter.write(sw,req,rsp);
+ responseWriter.write(sw, req, rsp);
return sw.toString();
}
@@ -365,11 +374,13 @@ public class TestHarness extends BaseTestHarness {
}
}
- /** It is the users responsibility to close the request object when done with it.
- * This method does not set/clear SolrRequestInfo */
+ /**
+ * It is the users responsibility to close the request object when done with it. This method does
+ * not set/clear SolrRequestInfo
+ */
public SolrQueryResponse queryAndResponse(String handler, SolrQueryRequest req) throws Exception {
try (var mdcSnap = MDCSnapshot.create();
- SolrCore core = getCoreInc()) {
+ SolrCore core = getCoreInc()) {
assert null != mdcSnap; // prevent compiler warning of unused var
SolrQueryResponse rsp = new SolrQueryResponse();
core.execute(core.getRequestHandler(handler), req, rsp);
@@ -380,9 +391,7 @@ public class TestHarness extends BaseTestHarness {
}
}
- /**
- * Shuts down and frees any resources
- */
+ /** Shuts down and frees any resources */
public void close() {
if (container != null) {
container.shutdown();
@@ -390,92 +399,78 @@ public class TestHarness extends BaseTestHarness {
}
}
- public LocalRequestFactory getRequestFactory(String qtype,
- int start,
- int limit) {
+ public LocalRequestFactory getRequestFactory(String qtype, int start, int limit) {
LocalRequestFactory f = new LocalRequestFactory();
f.qtype = qtype;
f.start = start;
f.limit = limit;
return f;
}
-
- /**
- * 0 and Even numbered args are keys, Odd numbered args are values.
- */
- public LocalRequestFactory getRequestFactory(String qtype,
- int start, int limit,
- String... args) {
+
+ /** 0 and Even numbered args are keys, Odd numbered args are values. */
+ public LocalRequestFactory getRequestFactory(String qtype, int start, int limit, String... args) {
LocalRequestFactory f = getRequestFactory(qtype, start, limit);
- for (int i = 0; i < args.length; i+=2) {
- f.args.put(args[i], args[i+1]);
+ for (int i = 0; i < args.length; i += 2) {
+ f.args.put(args[i], args[i + 1]);
}
return f;
-
}
-
- public LocalRequestFactory getRequestFactory(String qtype,
- int start, int limit,
- Map<String,String> args) {
+
+ public LocalRequestFactory getRequestFactory(
+ String qtype, int start, int limit, Map<String, String> args) {
LocalRequestFactory f = getRequestFactory(qtype, start, limit);
f.args.putAll(args);
return f;
}
-
+
/**
- * A Factory that generates LocalSolrQueryRequest objects using a
- * specified set of default options.
+ * A Factory that generates LocalSolrQueryRequest objects using a specified set of default
+ * options.
*/
public class LocalRequestFactory {
public String qtype = null;
public int start = 0;
public int limit = 1000;
- public Map<String,String> args = new HashMap<>();
- public LocalRequestFactory() {
- }
+ public Map<String, String> args = new HashMap<>();
+
+ public LocalRequestFactory() {}
/**
- * Creates a LocalSolrQueryRequest based on variable args; for
- * historical reasons, this method has some peculiar behavior:
+ * Creates a LocalSolrQueryRequest based on variable args; for historical reasons, this method
+ * has some peculiar behavior:
+ *
* <ul>
- * <li>If there is a single arg, then it is treated as the "q"
- * param, and the LocalSolrQueryRequest consists of that query
- * string along with "qt", "start", and "rows" params (based
- * on the qtype, start, and limit properties of this factory)
- * along with any other default "args" set on this factory.
- * </li>
- * <li>If there are multiple args, then there must be an even number
- * of them, and each pair of args is used as a key=value param in
- * the LocalSolrQueryRequest. <b>NOTE: In this usage, the "qtype",
- * "start", "limit", and "args" properties of this factory are
- * ignored.</b>
- * </li>
+ * <li>If there is a single arg, then it is treated as the "q" param, and the
+ * LocalSolrQueryRequest consists of that query string along with "qt", "start", and
+ * "rows" params (based on the qtype, start, and limit properties of this factory) along
+ * with any other default "args" set on this factory.
+ * <li>If there are multiple args, then there must be an even number of them, and each pair of
+ * args is used as a key=value param in the LocalSolrQueryRequest. <b>NOTE: In this usage,
+ * the "qtype", "start", "limit", and "args" properties of this factory are ignored.</b>
* </ul>
*
- * TODO: this isn't really safe in the presense of core reloads!
- * Perhaps the best we could do is increment the core reference count
- * and decrement it in the request close() method?
+ * TODO: this isn't really safe in the presense of core reloads! Perhaps the best we could do is
+ * increment the core reference count and decrement it in the request close() method?
*/
@SuppressWarnings({"unchecked"})
- public LocalSolrQueryRequest makeRequest(String ... q) {
- if (q.length==1) {
- return new LocalSolrQueryRequest(TestHarness.this.getCore(),
- q[0], qtype, start, limit, args);
+ public LocalSolrQueryRequest makeRequest(String... q) {
+ if (q.length == 1) {
+ return new LocalSolrQueryRequest(
+ TestHarness.this.getCore(), q[0], qtype, start, limit, args);
}
- if (q.length%2 != 0) {
- throw new RuntimeException("The length of the string array (query arguments) needs to be even");
+ if (q.length % 2 != 0) {
+ throw new RuntimeException(
+ "The length of the string array (query arguments) needs to be even");
}
@SuppressWarnings({"rawtypes"})
- Map.Entry<String, String> [] entries = new NamedListEntry[q.length / 2];
+ Map.Entry<String, String>[] entries = new NamedListEntry[q.length / 2];
for (int i = 0; i < q.length; i += 2) {
- entries[i/2] = new NamedListEntry<>(q[i], q[i+1]);
+ entries[i / 2] = new NamedListEntry<>(q[i], q[i + 1]);
}
@SuppressWarnings({"rawtypes"})
NamedList nl = new NamedList(entries);
- if(nl.get("wt" ) == null) nl.add("wt","xml");
+ if (nl.get("wt") == null) nl.add("wt", "xml");
return new LocalSolrQueryRequest(TestHarness.this.getCore(), nl);
}
}
-
-
}
diff --git a/solr/test-framework/src/test/org/apache/solr/TestLogLevelAnnotations.java b/solr/test-framework/src/test/org/apache/solr/TestLogLevelAnnotations.java
index bc5b9431095..83b2888910e 100644
--- a/solr/test-framework/src/test/org/apache/solr/TestLogLevelAnnotations.java
+++ b/solr/test-framework/src/test/org/apache/solr/TestLogLevelAnnotations.java
@@ -27,36 +27,35 @@ import org.apache.solr.util.LogLevel;
import org.junit.AfterClass;
import org.junit.BeforeClass;
-@SuppressForbidden(reason="We need to use log4J2 classes to access the log levels")
-@LogLevel("org.apache.solr.bogus_logger.ClassLogLevel=error;org.apache.solr.bogus_logger.MethodLogLevel=warn")
+@SuppressForbidden(reason = "We need to use log4J2 classes to access the log levels")
+@LogLevel(
+ "org.apache.solr.bogus_logger.ClassLogLevel=error;org.apache.solr.bogus_logger.MethodLogLevel=warn")
public class TestLogLevelAnnotations extends SolrTestCaseJ4 {
private static final String bogus_logger_prefix = "org.apache.solr.bogus_logger";
-
- /**
- * <p>
- * The default log level of the root logger when this class is loaded by the JVM, Used to validate
+
+ /**
+ * The default log level of the root logger when this class is loaded by the JVM, Used to validate
* some logger configurations when the tests are run.
- * </p>
- * <p>
- * We don't want a hardcoded assumption here because it may change based on how the user runs the test.
- * </p>
- * <p>
- * We also don't want to initialize this in a <code>@BeforeClass</code> method because that will run
- * <em>after</em> the <code>@BeforeClass</code> logic of our super class {@link SolrTestCaseJ4}
- * where the <code>@LogLevel</code> annotation on this class will be parsed and evaluated -- modifying the
- * log4j run time configuration.
- * There is no reason why the <code>@LogLevel</code> configuration of this class <em>should</em> affect
- * the "root" Logger, but setting this in static class initialization protect us (as best we can)
- * against the possibility that it <em>might</em> due to an unforseen (future) bug.
- * </p>
+ *
+ * <p>We don't want a hardcoded assumption here because it may change based on how the user runs
+ * the test.
+ *
+ * <p>We also don't want to initialize this in a <code>@BeforeClass</code> method because that
+ * will run <em>after</em> the <code>@BeforeClass</code> logic of our super class {@link
+ * SolrTestCaseJ4} where the <code>@LogLevel</code> annotation on this class will be parsed and
+ * evaluated -- modifying the log4j run time configuration. The <code>@LogLevel</code>
+ * configuration of this class <em>should</em> not affect the "root" Logger, but setting this in
+ * static class initialization protect us (as best we can) against the possibility that it
+ * <em>might</em> due to an unforseen (future) bug.
*
* @see #checkLogLevelsBeforeClass
*/
public static final Level DEFAULT_LOG_LEVEL = LogManager.getRootLogger().getLevel();
-
- /**
- * Sanity check that our <code>AfterClass</code> logic is valid, and isn't broken right from the start
+
+ /**
+ * Sanity check that our <code>AfterClass</code> logic is valid, and isn't broken right from the
+ * start
*
* @see #checkLogLevelsAfterClass
*/
@@ -65,31 +64,38 @@ public class TestLogLevelAnnotations extends SolrTestCaseJ4 {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
- // NOTE: we're checking the CONFIGURATION of the loggers, not the "effective" value of the Logger
- assertEquals("Somehow, the configured value of the root logger changed since this class was loaded",
- DEFAULT_LOG_LEVEL, config.getRootLogger().getLevel());
- assertEquals("Your Logger conf sets a level on a bogus package that breaks this test: "
- + bogus_logger_prefix,
- config.getRootLogger(),
- config.getLoggerConfig(bogus_logger_prefix));
- assertEquals(Level.ERROR, config.getLoggerConfig(bogus_logger_prefix + ".ClassLogLevel").getLevel());
- assertEquals(Level.WARN, config.getLoggerConfig(bogus_logger_prefix + ".MethodLogLevel").getLevel());
+ // NOTE: we're checking the CONFIGURATION of the loggers, not the "effective" value of the
+ // Logger
+ assertEquals(
+ "Somehow, the configured value of the root logger changed since this class was loaded",
+ DEFAULT_LOG_LEVEL,
+ config.getRootLogger().getLevel());
+ assertEquals(
+ "Your Logger conf sets a level on a bogus package that breaks this test: "
+ + bogus_logger_prefix,
+ config.getRootLogger(),
+ config.getLoggerConfig(bogus_logger_prefix));
+ assertEquals(
+ Level.ERROR, config.getLoggerConfig(bogus_logger_prefix + ".ClassLogLevel").getLevel());
+ assertEquals(
+ Level.WARN, config.getLoggerConfig(bogus_logger_prefix + ".MethodLogLevel").getLevel());
// Now sanity check the EFFECTIVE Level of these loggers before the methods run...
assertEquals(DEFAULT_LOG_LEVEL, LogManager.getRootLogger().getLevel());
assertEquals(DEFAULT_LOG_LEVEL, LogManager.getLogger(bogus_logger_prefix).getLevel());
- assertEquals(Level.ERROR, LogManager.getLogger(bogus_logger_prefix + ".ClassLogLevel").getLevel());
- assertEquals(Level.WARN, LogManager.getLogger(bogus_logger_prefix + ".MethodLogLevel").getLevel());
+ assertEquals(
+ Level.ERROR, LogManager.getLogger(bogus_logger_prefix + ".ClassLogLevel").getLevel());
+ assertEquals(
+ Level.WARN, LogManager.getLogger(bogus_logger_prefix + ".MethodLogLevel").getLevel());
}
- /**
+ /**
* Check that the expected log level <em>configurations</em> have been reset after the test
- * <p>
- * <b>NOTE:</b> We only validate <code>@LogLevel</code> modifications made at the
- * {@link #testMethodLogLevels} level, not at the 'class' level, because of the lifecycle of junit
- * methods: This <code>@AfterClass</code> will run before the <code>SolrTestCaseJ4</code>
- * <code>@AfterClass</code> method where the 'class' <code>@LogLevel</code> modifications will be reset.
- * </p>
+ *
+ * <p><b>NOTE:</b> We only validate <code>@LogLevel</code> modifications made at the {@link
+ * #testMethodLogLevels} level, not at the 'class' level, because of the lifecycle of junit
+ * methods: This <code>@AfterClass</code> will run before the <code>SolrTestCaseJ4#@AfterClass
+ * </code> method where the 'class' <code>@LogLevel</code> modifications will be reset.
*
* @see #checkLogLevelsBeforeClass
* @see #testWhiteBoxMethods
@@ -98,59 +104,69 @@ public class TestLogLevelAnnotations extends SolrTestCaseJ4 {
public static void checkLogLevelsAfterClass() {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
-
- // NOTE: we're checking the CONFIGURATION of the loggers, not the "effective" value of the Logger
+
+ // NOTE: we're checking the CONFIGURATION of the loggers, not the "effective" value of the
+ // Logger
assertEquals(DEFAULT_LOG_LEVEL, config.getRootLogger().getLevel());
- assertEquals(bogus_logger_prefix
- + " should have had it's config unset; should now return the 'root' LoggerConfig",
- config.getRootLogger(),
- config.getLoggerConfig(bogus_logger_prefix));
- assertEquals(Level.ERROR, config.getLoggerConfig(bogus_logger_prefix + ".ClassLogLevel").getLevel());
- assertEquals(Level.WARN, config.getLoggerConfig(bogus_logger_prefix + ".MethodLogLevel").getLevel());
+ assertEquals(
+ bogus_logger_prefix
+ + " should have had it's config unset; should now return the 'root' LoggerConfig",
+ config.getRootLogger(),
+ config.getLoggerConfig(bogus_logger_prefix));
+ assertEquals(
+ Level.ERROR, config.getLoggerConfig(bogus_logger_prefix + ".ClassLogLevel").getLevel());
+ assertEquals(
+ Level.WARN, config.getLoggerConfig(bogus_logger_prefix + ".MethodLogLevel").getLevel());
// Now sanity check the EFFECTIVE Level of these loggers...
assertEquals(DEFAULT_LOG_LEVEL, LogManager.getRootLogger().getLevel());
assertEquals(DEFAULT_LOG_LEVEL, LogManager.getLogger(bogus_logger_prefix).getLevel());
- assertEquals(Level.ERROR, LogManager.getLogger(bogus_logger_prefix + ".ClassLogLevel").getLevel());
- assertEquals(Level.WARN, LogManager.getLogger(bogus_logger_prefix + ".MethodLogLevel").getLevel());
+ assertEquals(
+ Level.ERROR, LogManager.getLogger(bogus_logger_prefix + ".ClassLogLevel").getLevel());
+ assertEquals(
+ Level.WARN, LogManager.getLogger(bogus_logger_prefix + ".MethodLogLevel").getLevel());
}
-
+
public void testClassLogLevels() {
- assertEquals(DEFAULT_LOG_LEVEL, LogManager.getLogger("org.apache.solr.bogus_logger").getLevel());
- assertEquals(Level.ERROR, LogManager.getLogger(bogus_logger_prefix + ".ClassLogLevel").getLevel());
- assertEquals(Level.WARN, LogManager.getLogger(bogus_logger_prefix + ".MethodLogLevel").getLevel());
+ assertEquals(
+ DEFAULT_LOG_LEVEL, LogManager.getLogger("org.apache.solr.bogus_logger").getLevel());
+ assertEquals(
+ Level.ERROR, LogManager.getLogger(bogus_logger_prefix + ".ClassLogLevel").getLevel());
+ assertEquals(
+ Level.WARN, LogManager.getLogger(bogus_logger_prefix + ".MethodLogLevel").getLevel());
}
@LogLevel("org.apache.solr.bogus_logger.MethodLogLevel=debug;org.apache.solr.bogus_logger=INFO")
public void testMethodLogLevels() {
assertEquals(Level.INFO, LogManager.getLogger(bogus_logger_prefix + ".BogusClass").getLevel());
- assertEquals(Level.ERROR, LogManager.getLogger(bogus_logger_prefix + ".ClassLogLevel").getLevel());
- assertEquals(Level.DEBUG, LogManager.getLogger(bogus_logger_prefix + ".MethodLogLevel").getLevel());
+ assertEquals(
+ Level.ERROR, LogManager.getLogger(bogus_logger_prefix + ".ClassLogLevel").getLevel());
+ assertEquals(
+ Level.DEBUG, LogManager.getLogger(bogus_logger_prefix + ".MethodLogLevel").getLevel());
}
- /**
- * Directly test the methods in the {@link LogLevel} annotation class
- */
+ /** Directly test the methods in the {@link LogLevel} annotation class */
@LogLevel("org.apache.solr.bogus_logger.MethodLogLevel=TRACE")
public void testWhiteBoxMethods() {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
- final Map<String,Level> oldLevels = LogLevel.Configurer.setLevels(bogus_logger_prefix + "=TRACE");
+ final Map<String, Level> oldLevels =
+ LogLevel.Configurer.setLevels(bogus_logger_prefix + "=TRACE");
//
assertEquals(oldLevels.toString(), 1, oldLevels.size());
assertNull(oldLevels.get(bogus_logger_prefix));
//
assertEquals(Level.TRACE, config.getLoggerConfig(bogus_logger_prefix).getLevel());
assertEquals(Level.TRACE, LogManager.getLogger(bogus_logger_prefix).getLevel());
-
+
// restore (to 'unset' values)...
LogLevel.Configurer.restoreLogLevels(oldLevels);
- assertEquals(bogus_logger_prefix
- + " should have had it's config unset; should now return the 'root' LoggerConfig",
- config.getRootLogger(),
- config.getLoggerConfig(bogus_logger_prefix));
+ assertEquals(
+ bogus_logger_prefix
+ + " should have had it's config unset; should now return the 'root' LoggerConfig",
+ config.getRootLogger(),
+ config.getLoggerConfig(bogus_logger_prefix));
assertEquals(DEFAULT_LOG_LEVEL, LogManager.getLogger(bogus_logger_prefix).getLevel());
-
}
}
diff --git a/solr/test-framework/src/test/org/apache/solr/cloud/JettySolrRunnerTest.java b/solr/test-framework/src/test/org/apache/solr/cloud/JettySolrRunnerTest.java
index 8dd16b16654..c05d3763e99 100644
--- a/solr/test-framework/src/test/org/apache/solr/cloud/JettySolrRunnerTest.java
+++ b/solr/test-framework/src/test/org/apache/solr/cloud/JettySolrRunnerTest.java
@@ -17,25 +17,26 @@
package org.apache.solr.cloud;
+import static org.hamcrest.core.IsNot.not;
+
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
-
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.embedded.JettyConfig;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.junit.Test;
-import static org.hamcrest.core.IsNot.not;
-
public class JettySolrRunnerTest extends SolrTestCaseJ4 {
@Test
public void testRestartPorts() throws Exception {
Path solrHome = createTempDir();
- Files.write(solrHome.resolve("solr.xml"), MiniSolrCloudCluster.DEFAULT_CLOUD_SOLR_XML.getBytes(Charset.defaultCharset()));
+ Files.write(
+ solrHome.resolve("solr.xml"),
+ MiniSolrCloudCluster.DEFAULT_CLOUD_SOLR_XML.getBytes(Charset.defaultCharset()));
JettyConfig config = JettyConfig.builder().build();
@@ -49,18 +50,18 @@ public class JettySolrRunnerTest extends SolrTestCaseJ4 {
jetty.stop();
jetty.start();
- assertEquals("After restart, jetty port should be the same", usedPort, jetty.getBaseUrl().getPort());
+ assertEquals(
+ "After restart, jetty port should be the same", usedPort, jetty.getBaseUrl().getPort());
jetty.stop();
jetty.start(false);
- assertThat("After restart, jetty port should be different", jetty.getBaseUrl().getPort(), not(usedPort));
- }
- finally {
- if (jetty.isRunning())
- jetty.stop();
+ assertThat(
+ "After restart, jetty port should be different",
+ jetty.getBaseUrl().getPort(),
+ not(usedPort));
+ } finally {
+ if (jetty.isRunning()) jetty.stop();
}
-
}
-
}
diff --git a/solr/test-framework/src/test/org/apache/solr/cloud/MiniSolrCloudClusterTest.java b/solr/test-framework/src/test/org/apache/solr/cloud/MiniSolrCloudClusterTest.java
index 193e9ec2553..0c19564e3e6 100644
--- a/solr/test-framework/src/test/org/apache/solr/cloud/MiniSolrCloudClusterTest.java
+++ b/solr/test-framework/src/test/org/apache/solr/cloud/MiniSolrCloudClusterTest.java
@@ -18,13 +18,12 @@
package org.apache.solr.cloud;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;
+import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.concurrent.atomic.AtomicInteger;
import java.util.Properties;
-
-import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
+import java.util.concurrent.atomic.AtomicInteger;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.embedded.JettyConfig;
@@ -43,9 +42,9 @@ import org.junit.rules.TestRule;
public class MiniSolrCloudClusterTest extends SolrTestCaseJ4 {
@ClassRule
- public static TestRule solrClassRules = RuleChain.outerRule(
- new SystemPropertiesRestoreRule()).around(
- new RevertDefaultThreadHandlerRule());
+ public static TestRule solrClassRules =
+ RuleChain.outerRule(new SystemPropertiesRestoreRule())
+ .around(new RevertDefaultThreadHandlerRule());
@Test
public void testErrorsInStartup() throws Exception {
@@ -54,24 +53,23 @@ public class MiniSolrCloudClusterTest extends SolrTestCaseJ4 {
MiniSolrCloudCluster cluster = null;
try {
- cluster = new MiniSolrCloudCluster(3, createTempDir(), JettyConfig.builder().build()) {
- @Override
- public JettySolrRunner startJettySolrRunner(String name, String context, JettyConfig config) throws Exception {
- if (jettyIndex.incrementAndGet() != 2)
- return super.startJettySolrRunner(name, context, config);
- throw new IOException("Fake exception on startup!");
- }
- };
+ cluster =
+ new MiniSolrCloudCluster(3, createTempDir(), JettyConfig.builder().build()) {
+ @Override
+ public JettySolrRunner startJettySolrRunner(
+ String name, String context, JettyConfig config) throws Exception {
+ if (jettyIndex.incrementAndGet() != 2)
+ return super.startJettySolrRunner(name, context, config);
+ throw new IOException("Fake exception on startup!");
+ }
+ };
fail("Expected an exception to be thrown from MiniSolrCloudCluster");
- }
- catch (Exception e) {
+ } catch (Exception e) {
assertEquals("Error starting up MiniSolrCloudCluster", e.getMessage());
assertEquals("Expected one suppressed exception", 1, e.getSuppressed().length);
assertEquals("Fake exception on startup!", e.getSuppressed()[0].getMessage());
- }
- finally {
- if (cluster != null)
- cluster.shutdown();
+ } finally {
+ if (cluster != null) cluster.shutdown();
}
}
@@ -80,15 +78,16 @@ public class MiniSolrCloudClusterTest extends SolrTestCaseJ4 {
AtomicInteger jettyIndex = new AtomicInteger();
- MiniSolrCloudCluster cluster = new MiniSolrCloudCluster(3, createTempDir(), JettyConfig.builder().build()) {
- @Override
- public JettySolrRunner stopJettySolrRunner(JettySolrRunner jetty) throws Exception {
- JettySolrRunner j = super.stopJettySolrRunner(jetty);
- if (jettyIndex.incrementAndGet() == 2)
- throw new IOException("Fake IOException on shutdown!");
- return j;
- }
- };
+ MiniSolrCloudCluster cluster =
+ new MiniSolrCloudCluster(3, createTempDir(), JettyConfig.builder().build()) {
+ @Override
+ public JettySolrRunner stopJettySolrRunner(JettySolrRunner jetty) throws Exception {
+ JettySolrRunner j = super.stopJettySolrRunner(jetty);
+ if (jettyIndex.incrementAndGet() == 2)
+ throw new IOException("Fake IOException on shutdown!");
+ return j;
+ }
+ };
Exception ex = expectThrows(Exception.class, cluster::shutdown);
assertEquals("Error shutting down MiniSolrCloudCluster", ex.getMessage());
@@ -101,66 +100,83 @@ public class MiniSolrCloudClusterTest extends SolrTestCaseJ4 {
JettyConfig.Builder jettyConfig = JettyConfig.builder();
jettyConfig.waitForLoadingCoresToFinish(null);
jettyConfig.withFilter(JettySolrRunner.DebugFilter.class, "*");
- MiniSolrCloudCluster cluster = new MiniSolrCloudCluster(random().nextInt(3) + 1, createTempDir(), jettyConfig.build());
+ MiniSolrCloudCluster cluster =
+ new MiniSolrCloudCluster(random().nextInt(3) + 1, createTempDir(), jettyConfig.build());
cluster.shutdown();
}
public void testSolrHomeAndResourceLoaders() throws Exception {
final String SOLR_HOME_PROP = "solr.solr.home";
- // regardless of what sys prop may be set, everything in the cluster should use solr home dirs under the
- // configured base dir -- and nothing in the call stack should be "setting" the sys prop to make that work...
+ // regardless of what sys prop may be set, everything in the cluster should use solr home dirs
+ // under the configured base dir -- and nothing in the call stack should be "setting" the sys
+ // prop to make that work...
final String fakeSolrHome = createTempDir().toAbsolutePath().toString();
System.setProperty(SOLR_HOME_PROP, fakeSolrHome);
- // mock FS from createTempDir don't play nice using 'startsWith' when the solr stack reconsistutes the path from string
- // so we have to go the string route here as well...
+ // mock FS from createTempDir don't play nice using 'startsWith' when the solr stack
+ // reconsistutes the path from string so we have to go the string route here as well...
final Path workDir = Paths.get(createTempDir().toAbsolutePath().toString());
-
- final MiniSolrCloudCluster cluster = new MiniSolrCloudCluster(1, workDir, JettyConfig.builder().build());
+
+ final MiniSolrCloudCluster cluster =
+ new MiniSolrCloudCluster(1, workDir, JettyConfig.builder().build());
try {
final JettySolrRunner jetty = cluster.getJettySolrRunners().get(0);
- assertTrue(jetty.getCoreContainer().getSolrHome() + " vs " + workDir,
- // mock dirs from createTempDir() don't play nice with startsWith, so we have to use the string value
- Paths.get(jetty.getCoreContainer().getSolrHome()).startsWith(workDir));
- assertEquals(jetty.getCoreContainer().getSolrHome(),
- jetty.getCoreContainer().getResourceLoader().getInstancePath().toAbsolutePath().toString());
-
- assertTrue(CollectionAdminRequest.createCollection("test", 1,1).process(cluster.getSolrClient()).isSuccess());
+ assertTrue(
+ jetty.getCoreContainer().getSolrHome() + " vs " + workDir,
+ // mock dirs from createTempDir() don't play nice with startsWith, so we have to use the
+ // string value
+ Paths.get(jetty.getCoreContainer().getSolrHome()).startsWith(workDir));
+ assertEquals(
+ jetty.getCoreContainer().getSolrHome(),
+ jetty
+ .getCoreContainer()
+ .getResourceLoader()
+ .getInstancePath()
+ .toAbsolutePath()
+ .toString());
+
+ assertTrue(
+ CollectionAdminRequest.createCollection("test", 1, 1)
+ .process(cluster.getSolrClient())
+ .isSuccess());
final SolrCore core = jetty.getCoreContainer().getCores().get(0);
- assertTrue(core.getInstancePath() + " vs " + workDir,
- core.getInstancePath().startsWith(workDir));
- assertEquals(core.getInstancePath(),
- core.getResourceLoader().getInstancePath());
+ assertTrue(
+ core.getInstancePath() + " vs " + workDir, core.getInstancePath().startsWith(workDir));
+ assertEquals(core.getInstancePath(), core.getResourceLoader().getInstancePath());
} finally {
cluster.shutdown();
}
- assertEquals("There is no reason why anything should have set this sysprop",
- fakeSolrHome, System.getProperty(SOLR_HOME_PROP));
+ assertEquals(
+ "There is no reason why anything should have set this sysprop",
+ fakeSolrHome,
+ System.getProperty(SOLR_HOME_PROP));
}
-
+
public void testMultipleClustersDiffZk() throws Exception {
- final MiniSolrCloudCluster x = new MiniSolrCloudCluster(1, createTempDir(), JettyConfig.builder().build());
+ final MiniSolrCloudCluster x =
+ new MiniSolrCloudCluster(1, createTempDir(), JettyConfig.builder().build());
try {
- final MiniSolrCloudCluster y = new MiniSolrCloudCluster(1, createTempDir(), JettyConfig.builder().build());
+ final MiniSolrCloudCluster y =
+ new MiniSolrCloudCluster(1, createTempDir(), JettyConfig.builder().build());
try {
-
+
// sanity check we're not talking to ourselves
assertNotSame(x.getZkServer(), y.getZkServer());
assertNotEquals(x.getZkServer().getZkAddress(), y.getZkServer().getZkAddress());
-
+
// baseline check
assertEquals(1, x.getJettySolrRunners().size());
assertZkHost("x", x.getZkServer().getZkAddress(), x.getJettySolrRunners().get(0));
-
+
assertEquals(1, y.getJettySolrRunners().size());
assertZkHost("y", y.getZkServer().getZkAddress(), y.getJettySolrRunners().get(0));
-
+
// adding nodes should be isolated
final JettySolrRunner j2x = x.startJettySolrRunner();
assertZkHost("x2", x.getZkServer().getZkAddress(), j2x);
assertEquals(2, x.getJettySolrRunners().size());
assertEquals(1, y.getJettySolrRunners().size());
-
+
final JettySolrRunner j2y = y.startJettySolrRunner();
assertZkHost("y2", y.getZkServer().getZkAddress(), j2y);
assertEquals(2, x.getJettySolrRunners().size());
@@ -172,42 +188,49 @@ public class MiniSolrCloudClusterTest extends SolrTestCaseJ4 {
x.shutdown();
}
}
-
+
public void testJettyUsingSysProp() throws Exception {
try {
- // this cluster will use a sysprop to communicate zkHost to it's nodes -- not node props in the servlet context
- final MiniSolrCloudCluster x = new MiniSolrCloudCluster(1, createTempDir(), JettyConfig.builder().build()) {
- @Override
- public JettySolrRunner startJettySolrRunner(String name, String hostContext, JettyConfig config) throws Exception {
- System.setProperty("zkHost", getZkServer().getZkAddress());
-
- final Properties nodeProps = new Properties();
- nodeProps.setProperty("test-from-sysprop", "yup");
-
- Path runnerPath = createTempDir(name);
- JettyConfig newConfig = JettyConfig.builder(config).setContext("/blarfh").build();
- JettySolrRunner jetty = new JettySolrRunner(runnerPath.toString(), nodeProps, newConfig);
- return super.startJettySolrRunner(jetty);
- }
- };
+ // this cluster will use a sysprop to communicate zkHost to it's nodes -- not node props in
+ // the servlet context
+ final MiniSolrCloudCluster x =
+ new MiniSolrCloudCluster(1, createTempDir(), JettyConfig.builder().build()) {
+ @Override
+ public JettySolrRunner startJettySolrRunner(
+ String name, String hostContext, JettyConfig config) throws Exception {
+ System.setProperty("zkHost", getZkServer().getZkAddress());
+
+ final Properties nodeProps = new Properties();
+ nodeProps.setProperty("test-from-sysprop", "yup");
+
+ Path runnerPath = createTempDir(name);
+ JettyConfig newConfig = JettyConfig.builder(config).setContext("/blarfh").build();
+ JettySolrRunner jetty =
+ new JettySolrRunner(runnerPath.toString(), nodeProps, newConfig);
+ return super.startJettySolrRunner(jetty);
+ }
+ };
try {
// baseline check
assertEquals(1, x.getJettySolrRunners().size());
assertZkHost("x", x.getZkServer().getZkAddress(), x.getJettySolrRunners().get(0));
-
+
// verify MiniSolrCloudCluster's impl didn't change out from under us making test useless
- assertEquals("yup", x.getJettySolrRunners().get(0).getNodeProperties().getProperty("test-from-sysprop"));
+ assertEquals(
+ "yup",
+ x.getJettySolrRunners().get(0).getNodeProperties().getProperty("test-from-sysprop"));
assertNull(x.getJettySolrRunners().get(0).getNodeProperties().getProperty("zkHost"));
-
+
} finally {
x.shutdown();
}
- }finally {
+ } finally {
System.clearProperty("zkHost");
}
}
-
- private static void assertZkHost(final String msg, final String zkHost, final JettySolrRunner node) {
+
+ private static void assertZkHost(
+ final String msg, final String zkHost, final JettySolrRunner node) {
assertEquals(zkHost, node.getCoreContainer().getNodeConfig().getCloudConfig().getZkHost());
}
}
diff --git a/solr/test-framework/src/test/org/apache/solr/util/TestErrorLogMuter.java b/solr/test-framework/src/test/org/apache/solr/util/TestErrorLogMuter.java
index 961c8c8bad8..002ef355356 100644
--- a/solr/test-framework/src/test/org/apache/solr/util/TestErrorLogMuter.java
+++ b/solr/test-framework/src/test/org/apache/solr/util/TestErrorLogMuter.java
@@ -17,18 +17,17 @@
package org.apache.solr.util;
+import static org.hamcrest.core.StringContains.containsString;
+
import java.lang.invoke.MethodHandles;
import java.util.regex.Pattern;
-
-import org.apache.solr.common.util.SuppressForbidden;
import org.apache.solr.SolrTestCaseJ4;
-
+import org.apache.solr.common.util.SuppressForbidden;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.hamcrest.core.StringContains.containsString;
-
-@SuppressForbidden(reason="We need to use log4J2 classes directly to check that the ErrorLogMuter is working")
+@SuppressForbidden(
+ reason = "We need to use log4J2 classes directly to check that the ErrorLogMuter is working")
public class TestErrorLogMuter extends SolrTestCaseJ4 {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@@ -36,15 +35,15 @@ public class TestErrorLogMuter extends SolrTestCaseJ4 {
@LogLevel("=WARN")
public void testErrorMutingRegex() throws Exception {
- try (LogListener rootWarnCheck = LogListener.warn();
- LogListener rootErrorCheck = LogListener.error()) {
+ try (LogListener rootWarnCheck = LogListener.warn();
+ LogListener rootErrorCheck = LogListener.error()) {
try (ErrorLogMuter x = ErrorLogMuter.regex("eRrOr\\s+Log")) {
assertEquals(0, x.getCount());
log.error("This is an {} Log msg that x should be muted", "eRrOr");
assertEquals(1, x.getCount());
-
+
log.error("This is an {} Log msg that x should not mute", "err");
log.warn("This is an warn message, mentioning 'eRrOr Log', that should also not be muted");
assertEquals(1, x.getCount());
@@ -52,33 +51,37 @@ public class TestErrorLogMuter extends SolrTestCaseJ4 {
assertThat(rootErrorCheck.pollMessage(), containsString("should not mute"));
assertThat(rootWarnCheck.pollMessage(), containsString("also not be muted"));
- log.error("This {} because of the {} msg", "error", "thowable",
- new Exception("outer", new Exception("inner eRrOr Log throwable")));
+ log.error(
+ "This {} because of the {} msg",
+ "error",
+ "thowable",
+ new Exception("outer", new Exception("inner eRrOr Log throwable")));
assertEquals(2, x.getCount());
-
}
-
+
// the root logger must have only gotten the non-muted messages...
assertEquals(1, rootErrorCheck.getCount());
assertEquals(1, rootWarnCheck.getCount());
}
}
- @LogLevel("=WARN")
+ @LogLevel("=WARN")
public void testMultipleMuters() throws Exception {
- try (LogListener rootWarnCheck = LogListener.warn().substring("xxx");
- LogListener rootErrorCheck = LogListener.error()) {
-
+ try (LogListener rootWarnCheck = LogListener.warn().substring("xxx");
+ LogListener rootErrorCheck = LogListener.error()) {
+
// sanity check that muters "mute" in the order used...
- // (If this fails, then it means log4j has changed the precedence order it uses when addFilter is called,
- // if that happens, we'll need to change our impl to check if an impl of some special "container" Filter subclass we create.
- // is in the list of ROOT filters -- if not add one, and then "add" the specific muting filter to our "container" Filter)
+ // (If this fails, then it means log4j has changed the precedence order it uses when addFilter
+ // is called,
+ // if that happens, we'll need to change our impl to check if an impl of some special
+ // "container" Filter subclass we create.
+ // is in the list of ROOT filters -- if not add one, and then "add" the specific muting filter
+ // to our "container" Filter)
try (ErrorLogMuter x = ErrorLogMuter.substring("xxx");
- ErrorLogMuter y = ErrorLogMuter.regex(Pattern.compile("YYY", Pattern.CASE_INSENSITIVE));
- ErrorLogMuter z = ErrorLogMuter.regex("(xxx|yyy)")) {
-
-
+ ErrorLogMuter y = ErrorLogMuter.regex(Pattern.compile("YYY", Pattern.CASE_INSENSITIVE));
+ ErrorLogMuter z = ErrorLogMuter.regex("(xxx|yyy)")) {
+
log.error("xx{} ", "x");
log.error(" yyy");
log.error("xxx yyy");
@@ -86,26 +89,26 @@ public class TestErrorLogMuter extends SolrTestCaseJ4 {
// a warning shouldn't be muted...
log.warn("xxx yyy");
assertEquals(rootWarnCheck.pollMessage(), "xxx yyy");
-
+
log.error("abc", new Exception("yyy"));
-
+
assertEquals(2, x.getCount()); // x is first, so it swallows up the "x + y" message
assertEquals(2, y.getCount()); // doesn't get anything x already got
assertEquals(0, z.getCount()); // doesn't get anything x already got
}
-
+
// the root logger must have only gotten the non-muted messages...
assertEquals(1, rootWarnCheck.getCount());
assertEquals(0, rootErrorCheck.getCount());
}
}
- @LogLevel("=WARN")
+ @LogLevel("=WARN")
public void testDeprecatedBaseClassMethods() throws Exception {
// NOTE: using the same queue for both interceptors (mainly as proof that you can)
- try (LogListener rootWarnCheck = LogListener.warn();
- LogListener rootErrorCheck = LogListener.error().setQueue(rootWarnCheck.getQueue())) {
+ try (LogListener rootWarnCheck = LogListener.warn();
+ LogListener rootErrorCheck = LogListener.error().setQueue(rootWarnCheck.getQueue())) {
log.error("this matches the default ignore_exception pattern");
log.error("something matching foo that should make it"); // E1
@@ -117,7 +120,8 @@ public class TestErrorLogMuter extends SolrTestCaseJ4 {
ignoreException("ba+r");
log.error("something matching foo that should still NOT make it");
log.error("something matching baaaar that should NOT make it");
- log.warn("A warning should be fine even if it matches ignore_exception and foo and bar"); // W1
+ log.warn(
+ "A warning should be fine even if it matches ignore_exception and foo and bar"); // W1
assertEquals(1, rootErrorCheck.getCount());
assertEquals(1, rootWarnCheck.getCount());
assertThat(rootErrorCheck.pollMessage(), containsString("should be fine"));
@@ -131,11 +135,10 @@ public class TestErrorLogMuter extends SolrTestCaseJ4 {
log.error("this still matches the default ignore_exception pattern");
log.error("but something matching baaaar should make it now"); // E3
assertThat(rootErrorCheck.pollMessage(), containsString("should make it now"));
-
+
// the root logger must have only gotten the non-muted messages...
assertEquals(3, rootErrorCheck.getCount());
assertEquals(1, rootWarnCheck.getCount());
}
}
-
}
diff --git a/solr/test-framework/src/test/org/apache/solr/util/TestSSLTestConfig.java b/solr/test-framework/src/test/org/apache/solr/util/TestSSLTestConfig.java
index ed2345977c9..319f78923d8 100644
--- a/solr/test-framework/src/test/org/apache/solr/util/TestSSLTestConfig.java
+++ b/solr/test-framework/src/test/org/apache/solr/util/TestSSLTestConfig.java
@@ -19,9 +19,7 @@ package org.apache.solr.util;
import java.util.Arrays;
import java.util.List;
-
import org.apache.lucene.util.Constants;
-
import org.apache.solr.SolrTestCase;
public class TestSSLTestConfig extends SolrTestCase {
@@ -33,9 +31,10 @@ public class TestSSLTestConfig extends SolrTestCase {
final List<String> suffixes = Arrays.asList("", "+42", "-ea", "-ea+42");
// as far as we know, any Java 8, 9 or 10 impl should be fine...
- for (String base : Arrays.asList("1.8", "1.8.0", "1.8.1",
- "9", "9.0", "9.1", "9.0.0", "9.1.0", "9.1.1",
- "10", "10.0", "10.1", "10.0.0", "10.1.0", "10.1.1")) {
+ for (String base :
+ Arrays.asList(
+ "1.8", "1.8.0", "1.8.1", "9", "9.0", "9.1", "9.0.0", "9.1.0", "9.1.1", "10", "10.0",
+ "10.1", "10.0.0", "10.1.0", "10.1.1")) {
for (String suffix : suffixes) {
final String v = base + suffix;
assertFalse(v, SSLTestConfig.isOpenJdkJvmVersionKnownToHaveProblems(v));
@@ -51,7 +50,7 @@ public class TestSSLTestConfig extends SolrTestCase {
assertTrue(v, SSLTestConfig.isOpenJdkJvmVersionKnownToHaveProblems(v));
}
}
-
+
// ...but 11.0.3 or higher should be ok.
for (String ok : Arrays.asList("11.0.3", "11.0.42", "11.1", "11.1.42")) {
for (String suffix : suffixes) {
@@ -59,7 +58,7 @@ public class TestSSLTestConfig extends SolrTestCase {
assertFalse(v, SSLTestConfig.isOpenJdkJvmVersionKnownToHaveProblems(v));
}
}
-
+
// As far as we know/hope, all "official" java 12 and higher impls should be fine...
for (String major : Arrays.asList("12", "13", "99")) {
for (String minor : Arrays.asList("", ".0", ".42", ".0.42")) {
@@ -83,22 +82,23 @@ public class TestSSLTestConfig extends SolrTestCase {
final String v = "13" + suffix;
assertTrue(v, SSLTestConfig.isOpenJdkJvmVersionKnownToHaveProblems(v));
}
-
}
public void testFailIfUserRunsTestsWithJVMThatHasKnownSSLBugs() {
- // NOTE: If there is some future JVM version, where all available "ea" builds are known to be buggy,
- // but we still want to be able to use for running tests (ie: via jenkins) to look for *other* bugs,
- // then those -ea versions can be "white listed" here...
+ // NOTE: If there is some future JVM version, where all available "ea" builds are known to be
+ // buggy, but we still want to be able to use for running tests (ie: via jenkins) to look for
+ // *other* bugs, then those -ea versions can be "white listed" here...
try {
SSLTestConfig.assumeSslIsSafeToTest();
} catch (org.junit.AssumptionViolatedException ave) {
- fail("Current JVM (" + Constants.JVM_NAME + " / " + Constants.JVM_VERSION +
- ") is known to have SSL Bugs. Other tests that (explicitly or via randomization) " +
- " use SSL will be SKIPed");
+ fail(
+ "Current JVM ("
+ + Constants.JVM_NAME
+ + " / "
+ + Constants.JVM_VERSION
+ + ") is known to have SSL Bugs. Other tests that (explicitly or via randomization) "
+ + " use SSL will be SKIPed");
}
}
-
-
}