Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Fix failure in AppendProcessorTests.testAppendingToListWithDuplicatesDisallowed #63962

Merged
merged 1 commit into from
Oct 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.elasticsearch.ingest.common;

import org.elasticsearch.common.util.set.Sets;
import org.elasticsearch.ingest.IngestDocument;
import org.elasticsearch.ingest.IngestDocument.Metadata;
import org.elasticsearch.ingest.Processor;
Expand All @@ -34,6 +35,8 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;
Expand Down Expand Up @@ -192,23 +195,26 @@ public void testAppendingUniqueValueToScalar() throws Exception {

public void testAppendingToListWithDuplicatesDisallowed() throws Exception {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
List<String> list = new ArrayList<>();
int size = randomIntBetween(0, 10);
for (int i = 0; i < size; i++) {
list.add(randomAlphaOfLengthBetween(1, 10));
}
List<String> list = Stream.generate(() -> randomAlphaOfLengthBetween(1, 10)).limit(size).collect(Collectors.toList());
String originalField = RandomDocumentPicks.addRandomField(random(), ingestDocument, list);
List<String> expectedValues = new ArrayList<>(list);
List<String> existingValues = randomSubsetOf(list);
int uniqueValuesSize = randomIntBetween(0, 10);
Set<String> uniqueValues = new HashSet<>(uniqueValuesSize);
while (uniqueValues.size() < uniqueValuesSize) {
uniqueValues.add(randomValueOtherThanMany(list::contains, () -> randomAlphaOfLengthBetween(1, 10)));
}

// generate new values
int nonexistingValuesSize = randomIntBetween(0, 10);
Set<String> newValues = Stream.generate(() -> randomAlphaOfLengthBetween(1, 10))
.limit(nonexistingValuesSize)
.collect(Collectors.toSet());

// create a set using the new values making sure there are no overlapping values already present in the existing values
Set<String> nonexistingValues = Sets.difference(newValues, new HashSet<>(existingValues));
List<String> valuesToAppend = new ArrayList<>(existingValues);
valuesToAppend.addAll(uniqueValues);
expectedValues.addAll(uniqueValues);
valuesToAppend.addAll(nonexistingValues);
expectedValues.addAll(nonexistingValues);
Collections.sort(valuesToAppend);

// attempt to append both new and existing values
Processor appendProcessor = createAppendProcessor(originalField, valuesToAppend, false);
appendProcessor.execute(ingestDocument);
List<?> fieldValue = ingestDocument.getFieldValue(originalField, List.class);
Expand Down