Search in sources :

Example 6 with NodeValidationException

use of org.elasticsearch.node.NodeValidationException in project elasticsearch by elastic.

the class BootstrapChecksTests method runMightForkTest.

private void runMightForkTest(final BootstrapChecks.MightForkCheck check, final AtomicBoolean isSystemCallFilterInstalled, final Runnable disableMightFork, final Runnable enableMightFork, final Consumer<NodeValidationException> consumer) throws NodeValidationException {
    final String methodName = Thread.currentThread().getStackTrace()[2].getMethodName();
    // if system call filter is disabled, nothing should happen
    isSystemCallFilterInstalled.set(false);
    if (randomBoolean()) {
        disableMightFork.run();
    } else {
        enableMightFork.run();
    }
    BootstrapChecks.check(true, Collections.singletonList(check), methodName);
    // if system call filter is enabled, but we will not fork, nothing should
    // happen
    isSystemCallFilterInstalled.set(true);
    disableMightFork.run();
    BootstrapChecks.check(true, Collections.singletonList(check), methodName);
    // if system call filter is enabled, and we might fork, the check should be enforced, regardless of bootstrap checks being enabled
    // or not
    isSystemCallFilterInstalled.set(true);
    enableMightFork.run();
    final NodeValidationException e = expectThrows(NodeValidationException.class, () -> BootstrapChecks.check(randomBoolean(), Collections.singletonList(check), methodName));
    consumer.accept(e);
}
Also used : NodeValidationException(org.elasticsearch.node.NodeValidationException) Matchers.hasToString(org.hamcrest.Matchers.hasToString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 7 with NodeValidationException

use of org.elasticsearch.node.NodeValidationException in project elasticsearch by elastic.

the class BootstrapChecksTests method testUseSerialGCCheck.

public void testUseSerialGCCheck() throws NodeValidationException {
    final AtomicReference<String> useSerialGC = new AtomicReference<>("true");
    final BootstrapCheck check = new BootstrapChecks.UseSerialGCCheck() {

        @Override
        String getUseSerialGC() {
            return useSerialGC.get();
        }
    };
    final NodeValidationException e = expectThrows(NodeValidationException.class, () -> BootstrapChecks.check(true, Collections.singletonList(check), "testUseSerialGCCheck"));
    assertThat(e.getMessage(), containsString("JVM is using the serial collector but should not be for the best performance; " + "" + "either it's the default for the VM [" + JvmInfo.jvmInfo().getVmName() + "] or -XX:+UseSerialGC was explicitly specified"));
    useSerialGC.set("false");
    BootstrapChecks.check(true, Collections.singletonList(check), "testUseSerialGCCheck");
}
Also used : NodeValidationException(org.elasticsearch.node.NodeValidationException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Matchers.hasToString(org.hamcrest.Matchers.hasToString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 8 with NodeValidationException

use of org.elasticsearch.node.NodeValidationException in project elasticsearch by elastic.

the class BootstrapChecksTests method testExceptionAggregation.

public void testExceptionAggregation() {
    final List<BootstrapCheck> checks = Arrays.asList(new BootstrapCheck() {

        @Override
        public boolean check() {
            return true;
        }

        @Override
        public String errorMessage() {
            return "first";
        }
    }, new BootstrapCheck() {

        @Override
        public boolean check() {
            return true;
        }

        @Override
        public String errorMessage() {
            return "second";
        }
    });
    final NodeValidationException e = expectThrows(NodeValidationException.class, () -> BootstrapChecks.check(true, checks, "testExceptionAggregation"));
    assertThat(e, hasToString(allOf(containsString("bootstrap checks failed"), containsString("first"), containsString("second"))));
    final Throwable[] suppressed = e.getSuppressed();
    assertThat(suppressed.length, equalTo(2));
    assertThat(suppressed[0], instanceOf(IllegalStateException.class));
    assertThat(suppressed[0], hasToString(containsString("first")));
    assertThat(suppressed[1], instanceOf(IllegalStateException.class));
    assertThat(suppressed[1], hasToString(containsString("second")));
}
Also used : NodeValidationException(org.elasticsearch.node.NodeValidationException) Matchers.hasToString(org.hamcrest.Matchers.hasToString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 9 with NodeValidationException

use of org.elasticsearch.node.NodeValidationException in project elasticsearch by elastic.

the class BootstrapChecksTests method testHeapSizeCheck.

public void testHeapSizeCheck() throws NodeValidationException {
    final int initial = randomIntBetween(0, Integer.MAX_VALUE - 1);
    final int max = randomIntBetween(initial + 1, Integer.MAX_VALUE);
    final AtomicLong initialHeapSize = new AtomicLong(initial);
    final AtomicLong maxHeapSize = new AtomicLong(max);
    final BootstrapChecks.HeapSizeCheck check = new BootstrapChecks.HeapSizeCheck() {

        @Override
        long getInitialHeapSize() {
            return initialHeapSize.get();
        }

        @Override
        long getMaxHeapSize() {
            return maxHeapSize.get();
        }
    };
    final NodeValidationException e = expectThrows(NodeValidationException.class, () -> BootstrapChecks.check(true, Collections.singletonList(check), "testHeapSizeCheck"));
    assertThat(e.getMessage(), containsString("initial heap size [" + initialHeapSize.get() + "] " + "not equal to maximum heap size [" + maxHeapSize.get() + "]"));
    initialHeapSize.set(maxHeapSize.get());
    BootstrapChecks.check(true, Collections.singletonList(check), "testHeapSizeCheck");
    // heap size is not available
    if (randomBoolean()) {
        initialHeapSize.set(0);
    } else {
        maxHeapSize.set(0);
    }
    BootstrapChecks.check(true, Collections.singletonList(check), "testHeapSizeCheck");
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) NodeValidationException(org.elasticsearch.node.NodeValidationException)

Example 10 with NodeValidationException

use of org.elasticsearch.node.NodeValidationException in project elasticsearch by elastic.

the class BootstrapChecksTests method testAlwaysEnforcedChecks.

public void testAlwaysEnforcedChecks() {
    final BootstrapCheck check = new BootstrapCheck() {

        @Override
        public boolean check() {
            return true;
        }

        @Override
        public String errorMessage() {
            return "error";
        }

        @Override
        public boolean alwaysEnforce() {
            return true;
        }
    };
    final NodeValidationException alwaysEnforced = expectThrows(NodeValidationException.class, () -> BootstrapChecks.check(randomBoolean(), Collections.singletonList(check), "testAlwaysEnforcedChecks"));
    assertThat(alwaysEnforced, hasToString(containsString("error")));
}
Also used : NodeValidationException(org.elasticsearch.node.NodeValidationException)

Aggregations

NodeValidationException (org.elasticsearch.node.NodeValidationException)19 Matchers.hasToString (org.hamcrest.Matchers.hasToString)6 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Logger (org.apache.logging.log4j.Logger)2 SecureSettings (org.elasticsearch.common.settings.SecureSettings)2 Settings (org.elasticsearch.common.settings.Settings)2 Node (org.elasticsearch.node.Node)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URISyntaxException (java.net.URISyntaxException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Appender (org.apache.logging.log4j.core.Appender)1 LoggerContext (org.apache.logging.log4j.core.LoggerContext)1