suddendust commented on a change in pull request #7173: URL: https://github.com/apache/incubator-pinot/pull/7173#discussion_r675297116
########## File path: pinot-controller/src/test/java/org/apache/pinot/controller/ControllerConfTest.java ########## @@ -0,0 +1,193 @@ +/** + * 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.pinot.controller; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.concurrent.TimeUnit; +import org.apache.commons.lang3.RandomStringUtils; +import org.apache.pinot.spi.utils.TimeUtils; +import org.testng.Assert; +import org.testng.annotations.Test; + +import static org.apache.pinot.controller.ControllerConf.ControllerPeriodicTasksConf.*; + + +public class ControllerConfTest { + + private static final List<String> DEPRECATED_CONFIGS = Arrays + .asList(DEPRECATED_RETENTION_MANAGER_FREQUENCY_IN_SECONDS, + DEPRECATED_OFFLINE_SEGMENT_INTERVAL_CHECKER_FREQUENCY_IN_SECONDS, + DEPRECATED_OFFLINE_SEGMENT_INTERVAL_CHECKER_FREQUENCY_IN_SECONDS, + DEPRECATED_REALTIME_SEGMENT_VALIDATION_FREQUENCY_IN_SECONDS, + DEPRECATED_BROKER_RESOURCE_VALIDATION_FREQUENCY_IN_SECONDS, DEPRECATED_STATUS_CHECKER_FREQUENCY_IN_SECONDS, + DEPRECATED_TASK_MANAGER_FREQUENCY_IN_SECONDS, DEPRECATED_MINION_INSTANCES_CLEANUP_TASK_FREQUENCY_IN_SECONDS, + DEPRECATED_MINION_INSTANCES_CLEANUP_TASK_MIN_OFFLINE_TIME_BEFORE_DELETION_SECONDS, + DEPRECATED_TASK_METRICS_EMITTER_FREQUENCY_IN_SECONDS, DEPRECATED_SEGMENT_RELOCATOR_FREQUENCY_IN_SECONDS, + DEPRECATED_SEGMENT_LEVEL_VALIDATION_INTERVAL_IN_SECONDS, + DEPRECATED_REALTIME_SEGMENT_RELOCATION_INITIAL_DELAY_IN_SECONDS, + DEPRECATED_STATUS_CHECKER_WAIT_FOR_PUSH_TIME_IN_SECONDS); + + private static final List<String> NEW_CONFIGS = Arrays + .asList(RETENTION_MANAGER_FREQUENCY_PERIOD, OFFLINE_SEGMENT_INTERVAL_CHECKER_FREQUENCY_PERIOD, + REALTIME_SEGMENT_VALIDATION_FREQUENCY_PERIOD, BROKER_RESOURCE_VALIDATION_FREQUENCY_PERIOD, + STATUS_CHECKER_FREQUENCY_PERIOD, TASK_MANAGER_FREQUENCY_PERIOD, + MINION_INSTANCES_CLEANUP_TASK_FREQUENCY_PERIOD, + MINION_INSTANCES_CLEANUP_TASK_MIN_OFFLINE_TIME_BEFORE_DELETION_PERIOD, TASK_METRICS_EMITTER_FREQUENCY_PERIOD, + SEGMENT_RELOCATOR_FREQUENCY_PERIOD, SEGMENT_LEVEL_VALIDATION_INTERVAL_PERIOD, + STATUS_CHECKER_WAIT_FOR_PUSH_TIME_PERIOD); + + private static final Random RAND = new Random(); + + /** + * When config contains: 1. Both deprecated config and the corresponding new config. 2. All new + * configurations are valid. 3. Some deprecated configurations are invalid. then new configs + * override deprecated configs (invalid deprecated configs do not throw exceptions when + * corresponding valid new configs are supplied as well) + */ + @Test + public void validNewConfigOverridesCorrespondingValidOrInvalidOldConfigOnRead() { + //setup + Map<String, Object> controllerConfig = new HashMap<>(); + int durationInSeconds = getRandomDurationInSeconds(); + DEPRECATED_CONFIGS.forEach(config -> controllerConfig.put(config, durationInSeconds)); + //put some invalid deprecated configs + controllerConfig.put(DEPRECATED_RETENTION_MANAGER_FREQUENCY_IN_SECONDS, getRandomString()); + controllerConfig.put(DEPRECATED_SEGMENT_LEVEL_VALIDATION_INTERVAL_IN_SECONDS, getRandomString()); + //override all deprecated configs with valid new configs + String period = getRandomPeriodInMinutes(); + NEW_CONFIGS.forEach(config -> controllerConfig.put(config, period)); + ControllerConf conf = new ControllerConf(controllerConfig); + //execution and assertion + assertOnDurations(conf, TimeUnit.SECONDS.convert(TimeUtils.convertPeriodToMillis(period), TimeUnit.MILLISECONDS)); + } + + /** + * When config contains: 1. Both deprecated config and the corresponding new config. 2. All + * deprecated configurations are valid. 3. Some new configurations are invalid. then exceptions + * are thrown when invalid new configurations are read (there is no fall-back to the corresponding + * valid deprecated configuration). For all valid new configurations, they override the + * corresponding deprecated configuration. + */ + @Test + public void invalidNewConfigShouldThrowExceptionOnReadWithoutFallbackToCorrespondingValidDeprecatedConfig() { + //setup + Map<String, Object> controllerConfig = new HashMap<>(); + int durationInSeconds = getRandomDurationInSeconds(); + //all deprecated configs should be valid + DEPRECATED_CONFIGS.forEach(config -> controllerConfig.put(config, durationInSeconds)); + String randomPeriodInMinutes = getRandomPeriodInMinutes(); Review comment: While this definitely is needed for reproducing failing tests, in this case, simply printing the test configuration gives enough information to reproduce a failing test. So I have simply printing the config for any failing test. -- 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: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org