Skip to content

Commit

Permalink
Fix DissectParserTests expecting unique keys (#39262)
Browse files Browse the repository at this point in the history
Fixes a bug in DissectParserTests where the tests expected dissect
keys to be unique but were not.

Closes #39244
  • Loading branch information
albertzaharovits authored Feb 22, 2019
1 parent ca3b738 commit 1e7f28e
Showing 1 changed file with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
import org.elasticsearch.test.ESTestCase;
import org.hamcrest.CoreMatchers;
import org.hamcrest.Matchers;
import org.mockito.internal.util.collections.Sets;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -112,7 +112,7 @@ public void testBasicMatch() {
String delimiterFirstInput = "";
String delimiterFirstPattern = "";
//parallel arrays
List<String> expectedKeys = Arrays.asList(generateRandomStringArray(100, 10, false, false));
List<String> expectedKeys = new ArrayList<>(Sets.newSet(generateRandomStringArray(100, 10, false, false)));
List<String> expectedValues = new ArrayList<>(expectedKeys.size());
for (String key : expectedKeys) {
String value = randomAsciiAlphanumOfLengthBetween(1, 100);
Expand All @@ -127,7 +127,6 @@ public void testBasicMatch() {
assertMatch(delimiterFirstPattern, delimiterFirstInput, expectedKeys, expectedValues);
}

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

private void assertMatch(String pattern, String input, List<String> expectedKeys, List<String> expectedValues, String appendSeperator) {
Map<String, String> results = new DissectParser(pattern, appendSeperator).parse(input);
List<String> foundKeys = new ArrayList<>(results.keySet());
List<String> foundValues = new ArrayList<>(results.values());
Collections.sort(foundKeys);
Collections.sort(foundValues);
Collections.sort(expectedKeys);
Collections.sort(expectedValues);
assertThat(foundKeys, Matchers.equalTo(expectedKeys));
assertThat(foundValues, Matchers.equalTo(expectedValues));
assertThat(results.size(), Matchers.equalTo(expectedKeys.size()));
assertThat(results.size(), Matchers.equalTo(expectedValues.size()));
for (int i = 0; i < results.size(); i++) {
final String key = expectedKeys.get(i);
assertThat(results.get(key), Matchers.equalTo(expectedValues.get(i)));
}
}
}

0 comments on commit 1e7f28e

Please sign in to comment.