use of org.elasticsearch.common.logging.DeprecationLogger in project elasticsearch by elastic.
the class SettingsTests method testValidLenientBooleanForCurrentIndexVersion.
//#getAsBooleanLenientForPreEs6Indices is the test subject
@SuppressWarnings("deprecation")
public void testValidLenientBooleanForCurrentIndexVersion() {
Settings settings = Settings.builder().put("foo", "false").put("bar", "true").build();
final DeprecationLogger deprecationLogger = new DeprecationLogger(ESLoggerFactory.getLogger("testValidLenientBooleanForCurrentIndexVersion"));
assertFalse(settings.getAsBooleanLenientForPreEs6Indices(Version.CURRENT, "foo", null, deprecationLogger));
assertTrue(settings.getAsBooleanLenientForPreEs6Indices(Version.CURRENT, "bar", null, deprecationLogger));
assertTrue(settings.getAsBooleanLenientForPreEs6Indices(Version.CURRENT, "baz", true, deprecationLogger));
}
use of org.elasticsearch.common.logging.DeprecationLogger in project elasticsearch by elastic.
the class SettingsTests method testInvalidLenientBooleanForCurrentIndexVersion.
//#getAsBooleanLenientForPreEs6Indices is the test subject
@SuppressWarnings("deprecation")
public void testInvalidLenientBooleanForCurrentIndexVersion() {
String falsy = randomFrom("off", "no", "0");
String truthy = randomFrom("on", "yes", "1");
Settings settings = Settings.builder().put("foo", falsy).put("bar", truthy).build();
final DeprecationLogger deprecationLogger = new DeprecationLogger(ESLoggerFactory.getLogger("testInvalidLenientBooleanForCurrentIndexVersion"));
expectThrows(IllegalArgumentException.class, () -> settings.getAsBooleanLenientForPreEs6Indices(Version.CURRENT, "foo", null, deprecationLogger));
expectThrows(IllegalArgumentException.class, () -> settings.getAsBooleanLenientForPreEs6Indices(Version.CURRENT, "bar", null, deprecationLogger));
}
use of org.elasticsearch.common.logging.DeprecationLogger in project elasticsearch by elastic.
the class DoSection method checkWarningHeaders.
/**
* Check that the response contains only the warning headers that we expect.
*/
void checkWarningHeaders(final List<String> warningHeaders) {
final List<String> unexpected = new ArrayList<>();
final List<String> unmatched = new ArrayList<>();
final List<String> missing = new ArrayList<>();
// LinkedHashSet so that missing expected warnings come back in a predictable order which is nice for testing
final Set<String> expected = new LinkedHashSet<>(expectedWarningHeaders.stream().map(DeprecationLogger::escape).collect(Collectors.toList()));
for (final String header : warningHeaders) {
final Matcher matcher = WARNING_HEADER_PATTERN.matcher(header);
final boolean matches = matcher.matches();
if (matches) {
final String message = matcher.group(1);
if (expected.remove(message) == false) {
unexpected.add(header);
}
} else {
unmatched.add(header);
}
}
if (expected.isEmpty() == false) {
for (final String header : expected) {
missing.add(header);
}
}
if (unexpected.isEmpty() == false || unmatched.isEmpty() == false || missing.isEmpty() == false) {
final StringBuilder failureMessage = new StringBuilder();
appendBadHeaders(failureMessage, unexpected, "got unexpected warning header" + (unexpected.size() > 1 ? "s" : ""));
appendBadHeaders(failureMessage, unmatched, "got unmatched warning header" + (unmatched.size() > 1 ? "s" : ""));
appendBadHeaders(failureMessage, missing, "did not get expected warning header" + (missing.size() > 1 ? "s" : ""));
fail(failureMessage.toString());
}
}
Aggregations