You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2014/12/01 16:11:56 UTC

tomee git commit: fixing some tests relying on NetworkUtil + adding openejb.network.random-port.cache-timeout property for Lastport caching - 0 as default is actually the main value making sense, why do we use 10s?

Repository: tomee
Updated Branches:
  refs/heads/tomee-1.7.x 5b5782707 -> 00a1d74a3


fixing some tests relying on NetworkUtil + adding openejb.network.random-port.cache-timeout property for Lastport caching - 0 as default is actually the main value making sense, why do we use 10s?


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

Branch: refs/heads/tomee-1.7.x
Commit: 00a1d74a321fe97dd396f5073067a24f81349c93
Parents: 5b57827
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Mon Dec 1 16:09:22 2014 +0100
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Mon Dec 1 16:09:22 2014 +0100

----------------------------------------------------------------------
 .../src/main/java/org/apache/openejb/util/NetworkUtil.java    | 7 ++++---
 .../test/java/org/apache/openejb/util/NetworkUtilTest.java    | 6 +++++-
 2 files changed, 9 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/00a1d74a/container/openejb-core/src/main/java/org/apache/openejb/util/NetworkUtil.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/util/NetworkUtil.java b/container/openejb-core/src/main/java/org/apache/openejb/util/NetworkUtil.java
index c319226..d0ce67e 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/util/NetworkUtil.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/util/NetworkUtil.java
@@ -47,6 +47,7 @@ public final class NetworkUtil {
     private static final ByteBuffer buf = ByteBuffer.allocate(512);
     public static final int PORT_MIN = 1024;
     public static final int PORT_MAX = 65535;
+    public static final int EVICTION_TIMEOUT = Integer.getInteger("openejb.network.random-port.cache-timeout", 10000);
     private static File lockFile;
 
     private NetworkUtil() {
@@ -146,7 +147,7 @@ public final class NetworkUtil {
         final Iterator<LastPort> it = lastPort.iterator();
         while (it.hasNext()) {
             final LastPort last = it.next();
-            if ((System.currentTimeMillis() - last.time) >= 10000) {
+            if ((System.currentTimeMillis() - last.time) >= EVICTION_TIMEOUT) {
                 it.remove();
             }
         }
@@ -158,7 +159,7 @@ public final class NetworkUtil {
             try {
                 final LastPort lp = new LastPort(port, System.currentTimeMillis());
                 if (lastPort != null) {
-                    if (lastPort.contains(lp)) {
+                    if (lastPort.contains(lp)) { // actually doesn't mean much things excepted "it has been locked recently"
                         continue;
                     }
                 }
@@ -363,7 +364,7 @@ public final class NetworkUtil {
         }
     }
 
-    private static final class LastPort {
+    public static final class LastPort {
         private final int port;
         private final long time;
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/00a1d74a/container/openejb-core/src/test/java/org/apache/openejb/util/NetworkUtilTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/util/NetworkUtilTest.java b/container/openejb-core/src/test/java/org/apache/openejb/util/NetworkUtilTest.java
index ac7b228..5a8091d 100644
--- a/container/openejb-core/src/test/java/org/apache/openejb/util/NetworkUtilTest.java
+++ b/container/openejb-core/src/test/java/org/apache/openejb/util/NetworkUtilTest.java
@@ -24,6 +24,9 @@ import org.junit.Test;
 
 import java.io.File;
 import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
@@ -90,10 +93,11 @@ public class NetworkUtilTest {
         final long start = System.currentTimeMillis();
         final CopyOnWriteArrayList<Integer> list = new CopyOnWriteArrayList<Integer>();
 
+        final List<NetworkUtil.LastPort> lastPorts = new ArrayList<NetworkUtil.LastPort>();
         for (int i = 0; i < count; i++) {
             final Thread thread = new Thread(new Runnable() {
                 public void run() {
-                    final int nextAvailablePort = NetworkUtil.getNextAvailablePort();
+                    final int nextAvailablePort = NetworkUtil.getNextAvailablePort(NetworkUtil.PORT_MIN, NetworkUtil.PORT_MAX, Collections.<Integer>emptyList(), lastPorts);
                     if (list.contains(nextAvailablePort)) {
                         if ((System.currentTimeMillis() - start) < 10000) {
                             Assert.fail("Got a duplicate port with ten seconds");