From 0acf3cca5469ba0b4ffc3dcd35671f81058c06fe Mon Sep 17 00:00:00 2001 From: Guozhang Wang Date: Thu, 6 May 2021 15:26:22 -0700 Subject: [PATCH 1/2] fix flakiness --- .../kafka/streams/state/internals/RocksDBStoreTest.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/streams/src/test/java/org/apache/kafka/streams/state/internals/RocksDBStoreTest.java b/streams/src/test/java/org/apache/kafka/streams/state/internals/RocksDBStoreTest.java index 0568df2d5689c..fbaf612f34c98 100644 --- a/streams/src/test/java/org/apache/kafka/streams/state/internals/RocksDBStoreTest.java +++ b/streams/src/test/java/org/apache/kafka/streams/state/internals/RocksDBStoreTest.java @@ -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"))); @@ -451,17 +453,14 @@ public void shouldReturnUUIDsWithStringPrefix() { rocksDBStore.flush(); final KeyValueIterator keysWithPrefix = rocksDBStore.prefixScan(prefix, stringSerializer); - final List valuesWithPrefix = new ArrayList<>(); int numberOfKeysReturned = 0; while (keysWithPrefix.hasNext()) { - final KeyValue next = keysWithPrefix.next(); - valuesWithPrefix.add(new String(next.value)); + keysWithPrefix.next(); numberOfKeysReturned++; } - assertThat(numberOfKeysReturned, is(1)); - assertThat(valuesWithPrefix.get(0), is("a")); + assertThat(numberOfKeysReturned, is(numMatches)); } @Test From 27132ba8abff8620956ae44001dabcbbd749c8bb Mon Sep 17 00:00:00 2001 From: Guozhang Wang Date: Mon, 10 May 2021 10:36:21 -0700 Subject: [PATCH 2/2] github comments --- .../streams/state/internals/RocksDBStoreTest.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/streams/src/test/java/org/apache/kafka/streams/state/internals/RocksDBStoreTest.java b/streams/src/test/java/org/apache/kafka/streams/state/internals/RocksDBStoreTest.java index 2ae95348ee78e..c9e9a8d94692c 100644 --- a/streams/src/test/java/org/apache/kafka/streams/state/internals/RocksDBStoreTest.java +++ b/streams/src/test/java/org/apache/kafka/streams/state/internals/RocksDBStoreTest.java @@ -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; @@ -453,14 +454,21 @@ public void shouldReturnUUIDsWithStringPrefix() { rocksDBStore.flush(); final KeyValueIterator keysWithPrefix = rocksDBStore.prefixScan(prefix, stringSerializer); + final List valuesWithPrefix = new ArrayList<>(); int numberOfKeysReturned = 0; while (keysWithPrefix.hasNext()) { - keysWithPrefix.next(); + final KeyValue next = keysWithPrefix.next(); + valuesWithPrefix.add(new String(next.value)); numberOfKeysReturned++; } assertThat(numberOfKeysReturned, is(numMatches)); + if (numMatches == 2) { + assertThat(valuesWithPrefix.get(0), either(is("a")).or(is("b"))); + } else { + assertThat(valuesWithPrefix.get(0), is("a")); + } } @Test