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/10 20:00:42 UTC

svn commit: r1609531 - in /tomee/tomee/trunk: ./ container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessInstanceManagerPoolingTest.java

Author: andygumbrecht
Date: Thu Jul 10 18:00:41 2014
New Revision: 1609531

URL: http://svn.apache.org/r1609531
Log:
Strict pool can starve on discard

Modified:
    tomee/tomee/trunk/   (props changed)
    tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessInstanceManagerPoolingTest.java

Propchange: tomee/tomee/trunk/
------------------------------------------------------------------------------
  Merged /tomee/tomee/branches/tomee-1.7.x:r1609264

Modified: tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessInstanceManagerPoolingTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessInstanceManagerPoolingTest.java?rev=1609531&r1=1609530&r2=1609531&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessInstanceManagerPoolingTest.java (original)
+++ tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessInstanceManagerPoolingTest.java Thu Jul 10 18:00:41 2014
@@ -42,6 +42,9 @@ import java.util.concurrent.atomic.Atomi
  */
 public class StatelessInstanceManagerPoolingTest extends TestCase {
 
+    public static final AtomicInteger instances = new AtomicInteger();
+    public static final AtomicInteger discardedInstances = new AtomicInteger();
+
     public void testStatelessBeanPooling() throws Exception {
 
         InitialContext ctx = new InitialContext();            
@@ -74,7 +77,7 @@ public class StatelessInstanceManagerPoo
 
         //  -- SET --
 
-        assertEquals(10, CounterBean.instances.get());
+        assertEquals(10, instances.get());
 
         //  -- GO --
 
@@ -84,19 +87,19 @@ public class StatelessInstanceManagerPoo
 
         //  -- DONE --
 
-        assertEquals(10, CounterBean.instances.get());
+        assertEquals(10, instances.get());
 
     }
     
     public void testStatelessBeanRelease() throws Exception {
-    	
-    	
-    	final CountDownLatch invocations = new CountDownLatch(30);
-        final InitialContext ctx = new InitialContext(); 
-        final AtomicInteger instances = new AtomicInteger();
-        // Do a business method...
-        Runnable r = new Runnable(){        	
-        	public void run(){
+
+
+        final int count = 10; //Strict pool can starve on more than 10
+        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");
@@ -105,27 +108,25 @@ public class StatelessInstanceManagerPoo
 				}                                
                 Counter counter = (Counter) object;
                 assertNotNull(counter);
-                try{                
-        		    counter.explode(invocations);        	
-                }catch(Exception e){
-                	
-                }        	   
+                try {
+                    counter.explode(invocations);
+                } catch (final Exception e) {
+                    //Ignore
+                }
             }
         };
 
-        //  -- READY --
-
-        // 30 instances should be created and discarded.
-        for (int i = 0; i < 30; i++) {
-            Thread t = new Thread(r);
-            t.start();            
+        // 'count' instances should be created and discarded.
+        for (int i = 0; i < count; i++) {
+            final Thread thread = new Thread(counterBeanLocal);
+            thread.start();
         }
 
         boolean success = invocations.await(20000, TimeUnit.MILLISECONDS);
 
         assertTrue("invocations timeout -> invocations.getCount() == " + invocations.getCount(), success);
 
-        assertEquals(30, CounterBean.discardedInstances.get());
+        assertEquals(count, discardedInstances.get());
 
     }
 
@@ -170,7 +171,7 @@ public class StatelessInstanceManagerPoo
         // Wait for the other beans timeout
         assertTrue("expected 10 timeouts", timeouts.await(3000, TimeUnit.MILLISECONDS));
 
-        assertEquals(10, CounterBean.instances.get(), 1.1);
+        assertEquals(10, instances.get(), 1.1);
 
         comment("Go!");
 
@@ -216,16 +217,15 @@ public class StatelessInstanceManagerPoo
         EjbJar ejbJar = new EjbJar();
         ejbJar.addEnterpriseBean(bean);
 
-        CounterBean.instances.set(0);
+        instances.set(0);
         assembler.createApplication(config.configureApplication(ejbJar));
-
     }
 
  
     public static interface Counter {
         int count();
         void race(CountDownLatch ready, CountDownLatch go);
-        void explode(CountDownLatch invocations);
+        void explode(CountDownLatch latch);
     }
     
     @Remote
@@ -240,10 +240,9 @@ public class StatelessInstanceManagerPoo
     @Stateless
     public static class CounterBean implements Counter, RemoteCounter {
 
-        public static AtomicInteger instances = new AtomicInteger();
-        public static AtomicInteger discardedInstances = new AtomicInteger();
 
-        private int count;
+
+        private final int count;
 
         public CounterBean() {
             count = instances.incrementAndGet();
@@ -256,14 +255,14 @@ public class StatelessInstanceManagerPoo
         public int discardCount(){
         	return discardedInstances.get();
         }
-        
-        public void explode(CountDownLatch invocations){
-        	try{
-        	    discardedInstances.incrementAndGet();
-        	    throw new NullPointerException("Test expected this null pointer");
-        	}finally{
-        		invocations.countDown();
-        	}
+
+        public void explode(final CountDownLatch latch) {
+            discardedInstances.incrementAndGet();
+            try {
+                throw new NullPointerException("Test expected this null pointer");
+            } finally {
+                latch.countDown();
+            }
         }
 
         public void race(CountDownLatch ready, CountDownLatch go){