aliehsaeedii commented on code in PR #24326:
URL: https://github.com/apache/kafka/pull/24326#discussion_r4680524484


##########
streams/src/test/java/org/apache/kafka/streams/state/internals/MeteredWindowedKeyValueWithHeadersIteratorTest.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * 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.header.Headers;
+import org.apache.kafka.common.header.internals.RecordHeaders;
+import org.apache.kafka.common.metrics.Sensor;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.common.utils.MockTime;
+import org.apache.kafka.streams.KeyValue;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.kstream.internals.TimeWindow;
+import org.apache.kafka.streams.state.KeyValueIterator;
+import org.apache.kafka.streams.state.ValueTimestampHeaders;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.LongAdder;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * Direct coverage of {@link MeteredWindowedKeyValueWithHeadersIterator} 
(KAFKA-20328). Unlike its
+ * {@link MeteredWindowedKeyValueIterator} base, {@code next()} deserializes 
the value first and passes the
+ * headers carried by that value to the key deserializer, so a header-aware 
key serde sees the record's
+ * headers; the value is then converted (e.g. to the plain value or a {@code 
ReadOnlyRecord}). The iterator
+ * also inherits the base's open-iterator and latency bookkeeping on close.
+ */
+public class MeteredWindowedKeyValueWithHeadersIteratorTest {
+
+    private static final Windowed<Bytes> RAW_KEY = new 
Windowed<>(Bytes.wrap("key".getBytes()), new TimeWindow(0L, 10L));
+    private static final byte[] RAW_VALUE = "raw-value".getBytes();
+
+    private final MockTime time = new MockTime();
+    private final Sensor operationSensor = mock(Sensor.class);
+    private final Sensor iteratorSensor = mock(Sensor.class);
+    private final LongAdder numOpenIterators = new LongAdder();
+    private final Set<MeteredIterator> openIterators = new HashSet<>();
+    private final Headers valueHeaders = new RecordHeaders().add("h", 
"v".getBytes());
+    private final ValueTimestampHeaders<String> deserializedValue = 
ValueTimestampHeaders.make("value", 42L, valueHeaders);
+    private final List<byte[]> deserializedValueBytes = new ArrayList<>();
+    private final List<Headers> keyDeserializerHeaders = new ArrayList<>();
+
+    private KeyValueIterator<Windowed<Bytes>, byte[]> inner;
+    private MeteredWindowedKeyValueWithHeadersIterator<String, 
ValueTimestampHeaders<String>, String> iterator;
+
+    @SuppressWarnings("unchecked")
+    @BeforeEach
+    public void setUp() {
+        inner = mock(KeyValueIterator.class);
+        iterator = new MeteredWindowedKeyValueWithHeadersIterator<>(
+            inner,
+            operationSensor,
+            iteratorSensor,
+            bytes -> {
+                deserializedValueBytes.add(bytes);
+                return deserializedValue;
+            },
+            (bytes, headers) -> {
+                keyDeserializerHeaders.add(headers);
+                return new String(bytes);
+            },
+            ValueTimestampHeaders::headers,
+            ValueTimestampHeaders::value,
+            time,
+            numOpenIterators,
+            openIterators
+        );
+    }
+
+    @Test
+    public void shouldDeserializeKeyWithHeadersFromDeserializedValue() {
+        when(inner.next()).thenReturn(KeyValue.pair(RAW_KEY, RAW_VALUE));
+
+        final KeyValue<Windowed<String>, String> next = iterator.next();
+
+        assertEquals(new Windowed<>("key", RAW_KEY.window()), next.key);
+        assertEquals("value", next.value);
+        // the value bytes are deserialized exactly once, and those headers 
reach the key deserializer
+        assertEquals(1, deserializedValueBytes.size());
+        assertSame(RAW_VALUE, deserializedValueBytes.get(0));
+        assertEquals(1, keyDeserializerHeaders.size());
+        assertSame(valueHeaders, keyDeserializerHeaders.get(0));
+    }
+
+    @Test
+    public void shouldDelegateHasNext() {

Review Comment:
   essential: `peekNextKey()` is not tested, and it looks like it NPEs. The 
constructor passes `null` as `deserializeKey` to the base class, and the 
inherited `peekNextKey()` calls it. Add a test; it should fail today, so fix 
the iterator here or in a follow-up with a JIRA.



##########
streams/src/test/java/org/apache/kafka/streams/state/internals/CachingKeyValueStoreWithHeadersTest.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.header.internals.RecordHeaders;
+import org.apache.kafka.common.metrics.Metrics;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.serialization.StringDeserializer;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.common.utils.internals.LogContext;
+import org.apache.kafka.streams.processor.internals.MockStreamsMetrics;
+import org.apache.kafka.streams.processor.internals.ProcessorRecordContext;
+import org.apache.kafka.streams.query.KeyQuery;
+import org.apache.kafka.streams.query.PositionBound;
+import org.apache.kafka.streams.query.QueryConfig;
+import org.apache.kafka.streams.query.QueryResult;
+import org.apache.kafka.streams.state.KeyValueStore;
+import org.apache.kafka.streams.state.ValueTimestampHeaders;
+import org.apache.kafka.test.InternalMockProcessorContext;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Direct coverage of {@link CachingKeyValueStoreWithHeaders} (KAFKA-20328). 
The class adds no overrides to
+ * {@link CachingKeyValueStore}; its contract is that serialized {@link 
ValueTimestampHeaders} bytes pass
+ * through the cache unchanged on every path (cache hit, flush to the wrapped 
store, flush listener, IQv2
+ * {@link KeyQuery}), leaving header-aware deserialization to the metered 
layer. These tests pin that
+ * contract against a real {@link ThreadCache} and {@link 
InMemoryKeyValueStore}.
+ */
+public class CachingKeyValueStoreWithHeadersTest {

Review Comment:
   nit: the class adds no code, so four of these five tests re-run 
`CachingKeyValueStore` behavior already covered by 
`CachingInMemoryKeyValueStoreTest`, with only the payload changed. One 
header-payload round trip (get, flush, listener) would pin the same contract.



##########
streams/src/test/java/org/apache/kafka/streams/state/internals/WindowedTimestampedHeadersStoreToWindowedTimestampedStoreAdapterCompletenessTest.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.streams.state.TimestampedWindowStoreWithHeaders;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static 
org.apache.kafka.streams.state.internals.StoreMethodSignatures.inheritedInterfaceDefaults;
+import static 
org.apache.kafka.streams.state.internals.StoreMethodSignatures.instanceMethods;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Requires every {@link TimestampedWindowStoreWithHeaders} method to be 
classified into a contract group,
+ * and every method except {@link #INHERITED_DEFAULTS} to be overridden by
+ * {@link WindowedTimestampedHeadersStoreToWindowedTimestampedStoreAdapter} 
(or its {@link WrappedStateStore}
+ * base), so a dropped override fails this test rather than escaping to manual 
testing (KAFKA-20328). A
+ * dropped {@code backward*} override would inherit the {@code WindowStore} 
default that throws
+ * {@link UnsupportedOperationException}.
+ * Behavioral assertions live in {@link 
WindowedTimestampedHeadersStoreToWindowedTimestampedStoreAdapterTest}.
+ */
+public class 
WindowedTimestampedHeadersStoreToWindowedTimestampedStoreAdapterCompletenessTest
 {
+
+    private static final Set<String> VALUE_CONVERTING = Set.of(
+        "fetch(Object,long)"
+    );
+
+    private static final Set<String> ITERATOR_WRAPPING = Set.of(
+        "fetch(Object,long,long)",
+        "fetch(Object,Instant,Instant)",
+        "backwardFetch(Object,long,long)",
+        "backwardFetch(Object,Instant,Instant)",
+        "fetch(Object,Object,long,long)",
+        "fetch(Object,Object,Instant,Instant)",
+        "backwardFetch(Object,Object,long,long)",
+        "backwardFetch(Object,Object,Instant,Instant)",
+        "all()",
+        "backwardAll()",
+        "fetchAll(long,long)",
+        "fetchAll(Instant,Instant)",
+        "backwardFetchAll(long,long)",
+        "backwardFetchAll(Instant,Instant)"
+    );
+
+    private static final Set<String> HEADER_STRIPPING = Set.of(
+        "put(Object,Object,long)"
+    );
+
+    private static final Set<String> DELEGATING = Set.of(
+        "name()",
+        "init(StateStoreContext,StateStore)",
+        "commit(Map)",
+        "managesOffsets()",
+        "committedOffset(TopicPartition)",
+        "approximateNumUncommittedBytes()",
+        "close()",
+        "persistent()",
+        "isOpen()",
+        "query(Query,PositionBound,QueryConfig)",
+        "getPosition()",
+        "flush()"
+    );
+
+    // readOnly is NOT harmless: the adapter inherits the default that returns 
`this`, so the isolation
+    // level never reaches the inner store and READ_COMMITTED reads can 
observe uncommitted writes.
+    // Same gap as KAFKA-21505 (which covers the byte-level header adapters); 
remove readOnly from here
+    // once the adapter overrides it.
+    private static final Set<String> INHERITED_DEFAULTS = Set.of(

Review Comment:
   Same as the KV adapter test: KAFKA-21505 does not cover this adapter. Add it 
to the ticket (or open one) and reference it here.



##########
streams/src/test/java/org/apache/kafka/streams/state/internals/KeyValueTimestampedHeaderStoreToKeyValueTimestampStoreAdapterTest.java:
##########
@@ -0,0 +1,280 @@
+/*
+ * 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.TopicPartition;
+import org.apache.kafka.common.header.internals.RecordHeaders;
+import org.apache.kafka.common.serialization.StringSerializer;
+import org.apache.kafka.streams.KeyValue;
+import org.apache.kafka.streams.processor.StateStore;
+import org.apache.kafka.streams.processor.StateStoreContext;
+import org.apache.kafka.streams.query.KeyQuery;
+import org.apache.kafka.streams.query.Position;
+import org.apache.kafka.streams.query.PositionBound;
+import org.apache.kafka.streams.query.Query;
+import org.apache.kafka.streams.query.QueryConfig;
+import org.apache.kafka.streams.query.QueryResult;
+import org.apache.kafka.streams.state.KeyValueIterator;
+import org.apache.kafka.streams.state.KeyValueStore;
+import org.apache.kafka.streams.state.TimestampedKeyValueStore;
+import org.apache.kafka.streams.state.ValueAndTimestamp;
+import org.apache.kafka.streams.state.ValueTimestampHeaders;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Named;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * Method-level coverage of {@link 
KeyValueTimestampedHeaderStoreToKeyValueTimestampStoreAdapter} over a mocked
+ * inner store: writes drop headers, reads (including iterators) convert 
{@link ValueAndTimestamp} into
+ * {@link ValueTimestampHeaders} with empty headers, and the remaining {@link 
StateStore} methods delegate.
+ * Strict stubs make a call to the wrong inner method fail the test instead of 
returning {@code null}. See
+ * {@link 
KeyValueTimestampedHeaderStoreToKeyValueTimestampStoreAdapterCompletenessTest} 
for the
+ * completeness guard (KAFKA-20328).
+ */
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.STRICT_STUBS)
+public class KeyValueTimestampedHeaderStoreToKeyValueTimestampStoreAdapterTest 
{
+
+    private static final String KEY = "key";
+    private static final String KEY_TO = "key-to";
+    private static final long TIMESTAMP = 42L;
+    private static final ValueAndTimestamp<String> INNER_VALUE = 
ValueAndTimestamp.make("value", TIMESTAMP);
+    private static final ValueTimestampHeaders<String> EXPECTED_VALUE =
+        ValueTimestampHeaders.make("value", TIMESTAMP, new RecordHeaders());
+
+    @Mock
+    private TimestampedKeyValueStore<String, String> inner;
+
+    private 
KeyValueTimestampedHeaderStoreToKeyValueTimestampStoreAdapter<String, String> 
adapter;
+
+    @BeforeEach
+    public void setUp() {
+        adapter = new 
KeyValueTimestampedHeaderStoreToKeyValueTimestampStoreAdapter<>(inner);
+    }
+
+    private static ValueTimestampHeaders<String> withHeaders(final String 
value) {
+        final RecordHeaders headers = new RecordHeaders();
+        headers.add("h", "v".getBytes());
+        return ValueTimestampHeaders.make(value, TIMESTAMP, headers);
+    }
+
+    @Test
+    public void shouldStripHeadersOnPut() {
+        adapter.put(KEY, withHeaders("value"));
+        verify(inner).put(KEY, INNER_VALUE);
+    }
+
+    @Test
+    public void shouldForwardNullOnPut() {
+        adapter.put(KEY, null);
+        verify(inner).put(KEY, null);
+    }
+
+    @Test
+    public void shouldStripHeadersOnPutAll() {
+        adapter.putAll(List.of(KeyValue.pair(KEY, withHeaders("value")), 
KeyValue.pair(KEY_TO, withHeaders("other"))));

Review Comment:
   essential: `put` and `putIfAbsent` handle a null value, but the adapter's 
`putAll` calls `value.value()` unguarded, so a null-value entry throws NPE. Add 
a null-value entry to this test; it should expose the bug, so fix the adapter 
here or in a follow-up with a JIRA.



##########
streams/src/test/java/org/apache/kafka/streams/state/internals/KeyValueTimestampedHeaderStoreToKeyValueTimestampStoreAdapterCompletenessTest.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.streams.state.TimestampedKeyValueStoreWithHeaders;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static 
org.apache.kafka.streams.state.internals.StoreMethodSignatures.inheritedInterfaceDefaults;
+import static 
org.apache.kafka.streams.state.internals.StoreMethodSignatures.instanceMethods;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Requires every {@link TimestampedKeyValueStoreWithHeaders} method to be 
classified into a contract group,
+ * and every method except {@link #INHERITED_DEFAULTS} to be overridden by
+ * {@link KeyValueTimestampedHeaderStoreToKeyValueTimestampStoreAdapter} (or 
its {@link WrappedStateStore}
+ * base), so a dropped override fails this test rather than escaping to manual 
testing (KAFKA-20328).
+ * Behavioral assertions live in {@link 
KeyValueTimestampedHeaderStoreToKeyValueTimestampStoreAdapterTest}.
+ */
+public class 
KeyValueTimestampedHeaderStoreToKeyValueTimestampStoreAdapterCompletenessTest {
+
+    private static final Set<String> VALUE_CONVERTING = Set.of(
+        "get(Object)",
+        "delete(Object)",
+        "putIfAbsent(Object,Object)"
+    );
+
+    private static final Set<String> ITERATOR_WRAPPING = Set.of(
+        "range(Object,Object)",
+        "reverseRange(Object,Object)",
+        "all()",
+        "reverseAll()",
+        "prefixScan(Object,Serializer)"
+    );
+
+    private static final Set<String> HEADER_STRIPPING = Set.of(
+        "put(Object,Object)",
+        "putAll(List)"
+    );
+
+    private static final Set<String> DELEGATING = Set.of(
+        "approximateNumEntries()",
+        "name()",
+        "init(StateStoreContext,StateStore)",
+        "commit(Map)",
+        "managesOffsets()",
+        "committedOffset(TopicPartition)",
+        "approximateNumUncommittedBytes()",
+        "close()",
+        "persistent()",
+        "isOpen()",
+        "query(Query,PositionBound,QueryConfig)",
+        "getPosition()",
+        "flush()"
+    );
+
+    // readOnly is NOT harmless: the adapter inherits the default that returns 
`this`, so the isolation
+    // level never reaches the inner store and READ_COMMITTED reads can 
observe uncommitted writes.
+    // Same gap as KAFKA-21505 (which covers the byte-level header adapters); 
remove readOnly from here
+    // once the adapter overrides it.
+    private static final Set<String> INHERITED_DEFAULTS = Set.of(

Review Comment:
   KAFKA-21505 covers only the byte-level header adapters, not this one. Add 
this adapter to that ticket (or open one) and reference it here, so the pointer 
leads to a real fix.



##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/DecoratorCompletenessTest.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.processor.internals;
+
+import org.apache.kafka.streams.processor.StateStore;
+import 
org.apache.kafka.streams.processor.internals.AbstractReadOnlyDecorator.KeyValueStoreReadOnlyDecorator;
+import 
org.apache.kafka.streams.processor.internals.AbstractReadOnlyDecorator.SessionStoreReadOnlyDecorator;
+import 
org.apache.kafka.streams.processor.internals.AbstractReadOnlyDecorator.TimestampedKeyValueStoreReadOnlyDecorator;
+import 
org.apache.kafka.streams.processor.internals.AbstractReadOnlyDecorator.TimestampedKeyValueStoreReadOnlyDecoratorWithHeaders;
+import 
org.apache.kafka.streams.processor.internals.AbstractReadOnlyDecorator.TimestampedWindowStoreReadOnlyDecorator;
+import 
org.apache.kafka.streams.processor.internals.AbstractReadOnlyDecorator.VersionedKeyValueStoreReadOnlyDecorator;
+import 
org.apache.kafka.streams.processor.internals.AbstractReadOnlyDecorator.WindowStoreReadOnlyDecorator;
+import 
org.apache.kafka.streams.processor.internals.AbstractReadWriteDecorator.KeyValueStoreReadWriteDecorator;
+import 
org.apache.kafka.streams.processor.internals.AbstractReadWriteDecorator.SessionStoreReadWriteDecorator;
+import 
org.apache.kafka.streams.processor.internals.AbstractReadWriteDecorator.SessionStoreWithHeadersReadWriteDecorator;
+import 
org.apache.kafka.streams.processor.internals.AbstractReadWriteDecorator.TimestampedKeyValueStoreReadWriteDecorator;
+import 
org.apache.kafka.streams.processor.internals.AbstractReadWriteDecorator.TimestampedKeyValueStoreReadWriteDecoratorWithHeaders;
+import 
org.apache.kafka.streams.processor.internals.AbstractReadWriteDecorator.TimestampedWindowStoreReadWriteDecorator;
+import 
org.apache.kafka.streams.processor.internals.AbstractReadWriteDecorator.TimestampedWindowStoreWithHeadersReadWriteDecorator;
+import 
org.apache.kafka.streams.processor.internals.AbstractReadWriteDecorator.VersionedKeyValueStoreReadWriteDecorator;
+import 
org.apache.kafka.streams.processor.internals.AbstractReadWriteDecorator.WindowStoreReadWriteDecorator;
+import org.apache.kafka.streams.state.KeyValueStore;
+import org.apache.kafka.streams.state.SessionStore;
+import org.apache.kafka.streams.state.SessionStoreWithHeaders;
+import org.apache.kafka.streams.state.TimestampedKeyValueStore;
+import org.apache.kafka.streams.state.TimestampedKeyValueStoreWithHeaders;
+import org.apache.kafka.streams.state.TimestampedWindowStore;
+import org.apache.kafka.streams.state.TimestampedWindowStoreWithHeaders;
+import org.apache.kafka.streams.state.VersionedKeyValueStore;
+import org.apache.kafka.streams.state.WindowStore;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.stream.Stream;
+
+import static 
org.apache.kafka.streams.state.internals.StoreMethodSignatures.inheritedInterfaceDefaults;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Pins, for every {@link AbstractReadWriteDecorator} and {@link 
AbstractReadOnlyDecorator} subclass, the exact
+ * set of store-interface methods it leaves to the interface default 
(KAFKA-20328). A decorator that drops an
+ * override silently changes behavior inside a processor: e.g. a missing 
{@code backwardFetch} inherits the
+ * {@link WindowStore} default that throws {@link 
UnsupportedOperationException}. Behavioral coverage lives in
+ * {@link AbstractReadWriteDecoratorTest}, {@link 
AbstractReadOnlyDecoratorTest} and {@link ProcessorContextImplTest}.
+ * <p>
+ * The allow-lists are exact, so adding an override also requires updating 
this test.
+ */
+public class DecoratorCompletenessTest {
+
+    // readOnly is NOT harmless: the default returns `this`, so the isolation 
level is not propagated to the
+    // wrapped store even though ReadOnlyKeyValueStore#readOnly documents that 
wrapping stores propagate it.
+    // Remove it from the allow-lists once the decorators override it.
+    private static final String READ_ONLY = "readOnly(IsolationLevel)";

Review Comment:
   This `readOnly` gap in the decorators has no JIRA pointer, and KAFKA-21505 
does not cover decorators. Please open one and reference it here, like in the 
adapter tests.



##########
streams/src/test/java/org/apache/kafka/streams/state/internals/MeteredWindowedKeyValueWithHeadersIteratorTest.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * 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.header.Headers;
+import org.apache.kafka.common.header.internals.RecordHeaders;
+import org.apache.kafka.common.metrics.Sensor;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.common.utils.MockTime;
+import org.apache.kafka.streams.KeyValue;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.kstream.internals.TimeWindow;
+import org.apache.kafka.streams.state.KeyValueIterator;
+import org.apache.kafka.streams.state.ValueTimestampHeaders;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.LongAdder;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * Direct coverage of {@link MeteredWindowedKeyValueWithHeadersIterator} 
(KAFKA-20328). Unlike its
+ * {@link MeteredWindowedKeyValueIterator} base, {@code next()} deserializes 
the value first and passes the
+ * headers carried by that value to the key deserializer, so a header-aware 
key serde sees the record's
+ * headers; the value is then converted (e.g. to the plain value or a {@code 
ReadOnlyRecord}). The iterator
+ * also inherits the base's open-iterator and latency bookkeeping on close.
+ */
+public class MeteredWindowedKeyValueWithHeadersIteratorTest {
+
+    private static final Windowed<Bytes> RAW_KEY = new 
Windowed<>(Bytes.wrap("key".getBytes()), new TimeWindow(0L, 10L));
+    private static final byte[] RAW_VALUE = "raw-value".getBytes();
+
+    private final MockTime time = new MockTime();
+    private final Sensor operationSensor = mock(Sensor.class);
+    private final Sensor iteratorSensor = mock(Sensor.class);
+    private final LongAdder numOpenIterators = new LongAdder();
+    private final Set<MeteredIterator> openIterators = new HashSet<>();
+    private final Headers valueHeaders = new RecordHeaders().add("h", 
"v".getBytes());
+    private final ValueTimestampHeaders<String> deserializedValue = 
ValueTimestampHeaders.make("value", 42L, valueHeaders);
+    private final List<byte[]> deserializedValueBytes = new ArrayList<>();
+    private final List<Headers> keyDeserializerHeaders = new ArrayList<>();
+
+    private KeyValueIterator<Windowed<Bytes>, byte[]> inner;
+    private MeteredWindowedKeyValueWithHeadersIterator<String, 
ValueTimestampHeaders<String>, String> iterator;
+
+    @SuppressWarnings("unchecked")
+    @BeforeEach
+    public void setUp() {
+        inner = mock(KeyValueIterator.class);
+        iterator = new MeteredWindowedKeyValueWithHeadersIterator<>(
+            inner,
+            operationSensor,
+            iteratorSensor,
+            bytes -> {
+                deserializedValueBytes.add(bytes);
+                return deserializedValue;
+            },
+            (bytes, headers) -> {
+                keyDeserializerHeaders.add(headers);
+                return new String(bytes);
+            },
+            ValueTimestampHeaders::headers,
+            ValueTimestampHeaders::value,
+            time,
+            numOpenIterators,
+            openIterators
+        );
+    }
+
+    @Test
+    public void shouldDeserializeKeyWithHeadersFromDeserializedValue() {
+        when(inner.next()).thenReturn(KeyValue.pair(RAW_KEY, RAW_VALUE));
+
+        final KeyValue<Windowed<String>, String> next = iterator.next();
+
+        assertEquals(new Windowed<>("key", RAW_KEY.window()), next.key);
+        assertEquals("value", next.value);
+        // the value bytes are deserialized exactly once, and those headers 
reach the key deserializer
+        assertEquals(1, deserializedValueBytes.size());
+        assertSame(RAW_VALUE, deserializedValueBytes.get(0));
+        assertEquals(1, keyDeserializerHeaders.size());
+        assertSame(valueHeaders, keyDeserializerHeaders.get(0));
+    }
+
+    @Test
+    public void shouldDelegateHasNext() {
+        when(inner.hasNext()).thenReturn(true, false);
+        assertTrue(iterator.hasNext());
+        assertFalse(iterator.hasNext());
+    }
+
+    @Test
+    public void shouldRegisterAsOpenIteratorOnCreation() {

Review Comment:
   nit: this test and the two close tests exercise the inherited 
`MeteredWindowedKeyValueIterator`, not this class, and that base class has no 
test of its own. Move them to a `MeteredWindowedKeyValueIteratorTest`, or keep 
only the header-specific test here.



##########
streams/src/test/java/org/apache/kafka/streams/state/internals/StoreAdapterCompletenessTest.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.streams.processor.StateStore;
+import org.apache.kafka.streams.state.KeyValueStore;
+import org.apache.kafka.streams.state.VersionedBytesStore;
+import org.apache.kafka.streams.state.WindowStore;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.stream.Stream;
+
+import static 
org.apache.kafka.streams.state.internals.StoreMethodSignatures.inheritedInterfaceDefaults;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Pins, for each format-converting byte-store adapter without a dedicated 
completeness test, the exact set of
+ * store-interface methods it leaves to the interface default (KAFKA-20328). A 
dropped override silently changes
+ * behavior: e.g. a missing {@code backwardFetch} inherits the {@link 
WindowStore} default that throws
+ * {@link UnsupportedOperationException}, and a missing {@code reverseRange} 
stops reaching the inner store.
+ * <p>
+ * {@link SessionToHeadersStoreAdapter}, {@link 
TimestampedToHeadersWindowStoreAdapter},

Review Comment:
   `SessionHeadersStoreToSessionStoreAdapter` (kstream/internals) is in no 
completeness test and has no `readOnly` override either. Add it here, or say 
why it is left out; the ticket asked to cover the other adapters.



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