use of org.opensearch.common.util.concurrent.AbstractRunnable in project OpenSearch by opensearch-project.
the class RecoveryIT method asyncIndexDocs.
private Future<Void> asyncIndexDocs(String index, final int idStart, final int numDocs) throws IOException {
PlainActionFuture<Void> future = new PlainActionFuture<>();
Thread background = new Thread(new AbstractRunnable() {
@Override
public void onFailure(Exception e) {
future.onFailure(e);
}
@Override
protected void doRun() throws Exception {
indexDocs(index, idStart, numDocs);
future.onResponse(null);
}
});
background.start();
return future;
}
use of org.opensearch.common.util.concurrent.AbstractRunnable in project OpenSearch by opensearch-project.
the class FollowersChecker method handleFollowerCheck.
private void handleFollowerCheck(FollowerCheckRequest request, TransportChannel transportChannel) throws IOException {
final StatusInfo statusInfo = nodeHealthService.getHealth();
if (statusInfo.getStatus() == UNHEALTHY) {
final String message = "handleFollowerCheck: node is unhealthy [" + statusInfo.getInfo() + "], rejecting " + statusInfo.getInfo();
logger.debug(message);
throw new NodeHealthCheckFailureException(message);
}
final FastResponseState responder = this.fastResponseState;
if (responder.mode == Mode.FOLLOWER && responder.term == request.term) {
logger.trace("responding to {} on fast path", request);
transportChannel.sendResponse(Empty.INSTANCE);
return;
}
if (request.term < responder.term) {
throw new CoordinationStateRejectedException("rejecting " + request + " since local state is " + this);
}
transportService.getThreadPool().generic().execute(new AbstractRunnable() {
@Override
protected void doRun() throws IOException {
logger.trace("responding to {} on slow path", request);
try {
handleRequestAndUpdateState.accept(request);
} catch (Exception e) {
transportChannel.sendResponse(e);
return;
}
transportChannel.sendResponse(Empty.INSTANCE);
}
@Override
public void onFailure(Exception e) {
logger.debug(new ParameterizedMessage("exception while responding to {}", request), e);
}
@Override
public String toString() {
return "slow path response to " + request;
}
});
}
use of org.opensearch.common.util.concurrent.AbstractRunnable in project OpenSearch by opensearch-project.
the class NioSelectorTests method executeOnNewThread.
private static void executeOnNewThread(CheckedRunnable<Exception> runnable) throws InterruptedException {
final Thread thread = new Thread(new AbstractRunnable() {
@Override
protected void doRun() throws Exception {
runnable.run();
}
@Override
public void onFailure(Exception e) {
throw new AssertionError(e);
}
});
thread.start();
thread.join();
}
use of org.opensearch.common.util.concurrent.AbstractRunnable in project OpenSearch by opensearch-project.
the class AsyncBulkByScrollActionTests method testThreadPoolRejectionsAbortRequest.
/**
* Mimicks a ThreadPool rejecting execution of the task.
*/
public void testThreadPoolRejectionsAbortRequest() throws Exception {
worker.rethrottle(1);
setupClient(new TestThreadPool(getTestName()) {
@Override
public ScheduledCancellable schedule(Runnable command, TimeValue delay, String name) {
// While we're here we can check that the sleep made it through
assertThat(delay.nanos(), greaterThan(0L));
assertThat(delay.seconds(), lessThanOrEqualTo(10L));
final OpenSearchRejectedExecutionException exception = new OpenSearchRejectedExecutionException("test");
if (command instanceof AbstractRunnable) {
((AbstractRunnable) command).onRejection(exception);
return null;
} else {
throw exception;
}
}
});
ScrollableHitSource.Response response = new ScrollableHitSource.Response(false, emptyList(), 0, emptyList(), null);
simulateScrollResponse(new DummyAsyncBulkByScrollAction(), System.nanoTime(), 10, response);
ExecutionException e = expectThrows(ExecutionException.class, () -> listener.get());
assertThat(e.getCause(), instanceOf(OpenSearchRejectedExecutionException.class));
assertThat(e.getCause(), hasToString(containsString("test")));
assertThat(client.scrollsCleared, contains(scrollId));
// When the task is rejected we don't increment the throttled timer
assertEquals(timeValueMillis(0), testTask.getStatus().getThrottled());
}
use of org.opensearch.common.util.concurrent.AbstractRunnable in project OpenSearch by opensearch-project.
the class EvilThreadPoolTests method checkExecutionError.
private void checkExecutionError(Consumer<Runnable> runner) throws InterruptedException {
logger.info("checking error for {}", runner);
final Runnable runnable;
if (randomBoolean()) {
runnable = () -> {
throw new Error("future error");
};
} else {
runnable = new AbstractRunnable() {
@Override
public void onFailure(Exception e) {
}
@Override
protected void doRun() {
throw new Error("future error");
}
};
}
runExecutionTest(runner, runnable, true, o -> {
assertTrue(o.isPresent());
assertThat(o.get(), instanceOf(Error.class));
assertThat(o.get(), hasToString(containsString("future error")));
});
}
Aggregations