From a9abf18235e698c75bb97b14f0ba39303f7522e7 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Sat, 5 Jul 2014 15:20:46 +0200 Subject: [PATCH] [TEST] Close threadpool once test searchcontext is released --- .../child/ChildrenConstantScoreQueryTests.java | 5 ++++- .../index/search/child/ChildrenQueryTests.java | 3 +++ .../child/ParentConstantScoreQueryTests.java | 3 +++ .../index/search/child/ParentQueryTests.java | 3 +++ .../index/search/child/TestSearchContext.java | 18 ++++++++++++++++-- .../search/child/TopChildrenQueryTests.java | 5 +++++ 6 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQueryTests.java b/src/test/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQueryTests.java index 25e4c495c6e..e8e6ea6f5ff 100644 --- a/src/test/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQueryTests.java +++ b/src/test/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQueryTests.java @@ -34,6 +34,7 @@ import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.cache.recycler.PageCacheRecycler; import org.elasticsearch.common.compress.CompressedString; +import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.lucene.search.NotFilter; import org.elasticsearch.common.lucene.search.XConstantScoreQuery; import org.elasticsearch.common.lucene.search.XFilteredQuery; @@ -84,7 +85,9 @@ public class ChildrenConstantScoreQueryTests extends ElasticsearchLuceneTestCase @AfterClass public static void after() throws IOException { + SearchContext current = SearchContext.current(); SearchContext.removeCurrent(); + Releasables.close(current); } @Test @@ -365,7 +368,7 @@ public class ChildrenConstantScoreQueryTests extends ElasticsearchLuceneTestCase NodeSettingsService nodeSettingsService = new NodeSettingsService(settings); IndicesFilterCache indicesFilterCache = new IndicesFilterCache(settings, threadPool, cacheRecycler, nodeSettingsService); WeightedFilterCache filterCache = new WeightedFilterCache(index, settings, indicesFilterCache); - return new TestSearchContext(cacheRecycler, pageCacheRecycler, bigArrays, indexService, filterCache, indexFieldDataService); + return new TestSearchContext(threadPool, cacheRecycler, pageCacheRecycler, bigArrays, indexService, filterCache, indexFieldDataService); } } diff --git a/src/test/java/org/elasticsearch/index/search/child/ChildrenQueryTests.java b/src/test/java/org/elasticsearch/index/search/child/ChildrenQueryTests.java index b9d50ed54fd..d92b9417ee3 100644 --- a/src/test/java/org/elasticsearch/index/search/child/ChildrenQueryTests.java +++ b/src/test/java/org/elasticsearch/index/search/child/ChildrenQueryTests.java @@ -32,6 +32,7 @@ import org.apache.lucene.search.*; import org.apache.lucene.store.Directory; import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util.LuceneTestCase; +import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.lucene.search.NotFilter; import org.elasticsearch.common.lucene.search.XFilteredQuery; import org.elasticsearch.index.engine.Engine; @@ -68,7 +69,9 @@ public class ChildrenQueryTests extends ElasticsearchLuceneTestCase { @AfterClass public static void after() throws IOException { + SearchContext current = SearchContext.current(); SearchContext.removeCurrent(); + Releasables.close(current); } @Test diff --git a/src/test/java/org/elasticsearch/index/search/child/ParentConstantScoreQueryTests.java b/src/test/java/org/elasticsearch/index/search/child/ParentConstantScoreQueryTests.java index e43bcaa470b..a752ffbfb22 100644 --- a/src/test/java/org/elasticsearch/index/search/child/ParentConstantScoreQueryTests.java +++ b/src/test/java/org/elasticsearch/index/search/child/ParentConstantScoreQueryTests.java @@ -30,6 +30,7 @@ import org.apache.lucene.search.*; import org.apache.lucene.store.Directory; import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util.LuceneTestCase; +import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.lucene.search.NotFilter; import org.elasticsearch.common.lucene.search.XConstantScoreQuery; import org.elasticsearch.common.lucene.search.XFilteredQuery; @@ -66,7 +67,9 @@ public class ParentConstantScoreQueryTests extends ElasticsearchLuceneTestCase { @AfterClass public static void after() throws IOException { + SearchContext current = SearchContext.current(); SearchContext.removeCurrent(); + Releasables.close(current); } @Test diff --git a/src/test/java/org/elasticsearch/index/search/child/ParentQueryTests.java b/src/test/java/org/elasticsearch/index/search/child/ParentQueryTests.java index 0a9f370fb94..8c38a4a3b28 100644 --- a/src/test/java/org/elasticsearch/index/search/child/ParentQueryTests.java +++ b/src/test/java/org/elasticsearch/index/search/child/ParentQueryTests.java @@ -31,6 +31,7 @@ import org.apache.lucene.search.*; import org.apache.lucene.store.Directory; import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util.LuceneTestCase; +import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.lucene.search.NotFilter; import org.elasticsearch.common.lucene.search.XFilteredQuery; import org.elasticsearch.index.engine.Engine; @@ -66,7 +67,9 @@ public class ParentQueryTests extends ElasticsearchLuceneTestCase { @AfterClass public static void after() throws IOException { + SearchContext current = SearchContext.current(); SearchContext.removeCurrent(); + Releasables.close(current); } @Test diff --git a/src/test/java/org/elasticsearch/index/search/child/TestSearchContext.java b/src/test/java/org/elasticsearch/index/search/child/TestSearchContext.java index b50a53ef536..9a850f315b0 100644 --- a/src/test/java/org/elasticsearch/index/search/child/TestSearchContext.java +++ b/src/test/java/org/elasticsearch/index/search/child/TestSearchContext.java @@ -60,8 +60,11 @@ import org.elasticsearch.search.query.QuerySearchResult; import org.elasticsearch.search.rescore.RescoreSearchContext; import org.elasticsearch.search.scan.ScanContext; import org.elasticsearch.search.suggest.SuggestionSearchContext; +import org.elasticsearch.threadpool.ThreadPool; import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; public class TestSearchContext extends SearchContext { @@ -71,17 +74,20 @@ public class TestSearchContext extends SearchContext { final IndexService indexService; final FilterCache filterCache; final IndexFieldDataService indexFieldDataService; + final ThreadPool threadPool; + private final AtomicBoolean closed = new AtomicBoolean(false); ContextIndexSearcher searcher; int size; - public TestSearchContext(CacheRecycler cacheRecycler, PageCacheRecycler pageCacheRecycler, BigArrays bigArrays, IndexService indexService, FilterCache filterCache, IndexFieldDataService indexFieldDataService) { + public TestSearchContext(ThreadPool threadPool, CacheRecycler cacheRecycler, PageCacheRecycler pageCacheRecycler, BigArrays bigArrays, IndexService indexService, FilterCache filterCache, IndexFieldDataService indexFieldDataService) { this.cacheRecycler = cacheRecycler; this.pageCacheRecycler = pageCacheRecycler; this.bigArrays = bigArrays; this.indexService = indexService; this.filterCache = filterCache; this.indexFieldDataService = indexFieldDataService; + this.threadPool = threadPool; } public TestSearchContext() { @@ -91,6 +97,7 @@ public class TestSearchContext extends SearchContext { this.indexService = null; this.filterCache = null; this.indexFieldDataService = null; + this.threadPool = null; } @Override @@ -577,7 +584,14 @@ public class TestSearchContext extends SearchContext { @Override public void doClose() throws ElasticsearchException { - // no-op + if (closed.compareAndSet(false, true)) { + threadPool.shutdownNow(); + try { + threadPool.awaitTermination(10, TimeUnit.SECONDS); + } catch (InterruptedException e) { + Thread.interrupted(); + } + } } @Override diff --git a/src/test/java/org/elasticsearch/index/search/child/TopChildrenQueryTests.java b/src/test/java/org/elasticsearch/index/search/child/TopChildrenQueryTests.java index 2e398d7873e..01204228b54 100644 --- a/src/test/java/org/elasticsearch/index/search/child/TopChildrenQueryTests.java +++ b/src/test/java/org/elasticsearch/index/search/child/TopChildrenQueryTests.java @@ -23,6 +23,9 @@ import org.apache.lucene.index.Term; import org.apache.lucene.search.Query; import org.apache.lucene.search.QueryUtils; import org.apache.lucene.search.TermQuery; +import org.apache.lucene.util.IOUtils; +import org.elasticsearch.common.lease.Releasable; +import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.index.fielddata.plain.ParentChildIndexFieldData; import org.elasticsearch.index.mapper.internal.ParentFieldMapper; import org.elasticsearch.index.search.nested.NonNestedDocsFilter; @@ -48,7 +51,9 @@ public class TopChildrenQueryTests extends ElasticsearchLuceneTestCase { @AfterClass public static void after() throws IOException { + SearchContext current = SearchContext.current(); SearchContext.removeCurrent(); + Releasables.close(current); } @Test