use of org.elasticsearch.action.TimestampParsingException in project elasticsearch by elastic.
the class ExceptionSerializationTests method testTimestampParsingException.
public void testTimestampParsingException() throws IOException {
TimestampParsingException ex = serialize(new TimestampParsingException("TIMESTAMP", null));
assertEquals("failed to parse timestamp [TIMESTAMP]", ex.getMessage());
assertEquals("TIMESTAMP", ex.timestamp());
}
use of org.elasticsearch.action.TimestampParsingException in project elasticsearch by elastic.
the class SearchPhaseExecutionExceptionTests method testToAndFromXContent.
public void testToAndFromXContent() throws IOException {
final XContent xContent = randomFrom(XContentType.values()).xContent();
ShardSearchFailure[] shardSearchFailures = new ShardSearchFailure[randomIntBetween(1, 5)];
for (int i = 0; i < shardSearchFailures.length; i++) {
Exception cause = randomFrom(new ParsingException(1, 2, "foobar", null), new InvalidIndexTemplateException("foo", "bar"), new TimestampParsingException("foo", null), new NullPointerException());
shardSearchFailures[i] = new ShardSearchFailure(cause, new SearchShardTarget("node_" + i, new Index("test", "_na_"), i));
}
final String phase = randomFrom("query", "search", "other");
SearchPhaseExecutionException actual = new SearchPhaseExecutionException(phase, "unexpected failures", shardSearchFailures);
BytesReference exceptionBytes = XContentHelper.toXContent(actual, xContent.type(), randomBoolean());
ElasticsearchException parsedException;
try (XContentParser parser = createParser(xContent, exceptionBytes)) {
assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
parsedException = ElasticsearchException.fromXContent(parser);
assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken());
assertNull(parser.nextToken());
}
assertNotNull(parsedException);
assertThat(parsedException.getHeaderKeys(), hasSize(0));
assertThat(parsedException.getMetadataKeys(), hasSize(1));
assertThat(parsedException.getMetadata("es.phase"), hasItem(phase));
// SearchPhaseExecutionException has no cause field
assertNull(parsedException.getCause());
}
Aggregations