1515import org .elasticsearch .script .MockScriptPlugin ;
1616import org .elasticsearch .script .Script ;
1717import org .elasticsearch .script .ScriptType ;
18- import org .elasticsearch .xpack .watcher .condition .InternalAlwaysCondition ;
1918import org .elasticsearch .xpack .watcher .support .search .WatcherSearchTemplateRequest ;
2019import org .elasticsearch .xpack .watcher .test .AbstractWatcherIntegrationTestCase ;
2120import org .elasticsearch .xpack .watcher .test .WatcherMockScriptPlugin ;
@@ -120,7 +119,6 @@ public void testScriptTransform() throws Exception {
120119 .setSource (watchBuilder ()
121120 .trigger (schedule (interval ("5s" )))
122121 .input (simpleInput (MapBuilder .<String , Object >newMapBuilder ().put ("key1" , 10 ).put ("key2" , 10 )))
123- .condition (InternalAlwaysCondition .INSTANCE )
124122 .transform (scriptTransform (script ))
125123 .addAction ("_id" , indexAction ("output1" , "type" )))
126124 .get ();
@@ -130,13 +128,12 @@ public void testScriptTransform() throws Exception {
130128 .setSource (watchBuilder ()
131129 .trigger (schedule (interval ("5s" )))
132130 .input (simpleInput (MapBuilder .<String , Object >newMapBuilder ().put ("key1" , 10 ).put ("key2" , 10 )))
133- .condition (InternalAlwaysCondition .INSTANCE )
134131 .addAction ("_id" , scriptTransform (script ), indexAction ("output2" , "type" )))
135132 .get ();
136133 assertThat (putWatchResponse .isCreated (), is (true ));
137134
138- timeWarp (). trigger ("_id1" );
139- timeWarp (). trigger ("_id2" );
135+ executeWatch ("_id1" );
136+ executeWatch ("_id2" );
140137 refresh ();
141138
142139 assertWatchWithMinimumPerformedActionsCount ("_id1" , 1 , false );
@@ -183,8 +180,8 @@ public void testSearchTransform() throws Exception {
183180 ).get ();
184181 assertThat (putWatchResponse .isCreated (), is (true ));
185182
186- timeWarp (). trigger ("_id1" );
187- timeWarp (). trigger ("_id2" );
183+ executeWatch ("_id1" );
184+ executeWatch ("_id2" );
188185 refresh ();
189186
190187 assertWatchWithMinimumPerformedActionsCount ("_id1" , 1 , false );
@@ -211,7 +208,6 @@ public void testChainTransform() throws Exception {
211208 .setSource (watchBuilder ()
212209 .trigger (schedule (interval ("5s" )))
213210 .input (simpleInput (MapBuilder .<String , Object >newMapBuilder ().put ("key1" , 10 ).put ("key2" , 10 )))
214- .condition (InternalAlwaysCondition .INSTANCE )
215211 .transform (chainTransform (scriptTransform (script1 ), scriptTransform (script2 )))
216212 .addAction ("_id" , indexAction ("output1" , "type" )))
217213 .get ();
@@ -221,14 +217,13 @@ public void testChainTransform() throws Exception {
221217 .setSource (watchBuilder ()
222218 .trigger (schedule (interval ("5s" )))
223219 .input (simpleInput (MapBuilder .<String , Object >newMapBuilder ().put ("key1" , 10 ).put ("key2" , 10 )))
224- .condition (InternalAlwaysCondition .INSTANCE )
225220 .addAction ("_id" , chainTransform (scriptTransform (script1 ), scriptTransform (script2 )),
226221 indexAction ("output2" , "type" )))
227222 .get ();
228223 assertThat (putWatchResponse .isCreated (), is (true ));
229224
230- timeWarp (). trigger ("_id1" );
231- timeWarp (). trigger ("_id2" );
225+ executeWatch ("_id1" );
226+ executeWatch ("_id2" );
232227 refresh ();
233228
234229 assertWatchWithMinimumPerformedActionsCount ("_id1" , 1 , false );
@@ -247,4 +242,10 @@ public void testChainTransform() throws Exception {
247242 assertThat (response .getHits ().getAt (0 ).getSourceAsMap ().size (), equalTo (1 ));
248243 assertThat (response .getHits ().getAt (0 ).getSourceAsMap ().get ("key4" ).toString (), equalTo ("30" ));
249244 }
245+
246+ private void executeWatch (String watchId ) {
247+ watcherClient ().prepareExecuteWatch (watchId )
248+ .setRecordExecution (true )
249+ .get ();
250+ }
250251}
0 commit comments