use of org.opensearch.action.TimestampParsingException in project OpenSearch by opensearch-project.
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.opensearch.action.TimestampParsingException in project OpenSearch by opensearch-project.
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 ShardId("test", "_na_", i), null, OriginalIndices.NONE));
}
final String phase = randomFrom("query", "search", "other");
SearchPhaseExecutionException actual = new SearchPhaseExecutionException(phase, "unexpected failures", shardSearchFailures);
BytesReference exceptionBytes = toShuffledXContent(actual, xContent.type(), ToXContent.EMPTY_PARAMS, randomBoolean());
OpenSearchException parsedException;
try (XContentParser parser = createParser(xContent, exceptionBytes)) {
assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
parsedException = OpenSearchException.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("opensearch.phase"), hasItem(phase));
// SearchPhaseExecutionException has no cause field
assertNull(parsedException.getCause());
}
Aggregations