Copilot commented on code in PR #24253:
URL: https://github.com/apache/kafka/pull/24253#discussion_r4682298507


##########
streams/src/test/java/org/apache/kafka/streams/state/internals/PlainToHeadersStoreAdapterTest.java:
##########
@@ -413,4 +418,42 @@ public void shouldDelegateGetPosition() {
 
         verify(mockStore).getPosition();
     }
-}
\ No newline at end of file
+
+    @Test
+    public void shouldPropagateReadOnlyToInnerStoreWithFormatConversion() {
+        final PlainToHeadersStoreAdapter adapter = createAdapter();
+        final ReadOnlyKeyValueStore<Bytes, byte[]> innerView = 
mock(ReadOnlyKeyValueStore.class);
+        final Bytes key = new Bytes("k".getBytes());
+        final byte[] committedPlain = "committed".getBytes();
+
+        
when(mockStore.readOnly(IsolationLevel.READ_COMMITTED)).thenReturn(innerView);
+        when(innerView.get(key)).thenReturn(committedPlain);
+
+        final ReadOnlyKeyValueStore<Bytes, byte[]> view = 
adapter.readOnly(IsolationLevel.READ_COMMITTED);
+
+        assertNotSame(adapter, view);
+        assertArrayEquals(convertFromPlainToHeaderFormat(committedPlain), 
view.get(key));
+        verify(mockStore).readOnly(IsolationLevel.READ_COMMITTED);
+    }
+
+    @Test
+    public void shouldConvertIteratorValuesOnReadOnlyView() {
+        final PlainToHeadersStoreAdapter adapter = createAdapter();
+        final ReadOnlyKeyValueStore<Bytes, byte[]> innerView = 
mock(ReadOnlyKeyValueStore.class);
+        
when(mockStore.readOnly(IsolationLevel.READ_COMMITTED)).thenReturn(innerView);
+        when(innerView.range(any(), any())).thenReturn(mockIterator);
+        when(innerView.reverseRange(any(), any())).thenReturn(mockIterator);
+        when(innerView.all()).thenReturn(mockIterator);
+        when(innerView.reverseAll()).thenReturn(mockIterator);
+        when(innerView.prefixScan(any(), any())).thenReturn(mockIterator);
+
+        final ReadOnlyKeyValueStore<Bytes, byte[]> view = 
adapter.readOnly(IsolationLevel.READ_COMMITTED);
+
+        assertConvertsPlainToHeaders(view.range(null, null));
+        assertConvertsPlainToHeaders(view.reverseRange(null, null));
+        assertConvertsPlainToHeaders(view.all());
+        assertConvertsPlainToHeaders(view.reverseAll());
+        assertConvertsPlainToHeaders(view.prefixScan("p", new 
StringSerializer()));

Review Comment:
   This test stubs all read-only iterator-returning methods to return the same 
`mockIterator` instance. If `assertConvertsPlainToHeaders(...)` 
advances/consumes the iterator (common for iterator assertions), subsequent 
assertions can become order-dependent or brittle due to shared mock state. 
Prefer returning a fresh iterator mock per method call (or per assertion) so 
each assertion operates on an independent iterator instance.



##########
streams/src/test/java/org/apache/kafka/streams/state/internals/KeyValueToTimestampedKeyValueByteStoreAdapterTest.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.streams.state.internals;
+
+import org.apache.kafka.common.IsolationLevel;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.streams.state.KeyValueStore;
+import org.apache.kafka.streams.state.ReadOnlyKeyValueStore;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static 
org.apache.kafka.streams.state.TimestampedBytesStore.convertToTimestampedFormat;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+public class KeyValueToTimestampedKeyValueByteStoreAdapterTest {
+
+    @Mock
+    private KeyValueStore<Bytes, byte[]> mockStore;
+
+    @Test
+    public void shouldPropagateReadOnlyToInnerStoreWithFormatConversion() {
+        when(mockStore.persistent()).thenReturn(true);
+        final KeyValueToTimestampedKeyValueByteStoreAdapter adapter =
+            new KeyValueToTimestampedKeyValueByteStoreAdapter(mockStore);
+        final ReadOnlyKeyValueStore<Bytes, byte[]> innerView = 
mock(ReadOnlyKeyValueStore.class);
+        final Bytes key = new Bytes("k".getBytes());
+        final byte[] committedPlain = "committed".getBytes();

Review Comment:
   Using `String#getBytes()` relies on the platform default charset. Even 
though these literals are ASCII-safe, tests are generally more portable and 
explicit if they specify a charset (e.g., UTF-8) for all `getBytes()` calls.



##########
streams/src/test/java/org/apache/kafka/streams/state/internals/TimestampedToHeadersStoreAdapterTest.java:
##########
@@ -393,4 +397,42 @@ public void shouldDelegateGetPosition() {
 
         verify(mockStore).getPosition();
     }
+
+    @Test
+    public void shouldPropagateReadOnlyToInnerStoreWithFormatConversion() {
+        final TimestampedToHeadersStoreAdapter adapter = createAdapter();
+        final ReadOnlyKeyValueStore<Bytes, byte[]> innerView = 
mock(ReadOnlyKeyValueStore.class);
+        final Bytes key = new Bytes("k".getBytes());
+        final byte[] committedPlain = "committed".getBytes();
+
+        
when(mockStore.readOnly(IsolationLevel.READ_COMMITTED)).thenReturn(innerView);
+        when(innerView.get(key)).thenReturn(committedPlain);
+
+        final ReadOnlyKeyValueStore<Bytes, byte[]> view = 
adapter.readOnly(IsolationLevel.READ_COMMITTED);
+
+        assertNotSame(adapter, view);
+        assertArrayEquals(convertToHeaderFormat(committedPlain), 
view.get(key));
+        verify(mockStore).readOnly(IsolationLevel.READ_COMMITTED);
+    }
+
+    @Test
+    public void shouldConvertIteratorValuesOnReadOnlyView() {
+        final TimestampedToHeadersStoreAdapter adapter = createAdapter();
+        final ReadOnlyKeyValueStore<Bytes, byte[]> innerView = 
mock(ReadOnlyKeyValueStore.class);
+        
when(mockStore.readOnly(IsolationLevel.READ_COMMITTED)).thenReturn(innerView);
+        when(innerView.range(any(), any())).thenReturn(mockIterator);
+        when(innerView.reverseRange(any(), any())).thenReturn(mockIterator);
+        when(innerView.all()).thenReturn(mockIterator);
+        when(innerView.reverseAll()).thenReturn(mockIterator);
+        when(innerView.prefixScan(any(), any())).thenReturn(mockIterator);
+
+        final ReadOnlyKeyValueStore<Bytes, byte[]> view = 
adapter.readOnly(IsolationLevel.READ_COMMITTED);
+
+        assertConvertsTimestampedToHeaders(view.range(null, null));
+        assertConvertsTimestampedToHeaders(view.reverseRange(null, null));
+        assertConvertsTimestampedToHeaders(view.all());
+        assertConvertsTimestampedToHeaders(view.reverseAll());
+        assertConvertsTimestampedToHeaders(view.prefixScan("p", new 
StringSerializer()));

Review Comment:
   Same issue as in the plain adapter test: all iterator-returning methods are 
stubbed to the same `mockIterator` instance. If the helper consumes the 
iterator, later assertions may fail depending on call order. Return distinct 
iterator mocks (or reset the mock) per accessor to keep the test deterministic.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to