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);
}
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");
}
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")));
}
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");
}
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")));
}
Aggregations