From 4ee7ed987e653c7bf4e5b54092b04665fed7bb80 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Tue, 24 Feb 2015 08:06:10 -0800 Subject: [PATCH] Tests: Remove thread leak filter Now that the global cluster is gone, we shoudln't need to ignore thread leaks across tests. We unfortunately still need suite level scope, since most tests are using suite scope clusters (although test clope clusters should really switch back to test scope thread leaks). closes #9843 --- .../indices/recovery/RecoverySettings.java | 1 + .../ElasticsearchPostingsFormatTest.java | 9 ------ .../index/store/DistributorDirectoryTest.java | 15 ++++++--- .../index/store/DistributorInTheWildTest.java | 3 -- .../indices/analyze/HunspellServiceTests.java | 3 ++ .../test/ElasticsearchIntegrationTest.java | 32 ++++++------------- .../test/ElasticsearchLuceneTestCase.java | 1 - .../test/ElasticsearchSingleNodeTest.java | 4 +-- .../test/ElasticsearchTestCase.java | 1 - .../ElasticsearchTokenStreamTestCase.java | 2 -- 10 files changed, 25 insertions(+), 46 deletions(-) diff --git a/src/main/java/org/elasticsearch/indices/recovery/RecoverySettings.java b/src/main/java/org/elasticsearch/indices/recovery/RecoverySettings.java index 10cb8d5a430..361c2012976 100644 --- a/src/main/java/org/elasticsearch/indices/recovery/RecoverySettings.java +++ b/src/main/java/org/elasticsearch/indices/recovery/RecoverySettings.java @@ -145,6 +145,7 @@ public class RecoverySettings extends AbstractComponent implements Closeable { @Override public void close() { ThreadPool.terminate(concurrentStreamPool, 1, TimeUnit.SECONDS); + ThreadPool.terminate(concurrentSmallFileStreamPool, 1, TimeUnit.SECONDS); } public ByteSizeValue fileChunkSize() { diff --git a/src/test/java/org/elasticsearch/index/codec/postingformat/ElasticsearchPostingsFormatTest.java b/src/test/java/org/elasticsearch/index/codec/postingformat/ElasticsearchPostingsFormatTest.java index d015aead771..58bbe5825fd 100644 --- a/src/test/java/org/elasticsearch/index/codec/postingformat/ElasticsearchPostingsFormatTest.java +++ b/src/test/java/org/elasticsearch/index/codec/postingformat/ElasticsearchPostingsFormatTest.java @@ -20,27 +20,18 @@ package org.elasticsearch.index.codec.postingformat; import com.carrotsearch.randomizedtesting.annotations.Listeners; -import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters; -import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope; import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite; import org.apache.lucene.codecs.Codec; -import org.apache.lucene.codecs.PostingsFormat; import org.apache.lucene.index.BasePostingsFormatTestCase; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.TestUtil; import org.apache.lucene.util.TimeUnits; -import org.elasticsearch.common.util.BloomFilter; -import org.elasticsearch.index.codec.postingsformat.BloomFilterPostingsFormat; -import org.elasticsearch.index.codec.postingsformat.Elasticsearch090PostingsFormat; -import org.elasticsearch.test.ElasticsearchThreadFilter; import org.elasticsearch.test.junit.listeners.ReproduceInfoPrinter; /** Runs elasticsearch postings format against lucene's standard postings format tests */ @Listeners({ ReproduceInfoPrinter.class }) -@ThreadLeakFilters(defaultFilters = true, filters = {ElasticsearchThreadFilter.class}) -@ThreadLeakScope(ThreadLeakScope.Scope.NONE) @TimeoutSuite(millis = TimeUnits.HOUR) @LuceneTestCase.SuppressSysoutChecks(bugUrl = "we log a lot on purpose") public class ElasticsearchPostingsFormatTest extends BasePostingsFormatTestCase { diff --git a/src/test/java/org/elasticsearch/index/store/DistributorDirectoryTest.java b/src/test/java/org/elasticsearch/index/store/DistributorDirectoryTest.java index bdafa2f7f05..c00e275cc17 100644 --- a/src/test/java/org/elasticsearch/index/store/DistributorDirectoryTest.java +++ b/src/test/java/org/elasticsearch/index/store/DistributorDirectoryTest.java @@ -18,20 +18,26 @@ */ package org.elasticsearch.index.store; -import com.carrotsearch.randomizedtesting.annotations.*; +import com.carrotsearch.randomizedtesting.annotations.Listeners; +import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering; +import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope; +import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite; import com.carrotsearch.randomizedtesting.generators.RandomInts; import com.carrotsearch.randomizedtesting.generators.RandomPicks; import com.google.common.collect.ImmutableSet; - import org.apache.lucene.index.IndexFileNames; -import org.apache.lucene.store.*; +import org.apache.lucene.store.BaseDirectoryTestCase; +import org.apache.lucene.store.Directory; +import org.apache.lucene.store.FilterDirectory; +import org.apache.lucene.store.IOContext; +import org.apache.lucene.store.IndexOutput; +import org.apache.lucene.store.MockDirectoryWrapper; import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.TimeUnits; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.index.store.distributor.Distributor; -import org.elasticsearch.test.ElasticsearchThreadFilter; import org.elasticsearch.test.junit.listeners.LoggingListener; import java.io.FileNotFoundException; @@ -43,7 +49,6 @@ import java.util.Collection; import java.util.HashSet; import java.util.Set; -@ThreadLeakFilters(defaultFilters = true, filters = {ElasticsearchThreadFilter.class}) @ThreadLeakScope(ThreadLeakScope.Scope.SUITE) @ThreadLeakLingering(linger = 5000) // 5 sec lingering @TimeoutSuite(millis = 5 * TimeUnits.MINUTE) diff --git a/src/test/java/org/elasticsearch/index/store/DistributorInTheWildTest.java b/src/test/java/org/elasticsearch/index/store/DistributorInTheWildTest.java index 93a7f9abbcc..6ccc3cd8696 100644 --- a/src/test/java/org/elasticsearch/index/store/DistributorInTheWildTest.java +++ b/src/test/java/org/elasticsearch/index/store/DistributorInTheWildTest.java @@ -19,7 +19,6 @@ package org.elasticsearch.index.store; import com.carrotsearch.randomizedtesting.annotations.Listeners; -import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters; import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering; import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope; import org.apache.lucene.index.DirectoryReader; @@ -32,7 +31,6 @@ import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.index.store.distributor.Distributor; -import org.elasticsearch.test.ElasticsearchThreadFilter; import org.elasticsearch.test.junit.listeners.LoggingListener; import org.junit.Before; @@ -47,7 +45,6 @@ import java.util.concurrent.ExecutorService; * hard concurrent pressure on the directory etc. to ensure DistributorDirectory is behaving ok. */ @LuceneTestCase.SuppressCodecs({ "SimpleText", "Memory", "Direct" }) -@ThreadLeakFilters(defaultFilters = true, filters = {ElasticsearchThreadFilter.class}) @ThreadLeakScope(ThreadLeakScope.Scope.SUITE) @ThreadLeakLingering(linger = 5000) // 5 sec lingering @Listeners(LoggingListener.class) diff --git a/src/test/java/org/elasticsearch/indices/analyze/HunspellServiceTests.java b/src/test/java/org/elasticsearch/indices/analyze/HunspellServiceTests.java index a865a3a5d9d..b646251f795 100644 --- a/src/test/java/org/elasticsearch/indices/analyze/HunspellServiceTests.java +++ b/src/test/java/org/elasticsearch/indices/analyze/HunspellServiceTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.indices.analyze; import org.apache.lucene.analysis.hunspell.Dictionary; +import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.common.settings.ImmutableSettings; @@ -90,6 +91,7 @@ public class HunspellServiceTests extends ElasticsearchIntegrationTest { } @Test + @LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elasticsearch/elasticsearch/issues/9849") public void testDicWithNoAff() throws Exception { Settings settings = ImmutableSettings.settingsBuilder() .put("path.conf", getResourcePath("/indices/analyze/no_aff_conf_dir")) @@ -109,6 +111,7 @@ public class HunspellServiceTests extends ElasticsearchIntegrationTest { } @Test + @LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elasticsearch/elasticsearch/issues/9849") public void testDicWithTwoAffs() throws Exception { Settings settings = ImmutableSettings.settingsBuilder() .put("path.conf", getResourcePath("/indices/analyze/two_aff_conf_dir")) diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java index 663dc3f4003..672f0d97c7c 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java @@ -118,6 +118,7 @@ import org.junit.*; import java.io.IOException; import java.io.InputStream; import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @@ -579,7 +580,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase } } - protected final void afterInternal() throws Exception { + protected final void afterInternal(boolean afterClass) throws Exception { boolean success = false; try { logger.info("[{}#{}]: cleaning up after test", getTestClass().getSimpleName(), getTestName()); @@ -596,6 +597,9 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase } ensureClusterSizeConsistency(); cluster().wipe(); // wipe after to make sure we fail in the test that didn't ack the delete + if (afterClass || currentClusterScope == Scope.TEST) { + cluster().close(); + } cluster().assertAfterTest(); } } finally { @@ -1799,7 +1803,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase @After public final void after() throws Exception { if (runTestScopeLifecycle()) { - afterInternal(); + afterInternal(false); } } @@ -1807,7 +1811,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase public static void afterClass() throws Exception { if (!runTestScopeLifecycle()) { try { - INSTANCE.afterInternal(); + INSTANCE.afterInternal(true); } finally { INSTANCE = null; } @@ -1893,25 +1897,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase } private static boolean isSuiteScopedTest(Class clazz) { - if (clazz == Object.class || clazz == ElasticsearchIntegrationTest.class) { - return false; - } - SuiteScopeTest annotation = clazz.getAnnotation(SuiteScopeTest.class); - if (annotation != null) { - return true; - } - return isSuiteScopedTest(clazz.getSuperclass()); - } - - private static boolean isSuiteScopeCluster(Class clazz) { - if (clazz == Object.class || clazz == ElasticsearchIntegrationTest.class) { - return false; - } - SuiteScopeTest annotation = clazz.getAnnotation(SuiteScopeTest.class); - if (annotation != null) { - return true; - } - return isSuiteScopedTest(clazz.getSuperclass()); + return clazz.getAnnotation(SuiteScopeTest.class) != null; } /** @@ -1921,7 +1907,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase * that is executed in a separate test instance. Variables that need to be accessible across test instances must be static. */ @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.TYPE}) + @Inherited @Ignore public @interface SuiteScopeTest { } diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchLuceneTestCase.java b/src/test/java/org/elasticsearch/test/ElasticsearchLuceneTestCase.java index 3dcda533499..d7e011d4128 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchLuceneTestCase.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchLuceneTestCase.java @@ -34,7 +34,6 @@ import org.elasticsearch.test.junit.listeners.ReproduceInfoPrinter; @Listeners({ ReproduceInfoPrinter.class }) -@ThreadLeakFilters(defaultFilters = true, filters = {ElasticsearchThreadFilter.class}) @ThreadLeakScope(Scope.SUITE) @ThreadLeakLingering(linger = 5000) // 5 sec lingering @TimeoutSuite(millis = TimeUnits.HOUR) diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchSingleNodeTest.java b/src/test/java/org/elasticsearch/test/ElasticsearchSingleNodeTest.java index c14a5271243..fe8aaa55163 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchSingleNodeTest.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchSingleNodeTest.java @@ -58,8 +58,8 @@ public abstract class ElasticsearchSingleNodeTest extends ElasticsearchTestCase private static void reset() { assert NODE != null; - node().stop(); - NODE = newNode(); + stopNode(); + startNode(); } private static void startNode() { diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java b/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java index 9fe2f877b0b..150d40435fa 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java @@ -73,7 +73,6 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAllS /** * Base testcase for randomized unit testing with Elasticsearch */ -@ThreadLeakFilters(defaultFilters = true, filters = {ElasticsearchThreadFilter.class}) @ThreadLeakScope(Scope.SUITE) @ThreadLeakLingering(linger = 5000) // 5 sec lingering @TimeoutSuite(millis = 20 * TimeUnits.MINUTE) // timeout the suite after 20min and fail the test. diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchTokenStreamTestCase.java b/src/test/java/org/elasticsearch/test/ElasticsearchTokenStreamTestCase.java index f52795a12ce..783ce9dbc00 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchTokenStreamTestCase.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchTokenStreamTestCase.java @@ -35,8 +35,6 @@ import org.elasticsearch.test.junit.listeners.ReproduceInfoPrinter; @Listeners({ ReproduceInfoPrinter.class }) -@ThreadLeakFilters(defaultFilters = true, filters = {ElasticsearchThreadFilter.class}) -@ThreadLeakScope(Scope.NONE) @TimeoutSuite(millis = TimeUnits.HOUR) @LuceneTestCase.SuppressSysoutChecks(bugUrl = "we log a lot on purpose") /**