use of org.apache.lucene.index.IndexFormatTooOldException in project elasticsearch by elastic.
the class ExceptionSerializationTests method testWriteThrowable.
public void testWriteThrowable() throws IOException {
final QueryShardException queryShardException = new QueryShardException(new Index("foo", "_na_"), "foobar", null);
final UnknownException unknownException = new UnknownException("this exception is unknown", queryShardException);
final Exception[] causes = new Exception[] { new IllegalStateException("foobar"), new IllegalArgumentException("alalaal"), new NullPointerException("boom"), new EOFException("dadada"), new ElasticsearchSecurityException("nono!"), new NumberFormatException("not a number"), new CorruptIndexException("baaaam booom", "this is my resource"), new IndexFormatTooNewException("tooo new", 1, 2, 3), new IndexFormatTooOldException("tooo new", 1, 2, 3), new IndexFormatTooOldException("tooo new", "very old version"), new ArrayIndexOutOfBoundsException("booom"), new StringIndexOutOfBoundsException("booom"), new FileNotFoundException("booom"), new NoSuchFileException("booom"), new AlreadyClosedException("closed!!", new NullPointerException()), new LockObtainFailedException("can't lock directory", new NullPointerException()), unknownException };
for (final Exception cause : causes) {
ElasticsearchException ex = new ElasticsearchException("topLevel", cause);
ElasticsearchException deserialized = serialize(ex);
assertEquals(deserialized.getMessage(), ex.getMessage());
assertTrue("Expected: " + deserialized.getCause().getMessage() + " to contain: " + ex.getCause().getClass().getName() + " but it didn't", deserialized.getCause().getMessage().contains(ex.getCause().getMessage()));
if (ex.getCause().getClass() != UnknownException.class) {
// unknown exception is not directly mapped
assertEquals(deserialized.getCause().getClass(), ex.getCause().getClass());
} else {
assertEquals(deserialized.getCause().getClass(), NotSerializableExceptionWrapper.class);
}
assertArrayEquals(deserialized.getStackTrace(), ex.getStackTrace());
assertTrue(deserialized.getStackTrace().length > 1);
assertVersionSerializable(VersionUtils.randomVersion(random()), cause);
assertVersionSerializable(VersionUtils.randomVersion(random()), ex);
assertVersionSerializable(VersionUtils.randomVersion(random()), deserialized);
}
}
Aggregations