tillrohrmann commented on a change in pull request #17485: URL: https://github.com/apache/flink/pull/17485#discussion_r791061384
########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/leaderelection/DefaultMultipleComponentLeaderElectionServiceTest.java ########## @@ -0,0 +1,297 @@ +/* + * 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.leaderelection; + +import org.apache.flink.runtime.util.TestingFatalErrorHandlerExtension; +import org.apache.flink.util.TestLoggerExtension; +import org.apache.flink.util.concurrent.Executors; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.RegisterExtension; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThat; + +/** Tests for the {@link DefaultMultipleComponentLeaderElectionService}. */ +@ExtendWith(TestLoggerExtension.class) +class DefaultMultipleComponentLeaderElectionServiceTest { + + @RegisterExtension + public final TestingFatalErrorHandlerExtension fatalErrorHandlerExtension = + new TestingFatalErrorHandlerExtension(); + + @Test + public void isLeaderInformsAllRegisteredLeaderElectionEventHandlers() throws Exception { + final TestingMultipleComponentLeaderElectionDriver leaderElectionDriver = + TestingMultipleComponentLeaderElectionDriver.newBuilder().build(); + + final DefaultMultipleComponentLeaderElectionService leaderElectionService = + createDefaultMultiplexingLeaderElectionService(leaderElectionDriver); + + try { + final Collection<SimpleTestingLeaderElectionEventListener> eventListeners = + Stream.generate(SimpleTestingLeaderElectionEventListener::new) + .limit(4) + .collect(Collectors.toList()); + + int counter = 0; + for (SimpleTestingLeaderElectionEventListener eventListener : eventListeners) { + leaderElectionService.registerLeaderElectionEventHandler( + String.valueOf(counter), eventListener); + counter++; + } + + leaderElectionDriver.grantLeadership(); + + for (SimpleTestingLeaderElectionEventListener eventListener : eventListeners) { + assertThat(eventListener.hasLeadership()).isTrue(); + } + } finally { + leaderElectionService.close(); + } + } + + @Nonnull + private DefaultMultipleComponentLeaderElectionService + createDefaultMultiplexingLeaderElectionService( + TestingMultipleComponentLeaderElectionDriver leaderElectionDriver) + throws Exception { + final DefaultMultipleComponentLeaderElectionService leaderElectionService = Review comment: Yes, I will update the code. -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org