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


##########
streams/src/main/java/org/apache/kafka/streams/state/internals/SessionToHeadersStoreAdapter.java:
##########
@@ -223,4 +225,80 @@ public <R> QueryResult<R> query(final Query<R> query,
     public Position getPosition() {
         return store.getPosition();
     }
-}
+
+    @Override
+    public ReadOnlySessionStore<Bytes, byte[]> readOnly(final IsolationLevel 
isolationLevel) {

Review Comment:
   Done in 68171ce: `readOnly(IsolationLevel)` is now classified with the 
value-converting methods in both completeness tests, and the comments about the 
exemption are gone.
   
   I checked that it bites. With the `readOnly` override deleted from 
`SessionToHeadersStoreAdapter` and from 
`TimestampedToHeadersWindowStoreAdapter`, 
`everyNonSpecialMethodMustBeOverriddenByAdapter` fails in both tests and names 
`readOnly(IsolationLevel)`; the two behavioral tests fail as well.



##########
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:
   I checked this rather than assume. The shared `mockIterator` carries no 
state here: `assertConvertsPlainToHeaders` re-stubs `hasNext()` / `next()` with 
plain `thenReturn(...)` on every call, so no accessor sees the effect of a 
previous one.
   
   The class also runs with `Strictness.STRICT_STUBS`, which makes the test 
sensitive to an accessor that reaches the wrong inner method. I changed 
`PlainToHeadersReadOnlyView.all()` to call `underlying.range(null, null)` and 
`shouldConvertIteratorValuesOnReadOnlyView` fails with 
`UnnecessaryStubbingException` for the then-unused `innerView.all()` stub.
   
   So I left the test on the shared-mock pattern the other iterator tests in 
this file use. A fresh mock per accessor would work too, but it would not catch 
anything the strict-stubs check does not catch already.



##########
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 situation as in the plain adapter test, and I verified it here as well. 
The re-stubbing in `assertConvertsTimestampedToHeaders` is stateless, and with 
`TimestampedToHeadersReadOnlyView.all()` pointed at `underlying.range(null, 
null)` the test fails on the unused `innerView.all()` stub under `STRICT_STUBS`.
   
   Left unchanged for the same reason.



##########
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:
   Done in 68171ce: the `getBytes()` calls this PR adds now pass 
`StandardCharsets.UTF_8`. That covers this file, 
`WindowToTimestampedWindowByteStoreAdapterTest`, and the `readOnly` tests added 
to the three existing adapter tests.



-- 
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