flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aljos...@apache.org
Subject flink git commit: [FLINK-8177] Replace TestingContainer by mock in YARN UtilsTest
Date Mon, 04 Dec 2017 13:43:29 GMT
Repository: flink
Updated Branches:
  refs/heads/release-1.4 0bc2cf9b4 -> cfd1b787b


[FLINK-8177] Replace TestingContainer by mock in YARN UtilsTest

The Container Interface was extended in Hadoop 2.9, meaning that the
test would not run when compiling with Hadoop 2.9. Using a mock fixes
this problem.


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/cfd1b787
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/cfd1b787
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/cfd1b787

Branch: refs/heads/release-1.4
Commit: cfd1b787b6e4fb3aee2a7fc76d920032f7d17fd5
Parents: 0bc2cf9
Author: Aljoscha Krettek <aljoscha.krettek@gmail.com>
Authored: Wed Nov 29 17:04:20 2017 +0100
Committer: Aljoscha Krettek <aljoscha.krettek@gmail.com>
Committed: Mon Dec 4 14:42:18 2017 +0100

----------------------------------------------------------------------
 .../java/org/apache/flink/yarn/UtilsTest.java   | 97 +++-----------------
 1 file changed, 11 insertions(+), 86 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/cfd1b787/flink-yarn/src/test/java/org/apache/flink/yarn/UtilsTest.java
----------------------------------------------------------------------
diff --git a/flink-yarn/src/test/java/org/apache/flink/yarn/UtilsTest.java b/flink-yarn/src/test/java/org/apache/flink/yarn/UtilsTest.java
index 69c6e7d..3307291 100644
--- a/flink-yarn/src/test/java/org/apache/flink/yarn/UtilsTest.java
+++ b/flink-yarn/src/test/java/org/apache/flink/yarn/UtilsTest.java
@@ -43,9 +43,6 @@ import org.apache.hadoop.yarn.api.records.Container;
 import org.apache.hadoop.yarn.api.records.ContainerId;
 import org.apache.hadoop.yarn.api.records.ContainerLaunchContext;
 import org.apache.hadoop.yarn.api.records.NodeId;
-import org.apache.hadoop.yarn.api.records.Priority;
-import org.apache.hadoop.yarn.api.records.Resource;
-import org.apache.hadoop.yarn.api.records.Token;
 import org.apache.hadoop.yarn.client.api.AMRMClient;
 import org.apache.hadoop.yarn.client.api.NMClient;
 import org.apache.hadoop.yarn.client.api.async.AMRMClientAsync;
@@ -73,10 +70,12 @@ import scala.concurrent.duration.FiniteDuration;
 import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 /**
  * Tests for {@link Utils}.
  */
+
 public class UtilsTest extends TestLogger {
 
 	private static ActorSystem system;
@@ -118,7 +117,15 @@ public class UtilsTest extends TestLogger {
 			final List<Container> containerList = new ArrayList<>();
 
 			for (int i = 0; i < numInitialTaskManagers; i++) {
-				containerList.add(new TestingContainer("container", 1234, i));
+				Container mockContainer = mock(Container.class);
+				when(mockContainer.getId()).thenReturn(
+					ContainerId.newInstance(
+						ApplicationAttemptId.newInstance(
+							ApplicationId.newInstance(System.currentTimeMillis(), 1),
+							1),
+						i));
+				when(mockContainer.getNodeId()).thenReturn(NodeId.newInstance("container", 1234));
+				containerList.add(mockContainer);
 			}
 
 			doAnswer(new Answer() {
@@ -221,86 +228,4 @@ public class UtilsTest extends TestLogger {
 			}
 		}};
 	}
-
-	static class TestingContainer extends Container {
-
-		private final NodeId nodeId;
-		private final ContainerId containerId;
-
-		TestingContainer(String host, int port, int containerId) {
-			this.nodeId = NodeId.newInstance(host, port);
-			this.containerId = ContainerId.newInstance(
-				ApplicationAttemptId.newInstance(
-					ApplicationId.newInstance(
-						System.currentTimeMillis(),
-						1),
-					1),
-				containerId);
-		}
-
-		@Override
-		public ContainerId getId() {
-			return containerId;
-		}
-
-		@Override
-		public void setId(ContainerId containerId) {
-
-		}
-
-		@Override
-		public NodeId getNodeId() {
-			return nodeId;
-		}
-
-		@Override
-		public void setNodeId(NodeId nodeId) {
-
-		}
-
-		@Override
-		public String getNodeHttpAddress() {
-			return null;
-		}
-
-		@Override
-		public void setNodeHttpAddress(String s) {
-
-		}
-
-		@Override
-		public Resource getResource() {
-			return null;
-		}
-
-		@Override
-		public void setResource(Resource resource) {
-
-		}
-
-		@Override
-		public Priority getPriority() {
-			return null;
-		}
-
-		@Override
-		public void setPriority(Priority priority) {
-
-		}
-
-		@Override
-		public Token getContainerToken() {
-			return null;
-		}
-
-		@Override
-		public void setContainerToken(Token token) {
-
-		}
-
-		@Override
-		public int compareTo(Container o) {
-			return 0;
-		}
-	}
 }


Mime
View raw message