Skip to content

Commit f0f32c3

Browse files
committed
fixing tests
1 parent b444519 commit f0f32c3

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

server/src/test/java/org/elasticsearch/action/bulk/TransportSimulateBulkActionTests.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ public void onResponse(BulkResponse response) {
185185
"_index": "%s",
186186
"_version": -3,
187187
"_source": %s,
188-
"executed_pipelines": [%s]
188+
"executed_pipelines": [%s],
189+
"effective_mapping":{}
189190
}""",
190191
indexRequest.id(),
191192
indexRequest.index(),
@@ -319,7 +320,8 @@ public void onResponse(BulkResponse response) {
319320
"_version": -3,
320321
"_source": %s,
321322
"executed_pipelines": [%s],
322-
"error":{"type":"exception","reason":"invalid mapping"}
323+
"error":{"type":"exception","reason":"invalid mapping"},
324+
"effective_mapping":{"_doc":{"dynamic":"strict"}}
323325
}""",
324326
indexRequest.id(),
325327
indexName,
@@ -346,7 +348,8 @@ public void onResponse(BulkResponse response) {
346348
"_index": "%s",
347349
"_version": -3,
348350
"_source": %s,
349-
"executed_pipelines": [%s]
351+
"executed_pipelines": [%s],
352+
"effective_mapping":{"_doc":{"dynamic":"strict"}}
350353
}""",
351354
indexRequest.id(),
352355
indexName,
@@ -373,7 +376,9 @@ public void onFailure(Exception e) {
373376
};
374377
when(indicesService.withTempIndexService(any(), any())).thenAnswer((Answer<?>) invocation -> {
375378
IndexMetadata imd = invocation.getArgument(0);
376-
if (indicesWithInvalidMappings.contains(imd.getIndex().getName())) {
379+
if (indicesWithInvalidMappings.contains(imd.getIndex().getName())
380+
// We only want to throw exceptions inside TransportSimulateBulkAction:
381+
&& invocation.getArgument(1).getClass().getSimpleName().contains("TransportSimulateBulkAction")) {
377382
throw new ElasticsearchException("invalid mapping");
378383
} else {
379384
// we don't actually care what is returned, as long as no exception is thrown the request is considered valid:

server/src/test/java/org/elasticsearch/rest/action/ingest/RestSimulateIngestActionTests.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.action.bulk.BulkResponse;
1616
import org.elasticsearch.action.ingest.SimulateIndexResponse;
1717
import org.elasticsearch.common.bytes.BytesReference;
18+
import org.elasticsearch.common.compress.CompressedXContent;
1819
import org.elasticsearch.common.xcontent.XContentHelper;
1920
import org.elasticsearch.rest.AbstractRestChannel;
2021
import org.elasticsearch.rest.RestResponse;
@@ -23,6 +24,7 @@
2324
import org.elasticsearch.xcontent.NamedXContentRegistry;
2425
import org.elasticsearch.xcontent.XContentType;
2526

27+
import java.io.IOException;
2628
import java.nio.ByteBuffer;
2729
import java.nio.charset.StandardCharsets;
2830
import java.util.List;
@@ -157,9 +159,9 @@ private void testInputJsonConvertsToOutputJson(String inputJson, String expected
157159
public void testSimulateIngestRestToXContentListener() throws Exception {
158160
// First, make sure it works with success responses:
159161
BulkItemResponse[] responses = new BulkItemResponse[3];
160-
responses[0] = getSuccessBulkItemResponse("123", "{\"foo\": \"bar\"}");
162+
responses[0] = getSuccessBulkItemResponse("123", "{\"foo\": \"bar\"}", false);
161163
responses[1] = getFailureBulkItemResponse("678", "This has failed");
162-
responses[2] = getSuccessBulkItemResponse("456", "{\"bar\": \"baz\"}");
164+
responses[2] = getSuccessBulkItemResponse("456", "{\"bar\": \"baz\"}", true);
163165
BulkResponse bulkResponse = new BulkResponse(responses, randomLongBetween(0, 50000));
164166
String expectedXContent = """
165167
{
@@ -183,7 +185,8 @@ public void testSimulateIngestRestToXContentListener() throws Exception {
183185
{
184186
"field" : "def"
185187
}
186-
]
188+
],
189+
"effective_mapping" : { }
187190
}
188191
},
189192
{
@@ -215,7 +218,14 @@ public void testSimulateIngestRestToXContentListener() throws Exception {
215218
{
216219
"field" : "def"
217220
}
218-
]
221+
],
222+
"effective_mapping" : {
223+
"properties" : {
224+
"foo" : {
225+
"type" : "keyword"
226+
}
227+
}
228+
}
219229
}
220230
}
221231
]
@@ -231,7 +241,7 @@ private BulkItemResponse getFailureBulkItemResponse(String id, String failureMes
231241
);
232242
}
233243

234-
private BulkItemResponse getSuccessBulkItemResponse(String id, String source) {
244+
private BulkItemResponse getSuccessBulkItemResponse(String id, String source, boolean hasMapping) throws IOException {
235245
ByteBuffer[] sourceByteBuffer = new ByteBuffer[1];
236246
sourceByteBuffer[0] = ByteBuffer.wrap(source.getBytes(StandardCharsets.UTF_8));
237247
return BulkItemResponse.success(
@@ -246,7 +256,7 @@ private BulkItemResponse getSuccessBulkItemResponse(String id, String source) {
246256
List.of("pipeline1", "pipeline2"),
247257
List.of("abc", "def"),
248258
null,
249-
null
259+
hasMapping ? new CompressedXContent("{\"properties\":{\"foo\":{\"type\":\"keyword\"}}}") : null
250260
)
251261
);
252262
}

0 commit comments

Comments
 (0)