|
20 | 20 | package org.elasticsearch;
|
21 | 21 |
|
22 | 22 | import org.apache.commons.codec.DecoderException;
|
| 23 | +import org.apache.lucene.index.CorruptIndexException; |
23 | 24 | import org.elasticsearch.action.OriginalIndices;
|
24 | 25 | import org.elasticsearch.action.ShardOperationFailedException;
|
25 | 26 | import org.elasticsearch.action.search.ShardSearchFailure;
|
@@ -183,4 +184,31 @@ public void testGroupByNullIndex() {
|
183 | 184 | ShardOperationFailedException[] groupBy = ExceptionsHelper.groupBy(failures);
|
184 | 185 | assertThat(groupBy.length, equalTo(2));
|
185 | 186 | }
|
| 187 | + |
| 188 | + public void testUnwrapCorruption() { |
| 189 | + final Throwable corruptIndexException = new CorruptIndexException("corrupt", "resource"); |
| 190 | + assertThat(ExceptionsHelper.unwrapCorruption(corruptIndexException), equalTo(corruptIndexException)); |
| 191 | + |
| 192 | + final Throwable corruptionAsCause = new RuntimeException(corruptIndexException); |
| 193 | + assertThat(ExceptionsHelper.unwrapCorruption(corruptionAsCause), equalTo(corruptIndexException)); |
| 194 | + |
| 195 | + final Throwable corruptionSuppressed = new RuntimeException(); |
| 196 | + corruptionSuppressed.addSuppressed(corruptIndexException); |
| 197 | + assertThat(ExceptionsHelper.unwrapCorruption(corruptionSuppressed), equalTo(corruptIndexException)); |
| 198 | + |
| 199 | + final Throwable corruptionSuppressedOnCause = new RuntimeException(new RuntimeException()); |
| 200 | + corruptionSuppressedOnCause.getCause().addSuppressed(corruptIndexException); |
| 201 | + assertThat(ExceptionsHelper.unwrapCorruption(corruptionSuppressedOnCause), equalTo(corruptIndexException)); |
| 202 | + |
| 203 | + final Throwable corruptionCauseOnSuppressed = new RuntimeException(); |
| 204 | + corruptionCauseOnSuppressed.addSuppressed(new RuntimeException(corruptIndexException)); |
| 205 | + assertThat(ExceptionsHelper.unwrapCorruption(corruptionCauseOnSuppressed), equalTo(corruptIndexException)); |
| 206 | + |
| 207 | + assertThat(ExceptionsHelper.unwrapCorruption(new RuntimeException()), nullValue()); |
| 208 | + assertThat(ExceptionsHelper.unwrapCorruption(new RuntimeException(new RuntimeException())), nullValue()); |
| 209 | + |
| 210 | + final Throwable withSuppressedException = new RuntimeException(); |
| 211 | + withSuppressedException.addSuppressed(new RuntimeException()); |
| 212 | + assertThat(ExceptionsHelper.unwrapCorruption(withSuppressedException), nullValue()); |
| 213 | + } |
186 | 214 | }
|
0 commit comments