You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tez.apache.org by ss...@apache.org on 2014/08/01 22:39:07 UTC
git commit: TEZ-1342. Fix a bug which caused
tez.am.client.am.port-range to not take effect. Contributed by Jeff Zhang.
Repository: tez
Updated Branches:
refs/heads/master a9eb0d721 -> 0306928f7
TEZ-1342. Fix a bug which caused tez.am.client.am.port-range to not take
effect. Contributed by Jeff Zhang.
Project: http://git-wip-us.apache.org/repos/asf/tez/repo
Commit: http://git-wip-us.apache.org/repos/asf/tez/commit/0306928f
Tree: http://git-wip-us.apache.org/repos/asf/tez/tree/0306928f
Diff: http://git-wip-us.apache.org/repos/asf/tez/diff/0306928f
Branch: refs/heads/master
Commit: 0306928f7ce6c51fb56a573a5403a7cb132571bd
Parents: a9eb0d7
Author: Siddharth Seth <ss...@apache.org>
Authored: Fri Aug 1 13:38:15 2014 -0700
Committer: Siddharth Seth <ss...@apache.org>
Committed: Fri Aug 1 13:38:15 2014 -0700
----------------------------------------------------------------------
.../tez/dag/api/client/DAGClientServer.java | 4 +-
.../tez/dag/api/client/TestDAGClientServer.java | 82 ++++++++++++++++++++
2 files changed, 83 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tez/blob/0306928f/tez-dag/src/main/java/org/apache/tez/dag/api/client/DAGClientServer.java
----------------------------------------------------------------------
diff --git a/tez-dag/src/main/java/org/apache/tez/dag/api/client/DAGClientServer.java b/tez-dag/src/main/java/org/apache/tez/dag/api/client/DAGClientServer.java
index 34980b5..bd2a781 100644
--- a/tez-dag/src/main/java/org/apache/tez/dag/api/client/DAGClientServer.java
+++ b/tez-dag/src/main/java/org/apache/tez/dag/api/client/DAGClientServer.java
@@ -73,10 +73,8 @@ public class DAGClientServer extends AbstractService {
int numHandlers = conf.getInt(TezConfiguration.TEZ_AM_CLIENT_THREAD_COUNT,
TezConfiguration.TEZ_AM_CLIENT_THREAD_COUNT_DEFAULT);
- String portRange = conf.get(TezConfiguration.TEZ_AM_CLIENT_AM_PORT_RANGE);
-
server = createServer(DAGClientAMProtocolBlockingPB.class, addr, conf,
- numHandlers, blockingService, portRange);
+ numHandlers, blockingService, TezConfiguration.TEZ_AM_CLIENT_AM_PORT_RANGE);
// Enable service authorization?
if (conf.getBoolean(
http://git-wip-us.apache.org/repos/asf/tez/blob/0306928f/tez-dag/src/test/java/org/apache/tez/dag/api/client/TestDAGClientServer.java
----------------------------------------------------------------------
diff --git a/tez-dag/src/test/java/org/apache/tez/dag/api/client/TestDAGClientServer.java b/tez-dag/src/test/java/org/apache/tez/dag/api/client/TestDAGClientServer.java
new file mode 100644
index 0000000..fd0bc7a
--- /dev/null
+++ b/tez-dag/src/test/java/org/apache/tez/dag/api/client/TestDAGClientServer.java
@@ -0,0 +1,82 @@
+/**
+ * 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.tez.dag.api.client;
+
+import static org.mockito.Mockito.*;
+
+import java.io.IOException;
+import java.util.Random;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
+import org.apache.tez.dag.api.TezConfiguration;
+import org.apache.tez.dag.api.TezUncheckedException;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class TestDAGClientServer {
+
+ // try 10 times to allocate random port, fail it if no one is succeed.
+ @Test
+ public void testPortRange() {
+ boolean succeedToAllocate = false;
+ Random rand = new Random();
+ for (int i = 0; i < 10; ++i) {
+ int nextPort = 1024 + rand.nextInt(65535 - 1024);
+ if (testPortRange(nextPort)) {
+ succeedToAllocate = true;
+ }
+ }
+ if (!succeedToAllocate) {
+ fail("Can not allocate free port even in 10 iterations for DAGClientServer");
+ }
+ }
+
+ private boolean testPortRange(int port) {
+ DAGClientServer clientServer = null;
+ boolean succeedToAllocate = true;
+ try {
+ DAGClientHandler mockDAGClientHander = mock(DAGClientHandler.class);
+ ApplicationAttemptId mockAppAttempId = mock(ApplicationAttemptId.class);
+ clientServer = new DAGClientServer(mockDAGClientHander, mockAppAttempId);
+ Configuration conf = new Configuration();
+ conf.set(TezConfiguration.TEZ_AM_CLIENT_AM_PORT_RANGE, port + "-" + port);
+ clientServer.init(conf);
+ clientServer.start();
+ int resultedPort = clientServer.getBindAddress().getPort();
+ System.out.println("bind to address: " + clientServer.getBindAddress());
+ assertEquals(port, resultedPort);
+ } catch (TezUncheckedException e) {
+ assertTrue(e.getMessage().contains(
+ "Could not find a free port in " + port + "-" + port));
+ succeedToAllocate = false;
+ } finally {
+ if (clientServer != null) {
+ try {
+ clientServer.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail("fail to stop DAGClientServer");
+ }
+ }
+ }
+ return succeedToAllocate;
+ }
+}