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

KAFKA-12747: Fix flakiness in shouldReturnUUIDsWithStringPrefix #10643

Merged
merged 3 commits into from
May 10, 2021
Merged
Changes from 1 commit
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 @@ -439,6 +439,8 @@ public void shouldReturnUUIDsWithStringPrefix() {
final UUID uuid1 = UUID.randomUUID();
final UUID uuid2 = UUID.randomUUID();
final String prefix = uuid1.toString().substring(0, 4);
final int numMatches = uuid2.toString().substring(0, 4).equals(prefix) ? 2 : 1;

entries.add(new KeyValue<>(
new Bytes(uuidSerializer.serialize(null, uuid1)),
stringSerializer.serialize(null, "a")));
Expand All @@ -451,17 +453,14 @@ public void shouldReturnUUIDsWithStringPrefix() {
rocksDBStore.flush();

final KeyValueIterator<Bytes, byte[]> keysWithPrefix = rocksDBStore.prefixScan(prefix, stringSerializer);
final List<String> valuesWithPrefix = new ArrayList<>();
int numberOfKeysReturned = 0;

while (keysWithPrefix.hasNext()) {
final KeyValue<Bytes, byte[]> next = keysWithPrefix.next();
valuesWithPrefix.add(new String(next.value));
keysWithPrefix.next();
numberOfKeysReturned++;
}

assertThat(numberOfKeysReturned, is(1));
assertThat(valuesWithPrefix.get(0), is("a"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still try to keep this assertion, something among the lines of:

if (clashOnPrefix) {
    assertThat(valuesWithPrefix.get(0), either(is("a")).or(is("b")));
} else {
    assertThat(valuesWithPrefix.get(0), is("a"));
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SG, I will do that upon merging.

assertThat(numberOfKeysReturned, is(numMatches));
}

@Test
Expand Down