From 28b771f5db0d4a14e602f006fadfebc1c0c29d5f Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Wed, 27 Feb 2019 09:38:47 +0100 Subject: [PATCH] Remove Dead Code Test Infrastructure (#39192) (#39436) * Just removing some obviously unused things --- .../discovery/PeerFinderTests.java | 2 +- .../index/SearchSlowLogTests.java | 2 +- .../RemoteClusterConnectionTests.java | 6 +- .../test/AbstractQueryTestCase.java | 2 +- .../elasticsearch/test/BackgroundIndexer.java | 31 ----- .../test/ESSingleNodeTestCase.java | 4 +- .../elasticsearch/test/TestSearchContext.java | 11 +- .../test/discovery/MockZenPing.java | 110 ------------------ .../BlockClusterStateProcessing.java | 7 +- .../hamcrest/ElasticsearchAssertions.java | 12 -- .../test/store/MockFSDirectoryService.java | 2 +- .../test/transport/MockTransport.java | 2 +- .../test/transport/MockTransportService.java | 2 +- .../transport/StubbableConnectionManager.java | 3 +- 14 files changed, 12 insertions(+), 184 deletions(-) delete mode 100644 test/framework/src/main/java/org/elasticsearch/test/discovery/MockZenPing.java diff --git a/server/src/test/java/org/elasticsearch/discovery/PeerFinderTests.java b/server/src/test/java/org/elasticsearch/discovery/PeerFinderTests.java index 5ffe242dfb208..33397ae580282 100644 --- a/server/src/test/java/org/elasticsearch/discovery/PeerFinderTests.java +++ b/server/src/test/java/org/elasticsearch/discovery/PeerFinderTests.java @@ -213,7 +213,7 @@ public void setup() { ConnectionManager innerConnectionManager = new ConnectionManager(settings, capturingTransport); StubbableConnectionManager connectionManager - = new StubbableConnectionManager(innerConnectionManager, settings, capturingTransport, deterministicTaskQueue.getThreadPool()); + = new StubbableConnectionManager(innerConnectionManager, settings, capturingTransport); connectionManager.setDefaultNodeConnectedBehavior((cm, discoveryNode) -> { final boolean isConnected = connectedNodes.contains(discoveryNode); final boolean isDisconnected = disconnectedNodes.contains(discoveryNode); diff --git a/server/src/test/java/org/elasticsearch/index/SearchSlowLogTests.java b/server/src/test/java/org/elasticsearch/index/SearchSlowLogTests.java index 2389ce12f0f41..c054b2008dba6 100644 --- a/server/src/test/java/org/elasticsearch/index/SearchSlowLogTests.java +++ b/server/src/test/java/org/elasticsearch/index/SearchSlowLogTests.java @@ -55,7 +55,7 @@ public class SearchSlowLogTests extends ESSingleNodeTestCase { protected SearchContext createSearchContext(IndexService indexService) { BigArrays bigArrays = indexService.getBigArrays(); ThreadPool threadPool = indexService.getThreadPool(); - return new TestSearchContext(threadPool, bigArrays, indexService) { + return new TestSearchContext(bigArrays, indexService) { final ShardSearchRequest request = new ShardSearchRequest() { private SearchSourceBuilder searchSourceBuilder; @Override diff --git a/server/src/test/java/org/elasticsearch/transport/RemoteClusterConnectionTests.java b/server/src/test/java/org/elasticsearch/transport/RemoteClusterConnectionTests.java index 5bc683d6fd708..3af98eaaf4009 100644 --- a/server/src/test/java/org/elasticsearch/transport/RemoteClusterConnectionTests.java +++ b/server/src/test/java/org/elasticsearch/transport/RemoteClusterConnectionTests.java @@ -508,8 +508,7 @@ public void sendRequest(long requestId, String action, TransportRequest request, }; ConnectionManager delegate = new ConnectionManager(Settings.EMPTY, service.transport); - StubbableConnectionManager connectionManager = new StubbableConnectionManager(delegate, Settings.EMPTY, service.transport, - threadPool); + StubbableConnectionManager connectionManager = new StubbableConnectionManager(delegate, Settings.EMPTY, service.transport); connectionManager.addConnectBehavior(seedNode.getAddress(), (cm, discoveryNode) -> { if (discoveryNode == seedNode) { @@ -1162,8 +1161,7 @@ public void sendRequest(long requestId, String action, TransportRequest request, }; ConnectionManager delegate = new ConnectionManager(Settings.EMPTY, service.transport); - StubbableConnectionManager connectionManager = new StubbableConnectionManager(delegate, Settings.EMPTY, service.transport, - threadPool); + StubbableConnectionManager connectionManager = new StubbableConnectionManager(delegate, Settings.EMPTY, service.transport); connectionManager.addNodeConnectedBehavior(connectedNode.getAddress(), (cm, discoveryNode) -> discoveryNode.equals(connectedNode)); diff --git a/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java index a16f55e04d74a..5d88b44b21955 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java @@ -793,7 +793,7 @@ protected Query rewrite(Query query) throws IOException { return query; } - protected QueryBuilder rewriteAndFetch(QueryBuilder builder, QueryRewriteContext context) throws IOException { + protected QueryBuilder rewriteAndFetch(QueryBuilder builder, QueryRewriteContext context) { PlainActionFuture future = new PlainActionFuture<>(); Rewriteable.rewriteAndFetch(builder, context, future); return future.actionGet(); diff --git a/test/framework/src/main/java/org/elasticsearch/test/BackgroundIndexer.java b/test/framework/src/main/java/org/elasticsearch/test/BackgroundIndexer.java index ed3a836d2c506..c2e97f35faee9 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/BackgroundIndexer.java +++ b/test/framework/src/main/java/org/elasticsearch/test/BackgroundIndexer.java @@ -67,17 +67,6 @@ public class BackgroundIndexer implements AutoCloseable { volatile int minFieldSize = 10; volatile int maxFieldSize = 140; - /** - * Start indexing in the background using a random number of threads. - * - * @param index index name to index into - * @param type document type - * @param client client to use - */ - public BackgroundIndexer(String index, String type, Client client) { - this(index, type, client, -1); - } - /** * Start indexing in the background using a random number of threads. Indexing will be paused after numOfDocs docs has * been indexed. @@ -239,11 +228,6 @@ private void setBudget(int numOfDocs) { } - /** Start indexing with no limit to the number of documents */ - public void start() { - start(-1); - } - /** * Start indexing * @@ -261,11 +245,6 @@ public void pauseIndexing() { setBudget(0); } - /** Continue indexing after it has paused. No new document limit will be set */ - public void continueIndexing() { - continueIndexing(-1); - } - /** * Continue indexing after it has paused. * @@ -299,16 +278,6 @@ public void assertNoFailures() { Assert.assertThat(failures, emptyIterable()); } - /** the minimum size in code points of a payload field in the indexed documents */ - public void setMinFieldSize(int fieldSize) { - minFieldSize = fieldSize; - } - - /** the minimum size in code points of a payload field in the indexed documents */ - public void setMaxFieldSize(int fieldSize) { - maxFieldSize = fieldSize; - } - public void setAssertNoFailuresOnStop(final boolean assertNoFailuresOnStop) { this.assertNoFailuresOnStop = assertNoFailuresOnStop; } diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java index 9ac74c29c1ef3..4d8f9fed51b24 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java @@ -51,7 +51,6 @@ import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.ScriptService; import org.elasticsearch.search.internal.SearchContext; -import org.elasticsearch.threadpool.ThreadPool; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -312,8 +311,7 @@ public Index resolveIndex(String index) { */ protected SearchContext createSearchContext(IndexService indexService) { BigArrays bigArrays = indexService.getBigArrays(); - ThreadPool threadPool = indexService.getThreadPool(); - return new TestSearchContext(threadPool, bigArrays, indexService); + return new TestSearchContext(bigArrays, indexService); } /** diff --git a/test/framework/src/main/java/org/elasticsearch/test/TestSearchContext.java b/test/framework/src/main/java/org/elasticsearch/test/TestSearchContext.java index bba2f1e4015a3..07b5f67db380d 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/TestSearchContext.java +++ b/test/framework/src/main/java/org/elasticsearch/test/TestSearchContext.java @@ -27,7 +27,6 @@ import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.cache.bitset.BitsetFilterCache; -import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MapperService; @@ -57,7 +56,6 @@ import org.elasticsearch.search.rescore.RescoreContext; import org.elasticsearch.search.sort.SortAndFormats; import org.elasticsearch.search.suggest.SuggestionSearchContext; -import org.elasticsearch.threadpool.ThreadPool; import java.util.Collections; import java.util.HashMap; @@ -69,7 +67,6 @@ public class TestSearchContext extends SearchContext { final BigArrays bigArrays; final IndexService indexService; final BitsetFilterCache fixedBitSetFilterCache; - final ThreadPool threadPool; final Map, Collector> queryCollectors = new HashMap<>(); final IndexShard indexShard; final QuerySearchResult queryResult = new QuerySearchResult(); @@ -92,11 +89,10 @@ public class TestSearchContext extends SearchContext { private final long originNanoTime = System.nanoTime(); private final Map searchExtBuilders = new HashMap<>(); - public TestSearchContext(ThreadPool threadPool, BigArrays bigArrays, IndexService indexService) { + public TestSearchContext(BigArrays bigArrays, IndexService indexService) { this.bigArrays = bigArrays.withCircuitBreaking(); this.indexService = indexService; this.fixedBitSetFilterCache = indexService.cache().bitsetFilterCache(); - this.threadPool = threadPool; this.indexShard = indexService.getShardOrNull(0); queryShardContext = indexService.newQueryShardContext(0, null, () -> 0L, null); } @@ -108,7 +104,6 @@ public TestSearchContext(QueryShardContext queryShardContext) { public TestSearchContext(QueryShardContext queryShardContext, IndexShard indexShard) { this.bigArrays = null; this.indexService = null; - this.threadPool = null; this.fixedBitSetFilterCache = null; this.indexShard = indexShard; this.queryShardContext = queryShardContext; @@ -267,10 +262,6 @@ public ContextIndexSearcher searcher() { return searcher; } - public void setSearcher(Engine.Searcher searcher) { - this.searcher = new ContextIndexSearcher(searcher, indexService.cache().query(), indexShard.getQueryCachingPolicy()); - } - @Override public IndexShard indexShard() { return indexShard; diff --git a/test/framework/src/main/java/org/elasticsearch/test/discovery/MockZenPing.java b/test/framework/src/main/java/org/elasticsearch/test/discovery/MockZenPing.java deleted file mode 100644 index 142e8b19a5ce3..0000000000000 --- a/test/framework/src/main/java/org/elasticsearch/test/discovery/MockZenPing.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.test.discovery; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.elasticsearch.cluster.ClusterName; -import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.util.concurrent.ConcurrentCollections; -import org.elasticsearch.discovery.zen.PingContextProvider; -import org.elasticsearch.discovery.zen.ZenPing; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.function.Consumer; - -/** - * A {@link ZenPing} implementation which returns results based on a static in-memory map. This allows pinging - * to be immediate and can be used to speed up tests. - */ -public final class MockZenPing implements ZenPing { - - private static final Logger logger = LogManager.getLogger(MockZenPing.class); - - static final Map> activeNodesPerCluster = new HashMap<>(); - - /** a set of the last discovered pings. used to throttle busy spinning where MockZenPing will keep returning the same results */ - private Set lastDiscoveredPings = null; - - private final PingContextProvider contextProvider; - - public MockZenPing(PingContextProvider contextProvider) { - this.contextProvider = contextProvider; - } - - @Override - public void start() { - synchronized (activeNodesPerCluster) { - boolean added = getActiveNodesForCurrentCluster().add(this); - assert added; - activeNodesPerCluster.notifyAll(); - } - } - - @Override - public void ping(Consumer resultsConsumer, TimeValue timeout) { - logger.info("pinging using mock zen ping"); - synchronized (activeNodesPerCluster) { - Set activeNodes = getActiveNodesForCurrentCluster(); - if (activeNodes.equals(lastDiscoveredPings)) { - try { - logger.trace("nothing has changed since the last ping. waiting for a change"); - activeNodesPerCluster.wait(timeout.millis()); - } catch (InterruptedException e) { - - } - activeNodes = getActiveNodesForCurrentCluster(); - } - lastDiscoveredPings = activeNodes; - PingCollection pingCollection = new PingCollection(); - activeNodes.stream() - .filter(p -> p != this) // remove this as pings are not expected to return the local node - .map(MockZenPing::getPingResponse) - .forEach(pingCollection::addPing); - resultsConsumer.accept(pingCollection); - } - } - - private ClusterName getClusterName() { - return contextProvider.clusterState().getClusterName(); - } - - private PingResponse getPingResponse() { - final ClusterState clusterState = contextProvider.clusterState(); - return new PingResponse(clusterState.nodes().getLocalNode(), clusterState.nodes().getMasterNode(), clusterState); - } - - private Set getActiveNodesForCurrentCluster() { - assert Thread.holdsLock(activeNodesPerCluster); - return activeNodesPerCluster.computeIfAbsent(getClusterName(), - clusterName -> ConcurrentCollections.newConcurrentSet()); - } - - @Override - public void close() { - synchronized (activeNodesPerCluster) { - boolean found = getActiveNodesForCurrentCluster().remove(this); - assert found; - activeNodesPerCluster.notifyAll(); - } - } -} diff --git a/test/framework/src/main/java/org/elasticsearch/test/disruption/BlockClusterStateProcessing.java b/test/framework/src/main/java/org/elasticsearch/test/disruption/BlockClusterStateProcessing.java index f144cb0b118a0..8494fa8ce9af3 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/disruption/BlockClusterStateProcessing.java +++ b/test/framework/src/main/java/org/elasticsearch/test/disruption/BlockClusterStateProcessing.java @@ -30,12 +30,7 @@ public class BlockClusterStateProcessing extends SingleNodeDisruption { - AtomicReference disruptionLatch = new AtomicReference<>(); - - - public BlockClusterStateProcessing(Random random) { - this(null, random); - } + private final AtomicReference disruptionLatch = new AtomicReference<>(); public BlockClusterStateProcessing(String disruptedNode, Random random) { super(random); diff --git a/test/framework/src/main/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java b/test/framework/src/main/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java index f18824b27e6c7..fdb7b8984c3b0 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java +++ b/test/framework/src/main/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java @@ -280,10 +280,6 @@ public static void assertFourthHit(SearchResponse searchResponse, Matcher matcher) { - assertSearchHit(searchResponse, 5, matcher); - } - public static void assertSearchHit(SearchResponse searchResponse, int number, Matcher matcher) { assertThat(number, greaterThan(0)); assertThat("SearchHit number must be greater than 0", number, greaterThan(0)); @@ -657,14 +653,6 @@ public static void assertFileNotExists(Path file) { assertThat("file/dir [" + file + "] should not exist.", Files.exists(file), is(false)); } - /** - * Check if a directory exists - */ - public static void assertDirectoryExists(Path dir) { - assertFileExists(dir); - assertThat("file [" + dir + "] should be a directory.", Files.isDirectory(dir), is(true)); - } - /** * Asserts that the provided {@link BytesReference}s created through * {@link org.elasticsearch.common.xcontent.ToXContent#toXContent(XContentBuilder, ToXContent.Params)} hold the same content. diff --git a/test/framework/src/main/java/org/elasticsearch/test/store/MockFSDirectoryService.java b/test/framework/src/main/java/org/elasticsearch/test/store/MockFSDirectoryService.java index 070343bf68785..c067c1aabd85b 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/store/MockFSDirectoryService.java +++ b/test/framework/src/main/java/org/elasticsearch/test/store/MockFSDirectoryService.java @@ -181,7 +181,7 @@ public synchronized void crash() throws IOException { } } - final class CloseableDirectory implements Closeable { + static final class CloseableDirectory implements Closeable { private final BaseDirectoryWrapper dir; private final TestRuleMarkFailure failureMarker; diff --git a/test/framework/src/main/java/org/elasticsearch/test/transport/MockTransport.java b/test/framework/src/main/java/org/elasticsearch/test/transport/MockTransport.java index e39f5d03cba07..52ba7efa3fa41 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/transport/MockTransport.java +++ b/test/framework/src/main/java/org/elasticsearch/test/transport/MockTransport.java @@ -81,7 +81,7 @@ public TransportService createTransportService(Settings settings, ThreadPool thr Function localNodeFactory, @Nullable ClusterSettings clusterSettings, Set taskHeaders) { StubbableConnectionManager connectionManager = new StubbableConnectionManager(new ConnectionManager(settings, this), - settings, this, threadPool); + settings, this); connectionManager.setDefaultNodeConnectedBehavior((cm, discoveryNode) -> nodeConnected(discoveryNode)); connectionManager.setDefaultGetConnectionBehavior((cm, discoveryNode) -> createConnection(discoveryNode)); return new TransportService(settings, this, threadPool, interceptor, localNodeFactory, clusterSettings, taskHeaders, diff --git a/test/framework/src/main/java/org/elasticsearch/test/transport/MockTransportService.java b/test/framework/src/main/java/org/elasticsearch/test/transport/MockTransportService.java index 4b998f04a568a..e72bbf3a72897 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/transport/MockTransportService.java +++ b/test/framework/src/main/java/org/elasticsearch/test/transport/MockTransportService.java @@ -157,7 +157,7 @@ private MockTransportService(Settings settings, StubbableTransport transport, Th Function localNodeFactory, @Nullable ClusterSettings clusterSettings, Set taskHeaders) { super(settings, transport, threadPool, interceptor, localNodeFactory, clusterSettings, taskHeaders, - new StubbableConnectionManager(new ConnectionManager(settings, transport), settings, transport, threadPool)); + new StubbableConnectionManager(new ConnectionManager(settings, transport), settings, transport)); this.original = transport.getDelegate(); } diff --git a/test/framework/src/main/java/org/elasticsearch/test/transport/StubbableConnectionManager.java b/test/framework/src/main/java/org/elasticsearch/test/transport/StubbableConnectionManager.java index 108e1bf5e24b5..d01b91258d576 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/transport/StubbableConnectionManager.java +++ b/test/framework/src/main/java/org/elasticsearch/test/transport/StubbableConnectionManager.java @@ -22,7 +22,6 @@ import org.elasticsearch.common.CheckedBiConsumer; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; -import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.ConnectTransportException; import org.elasticsearch.transport.ConnectionManager; import org.elasticsearch.transport.ConnectionProfile; @@ -41,7 +40,7 @@ public class StubbableConnectionManager extends ConnectionManager { private volatile GetConnectionBehavior defaultGetConnectionBehavior = ConnectionManager::getConnection; private volatile NodeConnectedBehavior defaultNodeConnectedBehavior = ConnectionManager::nodeConnected; - public StubbableConnectionManager(ConnectionManager delegate, Settings settings, Transport transport, ThreadPool threadPool) { + public StubbableConnectionManager(ConnectionManager delegate, Settings settings, Transport transport) { super(settings, transport); this.delegate = delegate; this.getConnectionBehaviors = new ConcurrentHashMap<>();