davidradl commented on code in PR #26902: URL: https://github.com/apache/flink/pull/26902#discussion_r2378243332
########## flink-runtime-web/src/test/java/org/apache/flink/runtime/webmonitor/history/retaining/CompositeJobRetainedStrategyTest.java: ########## @@ -0,0 +1,139 @@ +/* + * 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.flink.runtime.webmonitor.history.retaining; + +import org.apache.flink.configuration.Configuration; +import org.apache.flink.core.fs.FileStatus; +import org.apache.flink.core.fs.Path; + +import org.junit.jupiter.api.Test; + +import java.time.Duration; +import java.time.Instant; + +import static org.apache.flink.configuration.HistoryServerOptions.HISTORY_SERVER_RETAINED_JOBS; +import static org.apache.flink.configuration.HistoryServerOptions.HISTORY_SERVER_RETAINED_TTL; +import static org.assertj.core.api.Assertions.assertThat; + +/** Testing for {@link CompositeJobRetainedStrategy}. */ +class CompositeJobRetainedStrategyTest { + + @Test + void testTimeToLiveBasedJobRetainedStrategy() { + Configuration conf = new Configuration(); + JobRetainedStrategy strategy = CompositeJobRetainedStrategy.createFrom(conf); + assertThat(strategy.shouldRetain(new TestingFileStatus(), 1)).isTrue(); + assertThat( + strategy.shouldRetain( + new TestingFileStatus( + Instant.now().toEpochMilli() + - Duration.ofMinutes(1).toMillis()), + 1)) + .isTrue(); + + conf.set(HISTORY_SERVER_RETAINED_TTL, Duration.ofMinutes(1L)); + strategy = CompositeJobRetainedStrategy.createFrom(conf); + assertThat(strategy.shouldRetain(new TestingFileStatus(), 1)).isTrue(); + assertThat( + strategy.shouldRetain( + new TestingFileStatus( + Instant.now().toEpochMilli() + - Duration.ofMinutes(1).toMillis()), + 1)) + .isFalse(); + } + + @Test + void testQuantityBasedJobRetainedStrategy() { + Configuration conf = new Configuration(); + + JobRetainedStrategy strategy = CompositeJobRetainedStrategy.createFrom(conf); + assertThat(strategy.shouldRetain(new TestingFileStatus(), 1)).isTrue(); + assertThat(strategy.shouldRetain(new TestingFileStatus(), 3)).isTrue(); + + conf.set(HISTORY_SERVER_RETAINED_JOBS, 2); + strategy = CompositeJobRetainedStrategy.createFrom(conf); + assertThat(strategy.shouldRetain(new TestingFileStatus(), 1)).isTrue(); + assertThat(strategy.shouldRetain(new TestingFileStatus(), 3)).isFalse(); + } + + @Test + void testCompositeBasedJobRetainedStrategy() { + + final long outOfTtlMillis = + Instant.now().toEpochMilli() - Duration.ofMinutes(2L).toMillis(); + + final Configuration conf = new Configuration(); + conf.set(HISTORY_SERVER_RETAINED_TTL, Duration.ofMinutes(1)); + conf.set(HISTORY_SERVER_RETAINED_JOBS, 2); + JobRetainedStrategy strategy = CompositeJobRetainedStrategy.createFrom(conf); + assertThat(strategy.shouldRetain(new TestingFileStatus(outOfTtlMillis), 1)).isFalse(); + assertThat(strategy.shouldRetain(new TestingFileStatus(), 10)).isFalse(); + assertThat(strategy.shouldRetain(new TestingFileStatus(outOfTtlMillis), 3)).isFalse(); + assertThat(strategy.shouldRetain(new TestingFileStatus(), 1)).isTrue(); + } + + private static final class TestingFileStatus implements FileStatus { Review Comment: can we test specifying TTL and no HISTORY_SERVER_RETAINED_JOBS. I think we should honour the TTL in this case, not require the HISTORY_SERVER_RETAINED_JOBS to have a positive value to have this take effect. -- 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]
