Introduce base test classes to share thread scope annotations

Currently we run unittests with clusters running in the background
that can potentiallly spawn threads causeing the thread leak control
to fire off in tests that don't use the test cluster. This commit
introduces some base classes for that purpose shadowning lucene test
framework classes adding the approriate ThreadScope.
This commit is contained in:
Simon Willnauer 2013-08-23 10:15:17 +02:00
parent 71ebb14b58
commit 6d49170509
17 changed files with 126 additions and 69 deletions

View File

@ -33,13 +33,13 @@ import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.PhraseQuery;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.test.integration.ElasticsearchLuceneTestCase;
import org.junit.Test;
import java.io.IOException;
public class XFastVectorHighlighterTest extends LuceneTestCase {
public class XFastVectorHighlighterTest extends ElasticsearchLuceneTestCase {
@Test
public void testLotsOfPhrases() throws IOException {

View File

@ -0,0 +1,29 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.test.integration;
import com.carrotsearch.randomizedtesting.ThreadFilter;
public class ElasticSearchThreadFilter implements ThreadFilter {
@Override
public boolean reject(Thread t) {
return true;
}
}

View File

@ -0,0 +1,34 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.test.integration;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite;
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
import org.apache.lucene.util.TimeUnits;
@ThreadLeakFilters(defaultFilters = true, filters = {ElasticSearchThreadFilter.class})
@ThreadLeakScope(Scope.NONE)
@TimeoutSuite(millis = TimeUnits.HOUR)
public class ElasticSearchTokenStreamTestCase extends BaseTokenStreamTestCase {
}

View File

@ -0,0 +1,36 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.test.integration;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
import org.apache.lucene.util.TimeUnits;
@ThreadLeakFilters(defaultFilters = true, filters = {ElasticSearchThreadFilter.class})
@ThreadLeakScope(Scope.NONE)
@TimeoutSuite(millis = TimeUnits.HOUR)
@SuppressCodecs("Lucene3x")
public class ElasticsearchLuceneTestCase extends LuceneTestCase {
}

View File

@ -18,7 +18,6 @@
*/
package org.elasticsearch.test.integration;
import com.carrotsearch.randomizedtesting.ThreadFilter;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
@ -32,7 +31,7 @@ import org.elasticsearch.common.logging.Loggers;
import java.util.Random;
import java.util.concurrent.TimeUnit;
@ThreadLeakFilters(defaultFilters = true, filters = {ElasticsearchTestCase.ElasticSearchThreadFilter.class})
@ThreadLeakFilters(defaultFilters = true, filters = {ElasticSearchThreadFilter.class})
@ThreadLeakScope(Scope.NONE)
@TimeoutSuite(millis = TimeUnits.HOUR) // timeout the suite after 1h and fail the test.
public abstract class ElasticsearchTestCase extends AbstractRandomizedTest {
@ -41,14 +40,6 @@ public abstract class ElasticsearchTestCase extends AbstractRandomizedTest {
public static final String CHILD_VM_ID = System.getProperty("junit4.childvm.id", "" + System.currentTimeMillis());
public static class ElasticSearchThreadFilter implements ThreadFilter {
@Override
public boolean reject(Thread t) {
return true;
}
}
public void awaitBusy(Predicate<?> breakPredicate) throws InterruptedException {
awaitBusy(breakPredicate, 10, TimeUnit.SECONDS);
}

View File

@ -18,7 +18,6 @@
*/
package org.elasticsearch.test.integration.search.suggest;
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
import org.apache.lucene.analysis.MockTokenizer;
import org.apache.lucene.analysis.TokenFilter;
import org.apache.lucene.analysis.TokenStream;
@ -36,13 +35,14 @@ import org.apache.lucene.util.CharsRef;
import org.apache.lucene.util.IntsRef;
import org.elasticsearch.search.suggest.completion.CompletionTokenStream;
import org.elasticsearch.search.suggest.completion.CompletionTokenStream.ByteTermAttribute;
import org.elasticsearch.test.integration.ElasticSearchTokenStreamTestCase;
import org.junit.Test;
import java.io.IOException;
import java.io.StringReader;
import java.util.Set;
public class CompletionTokenStreamTest extends BaseTokenStreamTestCase {
public class CompletionTokenStreamTest extends ElasticSearchTokenStreamTestCase {
final XAnalyzingSuggester suggester = new XAnalyzingSuggester(new SimpleAnalyzer(TEST_VERSION_CURRENT));

View File

@ -19,8 +19,6 @@
package org.elasticsearch.test.unit.common.lucene.uid;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
import com.google.common.collect.ImmutableMap;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
@ -33,13 +31,12 @@ import org.apache.lucene.index.*;
import org.apache.lucene.index.FieldInfo.IndexOptions;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
import org.elasticsearch.common.Numbers;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.lucene.uid.Versions;
import org.elasticsearch.index.mapper.internal.UidFieldMapper;
import org.elasticsearch.index.merge.policy.IndexUpgraderMergePolicy;
import org.elasticsearch.test.integration.ElasticsearchLuceneTestCase;
import org.hamcrest.MatcherAssert;
import org.junit.Test;
@ -50,9 +47,7 @@ import java.util.Map;
import static org.hamcrest.Matchers.*;
@SuppressCodecs("Lucene3x")
@ThreadLeakScope(Scope.NONE) // a thread in this JVM might be from a prev. test
public class VersionsTests extends LuceneTestCase {
public class VersionsTests extends ElasticsearchLuceneTestCase {
public static DirectoryReader reopen(DirectoryReader reader) throws IOException {
return reopen(reader, true);

View File

@ -19,20 +19,17 @@
package org.elasticsearch.test.unit.index.analysis;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.standard.StandardTokenizer;
import org.elasticsearch.index.analysis.AnalysisService;
import org.elasticsearch.index.analysis.TokenFilterFactory;
import org.elasticsearch.test.integration.ElasticSearchTokenStreamTestCase;
import org.junit.Test;
import java.io.IOException;
import java.io.StringReader;
@ThreadLeakScope(Scope.NONE)
public class CJKFilterFactoryTests extends BaseTokenStreamTestCase{
public class CJKFilterFactoryTests extends ElasticSearchTokenStreamTestCase {
private static final String RESOURCE = "org/elasticsearch/test/unit/index/analysis/cjk_analysis.json";

View File

@ -18,9 +18,6 @@
*/
package org.elasticsearch.test.unit.index.analysis;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.inject.ModulesBuilder;
import org.elasticsearch.common.settings.Settings;
@ -35,14 +32,14 @@ import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.settings.IndexSettingsModule;
import org.elasticsearch.indices.analysis.IndicesAnalysisModule;
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
import org.elasticsearch.test.integration.ElasticSearchTokenStreamTestCase;
import org.junit.Test;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
/**
*/
@ThreadLeakScope(Scope.NONE)
public class CharFilterTests extends BaseTokenStreamTestCase{
public class CharFilterTests extends ElasticSearchTokenStreamTestCase {
@Test
public void testMappingCharFilter() throws Exception {

View File

@ -19,9 +19,6 @@
package org.elasticsearch.test.unit.index.analysis;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.core.WhitespaceTokenizer;
import org.elasticsearch.ElasticSearchIllegalArgumentException;
@ -30,6 +27,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.analysis.AnalysisService;
import org.elasticsearch.index.analysis.KeepWordFilterFactory;
import org.elasticsearch.index.analysis.TokenFilterFactory;
import org.elasticsearch.test.integration.ElasticSearchTokenStreamTestCase;
import org.junit.Assert;
import org.junit.Test;
@ -38,8 +36,7 @@ import java.io.StringReader;
import static org.hamcrest.Matchers.instanceOf;
@ThreadLeakScope(Scope.NONE)
public class KeepFilterFactoryTests extends BaseTokenStreamTestCase {
public class KeepFilterFactoryTests extends ElasticSearchTokenStreamTestCase {
private static final String RESOURCE = "org/elasticsearch/test/unit/index/analysis/keep_analysis.json";

View File

@ -19,22 +19,19 @@
package org.elasticsearch.test.unit.index.analysis;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.core.WhitespaceTokenizer;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.analysis.AnalysisService;
import org.elasticsearch.index.analysis.TokenFilterFactory;
import org.elasticsearch.test.integration.ElasticSearchTokenStreamTestCase;
import org.junit.Test;
import java.io.IOException;
import java.io.StringReader;
@ThreadLeakScope(Scope.NONE)
public class LimitTokenCountFilterFactoryTests extends BaseTokenStreamTestCase {
public class LimitTokenCountFilterFactoryTests extends ElasticSearchTokenStreamTestCase {
@Test
public void testDefault() throws IOException {

View File

@ -19,9 +19,6 @@
package org.elasticsearch.test.unit.index.analysis;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
import org.apache.lucene.analysis.MockTokenizer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.Tokenizer;
@ -37,6 +34,7 @@ import org.elasticsearch.index.Index;
import org.elasticsearch.index.analysis.EdgeNGramTokenFilterFactory;
import org.elasticsearch.index.analysis.EdgeNGramTokenizerFactory;
import org.elasticsearch.index.analysis.NGramTokenizerFactory;
import org.elasticsearch.test.integration.ElasticSearchTokenStreamTestCase;
import org.junit.Test;
import java.io.IOException;
@ -50,8 +48,7 @@ import java.util.Random;
import static org.hamcrest.Matchers.instanceOf;
@ThreadLeakScope(Scope.NONE)
public class NGramTokenizerFactoryTests extends BaseTokenStreamTestCase {
public class NGramTokenizerFactoryTests extends ElasticSearchTokenStreamTestCase {
@Test
public void testParseTokenChars() {

View File

@ -19,9 +19,6 @@
package org.elasticsearch.test.unit.index.analysis;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.inject.ModulesBuilder;
import org.elasticsearch.common.settings.Settings;
@ -36,12 +33,12 @@ import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.settings.IndexSettingsModule;
import org.elasticsearch.indices.analysis.IndicesAnalysisModule;
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
import org.elasticsearch.test.integration.ElasticSearchTokenStreamTestCase;
import org.junit.Test;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
@ThreadLeakScope(Scope.NONE)
public class PatternCaptureTokenFilterTests extends BaseTokenStreamTestCase{
public class PatternCaptureTokenFilterTests extends ElasticSearchTokenStreamTestCase {
@Test
public void testPatternCaptureTokenFilter() throws Exception {

View File

@ -21,12 +21,12 @@ package org.elasticsearch.test.unit.index.analysis;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.core.WhitespaceTokenizer;
import org.elasticsearch.index.analysis.AnalysisService;
import org.elasticsearch.index.analysis.ShingleTokenFilterFactory;
import org.elasticsearch.index.analysis.TokenFilterFactory;
import org.elasticsearch.test.integration.ElasticSearchTokenStreamTestCase;
import org.junit.Test;
import java.io.IOException;
@ -35,7 +35,7 @@ import java.io.StringReader;
import static org.hamcrest.Matchers.instanceOf;
@ThreadLeakScope(Scope.NONE)
public class ShingleTokenFilterFactoryTests extends BaseTokenStreamTestCase{
public class ShingleTokenFilterFactoryTests extends ElasticSearchTokenStreamTestCase {
private static final String RESOURCE = "org/elasticsearch/test/unit/index/analysis/shingle_analysis.json";

View File

@ -19,9 +19,6 @@
package org.elasticsearch.test.unit.index.analysis;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.inject.ModulesBuilder;
import org.elasticsearch.common.settings.Settings;
@ -36,12 +33,12 @@ import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.settings.IndexSettingsModule;
import org.elasticsearch.indices.analysis.IndicesAnalysisModule;
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
import org.elasticsearch.test.integration.ElasticSearchTokenStreamTestCase;
import org.junit.Test;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
@ThreadLeakScope(Scope.NONE)
public class StopAnalyzerTests extends BaseTokenStreamTestCase {
public class StopAnalyzerTests extends ElasticSearchTokenStreamTestCase {
@Test
public void testDefaultsCompoundAnalysis() throws Exception {

View File

@ -19,13 +19,11 @@
package org.elasticsearch.test.unit.index.analysis;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.core.WhitespaceTokenizer;
import org.elasticsearch.index.analysis.AnalysisService;
import org.elasticsearch.index.analysis.TokenFilterFactory;
import org.elasticsearch.test.integration.ElasticSearchTokenStreamTestCase;
import org.junit.Test;
import java.io.IOException;
@ -33,8 +31,7 @@ import java.io.StringReader;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
@ThreadLeakScope(Scope.NONE)
public class WordDelimiterTokenFilterFactoryTests extends BaseTokenStreamTestCase {
public class WordDelimiterTokenFilterFactoryTests extends ElasticSearchTokenStreamTestCase {
@Test
public void testDefault() throws IOException {

View File

@ -19,10 +19,7 @@
package org.elasticsearch.test.unit.index.analysis.commongrams;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.core.WhitespaceTokenizer;
import org.elasticsearch.ElasticSearchIllegalArgumentException;
@ -30,6 +27,7 @@ import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.analysis.AnalysisService;
import org.elasticsearch.index.analysis.TokenFilterFactory;
import org.elasticsearch.test.integration.ElasticSearchTokenStreamTestCase;
import org.elasticsearch.test.unit.index.analysis.AnalysisTestsHelper;
import org.junit.Assert;
import org.junit.Test;
@ -38,9 +36,7 @@ import java.io.IOException;
import java.io.StringReader;
import static org.hamcrest.Matchers.instanceOf;
@ThreadLeakScope(Scope.NONE)
public class CommonGramsTokenFilterFactoryTests extends BaseTokenStreamTestCase {
public class CommonGramsTokenFilterFactoryTests extends ElasticSearchTokenStreamTestCase {
@Test
public void testDefault() throws IOException {