mjsax commented on code in PR #18816: URL: https://github.com/apache/kafka/pull/18816#discussion_r2040351003
########## streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java: ########## @@ -89,8 +95,81 @@ public 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<Bytes, byte[]> mockMap) { Review Comment: Yes, we want to mock, but we use two different techniques and mix them... First you use ``` @Mock private InMemoryKeyValueStore innerMock; ``` For this case, to me, all call a test make into this mock, should be stubbed via corresponding `when(...).thanAnswer(...)` code setup and the mock itself is stateless. If we make the mock stateful, we can just keep using `new InMemoryKeyValueStore` to begin with, that is just an `Map<Bytes, bytes[]>` internally, too. \cc @cadonna who requested to rewrite this using mocks to clarify, in cases I misunderstand the purpose of the ticket. ########## streams/src/test/java/org/apache/kafka/streams/state/internals/ChangeLoggingKeyValueBytesStoreTest.java: ########## @@ -89,9 +95,86 @@ public 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<Bytes, byte[]> mockMap) { + when(innerMock.get(any(Bytes.class))).thenAnswer(invocation -> mockMap.get(invocation.getArgument(0))); + } + + private void mockPut(final Map<Bytes, byte[]> 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<Bytes, byte[]> mockMap) { + doAnswer(invocation -> { + final List<KeyValue<Bytes, byte[]>> entries = invocation.getArgument(0); + for (final KeyValue<Bytes, byte[]> entry : entries) { + mockMap.put(entry.key, entry.value); + } + return null; + }).when(innerMock).putAll(anyList()); + } + private void mockDelete(final Map<Bytes, byte[]> mockMap) { Review Comment: Seems you forgot the add empty lines between methods. More of the same below. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org