[TEST] Close threadpool once test searchcontext is released

This commit is contained in:
Simon Willnauer 2014-07-05 15:20:46 +02:00
parent 10cfc2fa0b
commit a9abf18235
6 changed files with 34 additions and 3 deletions

View File

@ -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);
}
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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