|
45 | 45 | import java.io.IOException;
|
46 | 46 | import java.time.ZonedDateTime;
|
47 | 47 | import java.util.ArrayList;
|
| 48 | +import java.util.Arrays; |
48 | 49 | import java.util.BitSet;
|
49 | 50 | import java.util.Collections;
|
50 | 51 | import java.util.HashMap;
|
@@ -200,15 +201,48 @@ public void testPreIndexCheckParsingException() throws Exception {
|
200 | 201 | assertThat(exc.getMessage(), containsString(id));
|
201 | 202 | }
|
202 | 203 |
|
203 |
| - public void testPostIndexRemoveTriggerOnException() throws Exception { |
| 204 | + public void testPostIndexRemoveTriggerOnDocumentRelatedException() throws Exception { |
| 205 | + when(operation.id()).thenReturn("_id"); |
| 206 | + when(result.getResultType()).thenReturn(Engine.Result.Type.FAILURE); |
| 207 | + when(result.getFailure()).thenReturn(new RuntimeException()); |
| 208 | + when(shardId.getIndexName()).thenReturn(Watch.INDEX); |
| 209 | + |
| 210 | + listener.postIndex(shardId, operation, result); |
| 211 | + verify(triggerService).remove(eq("_id")); |
| 212 | + } |
| 213 | + |
| 214 | + public void testPostIndexRemoveTriggerOnDocumentRelatedException_ignoreOtherEngineResultTypes() throws Exception { |
| 215 | + List<Engine.Result.Type> types = new ArrayList<>(Arrays.asList(Engine.Result.Type.values())); |
| 216 | + types.remove(Engine.Result.Type.FAILURE); |
| 217 | + |
| 218 | + when(operation.id()).thenReturn("_id"); |
| 219 | + when(result.getResultType()).thenReturn(randomFrom(types)); |
| 220 | + when(result.getFailure()).thenReturn(new RuntimeException()); |
| 221 | + when(shardId.getIndexName()).thenReturn(Watch.INDEX); |
| 222 | + |
| 223 | + listener.postIndex(shardId, operation, result); |
| 224 | + verifyZeroInteractions(triggerService); |
| 225 | + } |
| 226 | + |
| 227 | + public void testPostIndexRemoveTriggerOnDocumentRelatedException_ignoreNonWatcherDocument() throws Exception { |
| 228 | + when(operation.id()).thenReturn("_id"); |
| 229 | + when(result.getResultType()).thenReturn(Engine.Result.Type.FAILURE); |
| 230 | + when(result.getFailure()).thenReturn(new RuntimeException()); |
| 231 | + when(shardId.getIndexName()).thenReturn(randomAlphaOfLength(4)); |
| 232 | + |
| 233 | + listener.postIndex(shardId, operation, result); |
| 234 | + verifyZeroInteractions(triggerService); |
| 235 | + } |
| 236 | + |
| 237 | + public void testPostIndexRemoveTriggerOnEngineLevelException() throws Exception { |
204 | 238 | when(operation.id()).thenReturn("_id");
|
205 | 239 | when(shardId.getIndexName()).thenReturn(Watch.INDEX);
|
206 | 240 |
|
207 | 241 | listener.postIndex(shardId, operation, new ElasticsearchParseException("whatever"));
|
208 | 242 | verify(triggerService).remove(eq("_id"));
|
209 | 243 | }
|
210 | 244 |
|
211 |
| - public void testPostIndexDontInvokeForOtherDocuments() throws Exception { |
| 245 | + public void testPostIndexRemoveTriggerOnEngineLevelException_ignoreNonWatcherDocument() throws Exception { |
212 | 246 | when(operation.id()).thenReturn("_id");
|
213 | 247 | when(shardId.getIndexName()).thenReturn("anything");
|
214 | 248 | when(result.getResultType()).thenReturn(Engine.Result.Type.SUCCESS);
|
|
0 commit comments