1616import org .elasticsearch .script .Script ;
1717import org .elasticsearch .script .ScriptType ;
1818import org .elasticsearch .test .junit .annotations .TestLogging ;
19- import org .elasticsearch .xpack .watcher .condition .InternalAlwaysCondition ;
2019import org .elasticsearch .xpack .watcher .support .search .WatcherSearchTemplateRequest ;
2120import org .elasticsearch .xpack .watcher .test .AbstractWatcherIntegrationTestCase ;
2221import org .elasticsearch .xpack .watcher .test .WatcherMockScriptPlugin ;
@@ -121,7 +120,6 @@ public void testScriptTransform() throws Exception {
121120 .setSource (watchBuilder ()
122121 .trigger (schedule (interval ("5s" )))
123122 .input (simpleInput (MapBuilder .<String , Object >newMapBuilder ().put ("key1" , 10 ).put ("key2" , 10 )))
124- .condition (InternalAlwaysCondition .INSTANCE )
125123 .transform (scriptTransform (script ))
126124 .addAction ("_id" , indexAction ("output1" , "type" )))
127125 .get ();
@@ -131,13 +129,12 @@ public void testScriptTransform() throws Exception {
131129 .setSource (watchBuilder ()
132130 .trigger (schedule (interval ("5s" )))
133131 .input (simpleInput (MapBuilder .<String , Object >newMapBuilder ().put ("key1" , 10 ).put ("key2" , 10 )))
134- .condition (InternalAlwaysCondition .INSTANCE )
135132 .addAction ("_id" , scriptTransform (script ), indexAction ("output2" , "type" )))
136133 .get ();
137134 assertThat (putWatchResponse .isCreated (), is (true ));
138135
139- timeWarp (). trigger ("_id1" );
140- timeWarp (). trigger ("_id2" );
136+ executeWatch ("_id1" );
137+ executeWatch ("_id2" );
141138 refresh ();
142139
143140 assertWatchWithMinimumPerformedActionsCount ("_id1" , 1 , false );
@@ -184,8 +181,8 @@ public void testSearchTransform() throws Exception {
184181 ).get ();
185182 assertThat (putWatchResponse .isCreated (), is (true ));
186183
187- timeWarp (). trigger ("_id1" );
188- timeWarp (). trigger ("_id2" );
184+ executeWatch ("_id1" );
185+ executeWatch ("_id2" );
189186 refresh ();
190187
191188 assertWatchWithMinimumPerformedActionsCount ("_id1" , 1 , false );
@@ -212,7 +209,6 @@ public void testChainTransform() throws Exception {
212209 .setSource (watchBuilder ()
213210 .trigger (schedule (interval ("5s" )))
214211 .input (simpleInput (MapBuilder .<String , Object >newMapBuilder ().put ("key1" , 10 ).put ("key2" , 10 )))
215- .condition (InternalAlwaysCondition .INSTANCE )
216212 .transform (chainTransform (scriptTransform (script1 ), scriptTransform (script2 )))
217213 .addAction ("_id" , indexAction ("output1" , "type" )))
218214 .get ();
@@ -222,14 +218,13 @@ public void testChainTransform() throws Exception {
222218 .setSource (watchBuilder ()
223219 .trigger (schedule (interval ("5s" )))
224220 .input (simpleInput (MapBuilder .<String , Object >newMapBuilder ().put ("key1" , 10 ).put ("key2" , 10 )))
225- .condition (InternalAlwaysCondition .INSTANCE )
226221 .addAction ("_id" , chainTransform (scriptTransform (script1 ), scriptTransform (script2 )),
227222 indexAction ("output2" , "type" )))
228223 .get ();
229224 assertThat (putWatchResponse .isCreated (), is (true ));
230225
231- timeWarp (). trigger ("_id1" );
232- timeWarp (). trigger ("_id2" );
226+ executeWatch ("_id1" );
227+ executeWatch ("_id2" );
233228 refresh ();
234229
235230 assertWatchWithMinimumPerformedActionsCount ("_id1" , 1 , false );
@@ -248,4 +243,10 @@ public void testChainTransform() throws Exception {
248243 assertThat (response .getHits ().getAt (0 ).getSourceAsMap ().size (), equalTo (1 ));
249244 assertThat (response .getHits ().getAt (0 ).getSourceAsMap ().get ("key4" ).toString (), equalTo ("30" ));
250245 }
246+
247+ private void executeWatch (String watchId ) {
248+ watcherClient ().prepareExecuteWatch (watchId )
249+ .setRecordExecution (true )
250+ .get ();
251+ }
251252}
0 commit comments