@@ -114,18 +114,20 @@ public void testPreIndexCheckActive() throws Exception {
114
114
verifyZeroInteractions (parser );
115
115
}
116
116
117
- public void testPreIndex () throws Exception {
117
+ public void testPostIndex () throws Exception {
118
118
when (operation .id ()).thenReturn (randomAlphaOfLength (10 ));
119
119
when (operation .source ()).thenReturn (BytesArray .EMPTY );
120
120
when (shardId .getIndexName ()).thenReturn (Watch .INDEX );
121
+ List <Engine .Result .Type > types = new ArrayList <>(Arrays .asList (Engine .Result .Type .values ()));
122
+ types .remove (Engine .Result .Type .FAILURE );
123
+ when (result .getResultType ()).thenReturn (randomFrom (types ));
121
124
122
125
boolean watchActive = randomBoolean ();
123
126
boolean isNewWatch = randomBoolean ();
124
127
Watch watch = mockWatch ("_id" , watchActive , isNewWatch );
125
128
when (parser .parseWithSecrets (anyObject (), eq (true ), anyObject (), anyObject (), anyObject (), anyLong (), anyLong ())).thenReturn (watch );
126
129
127
- Engine .Index returnedOperation = listener .preIndex (shardId , operation );
128
- assertThat (returnedOperation , is (operation ));
130
+ listener .postIndex (shardId , operation , result );
129
131
ZonedDateTime now = DateUtils .nowWithMillisResolution (clock );
130
132
verify (parser ).parseWithSecrets (eq (operation .id ()), eq (true ), eq (BytesArray .EMPTY ), eq (now ), anyObject (), anyLong (), anyLong ());
131
133
@@ -140,12 +142,13 @@ public void testPreIndex() throws Exception {
140
142
141
143
// this test emulates an index with 10 shards, and ensures that triggering only happens on a
142
144
// single shard
143
- public void testPreIndexWatchGetsOnlyTriggeredOnceAcrossAllShards () throws Exception {
145
+ public void testPostIndexWatchGetsOnlyTriggeredOnceAcrossAllShards () throws Exception {
144
146
String id = randomAlphaOfLength (10 );
145
147
int totalShardCount = randomIntBetween (1 , 10 );
146
148
boolean watchActive = randomBoolean ();
147
149
boolean isNewWatch = randomBoolean ();
148
150
Watch watch = mockWatch (id , watchActive , isNewWatch );
151
+ when (result .getResultType ()).thenReturn (Engine .Result .Type .SUCCESS );
149
152
150
153
when (shardId .getIndexName ()).thenReturn (Watch .INDEX );
151
154
when (parser .parseWithSecrets (anyObject (), eq (true ), anyObject (), anyObject (), anyObject (), anyLong (), anyLong ())).thenReturn (watch );
@@ -155,7 +158,7 @@ public void testPreIndexWatchGetsOnlyTriggeredOnceAcrossAllShards() throws Excep
155
158
localShards .put (shardId , new ShardAllocationConfiguration (idx , totalShardCount , Collections .emptyList ()));
156
159
Configuration configuration = new Configuration (Watch .INDEX , localShards );
157
160
listener .setConfiguration (configuration );
158
- listener .preIndex (shardId , operation );
161
+ listener .postIndex (shardId , operation , result );
159
162
}
160
163
161
164
// no matter how many shards we had, this should have been only called once
@@ -187,16 +190,17 @@ private Watch mockWatch(String id, boolean active, boolean isNewWatch) {
187
190
return watch ;
188
191
}
189
192
190
- public void testPreIndexCheckParsingException () throws Exception {
193
+ public void testPostIndexCheckParsingException () throws Exception {
191
194
String id = randomAlphaOfLength (10 );
192
195
when (operation .id ()).thenReturn (id );
193
196
when (operation .source ()).thenReturn (BytesArray .EMPTY );
194
197
when (shardId .getIndexName ()).thenReturn (Watch .INDEX );
195
198
when (parser .parseWithSecrets (anyObject (), eq (true ), anyObject (), anyObject (), anyObject (), anyLong (), anyLong ()))
196
199
.thenThrow (new IOException ("self thrown" ));
200
+ when (result .getResultType ()).thenReturn (Engine .Result .Type .SUCCESS );
197
201
198
202
ElasticsearchParseException exc = expectThrows (ElasticsearchParseException .class ,
199
- () -> listener .preIndex (shardId , operation ));
203
+ () -> listener .postIndex (shardId , operation , result ));
200
204
assertThat (exc .getMessage (), containsString ("Could not parse watch" ));
201
205
assertThat (exc .getMessage (), containsString (id ));
202
206
}
@@ -207,19 +211,6 @@ public void testPostIndexRemoveTriggerOnDocumentRelatedException() throws Except
207
211
when (result .getFailure ()).thenReturn (new RuntimeException ());
208
212
when (shardId .getIndexName ()).thenReturn (Watch .INDEX );
209
213
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
214
listener .postIndex (shardId , operation , result );
224
215
verifyZeroInteractions (triggerService );
225
216
}
@@ -239,7 +230,7 @@ public void testPostIndexRemoveTriggerOnEngineLevelException() throws Exception
239
230
when (shardId .getIndexName ()).thenReturn (Watch .INDEX );
240
231
241
232
listener .postIndex (shardId , operation , new ElasticsearchParseException ("whatever" ));
242
- verify (triggerService ). remove ( eq ( "_id" ) );
233
+ verifyZeroInteractions (triggerService );
243
234
}
244
235
245
236
public void testPostIndexRemoveTriggerOnEngineLevelException_ignoreNonWatcherDocument () throws Exception {
0 commit comments