GJL commented on a change in pull request #9832: [FLINK-11843] Bind lifespan of 
Dispatcher to leader session
URL: https://github.com/apache/flink/pull/9832#discussion_r335503334
 
 

 ##########
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/runner/SessionDispatcherLeaderProcessTest.java
 ##########
 @@ -0,0 +1,517 @@
+/*
+ * 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.dispatcher.runner;
+
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.core.testutils.OneShotLatch;
+import org.apache.flink.runtime.client.DuplicateJobSubmissionException;
+import org.apache.flink.runtime.client.JobSubmissionException;
+import org.apache.flink.runtime.concurrent.FutureUtils;
+import org.apache.flink.runtime.jobgraph.JobGraph;
+import org.apache.flink.runtime.jobmanager.JobGraphStore;
+import org.apache.flink.runtime.messages.Acknowledge;
+import org.apache.flink.runtime.testutils.TestingJobGraphStore;
+import org.apache.flink.runtime.util.TestingFatalErrorHandler;
+import org.apache.flink.runtime.webmonitor.TestingDispatcherGateway;
+import org.apache.flink.util.ExceptionUtils;
+import org.apache.flink.util.ExecutorUtils;
+import org.apache.flink.util.FlinkException;
+import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.function.ThrowingConsumer;
+import org.apache.flink.util.function.TriFunctionWithException;
+
+import org.hamcrest.core.Is;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.hasSize;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * Tests for the {@link SessionDispatcherLeaderProcess}.
+ */
+public class SessionDispatcherLeaderProcessTest extends TestLogger {
+
+       private static final JobGraph JOB_GRAPH = new JobGraph("JobGraph");
+
+       private static ExecutorService ioExecutor;
+
+       private final UUID leaderSessionId = UUID.randomUUID();
+
+       private TestingFatalErrorHandler fatalErrorHandler;
+
+       private JobGraphStore jobGraphStore;
+
+       private TestingDispatcherServiceFactory dispatcherServiceFactory;
+
+       @BeforeClass
+       public static void setupClass() {
+               ioExecutor = Executors.newSingleThreadExecutor();
+       }
+
+       @Before
+       public void setup() {
+               fatalErrorHandler = new TestingFatalErrorHandler();
+               jobGraphStore = TestingJobGraphStore.newBuilder().build();
+               dispatcherServiceFactory = 
TestingDispatcherServiceFactory.newBuilder().build();
+       }
+
+       @After
+       public void teardown() throws Exception {
+               if (fatalErrorHandler != null) {
+                       fatalErrorHandler.rethrowError();
+                       fatalErrorHandler = null;
+               }
+       }
+
+       @AfterClass
+       public static void teardownClass() {
+               if (ioExecutor != null) {
+                       ExecutorUtils.gracefulShutdown(5L, TimeUnit.SECONDS, 
ioExecutor);
+               }
+       }
+
+       @Test
+       public void start_afterClose_doesNotHaveAnEffect() throws Exception {
+               final SessionDispatcherLeaderProcess dispatcherLeaderProcess = 
createDispatcherLeaderProcess();
+
+               dispatcherLeaderProcess.close();
+               dispatcherLeaderProcess.start();
+
+               assertThat(dispatcherLeaderProcess.getState(), 
is(SessionDispatcherLeaderProcess.State.STOPPED));
+       }
+
+       @Test
+       public void 
start_triggersJobGraphRecoveryAndDispatcherServiceCreation() throws Exception {
+               jobGraphStore = TestingJobGraphStore.newBuilder()
+                       .setInitialJobGraphs(Collections.singleton(JOB_GRAPH))
+                       .build();
+
+               final CompletableFuture<Collection<JobGraph>> 
recoveredJobGraphsFuture = new CompletableFuture<>();
+               dispatcherServiceFactory = 
TestingDispatcherServiceFactory.newBuilder()
+                       .setCreateFunction(
+                               (fencingToken, recoveredJobGraphs, 
jobGraphStore) -> {
+                                       
recoveredJobGraphsFuture.complete(recoveredJobGraphs);
+                                       return 
TestingDispatcherService.newBuilder().build();
+                               }
+                       )
+                       .build();
+
+               try (final SessionDispatcherLeaderProcess 
dispatcherLeaderProcess = createDispatcherLeaderProcess()) {
+                       dispatcherLeaderProcess.start();
+                       assertThat(dispatcherLeaderProcess.getState(), 
is(SessionDispatcherLeaderProcess.State.RUNNING));
+
+                       final Collection<JobGraph> recoveredJobGraphs = 
recoveredJobGraphsFuture.get();
+
+                       assertThat(recoveredJobGraphs, hasSize(1));
 
 Review comment:
   `containsInAnyOrder` already checks the size

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to