Skip to content

Commit 9969f56

Browse files
authored
[8.x] Remove legacy block loader test infrastructure (#127273) (#127413)
* Remove legacy block loader test infrastructure (#127273) (cherry picked from commit 26e2261) # Conflicts: # x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapperTests.java * fix
1 parent 020e3a7 commit 9969f56

File tree

32 files changed

+148
-778
lines changed

32 files changed

+148
-778
lines changed

modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/extras/MatchOnlyTextFieldMapperTests.java

-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.apache.lucene.tests.analysis.CannedTokenStream;
2222
import org.apache.lucene.tests.analysis.Token;
2323
import org.apache.lucene.tests.index.RandomIndexWriter;
24-
import org.apache.lucene.util.BytesRef;
2524
import org.elasticsearch.common.Strings;
2625
import org.elasticsearch.core.Tuple;
2726
import org.elasticsearch.index.mapper.DocumentMapper;
@@ -44,7 +43,6 @@
4443
import java.util.Collection;
4544
import java.util.Collections;
4645
import java.util.List;
47-
import java.util.function.Function;
4846
import java.util.stream.Collectors;
4947

5048
import static org.hamcrest.Matchers.containsString;
@@ -257,9 +255,4 @@ public void testDocValuesLoadedFromSynthetic() throws IOException {
257255
protected IngestScriptSupport ingestScriptSupport() {
258256
throw new AssumptionViolatedException("not supported");
259257
}
260-
261-
@Override
262-
protected Function<Object, Object> loadBlockExpected() {
263-
return v -> ((BytesRef) v).utf8ToString();
264-
}
265258
}

modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/extras/ScaledFloatFieldMapperTests.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,6 @@ public SyntheticSourceExample example(int maxVals) {
377377
return new SyntheticSourceExample(
378378
example.expectedForSyntheticSource(),
379379
example.expectedForSyntheticSource(),
380-
example.expectedForBlockLoader(),
381380
example.mapping()
382381
);
383382
}
@@ -400,7 +399,7 @@ public SyntheticSourceExample example(int maxValues) {
400399
if (v.malformedOutput == null) {
401400
return new SyntheticSourceExample(v.input, v.output, this::mapping);
402401
}
403-
return new SyntheticSourceExample(v.input, v.malformedOutput, null, this::mapping);
402+
return new SyntheticSourceExample(v.input, v.malformedOutput, this::mapping);
404403
}
405404
List<Value> values = randomList(1, maxValues, this::generateValue);
406405
List<Object> in = values.stream().map(Value::input).toList();
@@ -479,11 +478,6 @@ public List<SyntheticSourceInvalidExample> invalidExample() throws IOException {
479478
}
480479
}
481480

482-
protected BlockReaderSupport getSupportedReaders(MapperService mapper, String loaderFieldName) {
483-
assumeTrue("Disabled, tested by ScaledFloatFieldBlockLoaderTests instead", false);
484-
return null;
485-
}
486-
487481
@Override
488482
protected IngestScriptSupport ingestScriptSupport() {
489483
throw new AssumptionViolatedException("not supported");

modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/extras/TokenCountFieldMapperTests.java

+2-13
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
import java.util.Collections;
3737
import java.util.List;
3838
import java.util.Map;
39-
import java.util.Objects;
40-
import java.util.function.Function;
4139
import java.util.stream.Collectors;
4240

4341
import static org.hamcrest.Matchers.equalTo;
@@ -213,17 +211,13 @@ public boolean preservesExactSource() {
213211
public SyntheticSourceExample example(int maxValues) {
214212
if (randomBoolean()) {
215213
var value = generateValue();
216-
return new SyntheticSourceExample(value.text, value.text, value.tokenCount, this::mapping);
214+
return new SyntheticSourceExample(value.text, value.text, this::mapping);
217215
}
218216

219217
var values = randomList(1, 5, this::generateValue);
220-
221218
var textArray = values.stream().map(Value::text).toList();
222219

223-
var blockExpectedList = values.stream().map(Value::tokenCount).filter(Objects::nonNull).sorted().toList();
224-
var blockExpected = blockExpectedList.size() == 1 ? blockExpectedList.get(0) : blockExpectedList;
225-
226-
return new SyntheticSourceExample(textArray, textArray, blockExpected, this::mapping);
220+
return new SyntheticSourceExample(textArray, textArray, this::mapping);
227221
}
228222

229223
private record Value(String text, Integer tokenCount) {}
@@ -258,11 +252,6 @@ public List<SyntheticSourceInvalidExample> invalidExample() throws IOException {
258252
};
259253
}
260254

261-
protected Function<Object, Object> loadBlockExpected() {
262-
// we can get either a number from doc values or null
263-
return v -> v != null ? (Number) v : null;
264-
}
265-
266255
@Override
267256
protected IngestScriptSupport ingestScriptSupport() {
268257
throw new AssumptionViolatedException("not supported");

plugins/mapper-annotated-text/src/test/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapperTests.java

-11
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
import java.util.List;
6262
import java.util.Map;
6363
import java.util.Set;
64-
import java.util.function.Function;
6564

6665
import static org.hamcrest.Matchers.containsString;
6766
import static org.hamcrest.Matchers.equalTo;
@@ -666,16 +665,6 @@ protected SyntheticSourceSupport syntheticSourceSupport(boolean ignoreMalformed)
666665
return TextFieldFamilySyntheticSourceTestSetup.syntheticSourceSupport("annotated_text", false);
667666
}
668667

669-
@Override
670-
protected BlockReaderSupport getSupportedReaders(MapperService mapper, String loaderFieldName) {
671-
return TextFieldFamilySyntheticSourceTestSetup.getSupportedReaders(mapper, loaderFieldName);
672-
}
673-
674-
@Override
675-
protected Function<Object, Object> loadBlockExpected(BlockReaderSupport blockReaderSupport, boolean columnReader) {
676-
return TextFieldFamilySyntheticSourceTestSetup.loadBlockExpected(blockReaderSupport, columnReader);
677-
}
678-
679668
@Override
680669
protected void validateRoundTripReader(String syntheticSource, DirectoryReader reader, DirectoryReader roundTripReader) {
681670
TextFieldFamilySyntheticSourceTestSetup.validateRoundTripReader(syntheticSource, reader, roundTripReader);

server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -1020,9 +1020,13 @@ protected String delegatingTo() {
10201020
return new BlockStoredFieldsReader.BytesFromStringsBlockLoader(name());
10211021
}
10221022

1023-
// _ignored_source field will only be present if text field is not stored
1024-
// and there is no syntheticSourceDelegate
1025-
if (isSyntheticSource && syntheticSourceDelegate == null) {
1023+
// _ignored_source field will contain entries for this field if it is not stored
1024+
// and there is no syntheticSourceDelegate.
1025+
// See #syntheticSourceSupport().
1026+
// But if a text field is a multi field it won't have an entry in _ignored_source.
1027+
// The parent might, but we don't have enough context here to figure this out.
1028+
// So we bail.
1029+
if (isSyntheticSource && syntheticSourceDelegate == null && parentField == null) {
10261030
return fallbackSyntheticSourceBlockLoader();
10271031
}
10281032

server/src/test/java/org/elasticsearch/index/mapper/BooleanFieldMapperTests.java

-8
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.io.IOException;
3030
import java.time.Instant;
3131
import java.util.List;
32-
import java.util.function.Function;
3332

3433
import static org.hamcrest.Matchers.containsString;
3534
import static org.hamcrest.Matchers.equalTo;
@@ -371,19 +370,12 @@ public SyntheticSourceExample example(int maxVals) throws IOException {
371370
return new SyntheticSourceExample(
372371
example.expectedForSyntheticSource(),
373372
example.expectedForSyntheticSource(),
374-
example.expectedForBlockLoader(),
375373
example.mapping()
376374
);
377375
}
378376
};
379377
}
380378

381-
@Override
382-
protected Function<Object, Object> loadBlockExpected() {
383-
// Just assert that we expect a boolean. Otherwise no munging.
384-
return v -> (Boolean) v;
385-
}
386-
387379
protected IngestScriptSupport ingestScriptSupport() {
388380
return new IngestScriptSupport() {
389381
@Override

server/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java

+3-29
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import java.time.ZonedDateTime;
3434
import java.util.Comparator;
3535
import java.util.List;
36-
import java.util.function.Function;
3736
import java.util.stream.Stream;
3837

3938
import static org.elasticsearch.index.mapper.DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER;
@@ -595,15 +594,10 @@ public SyntheticSourceExample example(int maxValues) {
595594
if (randomBoolean()) {
596595
Value v = generateValue();
597596
if (v.malformedOutput != null) {
598-
return new SyntheticSourceExample(v.input, v.malformedOutput, null, this::mapping);
597+
return new SyntheticSourceExample(v.input, v.malformedOutput, this::mapping);
599598
}
600599

601-
return new SyntheticSourceExample(
602-
v.input,
603-
v.output,
604-
resolution.convert(Instant.from(formatter.parse(v.output))),
605-
this::mapping
606-
);
600+
return new SyntheticSourceExample(v.input, v.output, this::mapping);
607601
}
608602

609603
List<Value> values = randomList(1, maxValues, this::generateValue);
@@ -625,11 +619,7 @@ public SyntheticSourceExample example(int maxValues) {
625619
List<Object> outList = Stream.concat(outputFromDocValues.stream(), malformedOutput).toList();
626620
Object out = outList.size() == 1 ? outList.get(0) : outList;
627621

628-
List<Long> outBlockList = outputFromDocValues.stream()
629-
.map(v -> resolution.convert(Instant.from(formatter.parse(v))))
630-
.toList();
631-
Object outBlock = outBlockList.size() == 1 ? outBlockList.get(0) : outBlockList;
632-
return new SyntheticSourceExample(in, out, outBlock, this::mapping);
622+
return new SyntheticSourceExample(in, out, this::mapping);
633623
}
634624

635625
private record Value(Object input, String output, Object malformedOutput) {}
@@ -727,22 +717,6 @@ public void execute() {
727717
};
728718
}
729719

730-
@Override
731-
protected Function<Object, Object> loadBlockExpected() {
732-
return v -> asJacksonNumberOutput(((Number) v).longValue());
733-
}
734-
735-
protected static Object asJacksonNumberOutput(long l) {
736-
// If a long value fits in int, Jackson will write it as int in NumberOutput.outputLong()
737-
// and we hit this during serialization of expected values.
738-
// Code below mimics that behaviour in order for matching to work.
739-
if (l < 0 && l >= Integer.MIN_VALUE || l >= 0 && l <= Integer.MAX_VALUE) {
740-
return (int) l;
741-
} else {
742-
return l;
743-
}
744-
}
745-
746720
public void testLegacyField() throws Exception {
747721
// check that unknown date formats are treated leniently on old indices
748722
MapperService service = createMapperService(IndexVersion.fromId(5000099), Settings.EMPTY, () -> false, mapping(b -> {

server/src/test/java/org/elasticsearch/index/mapper/FloatFieldMapperTests.java

-10
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import java.io.IOException;
1616
import java.util.List;
17-
import java.util.function.Function;
1817

1918
public class FloatFieldMapperTests extends NumberFieldMapperTests {
2019

@@ -61,15 +60,6 @@ protected SyntheticSourceSupport syntheticSourceSupportForKeepTests(boolean igno
6160

6261
}
6362

64-
@Override
65-
protected Function<Object, Object> loadBlockExpected() {
66-
return v -> {
67-
// The test converts the float into a string so we do do
68-
Number n = (Number) v;
69-
return Double.parseDouble(Float.toString(n.floatValue()));
70-
};
71-
}
72-
7363
@Override
7464
protected IngestScriptSupport ingestScriptSupport() {
7565
throw new AssumptionViolatedException("not supported");

server/src/test/java/org/elasticsearch/index/mapper/GeoPointFieldMapperTests.java

+4-56
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@
1818
import org.elasticsearch.common.geo.GeoJson;
1919
import org.elasticsearch.common.geo.GeoPoint;
2020
import org.elasticsearch.geo.GeometryTestUtils;
21-
import org.elasticsearch.geometry.Geometry;
2221
import org.elasticsearch.geometry.Point;
23-
import org.elasticsearch.geometry.utils.GeometryValidator;
24-
import org.elasticsearch.geometry.utils.WellKnownBinary;
2522
import org.elasticsearch.geometry.utils.WellKnownText;
2623
import org.elasticsearch.index.IndexMode;
2724
import org.elasticsearch.index.IndexSettings;
@@ -37,7 +34,6 @@
3734
import java.util.List;
3835
import java.util.Map;
3936
import java.util.Objects;
40-
import java.util.function.Function;
4137
import java.util.function.Supplier;
4238
import java.util.stream.Stream;
4339

@@ -611,13 +607,13 @@ public SyntheticSourceExample example(int maxVals) {
611607
if (randomBoolean()) {
612608
Value v = generateValue();
613609
if (v.malformedOutput != null) {
614-
return new SyntheticSourceExample(v.input, v.malformedOutput, null, this::mapping);
610+
return new SyntheticSourceExample(v.input, v.malformedOutput, this::mapping);
615611
}
616612

617613
if (columnReader) {
618-
return new SyntheticSourceExample(v.input, decode(encode(v.output)), encode(v.output), this::mapping);
614+
return new SyntheticSourceExample(v.input, decode(encode(v.output)), this::mapping);
619615
}
620-
return new SyntheticSourceExample(v.input, v.output, v.output.toWKT(), this::mapping);
616+
return new SyntheticSourceExample(v.input, v.output, this::mapping);
621617

622618
}
623619
List<Value> values = randomList(1, maxVals, this::generateValue);
@@ -635,18 +631,7 @@ public SyntheticSourceExample example(int maxVals) {
635631
List<Object> outList = Stream.concat(outputFromDocValues.stream(), malformedValues).toList();
636632
Object out = outList.size() == 1 ? outList.get(0) : outList;
637633

638-
if (columnReader) {
639-
// When reading doc-values, the block is a list of encoded longs
640-
List<Long> outBlockList = outputFromDocValues.stream().map(this::encode).toList();
641-
Object outBlock = outBlockList.size() == 1 ? outBlockList.get(0) : outBlockList;
642-
return new SyntheticSourceExample(in, out, outBlock, this::mapping);
643-
} else {
644-
// When reading row-stride, the block is a list of WKT encoded BytesRefs.
645-
// Values are ordered in order of input.
646-
List<String> outBlockList = values.stream().filter(v -> v.malformedOutput == null).map(v -> v.output.toWKT()).toList();
647-
Object outBlock = outBlockList.size() == 1 ? outBlockList.get(0) : outBlockList;
648-
return new SyntheticSourceExample(in, out, outBlock, this::mapping);
649-
}
634+
return new SyntheticSourceExample(in, out, this::mapping);
650635
}
651636

652637
private record Value(Object input, GeoPoint output, Object malformedOutput) {}
@@ -736,41 +721,4 @@ public void testSyntheticSourceKeepArrays() {
736721
protected IngestScriptSupport ingestScriptSupport() {
737722
throw new AssumptionViolatedException("not supported");
738723
}
739-
740-
@Override
741-
protected Function<Object, Object> loadBlockExpected() {
742-
throw new IllegalStateException("Should never reach here, call loadBlockExpected(BlockReaderSupport, boolean) instead");
743-
}
744-
745-
@Override
746-
protected Function<Object, Object> loadBlockExpected(BlockReaderSupport blockReaderSupport, boolean columnReader) {
747-
if (columnReader) {
748-
// When using column reader, we expect the output to be doc-values (which means encoded longs)
749-
return v -> asJacksonNumberOutput(((Number) v).longValue());
750-
} else {
751-
// When using row-stride reader, we expect the output to be WKT encoded BytesRef
752-
return v -> asWKT((BytesRef) v);
753-
}
754-
}
755-
756-
protected static Object asJacksonNumberOutput(long l) {
757-
// Cast to int to mimic jackson-core behaviour in NumberOutput.outputLong()
758-
if (l < 0 && l >= Integer.MIN_VALUE || l >= 0 && l <= Integer.MAX_VALUE) {
759-
return (int) l;
760-
} else {
761-
return l;
762-
}
763-
}
764-
765-
protected static Object asWKT(BytesRef value) {
766-
// Internally we use WKB in BytesRef, but for test assertions we want to use WKT for readability
767-
Geometry geometry = WellKnownBinary.fromWKB(GeometryValidator.NOOP, false, value.bytes);
768-
return WellKnownText.toWKT(geometry);
769-
}
770-
771-
@Override
772-
protected BlockReaderSupport getSupportedReaders(MapperService mapper, String loaderFieldName) {
773-
MappedFieldType ft = mapper.fieldType(loaderFieldName);
774-
return new BlockReaderSupport(ft.hasDocValues(), false, mapper, loaderFieldName);
775-
}
776724
}

server/src/test/java/org/elasticsearch/index/mapper/HalfFloatFieldMapperTests.java

-12
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import java.io.IOException;
1818
import java.util.List;
19-
import java.util.function.Function;
2019

2120
public class HalfFloatFieldMapperTests extends NumberFieldMapperTests {
2221

@@ -65,17 +64,6 @@ protected SyntheticSourceSupport syntheticSourceSupportForKeepTests(boolean igno
6564

6665
}
6766

68-
@Override
69-
protected Function<Object, Object> loadBlockExpected() {
70-
return v -> {
71-
// The test converts the float into a string so we do do
72-
Number n = (Number) v;
73-
return Double.parseDouble(
74-
Float.toString(HalfFloatPoint.sortableShortToHalfFloat(HalfFloatPoint.halfFloatToSortableShort(n.floatValue())))
75-
);
76-
};
77-
}
78-
7967
@Override
8068
protected IngestScriptSupport ingestScriptSupport() {
8169
throw new AssumptionViolatedException("not supported");

server/src/test/java/org/elasticsearch/index/mapper/IpFieldMapperTests.java

-6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import java.time.Instant;
3232
import java.util.ArrayList;
3333
import java.util.List;
34-
import java.util.function.Function;
3534
import java.util.function.Supplier;
3635
import java.util.stream.Collectors;
3736

@@ -435,11 +434,6 @@ public void execute() {
435434
};
436435
}
437436

438-
@Override
439-
protected Function<Object, Object> loadBlockExpected() {
440-
return v -> InetAddresses.toAddrString(InetAddressPoint.decode(BytesRef.deepCopyOf((BytesRef) v).bytes));
441-
}
442-
443437
@Override
444438
protected String randomSyntheticSourceKeep() {
445439
return "all";

0 commit comments

Comments
 (0)