mjsax commented on code in PR #13188:
URL: https://github.com/apache/kafka/pull/13188#discussion_r1102246409


##########
streams/src/test/java/org/apache/kafka/streams/state/internals/RocksDBVersionedStoreTest.java:
##########
@@ -0,0 +1,435 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.streams.state.internals;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import org.apache.kafka.common.serialization.Deserializer;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.serialization.Serializer;
+import org.apache.kafka.common.serialization.StringDeserializer;
+import org.apache.kafka.common.serialization.StringSerializer;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.streams.StreamsConfig;
+import org.apache.kafka.streams.processor.StateStoreContext;
+import org.apache.kafka.streams.state.VersionedRecord;
+import org.apache.kafka.test.InternalMockProcessorContext;
+import org.apache.kafka.test.StreamsTestUtils;
+import org.apache.kafka.test.TestUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class RocksDBVersionedStoreTest {
+
+    private static final String STORE_NAME = "myversionedrocks";
+    private static final String METRICS_SCOPE = "versionedrocksdb";
+    private static final long HISTORY_RETENTION = 300_000L;
+    private static final long SEGMENT_INTERVAL = HISTORY_RETENTION / 3;
+    private static final long BASE_TIMESTAMP = 10L;
+    private static final Serializer<String> STRING_SERIALIZER = new 
StringSerializer();
+    private static final Deserializer<String> STRING_DESERIALIZER = new 
StringDeserializer();
+
+    private InternalMockProcessorContext context;
+
+    private RocksDBVersionedStore store;
+
+    @Before
+    public void before() {
+        context = new InternalMockProcessorContext<>(
+            TestUtils.tempDirectory(),
+            Serdes.String(),
+            Serdes.String(),
+            new StreamsConfig(StreamsTestUtils.getStreamsConfig())
+        );
+        context.setTime(BASE_TIMESTAMP);
+
+        store = new RocksDBVersionedStore(STORE_NAME, METRICS_SCOPE, 
HISTORY_RETENTION, SEGMENT_INTERVAL);
+        store.init((StateStoreContext) context, store);
+    }
+
+    @After
+    public void after() {
+        store.close();
+    }
+
+    @Test
+    public void shouldPutLatest() {
+        putToStore("k", "v", BASE_TIMESTAMP);
+        putToStore("k", "v2", BASE_TIMESTAMP + 1);
+
+        verifyGetValueFromStore("k", "v2", BASE_TIMESTAMP + 1);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP, "v", 
BASE_TIMESTAMP);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP + 1, "v2", 
BASE_TIMESTAMP + 1);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP + 2, "v2", 
BASE_TIMESTAMP + 1);
+    }
+
+    @Test
+    public void shouldPutNullAsLatest() {
+        putToStore("k", null, BASE_TIMESTAMP);
+        putToStore("k", null, BASE_TIMESTAMP + 1);
+
+        verifyGetNullFromStore("k");
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP);
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP + 1);
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP + 2);
+    }
+
+    @Test
+    public void shouldPutOlderWithNonNullLatest() {
+        putToStore("k", "v", BASE_TIMESTAMP);
+        putToStore("k", "v2", BASE_TIMESTAMP - 2);
+        putToStore("k", "v1", BASE_TIMESTAMP - 1);
+        putToStore("k", "v4", BASE_TIMESTAMP - 4);
+
+        verifyGetValueFromStore("k", "v", BASE_TIMESTAMP);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP, "v", 
BASE_TIMESTAMP);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP - 1, "v1", 
BASE_TIMESTAMP - 1);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP - 2, "v2", 
BASE_TIMESTAMP - 2);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP - 3, "v4", 
BASE_TIMESTAMP - 4);
+    }
+
+    @Test
+    public void shouldPutOlderWithNullLatest() {
+        putToStore("k", null, BASE_TIMESTAMP);
+        putToStore("k", "v2", BASE_TIMESTAMP - 2);
+        putToStore("k", "v1", BASE_TIMESTAMP - 1);
+        putToStore("k", "v4", BASE_TIMESTAMP - 4);
+
+        verifyGetNullFromStore("k");
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP - 1, "v1", 
BASE_TIMESTAMP - 1);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP - 2, "v2", 
BASE_TIMESTAMP - 2);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP - 3, "v4", 
BASE_TIMESTAMP - 4);
+    }
+
+    @Test
+    public void shouldPutOlderNullWithNonNullLatest() {
+        putToStore("k", "v", BASE_TIMESTAMP);
+        putToStore("k", null, BASE_TIMESTAMP - 2);
+        putToStore("k", null, BASE_TIMESTAMP - 1);
+        putToStore("k", null, BASE_TIMESTAMP - 4);
+        putToStore("k", "v5", BASE_TIMESTAMP - 5);
+        putToStore("k", "v3", BASE_TIMESTAMP - 3);
+        putToStore("k", null, BASE_TIMESTAMP - 6);
+
+        verifyGetValueFromStore("k", "v", BASE_TIMESTAMP);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP, "v", 
BASE_TIMESTAMP);
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP - 1);
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP - 2);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP - 3, "v3", 
BASE_TIMESTAMP - 3);
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP - 4);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP - 5, "v5", 
BASE_TIMESTAMP - 5);
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP - 6);
+    }
+
+    @Test
+    public void shouldPutOlderNullWithNullLatest() {
+        putToStore("k", null, BASE_TIMESTAMP);
+        putToStore("k", null, BASE_TIMESTAMP - 2);
+        putToStore("k", null, BASE_TIMESTAMP - 1);
+        putToStore("k", null, BASE_TIMESTAMP - 4);
+        putToStore("k", "v3", BASE_TIMESTAMP - 3);
+        putToStore("k", "v5", BASE_TIMESTAMP - 5);
+        putToStore("k", null, BASE_TIMESTAMP - 6);
+
+        verifyGetNullFromStore("k");
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP);
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP - 1);
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP - 2);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP - 3, "v3", 
BASE_TIMESTAMP - 3);
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP - 4);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP - 5, "v5", 
BASE_TIMESTAMP - 5);
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP - 6);
+    }
+
+    @Test
+    public void shouldPutRepeatTimestampAsLatest() {
+        putToStore("k", "to_be_replaced", BASE_TIMESTAMP);
+        putToStore("k", "b", BASE_TIMESTAMP);
+
+        verifyGetValueFromStore("k", "b", BASE_TIMESTAMP);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP, "b", 
BASE_TIMESTAMP);

Review Comment:
   Should we verify that `"to_be_replaced"` was not move and thus we cannot 
query it with `BASE_TIMESTAMP - 1`?



##########
streams/src/test/java/org/apache/kafka/streams/state/internals/RocksDBVersionedStoreTest.java:
##########
@@ -0,0 +1,435 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.streams.state.internals;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import org.apache.kafka.common.serialization.Deserializer;
+import org.apache.kafka.common.serialization.Serdes;
+import org.apache.kafka.common.serialization.Serializer;
+import org.apache.kafka.common.serialization.StringDeserializer;
+import org.apache.kafka.common.serialization.StringSerializer;
+import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.streams.StreamsConfig;
+import org.apache.kafka.streams.processor.StateStoreContext;
+import org.apache.kafka.streams.state.VersionedRecord;
+import org.apache.kafka.test.InternalMockProcessorContext;
+import org.apache.kafka.test.StreamsTestUtils;
+import org.apache.kafka.test.TestUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class RocksDBVersionedStoreTest {
+
+    private static final String STORE_NAME = "myversionedrocks";
+    private static final String METRICS_SCOPE = "versionedrocksdb";
+    private static final long HISTORY_RETENTION = 300_000L;
+    private static final long SEGMENT_INTERVAL = HISTORY_RETENTION / 3;
+    private static final long BASE_TIMESTAMP = 10L;
+    private static final Serializer<String> STRING_SERIALIZER = new 
StringSerializer();
+    private static final Deserializer<String> STRING_DESERIALIZER = new 
StringDeserializer();
+
+    private InternalMockProcessorContext context;
+
+    private RocksDBVersionedStore store;
+
+    @Before
+    public void before() {
+        context = new InternalMockProcessorContext<>(
+            TestUtils.tempDirectory(),
+            Serdes.String(),
+            Serdes.String(),
+            new StreamsConfig(StreamsTestUtils.getStreamsConfig())
+        );
+        context.setTime(BASE_TIMESTAMP);
+
+        store = new RocksDBVersionedStore(STORE_NAME, METRICS_SCOPE, 
HISTORY_RETENTION, SEGMENT_INTERVAL);
+        store.init((StateStoreContext) context, store);
+    }
+
+    @After
+    public void after() {
+        store.close();
+    }
+
+    @Test
+    public void shouldPutLatest() {
+        putToStore("k", "v", BASE_TIMESTAMP);
+        putToStore("k", "v2", BASE_TIMESTAMP + 1);
+
+        verifyGetValueFromStore("k", "v2", BASE_TIMESTAMP + 1);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP, "v", 
BASE_TIMESTAMP);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP + 1, "v2", 
BASE_TIMESTAMP + 1);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP + 2, "v2", 
BASE_TIMESTAMP + 1);
+    }
+
+    @Test
+    public void shouldPutNullAsLatest() {
+        putToStore("k", null, BASE_TIMESTAMP);
+        putToStore("k", null, BASE_TIMESTAMP + 1);
+
+        verifyGetNullFromStore("k");
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP);
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP + 1);
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP + 2);
+    }
+
+    @Test
+    public void shouldPutOlderWithNonNullLatest() {
+        putToStore("k", "v", BASE_TIMESTAMP);
+        putToStore("k", "v2", BASE_TIMESTAMP - 2);
+        putToStore("k", "v1", BASE_TIMESTAMP - 1);
+        putToStore("k", "v4", BASE_TIMESTAMP - 4);
+
+        verifyGetValueFromStore("k", "v", BASE_TIMESTAMP);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP, "v", 
BASE_TIMESTAMP);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP - 1, "v1", 
BASE_TIMESTAMP - 1);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP - 2, "v2", 
BASE_TIMESTAMP - 2);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP - 3, "v4", 
BASE_TIMESTAMP - 4);
+    }
+
+    @Test
+    public void shouldPutOlderWithNullLatest() {
+        putToStore("k", null, BASE_TIMESTAMP);
+        putToStore("k", "v2", BASE_TIMESTAMP - 2);
+        putToStore("k", "v1", BASE_TIMESTAMP - 1);
+        putToStore("k", "v4", BASE_TIMESTAMP - 4);
+
+        verifyGetNullFromStore("k");
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP - 1, "v1", 
BASE_TIMESTAMP - 1);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP - 2, "v2", 
BASE_TIMESTAMP - 2);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP - 3, "v4", 
BASE_TIMESTAMP - 4);
+    }
+
+    @Test
+    public void shouldPutOlderNullWithNonNullLatest() {
+        putToStore("k", "v", BASE_TIMESTAMP);
+        putToStore("k", null, BASE_TIMESTAMP - 2);
+        putToStore("k", null, BASE_TIMESTAMP - 1);
+        putToStore("k", null, BASE_TIMESTAMP - 4);
+        putToStore("k", "v5", BASE_TIMESTAMP - 5);
+        putToStore("k", "v3", BASE_TIMESTAMP - 3);
+        putToStore("k", null, BASE_TIMESTAMP - 6);
+
+        verifyGetValueFromStore("k", "v", BASE_TIMESTAMP);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP, "v", 
BASE_TIMESTAMP);
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP - 1);
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP - 2);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP - 3, "v3", 
BASE_TIMESTAMP - 3);
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP - 4);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP - 5, "v5", 
BASE_TIMESTAMP - 5);
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP - 6);
+    }
+
+    @Test
+    public void shouldPutOlderNullWithNullLatest() {
+        putToStore("k", null, BASE_TIMESTAMP);
+        putToStore("k", null, BASE_TIMESTAMP - 2);
+        putToStore("k", null, BASE_TIMESTAMP - 1);
+        putToStore("k", null, BASE_TIMESTAMP - 4);
+        putToStore("k", "v3", BASE_TIMESTAMP - 3);
+        putToStore("k", "v5", BASE_TIMESTAMP - 5);
+        putToStore("k", null, BASE_TIMESTAMP - 6);
+
+        verifyGetNullFromStore("k");
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP);
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP - 1);
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP - 2);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP - 3, "v3", 
BASE_TIMESTAMP - 3);
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP - 4);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP - 5, "v5", 
BASE_TIMESTAMP - 5);
+        verifyTimestampedGetNullFromStore("k", BASE_TIMESTAMP - 6);
+    }
+
+    @Test
+    public void shouldPutRepeatTimestampAsLatest() {
+        putToStore("k", "to_be_replaced", BASE_TIMESTAMP);
+        putToStore("k", "b", BASE_TIMESTAMP);
+
+        verifyGetValueFromStore("k", "b", BASE_TIMESTAMP);
+        verifyTimestampedGetValueFromStore("k", BASE_TIMESTAMP, "b", 
BASE_TIMESTAMP);

Review Comment:
   Should we verify that `"to_be_replaced"` was not move and thus we cannot 
query it with `BASE_TIMESTAMP - 1`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

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

Reply via email to