Skip to content

Commit 5abc390

Browse files
committed
Updates tests to be compatible with ES v9 Bulk API error message format
1 parent 16baed4 commit 5abc390

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

sdks/java/io/elasticsearch-tests/elasticsearch-tests-common/src/main/java/org/apache/beam/sdk/io/elasticsearch/ElasticsearchIOTestCommon.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import java.util.ArrayList;
6161
import java.util.Arrays;
6262
import java.util.Collections;
63+
import java.util.HashSet;
6364
import java.util.List;
6465
import java.util.Map;
6566
import java.util.Set;
@@ -383,8 +384,8 @@ public boolean matches(Object o) {
383384
// the other messages are matched using .+
384385
return message.matches(
385386
"(?is).*Error writing to Elasticsearch, some elements could not be inserted"
386-
+ ".*Document id .+: failed to parse \\(.+\\).*Caused by: .+ \\(.+\\).*"
387-
+ "Document id .+: failed to parse \\(.+\\).*Caused by: .+ \\(.+\\).*");
387+
+ ".*Document id .+:.*failed to parse.*\\(.+\\).*Caused by: .+ \\(.+\\).*"
388+
+ "Document id .+:.*failed to parse.*\\(.+\\).*Caused by: .+ \\(.+\\).*");
388389
}
389390
});
390391

@@ -429,12 +430,15 @@ void testWriteWithErrorsReturned() throws Exception {
429430
}
430431

431432
void testWriteWithErrorsReturnedAllowedErrors() throws Exception {
433+
Set<String> allowedErrors = new HashSet<>();
434+
allowedErrors.add("json_parse_exception");
435+
allowedErrors.add("document_parsing_exception");
432436
Write write =
433437
ElasticsearchIO.write()
434438
.withConnectionConfiguration(connectionConfiguration)
435439
.withMaxBatchSize(BATCH_SIZE)
436440
.withThrowWriteErrors(false)
437-
.withAllowableResponseErrors(Collections.singleton("json_parse_exception"));
441+
.withAllowableResponseErrors(allowedErrors);
438442

439443
List<String> data =
440444
ElasticsearchIOTestUtils.createDocuments(
@@ -503,11 +507,14 @@ void testWriteWithElasticClientResponseException() throws Exception {
503507
}
504508

505509
void testWriteWithAllowedErrors() throws Exception {
510+
Set<String> allowedErrors = new HashSet<>();
511+
allowedErrors.add("json_parse_exception");
512+
allowedErrors.add("document_parsing_exception");
506513
Write write =
507514
ElasticsearchIO.write()
508515
.withConnectionConfiguration(connectionConfiguration)
509516
.withMaxBatchSize(BATCH_SIZE)
510-
.withAllowableResponseErrors(Collections.singleton("json_parse_exception"));
517+
.withAllowableResponseErrors(allowedErrors);
511518
List<String> input =
512519
ElasticsearchIOTestUtils.createDocuments(
513520
numDocs, ElasticsearchIOTestUtils.InjectionMode.INJECT_SOME_INVALID_DOCS);

0 commit comments

Comments
 (0)