|
25 | 25 | import org.elasticsearch.common.ParsingException;
|
26 | 26 | import org.elasticsearch.common.Strings;
|
27 | 27 | import org.elasticsearch.common.bytes.BytesReference;
|
| 28 | +import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; |
28 | 29 | import org.elasticsearch.common.xcontent.ToXContent;
|
29 | 30 | import org.elasticsearch.common.xcontent.XContent;
|
30 | 31 | import org.elasticsearch.common.xcontent.XContentParser;
|
31 | 32 | import org.elasticsearch.common.xcontent.XContentType;
|
32 | 33 | import org.elasticsearch.index.shard.IndexShardClosedException;
|
33 | 34 | import org.elasticsearch.index.shard.ShardId;
|
34 | 35 | import org.elasticsearch.indices.InvalidIndexTemplateException;
|
| 36 | +import org.elasticsearch.rest.RestStatus; |
35 | 37 | import org.elasticsearch.search.SearchShardTarget;
|
36 | 38 | import org.elasticsearch.test.ESTestCase;
|
37 | 39 |
|
@@ -121,4 +123,39 @@ public void testToAndFromXContent() throws IOException {
|
121 | 123 | // SearchPhaseExecutionException has no cause field
|
122 | 124 | assertNull(parsedException.getCause());
|
123 | 125 | }
|
| 126 | + |
| 127 | + public void testPhaseFailureWithoutSearchShardFailure() { |
| 128 | + final ShardSearchFailure[] searchShardFailures = new ShardSearchFailure[0]; |
| 129 | + final String phase = randomFrom("fetch", "search", "other"); |
| 130 | + SearchPhaseExecutionException actual = new SearchPhaseExecutionException(phase, "unexpected failures", |
| 131 | + new EsRejectedExecutionException("ES rejected execution of fetch phase"), searchShardFailures); |
| 132 | + |
| 133 | + assertEquals(actual.status(), RestStatus.TOO_MANY_REQUESTS); |
| 134 | + } |
| 135 | + |
| 136 | + public void testPhaseFailureWithoutSearchShardFailureAndCause() { |
| 137 | + final ShardSearchFailure[] searchShardFailures = new ShardSearchFailure[0]; |
| 138 | + final String phase = randomFrom("fetch", "search", "other"); |
| 139 | + SearchPhaseExecutionException actual = new SearchPhaseExecutionException(phase, "unexpected failures", null, searchShardFailures); |
| 140 | + |
| 141 | + assertEquals(actual.status(), RestStatus.SERVICE_UNAVAILABLE); |
| 142 | + } |
| 143 | + |
| 144 | + public void testPhaseFailureWithSearchShardFailure() { |
| 145 | + final ShardSearchFailure[] shardSearchFailures = new ShardSearchFailure[randomIntBetween(1, 5)]; |
| 146 | + for (int i = 0; i < shardSearchFailures.length; i++) { |
| 147 | + Exception cause = randomFrom( |
| 148 | + new ParsingException(1, 2, "foobar", null), |
| 149 | + new InvalidIndexTemplateException("foo", "bar") |
| 150 | + ); |
| 151 | + shardSearchFailures[i] = new ShardSearchFailure(cause, new SearchShardTarget("node_" + i, |
| 152 | + new ShardId("test", "_na_", i), null, OriginalIndices.NONE)); |
| 153 | + } |
| 154 | + |
| 155 | + final String phase = randomFrom("fetch", "search", "other"); |
| 156 | + SearchPhaseExecutionException actual = new SearchPhaseExecutionException(phase, "unexpected failures", |
| 157 | + new EsRejectedExecutionException("ES rejected execution of fetch phase"), shardSearchFailures); |
| 158 | + |
| 159 | + assertEquals(actual.status(), RestStatus.BAD_REQUEST); |
| 160 | + } |
124 | 161 | }
|
0 commit comments