zentol commented on a change in pull request #7935: [FLINK-11855] Fix race condition in EmbeddedLeaderService#GrantLeadershipCall URL: https://github.com/apache/flink/pull/7935#discussion_r263465103
########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/highavailability/nonha/embedded/EmbeddedLeaderServiceTest.java ########## @@ -0,0 +1,67 @@ +/* + * 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.highavailability.nonha.embedded; + +import org.apache.flink.runtime.concurrent.ManuallyTriggeredScheduledExecutor; +import org.apache.flink.runtime.leaderelection.LeaderElectionService; +import org.apache.flink.util.TestLogger; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.UUID; +import java.util.concurrent.ArrayBlockingQueue; + +import static org.hamcrest.Matchers.is; + +/** + * Tests for the {@link EmbeddedLeaderService}. + */ +public class EmbeddedLeaderServiceTest extends TestLogger { + + /** + * Tests that the {@link EmbeddedLeaderService} can handle a concurrent grant + * leadership call and a shutdown. + */ + @Test + public void testConcurrentGrantLeadershipAndShutdown() throws Exception { + final ManuallyTriggeredScheduledExecutor executor = new ManuallyTriggeredScheduledExecutor(); + final EmbeddedLeaderService embeddedLeaderService = new EmbeddedLeaderService(executor); + + try { + final LeaderElectionService leaderElectionService = embeddedLeaderService.createLeaderElectionService(); + + final ArrayBlockingQueue<UUID> offeredSessionIds = new ArrayBlockingQueue<>(1); + final TestingLeaderContender contender = new TestingLeaderContender(offeredSessionIds); + + leaderElectionService.start(contender); + leaderElectionService.stop(); + + if (executor.numQueuedRunnables() > 0) { Review comment: what safeguards are in place to ensure that this is usually true? I'd prefer introducing a CountdownLatch into the `ManuallyTriggeredScheduledExecutor` to allow waiting for X runnables. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
