You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by an...@apache.org on 2014/07/20 23:33:10 UTC

svn commit: r1612163 - in /tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src: main/java/org/apache/openejb/util/NetworkUtil.java test/java/org/apache/openejb/core/stateless/StatelessInstanceManagerPoolingTest.java

Author: andygumbrecht
Date: Sun Jul 20 21:33:10 2014
New Revision: 1612163

URL: http://svn.apache.org/r1612163
Log:
PMD

Modified:
    tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/util/NetworkUtil.java
    tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessInstanceManagerPoolingTest.java

Modified: tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/util/NetworkUtil.java
URL: http://svn.apache.org/viewvc/tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/util/NetworkUtil.java?rev=1612163&r1=1612162&r2=1612163&view=diff
==============================================================================
--- tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/util/NetworkUtil.java (original)
+++ tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/util/NetworkUtil.java Sun Jul 20 21:33:10 2014
@@ -42,7 +42,7 @@ public final class NetworkUtil {
         }
     }
 
-    public synchronized static int getNextAvailablePort(final int[] portList) {
+    public static synchronized int getNextAvailablePort(final int[] portList) {
 
         final ReentrantLock l = lock;
         l.lock();
@@ -72,7 +72,7 @@ public final class NetworkUtil {
         }
     }
 
-    public synchronized static int getNextAvailablePort(final int min, final int max, final Collection<Integer> excluded) {
+    public static synchronized int getNextAvailablePort(final int min, final int max, final Collection<Integer> excluded) {
 
         final ReentrantLock l = lock;
         l.lock();

Modified: tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessInstanceManagerPoolingTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessInstanceManagerPoolingTest.java?rev=1612163&r1=1612162&r2=1612163&view=diff
==============================================================================
--- tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessInstanceManagerPoolingTest.java (original)
+++ tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessInstanceManagerPoolingTest.java Sun Jul 20 21:33:10 2014
@@ -34,6 +34,7 @@ import javax.ejb.Remote;
 import javax.ejb.Stateless;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
+import java.util.ArrayList;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -97,40 +98,39 @@ public class StatelessInstanceManagerPoo
         final int count = 50;
         final CountDownLatch invocations = new CountDownLatch(count);
         final InitialContext ctx = new InitialContext();
-        final Runnable counterBeanLocal = new Runnable() {
-            public void run() {
-
-                Object object = null;
-                try {
-                    object = ctx.lookup("CounterBeanLocal");
-                } catch (final NamingException e) {
-                    assertTrue(false);
-                }
-                final Counter counter = (Counter) object;
-                assertNotNull(counter);
-                try {
-                    counter.explode(invocations);
-                } catch (final Exception e) {
-                    //Ignore
-                }
-            }
-        };
+        final ArrayList<Thread> threads = new ArrayList<Thread>(count);
 
         // 'count' instances should be created and discarded.
         for (int i = 0; i < count; i++) {
-            final Thread thread = new Thread(counterBeanLocal);
-            thread.setDaemon(false);
-            thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
-                @Override
-                public void uncaughtException(final Thread t, final Throwable e) {
-                    System.out.println("e = " + e);
+            final Thread thread = new Thread(new Runnable() {
+                public void run() {
+
+                    Object object = null;
+                    try {
+                        object = ctx.lookup("CounterBeanLocal");
+                    } catch (final NamingException e) {
+                        assertTrue(false);
+                    }
+                    final Counter counter = (Counter) object;
+                    assertNotNull(counter);
+                    try {
+                        counter.explode();
+                    } catch (final Exception e) {
+                        invocations.countDown();
+                    }
                 }
-            });
+            }, "test-thread-" + count);
+
+            thread.setDaemon(false);
+            threads.add(thread);
             thread.start();
+        }
+
+        for (final Thread thread : threads) {
             thread.join();
         }
 
-        final boolean success = invocations.await(60, TimeUnit.SECONDS);
+        final boolean success = invocations.await(160, TimeUnit.SECONDS);
 
         assertTrue("invocations timeout -> invocations.getCount() == " + invocations.getCount(), success);
 
@@ -240,7 +240,7 @@ public class StatelessInstanceManagerPoo
 
         void race(CountDownLatch ready, CountDownLatch go);
 
-        void explode(CountDownLatch latch);
+        void explode();
     }
 
     @Remote
@@ -269,13 +269,9 @@ public class StatelessInstanceManagerPoo
             return discardedInstances.get();
         }
 
-        public void explode(final CountDownLatch latch) {
+        public void explode() {
             discardedInstances.incrementAndGet();
-            try {
-                throw new NullPointerException("Test expected this null pointer: " + latch.getCount());
-            } finally {
-                latch.countDown();
-            }
+            throw new NullPointerException("Test expected this null pointer");
         }
 
         public void race(final CountDownLatch ready, final CountDownLatch go) {