[TEST] Close threadpool once test searchcontext is released
This commit is contained in:
parent
10cfc2fa0b
commit
a9abf18235
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue