Search in sources :

Example 1 with TimestampParsingException

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());
}
Also used : TimestampParsingException(org.opensearch.action.TimestampParsingException)

Example 2 with TimestampParsingException

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());
}
Also used : BytesReference(org.opensearch.common.bytes.BytesReference) InvalidIndexTemplateException(org.opensearch.indices.InvalidIndexTemplateException) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) IndexShardClosedException(org.opensearch.index.shard.IndexShardClosedException) IOException(java.io.IOException) OpenSearchException(org.opensearch.OpenSearchException) TimestampParsingException(org.opensearch.action.TimestampParsingException) InvalidIndexTemplateException(org.opensearch.indices.InvalidIndexTemplateException) ParsingException(org.opensearch.common.ParsingException) ShardId(org.opensearch.index.shard.ShardId) ToXContent(org.opensearch.common.xcontent.ToXContent) XContent(org.opensearch.common.xcontent.XContent) TimestampParsingException(org.opensearch.action.TimestampParsingException) ParsingException(org.opensearch.common.ParsingException) SearchShardTarget(org.opensearch.search.SearchShardTarget) TimestampParsingException(org.opensearch.action.TimestampParsingException) OpenSearchException(org.opensearch.OpenSearchException) XContentParser(org.opensearch.common.xcontent.XContentParser)

Aggregations

TimestampParsingException (org.opensearch.action.TimestampParsingException)2 IOException (java.io.IOException)1 OpenSearchException (org.opensearch.OpenSearchException)1 ParsingException (org.opensearch.common.ParsingException)1 BytesReference (org.opensearch.common.bytes.BytesReference)1 OpenSearchRejectedExecutionException (org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException)1 ToXContent (org.opensearch.common.xcontent.ToXContent)1 XContent (org.opensearch.common.xcontent.XContent)1 XContentParser (org.opensearch.common.xcontent.XContentParser)1 IndexShardClosedException (org.opensearch.index.shard.IndexShardClosedException)1 ShardId (org.opensearch.index.shard.ShardId)1 InvalidIndexTemplateException (org.opensearch.indices.InvalidIndexTemplateException)1 SearchShardTarget (org.opensearch.search.SearchShardTarget)1