Search in sources :

Example 1 with TimestampParsingException

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

Example 2 with TimestampParsingException

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

Aggregations

TimestampParsingException (org.elasticsearch.action.TimestampParsingException)2 IOException (java.io.IOException)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 ParsingException (org.elasticsearch.common.ParsingException)1 BytesReference (org.elasticsearch.common.bytes.BytesReference)1 ToXContent (org.elasticsearch.common.xcontent.ToXContent)1 XContent (org.elasticsearch.common.xcontent.XContent)1 XContentParser (org.elasticsearch.common.xcontent.XContentParser)1 Index (org.elasticsearch.index.Index)1 IndexShardClosedException (org.elasticsearch.index.shard.IndexShardClosedException)1 InvalidIndexTemplateException (org.elasticsearch.indices.InvalidIndexTemplateException)1 SearchShardTarget (org.elasticsearch.search.SearchShardTarget)1