19
19
20
20
package org .elasticsearch .index .fielddata ;
21
21
22
- import org .elasticsearch .common .geo .GeoPoint ;
23
- import org .elasticsearch .common .settings .Settings ;
22
+ import org .elasticsearch .common .geo .GeoPoint ;;
24
23
import org .elasticsearch .index .fielddata .ScriptDocValues .Longs ;
25
24
import org .elasticsearch .index .fielddata .ScriptDocValues .Dates ;
26
25
import org .elasticsearch .index .fielddata .ScriptDocValues .Booleans ;
27
- import org .elasticsearch .plugins .ScriptPlugin ;
28
- import org .elasticsearch .script .MockScriptEngine ;
29
- import org .elasticsearch .script .ScriptContext ;
30
- import org .elasticsearch .script .ScriptEngine ;
31
- import org .elasticsearch .script .ScriptModule ;
32
26
import org .elasticsearch .test .ESTestCase ;
33
27
34
28
import org .joda .time .DateTime ;
35
29
import org .joda .time .DateTimeZone ;
36
30
import org .joda .time .ReadableDateTime ;
37
31
import java .io .IOException ;
38
- import java .util .Collection ;
39
- import java .util .Collections ;
32
+ import java .util .HashSet ;
33
+ import java .util .Set ;
34
+ import java .util .function .BiConsumer ;
40
35
41
- import static java .util .Collections .singletonList ;
36
+ import static org .hamcrest .Matchers .contains ;
37
+ import static org .hamcrest .Matchers .equalTo ;
42
38
43
39
public class ScriptDocValuesMissingV6BehaviourTests extends ESTestCase {
44
40
45
- public void testScriptMissingValuesWarning (){
46
- new ScriptModule (Settings .EMPTY , singletonList (new ScriptPlugin () {
47
- @ Override
48
- public ScriptEngine getScriptEngine (Settings settings , Collection <ScriptContext <?>> contexts ) {
49
- return new MockScriptEngine (MockScriptEngine .NAME , Collections .singletonMap ("1" , script -> "1" ));
50
- }
51
- }));
52
- assertWarnings ("Script: returning default values for missing document values is deprecated. " +
53
- "Set system property '-Des.scripting.exception_for_missing_value=true' " +
54
- "to make behaviour compatible with future major versions." );
55
- }
56
-
57
41
public void testZeroForMissingValueLong () throws IOException {
58
42
long [][] values = new long [between (3 , 10 )][];
59
43
for (int d = 0 ; d < values .length ; d ++) {
60
44
values [d ] = new long [0 ];
61
45
}
62
- Longs longs = wrap (values );
46
+ Set <String > warnings = new HashSet <>();
47
+ Longs longs = wrap (values , (key , deprecationMessage ) -> { warnings .add (deprecationMessage ); });
63
48
for (int round = 0 ; round < 10 ; round ++) {
64
49
int d = between (0 , values .length - 1 );
65
50
longs .setNextDocId (d );
66
51
assertEquals (0 , longs .getValue ());
67
52
}
53
+ assertThat (warnings , contains (equalTo (
54
+ "returning default values for missing document values is deprecated. " +
55
+ "Set system property '-Des.scripting.exception_for_missing_value=true' " +
56
+ "to make behaviour compatible with future major versions!" )));
68
57
}
69
58
70
59
public void testEpochForMissingValueDate () throws IOException {
@@ -73,36 +62,52 @@ public void testEpochForMissingValueDate() throws IOException {
73
62
for (int d = 0 ; d < values .length ; d ++) {
74
63
values [d ] = new long [0 ];
75
64
}
76
- Dates dates = wrapDates (values );
65
+ Set <String > warnings = new HashSet <>();
66
+ Dates dates = wrapDates (values , (key , deprecationMessage ) -> { warnings .add (deprecationMessage ); });
77
67
for (int round = 0 ; round < 10 ; round ++) {
78
68
int d = between (0 , values .length - 1 );
79
69
dates .setNextDocId (d );
80
70
assertEquals (EPOCH , dates .getValue ());
81
71
}
72
+ assertThat (warnings , contains (equalTo (
73
+ "returning default values for missing document values is deprecated. " +
74
+ "Set system property '-Des.scripting.exception_for_missing_value=true' " +
75
+ "to make behaviour compatible with future major versions!" )));
82
76
}
83
77
84
78
public void testFalseForMissingValueBoolean () throws IOException {
85
79
long [][] values = new long [between (3 , 10 )][];
86
80
for (int d = 0 ; d < values .length ; d ++) {
87
81
values [d ] = new long [0 ];
88
82
}
89
- Booleans bools = wrapBooleans (values );
83
+ Set <String > warnings = new HashSet <>();
84
+ Booleans bools = wrapBooleans (values , (key , deprecationMessage ) -> { warnings .add (deprecationMessage ); });
90
85
for (int round = 0 ; round < 10 ; round ++) {
91
86
int d = between (0 , values .length - 1 );
92
87
bools .setNextDocId (d );
93
88
assertEquals (false , bools .getValue ());
94
89
}
90
+ assertThat (warnings , contains (equalTo (
91
+ "returning default values for missing document values is deprecated. " +
92
+ "Set system property '-Des.scripting.exception_for_missing_value=true' " +
93
+ "to make behaviour compatible with future major versions!" )));
95
94
}
96
95
97
96
public void testNullForMissingValueGeo () throws IOException {
97
+ Set <String > warnings = new HashSet <>();
98
98
final MultiGeoPointValues values = wrap (new GeoPoint [0 ]);
99
- final ScriptDocValues .GeoPoints script = new ScriptDocValues .GeoPoints (values );
99
+ final ScriptDocValues .GeoPoints script = new ScriptDocValues .GeoPoints (
100
+ values , (key , deprecationMessage ) -> { warnings .add (deprecationMessage ); });
100
101
script .setNextDocId (0 );
101
102
assertEquals (null , script .getValue ());
103
+ assertThat (warnings , contains (equalTo (
104
+ "returning default values for missing document values is deprecated. " +
105
+ "Set system property '-Des.scripting.exception_for_missing_value=true' " +
106
+ "to make behaviour compatible with future major versions!" )));
102
107
}
103
108
104
109
105
- private Longs wrap (long [][] values ) {
110
+ private Longs wrap (long [][] values , BiConsumer < String , String > deprecationCallback ) {
106
111
return new Longs (new AbstractSortedNumericDocValues () {
107
112
long [] current ;
108
113
int i ;
@@ -120,10 +125,10 @@ public int docValueCount() {
120
125
public long nextValue () {
121
126
return current [i ++];
122
127
}
123
- });
128
+ }, deprecationCallback );
124
129
}
125
130
126
- private Booleans wrapBooleans (long [][] values ) {
131
+ private Booleans wrapBooleans (long [][] values , BiConsumer < String , String > deprecationCallback ) {
127
132
return new Booleans (new AbstractSortedNumericDocValues () {
128
133
long [] current ;
129
134
int i ;
@@ -141,10 +146,10 @@ public int docValueCount() {
141
146
public long nextValue () {
142
147
return current [i ++];
143
148
}
144
- });
149
+ }, deprecationCallback );
145
150
}
146
151
147
- private Dates wrapDates (long [][] values ) {
152
+ private Dates wrapDates (long [][] values , BiConsumer < String , String > deprecationCallback ) {
148
153
return new Dates (new AbstractSortedNumericDocValues () {
149
154
long [] current ;
150
155
int i ;
@@ -162,7 +167,7 @@ public int docValueCount() {
162
167
public long nextValue () {
163
168
return current [i ++];
164
169
}
165
- });
170
+ }, deprecationCallback );
166
171
}
167
172
168
173
0 commit comments