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


##########
streams/integration-tests/src/test/java/org/apache/kafka/streams/integration/VersionedKeyValueStoreWithHeadersIntegrationTest.java:
##########
@@ -0,0 +1,364 @@
+/*
+ * 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.integration;
+
+import org.apache.kafka.common.header.Headers;
+import org.apache.kafka.common.header.internals.RecordHeaders;
+import org.apache.kafka.common.serialization.IntegerDeserializer;
+import org.apache.kafka.common.serialization.IntegerSerializer;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.serialization.StringSerializer;
+import org.apache.kafka.streams.KafkaStreams;
+import org.apache.kafka.streams.KeyValue;
+import org.apache.kafka.streams.StreamsConfig;
+import org.apache.kafka.streams.Topology;
+import org.apache.kafka.streams.integration.utils.EmbeddedKafkaCluster;
+import org.apache.kafka.streams.integration.utils.IntegrationTestUtils;
+import org.apache.kafka.streams.processor.api.Processor;
+import org.apache.kafka.streams.processor.api.ProcessorContext;
+import org.apache.kafka.streams.processor.api.ProcessorSupplier;
+import org.apache.kafka.streams.processor.api.Record;
+import org.apache.kafka.streams.state.Stores;
+import org.apache.kafka.streams.state.VersionedKeyValueStoreWithHeaders;
+import org.apache.kafka.streams.state.VersionedRecord;
+import org.apache.kafka.test.TestUtils;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Properties;
+
+import static org.apache.kafka.streams.utils.TestUtils.safeUniqueTestName;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+@Tag("integration")
+public class VersionedKeyValueStoreWithHeadersIntegrationTest {
+
+    private static final String STORE_NAME = "versioned-headers-store";
+    private static final Duration HISTORY_RETENTION = Duration.ofMinutes(10);
+
+    private String inputStream;
+    private String outputStream;
+    private long baseTimestamp;
+
+    private KafkaStreams kafkaStreams;
+
+    private static final EmbeddedKafkaCluster CLUSTER = new 
EmbeddedKafkaCluster(1);
+
+    public TestInfo testInfo;
+
+    @BeforeAll
+    public static void before() throws IOException {
+        CLUSTER.start();
+    }
+
+    @AfterAll
+    public static void after() {
+        CLUSTER.stop();
+    }
+
+    @BeforeEach
+    public void setUp(final TestInfo testInfo) throws Exception {
+        this.testInfo = testInfo;
+        final String testName = safeUniqueTestName(testInfo);
+        inputStream = "input-" + testName;
+        outputStream = "output-" + testName;
+        baseTimestamp = System.currentTimeMillis() - 
Duration.ofMinutes(5).toMillis();
+        CLUSTER.createTopic(inputStream, 1, 1);
+        CLUSTER.createTopic(outputStream, 1, 1);
+    }
+
+    @AfterEach
+    public void tearDown() {
+        if (kafkaStreams != null) {
+            kafkaStreams.close(Duration.ofSeconds(30));
+        }
+    }
+
+    @Test
+    public void shouldPutAndGetWithHeaders() throws Exception {
+        final Topology topology = buildTopology(() -> new 
VersionedStoreWithHeadersCheckerProcessor(true));
+        kafkaStreams = new KafkaStreams(topology, streamsConfiguration());
+        IntegrationTestUtils.startApplicationAndWaitUntilRunning(kafkaStreams);
+
+        produceDataToTopicWithHeaders(inputStream, baseTimestamp, headers1(),
+            new KeyValue<>(1, "value1"));
+
+        final List<KeyValue<Integer, Integer>> results =
+            IntegrationTestUtils.waitUntilMinKeyValueRecordsReceived(
+                consumerConfig(), outputStream, 1);
+
+        assertEquals(0, results.get(0).value, "Store content check failed");
+    }
+
+    @Test
+    public void shouldPutAndGetWithEmptyHeaders() throws Exception {
+        final Topology topology = buildTopology(() -> new 
VersionedStoreWithHeadersCheckerProcessor(true));
+        kafkaStreams = new KafkaStreams(topology, streamsConfiguration());
+        IntegrationTestUtils.startApplicationAndWaitUntilRunning(kafkaStreams);
+
+        produceDataToTopicWithHeaders(inputStream, baseTimestamp, 
emptyHeaders(),
+            new KeyValue<>(1, "value1"));
+
+        final List<KeyValue<Integer, Integer>> results =
+            IntegrationTestUtils.waitUntilMinKeyValueRecordsReceived(
+                consumerConfig(), outputStream, 1);
+
+        assertEquals(0, results.get(0).value, "Store content check failed for 
empty headers");
+    }
+
+    @Test
+    public void shouldPreserveHeadersAcrossMultipleVersions() throws Exception 
{

Review Comment:
   This never checks an older version. `data` is a HashMap keyed by the same 
key, so version2 overwrites the expectation and every check reads get(key) 
(latest) only — the older version's headers are never verified via get(key, 
olderTimestamp). Despite the name, multi-version header retention isn't 
actually exercised.



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