Github user tillrohrmann commented on a diff in the pull request:
https://github.com/apache/flink/pull/2451#discussion_r77339204
--- Diff:
flink-runtime/src/test/java/org/apache/flink/runtime/rpc/resourcemanager/ResourceManagerTest.java
---
@@ -0,0 +1,85 @@
+package org.apache.flink.runtime.rpc.resourcemanager;
+
+import org.apache.flink.runtime.clusterframework.types.ResourceID;
+import
org.apache.flink.runtime.highavailability.TestingHighAvailabilityServices;
+import
org.apache.flink.runtime.leaderelection.TestingLeaderElectionService;
+import org.apache.flink.runtime.rpc.TestingSerialRpcService;
+import org.apache.flink.runtime.rpc.UnmatchedLeaderSessionIDException;
+import org.apache.flink.runtime.rpc.registration.RegistrationResponse;
+import org.apache.flink.runtime.rpc.taskexecutor.TaskExecutorGateway;
+import
org.apache.flink.runtime.rpc.taskexecutor.TaskExecutorRegistrationSuccess;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import scala.concurrent.Await;
+import scala.concurrent.Future;
+import scala.concurrent.duration.FiniteDuration;
+
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.*;
+
+public class ResourceManagerTest {
+
+ private TestingSerialRpcService rpcService;
+
+ @Before
+ public void setup() throws Exception {
+ rpcService = new TestingSerialRpcService();
+ }
+
+ @After
+ public void teardown() throws Exception {
+ rpcService.stopService();
+ }
+
+ /**
+ * Test registerTaskExecutor, including normal registration,
registration with unmatched leadershipId, registration with invalid address,
duplicate registration
+ * @throws Exception
+ */
+ @Test
+ public void testRegisterTaskExecutor() throws Exception {
+ String taskExecutorAddress = "/taskExecutor1";
+ TaskExecutorGateway taskExecutorGateway =
mock(TaskExecutorGateway.class);
+ ResourceID taskExecutorResourceID = ResourceID.generate();
+ rpcService.registerGateway(taskExecutorAddress,
taskExecutorGateway);
+
+ TestingLeaderElectionService leaderElectionService = new
TestingLeaderElectionService();
+ TestingHighAvailabilityServices highAvailabilityServices = new
TestingHighAvailabilityServices();
+
highAvailabilityServices.setResourceManagerLeaderElectionService(leaderElectionService);
+
+ final ResourceManager resourceManager = new
ResourceManager(rpcService, highAvailabilityServices);
+ resourceManager.start();
+ final UUID leaderSessionId = UUID.randomUUID();
+ leaderElectionService.isLeader(leaderSessionId);
+
+ // test throw exception when receive a registration from
taskExecutor which takes unmatched leaderSessionId
+ UUID differentLeaderSessionID = UUID.randomUUID();
+ Future<RegistrationResponse> unMatchedLeaderFuture =
resourceManager.registerTaskExecutor(differentLeaderSessionID,
taskExecutorAddress, taskExecutorResourceID);
+ assertTrue(unMatchedLeaderFuture.isCompleted());
+ assertTrue(unMatchedLeaderFuture.failed().isCompleted());
+ assertTrue(unMatchedLeaderFuture.failed().value().get().get()
instanceof UnmatchedLeaderSessionIDException);
--- End diff --
Why not simply doing `Await.result` and catching the
`UnmatchedLeaderSessionIDException`?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---