Eliminate unneccessary declaration of IOException

With this commit we remove the declaration of IOException from
assertWarnings and modify all call sites.

Checked with @javanna
This commit is contained in:
Daniel Mitterdorfer 2017-01-03 12:36:28 +01:00
parent 16d79842ac
commit 1ed64f0551
7 changed files with 27 additions and 22 deletions

View File

@ -20,15 +20,13 @@ package org.elasticsearch.common;
import org.elasticsearch.test.ESTestCase;
import java.io.IOException;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.hamcrest.collection.IsArrayContainingInAnyOrder.arrayContainingInAnyOrder;
public class ParseFieldTests extends ESTestCase {
public void testParse() throws IOException {
public void testParse() {
String name = "foo_bar";
ParseField field = new ParseField(name);
String[] deprecated = new String[]{"barFoo", "bar_foo", "Foobar"};
@ -48,7 +46,7 @@ public class ParseFieldTests extends ESTestCase {
}
}
public void testAllDeprecated() throws IOException {
public void testAllDeprecated() {
String name = "like_text";
String[] deprecated = new String[]{"text", "same_as_text"};
ParseField field = new ParseField(name).withDeprecation(deprecated).withAllDeprecated("like");

View File

@ -105,7 +105,7 @@ public class AnalysisRegistryTests extends ESTestCase {
assertTrue(e.getMessage().contains("[index.analysis.analyzer.default_index] is not supported"));
}
public void testBackCompatOverrideDefaultIndexAnalyzer() throws IOException {
public void testBackCompatOverrideDefaultIndexAnalyzer() {
Version version = VersionUtils.randomVersionBetween(random(), VersionUtils.getFirstVersion(),
VersionUtils.getPreviousVersion(Version.V_5_0_0_alpha1));
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
@ -128,7 +128,7 @@ public class AnalysisRegistryTests extends ESTestCase {
assertThat(indexAnalyzers.getDefaultSearchQuoteAnalyzer().analyzer(), instanceOf(EnglishAnalyzer.class));
}
public void testBackCompatOverrideDefaultIndexAndSearchAnalyzer() throws IOException {
public void testBackCompatOverrideDefaultIndexAndSearchAnalyzer() {
Version version = VersionUtils.randomVersionBetween(random(), VersionUtils.getFirstVersion(),
VersionUtils.getPreviousVersion(Version.V_5_0_0_alpha1));
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();

View File

@ -26,7 +26,6 @@ import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.mapper.DynamicTemplate.XContentFieldType;
import org.elasticsearch.test.ESTestCase;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@ -44,7 +43,7 @@ public class DynamicTemplateTests extends ESTestCase {
assertEquals("Illegal dynamic template parameter: [random_param]", e.getMessage());
}
public void testParseUnknownMatchType() throws IOException {
public void testParseUnknownMatchType() {
Map<String, Object> templateDef = new HashMap<>();
templateDef.put("match_mapping_type", "short");
templateDef.put("mapping", Collections.singletonMap("store", true));

View File

@ -160,7 +160,7 @@ public class MapperServiceTests extends ESSingleNodeTestCase {
assertThat(e.getMessage(), containsString("Limit of mapping depth [1] in index [test1] has been exceeded"));
}
public void testUnmappedFieldType() throws IOException {
public void testUnmappedFieldType() {
MapperService mapperService = createIndex("index").mapperService();
assertThat(mapperService.unmappedFieldType("keyword"), instanceOf(KeywordFieldType.class));
assertThat(mapperService.unmappedFieldType("long"), instanceOf(NumberFieldType.class));

View File

@ -63,7 +63,7 @@ public class TemplateQueryBuilderTests extends AbstractQueryTestCase<TemplateQue
* Instead of having to check them in every single test, we do it after each test is run
*/
@After
public void checkWarning() throws IOException {
public void checkWarning() {
assertWarnings("[template] query is deprecated, use search template api instead");
}

View File

@ -27,7 +27,7 @@ import java.io.IOException;
public class FileBasedDiscoveryPluginTests extends ESTestCase {
public void testHostsProviderBwc() throws IOException {
public void testHostsProviderBwc() {
FileBasedDiscoveryPlugin plugin = new FileBasedDiscoveryPlugin(Settings.EMPTY);
Settings additionalSettings = plugin.additionalSettings();
assertEquals("file", additionalSettings.get(DiscoveryModule.DISCOVERY_HOSTS_PROVIDER_SETTING.getKey()));
@ -35,11 +35,11 @@ public class FileBasedDiscoveryPluginTests extends ESTestCase {
"Set \"discovery.zen.hosts_provider: file\" instead");
}
public void testHostsProviderExplicit() throws IOException {
public void testHostsProviderExplicit() {
Settings settings = Settings.builder().put(DiscoveryModule.DISCOVERY_HOSTS_PROVIDER_SETTING.getKey(), "foo").build();
FileBasedDiscoveryPlugin plugin = new FileBasedDiscoveryPlugin(settings);
assertEquals(Settings.EMPTY, plugin.additionalSettings());
assertWarnings("Using discovery.type setting to set hosts provider is deprecated. " +
"Set \"discovery.zen.hosts_provider: file\" instead");
}
}
}

View File

@ -48,7 +48,6 @@ import org.elasticsearch.bootstrap.BootstrapForTesting;
import org.elasticsearch.client.Requests;
import org.elasticsearch.cluster.ClusterModule;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.io.PathUtilsForTesting;
@ -295,12 +294,11 @@ public abstract class ESTestCase extends LuceneTestCase {
final List<String> warnings = threadContext.getResponseHeaders().get(DeprecationLogger.WARNING_HEADER);
assertNull("unexpected warning headers", warnings);
} finally {
DeprecationLogger.removeThreadContext(this.threadContext);
this.threadContext.close();
resetDeprecationLogger();
}
}
protected final void assertWarnings(String... expectedWarnings) throws IOException {
protected final void assertWarnings(String... expectedWarnings) {
if (enableWarningsCheck() == false) {
throw new IllegalStateException("unable to check warning headers if the test is not set to do so");
}
@ -313,14 +311,24 @@ public abstract class ESTestCase extends LuceneTestCase {
assertThat(actualWarnings, hasItem(equalTo(msg)));
}
} finally {
// "clear" current warning headers by setting a new ThreadContext
DeprecationLogger.removeThreadContext(this.threadContext);
this.threadContext.close();
this.threadContext = new ThreadContext(Settings.EMPTY);
DeprecationLogger.setThreadContext(this.threadContext);
resetDeprecationLogger();
}
}
private void resetDeprecationLogger() {
// "clear" current warning headers by setting a new ThreadContext
DeprecationLogger.removeThreadContext(this.threadContext);
try {
this.threadContext.close();
// catch IOException to avoid that call sites have to deal with it. It is only declared because this class implements Closeable
// but it is impossible that this implementation will ever throw an IOException.
} catch (IOException ex) {
throw new AssertionError("IOException thrown while closing deprecation logger's thread context", ex);
}
this.threadContext = new ThreadContext(Settings.EMPTY);
DeprecationLogger.setThreadContext(this.threadContext);
}
private static final List<StatusData> statusData = new ArrayList<>();
static {
// ensure that the status logger is set to the warn level so we do not miss any warnings with our Log4j usage