You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2021/07/15 20:09:36 UTC

[GitHub] [kafka] cadonna opened a new pull request #11063: Add test to verify behavior of grace API

cadonna opened a new pull request #11063:
URL: https://github.com/apache/kafka/pull/11063


   
   ### Committer Checklist (excluded from commit message)
   - [ ] Verify design and implementation 
   - [ ] Verify test coverage and CI build status
   - [ ] Verify documentation (including upgrade notes)
   


-- 
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-unsubscribe@kafka.apache.org

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



[GitHub] [kafka] cadonna commented on pull request #11063: Add test to verify behavior of grace API

Posted by GitBox <gi...@apache.org>.
cadonna commented on pull request #11063:
URL: https://github.com/apache/kafka/pull/11063#issuecomment-880982426


   It is expected that the tests fail since #10953 is not merged yet. Once #10953 is merged and this PR is rebased on trunk the test should not fail anymore.


-- 
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-unsubscribe@kafka.apache.org

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



[GitHub] [kafka] cadonna commented on a change in pull request #11063: Add test to verify behavior of grace API

Posted by GitBox <gi...@apache.org>.
cadonna commented on a change in pull request #11063:
URL: https://github.com/apache/kafka/pull/11063#discussion_r671139543



##########
File path: streams/src/test/java/org/apache/kafka/streams/integration/WindowedChangelogRetentionIntegrationTest.java
##########
@@ -0,0 +1,365 @@
+/*
+ * 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.common.config.TopicConfig;
+import org.apache.kafka.common.serialization.Serde;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.streams.KafkaStreams;
+import org.apache.kafka.streams.KafkaStreams.State;
+import org.apache.kafka.streams.StreamsBuilder;
+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.kstream.Consumed;
+import org.apache.kafka.streams.kstream.Grouped;
+import org.apache.kafka.streams.kstream.JoinWindows;
+import org.apache.kafka.streams.kstream.KGroupedStream;
+import org.apache.kafka.streams.kstream.KStream;
+import org.apache.kafka.streams.kstream.KeyValueMapper;
+import org.apache.kafka.streams.kstream.Materialized;
+import org.apache.kafka.streams.kstream.Produced;
+import org.apache.kafka.streams.kstream.SessionWindows;
+import org.apache.kafka.streams.kstream.StreamJoined;
+import org.apache.kafka.streams.kstream.TimeWindows;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.kstream.WindowedSerdes;
+import org.apache.kafka.streams.state.SessionStore;
+import org.apache.kafka.streams.state.WindowStore;
+import org.apache.kafka.test.IntegrationTest;
+import org.apache.kafka.test.MockMapper;
+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.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Properties;
+
+import static org.apache.kafka.streams.integration.utils.IntegrationTestUtils.safeUniqueTestName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+@SuppressWarnings("deprecation")
+@Category({IntegrationTest.class})
+public class WindowedChangelogRetentionIntegrationTest {
+    private static final int NUM_BROKERS = 1;
+    private static final Duration DEFAULT_RETENTION = Duration.ofDays(1);
+
+    public static final EmbeddedKafkaCluster CLUSTER = new EmbeddedKafkaCluster(NUM_BROKERS);
+
+    private StreamsBuilder builder;
+    private Properties streamsConfiguration;
+    private KafkaStreams kafkaStreams;
+    private String streamOneInput;
+    private String streamTwoInput;
+    private String outputTopic;
+    private KGroupedStream<String, String> groupedStream;
+    private KStream<Integer, String> stream;
+    private KStream<Integer, String> stream1;
+    private KStream<Integer, String> stream2;
+
+    @Rule
+    public TestName testName = new TestName();
+
+    @BeforeClass
+    public static void startCluster() throws IOException {
+        CLUSTER.start();
+    }
+
+    @AfterClass
+    public static void closeCluster() {
+        CLUSTER.stop();
+    }
+
+    @Before
+    public void before() throws InterruptedException {
+        builder = new StreamsBuilder();
+        createTopics();
+        streamsConfiguration = new Properties();
+        final String safeTestName = safeUniqueTestName(getClass(), testName);
+        streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "app-" + safeTestName);
+        streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
+        streamsConfiguration.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
+        streamsConfiguration.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath());
+        streamsConfiguration.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 0);
+        streamsConfiguration.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 100);
+        streamsConfiguration.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
+        streamsConfiguration.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.Integer().getClass());
+
+        final KeyValueMapper<Integer, String, String> mapper = MockMapper.selectValueMapper();
+        stream = builder.stream(streamOneInput, Consumed.with(Serdes.Integer(), Serdes.String()));
+        groupedStream = stream.groupBy(mapper, Grouped.with(Serdes.String(), Serdes.String()));
+    }
+
+    @After
+    public void whenShuttingDown() throws Exception {
+        if (kafkaStreams != null) {
+            kafkaStreams.close();
+        }
+        IntegrationTestUtils.purgeLocalStreamsState(streamsConfiguration);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSize() throws Exception {
+        final Duration windowSize = Duration.ofDays(2);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize))
+                .count(Materialized.as(storeName))
+                .toStream()
+                .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, windowSize);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveDefaultRetentionWithoutGrace() throws Exception {
+        final Duration windowSize = Duration.ofMillis(500);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(Duration.ofMillis(500)))
+                .count(Materialized.as(storeName))
+                .toStream()
+                .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, DEFAULT_RETENTION);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveDefaultRetentionWithGrace() throws Exception {
+        final Duration windowSize = Duration.ofMillis(500);
+        final Duration grace = Duration.ofMillis(1000);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize).grace(grace))
+                .count(Materialized.as(storeName))
+                .toStream()
+                .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, DEFAULT_RETENTION);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSizeAndGrace() throws Exception {
+        final Duration windowSize = Duration.ofDays(1);
+        final Duration grace = Duration.ofHours(12);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize).grace(grace))
+                .count(Materialized.as(storeName))
+                .toStream()
+                .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, windowSize.plus(grace));
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveUserSpecifiedRetention() throws Exception {
+        final Duration windowSize = Duration.ofDays(1);
+        final Duration grace = Duration.ofHours(12);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize).grace(grace))
+                .count(Materialized.<String, Long, WindowStore<Bytes, byte[]>>as(storeName).withRetention(windowSize.multipliedBy(3)))

Review comment:
       "times 3" is indeed not that comprehensible. I just chose a duration that was greater than window size + grace. The point is not that it must be greater than max(default, windowSize + grace). If users specify a retention via `Materialized`, the retention must be larger than window size + grace, otherwhise an exception is thrown. I will set window size + grace + 1 hour.




-- 
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-unsubscribe@kafka.apache.org

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



[GitHub] [kafka] cadonna commented on a change in pull request #11063: MINOR: Add test to verify behavior of grace API

Posted by GitBox <gi...@apache.org>.
cadonna commented on a change in pull request #11063:
URL: https://github.com/apache/kafka/pull/11063#discussion_r673232056



##########
File path: streams/src/test/java/org/apache/kafka/streams/integration/WindowedChangelogRetentionIntegrationTest.java
##########
@@ -0,0 +1,326 @@
+/*
+ * 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.common.config.TopicConfig;
+import org.apache.kafka.common.serialization.Serde;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.streams.KafkaStreams;
+import org.apache.kafka.streams.KafkaStreams.State;
+import org.apache.kafka.streams.StreamsBuilder;
+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.kstream.Consumed;
+import org.apache.kafka.streams.kstream.Grouped;
+import org.apache.kafka.streams.kstream.JoinWindows;
+import org.apache.kafka.streams.kstream.KGroupedStream;
+import org.apache.kafka.streams.kstream.KStream;
+import org.apache.kafka.streams.kstream.KeyValueMapper;
+import org.apache.kafka.streams.kstream.Materialized;
+import org.apache.kafka.streams.kstream.Produced;
+import org.apache.kafka.streams.kstream.SessionWindows;
+import org.apache.kafka.streams.kstream.StreamJoined;
+import org.apache.kafka.streams.kstream.TimeWindows;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.kstream.WindowedSerdes;
+import org.apache.kafka.streams.kstream.Windows;
+import org.apache.kafka.streams.kstream.internals.TimeWindow;
+import org.apache.kafka.streams.state.SessionStore;
+import org.apache.kafka.streams.state.WindowStore;
+import org.apache.kafka.test.IntegrationTest;
+import org.apache.kafka.test.MockMapper;
+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.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Properties;
+
+import static org.apache.kafka.streams.integration.utils.IntegrationTestUtils.safeUniqueTestName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+@SuppressWarnings("deprecation")
+@Category({IntegrationTest.class})
+public class WindowedChangelogRetentionIntegrationTest {
+    private static final int NUM_BROKERS = 1;
+    private static final Duration DEFAULT_RETENTION = Duration.ofDays(1);
+    private static final String STREAM_ONE_INPUT = "stream-one";
+    private static final String STREAM_TWO_INPUT = "stream-two";
+    private static final String OUTPUT_TOPIC = "output";
+
+    public static final EmbeddedKafkaCluster CLUSTER = new EmbeddedKafkaCluster(NUM_BROKERS);
+
+    private StreamsBuilder builder;
+    private Properties streamsConfiguration;
+    private KafkaStreams kafkaStreams;
+    private KGroupedStream<String, String> groupedStream;
+
+    @Rule
+    public TestName testName = new TestName();
+
+    @BeforeClass
+    public static void startCluster() throws IOException, InterruptedException {
+        CLUSTER.start();
+        createTopics();
+    }
+
+    @AfterClass
+    public static void closeCluster() {
+        CLUSTER.stop();
+    }
+
+    @Before
+    public void before() {
+        builder = new StreamsBuilder();
+        streamsConfiguration = new Properties();
+        final String safeTestName = safeUniqueTestName(getClass(), testName);
+        streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "app-" + safeTestName);
+        streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
+        streamsConfiguration.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
+        streamsConfiguration.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath());
+        streamsConfiguration.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 0);
+        streamsConfiguration.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 100);
+        streamsConfiguration.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
+        streamsConfiguration.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.Integer().getClass());
+
+        final KeyValueMapper<Integer, String, String> mapper = MockMapper.selectValueMapper();
+        final KStream<Integer, String> stream = builder.stream(STREAM_ONE_INPUT, Consumed.with(Serdes.Integer(), Serdes.String()));
+        groupedStream = stream.groupBy(mapper, Grouped.with(Serdes.String(), Serdes.String()));
+    }
+
+    @After
+    public void whenShuttingDown() throws Exception {
+        if (kafkaStreams != null) {
+            kafkaStreams.close();
+        }
+        IntegrationTestUtils.purgeLocalStreamsState(streamsConfiguration);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSizeIfWindowSizeLargerThanDefaultRetention() throws Exception {
+        final Duration windowSize = DEFAULT_RETENTION.plus(Duration.ofHours(1));
+        final Duration expectedRetention = windowSize;
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveDefaultRetentionIfWindowSizeLessThanDefaultRetention() throws Exception {
+        final Duration windowSize = DEFAULT_RETENTION.minus(Duration.ofHours(1));
+        final Duration expectedRetention = DEFAULT_RETENTION;
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSizePlusGraceIfWindowSizePlusGraceLargerThanDefaultRetention() throws Exception {
+        final Duration windowSize = DEFAULT_RETENTION.plus(Duration.ofHours(1));
+        final Duration grace = Duration.ofHours(12);
+        final Duration expectedRetention = windowSize.plus(grace);
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize).grace(grace), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSizePlusGraceIfWindowSizePlusGraceLessThanDefaultRetention() throws Exception {
+        final Duration grace = Duration.ofMillis(1000);
+        final Duration windowSize = DEFAULT_RETENTION.minus(grace).minus(Duration.ofMillis(500));
+        final Duration expectedRetention = windowSize.plus(grace);
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize).grace(grace), null, expectedRetention);

Review comment:
       With 3.0 we do not use the default retention if window size + grace is less than the default retention. I think that is fine because a changelog topic that is created with 2.8 has a larger retention time than a changelog topic created with 3.0. \cc @mjsax  @showuon 

##########
File path: streams/src/test/java/org/apache/kafka/streams/integration/WindowedChangelogRetentionIntegrationTest.java
##########
@@ -0,0 +1,326 @@
+/*
+ * 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.common.config.TopicConfig;
+import org.apache.kafka.common.serialization.Serde;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.streams.KafkaStreams;
+import org.apache.kafka.streams.KafkaStreams.State;
+import org.apache.kafka.streams.StreamsBuilder;
+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.kstream.Consumed;
+import org.apache.kafka.streams.kstream.Grouped;
+import org.apache.kafka.streams.kstream.JoinWindows;
+import org.apache.kafka.streams.kstream.KGroupedStream;
+import org.apache.kafka.streams.kstream.KStream;
+import org.apache.kafka.streams.kstream.KeyValueMapper;
+import org.apache.kafka.streams.kstream.Materialized;
+import org.apache.kafka.streams.kstream.Produced;
+import org.apache.kafka.streams.kstream.SessionWindows;
+import org.apache.kafka.streams.kstream.StreamJoined;
+import org.apache.kafka.streams.kstream.TimeWindows;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.kstream.WindowedSerdes;
+import org.apache.kafka.streams.kstream.Windows;
+import org.apache.kafka.streams.kstream.internals.TimeWindow;
+import org.apache.kafka.streams.state.SessionStore;
+import org.apache.kafka.streams.state.WindowStore;
+import org.apache.kafka.test.IntegrationTest;
+import org.apache.kafka.test.MockMapper;
+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.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Properties;
+
+import static org.apache.kafka.streams.integration.utils.IntegrationTestUtils.safeUniqueTestName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+@SuppressWarnings("deprecation")
+@Category({IntegrationTest.class})
+public class WindowedChangelogRetentionIntegrationTest {
+    private static final int NUM_BROKERS = 1;
+    private static final Duration DEFAULT_RETENTION = Duration.ofDays(1);
+    private static final String STREAM_ONE_INPUT = "stream-one";
+    private static final String STREAM_TWO_INPUT = "stream-two";
+    private static final String OUTPUT_TOPIC = "output";
+
+    public static final EmbeddedKafkaCluster CLUSTER = new EmbeddedKafkaCluster(NUM_BROKERS);
+
+    private StreamsBuilder builder;
+    private Properties streamsConfiguration;
+    private KafkaStreams kafkaStreams;
+    private KGroupedStream<String, String> groupedStream;
+
+    @Rule
+    public TestName testName = new TestName();
+
+    @BeforeClass
+    public static void startCluster() throws IOException, InterruptedException {
+        CLUSTER.start();
+        createTopics();
+    }
+
+    @AfterClass
+    public static void closeCluster() {
+        CLUSTER.stop();
+    }
+
+    @Before
+    public void before() {
+        builder = new StreamsBuilder();
+        streamsConfiguration = new Properties();
+        final String safeTestName = safeUniqueTestName(getClass(), testName);
+        streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "app-" + safeTestName);
+        streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
+        streamsConfiguration.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
+        streamsConfiguration.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath());
+        streamsConfiguration.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 0);
+        streamsConfiguration.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 100);
+        streamsConfiguration.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
+        streamsConfiguration.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.Integer().getClass());
+
+        final KeyValueMapper<Integer, String, String> mapper = MockMapper.selectValueMapper();
+        final KStream<Integer, String> stream = builder.stream(STREAM_ONE_INPUT, Consumed.with(Serdes.Integer(), Serdes.String()));
+        groupedStream = stream.groupBy(mapper, Grouped.with(Serdes.String(), Serdes.String()));
+    }
+
+    @After
+    public void whenShuttingDown() throws Exception {
+        if (kafkaStreams != null) {
+            kafkaStreams.close();
+        }
+        IntegrationTestUtils.purgeLocalStreamsState(streamsConfiguration);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSizeIfWindowSizeLargerThanDefaultRetention() throws Exception {
+        final Duration windowSize = DEFAULT_RETENTION.plus(Duration.ofHours(1));
+        final Duration expectedRetention = windowSize;
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveDefaultRetentionIfWindowSizeLessThanDefaultRetention() throws Exception {
+        final Duration windowSize = DEFAULT_RETENTION.minus(Duration.ofHours(1));
+        final Duration expectedRetention = DEFAULT_RETENTION;
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSizePlusGraceIfWindowSizePlusGraceLargerThanDefaultRetention() throws Exception {
+        final Duration windowSize = DEFAULT_RETENTION.plus(Duration.ofHours(1));
+        final Duration grace = Duration.ofHours(12);
+        final Duration expectedRetention = windowSize.plus(grace);
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize).grace(grace), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSizePlusGraceIfWindowSizePlusGraceLessThanDefaultRetention() throws Exception {
+        final Duration grace = Duration.ofMillis(1000);
+        final Duration windowSize = DEFAULT_RETENTION.minus(grace).minus(Duration.ofMillis(500));
+        final Duration expectedRetention = windowSize.plus(grace);
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize).grace(grace), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveUserSpecifiedRetentionIfUserSpecifiedRetentionEvenIfLessThanDefaultRetention() throws Exception {
+        final Duration grace = Duration.ofHours(6);
+        final Duration windowSize = DEFAULT_RETENTION.minus(grace).minus(Duration.ofHours(1));
+        final Duration userSpecifiedRetention = windowSize.plus(grace).plus(Duration.ofHours(1));
+        final Duration expectedRetention = userSpecifiedRetention;
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize).grace(grace), userSpecifiedRetention, expectedRetention);
+    }
+
+    private void runAndVerifyTimeWindows(final Windows<TimeWindow> window,
+                                         final Duration userSpecifiedRetention,
+                                         final Duration expectedRetention) throws Exception {
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, window.size());
+        groupedStream.windowedBy(window)
+            .count(userSpecifiedRetention != null
+                ? Materialized.<String, Long, WindowStore<Bytes, byte[]>>as(storeName).withRetention(userSpecifiedRetention)
+                : Materialized.as(storeName))
+            .toStream()
+            .to(OUTPUT_TOPIC, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, expectedRetention);
+    }
+
+    @Test
+    public void sessionWindowedChangelogShouldHaveRetentionOfGapIfGapLargerThanDefaultRetention() throws Exception {
+        final Duration gap = DEFAULT_RETENTION.plus(Duration.ofHours(1));
+        final Duration expectedRetention = gap;
+        runAndVerifySessionWindows(SessionWindows.with(gap), null, expectedRetention);
+    }
+
+    @Test
+    public void sessionWindowedChangelogShouldHaveDefaultRetentionIfGapLessThanDefaultRetention() throws Exception {
+        final Duration gap = DEFAULT_RETENTION.minus(Duration.ofHours(1));
+        final Duration expectedRetention = DEFAULT_RETENTION;
+        runAndVerifySessionWindows(SessionWindows.with(gap), null, expectedRetention);
+    }
+
+    @Test
+    public void sessionWindowedChangelogShouldHaveRetentionOfGapPlusGraceIfGapPlusGraceLessThanDefaultRetention() throws Exception {
+        final Duration grace = Duration.ofHours(1);
+        final Duration gap = DEFAULT_RETENTION.minus(grace).minus(Duration.ofHours(1));
+        final Duration expectedRetention = gap.plus(grace);
+        runAndVerifySessionWindows(SessionWindows.with(gap).grace(grace), null, expectedRetention);
+    }

Review comment:
       With 3.0 we do not use the default retention if gap + grace is less than the default retention. I think that is fine because a changelog topic that is created with 2.8 has a larger retention time than a changelog topic created with 3.0. \cc @mjsax   @showuon 




-- 
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-unsubscribe@kafka.apache.org

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



[GitHub] [kafka] cadonna commented on a change in pull request #11063: MINOR: Add test to verify behavior of grace API

Posted by GitBox <gi...@apache.org>.
cadonna commented on a change in pull request #11063:
URL: https://github.com/apache/kafka/pull/11063#discussion_r673232451



##########
File path: streams/src/test/java/org/apache/kafka/streams/integration/WindowedChangelogRetentionIntegrationTest.java
##########
@@ -0,0 +1,326 @@
+/*
+ * 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.common.config.TopicConfig;
+import org.apache.kafka.common.serialization.Serde;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.streams.KafkaStreams;
+import org.apache.kafka.streams.KafkaStreams.State;
+import org.apache.kafka.streams.StreamsBuilder;
+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.kstream.Consumed;
+import org.apache.kafka.streams.kstream.Grouped;
+import org.apache.kafka.streams.kstream.JoinWindows;
+import org.apache.kafka.streams.kstream.KGroupedStream;
+import org.apache.kafka.streams.kstream.KStream;
+import org.apache.kafka.streams.kstream.KeyValueMapper;
+import org.apache.kafka.streams.kstream.Materialized;
+import org.apache.kafka.streams.kstream.Produced;
+import org.apache.kafka.streams.kstream.SessionWindows;
+import org.apache.kafka.streams.kstream.StreamJoined;
+import org.apache.kafka.streams.kstream.TimeWindows;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.kstream.WindowedSerdes;
+import org.apache.kafka.streams.kstream.Windows;
+import org.apache.kafka.streams.kstream.internals.TimeWindow;
+import org.apache.kafka.streams.state.SessionStore;
+import org.apache.kafka.streams.state.WindowStore;
+import org.apache.kafka.test.IntegrationTest;
+import org.apache.kafka.test.MockMapper;
+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.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Properties;
+
+import static org.apache.kafka.streams.integration.utils.IntegrationTestUtils.safeUniqueTestName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+@SuppressWarnings("deprecation")
+@Category({IntegrationTest.class})
+public class WindowedChangelogRetentionIntegrationTest {
+    private static final int NUM_BROKERS = 1;
+    private static final Duration DEFAULT_RETENTION = Duration.ofDays(1);
+    private static final String STREAM_ONE_INPUT = "stream-one";
+    private static final String STREAM_TWO_INPUT = "stream-two";
+    private static final String OUTPUT_TOPIC = "output";
+
+    public static final EmbeddedKafkaCluster CLUSTER = new EmbeddedKafkaCluster(NUM_BROKERS);
+
+    private StreamsBuilder builder;
+    private Properties streamsConfiguration;
+    private KafkaStreams kafkaStreams;
+    private KGroupedStream<String, String> groupedStream;
+
+    @Rule
+    public TestName testName = new TestName();
+
+    @BeforeClass
+    public static void startCluster() throws IOException, InterruptedException {
+        CLUSTER.start();
+        createTopics();
+    }
+
+    @AfterClass
+    public static void closeCluster() {
+        CLUSTER.stop();
+    }
+
+    @Before
+    public void before() {
+        builder = new StreamsBuilder();
+        streamsConfiguration = new Properties();
+        final String safeTestName = safeUniqueTestName(getClass(), testName);
+        streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "app-" + safeTestName);
+        streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
+        streamsConfiguration.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
+        streamsConfiguration.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath());
+        streamsConfiguration.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 0);
+        streamsConfiguration.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 100);
+        streamsConfiguration.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
+        streamsConfiguration.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.Integer().getClass());
+
+        final KeyValueMapper<Integer, String, String> mapper = MockMapper.selectValueMapper();
+        final KStream<Integer, String> stream = builder.stream(STREAM_ONE_INPUT, Consumed.with(Serdes.Integer(), Serdes.String()));
+        groupedStream = stream.groupBy(mapper, Grouped.with(Serdes.String(), Serdes.String()));
+    }
+
+    @After
+    public void whenShuttingDown() throws Exception {
+        if (kafkaStreams != null) {
+            kafkaStreams.close();
+        }
+        IntegrationTestUtils.purgeLocalStreamsState(streamsConfiguration);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSizeIfWindowSizeLargerThanDefaultRetention() throws Exception {
+        final Duration windowSize = DEFAULT_RETENTION.plus(Duration.ofHours(1));
+        final Duration expectedRetention = windowSize;
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveDefaultRetentionIfWindowSizeLessThanDefaultRetention() throws Exception {
+        final Duration windowSize = DEFAULT_RETENTION.minus(Duration.ofHours(1));
+        final Duration expectedRetention = DEFAULT_RETENTION;
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSizePlusGraceIfWindowSizePlusGraceLargerThanDefaultRetention() throws Exception {
+        final Duration windowSize = DEFAULT_RETENTION.plus(Duration.ofHours(1));
+        final Duration grace = Duration.ofHours(12);
+        final Duration expectedRetention = windowSize.plus(grace);
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize).grace(grace), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSizePlusGraceIfWindowSizePlusGraceLessThanDefaultRetention() throws Exception {
+        final Duration grace = Duration.ofMillis(1000);
+        final Duration windowSize = DEFAULT_RETENTION.minus(grace).minus(Duration.ofMillis(500));
+        final Duration expectedRetention = windowSize.plus(grace);
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize).grace(grace), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveUserSpecifiedRetentionIfUserSpecifiedRetentionEvenIfLessThanDefaultRetention() throws Exception {
+        final Duration grace = Duration.ofHours(6);
+        final Duration windowSize = DEFAULT_RETENTION.minus(grace).minus(Duration.ofHours(1));
+        final Duration userSpecifiedRetention = windowSize.plus(grace).plus(Duration.ofHours(1));
+        final Duration expectedRetention = userSpecifiedRetention;
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize).grace(grace), userSpecifiedRetention, expectedRetention);
+    }
+
+    private void runAndVerifyTimeWindows(final Windows<TimeWindow> window,
+                                         final Duration userSpecifiedRetention,
+                                         final Duration expectedRetention) throws Exception {
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, window.size());
+        groupedStream.windowedBy(window)
+            .count(userSpecifiedRetention != null
+                ? Materialized.<String, Long, WindowStore<Bytes, byte[]>>as(storeName).withRetention(userSpecifiedRetention)
+                : Materialized.as(storeName))
+            .toStream()
+            .to(OUTPUT_TOPIC, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, expectedRetention);
+    }
+
+    @Test
+    public void sessionWindowedChangelogShouldHaveRetentionOfGapIfGapLargerThanDefaultRetention() throws Exception {
+        final Duration gap = DEFAULT_RETENTION.plus(Duration.ofHours(1));
+        final Duration expectedRetention = gap;
+        runAndVerifySessionWindows(SessionWindows.with(gap), null, expectedRetention);
+    }
+
+    @Test
+    public void sessionWindowedChangelogShouldHaveDefaultRetentionIfGapLessThanDefaultRetention() throws Exception {
+        final Duration gap = DEFAULT_RETENTION.minus(Duration.ofHours(1));
+        final Duration expectedRetention = DEFAULT_RETENTION;
+        runAndVerifySessionWindows(SessionWindows.with(gap), null, expectedRetention);
+    }
+
+    @Test
+    public void sessionWindowedChangelogShouldHaveRetentionOfGapPlusGraceIfGapPlusGraceLessThanDefaultRetention() throws Exception {
+        final Duration grace = Duration.ofHours(1);
+        final Duration gap = DEFAULT_RETENTION.minus(grace).minus(Duration.ofHours(1));
+        final Duration expectedRetention = gap.plus(grace);
+        runAndVerifySessionWindows(SessionWindows.with(gap).grace(grace), null, expectedRetention);
+    }

Review comment:
       With 3.0 we do not use the default retention if gap + grace is less than the default retention. I think that is fine because a changelog topic that is created with 2.8 has a larger retention time than a changelog topic created with 3.0. \cc @mjsax  




-- 
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-unsubscribe@kafka.apache.org

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



[GitHub] [kafka] showuon commented on a change in pull request #11063: Add test to verify behavior of grace API

Posted by GitBox <gi...@apache.org>.
showuon commented on a change in pull request #11063:
URL: https://github.com/apache/kafka/pull/11063#discussion_r671818564



##########
File path: streams/src/test/java/org/apache/kafka/streams/integration/WindowedChangelogRetentionIntegrationTest.java
##########
@@ -0,0 +1,304 @@
+/*
+ * 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.common.config.TopicConfig;
+import org.apache.kafka.common.serialization.Serde;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.streams.KafkaStreams;
+import org.apache.kafka.streams.KafkaStreams.State;
+import org.apache.kafka.streams.StreamsBuilder;
+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.kstream.Consumed;
+import org.apache.kafka.streams.kstream.Grouped;
+import org.apache.kafka.streams.kstream.JoinWindows;
+import org.apache.kafka.streams.kstream.KGroupedStream;
+import org.apache.kafka.streams.kstream.KStream;
+import org.apache.kafka.streams.kstream.KeyValueMapper;
+import org.apache.kafka.streams.kstream.Materialized;
+import org.apache.kafka.streams.kstream.Produced;
+import org.apache.kafka.streams.kstream.SessionWindows;
+import org.apache.kafka.streams.kstream.StreamJoined;
+import org.apache.kafka.streams.kstream.TimeWindows;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.kstream.WindowedSerdes;
+import org.apache.kafka.streams.kstream.Windows;
+import org.apache.kafka.streams.kstream.internals.TimeWindow;
+import org.apache.kafka.streams.state.SessionStore;
+import org.apache.kafka.streams.state.WindowStore;
+import org.apache.kafka.test.IntegrationTest;
+import org.apache.kafka.test.MockMapper;
+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.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Properties;
+
+import static org.apache.kafka.streams.integration.utils.IntegrationTestUtils.safeUniqueTestName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+@SuppressWarnings("deprecation")
+@Category({IntegrationTest.class})
+public class WindowedChangelogRetentionIntegrationTest {
+    private static final int NUM_BROKERS = 1;
+    private static final Duration DEFAULT_RETENTION = Duration.ofDays(1);
+
+    public static final EmbeddedKafkaCluster CLUSTER = new EmbeddedKafkaCluster(NUM_BROKERS);
+
+    private StreamsBuilder builder;
+    private Properties streamsConfiguration;
+    private KafkaStreams kafkaStreams;
+    private String streamOneInput;
+    private String streamTwoInput;
+    private String outputTopic;
+    private KGroupedStream<String, String> groupedStream;
+
+    @Rule
+    public TestName testName = new TestName();
+
+    @BeforeClass
+    public static void startCluster() throws IOException {
+        CLUSTER.start();
+    }
+
+    @AfterClass
+    public static void closeCluster() {
+        CLUSTER.stop();
+    }
+
+    @Before
+    public void before() throws InterruptedException {
+        builder = new StreamsBuilder();
+        createTopics();
+        streamsConfiguration = new Properties();
+        final String safeTestName = safeUniqueTestName(getClass(), testName);
+        streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "app-" + safeTestName);
+        streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
+        streamsConfiguration.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
+        streamsConfiguration.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath());
+        streamsConfiguration.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 0);
+        streamsConfiguration.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 100);
+        streamsConfiguration.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
+        streamsConfiguration.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.Integer().getClass());
+
+        final KeyValueMapper<Integer, String, String> mapper = MockMapper.selectValueMapper();
+        final KStream<Integer, String> stream = builder.stream(streamOneInput, Consumed.with(Serdes.Integer(), Serdes.String()));
+        groupedStream = stream.groupBy(mapper, Grouped.with(Serdes.String(), Serdes.String()));
+    }
+
+    @After
+    public void whenShuttingDown() throws Exception {
+        if (kafkaStreams != null) {
+            kafkaStreams.close();
+        }
+        IntegrationTestUtils.purgeLocalStreamsState(streamsConfiguration);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSizeIfWindowSizeLargerThanDefaultRetention() throws Exception {
+        final Duration windowSize = DEFAULT_RETENTION.plus(Duration.ofHours(1));
+        final Duration expectedRetention = windowSize;
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveDefaultRetentionIfWindowSizeLessThanDefaultRetention() throws Exception {
+        final Duration windowSize = DEFAULT_RETENTION.minus(Duration.ofHours(1));
+        final Duration expectedRetention = DEFAULT_RETENTION;
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSizePlusGraceIfWindowSizePlusGraceLargerThanDefaultRetention() throws Exception {
+        final Duration windowSize = DEFAULT_RETENTION.plus(Duration.ofHours(1));
+        final Duration grace = Duration.ofHours(12);
+        final Duration expectedRetention = windowSize.plus(grace);
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize).grace(grace), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveDefaultRetentionIfWindowSizePlusGraceLessThanDefaultRetention() throws Exception {
+        final Duration grace = Duration.ofMillis(1000);
+        final Duration windowSize = DEFAULT_RETENTION.minus(grace).minus(Duration.ofMillis(500));
+        final Duration expectedRetention = DEFAULT_RETENTION;
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize).grace(grace), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveUserSpecifiedRetentionIfUserSpecifiedRetentionEvenIfLessThanDefaultRetention() throws Exception {

Review comment:
       typo: `timeWindowedChangelogShouldHaveUserSpecifiedRetentionIfUserSpecifiedRetentionEvenIfLessThanDefaultRetention` -> `timeWindowedChangelogShouldHaveUserSpecifiedRetentionIfUserSpecifiedRetentionLessThanDefaultRetention`?

##########
File path: streams/src/test/java/org/apache/kafka/streams/integration/WindowedChangelogRetentionIntegrationTest.java
##########
@@ -0,0 +1,304 @@
+/*
+ * 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.common.config.TopicConfig;
+import org.apache.kafka.common.serialization.Serde;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.streams.KafkaStreams;
+import org.apache.kafka.streams.KafkaStreams.State;
+import org.apache.kafka.streams.StreamsBuilder;
+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.kstream.Consumed;
+import org.apache.kafka.streams.kstream.Grouped;
+import org.apache.kafka.streams.kstream.JoinWindows;
+import org.apache.kafka.streams.kstream.KGroupedStream;
+import org.apache.kafka.streams.kstream.KStream;
+import org.apache.kafka.streams.kstream.KeyValueMapper;
+import org.apache.kafka.streams.kstream.Materialized;
+import org.apache.kafka.streams.kstream.Produced;
+import org.apache.kafka.streams.kstream.SessionWindows;
+import org.apache.kafka.streams.kstream.StreamJoined;
+import org.apache.kafka.streams.kstream.TimeWindows;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.kstream.WindowedSerdes;
+import org.apache.kafka.streams.kstream.Windows;
+import org.apache.kafka.streams.kstream.internals.TimeWindow;
+import org.apache.kafka.streams.state.SessionStore;
+import org.apache.kafka.streams.state.WindowStore;
+import org.apache.kafka.test.IntegrationTest;
+import org.apache.kafka.test.MockMapper;
+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.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Properties;
+
+import static org.apache.kafka.streams.integration.utils.IntegrationTestUtils.safeUniqueTestName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+@SuppressWarnings("deprecation")
+@Category({IntegrationTest.class})
+public class WindowedChangelogRetentionIntegrationTest {
+    private static final int NUM_BROKERS = 1;
+    private static final Duration DEFAULT_RETENTION = Duration.ofDays(1);
+
+    public static final EmbeddedKafkaCluster CLUSTER = new EmbeddedKafkaCluster(NUM_BROKERS);
+
+    private StreamsBuilder builder;
+    private Properties streamsConfiguration;
+    private KafkaStreams kafkaStreams;
+    private String streamOneInput;
+    private String streamTwoInput;
+    private String outputTopic;
+    private KGroupedStream<String, String> groupedStream;
+
+    @Rule
+    public TestName testName = new TestName();
+
+    @BeforeClass
+    public static void startCluster() throws IOException {
+        CLUSTER.start();
+    }
+
+    @AfterClass
+    public static void closeCluster() {
+        CLUSTER.stop();
+    }
+
+    @Before
+    public void before() throws InterruptedException {
+        builder = new StreamsBuilder();
+        createTopics();
+        streamsConfiguration = new Properties();
+        final String safeTestName = safeUniqueTestName(getClass(), testName);
+        streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "app-" + safeTestName);
+        streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
+        streamsConfiguration.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
+        streamsConfiguration.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath());
+        streamsConfiguration.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 0);
+        streamsConfiguration.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 100);
+        streamsConfiguration.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
+        streamsConfiguration.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.Integer().getClass());
+
+        final KeyValueMapper<Integer, String, String> mapper = MockMapper.selectValueMapper();
+        final KStream<Integer, String> stream = builder.stream(streamOneInput, Consumed.with(Serdes.Integer(), Serdes.String()));
+        groupedStream = stream.groupBy(mapper, Grouped.with(Serdes.String(), Serdes.String()));
+    }
+
+    @After
+    public void whenShuttingDown() throws Exception {
+        if (kafkaStreams != null) {
+            kafkaStreams.close();
+        }
+        IntegrationTestUtils.purgeLocalStreamsState(streamsConfiguration);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSizeIfWindowSizeLargerThanDefaultRetention() throws Exception {
+        final Duration windowSize = DEFAULT_RETENTION.plus(Duration.ofHours(1));
+        final Duration expectedRetention = windowSize;
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveDefaultRetentionIfWindowSizeLessThanDefaultRetention() throws Exception {
+        final Duration windowSize = DEFAULT_RETENTION.minus(Duration.ofHours(1));
+        final Duration expectedRetention = DEFAULT_RETENTION;
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSizePlusGraceIfWindowSizePlusGraceLargerThanDefaultRetention() throws Exception {
+        final Duration windowSize = DEFAULT_RETENTION.plus(Duration.ofHours(1));
+        final Duration grace = Duration.ofHours(12);
+        final Duration expectedRetention = windowSize.plus(grace);
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize).grace(grace), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveDefaultRetentionIfWindowSizePlusGraceLessThanDefaultRetention() throws Exception {
+        final Duration grace = Duration.ofMillis(1000);
+        final Duration windowSize = DEFAULT_RETENTION.minus(grace).minus(Duration.ofMillis(500));
+        final Duration expectedRetention = DEFAULT_RETENTION;
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize).grace(grace), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveUserSpecifiedRetentionIfUserSpecifiedRetentionEvenIfLessThanDefaultRetention() throws Exception {
+        final Duration grace = Duration.ofHours(6);
+        final Duration windowSize = DEFAULT_RETENTION.minus(grace).minus(Duration.ofHours(1));
+        final Duration userSpecifiedRetention = windowSize.plus(grace).plus(Duration.ofHours(1));
+        final Duration expectedRetention = userSpecifiedRetention;
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize).grace(grace), userSpecifiedRetention, expectedRetention);
+    }
+
+    private void runAndVerifyTimeWindows(final Windows<TimeWindow> window,
+                                         final Duration userSpecifiedRetention,
+                                         final Duration expectedRetention) throws Exception {
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, window.size());
+        groupedStream.windowedBy(window)
+            .count(userSpecifiedRetention != null
+                ? Materialized.<String, Long, WindowStore<Bytes, byte[]>>as(storeName).withRetention(userSpecifiedRetention)
+                : Materialized.as(storeName))
+            .toStream()
+            .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, expectedRetention);
+    }
+
+    @Test
+    public void sessionWindowedChangelogShouldHaveRetentionOfGapIfGapLargerThanDefaultRetention() throws Exception {
+        final Duration gap = DEFAULT_RETENTION.plus(Duration.ofHours(1));
+        final Duration expectedRetention = gap;
+        runAndVerifySessionWindows(SessionWindows.with(gap), null, expectedRetention);
+    }
+
+    @Test
+    public void sessionWindowedChangelogShouldHaveDefaultRetentionIfGapLessThanDefaultRetention() throws Exception {
+        final Duration gap = DEFAULT_RETENTION.minus(Duration.ofHours(1));
+        final Duration expectedRetention = DEFAULT_RETENTION;
+        runAndVerifySessionWindows(SessionWindows.with(gap), null, expectedRetention);
+    }
+
+    @Test
+    public void sessionWindowedChangelogShouldHaveDefaultRetentionIfGapPlusGraceLessThanDefaultRetention() throws Exception {
+        final Duration grace = Duration.ofHours(1);
+        final Duration gap = DEFAULT_RETENTION.minus(grace).minus(Duration.ofHours(1));
+        final Duration expectedRetention = DEFAULT_RETENTION;
+        runAndVerifySessionWindows(SessionWindows.with(gap).grace(grace), null, expectedRetention);
+    }
+
+    @Test
+    public void sessionWindowedChangelogShouldHaveUserSpecifiedRetentionIfUserSpecifiedRetentionEvenIfLessThanDefaultRetention() throws Exception {

Review comment:
       typo: `sessionWindowedChangelogShouldHaveUserSpecifiedRetentionIfUserSpecifiedRetentionEvenIfLessThanDefaultRetention` -> `sessionWindowedChangelogShouldHaveUserSpecifiedRetentionIfUserSpecifiedRetentionLessThanDefaultRetention` ?




-- 
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-unsubscribe@kafka.apache.org

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



[GitHub] [kafka] cadonna commented on a change in pull request #11063: Add test to verify behavior of grace API

Posted by GitBox <gi...@apache.org>.
cadonna commented on a change in pull request #11063:
URL: https://github.com/apache/kafka/pull/11063#discussion_r671016200



##########
File path: streams/src/test/java/org/apache/kafka/streams/integration/WindowedChangelogRetentionIntegrationTest.java
##########
@@ -0,0 +1,365 @@
+/*
+ * 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.common.config.TopicConfig;
+import org.apache.kafka.common.serialization.Serde;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.streams.KafkaStreams;
+import org.apache.kafka.streams.KafkaStreams.State;
+import org.apache.kafka.streams.StreamsBuilder;
+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.kstream.Consumed;
+import org.apache.kafka.streams.kstream.Grouped;
+import org.apache.kafka.streams.kstream.JoinWindows;
+import org.apache.kafka.streams.kstream.KGroupedStream;
+import org.apache.kafka.streams.kstream.KStream;
+import org.apache.kafka.streams.kstream.KeyValueMapper;
+import org.apache.kafka.streams.kstream.Materialized;
+import org.apache.kafka.streams.kstream.Produced;
+import org.apache.kafka.streams.kstream.SessionWindows;
+import org.apache.kafka.streams.kstream.StreamJoined;
+import org.apache.kafka.streams.kstream.TimeWindows;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.kstream.WindowedSerdes;
+import org.apache.kafka.streams.state.SessionStore;
+import org.apache.kafka.streams.state.WindowStore;
+import org.apache.kafka.test.IntegrationTest;
+import org.apache.kafka.test.MockMapper;
+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.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Properties;
+
+import static org.apache.kafka.streams.integration.utils.IntegrationTestUtils.safeUniqueTestName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+@SuppressWarnings("deprecation")
+@Category({IntegrationTest.class})
+public class WindowedChangelogRetentionIntegrationTest {
+    private static final int NUM_BROKERS = 1;
+    private static final Duration DEFAULT_RETENTION = Duration.ofDays(1);
+
+    public static final EmbeddedKafkaCluster CLUSTER = new EmbeddedKafkaCluster(NUM_BROKERS);
+
+    private StreamsBuilder builder;
+    private Properties streamsConfiguration;
+    private KafkaStreams kafkaStreams;
+    private String streamOneInput;
+    private String streamTwoInput;
+    private String outputTopic;
+    private KGroupedStream<String, String> groupedStream;
+    private KStream<Integer, String> stream;
+    private KStream<Integer, String> stream1;
+    private KStream<Integer, String> stream2;
+
+    @Rule
+    public TestName testName = new TestName();
+
+    @BeforeClass
+    public static void startCluster() throws IOException {
+        CLUSTER.start();
+    }
+
+    @AfterClass
+    public static void closeCluster() {
+        CLUSTER.stop();
+    }
+
+    @Before
+    public void before() throws InterruptedException {
+        builder = new StreamsBuilder();
+        createTopics();
+        streamsConfiguration = new Properties();
+        final String safeTestName = safeUniqueTestName(getClass(), testName);
+        streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "app-" + safeTestName);
+        streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
+        streamsConfiguration.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
+        streamsConfiguration.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath());
+        streamsConfiguration.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 0);
+        streamsConfiguration.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 100);
+        streamsConfiguration.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
+        streamsConfiguration.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.Integer().getClass());
+
+        final KeyValueMapper<Integer, String, String> mapper = MockMapper.selectValueMapper();
+        stream = builder.stream(streamOneInput, Consumed.with(Serdes.Integer(), Serdes.String()));
+        groupedStream = stream.groupBy(mapper, Grouped.with(Serdes.String(), Serdes.String()));
+    }
+
+    @After
+    public void whenShuttingDown() throws Exception {
+        if (kafkaStreams != null) {
+            kafkaStreams.close();
+        }
+        IntegrationTestUtils.purgeLocalStreamsState(streamsConfiguration);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSize() throws Exception {
+        final Duration windowSize = Duration.ofDays(2);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize))

Review comment:
       >TimeWindows .of is deprecated, right? Do we need to test old API? If yes, I think we need a @SuppressWarning to make the build pass
   
   Isn't that the whole point of this tests. To verify that the deprecated APIs work as in 2.8 where they were not deprecated?
   
   >If yes, I think we need a @SuppressWarning to make the build pass
   
   See line 67
   
   >Btw: all those test only set differn window size and grace and thus it seems we can share more code (ie, setting up the topology). Only the window definition is different.
   
   Good point!




-- 
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-unsubscribe@kafka.apache.org

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



[GitHub] [kafka] cadonna commented on a change in pull request #11063: MINOR: Add test to verify behavior of grace API

Posted by GitBox <gi...@apache.org>.
cadonna commented on a change in pull request #11063:
URL: https://github.com/apache/kafka/pull/11063#discussion_r673232056



##########
File path: streams/src/test/java/org/apache/kafka/streams/integration/WindowedChangelogRetentionIntegrationTest.java
##########
@@ -0,0 +1,326 @@
+/*
+ * 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.common.config.TopicConfig;
+import org.apache.kafka.common.serialization.Serde;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.streams.KafkaStreams;
+import org.apache.kafka.streams.KafkaStreams.State;
+import org.apache.kafka.streams.StreamsBuilder;
+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.kstream.Consumed;
+import org.apache.kafka.streams.kstream.Grouped;
+import org.apache.kafka.streams.kstream.JoinWindows;
+import org.apache.kafka.streams.kstream.KGroupedStream;
+import org.apache.kafka.streams.kstream.KStream;
+import org.apache.kafka.streams.kstream.KeyValueMapper;
+import org.apache.kafka.streams.kstream.Materialized;
+import org.apache.kafka.streams.kstream.Produced;
+import org.apache.kafka.streams.kstream.SessionWindows;
+import org.apache.kafka.streams.kstream.StreamJoined;
+import org.apache.kafka.streams.kstream.TimeWindows;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.kstream.WindowedSerdes;
+import org.apache.kafka.streams.kstream.Windows;
+import org.apache.kafka.streams.kstream.internals.TimeWindow;
+import org.apache.kafka.streams.state.SessionStore;
+import org.apache.kafka.streams.state.WindowStore;
+import org.apache.kafka.test.IntegrationTest;
+import org.apache.kafka.test.MockMapper;
+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.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Properties;
+
+import static org.apache.kafka.streams.integration.utils.IntegrationTestUtils.safeUniqueTestName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+@SuppressWarnings("deprecation")
+@Category({IntegrationTest.class})
+public class WindowedChangelogRetentionIntegrationTest {
+    private static final int NUM_BROKERS = 1;
+    private static final Duration DEFAULT_RETENTION = Duration.ofDays(1);
+    private static final String STREAM_ONE_INPUT = "stream-one";
+    private static final String STREAM_TWO_INPUT = "stream-two";
+    private static final String OUTPUT_TOPIC = "output";
+
+    public static final EmbeddedKafkaCluster CLUSTER = new EmbeddedKafkaCluster(NUM_BROKERS);
+
+    private StreamsBuilder builder;
+    private Properties streamsConfiguration;
+    private KafkaStreams kafkaStreams;
+    private KGroupedStream<String, String> groupedStream;
+
+    @Rule
+    public TestName testName = new TestName();
+
+    @BeforeClass
+    public static void startCluster() throws IOException, InterruptedException {
+        CLUSTER.start();
+        createTopics();
+    }
+
+    @AfterClass
+    public static void closeCluster() {
+        CLUSTER.stop();
+    }
+
+    @Before
+    public void before() {
+        builder = new StreamsBuilder();
+        streamsConfiguration = new Properties();
+        final String safeTestName = safeUniqueTestName(getClass(), testName);
+        streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "app-" + safeTestName);
+        streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
+        streamsConfiguration.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
+        streamsConfiguration.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath());
+        streamsConfiguration.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 0);
+        streamsConfiguration.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 100);
+        streamsConfiguration.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
+        streamsConfiguration.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.Integer().getClass());
+
+        final KeyValueMapper<Integer, String, String> mapper = MockMapper.selectValueMapper();
+        final KStream<Integer, String> stream = builder.stream(STREAM_ONE_INPUT, Consumed.with(Serdes.Integer(), Serdes.String()));
+        groupedStream = stream.groupBy(mapper, Grouped.with(Serdes.String(), Serdes.String()));
+    }
+
+    @After
+    public void whenShuttingDown() throws Exception {
+        if (kafkaStreams != null) {
+            kafkaStreams.close();
+        }
+        IntegrationTestUtils.purgeLocalStreamsState(streamsConfiguration);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSizeIfWindowSizeLargerThanDefaultRetention() throws Exception {
+        final Duration windowSize = DEFAULT_RETENTION.plus(Duration.ofHours(1));
+        final Duration expectedRetention = windowSize;
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveDefaultRetentionIfWindowSizeLessThanDefaultRetention() throws Exception {
+        final Duration windowSize = DEFAULT_RETENTION.minus(Duration.ofHours(1));
+        final Duration expectedRetention = DEFAULT_RETENTION;
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSizePlusGraceIfWindowSizePlusGraceLargerThanDefaultRetention() throws Exception {
+        final Duration windowSize = DEFAULT_RETENTION.plus(Duration.ofHours(1));
+        final Duration grace = Duration.ofHours(12);
+        final Duration expectedRetention = windowSize.plus(grace);
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize).grace(grace), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSizePlusGraceIfWindowSizePlusGraceLessThanDefaultRetention() throws Exception {
+        final Duration grace = Duration.ofMillis(1000);
+        final Duration windowSize = DEFAULT_RETENTION.minus(grace).minus(Duration.ofMillis(500));
+        final Duration expectedRetention = windowSize.plus(grace);
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize).grace(grace), null, expectedRetention);

Review comment:
       With 3.0 we do not use the default retention if window size + gap is less than the default retention. I think that is fine because a changelog topic that is created with 2.8 has a larger retention time than a changelog topic created with 3.0. \cc @mjsax  




-- 
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-unsubscribe@kafka.apache.org

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



[GitHub] [kafka] showuon commented on a change in pull request #11063: Add test to verify behavior of grace API

Posted by GitBox <gi...@apache.org>.
showuon commented on a change in pull request #11063:
URL: https://github.com/apache/kafka/pull/11063#discussion_r671818792



##########
File path: streams/src/test/java/org/apache/kafka/streams/integration/WindowedChangelogRetentionIntegrationTest.java
##########
@@ -0,0 +1,304 @@
+/*
+ * 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.common.config.TopicConfig;
+import org.apache.kafka.common.serialization.Serde;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.streams.KafkaStreams;
+import org.apache.kafka.streams.KafkaStreams.State;
+import org.apache.kafka.streams.StreamsBuilder;
+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.kstream.Consumed;
+import org.apache.kafka.streams.kstream.Grouped;
+import org.apache.kafka.streams.kstream.JoinWindows;
+import org.apache.kafka.streams.kstream.KGroupedStream;
+import org.apache.kafka.streams.kstream.KStream;
+import org.apache.kafka.streams.kstream.KeyValueMapper;
+import org.apache.kafka.streams.kstream.Materialized;
+import org.apache.kafka.streams.kstream.Produced;
+import org.apache.kafka.streams.kstream.SessionWindows;
+import org.apache.kafka.streams.kstream.StreamJoined;
+import org.apache.kafka.streams.kstream.TimeWindows;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.kstream.WindowedSerdes;
+import org.apache.kafka.streams.kstream.Windows;
+import org.apache.kafka.streams.kstream.internals.TimeWindow;
+import org.apache.kafka.streams.state.SessionStore;
+import org.apache.kafka.streams.state.WindowStore;
+import org.apache.kafka.test.IntegrationTest;
+import org.apache.kafka.test.MockMapper;
+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.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Properties;
+
+import static org.apache.kafka.streams.integration.utils.IntegrationTestUtils.safeUniqueTestName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+@SuppressWarnings("deprecation")
+@Category({IntegrationTest.class})
+public class WindowedChangelogRetentionIntegrationTest {
+    private static final int NUM_BROKERS = 1;
+    private static final Duration DEFAULT_RETENTION = Duration.ofDays(1);
+
+    public static final EmbeddedKafkaCluster CLUSTER = new EmbeddedKafkaCluster(NUM_BROKERS);
+
+    private StreamsBuilder builder;
+    private Properties streamsConfiguration;
+    private KafkaStreams kafkaStreams;
+    private String streamOneInput;
+    private String streamTwoInput;
+    private String outputTopic;
+    private KGroupedStream<String, String> groupedStream;
+
+    @Rule
+    public TestName testName = new TestName();
+
+    @BeforeClass
+    public static void startCluster() throws IOException {
+        CLUSTER.start();
+    }
+
+    @AfterClass
+    public static void closeCluster() {
+        CLUSTER.stop();
+    }
+
+    @Before
+    public void before() throws InterruptedException {
+        builder = new StreamsBuilder();
+        createTopics();
+        streamsConfiguration = new Properties();
+        final String safeTestName = safeUniqueTestName(getClass(), testName);
+        streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "app-" + safeTestName);
+        streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
+        streamsConfiguration.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
+        streamsConfiguration.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath());
+        streamsConfiguration.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 0);
+        streamsConfiguration.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 100);
+        streamsConfiguration.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
+        streamsConfiguration.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.Integer().getClass());
+
+        final KeyValueMapper<Integer, String, String> mapper = MockMapper.selectValueMapper();
+        final KStream<Integer, String> stream = builder.stream(streamOneInput, Consumed.with(Serdes.Integer(), Serdes.String()));
+        groupedStream = stream.groupBy(mapper, Grouped.with(Serdes.String(), Serdes.String()));
+    }
+
+    @After
+    public void whenShuttingDown() throws Exception {
+        if (kafkaStreams != null) {
+            kafkaStreams.close();
+        }
+        IntegrationTestUtils.purgeLocalStreamsState(streamsConfiguration);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSizeIfWindowSizeLargerThanDefaultRetention() throws Exception {
+        final Duration windowSize = DEFAULT_RETENTION.plus(Duration.ofHours(1));
+        final Duration expectedRetention = windowSize;
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveDefaultRetentionIfWindowSizeLessThanDefaultRetention() throws Exception {
+        final Duration windowSize = DEFAULT_RETENTION.minus(Duration.ofHours(1));
+        final Duration expectedRetention = DEFAULT_RETENTION;
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSizePlusGraceIfWindowSizePlusGraceLargerThanDefaultRetention() throws Exception {
+        final Duration windowSize = DEFAULT_RETENTION.plus(Duration.ofHours(1));
+        final Duration grace = Duration.ofHours(12);
+        final Duration expectedRetention = windowSize.plus(grace);
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize).grace(grace), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveDefaultRetentionIfWindowSizePlusGraceLessThanDefaultRetention() throws Exception {
+        final Duration grace = Duration.ofMillis(1000);
+        final Duration windowSize = DEFAULT_RETENTION.minus(grace).minus(Duration.ofMillis(500));
+        final Duration expectedRetention = DEFAULT_RETENTION;
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize).grace(grace), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveUserSpecifiedRetentionIfUserSpecifiedRetentionEvenIfLessThanDefaultRetention() throws Exception {
+        final Duration grace = Duration.ofHours(6);
+        final Duration windowSize = DEFAULT_RETENTION.minus(grace).minus(Duration.ofHours(1));
+        final Duration userSpecifiedRetention = windowSize.plus(grace).plus(Duration.ofHours(1));
+        final Duration expectedRetention = userSpecifiedRetention;
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize).grace(grace), userSpecifiedRetention, expectedRetention);
+    }
+
+    private void runAndVerifyTimeWindows(final Windows<TimeWindow> window,
+                                         final Duration userSpecifiedRetention,
+                                         final Duration expectedRetention) throws Exception {
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, window.size());
+        groupedStream.windowedBy(window)
+            .count(userSpecifiedRetention != null
+                ? Materialized.<String, Long, WindowStore<Bytes, byte[]>>as(storeName).withRetention(userSpecifiedRetention)
+                : Materialized.as(storeName))
+            .toStream()
+            .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, expectedRetention);
+    }
+
+    @Test
+    public void sessionWindowedChangelogShouldHaveRetentionOfGapIfGapLargerThanDefaultRetention() throws Exception {
+        final Duration gap = DEFAULT_RETENTION.plus(Duration.ofHours(1));
+        final Duration expectedRetention = gap;
+        runAndVerifySessionWindows(SessionWindows.with(gap), null, expectedRetention);
+    }
+
+    @Test
+    public void sessionWindowedChangelogShouldHaveDefaultRetentionIfGapLessThanDefaultRetention() throws Exception {
+        final Duration gap = DEFAULT_RETENTION.minus(Duration.ofHours(1));
+        final Duration expectedRetention = DEFAULT_RETENTION;
+        runAndVerifySessionWindows(SessionWindows.with(gap), null, expectedRetention);
+    }
+
+    @Test
+    public void sessionWindowedChangelogShouldHaveDefaultRetentionIfGapPlusGraceLessThanDefaultRetention() throws Exception {
+        final Duration grace = Duration.ofHours(1);
+        final Duration gap = DEFAULT_RETENTION.minus(grace).minus(Duration.ofHours(1));
+        final Duration expectedRetention = DEFAULT_RETENTION;
+        runAndVerifySessionWindows(SessionWindows.with(gap).grace(grace), null, expectedRetention);
+    }
+
+    @Test
+    public void sessionWindowedChangelogShouldHaveUserSpecifiedRetentionIfUserSpecifiedRetentionEvenIfLessThanDefaultRetention() throws Exception {

Review comment:
       typo: `sessionWindowedChangelogShouldHaveUserSpecifiedRetentionIfUserSpecifiedRetention[EvenIf]LessThanDefaultRetention` -> `sessionWindowedChangelogShouldHaveUserSpecifiedRetentionIfUserSpecifiedRetentionLessThanDefaultRetention` ?




-- 
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-unsubscribe@kafka.apache.org

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



[GitHub] [kafka] mjsax commented on a change in pull request #11063: Add test to verify behavior of grace API

Posted by GitBox <gi...@apache.org>.
mjsax commented on a change in pull request #11063:
URL: https://github.com/apache/kafka/pull/11063#discussion_r670792151



##########
File path: streams/src/test/java/org/apache/kafka/streams/integration/WindowedChangelogRetentionIntegrationTest.java
##########
@@ -0,0 +1,365 @@
+/*
+ * 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.common.config.TopicConfig;
+import org.apache.kafka.common.serialization.Serde;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.streams.KafkaStreams;
+import org.apache.kafka.streams.KafkaStreams.State;
+import org.apache.kafka.streams.StreamsBuilder;
+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.kstream.Consumed;
+import org.apache.kafka.streams.kstream.Grouped;
+import org.apache.kafka.streams.kstream.JoinWindows;
+import org.apache.kafka.streams.kstream.KGroupedStream;
+import org.apache.kafka.streams.kstream.KStream;
+import org.apache.kafka.streams.kstream.KeyValueMapper;
+import org.apache.kafka.streams.kstream.Materialized;
+import org.apache.kafka.streams.kstream.Produced;
+import org.apache.kafka.streams.kstream.SessionWindows;
+import org.apache.kafka.streams.kstream.StreamJoined;
+import org.apache.kafka.streams.kstream.TimeWindows;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.kstream.WindowedSerdes;
+import org.apache.kafka.streams.state.SessionStore;
+import org.apache.kafka.streams.state.WindowStore;
+import org.apache.kafka.test.IntegrationTest;
+import org.apache.kafka.test.MockMapper;
+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.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Properties;
+
+import static org.apache.kafka.streams.integration.utils.IntegrationTestUtils.safeUniqueTestName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+@SuppressWarnings("deprecation")
+@Category({IntegrationTest.class})
+public class WindowedChangelogRetentionIntegrationTest {
+    private static final int NUM_BROKERS = 1;
+    private static final Duration DEFAULT_RETENTION = Duration.ofDays(1);
+
+    public static final EmbeddedKafkaCluster CLUSTER = new EmbeddedKafkaCluster(NUM_BROKERS);
+
+    private StreamsBuilder builder;
+    private Properties streamsConfiguration;
+    private KafkaStreams kafkaStreams;
+    private String streamOneInput;
+    private String streamTwoInput;
+    private String outputTopic;
+    private KGroupedStream<String, String> groupedStream;
+    private KStream<Integer, String> stream;
+    private KStream<Integer, String> stream1;
+    private KStream<Integer, String> stream2;
+
+    @Rule
+    public TestName testName = new TestName();
+
+    @BeforeClass
+    public static void startCluster() throws IOException {
+        CLUSTER.start();
+    }
+
+    @AfterClass
+    public static void closeCluster() {
+        CLUSTER.stop();
+    }
+
+    @Before
+    public void before() throws InterruptedException {
+        builder = new StreamsBuilder();
+        createTopics();
+        streamsConfiguration = new Properties();
+        final String safeTestName = safeUniqueTestName(getClass(), testName);
+        streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "app-" + safeTestName);
+        streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
+        streamsConfiguration.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
+        streamsConfiguration.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath());
+        streamsConfiguration.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 0);
+        streamsConfiguration.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 100);
+        streamsConfiguration.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
+        streamsConfiguration.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.Integer().getClass());
+
+        final KeyValueMapper<Integer, String, String> mapper = MockMapper.selectValueMapper();
+        stream = builder.stream(streamOneInput, Consumed.with(Serdes.Integer(), Serdes.String()));
+        groupedStream = stream.groupBy(mapper, Grouped.with(Serdes.String(), Serdes.String()));
+    }
+
+    @After
+    public void whenShuttingDown() throws Exception {
+        if (kafkaStreams != null) {
+            kafkaStreams.close();
+        }
+        IntegrationTestUtils.purgeLocalStreamsState(streamsConfiguration);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSize() throws Exception {
+        final Duration windowSize = Duration.ofDays(2);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize))
+                .count(Materialized.as(storeName))
+                .toStream()
+                .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, windowSize);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveDefaultRetentionWithoutGrace() throws Exception {

Review comment:
       Seems to be the exact same test as above (both don't use grace).
   
   Seem the difference is if window size enlarged retention time setting or not, but it's not reflected in the names of the tests.

##########
File path: streams/src/test/java/org/apache/kafka/streams/integration/WindowedChangelogRetentionIntegrationTest.java
##########
@@ -0,0 +1,365 @@
+/*
+ * 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.common.config.TopicConfig;
+import org.apache.kafka.common.serialization.Serde;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.streams.KafkaStreams;
+import org.apache.kafka.streams.KafkaStreams.State;
+import org.apache.kafka.streams.StreamsBuilder;
+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.kstream.Consumed;
+import org.apache.kafka.streams.kstream.Grouped;
+import org.apache.kafka.streams.kstream.JoinWindows;
+import org.apache.kafka.streams.kstream.KGroupedStream;
+import org.apache.kafka.streams.kstream.KStream;
+import org.apache.kafka.streams.kstream.KeyValueMapper;
+import org.apache.kafka.streams.kstream.Materialized;
+import org.apache.kafka.streams.kstream.Produced;
+import org.apache.kafka.streams.kstream.SessionWindows;
+import org.apache.kafka.streams.kstream.StreamJoined;
+import org.apache.kafka.streams.kstream.TimeWindows;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.kstream.WindowedSerdes;
+import org.apache.kafka.streams.state.SessionStore;
+import org.apache.kafka.streams.state.WindowStore;
+import org.apache.kafka.test.IntegrationTest;
+import org.apache.kafka.test.MockMapper;
+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.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Properties;
+
+import static org.apache.kafka.streams.integration.utils.IntegrationTestUtils.safeUniqueTestName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+@SuppressWarnings("deprecation")
+@Category({IntegrationTest.class})
+public class WindowedChangelogRetentionIntegrationTest {
+    private static final int NUM_BROKERS = 1;
+    private static final Duration DEFAULT_RETENTION = Duration.ofDays(1);
+
+    public static final EmbeddedKafkaCluster CLUSTER = new EmbeddedKafkaCluster(NUM_BROKERS);
+
+    private StreamsBuilder builder;
+    private Properties streamsConfiguration;
+    private KafkaStreams kafkaStreams;
+    private String streamOneInput;
+    private String streamTwoInput;
+    private String outputTopic;
+    private KGroupedStream<String, String> groupedStream;
+    private KStream<Integer, String> stream;
+    private KStream<Integer, String> stream1;
+    private KStream<Integer, String> stream2;
+
+    @Rule
+    public TestName testName = new TestName();
+
+    @BeforeClass
+    public static void startCluster() throws IOException {
+        CLUSTER.start();
+    }
+
+    @AfterClass
+    public static void closeCluster() {
+        CLUSTER.stop();
+    }
+
+    @Before
+    public void before() throws InterruptedException {
+        builder = new StreamsBuilder();
+        createTopics();
+        streamsConfiguration = new Properties();
+        final String safeTestName = safeUniqueTestName(getClass(), testName);
+        streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "app-" + safeTestName);
+        streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
+        streamsConfiguration.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
+        streamsConfiguration.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath());
+        streamsConfiguration.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 0);
+        streamsConfiguration.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 100);
+        streamsConfiguration.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
+        streamsConfiguration.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.Integer().getClass());
+
+        final KeyValueMapper<Integer, String, String> mapper = MockMapper.selectValueMapper();
+        stream = builder.stream(streamOneInput, Consumed.with(Serdes.Integer(), Serdes.String()));
+        groupedStream = stream.groupBy(mapper, Grouped.with(Serdes.String(), Serdes.String()));
+    }
+
+    @After
+    public void whenShuttingDown() throws Exception {
+        if (kafkaStreams != null) {
+            kafkaStreams.close();
+        }
+        IntegrationTestUtils.purgeLocalStreamsState(streamsConfiguration);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSize() throws Exception {
+        final Duration windowSize = Duration.ofDays(2);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize))

Review comment:
       `TimeWindows .of` is deprecated, right? Do we need to test old API? If yes, I think we need a `@SuppressWarning` to make the build pass 

##########
File path: streams/src/test/java/org/apache/kafka/streams/integration/WindowedChangelogRetentionIntegrationTest.java
##########
@@ -0,0 +1,365 @@
+/*
+ * 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.common.config.TopicConfig;
+import org.apache.kafka.common.serialization.Serde;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.streams.KafkaStreams;
+import org.apache.kafka.streams.KafkaStreams.State;
+import org.apache.kafka.streams.StreamsBuilder;
+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.kstream.Consumed;
+import org.apache.kafka.streams.kstream.Grouped;
+import org.apache.kafka.streams.kstream.JoinWindows;
+import org.apache.kafka.streams.kstream.KGroupedStream;
+import org.apache.kafka.streams.kstream.KStream;
+import org.apache.kafka.streams.kstream.KeyValueMapper;
+import org.apache.kafka.streams.kstream.Materialized;
+import org.apache.kafka.streams.kstream.Produced;
+import org.apache.kafka.streams.kstream.SessionWindows;
+import org.apache.kafka.streams.kstream.StreamJoined;
+import org.apache.kafka.streams.kstream.TimeWindows;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.kstream.WindowedSerdes;
+import org.apache.kafka.streams.state.SessionStore;
+import org.apache.kafka.streams.state.WindowStore;
+import org.apache.kafka.test.IntegrationTest;
+import org.apache.kafka.test.MockMapper;
+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.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Properties;
+
+import static org.apache.kafka.streams.integration.utils.IntegrationTestUtils.safeUniqueTestName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+@SuppressWarnings("deprecation")
+@Category({IntegrationTest.class})
+public class WindowedChangelogRetentionIntegrationTest {
+    private static final int NUM_BROKERS = 1;
+    private static final Duration DEFAULT_RETENTION = Duration.ofDays(1);
+
+    public static final EmbeddedKafkaCluster CLUSTER = new EmbeddedKafkaCluster(NUM_BROKERS);
+
+    private StreamsBuilder builder;
+    private Properties streamsConfiguration;
+    private KafkaStreams kafkaStreams;
+    private String streamOneInput;
+    private String streamTwoInput;
+    private String outputTopic;
+    private KGroupedStream<String, String> groupedStream;
+    private KStream<Integer, String> stream;
+    private KStream<Integer, String> stream1;
+    private KStream<Integer, String> stream2;
+
+    @Rule
+    public TestName testName = new TestName();
+
+    @BeforeClass
+    public static void startCluster() throws IOException {
+        CLUSTER.start();
+    }
+
+    @AfterClass
+    public static void closeCluster() {
+        CLUSTER.stop();
+    }
+
+    @Before
+    public void before() throws InterruptedException {
+        builder = new StreamsBuilder();
+        createTopics();
+        streamsConfiguration = new Properties();
+        final String safeTestName = safeUniqueTestName(getClass(), testName);
+        streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "app-" + safeTestName);
+        streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
+        streamsConfiguration.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
+        streamsConfiguration.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath());
+        streamsConfiguration.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 0);
+        streamsConfiguration.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 100);
+        streamsConfiguration.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
+        streamsConfiguration.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.Integer().getClass());
+
+        final KeyValueMapper<Integer, String, String> mapper = MockMapper.selectValueMapper();
+        stream = builder.stream(streamOneInput, Consumed.with(Serdes.Integer(), Serdes.String()));
+        groupedStream = stream.groupBy(mapper, Grouped.with(Serdes.String(), Serdes.String()));
+    }
+
+    @After
+    public void whenShuttingDown() throws Exception {
+        if (kafkaStreams != null) {
+            kafkaStreams.close();
+        }
+        IntegrationTestUtils.purgeLocalStreamsState(streamsConfiguration);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSize() throws Exception {
+        final Duration windowSize = Duration.ofDays(2);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize))
+                .count(Materialized.as(storeName))
+                .toStream()
+                .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, windowSize);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveDefaultRetentionWithoutGrace() throws Exception {

Review comment:
       `timeWindowedChangelogShouldHaveDefaultRetentionIfWindowSizePlusGraceIsSmallerThanDefaultRetention`

##########
File path: streams/src/test/java/org/apache/kafka/streams/integration/WindowedChangelogRetentionIntegrationTest.java
##########
@@ -0,0 +1,365 @@
+/*
+ * 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.common.config.TopicConfig;
+import org.apache.kafka.common.serialization.Serde;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.streams.KafkaStreams;
+import org.apache.kafka.streams.KafkaStreams.State;
+import org.apache.kafka.streams.StreamsBuilder;
+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.kstream.Consumed;
+import org.apache.kafka.streams.kstream.Grouped;
+import org.apache.kafka.streams.kstream.JoinWindows;
+import org.apache.kafka.streams.kstream.KGroupedStream;
+import org.apache.kafka.streams.kstream.KStream;
+import org.apache.kafka.streams.kstream.KeyValueMapper;
+import org.apache.kafka.streams.kstream.Materialized;
+import org.apache.kafka.streams.kstream.Produced;
+import org.apache.kafka.streams.kstream.SessionWindows;
+import org.apache.kafka.streams.kstream.StreamJoined;
+import org.apache.kafka.streams.kstream.TimeWindows;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.kstream.WindowedSerdes;
+import org.apache.kafka.streams.state.SessionStore;
+import org.apache.kafka.streams.state.WindowStore;
+import org.apache.kafka.test.IntegrationTest;
+import org.apache.kafka.test.MockMapper;
+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.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Properties;
+
+import static org.apache.kafka.streams.integration.utils.IntegrationTestUtils.safeUniqueTestName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+@SuppressWarnings("deprecation")
+@Category({IntegrationTest.class})
+public class WindowedChangelogRetentionIntegrationTest {
+    private static final int NUM_BROKERS = 1;
+    private static final Duration DEFAULT_RETENTION = Duration.ofDays(1);
+
+    public static final EmbeddedKafkaCluster CLUSTER = new EmbeddedKafkaCluster(NUM_BROKERS);
+
+    private StreamsBuilder builder;
+    private Properties streamsConfiguration;
+    private KafkaStreams kafkaStreams;
+    private String streamOneInput;
+    private String streamTwoInput;
+    private String outputTopic;
+    private KGroupedStream<String, String> groupedStream;
+    private KStream<Integer, String> stream;
+    private KStream<Integer, String> stream1;
+    private KStream<Integer, String> stream2;
+
+    @Rule
+    public TestName testName = new TestName();
+
+    @BeforeClass
+    public static void startCluster() throws IOException {
+        CLUSTER.start();
+    }
+
+    @AfterClass
+    public static void closeCluster() {
+        CLUSTER.stop();
+    }
+
+    @Before
+    public void before() throws InterruptedException {
+        builder = new StreamsBuilder();
+        createTopics();
+        streamsConfiguration = new Properties();
+        final String safeTestName = safeUniqueTestName(getClass(), testName);
+        streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "app-" + safeTestName);
+        streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
+        streamsConfiguration.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
+        streamsConfiguration.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath());
+        streamsConfiguration.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 0);
+        streamsConfiguration.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 100);
+        streamsConfiguration.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
+        streamsConfiguration.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.Integer().getClass());
+
+        final KeyValueMapper<Integer, String, String> mapper = MockMapper.selectValueMapper();
+        stream = builder.stream(streamOneInput, Consumed.with(Serdes.Integer(), Serdes.String()));
+        groupedStream = stream.groupBy(mapper, Grouped.with(Serdes.String(), Serdes.String()));
+    }
+
+    @After
+    public void whenShuttingDown() throws Exception {
+        if (kafkaStreams != null) {
+            kafkaStreams.close();
+        }
+        IntegrationTestUtils.purgeLocalStreamsState(streamsConfiguration);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSize() throws Exception {
+        final Duration windowSize = Duration.ofDays(2);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize))
+                .count(Materialized.as(storeName))
+                .toStream()
+                .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, windowSize);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveDefaultRetentionWithoutGrace() throws Exception {
+        final Duration windowSize = Duration.ofMillis(500);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(Duration.ofMillis(500)))
+                .count(Materialized.as(storeName))
+                .toStream()
+                .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, DEFAULT_RETENTION);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveDefaultRetentionWithGrace() throws Exception {
+        final Duration windowSize = Duration.ofMillis(500);
+        final Duration grace = Duration.ofMillis(1000);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize).grace(grace))
+                .count(Materialized.as(storeName))
+                .toStream()
+                .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, DEFAULT_RETENTION);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSizeAndGrace() throws Exception {
+        final Duration windowSize = Duration.ofDays(1);
+        final Duration grace = Duration.ofHours(12);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize).grace(grace))
+                .count(Materialized.as(storeName))
+                .toStream()
+                .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, windowSize.plus(grace));
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveUserSpecifiedRetention() throws Exception {
+        final Duration windowSize = Duration.ofDays(1);
+        final Duration grace = Duration.ofHours(12);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize).grace(grace))
+                .count(Materialized.<String, Long, WindowStore<Bytes, byte[]>>as(storeName).withRetention(windowSize.multipliedBy(3)))
+                .toStream()
+                .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, windowSize.multipliedBy(3));
+    }
+
+    @Test
+    public void sessionWindowedChangelogShouldHaveRetentionOfGap() throws Exception {

Review comment:
       `sessionWindowedChangelogShouldHaveRetentionOfGapIfGapLargenThanDefaultRetention`

##########
File path: streams/src/test/java/org/apache/kafka/streams/integration/WindowedChangelogRetentionIntegrationTest.java
##########
@@ -0,0 +1,365 @@
+/*
+ * 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.common.config.TopicConfig;
+import org.apache.kafka.common.serialization.Serde;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.streams.KafkaStreams;
+import org.apache.kafka.streams.KafkaStreams.State;
+import org.apache.kafka.streams.StreamsBuilder;
+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.kstream.Consumed;
+import org.apache.kafka.streams.kstream.Grouped;
+import org.apache.kafka.streams.kstream.JoinWindows;
+import org.apache.kafka.streams.kstream.KGroupedStream;
+import org.apache.kafka.streams.kstream.KStream;
+import org.apache.kafka.streams.kstream.KeyValueMapper;
+import org.apache.kafka.streams.kstream.Materialized;
+import org.apache.kafka.streams.kstream.Produced;
+import org.apache.kafka.streams.kstream.SessionWindows;
+import org.apache.kafka.streams.kstream.StreamJoined;
+import org.apache.kafka.streams.kstream.TimeWindows;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.kstream.WindowedSerdes;
+import org.apache.kafka.streams.state.SessionStore;
+import org.apache.kafka.streams.state.WindowStore;
+import org.apache.kafka.test.IntegrationTest;
+import org.apache.kafka.test.MockMapper;
+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.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Properties;
+
+import static org.apache.kafka.streams.integration.utils.IntegrationTestUtils.safeUniqueTestName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+@SuppressWarnings("deprecation")
+@Category({IntegrationTest.class})
+public class WindowedChangelogRetentionIntegrationTest {
+    private static final int NUM_BROKERS = 1;
+    private static final Duration DEFAULT_RETENTION = Duration.ofDays(1);
+
+    public static final EmbeddedKafkaCluster CLUSTER = new EmbeddedKafkaCluster(NUM_BROKERS);
+
+    private StreamsBuilder builder;
+    private Properties streamsConfiguration;
+    private KafkaStreams kafkaStreams;
+    private String streamOneInput;
+    private String streamTwoInput;
+    private String outputTopic;
+    private KGroupedStream<String, String> groupedStream;
+    private KStream<Integer, String> stream;
+    private KStream<Integer, String> stream1;
+    private KStream<Integer, String> stream2;
+
+    @Rule
+    public TestName testName = new TestName();
+
+    @BeforeClass
+    public static void startCluster() throws IOException {
+        CLUSTER.start();
+    }
+
+    @AfterClass
+    public static void closeCluster() {
+        CLUSTER.stop();
+    }
+
+    @Before
+    public void before() throws InterruptedException {
+        builder = new StreamsBuilder();
+        createTopics();
+        streamsConfiguration = new Properties();
+        final String safeTestName = safeUniqueTestName(getClass(), testName);
+        streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "app-" + safeTestName);
+        streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
+        streamsConfiguration.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
+        streamsConfiguration.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath());
+        streamsConfiguration.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 0);
+        streamsConfiguration.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 100);
+        streamsConfiguration.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
+        streamsConfiguration.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.Integer().getClass());
+
+        final KeyValueMapper<Integer, String, String> mapper = MockMapper.selectValueMapper();
+        stream = builder.stream(streamOneInput, Consumed.with(Serdes.Integer(), Serdes.String()));
+        groupedStream = stream.groupBy(mapper, Grouped.with(Serdes.String(), Serdes.String()));
+    }
+
+    @After
+    public void whenShuttingDown() throws Exception {
+        if (kafkaStreams != null) {
+            kafkaStreams.close();
+        }
+        IntegrationTestUtils.purgeLocalStreamsState(streamsConfiguration);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSize() throws Exception {
+        final Duration windowSize = Duration.ofDays(2);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize))

Review comment:
       Btw: all those test only set differn window size and grace and thus it seems we can share more code (ie, setting up the topology). Only the window definition is different.

##########
File path: streams/src/test/java/org/apache/kafka/streams/integration/WindowedChangelogRetentionIntegrationTest.java
##########
@@ -0,0 +1,365 @@
+/*
+ * 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.common.config.TopicConfig;
+import org.apache.kafka.common.serialization.Serde;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.streams.KafkaStreams;
+import org.apache.kafka.streams.KafkaStreams.State;
+import org.apache.kafka.streams.StreamsBuilder;
+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.kstream.Consumed;
+import org.apache.kafka.streams.kstream.Grouped;
+import org.apache.kafka.streams.kstream.JoinWindows;
+import org.apache.kafka.streams.kstream.KGroupedStream;
+import org.apache.kafka.streams.kstream.KStream;
+import org.apache.kafka.streams.kstream.KeyValueMapper;
+import org.apache.kafka.streams.kstream.Materialized;
+import org.apache.kafka.streams.kstream.Produced;
+import org.apache.kafka.streams.kstream.SessionWindows;
+import org.apache.kafka.streams.kstream.StreamJoined;
+import org.apache.kafka.streams.kstream.TimeWindows;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.kstream.WindowedSerdes;
+import org.apache.kafka.streams.state.SessionStore;
+import org.apache.kafka.streams.state.WindowStore;
+import org.apache.kafka.test.IntegrationTest;
+import org.apache.kafka.test.MockMapper;
+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.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Properties;
+
+import static org.apache.kafka.streams.integration.utils.IntegrationTestUtils.safeUniqueTestName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+@SuppressWarnings("deprecation")
+@Category({IntegrationTest.class})
+public class WindowedChangelogRetentionIntegrationTest {
+    private static final int NUM_BROKERS = 1;
+    private static final Duration DEFAULT_RETENTION = Duration.ofDays(1);
+
+    public static final EmbeddedKafkaCluster CLUSTER = new EmbeddedKafkaCluster(NUM_BROKERS);
+
+    private StreamsBuilder builder;
+    private Properties streamsConfiguration;
+    private KafkaStreams kafkaStreams;
+    private String streamOneInput;
+    private String streamTwoInput;
+    private String outputTopic;
+    private KGroupedStream<String, String> groupedStream;
+    private KStream<Integer, String> stream;
+    private KStream<Integer, String> stream1;
+    private KStream<Integer, String> stream2;
+
+    @Rule
+    public TestName testName = new TestName();
+
+    @BeforeClass
+    public static void startCluster() throws IOException {
+        CLUSTER.start();
+    }
+
+    @AfterClass
+    public static void closeCluster() {
+        CLUSTER.stop();
+    }
+
+    @Before
+    public void before() throws InterruptedException {
+        builder = new StreamsBuilder();
+        createTopics();
+        streamsConfiguration = new Properties();
+        final String safeTestName = safeUniqueTestName(getClass(), testName);
+        streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "app-" + safeTestName);
+        streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
+        streamsConfiguration.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
+        streamsConfiguration.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath());
+        streamsConfiguration.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 0);
+        streamsConfiguration.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 100);
+        streamsConfiguration.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
+        streamsConfiguration.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.Integer().getClass());
+
+        final KeyValueMapper<Integer, String, String> mapper = MockMapper.selectValueMapper();
+        stream = builder.stream(streamOneInput, Consumed.with(Serdes.Integer(), Serdes.String()));
+        groupedStream = stream.groupBy(mapper, Grouped.with(Serdes.String(), Serdes.String()));
+    }
+
+    @After
+    public void whenShuttingDown() throws Exception {
+        if (kafkaStreams != null) {
+            kafkaStreams.close();
+        }
+        IntegrationTestUtils.purgeLocalStreamsState(streamsConfiguration);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSize() throws Exception {
+        final Duration windowSize = Duration.ofDays(2);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize))

Review comment:
       `timeWindowedChangelogShouldHaveRetentionOfWindowSizeWhenWindowSizeLargenThanDefaultRetention`

##########
File path: streams/src/test/java/org/apache/kafka/streams/integration/WindowedChangelogRetentionIntegrationTest.java
##########
@@ -0,0 +1,365 @@
+/*
+ * 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.common.config.TopicConfig;
+import org.apache.kafka.common.serialization.Serde;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.streams.KafkaStreams;
+import org.apache.kafka.streams.KafkaStreams.State;
+import org.apache.kafka.streams.StreamsBuilder;
+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.kstream.Consumed;
+import org.apache.kafka.streams.kstream.Grouped;
+import org.apache.kafka.streams.kstream.JoinWindows;
+import org.apache.kafka.streams.kstream.KGroupedStream;
+import org.apache.kafka.streams.kstream.KStream;
+import org.apache.kafka.streams.kstream.KeyValueMapper;
+import org.apache.kafka.streams.kstream.Materialized;
+import org.apache.kafka.streams.kstream.Produced;
+import org.apache.kafka.streams.kstream.SessionWindows;
+import org.apache.kafka.streams.kstream.StreamJoined;
+import org.apache.kafka.streams.kstream.TimeWindows;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.kstream.WindowedSerdes;
+import org.apache.kafka.streams.state.SessionStore;
+import org.apache.kafka.streams.state.WindowStore;
+import org.apache.kafka.test.IntegrationTest;
+import org.apache.kafka.test.MockMapper;
+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.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Properties;
+
+import static org.apache.kafka.streams.integration.utils.IntegrationTestUtils.safeUniqueTestName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+@SuppressWarnings("deprecation")
+@Category({IntegrationTest.class})
+public class WindowedChangelogRetentionIntegrationTest {
+    private static final int NUM_BROKERS = 1;
+    private static final Duration DEFAULT_RETENTION = Duration.ofDays(1);
+
+    public static final EmbeddedKafkaCluster CLUSTER = new EmbeddedKafkaCluster(NUM_BROKERS);
+
+    private StreamsBuilder builder;
+    private Properties streamsConfiguration;
+    private KafkaStreams kafkaStreams;
+    private String streamOneInput;
+    private String streamTwoInput;
+    private String outputTopic;
+    private KGroupedStream<String, String> groupedStream;
+    private KStream<Integer, String> stream;
+    private KStream<Integer, String> stream1;
+    private KStream<Integer, String> stream2;
+
+    @Rule
+    public TestName testName = new TestName();
+
+    @BeforeClass
+    public static void startCluster() throws IOException {
+        CLUSTER.start();
+    }
+
+    @AfterClass
+    public static void closeCluster() {
+        CLUSTER.stop();
+    }
+
+    @Before
+    public void before() throws InterruptedException {
+        builder = new StreamsBuilder();
+        createTopics();
+        streamsConfiguration = new Properties();
+        final String safeTestName = safeUniqueTestName(getClass(), testName);
+        streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "app-" + safeTestName);
+        streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
+        streamsConfiguration.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
+        streamsConfiguration.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath());
+        streamsConfiguration.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 0);
+        streamsConfiguration.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 100);
+        streamsConfiguration.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
+        streamsConfiguration.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.Integer().getClass());
+
+        final KeyValueMapper<Integer, String, String> mapper = MockMapper.selectValueMapper();
+        stream = builder.stream(streamOneInput, Consumed.with(Serdes.Integer(), Serdes.String()));
+        groupedStream = stream.groupBy(mapper, Grouped.with(Serdes.String(), Serdes.String()));
+    }
+
+    @After
+    public void whenShuttingDown() throws Exception {
+        if (kafkaStreams != null) {
+            kafkaStreams.close();
+        }
+        IntegrationTestUtils.purgeLocalStreamsState(streamsConfiguration);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSize() throws Exception {
+        final Duration windowSize = Duration.ofDays(2);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize))
+                .count(Materialized.as(storeName))
+                .toStream()
+                .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, windowSize);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveDefaultRetentionWithoutGrace() throws Exception {
+        final Duration windowSize = Duration.ofMillis(500);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(Duration.ofMillis(500)))
+                .count(Materialized.as(storeName))
+                .toStream()
+                .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, DEFAULT_RETENTION);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveDefaultRetentionWithGrace() throws Exception {
+        final Duration windowSize = Duration.ofMillis(500);
+        final Duration grace = Duration.ofMillis(1000);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize).grace(grace))
+                .count(Materialized.as(storeName))
+                .toStream()
+                .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, DEFAULT_RETENTION);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSizeAndGrace() throws Exception {
+        final Duration windowSize = Duration.ofDays(1);
+        final Duration grace = Duration.ofHours(12);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize).grace(grace))
+                .count(Materialized.as(storeName))
+                .toStream()
+                .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, windowSize.plus(grace));
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveUserSpecifiedRetention() throws Exception {
+        final Duration windowSize = Duration.ofDays(1);
+        final Duration grace = Duration.ofHours(12);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize).grace(grace))
+                .count(Materialized.<String, Long, WindowStore<Bytes, byte[]>>as(storeName).withRetention(windowSize.multipliedBy(3)))

Review comment:
       Why "times 3" -- The point is that is must be larger than "max(default, windowSize + grace)" -- maybe hardcode a value instead?

##########
File path: streams/src/test/java/org/apache/kafka/streams/integration/WindowedChangelogRetentionIntegrationTest.java
##########
@@ -0,0 +1,365 @@
+/*
+ * 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.common.config.TopicConfig;
+import org.apache.kafka.common.serialization.Serde;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.streams.KafkaStreams;
+import org.apache.kafka.streams.KafkaStreams.State;
+import org.apache.kafka.streams.StreamsBuilder;
+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.kstream.Consumed;
+import org.apache.kafka.streams.kstream.Grouped;
+import org.apache.kafka.streams.kstream.JoinWindows;
+import org.apache.kafka.streams.kstream.KGroupedStream;
+import org.apache.kafka.streams.kstream.KStream;
+import org.apache.kafka.streams.kstream.KeyValueMapper;
+import org.apache.kafka.streams.kstream.Materialized;
+import org.apache.kafka.streams.kstream.Produced;
+import org.apache.kafka.streams.kstream.SessionWindows;
+import org.apache.kafka.streams.kstream.StreamJoined;
+import org.apache.kafka.streams.kstream.TimeWindows;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.kstream.WindowedSerdes;
+import org.apache.kafka.streams.state.SessionStore;
+import org.apache.kafka.streams.state.WindowStore;
+import org.apache.kafka.test.IntegrationTest;
+import org.apache.kafka.test.MockMapper;
+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.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Properties;
+
+import static org.apache.kafka.streams.integration.utils.IntegrationTestUtils.safeUniqueTestName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+@SuppressWarnings("deprecation")
+@Category({IntegrationTest.class})
+public class WindowedChangelogRetentionIntegrationTest {
+    private static final int NUM_BROKERS = 1;
+    private static final Duration DEFAULT_RETENTION = Duration.ofDays(1);
+
+    public static final EmbeddedKafkaCluster CLUSTER = new EmbeddedKafkaCluster(NUM_BROKERS);
+
+    private StreamsBuilder builder;
+    private Properties streamsConfiguration;
+    private KafkaStreams kafkaStreams;
+    private String streamOneInput;
+    private String streamTwoInput;
+    private String outputTopic;
+    private KGroupedStream<String, String> groupedStream;
+    private KStream<Integer, String> stream;
+    private KStream<Integer, String> stream1;
+    private KStream<Integer, String> stream2;
+
+    @Rule
+    public TestName testName = new TestName();
+
+    @BeforeClass
+    public static void startCluster() throws IOException {
+        CLUSTER.start();
+    }
+
+    @AfterClass
+    public static void closeCluster() {
+        CLUSTER.stop();
+    }
+
+    @Before
+    public void before() throws InterruptedException {
+        builder = new StreamsBuilder();
+        createTopics();
+        streamsConfiguration = new Properties();
+        final String safeTestName = safeUniqueTestName(getClass(), testName);
+        streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "app-" + safeTestName);
+        streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
+        streamsConfiguration.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
+        streamsConfiguration.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath());
+        streamsConfiguration.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 0);
+        streamsConfiguration.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 100);
+        streamsConfiguration.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
+        streamsConfiguration.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.Integer().getClass());
+
+        final KeyValueMapper<Integer, String, String> mapper = MockMapper.selectValueMapper();
+        stream = builder.stream(streamOneInput, Consumed.with(Serdes.Integer(), Serdes.String()));
+        groupedStream = stream.groupBy(mapper, Grouped.with(Serdes.String(), Serdes.String()));
+    }
+
+    @After
+    public void whenShuttingDown() throws Exception {
+        if (kafkaStreams != null) {
+            kafkaStreams.close();
+        }
+        IntegrationTestUtils.purgeLocalStreamsState(streamsConfiguration);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSize() throws Exception {
+        final Duration windowSize = Duration.ofDays(2);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize))
+                .count(Materialized.as(storeName))
+                .toStream()
+                .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, windowSize);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveDefaultRetentionWithoutGrace() throws Exception {
+        final Duration windowSize = Duration.ofMillis(500);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(Duration.ofMillis(500)))
+                .count(Materialized.as(storeName))
+                .toStream()
+                .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, DEFAULT_RETENTION);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveDefaultRetentionWithGrace() throws Exception {
+        final Duration windowSize = Duration.ofMillis(500);
+        final Duration grace = Duration.ofMillis(1000);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize).grace(grace))
+                .count(Materialized.as(storeName))
+                .toStream()
+                .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, DEFAULT_RETENTION);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSizeAndGrace() throws Exception {
+        final Duration windowSize = Duration.ofDays(1);
+        final Duration grace = Duration.ofHours(12);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize).grace(grace))
+                .count(Materialized.as(storeName))
+                .toStream()
+                .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, windowSize.plus(grace));
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveUserSpecifiedRetention() throws Exception {
+        final Duration windowSize = Duration.ofDays(1);
+        final Duration grace = Duration.ofHours(12);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize).grace(grace))
+                .count(Materialized.<String, Long, WindowStore<Bytes, byte[]>>as(storeName).withRetention(windowSize.multipliedBy(3)))
+                .toStream()
+                .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, windowSize.multipliedBy(3));
+    }
+
+    @Test
+    public void sessionWindowedChangelogShouldHaveRetentionOfGap() throws Exception {

Review comment:
       Similar below.




-- 
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-unsubscribe@kafka.apache.org

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



[GitHub] [kafka] showuon commented on a change in pull request #11063: Add test to verify behavior of grace API

Posted by GitBox <gi...@apache.org>.
showuon commented on a change in pull request #11063:
URL: https://github.com/apache/kafka/pull/11063#discussion_r671818564



##########
File path: streams/src/test/java/org/apache/kafka/streams/integration/WindowedChangelogRetentionIntegrationTest.java
##########
@@ -0,0 +1,304 @@
+/*
+ * 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.common.config.TopicConfig;
+import org.apache.kafka.common.serialization.Serde;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.streams.KafkaStreams;
+import org.apache.kafka.streams.KafkaStreams.State;
+import org.apache.kafka.streams.StreamsBuilder;
+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.kstream.Consumed;
+import org.apache.kafka.streams.kstream.Grouped;
+import org.apache.kafka.streams.kstream.JoinWindows;
+import org.apache.kafka.streams.kstream.KGroupedStream;
+import org.apache.kafka.streams.kstream.KStream;
+import org.apache.kafka.streams.kstream.KeyValueMapper;
+import org.apache.kafka.streams.kstream.Materialized;
+import org.apache.kafka.streams.kstream.Produced;
+import org.apache.kafka.streams.kstream.SessionWindows;
+import org.apache.kafka.streams.kstream.StreamJoined;
+import org.apache.kafka.streams.kstream.TimeWindows;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.kstream.WindowedSerdes;
+import org.apache.kafka.streams.kstream.Windows;
+import org.apache.kafka.streams.kstream.internals.TimeWindow;
+import org.apache.kafka.streams.state.SessionStore;
+import org.apache.kafka.streams.state.WindowStore;
+import org.apache.kafka.test.IntegrationTest;
+import org.apache.kafka.test.MockMapper;
+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.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Properties;
+
+import static org.apache.kafka.streams.integration.utils.IntegrationTestUtils.safeUniqueTestName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+@SuppressWarnings("deprecation")
+@Category({IntegrationTest.class})
+public class WindowedChangelogRetentionIntegrationTest {
+    private static final int NUM_BROKERS = 1;
+    private static final Duration DEFAULT_RETENTION = Duration.ofDays(1);
+
+    public static final EmbeddedKafkaCluster CLUSTER = new EmbeddedKafkaCluster(NUM_BROKERS);
+
+    private StreamsBuilder builder;
+    private Properties streamsConfiguration;
+    private KafkaStreams kafkaStreams;
+    private String streamOneInput;
+    private String streamTwoInput;
+    private String outputTopic;
+    private KGroupedStream<String, String> groupedStream;
+
+    @Rule
+    public TestName testName = new TestName();
+
+    @BeforeClass
+    public static void startCluster() throws IOException {
+        CLUSTER.start();
+    }
+
+    @AfterClass
+    public static void closeCluster() {
+        CLUSTER.stop();
+    }
+
+    @Before
+    public void before() throws InterruptedException {
+        builder = new StreamsBuilder();
+        createTopics();
+        streamsConfiguration = new Properties();
+        final String safeTestName = safeUniqueTestName(getClass(), testName);
+        streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "app-" + safeTestName);
+        streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
+        streamsConfiguration.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
+        streamsConfiguration.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath());
+        streamsConfiguration.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 0);
+        streamsConfiguration.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 100);
+        streamsConfiguration.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
+        streamsConfiguration.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.Integer().getClass());
+
+        final KeyValueMapper<Integer, String, String> mapper = MockMapper.selectValueMapper();
+        final KStream<Integer, String> stream = builder.stream(streamOneInput, Consumed.with(Serdes.Integer(), Serdes.String()));
+        groupedStream = stream.groupBy(mapper, Grouped.with(Serdes.String(), Serdes.String()));
+    }
+
+    @After
+    public void whenShuttingDown() throws Exception {
+        if (kafkaStreams != null) {
+            kafkaStreams.close();
+        }
+        IntegrationTestUtils.purgeLocalStreamsState(streamsConfiguration);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSizeIfWindowSizeLargerThanDefaultRetention() throws Exception {
+        final Duration windowSize = DEFAULT_RETENTION.plus(Duration.ofHours(1));
+        final Duration expectedRetention = windowSize;
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveDefaultRetentionIfWindowSizeLessThanDefaultRetention() throws Exception {
+        final Duration windowSize = DEFAULT_RETENTION.minus(Duration.ofHours(1));
+        final Duration expectedRetention = DEFAULT_RETENTION;
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSizePlusGraceIfWindowSizePlusGraceLargerThanDefaultRetention() throws Exception {
+        final Duration windowSize = DEFAULT_RETENTION.plus(Duration.ofHours(1));
+        final Duration grace = Duration.ofHours(12);
+        final Duration expectedRetention = windowSize.plus(grace);
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize).grace(grace), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveDefaultRetentionIfWindowSizePlusGraceLessThanDefaultRetention() throws Exception {
+        final Duration grace = Duration.ofMillis(1000);
+        final Duration windowSize = DEFAULT_RETENTION.minus(grace).minus(Duration.ofMillis(500));
+        final Duration expectedRetention = DEFAULT_RETENTION;
+        runAndVerifyTimeWindows(TimeWindows.of(windowSize).grace(grace), null, expectedRetention);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveUserSpecifiedRetentionIfUserSpecifiedRetentionEvenIfLessThanDefaultRetention() throws Exception {

Review comment:
       typo: `timeWindowedChangelogShouldHaveUserSpecifiedRetentionIfUserSpecifiedRetention[EvenIf]LessThanDefaultRetention` -> `timeWindowedChangelogShouldHaveUserSpecifiedRetentionIfUserSpecifiedRetentionLessThanDefaultRetention`?




-- 
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-unsubscribe@kafka.apache.org

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



[GitHub] [kafka] cadonna commented on pull request #11063: Add test to verify behavior of grace API

Posted by GitBox <gi...@apache.org>.
cadonna commented on pull request #11063:
URL: https://github.com/apache/kafka/pull/11063#issuecomment-881468501


   @mjsax Thanks for the feedback!
   I acted on all of them. Regarding, not using an integration test, I would love to not use one, but I could not came up with an alternative solution until now. I think for verifying  #10953 it is also not strictly needed. If I manage to avoid the integration, I would like to open a separate PR and not block this.


-- 
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-unsubscribe@kafka.apache.org

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



[GitHub] [kafka] cadonna commented on a change in pull request #11063: Add test to verify behavior of grace API

Posted by GitBox <gi...@apache.org>.
cadonna commented on a change in pull request #11063:
URL: https://github.com/apache/kafka/pull/11063#discussion_r671139543



##########
File path: streams/src/test/java/org/apache/kafka/streams/integration/WindowedChangelogRetentionIntegrationTest.java
##########
@@ -0,0 +1,365 @@
+/*
+ * 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.common.config.TopicConfig;
+import org.apache.kafka.common.serialization.Serde;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.streams.KafkaStreams;
+import org.apache.kafka.streams.KafkaStreams.State;
+import org.apache.kafka.streams.StreamsBuilder;
+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.kstream.Consumed;
+import org.apache.kafka.streams.kstream.Grouped;
+import org.apache.kafka.streams.kstream.JoinWindows;
+import org.apache.kafka.streams.kstream.KGroupedStream;
+import org.apache.kafka.streams.kstream.KStream;
+import org.apache.kafka.streams.kstream.KeyValueMapper;
+import org.apache.kafka.streams.kstream.Materialized;
+import org.apache.kafka.streams.kstream.Produced;
+import org.apache.kafka.streams.kstream.SessionWindows;
+import org.apache.kafka.streams.kstream.StreamJoined;
+import org.apache.kafka.streams.kstream.TimeWindows;
+import org.apache.kafka.streams.kstream.Windowed;
+import org.apache.kafka.streams.kstream.WindowedSerdes;
+import org.apache.kafka.streams.state.SessionStore;
+import org.apache.kafka.streams.state.WindowStore;
+import org.apache.kafka.test.IntegrationTest;
+import org.apache.kafka.test.MockMapper;
+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.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Properties;
+
+import static org.apache.kafka.streams.integration.utils.IntegrationTestUtils.safeUniqueTestName;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+@SuppressWarnings("deprecation")
+@Category({IntegrationTest.class})
+public class WindowedChangelogRetentionIntegrationTest {
+    private static final int NUM_BROKERS = 1;
+    private static final Duration DEFAULT_RETENTION = Duration.ofDays(1);
+
+    public static final EmbeddedKafkaCluster CLUSTER = new EmbeddedKafkaCluster(NUM_BROKERS);
+
+    private StreamsBuilder builder;
+    private Properties streamsConfiguration;
+    private KafkaStreams kafkaStreams;
+    private String streamOneInput;
+    private String streamTwoInput;
+    private String outputTopic;
+    private KGroupedStream<String, String> groupedStream;
+    private KStream<Integer, String> stream;
+    private KStream<Integer, String> stream1;
+    private KStream<Integer, String> stream2;
+
+    @Rule
+    public TestName testName = new TestName();
+
+    @BeforeClass
+    public static void startCluster() throws IOException {
+        CLUSTER.start();
+    }
+
+    @AfterClass
+    public static void closeCluster() {
+        CLUSTER.stop();
+    }
+
+    @Before
+    public void before() throws InterruptedException {
+        builder = new StreamsBuilder();
+        createTopics();
+        streamsConfiguration = new Properties();
+        final String safeTestName = safeUniqueTestName(getClass(), testName);
+        streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "app-" + safeTestName);
+        streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
+        streamsConfiguration.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
+        streamsConfiguration.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath());
+        streamsConfiguration.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 0);
+        streamsConfiguration.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 100);
+        streamsConfiguration.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
+        streamsConfiguration.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.Integer().getClass());
+
+        final KeyValueMapper<Integer, String, String> mapper = MockMapper.selectValueMapper();
+        stream = builder.stream(streamOneInput, Consumed.with(Serdes.Integer(), Serdes.String()));
+        groupedStream = stream.groupBy(mapper, Grouped.with(Serdes.String(), Serdes.String()));
+    }
+
+    @After
+    public void whenShuttingDown() throws Exception {
+        if (kafkaStreams != null) {
+            kafkaStreams.close();
+        }
+        IntegrationTestUtils.purgeLocalStreamsState(streamsConfiguration);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSize() throws Exception {
+        final Duration windowSize = Duration.ofDays(2);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize))
+                .count(Materialized.as(storeName))
+                .toStream()
+                .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, windowSize);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveDefaultRetentionWithoutGrace() throws Exception {
+        final Duration windowSize = Duration.ofMillis(500);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(Duration.ofMillis(500)))
+                .count(Materialized.as(storeName))
+                .toStream()
+                .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, DEFAULT_RETENTION);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveDefaultRetentionWithGrace() throws Exception {
+        final Duration windowSize = Duration.ofMillis(500);
+        final Duration grace = Duration.ofMillis(1000);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize).grace(grace))
+                .count(Materialized.as(storeName))
+                .toStream()
+                .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, DEFAULT_RETENTION);
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveRetentionOfWindowSizeAndGrace() throws Exception {
+        final Duration windowSize = Duration.ofDays(1);
+        final Duration grace = Duration.ofHours(12);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize).grace(grace))
+                .count(Materialized.as(storeName))
+                .toStream()
+                .to(outputTopic, Produced.with(windowedSerde, Serdes.Long()));
+
+        startStreams();
+
+        verifyChangelogRetentionOfWindowedStore(storeName, windowSize.plus(grace));
+    }
+
+    @Test
+    public void timeWindowedChangelogShouldHaveUserSpecifiedRetention() throws Exception {
+        final Duration windowSize = Duration.ofDays(1);
+        final Duration grace = Duration.ofHours(12);
+        final String storeName = "windowed-store";
+        final Serde<Windowed<String>> windowedSerde = WindowedSerdes.timeWindowedSerdeFrom(String.class, windowSize.toMillis());
+        groupedStream.windowedBy(TimeWindows.of(windowSize).grace(grace))
+                .count(Materialized.<String, Long, WindowStore<Bytes, byte[]>>as(storeName).withRetention(windowSize.multipliedBy(3)))

Review comment:
       "times 3" is indeed not that comprehensible. I just chose a duration that was greater than window size + grace. The point is not that it must be greater than max(default, windowSize + grace). If users specify a retention via `Materialized`, the retention must be larger than window size + grace, otherwhise an exception is thrown. I will set window size + grace + 1 hour where window size + grace + 1 hour is less than default retention.




-- 
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-unsubscribe@kafka.apache.org

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