19
19
20
20
package org .elasticsearch .test ;
21
21
22
+ import com .carrotsearch .randomizedtesting .RandomizedTest ;
23
+ import com .carrotsearch .randomizedtesting .SeedUtils ;
24
+
22
25
import org .apache .lucene .index .IndexReader ;
23
26
import org .apache .lucene .util .Accountable ;
24
27
import org .elasticsearch .Version ;
86
89
import java .util .HashMap ;
87
90
import java .util .List ;
88
91
import java .util .Map ;
92
+ import java .util .concurrent .Callable ;
89
93
import java .util .concurrent .ExecutionException ;
90
94
import java .util .function .Function ;
91
95
import java .util .stream .Stream ;
@@ -126,14 +130,13 @@ public abstract class AbstractBuilderTestCase extends ESTestCase {
126
130
ALIAS_TO_CONCRETE_FIELD_NAME .put (GEO_POINT_ALIAS_FIELD_NAME , GEO_POINT_FIELD_NAME );
127
131
}
128
132
129
- protected static Version indexVersionCreated ;
130
-
131
133
private static ServiceHolder serviceHolder ;
132
134
private static int queryNameId = 0 ;
133
135
private static Settings nodeSettings ;
134
136
private static Index index ;
135
137
private static String [] currentTypes ;
136
138
protected static String [] randomTypes ;
139
+ private static long nowInMillis ;
137
140
138
141
protected static Index getIndex () {
139
142
return index ;
@@ -162,6 +165,7 @@ public static void beforeClass() {
162
165
.build ();
163
166
164
167
index = new Index (randomAlphaOfLengthBetween (1 , 10 ), "_na_" );
168
+ nowInMillis = randomNonNegativeLong ();
165
169
166
170
// Set a single type in the index
167
171
switch (random ().nextInt (3 )) {
@@ -211,15 +215,19 @@ protected static String createUniqueRandomName() {
211
215
return queryName ;
212
216
}
213
217
214
- protected Settings indexSettings () {
218
+ protected Settings createTestIndexSettings () {
215
219
// we have to prefer CURRENT since with the range of versions we support it's rather unlikely to get the current actually.
216
- indexVersionCreated = randomBoolean () ? Version .CURRENT
217
- : VersionUtils .randomVersionBetween (random (), null , Version .CURRENT );
220
+ Version indexVersionCreated = randomBoolean () ? Version .CURRENT
221
+ : VersionUtils .randomVersionBetween (random (), Version . V_6_0_0 , Version .CURRENT );
218
222
return Settings .builder ()
219
223
.put (IndexMetaData .SETTING_VERSION_CREATED , indexVersionCreated )
220
224
.build ();
221
225
}
222
226
227
+ protected static IndexSettings indexSettings () {
228
+ return serviceHolder .idxSettings ;
229
+ }
230
+
223
231
protected static String expectedFieldName (String builderFieldName ) {
224
232
if (currentTypes .length == 0 || !isSingleType ()) {
225
233
return builderFieldName ;
@@ -234,10 +242,20 @@ public static void afterClass() throws Exception {
234
242
}
235
243
236
244
@ Before
237
- public void beforeTest () throws IOException {
245
+ public void beforeTest () throws Exception {
238
246
if (serviceHolder == null ) {
239
- serviceHolder = new ServiceHolder (nodeSettings , indexSettings (), getPlugins (), this );
247
+ // we initialize the serviceHolder and serviceHolderWithNoType just once, but need some
248
+ // calls to the randomness source during its setup. In order to not mix these calls with
249
+ // the randomness source that is later used in the test method, we use the master seed during
250
+ // this setup
251
+ long masterSeed = SeedUtils .parseSeed (RandomizedTest .getContext ().getRunnerSeedAsString ());
252
+ RandomizedTest .getContext ().runWithPrivateRandomness (masterSeed , (Callable <Void >) () -> {
253
+ serviceHolder = new ServiceHolder (nodeSettings , createTestIndexSettings (), getPlugins (), nowInMillis ,
254
+ AbstractBuilderTestCase .this );
255
+ return null ;
256
+ });
240
257
}
258
+
241
259
serviceHolder .clientInvocationHandler .delegate = this ;
242
260
}
243
261
@@ -333,11 +351,12 @@ private static class ServiceHolder implements Closeable {
333
351
private final BitsetFilterCache bitsetFilterCache ;
334
352
private final ScriptService scriptService ;
335
353
private final Client client ;
336
- private final long nowInMillis = randomNonNegativeLong () ;
354
+ private final long nowInMillis ;
337
355
338
- ServiceHolder (Settings nodeSettings , Settings indexSettings ,
339
- Collection < Class <? extends Plugin >> plugins , AbstractBuilderTestCase testCase ) throws IOException {
356
+ ServiceHolder (Settings nodeSettings , Settings indexSettings , Collection < Class <? extends Plugin >> plugins , long nowInMillis ,
357
+ AbstractBuilderTestCase testCase ) throws IOException {
340
358
Environment env = InternalSettingsPreparer .prepareEnvironment (nodeSettings , null );
359
+ this .nowInMillis = nowInMillis ;
341
360
PluginsService pluginsService ;
342
361
pluginsService = new PluginsService (nodeSettings , null , env .modulesFile (), env .pluginsFile (), plugins );
343
362
0 commit comments