vpapavas commented on a change in pull request #11676:
URL: https://github.com/apache/kafka/pull/11676#discussion_r789512396



##########
File path: 
streams/src/test/java/org/apache/kafka/streams/integration/PositionCheckpointIntegrationTest.java
##########
@@ -0,0 +1,777 @@
+/*
+ * 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.clients.consumer.ConsumerConfig;
+import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.clients.producer.Producer;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.kafka.common.serialization.IntegerSerializer;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.common.utils.Time;
+import org.apache.kafka.streams.KafkaStreams;
+import org.apache.kafka.streams.StreamsBuilder;
+import org.apache.kafka.streams.StreamsConfig;
+import org.apache.kafka.streams.StreamsConfig.InternalConfig;
+import org.apache.kafka.streams.integration.utils.EmbeddedKafkaCluster;
+import org.apache.kafka.streams.integration.utils.IntegrationTestUtils;
+import org.apache.kafka.streams.kstream.Consumed;
+import org.apache.kafka.streams.kstream.Materialized;
+import org.apache.kafka.streams.kstream.SessionWindows;
+import org.apache.kafka.streams.kstream.TimeWindows;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.kstream.internals.SessionWindow;
+import org.apache.kafka.streams.processor.api.ContextualProcessor;
+import org.apache.kafka.streams.processor.api.ProcessorSupplier;
+import org.apache.kafka.streams.processor.api.Record;
+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.QueryResult;
+import org.apache.kafka.streams.query.StateQueryRequest;
+import org.apache.kafka.streams.query.StateQueryResult;
+import org.apache.kafka.streams.query.WindowKeyQuery;
+import org.apache.kafka.streams.query.WindowRangeQuery;
+import org.apache.kafka.streams.state.KeyValueBytesStoreSupplier;
+import org.apache.kafka.streams.state.KeyValueIterator;
+import org.apache.kafka.streams.state.KeyValueStore;
+import org.apache.kafka.streams.state.SessionBytesStoreSupplier;
+import org.apache.kafka.streams.state.SessionStore;
+import org.apache.kafka.streams.state.StoreBuilder;
+import org.apache.kafka.streams.state.StoreSupplier;
+import org.apache.kafka.streams.state.Stores;
+import org.apache.kafka.streams.state.TimestampedKeyValueStore;
+import org.apache.kafka.streams.state.TimestampedWindowStore;
+import org.apache.kafka.streams.state.ValueAndTimestamp;
+import org.apache.kafka.streams.state.WindowBytesStoreSupplier;
+import org.apache.kafka.streams.state.WindowStore;
+import org.apache.kafka.streams.state.WindowStoreIterator;
+import org.apache.kafka.test.IntegrationTest;
+import org.apache.kafka.test.TestUtils;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.Random;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.function.Consumer;
+
+import static org.apache.kafka.common.utils.Utils.mkSet;
+import static org.apache.kafka.streams.query.StateQueryRequest.inStore;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.fail;
+
+@Category({IntegrationTest.class})
+@RunWith(value = Parameterized.class)
+public class PositionCheckpointIntegrationTest {
+    private static final Logger LOG = 
LoggerFactory.getLogger(PositionCheckpointIntegrationTest.class);
+    private static final long SEED = new Random().nextLong();
+    private static final int NUM_BROKERS = 1;
+    public static final Duration WINDOW_SIZE = Duration.ofMinutes(5);
+    private static int port = 0;
+    private static final String INPUT_TOPIC_NAME = "input-topic";
+    private static final Position INPUT_POSITION = Position.emptyPosition();
+    private static final String STORE_NAME = "kv-store";
+    private static final long RECORD_TIME = System.currentTimeMillis();
+    private static final long WINDOW_START =
+        (RECORD_TIME / WINDOW_SIZE.toMillis()) * WINDOW_SIZE.toMillis();
+    public static final EmbeddedKafkaCluster CLUSTER = new 
EmbeddedKafkaCluster(NUM_BROKERS);
+    private final StoresToTest storeToTest;
+    private final String kind;
+    private final boolean cache;
+    private final boolean log;
+    private KafkaStreams kafkaStreams;
+    private Properties streamsConfig;
+
+    public enum StoresToTest {
+        ROCKS_KV {
+            @Override
+            public StoreSupplier<?> supplier() {
+                return Stores.persistentKeyValueStore(STORE_NAME);
+            }
+
+            @Override
+            public boolean timestamped() {
+                return false;
+            }
+
+            @Override
+            public boolean keyValue() {
+                return true;
+            }
+        },
+        TIME_ROCKS_KV {
+            @Override
+            public StoreSupplier<?> supplier() {
+                return Stores.persistentTimestampedKeyValueStore(STORE_NAME);
+            }
+
+            @Override
+            public boolean keyValue() {
+                return true;
+            }
+        },
+        ROCKS_WINDOW {
+            @Override
+            public StoreSupplier<?> supplier() {
+                return Stores.persistentWindowStore(STORE_NAME, 
Duration.ofDays(1), WINDOW_SIZE,
+                                                    false
+                );
+            }
+
+            @Override
+            public boolean isWindowed() {
+                return true;
+            }
+
+            @Override
+            public boolean timestamped() {
+                return false;
+            }
+        },
+        TIME_ROCKS_WINDOW {
+            @Override
+            public StoreSupplier<?> supplier() {
+                return Stores.persistentTimestampedWindowStore(STORE_NAME, 
Duration.ofDays(1),
+                                                               WINDOW_SIZE, 
false
+                );
+            }
+
+            @Override
+            public boolean isWindowed() {
+                return true;
+            }
+        },
+        ROCKS_SESSION {
+            @Override
+            public StoreSupplier<?> supplier() {
+                return Stores.persistentSessionStore(STORE_NAME, 
Duration.ofDays(1));
+            }
+
+            @Override
+            public boolean isSession() {
+                return true;
+            }
+        };
+
+        public abstract StoreSupplier<?> supplier();
+
+        public boolean timestamped() {
+            return true; // most stores are timestamped
+        }
+
+        public boolean global() {
+            return false;
+        }
+
+        public boolean keyValue() {
+            return false;
+        }
+
+        public boolean isWindowed() {
+            return false;
+        }
+
+        public boolean isSession() {
+            return false;
+        }
+    }
+
+    @Parameterized.Parameters(name = "cache={0}, log={1}, supplier={2}, 
kind={3}")
+    public static Collection<Object[]> data() {
+        LOG.info("Generating test cases according to random seed: {}", SEED);
+        final List<Object[]> values = new ArrayList<>();
+        for (final boolean cacheEnabled : Arrays.asList(false, true)) {
+            for (final boolean logEnabled : Arrays.asList(true)) {

Review comment:
       We had discussed this with Patrick. I think this is because only these 
stores are the ones that have changelog enabled. Hence, only these stores will 
restore their changelog into the state store and won't start with an empty 
store. The rationale then was that the position should match what the state 
store contains: if the state store is empty, the position should be empty, 
whereas if the state store is restored from the changelog, the position should 
be restored from the checkpoint file




-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to