Search in sources :

Example 6 with DeprecationLogger

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));
}
Also used : DeprecationLogger(org.elasticsearch.common.logging.DeprecationLogger)

Example 7 with 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));
}
Also used : Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) DeprecationLogger(org.elasticsearch.common.logging.DeprecationLogger)

Example 8 with 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());
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) DeprecationLogger(org.elasticsearch.common.logging.DeprecationLogger)

Aggregations

DeprecationLogger (org.elasticsearch.common.logging.DeprecationLogger)8 Matchers.containsString (org.hamcrest.Matchers.containsString)4 ArrayList (java.util.ArrayList)2 FakeRestRequest (org.elasticsearch.test.rest.FakeRestRequest)2 Matchers.hasToString (org.hamcrest.Matchers.hasToString)2 Collections.unmodifiableMap (java.util.Collections.unmodifiableMap)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Matcher (java.util.regex.Matcher)1 Logger (org.apache.logging.log4j.Logger)1 Version (org.elasticsearch.Version)1 Index (org.elasticsearch.index.Index)1