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


##########
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:
   Done, fixed and added a regression test too.



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