You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2020/07/14 15:56:41 UTC
[lucene-solr] 03/03: #143 - More test executor usage.
This is an automated email from the ASF dual-hosted git repository.
markrmiller pushed a commit to branch reference_impl
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
commit bfb4caeeae9a6f9a68099e2c59131423163ca317
Author: markrmiller@gmail.com <ma...@gmail.com>
AuthorDate: Tue Jul 14 10:55:31 2020 -0500
#143 - More test executor usage.
---
.../cloud/TestWaitForStateWithJettyShutdowns.java | 5 +-
.../CollectionsAPIAsyncDistributedZkTest.java | 2 -
.../test/org/apache/solr/core/SolrCoreTest.java | 3 --
.../solr/request/TestUnInvertedFieldException.java | 5 --
.../org/apache/solr/update/AddBlockUpdateTest.java | 2 -
.../processor/DistributedUpdateProcessorTest.java | 3 +-
.../processor/RoutedAliasUpdateProcessorTest.java | 3 +-
.../processor/TestDocBasedVersionConstraints.java | 62 +++++++++++-----------
.../TimeRoutedAliasUpdateProcessorTest.java | 52 +++++++++---------
9 files changed, 58 insertions(+), 79 deletions(-)
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestWaitForStateWithJettyShutdowns.java b/solr/core/src/test/org/apache/solr/cloud/TestWaitForStateWithJettyShutdowns.java
index 4e335f2..bbaf57f 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestWaitForStateWithJettyShutdowns.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestWaitForStateWithJettyShutdowns.java
@@ -79,8 +79,7 @@ public class TestWaitForStateWithJettyShutdowns extends SolrTestCaseJ4 {
public void testWaitForStateBeforeShutDown() throws Exception {
final String col_name = "test_col";
- final ExecutorService executor = ExecutorUtil.newMDCAwareFixedThreadPool
- (1, new SolrNamedThreadFactory("background_executor"));
+ final ExecutorService executor = testExecutor;
final MiniSolrCloudCluster cluster = new MiniSolrCloudCluster
(1, createTempDir(), buildJettyConfig("/solr"));
try {
@@ -116,7 +115,7 @@ public class TestWaitForStateWithJettyShutdowns extends SolrTestCaseJ4 {
}, null);
log.info("Awaiting latch...");
- if (! latch.await(120, TimeUnit.SECONDS)) {
+ if (! latch.await(15, TimeUnit.SECONDS)) {
fail("timed out Waiting a ridiculous amount of time for the waitForState latch -- did impl change?");
}
diff --git a/solr/core/src/test/org/apache/solr/cloud/api/collections/CollectionsAPIAsyncDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/api/collections/CollectionsAPIAsyncDistributedZkTest.java
index 96926d4..e0db8e3 100644
--- a/solr/core/src/test/org/apache/solr/cloud/api/collections/CollectionsAPIAsyncDistributedZkTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/api/collections/CollectionsAPIAsyncDistributedZkTest.java
@@ -41,8 +41,6 @@ import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.cloud.ZkStateReader;
-import org.apache.solr.common.util.ExecutorUtil;
-import org.apache.solr.common.util.SolrNamedThreadFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
diff --git a/solr/core/src/test/org/apache/solr/core/SolrCoreTest.java b/solr/core/src/test/org/apache/solr/core/SolrCoreTest.java
index 9dcc821..b56d5b9 100644
--- a/solr/core/src/test/org/apache/solr/core/SolrCoreTest.java
+++ b/solr/core/src/test/org/apache/solr/core/SolrCoreTest.java
@@ -288,9 +288,6 @@ public class SolrCoreTest extends SolrTestCaseJ4 {
// and close it when we call reload.
h.reload();
- executor.shutdown();
- executor.awaitTermination(1, TimeUnit.MINUTES);
-
// Check that all cores are closed and no searcher references are leaked.
assertTrue("SolrCore " + core + " is not closed", core.isClosed());
}
diff --git a/solr/core/src/test/org/apache/solr/request/TestUnInvertedFieldException.java b/solr/core/src/test/org/apache/solr/request/TestUnInvertedFieldException.java
index 37ae4f1..bfbdd1c 100644
--- a/solr/core/src/test/org/apache/solr/request/TestUnInvertedFieldException.java
+++ b/solr/core/src/test/org/apache/solr/request/TestUnInvertedFieldException.java
@@ -23,18 +23,13 @@ import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.apache.lucene.index.Term;
-import org.apache.lucene.util.NamedThreadFactory;
import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
-import org.apache.solr.common.util.ExecutorUtil.MDCAwareThreadPoolExecutor;
import org.apache.solr.search.SolrIndexSearcher;
import org.apache.solr.search.facet.UnInvertedField;
import org.apache.solr.util.TestInjection;
diff --git a/solr/core/src/test/org/apache/solr/update/AddBlockUpdateTest.java b/solr/core/src/test/org/apache/solr/update/AddBlockUpdateTest.java
index b4c9737..91bcbeb 100644
--- a/solr/core/src/test/org/apache/solr/update/AddBlockUpdateTest.java
+++ b/solr/core/src/test/org/apache/solr/update/AddBlockUpdateTest.java
@@ -59,14 +59,12 @@ import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.ModifiableSolrParams;
-import org.apache.solr.common.util.ExecutorUtil;
import org.apache.solr.common.util.JavaBinCodec;
import org.apache.solr.handler.loader.XMLLoader;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.rest.schema.FieldTypeXmlAdapter;
import org.apache.solr.search.SolrIndexSearcher;
-import org.apache.solr.common.util.SolrNamedThreadFactory;
import org.apache.solr.util.RefCounted;
import org.junit.After;
import org.junit.AfterClass;
diff --git a/solr/core/src/test/org/apache/solr/update/processor/DistributedUpdateProcessorTest.java b/solr/core/src/test/org/apache/solr/update/processor/DistributedUpdateProcessorTest.java
index 47a49b5..d162fa4 100644
--- a/solr/core/src/test/org/apache/solr/update/processor/DistributedUpdateProcessorTest.java
+++ b/solr/core/src/test/org/apache/solr/update/processor/DistributedUpdateProcessorTest.java
@@ -29,7 +29,6 @@ import java.util.function.Function;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.ModifiableSolrParams;
-import org.apache.solr.common.util.ExecutorUtil;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.update.AddUpdateCommand;
@@ -60,7 +59,7 @@ public class DistributedUpdateProcessorTest extends SolrTestCaseJ4 {
@BeforeClass
public static void beforeClass() throws Exception {
assumeWorkingMockito();
- executor = ExecutorUtil.newMDCAwareCachedThreadPool(getClassName());
+ executor = testExecutor;
System.setProperty("enable.update.log", "true");
initCore("solr/collection1/conf/solrconfig.xml","solr/collection1/conf/schema-minimal-with-another-uniqkey.xml");
}
diff --git a/solr/core/src/test/org/apache/solr/update/processor/RoutedAliasUpdateProcessorTest.java b/solr/core/src/test/org/apache/solr/update/processor/RoutedAliasUpdateProcessorTest.java
index 69eeadb..a694ae8 100644
--- a/solr/core/src/test/org/apache/solr/update/processor/RoutedAliasUpdateProcessorTest.java
+++ b/solr/core/src/test/org/apache/solr/update/processor/RoutedAliasUpdateProcessorTest.java
@@ -272,8 +272,7 @@ public abstract class RoutedAliasUpdateProcessorTest extends SolrCloudTestCase {
ExecutorService exec = null;
try (CloudSolrClient solrClient = getCloudSolrClient(cluster)) {
try {
- exec = ExecutorUtil.newMDCAwareFixedThreadPool(1 + random().nextInt(2),
- new SolrNamedThreadFactory(getSaferTestName()));
+ exec = testExecutor;
List<Future<UpdateResponse>> futures = new ArrayList<>(solrInputDocuments.length);
for (SolrInputDocument solrInputDocument : solrInputDocuments) {
String col = collections.get(random().nextInt(collections.size()));
diff --git a/solr/core/src/test/org/apache/solr/update/processor/TestDocBasedVersionConstraints.java b/solr/core/src/test/org/apache/solr/update/processor/TestDocBasedVersionConstraints.java
index 5132a9b..663d19d 100644
--- a/solr/core/src/test/org/apache/solr/update/processor/TestDocBasedVersionConstraints.java
+++ b/solr/core/src/test/org/apache/solr/update/processor/TestDocBasedVersionConstraints.java
@@ -445,42 +445,40 @@ public class TestDocBasedVersionConstraints extends SolrTestCaseJ4 {
public void testConcurrentAdds() throws Exception {
final int NUM_DOCS = atLeast(50);
final int MAX_CONCURENT = atLeast(10);
- ExecutorService runner = ExecutorUtil.newMDCAwareFixedThreadPool(MAX_CONCURENT, new SolrNamedThreadFactory("TestDocBasedVersionConstraints"));
+ ExecutorService runner = testExecutor;
// runner = Executors.newFixedThreadPool(1); // to test single threaded
- try {
- for (int id = 0; id < NUM_DOCS; id++) {
- final int numAdds = TestUtil.nextInt(random(), 3, MAX_CONCURENT);
- final int winner = TestUtil.nextInt(random(), 0, numAdds - 1);
- final int winnerVersion = atLeast(100);
- final boolean winnerIsDeleted = (0 == TestUtil.nextInt(random(), 0, 4));
- List<Callable<Object>> tasks = new ArrayList<>(numAdds);
- for (int variant = 0; variant < numAdds; variant++) {
- final boolean iShouldWin = (variant==winner);
- final long version = (iShouldWin ? winnerVersion
- : TestUtil.nextInt(random(), 1, winnerVersion - 1));
- if ((iShouldWin && winnerIsDeleted)
- || (!iShouldWin && 0 == TestUtil.nextInt(random(), 0, 4))) {
- tasks.add(delayedDelete(""+id, ""+version));
- } else {
- tasks.add(delayedAdd("id",""+id,"name","name"+id+"_"+variant,
- "my_version_l", ""+ version));
- }
+
+ for (int id = 0; id < NUM_DOCS; id++) {
+ final int numAdds = TestUtil.nextInt(random(), 3, MAX_CONCURENT);
+ final int winner = TestUtil.nextInt(random(), 0, numAdds - 1);
+ final int winnerVersion = atLeast(100);
+ final boolean winnerIsDeleted = (0 == TestUtil.nextInt(random(), 0, 4));
+ List<Callable<Object>> tasks = new ArrayList<>(numAdds);
+ for (int variant = 0; variant < numAdds; variant++) {
+ final boolean iShouldWin = (variant == winner);
+ final long version = (iShouldWin ? winnerVersion
+ : TestUtil.nextInt(random(), 1, winnerVersion - 1));
+ if ((iShouldWin && winnerIsDeleted)
+ || (!iShouldWin && 0 == TestUtil.nextInt(random(), 0, 4))) {
+ tasks.add(delayedDelete("" + id, "" + version));
+ } else {
+ tasks.add(delayedAdd("id", "" + id, "name", "name" + id + "_" + variant,
+ "my_version_l", "" + version));
}
- runner.invokeAll(tasks);
- final String expectedDoc = "{'id':'"+id+"','my_version_l':"+winnerVersion +
- ( ! winnerIsDeleted ? ",'name':'name"+id+"_"+winner+"'}" : "}");
-
- assertJQ(req("qt","/get", "id",""+id, "fl","id,name,my_version_l")
- , "=={'doc':" + expectedDoc + "}");
- assertU(commit());
- assertJQ(req("q","id:"+id,
- "fl","id,name,my_version_l")
- ,"/response/numFound==1"
- ,"/response/docs==["+expectedDoc+"]");
}
- } finally {
- ExecutorUtil.shutdownAndAwaitTermination(runner);
+ runner.invokeAll(tasks);
+ final String expectedDoc = "{'id':'" + id + "','my_version_l':" + winnerVersion +
+ (!winnerIsDeleted ? ",'name':'name" + id + "_" + winner + "'}" : "}");
+
+ assertJQ(req("qt", "/get", "id", "" + id, "fl", "id,name,my_version_l")
+ , "=={'doc':" + expectedDoc + "}");
+ assertU(commit());
+ assertJQ(req("q", "id:" + id,
+ "fl", "id,name,my_version_l")
+ , "/response/numFound==1"
+ , "/response/docs==[" + expectedDoc + "]");
}
+
}
public void testMissingVersionOnOldDocs() throws Exception {
diff --git a/solr/core/src/test/org/apache/solr/update/processor/TimeRoutedAliasUpdateProcessorTest.java b/solr/core/src/test/org/apache/solr/update/processor/TimeRoutedAliasUpdateProcessorTest.java
index 7f76453..6a0ff7b 100644
--- a/solr/core/src/test/org/apache/solr/update/processor/TimeRoutedAliasUpdateProcessorTest.java
+++ b/solr/core/src/test/org/apache/solr/update/processor/TimeRoutedAliasUpdateProcessorTest.java
@@ -306,38 +306,34 @@ public class TimeRoutedAliasUpdateProcessorTest extends RoutedAliasUpdateProcess
// Using threads to ensure that two TRA's are simultaneously preemptively creating and don't
// interfere with each other
- ExecutorService executorService = ExecutorUtil.newMDCAwareCachedThreadPool("TimeRoutedAliasProcessorTestx-testPreemptiveCreation");
+ ExecutorService executorService = testExecutor;
Exception[] threadExceptions = new Exception[2];
boolean[] threadStarted = new boolean[2];
boolean[] threadFinished = new boolean[2];
- try {
- CountDownLatch starter = new CountDownLatch(1);
- executorService.submit(() -> {
- threadStarted[0] = true;
- try {
- starter.await();
- concurrentUpdates(params, alias);
- } catch (Exception e) {
- threadExceptions[0] = e;
- }
- threadFinished[0] = true;
- });
-
- executorService.submit(() -> {
- threadStarted[1] = true;
- try {
- starter.await();
- concurrentUpdates(params, alias2);
- } catch (Exception e) {
- threadExceptions[1] = e;
- }
- threadFinished[1] = true;
- });
- starter.countDown();
- } finally {
- ExecutorUtil.shutdownAndAwaitTermination(executorService);
- }
+ CountDownLatch starter = new CountDownLatch(1);
+ executorService.submit(() -> {
+ threadStarted[0] = true;
+ try {
+ starter.await();
+ concurrentUpdates(params, alias);
+ } catch (Exception e) {
+ threadExceptions[0] = e;
+ }
+ threadFinished[0] = true;
+ });
+
+ executorService.submit(() -> {
+ threadStarted[1] = true;
+ try {
+ starter.await();
+ concurrentUpdates(params, alias2);
+ } catch (Exception e) {
+ threadExceptions[1] = e;
+ }
+ threadFinished[1] = true;
+ });
+ starter.countDown();
// threads are known to be terminated by now, check for exceptions
for (Exception threadException : threadExceptions) {