Skip to content

Commit be14c60

Browse files
Fix DissectParserTests expecting unique keys (#39262)
Fixes a bug in DissectParserTests where the tests expected dissect keys to be unique but were not. Closes #39244
1 parent cf1f3ef commit be14c60

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

libs/dissect/src/test/java/org/elasticsearch/dissect/DissectParserTests.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
import org.elasticsearch.test.ESTestCase;
2525
import org.hamcrest.CoreMatchers;
2626
import org.hamcrest.Matchers;
27+
import org.mockito.internal.util.collections.Sets;
2728

2829
import java.util.ArrayList;
2930
import java.util.Arrays;
30-
import java.util.Collections;
3131
import java.util.Iterator;
3232
import java.util.List;
3333
import java.util.Map;
@@ -112,7 +112,7 @@ public void testBasicMatch() {
112112
String delimiterFirstInput = "";
113113
String delimiterFirstPattern = "";
114114
//parallel arrays
115-
List<String> expectedKeys = Arrays.asList(generateRandomStringArray(100, 10, false, false));
115+
List<String> expectedKeys = new ArrayList<>(Sets.newSet(generateRandomStringArray(100, 10, false, false)));
116116
List<String> expectedValues = new ArrayList<>(expectedKeys.size());
117117
for (String key : expectedKeys) {
118118
String value = randomAsciiAlphanumOfLengthBetween(1, 100);
@@ -127,7 +127,6 @@ public void testBasicMatch() {
127127
assertMatch(delimiterFirstPattern, delimiterFirstInput, expectedKeys, expectedValues);
128128
}
129129

130-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/39244")
131130
public void testBasicMatchUnicode() {
132131
String valueFirstInput = "";
133132
String keyFirstPattern = "";
@@ -138,6 +137,9 @@ public void testBasicMatchUnicode() {
138137
List<String> expectedValues = new ArrayList<>();
139138
for (int i = 0; i < randomIntBetween(1, 100); i++) {
140139
String key = randomAsciiAlphanumOfLengthBetween(1, 100);
140+
while (expectedKeys.contains(key)) { // keys should be unique in this test
141+
key = randomAsciiAlphanumOfLengthBetween(1, 100);
142+
}
141143
String value = randomRealisticUnicodeOfCodepointLengthBetween(1, 100);
142144
String delimiter = Integer.toString(randomInt()); //int to ensures values and delimiters don't overlap, else validation can fail
143145
keyFirstPattern += "%{" + key + "}" + delimiter;
@@ -375,13 +377,11 @@ private void assertMatch(String pattern, String input, List<String> expectedKeys
375377

376378
private void assertMatch(String pattern, String input, List<String> expectedKeys, List<String> expectedValues, String appendSeperator) {
377379
Map<String, String> results = new DissectParser(pattern, appendSeperator).parse(input);
378-
List<String> foundKeys = new ArrayList<>(results.keySet());
379-
List<String> foundValues = new ArrayList<>(results.values());
380-
Collections.sort(foundKeys);
381-
Collections.sort(foundValues);
382-
Collections.sort(expectedKeys);
383-
Collections.sort(expectedValues);
384-
assertThat(foundKeys, Matchers.equalTo(expectedKeys));
385-
assertThat(foundValues, Matchers.equalTo(expectedValues));
380+
assertThat(results.size(), Matchers.equalTo(expectedKeys.size()));
381+
assertThat(results.size(), Matchers.equalTo(expectedValues.size()));
382+
for (int i = 0; i < results.size(); i++) {
383+
final String key = expectedKeys.get(i);
384+
assertThat(results.get(key), Matchers.equalTo(expectedValues.get(i)));
385+
}
386386
}
387387
}

0 commit comments

Comments
 (0)