Skip to content

Commit

Permalink
fixing ValueReaderComparisonTest during to accidentally hitting surro…
Browse files Browse the repository at this point in the history
…gates (apache#11681)
  • Loading branch information
xiangfu0 authored Sep 26, 2023
1 parent 1748be4 commit 8ce3062
Showing 1 changed file with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import org.apache.commons.lang3.tuple.Pair;
Expand All @@ -44,15 +47,25 @@

public class ValueReaderComparisonTest {

// Number of rounds to run the test for, change this number to test locally for catching the corner cases.
private static final int NUM_ROUNDS = 1;

@DataProvider
public static Object[] text() {
return Stream.of(Pair.of(ByteOrder.BIG_ENDIAN, true), Pair.of(ByteOrder.LITTLE_ENDIAN, true),
// there is no little endian support for var length at the time of writing
Pair.of(ByteOrder.BIG_ENDIAN, false)).flatMap(
pair -> Stream.of(new AsciiTestCase(pair.getLeft(), pair.getRight()),
new Utf8TestCase(pair.getLeft(), pair.getRight()),
new RandomBytesTextTestCase(pair.getLeft(), pair.getRight()),
new OrderedInvalidUtf8TestCase(pair.getLeft(), pair.getRight()))).toArray(Object[]::new);
return Collections.nCopies(NUM_ROUNDS,
Stream.of(
Pair.of(ByteOrder.BIG_ENDIAN, true),
Pair.of(ByteOrder.LITTLE_ENDIAN, true),
Pair.of(ByteOrder.BIG_ENDIAN, false))
.flatMap(
pair -> Stream.of(
new AsciiTestCase(pair.getLeft(), pair.getRight()),
new Utf8TestCase(pair.getLeft(), pair.getRight()),
new RandomBytesTextTestCase(pair.getLeft(), pair.getRight()),
new OrderedInvalidUtf8TestCase(pair.getLeft(), pair.getRight())))
.collect(Collectors.toList()))
.stream()
.flatMap(List::stream).toArray(Object[]::new);
}

static abstract class TestCase {
Expand Down Expand Up @@ -142,7 +155,8 @@ void testSuperiorPrefixes(ValueReader reader, int numBytesPerValue, String... st
char[] chars = strings[i].toCharArray();
for (int j = 0; j < strings[i].length(); j++) {
// this test's ordering assumption is not valid for surrogates
if (!Character.isLowSurrogate(chars[j])) {
char nextChar = (char) (chars[j] + 1);
if (!Character.isSurrogate(chars[j]) && !Character.isSurrogate(nextChar)) {
chars[j]++;
String string = new String(chars);
int signum = strings[i].compareTo(string);
Expand Down

0 comments on commit 8ce3062

Please sign in to comment.