18
18
*/
19
19
package org .elasticsearch .ingest .common ;
20
20
21
+ import org .elasticsearch .action .admin .cluster .node .stats .NodesStatsResponse ;
21
22
import org .elasticsearch .action .support .WriteRequest ;
22
23
import org .elasticsearch .common .bytes .BytesArray ;
23
24
import org .elasticsearch .common .bytes .BytesReference ;
24
25
import org .elasticsearch .common .settings .Settings ;
25
26
import org .elasticsearch .common .xcontent .XContentType ;
27
+ import org .elasticsearch .ingest .IngestStats ;
26
28
import org .elasticsearch .plugins .Plugin ;
27
29
import org .elasticsearch .script .MockScriptEngine ;
28
30
import org .elasticsearch .script .MockScriptPlugin ;
31
33
32
34
import java .util .Arrays ;
33
35
import java .util .Collection ;
34
- import java .util .Collections ;
36
+ import java .util .HashMap ;
37
+ import java .util .List ;
35
38
import java .util .Map ;
36
39
import java .util .function .Consumer ;
37
40
import java .util .function .Function ;
38
41
39
42
import static org .hamcrest .Matchers .equalTo ;
43
+ import static org .hamcrest .Matchers .greaterThanOrEqualTo ;
40
44
41
45
// Ideally I like this test to live in the server module, but otherwise a large part of the ScriptProcessor
42
46
// ends up being copied into this test.
@@ -56,10 +60,52 @@ protected boolean ignoreExternalCluster() {
56
60
public static class CustomScriptPlugin extends MockScriptPlugin {
57
61
@ Override
58
62
protected Map <String , Function <Map <String , Object >, Object >> pluginScripts () {
59
- return Collections .singletonMap ("my_script" , ctx -> {
63
+ Map <String , Function <Map <String , Object >, Object >> pluginScripts = new HashMap <>();
64
+ pluginScripts .put ("my_script" , ctx -> {
60
65
ctx .put ("z" , 0 );
61
66
return null ;
62
67
});
68
+ pluginScripts .put ("throwing_script" , ctx -> {
69
+ throw new RuntimeException ("this script always fails" );
70
+ });
71
+ return pluginScripts ;
72
+ }
73
+ }
74
+
75
+ public void testFailureInConditionalProcessor () {
76
+ internalCluster ().ensureAtLeastNumDataNodes (1 );
77
+ internalCluster ().startMasterOnlyNode ();
78
+ final String pipelineId = "foo" ;
79
+ client ().admin ().cluster ().preparePutPipeline (pipelineId ,
80
+ new BytesArray ("{\n " +
81
+ " \" processors\" : [\n " +
82
+ " {\" set\" : {\" field\" : \" any_field\" , \" value\" : \" any_value\" }},\n " +
83
+ " {\" set\" : {" + "" +
84
+ " \" if\" : " + "{\" lang\" : \" " + MockScriptEngine .NAME + "\" , \" source\" : \" throwing_script\" }," +
85
+ " \" field\" : \" any_field2\" ," +
86
+ " \" value\" : \" any_value2\" }" +
87
+ " }\n " +
88
+ " ]\n " +
89
+ "}" ), XContentType .JSON ).get ();
90
+
91
+ Exception e = expectThrows (
92
+ Exception .class ,
93
+ () ->
94
+ client ().prepareIndex ("index" , "doc" ).setId ("1" )
95
+ .setSource ("x" , 0 )
96
+ .setPipeline (pipelineId )
97
+ .setRefreshPolicy (WriteRequest .RefreshPolicy .IMMEDIATE )
98
+ .get ()
99
+ );
100
+ assertTrue (e .getMessage ().contains ("this script always fails" ));
101
+
102
+ NodesStatsResponse r = client ().admin ().cluster ().prepareNodesStats (internalCluster ().getNodeNames ()).setIngest (true ).get ();
103
+ int nodeCount = r .getNodes ().size ();
104
+ for (int k = 0 ; k < nodeCount ; k ++) {
105
+ List <IngestStats .ProcessorStat > stats = r .getNodes ().get (k ).getIngestStats ().getProcessorStats ().get (pipelineId );
106
+ for (IngestStats .ProcessorStat st : stats ) {
107
+ assertThat (st .getStats ().getIngestCurrent (), greaterThanOrEqualTo (0L ));
108
+ }
63
109
}
64
110
}
65
111
0 commit comments