From 181091c6a2acbfa1753ede683068e9521101c4a7 Mon Sep 17 00:00:00 2001 From: zirunye Date: Thu, 6 Feb 2025 14:52:00 +0800 Subject: [PATCH 1/6] remove unnecessary public JUnit5 test classes and methods should have default package visibility --- .../ChangeLoggingKeyValueBytesStoreTest.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java b/streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java index 154517d3b94f4..9654d16e41b96 100644 --- a/streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java +++ b/streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java @@ -69,7 +69,7 @@ @SuppressWarnings("rawtypes") @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.STRICT_STUBS) -public class ChangeLoggingKeyValueBytesStoreTest { +class ChangeLoggingKeyValueBytesStoreTest { private final MockRecordCollector collector = new MockRecordCollector(); private final InMemoryKeyValueStore inner = new InMemoryKeyValueStore("kv"); @@ -111,7 +111,7 @@ public void after() { } @Test - public void shouldDelegateInit() { + void shouldDelegateInit() { final InternalMockProcessorContext context = mockContext(); final KeyValueStore innerMock = mock(InMemoryKeyValueStore.class); final StateStore outer = new ChangeLoggingKeyValueBytesStore(innerMock); @@ -120,7 +120,7 @@ public void shouldDelegateInit() { } @Test - public void shouldWriteKeyValueBytesToInnerStoreOnPut() { + void shouldWriteKeyValueBytesToInnerStoreOnPut() { store.put(hi, there); assertThat(inner.get(hi), equalTo(there)); assertThat(collector.collected().size(), equalTo(1)); @@ -129,7 +129,7 @@ public void shouldWriteKeyValueBytesToInnerStoreOnPut() { } @Test - public void shouldWriteAllKeyValueToInnerStoreOnPutAll() { + void shouldWriteAllKeyValueToInnerStoreOnPutAll() { store.putAll(Arrays.asList(KeyValue.pair(hi, there), KeyValue.pair(hello, world))); assertThat(inner.get(hi), equalTo(there)); @@ -143,7 +143,7 @@ public void shouldWriteAllKeyValueToInnerStoreOnPutAll() { } @Test - public void shouldPropagateDelete() { + void shouldPropagateDelete() { store.put(hi, there); store.delete(hi); assertThat(inner.approximateNumEntries(), equalTo(0L)); @@ -151,13 +151,13 @@ public void shouldPropagateDelete() { } @Test - public void shouldReturnOldValueOnDelete() { + void shouldReturnOldValueOnDelete() { store.put(hi, there); assertThat(store.delete(hi), equalTo(there)); } @Test - public void shouldLogKeyNullOnDelete() { + void shouldLogKeyNullOnDelete() { store.put(hi, there); assertThat(store.delete(hi), equalTo(there)); @@ -169,20 +169,20 @@ public void shouldLogKeyNullOnDelete() { } @Test - public void shouldWriteToInnerOnPutIfAbsentNoPreviousValue() { + void shouldWriteToInnerOnPutIfAbsentNoPreviousValue() { store.putIfAbsent(hi, there); assertThat(inner.get(hi), equalTo(there)); } @Test - public void shouldNotWriteToInnerOnPutIfAbsentWhenValueForKeyExists() { + void shouldNotWriteToInnerOnPutIfAbsentWhenValueForKeyExists() { store.put(hi, there); store.putIfAbsent(hi, world); assertThat(inner.get(hi), equalTo(there)); } @Test - public void shouldWriteToChangelogOnPutIfAbsentWhenNoPreviousValue() { + void shouldWriteToChangelogOnPutIfAbsentWhenNoPreviousValue() { store.putIfAbsent(hi, there); assertThat(collector.collected().size(), equalTo(1)); @@ -191,7 +191,7 @@ public void shouldWriteToChangelogOnPutIfAbsentWhenNoPreviousValue() { } @Test - public void shouldNotWriteToChangeLogOnPutIfAbsentWhenValueForKeyExists() { + void shouldNotWriteToChangeLogOnPutIfAbsentWhenValueForKeyExists() { store.put(hi, there); store.putIfAbsent(hi, world); @@ -201,24 +201,24 @@ public void shouldNotWriteToChangeLogOnPutIfAbsentWhenValueForKeyExists() { } @Test - public void shouldReturnCurrentValueOnPutIfAbsent() { + void shouldReturnCurrentValueOnPutIfAbsent() { store.put(hi, there); assertThat(store.putIfAbsent(hi, world), equalTo(there)); } @Test - public void shouldReturnNullOnPutIfAbsentWhenNoPreviousValue() { + void shouldReturnNullOnPutIfAbsentWhenNoPreviousValue() { assertThat(store.putIfAbsent(hi, there), is(nullValue())); } @Test - public void shouldReturnValueOnGetWhenExists() { + void shouldReturnValueOnGetWhenExists() { store.put(hello, world); assertThat(store.get(hello), equalTo(world)); } @Test - public void shouldGetRecordsWithPrefixKey() { + void shouldGetRecordsWithPrefixKey() { store.put(hi, there); store.put(Bytes.increment(hi), world); @@ -241,12 +241,12 @@ public void shouldGetRecordsWithPrefixKey() { } @Test - public void shouldReturnNullOnGetWhenDoesntExist() { + void shouldReturnNullOnGetWhenDoesntExist() { assertThat(store.get(hello), is(nullValue())); } @Test - public void shouldLogPositionOnPut() { + void shouldLogPositionOnPut() { context.setRecordContext(new ProcessorRecordContext(-1, INPUT_OFFSET, INPUT_PARTITION, INPUT_TOPIC_NAME, new RecordHeaders())); context.setTime(1L); store.put(hi, there); From 6265440d01f0f43680f1d42a1cda7f51b4fe410d Mon Sep 17 00:00:00 2001 From: zirunye Date: Thu, 6 Feb 2025 14:55:23 +0800 Subject: [PATCH 2/6] rename the context and streamsConfig Local variables should not shadow class fields --- .../ChangeLoggingKeyValueBytesStoreTest.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java b/streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java index 9654d16e41b96..2f41f856db082 100644 --- a/streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java +++ b/streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java @@ -112,11 +112,11 @@ public void after() { @Test void shouldDelegateInit() { - final InternalMockProcessorContext context = mockContext(); + final InternalMockProcessorContext mockContext = mockContext(); final KeyValueStore innerMock = mock(InMemoryKeyValueStore.class); final StateStore outer = new ChangeLoggingKeyValueBytesStore(innerMock); - outer.init(context, outer); - verify(innerMock).init(context, outer); + outer.init(mockContext, outer); + verify(innerMock).init(mockContext, outer); } @Test @@ -264,13 +264,13 @@ void shouldLogPositionOnPut() { } private StreamsConfig streamsConfigMock() { - final StreamsConfig streamsConfig = mock(StreamsConfig.class); + final StreamsConfig mockedStreamsConfig = mock(StreamsConfig.class); final Map myValues = new HashMap<>(); myValues.put(InternalConfig.IQ_CONSISTENCY_OFFSET_VECTOR_ENABLED, true); - when(streamsConfig.originals()).thenReturn(myValues); - when(streamsConfig.values()).thenReturn(Collections.emptyMap()); - when(streamsConfig.getString(StreamsConfig.APPLICATION_ID_CONFIG)).thenReturn("add-id"); - return streamsConfig; + when(mockedStreamsConfig.originals()).thenReturn(myValues); + when(mockedStreamsConfig.values()).thenReturn(Collections.emptyMap()); + when(mockedStreamsConfig.getString(StreamsConfig.APPLICATION_ID_CONFIG)).thenReturn("add-id"); + return mockedStreamsConfig; } } From f128915c6ec890a4d1d5dc662720812c54704014 Mon Sep 17 00:00:00 2001 From: zirunye Date: Thu, 6 Feb 2025 17:25:41 +0800 Subject: [PATCH 3/6] change the InMemoryKeyValueStore to mock All unittest passed --- .../ChangeLoggingKeyValueBytesStoreTest.java | 173 ++++++++++++++++-- 1 file changed, 162 insertions(+), 11 deletions(-) diff --git a/streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java b/streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java index 2f41f856db082..b1cd1bf61cfe3 100644 --- a/streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java +++ b/streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java @@ -35,7 +35,6 @@ import org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl; import org.apache.kafka.streams.query.Position; import org.apache.kafka.streams.state.KeyValueIterator; -import org.apache.kafka.streams.state.KeyValueStore; import org.apache.kafka.test.InternalMockProcessorContext; import org.apache.kafka.test.MockRecordCollector; import org.apache.kafka.test.TestUtils; @@ -44,6 +43,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoSettings; import org.mockito.quality.Strictness; @@ -53,6 +53,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; @@ -62,6 +63,10 @@ import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasEntry; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -72,8 +77,9 @@ class ChangeLoggingKeyValueBytesStoreTest { private final MockRecordCollector collector = new MockRecordCollector(); - private final InMemoryKeyValueStore inner = new InMemoryKeyValueStore("kv"); - private final ChangeLoggingKeyValueBytesStore store = new ChangeLoggingKeyValueBytesStore(inner); + @Mock + private InMemoryKeyValueStore innerMock; + private ChangeLoggingKeyValueBytesStore store; private InternalMockProcessorContext context; private final StreamsConfig streamsConfig = streamsConfigMock(); private final Bytes hi = Bytes.wrap("hi".getBytes()); @@ -89,8 +95,81 @@ class ChangeLoggingKeyValueBytesStoreTest { public void before() { context = mockContext(); context.setTime(0); + store = new ChangeLoggingKeyValueBytesStore(innerMock); store.init(context, store); } + private void mockPosition() { + when(innerMock.getPosition()).thenReturn(Position.emptyPosition()); + } + private void mockGet(final Map mockMap) { + when(innerMock.get(any(Bytes.class))).thenAnswer(invocation -> mockMap.get(invocation.getArgument(0))); + } + private void mockPut(final Map mockMap) { + doAnswer(invocation -> { + mockMap.put(invocation.getArgument(0), invocation.getArgument(1)); + StoreQueryUtils.updatePosition(innerMock.getPosition(), context); + return null; + }).when(innerMock).put(any(Bytes.class), any(byte[].class)); + } + private void mockPutAll(final Map mockMap) { + doAnswer(invocation -> { + final List> entries = invocation.getArgument(0); + for (final KeyValue entry : entries) { + mockMap.put(entry.key, entry.value); + } + return null; + }).when(innerMock).putAll(anyList()); + } + private void mockDelete(final Map mockMap) { + doAnswer(invocation -> { + final Bytes key = invocation.getArgument(0); + final byte[] oldValue = mockMap.get(key); + mockMap.remove(key); + return oldValue; + }).when(innerMock).delete(any(Bytes.class)); + } + private void mockPutIfAbsent(final Map mockMap) { + doAnswer(invocation -> { + final Bytes key = invocation.getArgument(0); + final byte[] value = invocation.getArgument(1); + return mockMap.putIfAbsent(key, value); + }).when(innerMock).putIfAbsent(any(Bytes.class), any(byte[].class)); + } + private void mockPrefixScan(final Map mockMap) { + when(innerMock.prefixScan(anyString(), any())).thenAnswer(invocation -> { + final String prefix = invocation.getArgument(0); + final List> matchingRecords = new ArrayList<>(); + for (final Map.Entry entry : mockMap.entrySet()) { + if (entry.getKey().toString().startsWith(prefix)) { + matchingRecords.add(KeyValue.pair(entry.getKey(), entry.getValue())); + } + } + return new KeyValueIterator() { + private final Iterator> iterator = matchingRecords.iterator(); + + @Override + public boolean hasNext() { + return iterator.hasNext(); + } + + @Override + public KeyValue next() { + return iterator.next(); + } + + @Override + public void close() { + // No resources to clean up in this mock + } + + @Override + public Bytes peekNextKey() { + return null; + } + }; + }); + } + private InternalMockProcessorContext mockContext() { return new InternalMockProcessorContext<>( @@ -113,7 +192,6 @@ public void after() { @Test void shouldDelegateInit() { final InternalMockProcessorContext mockContext = mockContext(); - final KeyValueStore innerMock = mock(InMemoryKeyValueStore.class); final StateStore outer = new ChangeLoggingKeyValueBytesStore(innerMock); outer.init(mockContext, outer); verify(innerMock).init(mockContext, outer); @@ -121,8 +199,13 @@ void shouldDelegateInit() { @Test void shouldWriteKeyValueBytesToInnerStoreOnPut() { + final Map mockMap = new HashMap<>(); + mockPut(mockMap); + mockGet(mockMap); + mockPosition(); + store.put(hi, there); - assertThat(inner.get(hi), equalTo(there)); + assertThat(innerMock.get(hi), equalTo(there)); assertThat(collector.collected().size(), equalTo(1)); assertThat(collector.collected().get(0).key(), equalTo(hi)); assertThat(collector.collected().get(0).value(), equalTo(there)); @@ -130,10 +213,15 @@ void shouldWriteKeyValueBytesToInnerStoreOnPut() { @Test void shouldWriteAllKeyValueToInnerStoreOnPutAll() { + final Map mockMap = new HashMap<>(); + mockPutAll(mockMap); + mockGet(mockMap); + mockPosition(); + store.putAll(Arrays.asList(KeyValue.pair(hi, there), KeyValue.pair(hello, world))); - assertThat(inner.get(hi), equalTo(there)); - assertThat(inner.get(hello), equalTo(world)); + assertThat(innerMock.get(hi), equalTo(there)); + assertThat(innerMock.get(hello), equalTo(world)); assertThat(collector.collected().size(), equalTo(2)); assertThat(collector.collected().get(0).key(), equalTo(hi)); @@ -144,20 +232,37 @@ void shouldWriteAllKeyValueToInnerStoreOnPutAll() { @Test void shouldPropagateDelete() { + final Map mockMap = new HashMap<>(); + mockPut(mockMap); + mockGet(mockMap); + mockDelete(mockMap); + mockPosition(); + store.put(hi, there); store.delete(hi); - assertThat(inner.approximateNumEntries(), equalTo(0L)); - assertThat(inner.get(hi), nullValue()); + + assertThat(innerMock.approximateNumEntries(), equalTo(0L)); + assertThat(innerMock.get(hi), nullValue()); } @Test void shouldReturnOldValueOnDelete() { + final Map mockMap = new HashMap<>(); + mockPut(mockMap); + mockDelete(mockMap); + mockPosition(); + store.put(hi, there); assertThat(store.delete(hi), equalTo(there)); } @Test void shouldLogKeyNullOnDelete() { + final Map mockMap = new HashMap<>(); + mockPut(mockMap); + mockDelete(mockMap); + mockPosition(); + store.put(hi, there); assertThat(store.delete(hi), equalTo(there)); @@ -170,19 +275,34 @@ void shouldLogKeyNullOnDelete() { @Test void shouldWriteToInnerOnPutIfAbsentNoPreviousValue() { + final Map mockMap = new HashMap<>(); + mockPutIfAbsent(mockMap); + mockGet(mockMap); + mockPosition(); + store.putIfAbsent(hi, there); - assertThat(inner.get(hi), equalTo(there)); + assertThat(innerMock.get(hi), equalTo(there)); } @Test void shouldNotWriteToInnerOnPutIfAbsentWhenValueForKeyExists() { + final Map mockMap = new HashMap<>(); + mockPut(mockMap); + mockPutIfAbsent(mockMap); + mockGet(mockMap); + mockPosition(); + store.put(hi, there); store.putIfAbsent(hi, world); - assertThat(inner.get(hi), equalTo(there)); + assertThat(innerMock.get(hi), equalTo(there)); } @Test void shouldWriteToChangelogOnPutIfAbsentWhenNoPreviousValue() { + final Map mockMap = new HashMap<>(); + mockPutIfAbsent(mockMap); + mockPosition(); + store.putIfAbsent(hi, there); assertThat(collector.collected().size(), equalTo(1)); @@ -192,6 +312,11 @@ void shouldWriteToChangelogOnPutIfAbsentWhenNoPreviousValue() { @Test void shouldNotWriteToChangeLogOnPutIfAbsentWhenValueForKeyExists() { + final Map mockMap = new HashMap<>(); + mockPut(mockMap); + mockPutIfAbsent(mockMap); + mockPosition(); + store.put(hi, there); store.putIfAbsent(hi, world); @@ -202,23 +327,42 @@ void shouldNotWriteToChangeLogOnPutIfAbsentWhenValueForKeyExists() { @Test void shouldReturnCurrentValueOnPutIfAbsent() { + final Map mockMap = new HashMap<>(); + mockPut(mockMap); + mockPutIfAbsent(mockMap); + mockPosition(); + store.put(hi, there); assertThat(store.putIfAbsent(hi, world), equalTo(there)); } @Test void shouldReturnNullOnPutIfAbsentWhenNoPreviousValue() { + final Map mockMap = new HashMap<>(); + mockPutIfAbsent(mockMap); + mockPosition(); + assertThat(store.putIfAbsent(hi, there), is(nullValue())); } @Test void shouldReturnValueOnGetWhenExists() { + final Map mockMap = new HashMap<>(); + mockPut(mockMap); + mockGet(mockMap); + mockPosition(); + store.put(hello, world); assertThat(store.get(hello), equalTo(world)); } @Test void shouldGetRecordsWithPrefixKey() { + final Map mockMap = new HashMap<>(); + mockPut(mockMap); + mockPrefixScan(mockMap); + mockPosition(); + store.put(hi, there); store.put(Bytes.increment(hi), world); @@ -242,11 +386,18 @@ void shouldGetRecordsWithPrefixKey() { @Test void shouldReturnNullOnGetWhenDoesntExist() { + final Map mockMap = new HashMap<>(); + mockGet(mockMap); + assertThat(store.get(hello), is(nullValue())); } @Test void shouldLogPositionOnPut() { + final Map mockMap = new HashMap<>(); + mockPut(mockMap); + mockPosition(); + context.setRecordContext(new ProcessorRecordContext(-1, INPUT_OFFSET, INPUT_PARTITION, INPUT_TOPIC_NAME, new RecordHeaders())); context.setTime(1L); store.put(hi, there); From d493559b0e034487b85f47ed796c05dd656407ea Mon Sep 17 00:00:00 2001 From: zirunye Date: Fri, 14 Feb 2025 11:49:16 +0800 Subject: [PATCH 4/6] fix import order fix import static org.mockito.ArgumentMatchers.anyString; --- .../state/internals/ChangeLoggingKeyValueBytesStoreTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java b/streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java index b1cd1bf61cfe3..7a69048a09bd4 100644 --- a/streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java +++ b/streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java @@ -64,8 +64,8 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasEntry; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; From 05cc3625aa664e635a1276a691dda6affdd3169c Mon Sep 17 00:00:00 2001 From: zirunye Date: Thu, 10 Apr 2025 09:54:18 +0800 Subject: [PATCH 5/6] revert remove unnecessary public revert remove unnecessary public --- .../ChangeLoggingKeyValueBytesStoreTest.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java b/streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java index 7a69048a09bd4..aa18e8aee3050 100644 --- a/streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java +++ b/streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java @@ -74,7 +74,7 @@ @SuppressWarnings("rawtypes") @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.STRICT_STUBS) -class ChangeLoggingKeyValueBytesStoreTest { +public class ChangeLoggingKeyValueBytesStoreTest { private final MockRecordCollector collector = new MockRecordCollector(); @Mock @@ -190,7 +190,7 @@ public void after() { } @Test - void shouldDelegateInit() { + public void shouldDelegateInit() { final InternalMockProcessorContext mockContext = mockContext(); final StateStore outer = new ChangeLoggingKeyValueBytesStore(innerMock); outer.init(mockContext, outer); @@ -198,7 +198,7 @@ void shouldDelegateInit() { } @Test - void shouldWriteKeyValueBytesToInnerStoreOnPut() { + public void shouldWriteKeyValueBytesToInnerStoreOnPut() { final Map mockMap = new HashMap<>(); mockPut(mockMap); mockGet(mockMap); @@ -212,7 +212,7 @@ void shouldWriteKeyValueBytesToInnerStoreOnPut() { } @Test - void shouldWriteAllKeyValueToInnerStoreOnPutAll() { + public void shouldWriteAllKeyValueToInnerStoreOnPutAll() { final Map mockMap = new HashMap<>(); mockPutAll(mockMap); mockGet(mockMap); @@ -231,7 +231,7 @@ void shouldWriteAllKeyValueToInnerStoreOnPutAll() { } @Test - void shouldPropagateDelete() { + public void shouldPropagateDelete() { final Map mockMap = new HashMap<>(); mockPut(mockMap); mockGet(mockMap); @@ -246,7 +246,7 @@ void shouldPropagateDelete() { } @Test - void shouldReturnOldValueOnDelete() { + public void shouldReturnOldValueOnDelete() { final Map mockMap = new HashMap<>(); mockPut(mockMap); mockDelete(mockMap); @@ -257,7 +257,7 @@ void shouldReturnOldValueOnDelete() { } @Test - void shouldLogKeyNullOnDelete() { + public void shouldLogKeyNullOnDelete() { final Map mockMap = new HashMap<>(); mockPut(mockMap); mockDelete(mockMap); @@ -274,7 +274,7 @@ void shouldLogKeyNullOnDelete() { } @Test - void shouldWriteToInnerOnPutIfAbsentNoPreviousValue() { + public void shouldWriteToInnerOnPutIfAbsentNoPreviousValue() { final Map mockMap = new HashMap<>(); mockPutIfAbsent(mockMap); mockGet(mockMap); @@ -285,7 +285,7 @@ void shouldWriteToInnerOnPutIfAbsentNoPreviousValue() { } @Test - void shouldNotWriteToInnerOnPutIfAbsentWhenValueForKeyExists() { + public void shouldNotWriteToInnerOnPutIfAbsentWhenValueForKeyExists() { final Map mockMap = new HashMap<>(); mockPut(mockMap); mockPutIfAbsent(mockMap); @@ -298,7 +298,7 @@ void shouldNotWriteToInnerOnPutIfAbsentWhenValueForKeyExists() { } @Test - void shouldWriteToChangelogOnPutIfAbsentWhenNoPreviousValue() { + public void shouldWriteToChangelogOnPutIfAbsentWhenNoPreviousValue() { final Map mockMap = new HashMap<>(); mockPutIfAbsent(mockMap); mockPosition(); @@ -311,7 +311,7 @@ void shouldWriteToChangelogOnPutIfAbsentWhenNoPreviousValue() { } @Test - void shouldNotWriteToChangeLogOnPutIfAbsentWhenValueForKeyExists() { + public void shouldNotWriteToChangeLogOnPutIfAbsentWhenValueForKeyExists() { final Map mockMap = new HashMap<>(); mockPut(mockMap); mockPutIfAbsent(mockMap); @@ -326,7 +326,7 @@ void shouldNotWriteToChangeLogOnPutIfAbsentWhenValueForKeyExists() { } @Test - void shouldReturnCurrentValueOnPutIfAbsent() { + public void shouldReturnCurrentValueOnPutIfAbsent() { final Map mockMap = new HashMap<>(); mockPut(mockMap); mockPutIfAbsent(mockMap); @@ -337,7 +337,7 @@ void shouldReturnCurrentValueOnPutIfAbsent() { } @Test - void shouldReturnNullOnPutIfAbsentWhenNoPreviousValue() { + public void shouldReturnNullOnPutIfAbsentWhenNoPreviousValue() { final Map mockMap = new HashMap<>(); mockPutIfAbsent(mockMap); mockPosition(); @@ -346,7 +346,7 @@ void shouldReturnNullOnPutIfAbsentWhenNoPreviousValue() { } @Test - void shouldReturnValueOnGetWhenExists() { + public void shouldReturnValueOnGetWhenExists() { final Map mockMap = new HashMap<>(); mockPut(mockMap); mockGet(mockMap); @@ -357,7 +357,7 @@ void shouldReturnValueOnGetWhenExists() { } @Test - void shouldGetRecordsWithPrefixKey() { + public void shouldGetRecordsWithPrefixKey() { final Map mockMap = new HashMap<>(); mockPut(mockMap); mockPrefixScan(mockMap); @@ -385,7 +385,7 @@ void shouldGetRecordsWithPrefixKey() { } @Test - void shouldReturnNullOnGetWhenDoesntExist() { + public void shouldReturnNullOnGetWhenDoesntExist() { final Map mockMap = new HashMap<>(); mockGet(mockMap); @@ -393,7 +393,7 @@ void shouldReturnNullOnGetWhenDoesntExist() { } @Test - void shouldLogPositionOnPut() { + public void shouldLogPositionOnPut() { final Map mockMap = new HashMap<>(); mockPut(mockMap); mockPosition(); From 84c49c01244bd8b89a7b05f4c91bccc4eba82ae0 Mon Sep 17 00:00:00 2001 From: zirunye Date: Thu, 10 Apr 2025 10:04:57 +0800 Subject: [PATCH 6/6] insert empty lines between methods insert empty lines between methods --- .../state/internals/ChangeLoggingKeyValueBytesStoreTest.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java b/streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java index aa18e8aee3050..633e04865eb47 100644 --- a/streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java +++ b/streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java @@ -98,12 +98,15 @@ public void before() { store = new ChangeLoggingKeyValueBytesStore(innerMock); store.init(context, store); } + private void mockPosition() { when(innerMock.getPosition()).thenReturn(Position.emptyPosition()); } + private void mockGet(final Map mockMap) { when(innerMock.get(any(Bytes.class))).thenAnswer(invocation -> mockMap.get(invocation.getArgument(0))); } + private void mockPut(final Map mockMap) { doAnswer(invocation -> { mockMap.put(invocation.getArgument(0), invocation.getArgument(1)); @@ -111,6 +114,7 @@ private void mockPut(final Map mockMap) { return null; }).when(innerMock).put(any(Bytes.class), any(byte[].class)); } + private void mockPutAll(final Map mockMap) { doAnswer(invocation -> { final List> entries = invocation.getArgument(0);