You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by se...@apache.org on 2019/07/10 09:36:13 UTC

[flink] 12/16: [hotfix] [tests] Factor out MockResourceManagerRuntimeServices to make them reusable in different tests

This is an automated email from the ASF dual-hosted git repository.

sewen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git

commit 1a06e71aaef727fd03a69094bb0ab1efe3fe7e11
Author: Stephan Ewen <se...@apache.org>
AuthorDate: Tue Jul 9 15:36:08 2019 +0200

    [hotfix] [tests] Factor out MockResourceManagerRuntimeServices to make them reusable in different tests
---
 .../utils/MockResourceManagerRuntimeServices.java  | 78 ++++++++++++++++++++++
 .../apache/flink/yarn/YarnResourceManagerTest.java | 48 +------------
 2 files changed, 80 insertions(+), 46 deletions(-)

diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/utils/MockResourceManagerRuntimeServices.java b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/utils/MockResourceManagerRuntimeServices.java
new file mode 100755
index 0000000..0b1a9bf
--- /dev/null
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/utils/MockResourceManagerRuntimeServices.java
@@ -0,0 +1,78 @@
+/*
+ * 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.resourcemanager.utils;
+
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.runtime.concurrent.ScheduledExecutorServiceAdapter;
+import org.apache.flink.runtime.heartbeat.HeartbeatServices;
+import org.apache.flink.runtime.heartbeat.TestingHeartbeatServices;
+import org.apache.flink.runtime.highavailability.TestingHighAvailabilityServices;
+import org.apache.flink.runtime.leaderelection.TestingLeaderElectionService;
+import org.apache.flink.runtime.metrics.MetricRegistry;
+import org.apache.flink.runtime.metrics.NoOpMetricRegistry;
+import org.apache.flink.runtime.resourcemanager.JobLeaderIdService;
+import org.apache.flink.runtime.resourcemanager.slotmanager.SlotManager;
+import org.apache.flink.runtime.resourcemanager.slotmanager.SlotManagerBuilder;
+import org.apache.flink.runtime.rpc.RpcService;
+import org.apache.flink.runtime.testutils.DirectScheduledExecutorService;
+
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * Mock services needed by the resource manager.
+ */
+public class MockResourceManagerRuntimeServices {
+
+	public final RpcService rpcService;
+	public final Time timeout;
+	public final TestingHighAvailabilityServices highAvailabilityServices;
+	public final HeartbeatServices heartbeatServices;
+	public final MetricRegistry metricRegistry;
+	public final TestingLeaderElectionService rmLeaderElectionService;
+	public final JobLeaderIdService jobLeaderIdService;
+	public final SlotManager slotManager;
+
+	public MockResourceManagerRuntimeServices(RpcService rpcService, Time timeout) {
+		this.rpcService = checkNotNull(rpcService);
+		this.timeout = checkNotNull(timeout);
+		highAvailabilityServices = new TestingHighAvailabilityServices();
+		rmLeaderElectionService = new TestingLeaderElectionService();
+		highAvailabilityServices.setResourceManagerLeaderElectionService(rmLeaderElectionService);
+		heartbeatServices = new TestingHeartbeatServices();
+		metricRegistry = NoOpMetricRegistry.INSTANCE;
+		slotManager = SlotManagerBuilder.newBuilder()
+			.setScheduledExecutor(new ScheduledExecutorServiceAdapter(new DirectScheduledExecutorService()))
+			.setTaskManagerRequestTimeout(Time.seconds(10))
+			.setSlotRequestTimeout(Time.seconds(10))
+			.setTaskManagerTimeout(Time.minutes(1))
+			.build();
+		jobLeaderIdService = new JobLeaderIdService(
+			highAvailabilityServices,
+			rpcService.getScheduledExecutor(),
+			Time.minutes(5L));
+	}
+
+	public void grantLeadership() throws Exception {
+		UUID rmLeaderSessionId = UUID.randomUUID();
+		rmLeaderElectionService.isLeader(rmLeaderSessionId).get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS);
+	}
+}
diff --git a/flink-yarn/src/test/java/org/apache/flink/yarn/YarnResourceManagerTest.java b/flink-yarn/src/test/java/org/apache/flink/yarn/YarnResourceManagerTest.java
index df3fc7f..19b2f67 100755
--- a/flink-yarn/src/test/java/org/apache/flink/yarn/YarnResourceManagerTest.java
+++ b/flink-yarn/src/test/java/org/apache/flink/yarn/YarnResourceManagerTest.java
@@ -30,17 +30,12 @@ import org.apache.flink.runtime.clusterframework.types.AllocationID;
 import org.apache.flink.runtime.clusterframework.types.ResourceID;
 import org.apache.flink.runtime.clusterframework.types.ResourceProfile;
 import org.apache.flink.runtime.clusterframework.types.SlotID;
-import org.apache.flink.runtime.concurrent.ScheduledExecutorServiceAdapter;
 import org.apache.flink.runtime.entrypoint.ClusterInformation;
 import org.apache.flink.runtime.heartbeat.HeartbeatServices;
-import org.apache.flink.runtime.heartbeat.TestingHeartbeatServices;
 import org.apache.flink.runtime.highavailability.HighAvailabilityServices;
-import org.apache.flink.runtime.highavailability.TestingHighAvailabilityServices;
 import org.apache.flink.runtime.instance.HardwareDescription;
-import org.apache.flink.runtime.leaderelection.TestingLeaderElectionService;
 import org.apache.flink.runtime.messages.Acknowledge;
 import org.apache.flink.runtime.metrics.MetricRegistry;
-import org.apache.flink.runtime.metrics.NoOpMetricRegistry;
 import org.apache.flink.runtime.metrics.groups.JobManagerMetricGroup;
 import org.apache.flink.runtime.metrics.groups.UnregisteredMetricGroups;
 import org.apache.flink.runtime.registration.RegistrationResponse;
@@ -48,7 +43,7 @@ import org.apache.flink.runtime.resourcemanager.JobLeaderIdService;
 import org.apache.flink.runtime.resourcemanager.ResourceManagerGateway;
 import org.apache.flink.runtime.resourcemanager.SlotRequest;
 import org.apache.flink.runtime.resourcemanager.slotmanager.SlotManager;
-import org.apache.flink.runtime.resourcemanager.slotmanager.SlotManagerBuilder;
+import org.apache.flink.runtime.resourcemanager.utils.MockResourceManagerRuntimeServices;
 import org.apache.flink.runtime.rpc.FatalErrorHandler;
 import org.apache.flink.runtime.rpc.RpcService;
 import org.apache.flink.runtime.rpc.TestingRpcService;
@@ -57,7 +52,6 @@ import org.apache.flink.runtime.taskexecutor.SlotStatus;
 import org.apache.flink.runtime.taskexecutor.TaskExecutorGateway;
 import org.apache.flink.runtime.taskexecutor.TaskExecutorRegistrationSuccess;
 import org.apache.flink.runtime.taskexecutor.TaskManagerServices;
-import org.apache.flink.runtime.testutils.DirectScheduledExecutorService;
 import org.apache.flink.runtime.util.TestingFatalErrorHandler;
 import org.apache.flink.util.TestLogger;
 import org.apache.flink.util.function.RunnableWithException;
@@ -92,10 +86,8 @@ import java.nio.file.Files;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.UUID;
 import java.util.concurrent.Callable;
 import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.TimeUnit;
 
 import static org.apache.flink.yarn.YarnConfigKeys.ENV_APP_ID;
 import static org.apache.flink.yarn.YarnConfigKeys.ENV_CLIENT_HOME_DIR;
@@ -270,7 +262,7 @@ public class YarnResourceManagerTest extends TestLogger {
 
 		Context(Configuration configuration) throws  Exception {
 			rpcService = new TestingRpcService();
-			rmServices = new MockResourceManagerRuntimeServices();
+			rmServices = new MockResourceManagerRuntimeServices(rpcService, TIMEOUT);
 
 			// resource manager
 			rmResourceID = ResourceID.generate();
@@ -295,42 +287,6 @@ public class YarnResourceManagerTest extends TestLogger {
 		}
 
 		/**
-		 * Mock services needed by the resource manager.
-		 */
-		class MockResourceManagerRuntimeServices {
-
-			private final TestingHighAvailabilityServices highAvailabilityServices;
-			private final HeartbeatServices heartbeatServices;
-			private final MetricRegistry metricRegistry;
-			private final TestingLeaderElectionService rmLeaderElectionService;
-			private final JobLeaderIdService jobLeaderIdService;
-			private final SlotManager slotManager;
-
-			MockResourceManagerRuntimeServices() throws Exception {
-				highAvailabilityServices = new TestingHighAvailabilityServices();
-				rmLeaderElectionService = new TestingLeaderElectionService();
-				highAvailabilityServices.setResourceManagerLeaderElectionService(rmLeaderElectionService);
-				heartbeatServices = new TestingHeartbeatServices();
-				metricRegistry = NoOpMetricRegistry.INSTANCE;
-				slotManager = SlotManagerBuilder.newBuilder()
-					.setScheduledExecutor(new ScheduledExecutorServiceAdapter(new DirectScheduledExecutorService()))
-					.setTaskManagerRequestTimeout(Time.seconds(10))
-					.setSlotRequestTimeout(Time.seconds(10))
-					.setTaskManagerTimeout(Time.minutes(1))
-					.build();
-				jobLeaderIdService = new JobLeaderIdService(
-						highAvailabilityServices,
-						rpcService.getScheduledExecutor(),
-						Time.minutes(5L));
-			}
-
-			void grantLeadership() throws Exception {
-				UUID rmLeaderSessionId = UUID.randomUUID();
-				rmLeaderElectionService.isLeader(rmLeaderSessionId).get(TIMEOUT.toMilliseconds(), TimeUnit.MILLISECONDS);
-			}
-		}
-
-		/**
 		 * Start the resource manager and grant leadership to it.
 		 */
 		void startResourceManager() throws Exception {