Tests: thread leaks detected

* exclude *StarndaloneTest*.class from test target
* add cleanup to MultifieldAttachementMapperTests for terminating ThreadPool
* Modify MapperTestUtils.newMapperService for adding ThreadPool

Closes #88
This commit is contained in:
Jun Ohtani 2014-11-03 02:20:11 +09:00
parent d3f2df6d62
commit 94880aae3e
3 changed files with 16 additions and 5 deletions

View File

@ -226,6 +226,7 @@
<excludes>
<exclude>**/Abstract*.class</exclude>
<exclude>**/*StressTest.class</exclude>
<exclude>**/*StandaloneTest*.class</exclude>
</excludes>
<jvmArgs>
<param>-Xmx512m</param>

View File

@ -48,16 +48,16 @@ import org.elasticsearch.threadpool.ThreadPool;
public class MapperTestUtils {
public static MapperService newMapperService() {
public static MapperService newMapperService(ThreadPool testingThreadPool) {
return newMapperService(new Index("test"), ImmutableSettings.builder()
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
.build());
.build(), testingThreadPool);
}
public static MapperService newMapperService(Index index, Settings indexSettings) {
public static MapperService newMapperService(Index index, Settings indexSettings, ThreadPool testingThreadPool) {
NoneCircuitBreakerService circuitBreakerService = new NoneCircuitBreakerService();
return new MapperService(index, indexSettings, new Environment(), newAnalysisService(), new IndexFieldDataService(index, ImmutableSettings.Builder.EMPTY_SETTINGS,
new IndicesFieldDataCache(ImmutableSettings.Builder.EMPTY_SETTINGS, new IndicesFieldDataCacheListener(circuitBreakerService), new ThreadPool("testing-only")),
new IndicesFieldDataCache(ImmutableSettings.Builder.EMPTY_SETTINGS, new IndicesFieldDataCacheListener(circuitBreakerService), testingThreadPool),
circuitBreakerService),
new PostingsFormatService(index), new DocValuesFormatService(index), newSimilarityLookupService(), null);
}

View File

@ -29,6 +29,8 @@ import org.elasticsearch.index.mapper.attachment.AttachmentMapper;
import org.elasticsearch.index.mapper.core.DateFieldMapper;
import org.elasticsearch.index.mapper.core.StringFieldMapper;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -41,11 +43,18 @@ import static org.hamcrest.Matchers.*;
public class MultifieldAttachmentMapperTests extends ElasticsearchTestCase {
private DocumentMapperParser mapperParser;
private ThreadPool threadPool;
@Before
public void setupMapperParser() {
mapperParser = MapperTestUtils.newMapperParser();
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
}
@After
public void cleanup() throws InterruptedException {
terminate(threadPool);
}
@Test
@ -83,8 +92,9 @@ public class MultifieldAttachmentMapperTests extends ElasticsearchTestCase {
String forcedName = "dummyname.txt";
String bytes = Base64.encodeBytes(originalText.getBytes());
threadPool = new ThreadPool("testing-only");
MapperService mapperService = MapperTestUtils.newMapperService();
MapperService mapperService = MapperTestUtils.newMapperService(threadPool);
mapperService.documentMapperParser().putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multifield/multifield-mapping.json");