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 flaky test RocksDBStoreTest.shouldReturnUUIDsWithStr… #10662

Closed
Closed
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 @@ -74,6 +74,7 @@
import static org.easymock.EasyMock.mock;
import static org.easymock.EasyMock.notNull;
import static org.easymock.EasyMock.reset;
import static org.hamcrest.CoreMatchers.either;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
Expand Down Expand Up @@ -438,7 +439,7 @@ public void shouldReturnUUIDsWithStringPrefix() {
final Serializer<UUID> uuidSerializer = Serdes.UUID().serializer();
final UUID uuid1 = UUID.randomUUID();
final UUID uuid2 = UUID.randomUUID();
final String prefix = uuid1.toString().substring(0, 4);
final String prefix1 = uuid1.toString().substring(0, 4);
entries.add(new KeyValue<>(
new Bytes(uuidSerializer.serialize(null, uuid1)),
stringSerializer.serialize(null, "a")));
Expand All @@ -450,18 +451,24 @@ public void shouldReturnUUIDsWithStringPrefix() {
rocksDBStore.putAll(entries);
rocksDBStore.flush();

final KeyValueIterator<Bytes, byte[]> keysWithPrefix = rocksDBStore.prefixScan(prefix, stringSerializer);
final KeyValueIterator<Bytes, byte[]> keysWithPrefix = rocksDBStore.prefixScan(prefix1, 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));
numberOfKeysReturned++;
}

assertThat(numberOfKeysReturned, is(1));
assertThat(valuesWithPrefix.get(0), is("a"));
final boolean clashOnPrefix = prefix1.equals(uuid2.toString().substring(0, 4));
final int expectedNumberOfKeysReturned = clashOnPrefix ? 2 : 1;
assertThat(numberOfKeysReturned, is(expectedNumberOfKeysReturned));

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

@Test
Expand Down