gharris1727 commented on code in PR #15598: URL: https://github.com/apache/kafka/pull/15598#discussion_r1695510458
########## clients/src/test/java/org/apache/kafka/common/utils/MockExit.java: ########## @@ -0,0 +1,202 @@ +/* + * 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.common.utils; + +import java.util.Collections; +import java.util.IdentityHashMap; +import java.util.Objects; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +/** + * Mock fatal procedures for use in testing environments where the application should not terminate the JVM. + * <p>Use factory methods {@link #disallowFatal()} ()}, {@link #forExit(Procedure)}, + * {@link #forExitAndHalt(Procedure, Procedure)}, and {@link #forHalt(Procedure)} + * to construct test-safe alternatives for {@link Exit#system()}. + * <p>Instances of this class throw from {@link #exitOrThrow(int, String)} and {@link #haltOrThrow(int, String)}, + * killing the calling thread, but keeping the JVM alive. Call {@link #close()} at the end of the test to run + * hooks and assertions. + */ +public class MockExit extends Exit implements AutoCloseable { + + @FunctionalInterface + public interface Procedure extends Exit.Procedure { + void execute(int statusCode, String message); + static Procedure noop() { + return (statusCode, message) -> { }; + } + } + + @FunctionalInterface + public interface ShutdownHookAdder extends Exit.ShutdownHookAdder { + void addShutdownHook(String name, Runnable runnable); + + static ShutdownHookAdder noop() { + return (name, runnable) -> { }; + } + } Review Comment: Yes, because these types are only useful for mocking out the exit behavior, and so should only be present in the `test` artifact. -- 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]
