use of org.elasticsearch.common.io.stream.NotSerializableExceptionWrapper in project elasticsearch by elastic.
the class ExceptionSerializationTests method testNotSerializableExceptionWrapper.
public void testNotSerializableExceptionWrapper() throws IOException {
NotSerializableExceptionWrapper ex = serialize(new NotSerializableExceptionWrapper(new NullPointerException()));
assertEquals("{\"type\":\"null_pointer_exception\",\"reason\":\"null_pointer_exception: null\"}", Strings.toString(ex));
ex = serialize(new NotSerializableExceptionWrapper(new IllegalArgumentException("nono!")));
assertEquals("{\"type\":\"illegal_argument_exception\",\"reason\":\"illegal_argument_exception: nono!\"}", Strings.toString(ex));
class UnknownException extends Exception {
UnknownException(final String message) {
super(message);
}
}
Exception[] unknowns = new Exception[] { new Exception("foobar"), new ClassCastException("boom boom boom"), new UnknownException("boom") };
for (Exception t : unknowns) {
if (randomBoolean()) {
t.addSuppressed(new UnsatisfiedLinkError("suppressed"));
t.addSuppressed(new NullPointerException());
}
Throwable deserialized = serialize(t);
assertTrue(deserialized.getClass().toString(), deserialized instanceof NotSerializableExceptionWrapper);
assertArrayEquals(t.getStackTrace(), deserialized.getStackTrace());
assertEquals(t.getSuppressed().length, deserialized.getSuppressed().length);
if (t.getSuppressed().length > 0) {
assertTrue(deserialized.getSuppressed()[0] instanceof NotSerializableExceptionWrapper);
assertArrayEquals(t.getSuppressed()[0].getStackTrace(), deserialized.getSuppressed()[0].getStackTrace());
assertTrue(deserialized.getSuppressed()[1] instanceof NullPointerException);
}
}
}
use of org.elasticsearch.common.io.stream.NotSerializableExceptionWrapper in project crate by crate.
the class BulkShardProcessor method executeRequests.
private void executeRequests() {
try {
executeLock.acquire();
for (Iterator<Map.Entry<ShardId, Request>> it = requestsByShard.entrySet().iterator(); it.hasNext(); ) {
if (failure.get() != null) {
return;
}
Map.Entry<ShardId, Request> entry = it.next();
final Request request = entry.getValue();
final ShardId shardId = entry.getKey();
requestExecutor.execute(request, new ActionListener<ShardResponse>() {
@Override
public void onResponse(ShardResponse response) {
processResponse(response);
}
@Override
public void onFailure(Throwable t) {
t = SQLExceptions.unwrap(t, throwable -> throwable instanceof RuntimeException);
if (t instanceof ClassCastException || t instanceof NotSerializableExceptionWrapper) {
// this is caused by passing mixed argument types into a bulk upsert.
// it can happen after an valid request already succeeded and data was written.
// so never bubble, but rather mark all items of this request as failed.
markItemsAsFailedAndReleaseRetryLock(request, Optional.absent());
LOGGER.warn("ShardUpsert: {} items failed", t, request.items().size());
return;
}
processFailure(t, shardId, request, Optional.absent());
}
});
it.remove();
}
} catch (InterruptedException e) {
Thread.interrupted();
} catch (Throwable e) {
setFailure(e);
} finally {
requestItemCounter.set(0);
executeLock.release();
}
}
Aggregations