mimaison commented on code in PR #21406: URL: https://github.com/apache/kafka/pull/21406#discussion_r2805118964
########## storage/src/test/java/org/apache/kafka/storage/internals/log/AbstractLogCleanerIntegrationTest.java: ########## @@ -0,0 +1,261 @@ +/* + * 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.storage.internals.log; + +import org.apache.kafka.common.TopicPartition; +import org.apache.kafka.common.compress.Compression; +import org.apache.kafka.common.config.TopicConfig; +import org.apache.kafka.common.record.internal.MemoryRecords; +import org.apache.kafka.common.record.internal.RecordBatch; +import org.apache.kafka.common.record.internal.RecordVersion; +import org.apache.kafka.common.utils.Utils; +import org.apache.kafka.coordinator.transaction.TransactionLogConfig; +import org.apache.kafka.server.util.MockTime; +import org.apache.kafka.storage.log.metrics.BrokerTopicStats; +import org.apache.kafka.test.TestUtils; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Tag; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.Properties; +import java.util.Random; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +@Tag("integration") +public abstract class AbstractLogCleanerIntegrationTest { + + protected LogCleaner cleaner; + protected final File logDir = TestUtils.tempDirectory(); + + private final List<UnifiedLog> logs = new ArrayList<>(); + private static final int DEFAULT_MAX_MESSAGE_SIZE = 128; + private static final float DEFAULT_MIN_CLEANABLE_DIRTY_RATIO = 0.0F; + private static final long DEFAULT_MIN_COMPACTION_LAG_MS = 0L; + private static final int DEFAULT_DELETE_DELAY = 1000; + private static final int DEFAULT_SEGMENT_SIZE = 2048; + private static final long DEFAULT_MAX_COMPACTION_LAG_MS = Long.MAX_VALUE; + + private int counter = 0; + + protected abstract MockTime time(); + + @AfterEach + public void teardown() throws IOException, InterruptedException { + if (cleaner != null) { + cleaner.shutdown(); + } + time().scheduler.shutdown(); + for (UnifiedLog log : logs) { + log.close(); + } + Utils.delete(logDir); + } + + protected Properties logConfigProperties(Properties propertyOverrides, + int maxMessageSize, + float minCleanableDirtyRatio, + long minCompactionLagMs, + int deleteDelay, + int segmentSize, + long maxCompactionLagMs) { + Properties props = new Properties(); + props.put(TopicConfig.MAX_MESSAGE_BYTES_CONFIG, maxMessageSize); + props.put(LogConfig.INTERNAL_SEGMENT_BYTES_CONFIG, segmentSize); + props.put(TopicConfig.SEGMENT_INDEX_BYTES_CONFIG, 100 * 1024); + props.put(TopicConfig.FILE_DELETE_DELAY_MS_CONFIG, deleteDelay); + props.put(TopicConfig.CLEANUP_POLICY_CONFIG, TopicConfig.CLEANUP_POLICY_COMPACT); + props.put(TopicConfig.MIN_CLEANABLE_DIRTY_RATIO_CONFIG, minCleanableDirtyRatio); + props.put(TopicConfig.MIN_COMPACTION_LAG_MS_CONFIG, minCompactionLagMs); + props.put(TopicConfig.MAX_COMPACTION_LAG_MS_CONFIG, maxCompactionLagMs); + props.putAll(propertyOverrides); + return props; + } + + // TODO: This would be used when `LogCleanerParameterizedIntegrationTest` is ported to Java and moved to storage module Review Comment: Not sure we really need these comments. This will force us to update this file again when we move the other tests. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
