Skip to content

Commit 5a62fd1

Browse files
authored
ESQL: Fix ShapeGeometryFieldMapperTests (and rename) (#122871)
Fixes #122661. The issue was caused by RandomIndexWriter (randomly) reshuffling the document writing order. Since this test also ensures that the documents are read in the input order, I've opted to use a regular IndexWriter instead. I've also renamed the class to AbstractShapeGeometryFieldMapperTests since it was originally renamed due to a misunderstanding of muted tests (which caused it to be muted again! Busted 😅).
1 parent 30a37c3 commit 5a62fd1

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

muted-tests.yml

-6
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,6 @@ tests:
130130
issue: https://github.com/elastic/elasticsearch/issues/118914
131131
- class: org.elasticsearch.xpack.security.authc.ldap.ActiveDirectoryRunAsIT
132132
issue: https://github.com/elastic/elasticsearch/issues/115727
133-
- class: org.elasticsearch.index.mapper.AbstractShapeGeometryFieldMapperTests
134-
method: testCartesianBoundsBlockLoader
135-
issue: https://github.com/elastic/elasticsearch/issues/119201
136133
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
137134
method: test {p0=transform/transforms_start_stop/Test start/stop/start transform}
138135
issue: https://github.com/elastic/elasticsearch/issues/119508
@@ -266,9 +263,6 @@ tests:
266263
- class: org.elasticsearch.smoketest.DocsClientYamlTestSuiteIT
267264
method: test {yaml=reference/snapshot-restore/apis/get-snapshot-api/line_488}
268265
issue: https://github.com/elastic/elasticsearch/issues/121611
269-
- class: org.elasticsearch.index.mapper.ShapeGeometryFieldMapperTests
270-
method: testCartesianBoundsBlockLoader
271-
issue: https://github.com/elastic/elasticsearch/issues/122661
272266
- class: org.elasticsearch.smoketest.DocsClientYamlTestSuiteIT
273267
method: test {yaml=reference/snapshot-restore/apis/get-snapshot-api/line_408}
274268
issue: https://github.com/elastic/elasticsearch/issues/122681

server/src/test/java/org/elasticsearch/index/mapper/ShapeGeometryFieldMapperTests.java server/src/test/java/org/elasticsearch/index/mapper/AbstractShapeGeometryFieldMapperTests.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
import org.apache.lucene.document.Document;
1313
import org.apache.lucene.geo.GeoEncodingUtils;
1414
import org.apache.lucene.index.DirectoryReader;
15+
import org.apache.lucene.index.IndexWriter;
16+
import org.apache.lucene.index.IndexWriterConfig;
1517
import org.apache.lucene.index.LeafReader;
1618
import org.apache.lucene.store.Directory;
17-
import org.apache.lucene.tests.index.RandomIndexWriter;
1819
import org.elasticsearch.common.geo.GeometryNormalizer;
1920
import org.elasticsearch.core.Strings;
2021
import org.elasticsearch.geo.GeometryTestUtils;
@@ -39,14 +40,14 @@
3940
import static org.apache.lucene.geo.GeoEncodingUtils.decodeLongitude;
4041
import static org.elasticsearch.common.geo.Orientation.RIGHT;
4142

42-
public class ShapeGeometryFieldMapperTests extends ESTestCase {
43+
public class AbstractShapeGeometryFieldMapperTests extends ESTestCase {
4344
public void testCartesianBoundsBlockLoader() throws IOException {
4445
testBoundsBlockLoader(
4546
CoordinateEncoder.CARTESIAN,
4647
() -> ShapeTestUtils.randomGeometryWithoutCircle(0, false),
4748
CartesianShapeIndexer::new,
4849
SpatialEnvelopeVisitor::visitCartesian,
49-
ShapeGeometryFieldMapperTests::makeCartesianRectangle
50+
AbstractShapeGeometryFieldMapperTests::makeCartesianRectangle
5051
);
5152
}
5253

@@ -58,7 +59,7 @@ public void ignoreTestGeoBoundsBlockLoader() throws IOException {
5859
() -> normalize(GeometryTestUtils.randomGeometryWithoutCircle(0, false)),
5960
field -> new GeoShapeIndexer(RIGHT, field),
6061
g -> SpatialEnvelopeVisitor.visitGeo(g, SpatialEnvelopeVisitor.WrapLongitude.WRAP),
61-
ShapeGeometryFieldMapperTests::makeGeoRectangle
62+
AbstractShapeGeometryFieldMapperTests::makeGeoRectangle
6263
);
6364
}
6465

@@ -72,7 +73,7 @@ public void ignoreTestRectangleCrossingDateline() throws IOException {
7273
geometries,
7374
field -> new GeoShapeIndexer(RIGHT, field),
7475
g -> SpatialEnvelopeVisitor.visitGeo(g, SpatialEnvelopeVisitor.WrapLongitude.WRAP),
75-
ShapeGeometryFieldMapperTests::makeGeoRectangle
76+
AbstractShapeGeometryFieldMapperTests::makeGeoRectangle
7677
);
7778
}
7879

@@ -100,7 +101,9 @@ private static void testBoundsBlockLoaderAux(
100101
) throws IOException {
101102
var loader = new AbstractShapeGeometryFieldMapper.AbstractShapeGeometryFieldType.BoundsBlockLoader("field");
102103
try (Directory directory = newDirectory()) {
103-
try (var iw = new RandomIndexWriter(random(), directory)) {
104+
// Since we also test that the documents are loaded in the correct order, we need to write them in order, so we can't use
105+
// RandomIndexWriter here.
106+
try (var iw = new IndexWriter(directory, new IndexWriterConfig(null /* analyzer */))) {
104107
for (Geometry geometry : geometries) {
105108
var shape = new BinaryShapeDocValuesField("field", encoder);
106109
shape.add(indexerFactory.apply("field").indexShape(geometry), geometry);

0 commit comments

Comments
 (0)