directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dran...@apache.org
Subject directory-kerberos git commit: Fixed test failure, network ports should be prepared during setUp()
Date Mon, 09 Feb 2015 04:50:36 GMT
Repository: directory-kerberos
Updated Branches:
  refs/heads/master 7c323a3ba -> 02ea20f63


Fixed test failure, network ports should be prepared during setUp()


Project: http://git-wip-us.apache.org/repos/asf/directory-kerberos/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerberos/commit/02ea20f6
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerberos/tree/02ea20f6
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerberos/diff/02ea20f6

Branch: refs/heads/master
Commit: 02ea20f639506dc1edb24fb8161c291122c2616f
Parents: 7c323a3
Author: Drankye <drankye@gmail.com>
Authored: Mon Feb 9 20:47:43 2015 +0800
Committer: Drankye <drankye@gmail.com>
Committed: Mon Feb 9 20:47:43 2015 +0800

----------------------------------------------------------------------
 .../org/apache/kerby/event/NetworkUtil.java     | 47 ++++++++++++++++++++
 .../kerby/event/network/TestNetworkBase.java    |  6 +++
 .../kerby/event/network/TestNetworkClient.java  |  6 +--
 .../kerby/event/network/TestNetworkServer.java  | 13 ++----
 .../org/apache/kerby/event/tcp/TestTcpBase.java |  5 +++
 .../apache/kerby/event/tcp/TestTcpClient.java   |  6 +--
 .../apache/kerby/event/tcp/TestTcpServer.java   |  6 +--
 .../org/apache/kerby/event/udp/TestUdpBase.java |  5 +++
 .../apache/kerby/event/udp/TestUdpClient.java   |  4 +-
 .../apache/kerby/event/udp/TestUdpServer.java   |  6 +--
 10 files changed, 77 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/02ea20f6/lib/kerby-event/src/test/java/org/apache/kerby/event/NetworkUtil.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/test/java/org/apache/kerby/event/NetworkUtil.java b/lib/kerby-event/src/test/java/org/apache/kerby/event/NetworkUtil.java
new file mode 100644
index 0000000..7e3e22e
--- /dev/null
+++ b/lib/kerby-event/src/test/java/org/apache/kerby/event/NetworkUtil.java
@@ -0,0 +1,47 @@
+/**
+ *  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.kerby.event;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+
+/**
+ * Some network and event testing utilities.
+ */
+public class NetworkUtil {
+
+    /**
+     * Get a server socket point for testing usage, either TCP or UDP.
+     * @return server socket point
+     */
+    public static int getServerPort() {
+        int serverPort = 0;
+
+        try {
+            ServerSocket serverSocket = new ServerSocket(0);
+            serverPort = serverSocket.getLocalPort();
+            serverSocket.close();
+        } catch (IOException e) {
+            throw new RuntimeException("Failed to get a server socket point");
+        }
+
+        return serverPort;
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/02ea20f6/lib/kerby-event/src/test/java/org/apache/kerby/event/network/TestNetworkBase.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/test/java/org/apache/kerby/event/network/TestNetworkBase.java
b/lib/kerby-event/src/test/java/org/apache/kerby/event/network/TestNetworkBase.java
index 04a15a9..9a0562c 100644
--- a/lib/kerby-event/src/test/java/org/apache/kerby/event/network/TestNetworkBase.java
+++ b/lib/kerby-event/src/test/java/org/apache/kerby/event/network/TestNetworkBase.java
@@ -20,6 +20,7 @@
 package org.apache.kerby.event.network;
 
 import org.apache.kerby.event.EventType;
+import org.apache.kerby.event.NetworkUtil;
 import org.apache.kerby.transport.tcp.DecodingCallback;
 import org.apache.kerby.transport.tcp.StreamingDecoder;
 
@@ -36,6 +37,11 @@ public class TestNetworkBase {
         FINISHED
     }
 
+    protected void preparePorts() {
+        tcpPort = NetworkUtil.getServerPort();
+        udpPort = NetworkUtil.getServerPort();
+    }
+
     protected String recvBuffer2String(ByteBuffer buffer) {
         byte[] bytes = new byte[buffer.remaining()];
         buffer.get(bytes);

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/02ea20f6/lib/kerby-event/src/test/java/org/apache/kerby/event/network/TestNetworkClient.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/test/java/org/apache/kerby/event/network/TestNetworkClient.java
b/lib/kerby-event/src/test/java/org/apache/kerby/event/network/TestNetworkClient.java
index 54dc6a9..7d00d58 100644
--- a/lib/kerby-event/src/test/java/org/apache/kerby/event/network/TestNetworkClient.java
+++ b/lib/kerby-event/src/test/java/org/apache/kerby/event/network/TestNetworkClient.java
@@ -51,6 +51,8 @@ public class TestNetworkClient extends TestNetworkBase {
 
     @Before
     public void setUp() throws IOException {
+        preparePorts();
+
         setUpServer();
         setUpClient();
     }
@@ -86,8 +88,6 @@ public class TestNetworkClient extends TestNetworkBase {
         ServerSocket serverSocket = serverSocketChannel.socket();
         serverSocket.bind(new InetSocketAddress(tcpPort));
         serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT);
-        
-        tcpPort = serverSocket.getLocalPort();
 
         SocketChannel socketChannel;
         while (true) {
@@ -132,8 +132,6 @@ public class TestNetworkClient extends TestNetworkBase {
         DatagramSocket serverSocket = serverSocketChannel.socket();
         serverSocket.bind(new InetSocketAddress(udpPort));
         serverSocketChannel.register(selector, SelectionKey.OP_READ);
-        
-        udpPort = serverSocket.getLocalPort();
 
         while (true) {
             if (selector.selectNow() > 0) {

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/02ea20f6/lib/kerby-event/src/test/java/org/apache/kerby/event/network/TestNetworkServer.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/test/java/org/apache/kerby/event/network/TestNetworkServer.java
b/lib/kerby-event/src/test/java/org/apache/kerby/event/network/TestNetworkServer.java
index b22c1d3..b68745d 100644
--- a/lib/kerby-event/src/test/java/org/apache/kerby/event/network/TestNetworkServer.java
+++ b/lib/kerby-event/src/test/java/org/apache/kerby/event/network/TestNetworkServer.java
@@ -45,6 +45,8 @@ public class TestNetworkServer extends TestNetworkBase {
 
     @Before
     public void setUp() throws IOException {
+        preparePorts();
+
         setUpServer();
     }
 
@@ -66,17 +68,8 @@ public class TestNetworkServer extends TestNetworkBase {
         eventHub.register(network);
 
         eventHub.start();
-        
-        ServerSocket serverSocket = new ServerSocket(0);
-        tcpPort = serverSocket.getLocalPort();
-        serverSocket.close();
-        
+
         network.tcpListen(serverHost, tcpPort);
-        
-        serverSocket = new ServerSocket(0);
-        udpPort = serverSocket.getLocalPort();
-        serverSocket.close();
-        
         network.udpListen(serverHost, udpPort);
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/02ea20f6/lib/kerby-event/src/test/java/org/apache/kerby/event/tcp/TestTcpBase.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/test/java/org/apache/kerby/event/tcp/TestTcpBase.java b/lib/kerby-event/src/test/java/org/apache/kerby/event/tcp/TestTcpBase.java
index 8949733..c4c2d55 100644
--- a/lib/kerby-event/src/test/java/org/apache/kerby/event/tcp/TestTcpBase.java
+++ b/lib/kerby-event/src/test/java/org/apache/kerby/event/tcp/TestTcpBase.java
@@ -20,6 +20,7 @@
 package org.apache.kerby.event.tcp;
 
 import org.apache.kerby.event.EventType;
+import org.apache.kerby.event.NetworkUtil;
 import org.apache.kerby.transport.tcp.DecodingCallback;
 import org.apache.kerby.transport.tcp.StreamingDecoder;
 
@@ -35,6 +36,10 @@ public class TestTcpBase {
         FINISHED
     }
 
+    protected void preparePort() {
+        serverPort = NetworkUtil.getServerPort();
+    }
+
     protected String recvBuffer2String(ByteBuffer buffer) {
         byte[] bytes = new byte[buffer.remaining()];
         buffer.get(bytes);

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/02ea20f6/lib/kerby-event/src/test/java/org/apache/kerby/event/tcp/TestTcpClient.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/test/java/org/apache/kerby/event/tcp/TestTcpClient.java b/lib/kerby-event/src/test/java/org/apache/kerby/event/tcp/TestTcpClient.java
index 106c3c7..823ae7b 100644
--- a/lib/kerby-event/src/test/java/org/apache/kerby/event/tcp/TestTcpClient.java
+++ b/lib/kerby-event/src/test/java/org/apache/kerby/event/tcp/TestTcpClient.java
@@ -54,6 +54,8 @@ public class TestTcpClient extends TestTcpBase {
 
     @Before
     public void setUp() throws IOException {
+        preparePort();
+
         setUpServer();
         setUpClient();
     }
@@ -76,10 +78,8 @@ public class TestTcpClient extends TestTcpBase {
         ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
         serverSocketChannel.configureBlocking(false);
         ServerSocket serverSocket = serverSocketChannel.socket();
-        serverSocket.bind(new InetSocketAddress(0));
+        serverSocket.bind(new InetSocketAddress(serverPort));
         serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT);
-        
-        serverPort = serverSocket.getLocalPort();
 
         SocketChannel socketChannel;
         while (true) {

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/02ea20f6/lib/kerby-event/src/test/java/org/apache/kerby/event/tcp/TestTcpServer.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/test/java/org/apache/kerby/event/tcp/TestTcpServer.java b/lib/kerby-event/src/test/java/org/apache/kerby/event/tcp/TestTcpServer.java
index 66a2df3..d95580a 100644
--- a/lib/kerby-event/src/test/java/org/apache/kerby/event/tcp/TestTcpServer.java
+++ b/lib/kerby-event/src/test/java/org/apache/kerby/event/tcp/TestTcpServer.java
@@ -45,6 +45,8 @@ public class TestTcpServer extends TestTcpBase {
 
     @Before
     public void setUp() throws IOException {
+        preparePort();
+
         setUpServer();
     }
 
@@ -63,10 +65,6 @@ public class TestTcpServer extends TestTcpBase {
 
         Acceptor acceptor = new TcpAcceptor(createStreamingDecoder());
         eventHub.register(acceptor);
-        
-        ServerSocket serverSocket = new ServerSocket(0);
-        serverPort = serverSocket.getLocalPort();
-        serverSocket.close();
 
         eventHub.start();
         acceptor.listen(serverHost, serverPort);

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/02ea20f6/lib/kerby-event/src/test/java/org/apache/kerby/event/udp/TestUdpBase.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/test/java/org/apache/kerby/event/udp/TestUdpBase.java b/lib/kerby-event/src/test/java/org/apache/kerby/event/udp/TestUdpBase.java
index f4d3ed1..1887043 100644
--- a/lib/kerby-event/src/test/java/org/apache/kerby/event/udp/TestUdpBase.java
+++ b/lib/kerby-event/src/test/java/org/apache/kerby/event/udp/TestUdpBase.java
@@ -20,6 +20,7 @@
 package org.apache.kerby.event.udp;
 
 import org.apache.kerby.event.EventType;
+import org.apache.kerby.event.NetworkUtil;
 
 import java.nio.ByteBuffer;
 
@@ -33,6 +34,10 @@ public class TestUdpBase {
         FINISHED
     }
 
+    protected void preparePort() {
+        serverPort = NetworkUtil.getServerPort();
+    }
+
     protected String recvBuffer2String(ByteBuffer buffer) {
         byte[] bytes = new byte[buffer.remaining()];
         buffer.get(bytes);

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/02ea20f6/lib/kerby-event/src/test/java/org/apache/kerby/event/udp/TestUdpClient.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/test/java/org/apache/kerby/event/udp/TestUdpClient.java b/lib/kerby-event/src/test/java/org/apache/kerby/event/udp/TestUdpClient.java
index 60001f4..6f3453e 100644
--- a/lib/kerby-event/src/test/java/org/apache/kerby/event/udp/TestUdpClient.java
+++ b/lib/kerby-event/src/test/java/org/apache/kerby/event/udp/TestUdpClient.java
@@ -53,6 +53,8 @@ public class TestUdpClient extends TestUdpBase {
 
     @Before
     public void setUp() throws IOException {
+        preparePort();
+
         setUpServer();
         setUpClient();
     }
@@ -77,8 +79,6 @@ public class TestUdpClient extends TestUdpBase {
         DatagramSocket serverSocket = serverSocketChannel.socket();
         serverSocket.bind(new InetSocketAddress(serverPort));
         serverSocketChannel.register(selector, SelectionKey.OP_READ);
-        
-        serverPort = serverSocket.getLocalPort();
 
         while (true) {
             if (selector.selectNow() > 0) {

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/02ea20f6/lib/kerby-event/src/test/java/org/apache/kerby/event/udp/TestUdpServer.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/test/java/org/apache/kerby/event/udp/TestUdpServer.java b/lib/kerby-event/src/test/java/org/apache/kerby/event/udp/TestUdpServer.java
index b525a55..f44aa53 100644
--- a/lib/kerby-event/src/test/java/org/apache/kerby/event/udp/TestUdpServer.java
+++ b/lib/kerby-event/src/test/java/org/apache/kerby/event/udp/TestUdpServer.java
@@ -45,6 +45,8 @@ public class TestUdpServer extends TestUdpBase {
 
     @Before
     public void setUp() throws IOException {
+        preparePort();
+
         setUpServer();
     }
 
@@ -63,10 +65,6 @@ public class TestUdpServer extends TestUdpBase {
 
         Acceptor acceptor = new UdpAcceptor();
         eventHub.register(acceptor);
-        
-        ServerSocket serverSocket = new ServerSocket(0);
-        serverPort = serverSocket.getLocalPort();
-        serverSocket.close();
 
         eventHub.start();
         acceptor.listen(serverHost, serverPort);


Mime
View raw message