vcrfxia commented on code in PR #13143: URL: https://github.com/apache/kafka/pull/13143#discussion_r1093929163
########## streams/src/test/java/org/apache/kafka/streams/state/internals/LogicalKeyValueSegmentsTest.java: ########## @@ -0,0 +1,168 @@ +/* + * 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 org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.util.List; +import org.apache.kafka.common.metrics.Metrics; +import org.apache.kafka.common.serialization.Serdes; +import org.apache.kafka.common.utils.LogContext; +import org.apache.kafka.streams.processor.internals.MockStreamsMetrics; +import org.apache.kafka.streams.state.internals.metrics.RocksDBMetricsRecorder; +import org.apache.kafka.test.InternalMockProcessorContext; +import org.apache.kafka.test.MockRecordCollector; +import org.apache.kafka.test.TestUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class LogicalKeyValueSegmentsTest { + + private static final long SEGMENT_INTERVAL = 100L; + private static final long RETENTION_PERIOD = 4 * SEGMENT_INTERVAL; + private static final String STORE_NAME = "logical-segments"; + private static final String METRICS_SCOPE = "metrics-scope"; + private static final String DB_FILE_DIR = "rocksdb"; + + private InternalMockProcessorContext context; + + private LogicalKeyValueSegments segments; + + @Before + public void setUp() { + context = new InternalMockProcessorContext<>( + TestUtils.tempDirectory(), + Serdes.String(), + Serdes.Long(), + new MockRecordCollector(), + new ThreadCache(new LogContext("testCache "), 0, new MockStreamsMetrics(new Metrics())) + ); + segments = new LogicalKeyValueSegments( + STORE_NAME, + DB_FILE_DIR, + RETENTION_PERIOD, + SEGMENT_INTERVAL, + new RocksDBMetricsRecorder(METRICS_SCOPE, STORE_NAME) + ); + segments.openExisting(context, -1L); + } + + @After + public void tearDown() { + segments.close(); + } + + @Test + public void shouldGetSegmentIdsFromTimestamp() { + assertEquals(0, segments.segmentId(0)); + assertEquals(1, segments.segmentId(SEGMENT_INTERVAL)); + assertEquals(2, segments.segmentId(2 * SEGMENT_INTERVAL)); + assertEquals(3, segments.segmentId(3 * SEGMENT_INTERVAL)); + } + + @Test + public void shouldCreateSegments() { + final LogicalKeyValueSegment segment1 = segments.getOrCreateSegmentIfLive(0, context, -1L); Review Comment: See [above](https://github.com/apache/kafka/pull/13143#discussion_r1093927849). -- 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