|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.elasticsearch.index.reindex.remote; |
| 21 | + |
| 22 | +import org.elasticsearch.action.search.ShardSearchFailure; |
| 23 | +import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; |
| 24 | +import org.elasticsearch.common.xcontent.ToXContent; |
| 25 | +import org.elasticsearch.common.xcontent.XContentBuilder; |
| 26 | +import org.elasticsearch.common.xcontent.XContentParser; |
| 27 | +import org.elasticsearch.common.xcontent.XContentType; |
| 28 | +import org.elasticsearch.index.reindex.ScrollableHitSource; |
| 29 | +import org.elasticsearch.test.ESTestCase; |
| 30 | +import org.hamcrest.Matchers; |
| 31 | + |
| 32 | +import java.io.IOException; |
| 33 | + |
| 34 | +import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; |
| 35 | + |
| 36 | +public class RemoteResponseParsersTests extends ESTestCase { |
| 37 | + |
| 38 | + /** |
| 39 | + * Check that we can parse shard search failures without index information. |
| 40 | + */ |
| 41 | + public void testFailureWithoutIndex() throws IOException { |
| 42 | + ShardSearchFailure failure = new ShardSearchFailure(new EsRejectedExecutionException("exhausted")); |
| 43 | + XContentBuilder builder = jsonBuilder(); |
| 44 | + failure.toXContent(builder, ToXContent.EMPTY_PARAMS); |
| 45 | + try (XContentParser parser = createParser(builder)) { |
| 46 | + ScrollableHitSource.SearchFailure parsed = RemoteResponseParsers.SEARCH_FAILURE_PARSER.parse(parser, XContentType.JSON); |
| 47 | + assertNotNull(parsed.getReason()); |
| 48 | + assertThat(parsed.getReason().getMessage(), Matchers.containsString("exhausted")); |
| 49 | + assertThat(parsed.getReason(), Matchers.instanceOf(EsRejectedExecutionException.class)); |
| 50 | + } |
| 51 | + } |
| 52 | +} |
0 commit comments