tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject [34/50] tomee git commit: Don't push to the pool twice
Date Mon, 19 Feb 2018 10:48:19 GMT
Don't push to the pool twice

(cherry picked from commit 9a3e474dce3f9e1e4a92d94048488dea80322df1)


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

Branch: refs/heads/fb_tomee8
Commit: 515e4352ccdae0cd34c1887ef344520adc622ade
Parents: 34a159f
Author: Jonathan Gallimore <jon@jrg.me.uk>
Authored: Wed Jan 17 16:15:07 2018 +0000
Committer: Thiago Veronezi <thiago@veronezi.org>
Committed: Wed Jan 17 15:51:13 2018 -0500

----------------------------------------------------------------------
 .../openejb/core/mdb/PoolEndpointHandler.java   |  1 +
 .../core/mdb/PoolEndpointHandlerTest.java       | 59 +++++++-------------
 2 files changed, 22 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/515e4352/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/PoolEndpointHandler.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/PoolEndpointHandler.java
b/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/PoolEndpointHandler.java
index 18b5216..d67b28d 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/PoolEndpointHandler.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/PoolEndpointHandler.java
@@ -100,6 +100,7 @@ public class PoolEndpointHandler extends AbstractEndpointHandler {
         } finally {
             // we are now in the default NONE state
             state = State.NONE;
+            this.instance = null;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/515e4352/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/PoolEndpointHandlerTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/PoolEndpointHandlerTest.java
b/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/PoolEndpointHandlerTest.java
index 9f78a7a..d9be63a 100644
--- a/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/PoolEndpointHandlerTest.java
+++ b/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/PoolEndpointHandlerTest.java
@@ -28,24 +28,19 @@ import org.apache.openejb.monitoring.LocalMBeanServer;
 import org.apache.openejb.testing.Configuration;
 import org.apache.openejb.testing.Module;
 import org.apache.openejb.testng.PropertiesBuilder;
-import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-import javax.annotation.PostConstruct;
 import javax.annotation.Resource;
 import javax.ejb.ActivationConfigProperty;
 import javax.ejb.MessageDriven;
 import javax.jms.Queue;
 import javax.management.ObjectName;
-import java.util.List;
 import java.util.Properties;
-import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
 
-import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
@@ -53,6 +48,8 @@ import static org.junit.Assert.assertTrue;
 public class PoolEndpointHandlerTest {
 
     private static final String TEXT = "foo";
+    private static CountDownLatch latch;
+    private static AtomicLong counter = new AtomicLong();
 
     @Configuration
     public Properties config() {
@@ -63,6 +60,9 @@ public class PoolEndpointHandlerTest {
             .p("mdbs", "new://Container?type=MESSAGE")
             .p("mdbs.ResourceAdapter", "sra")
             .p("mdbs.pool", "true")
+            .p("mdbs.MaxSize", "10")
+            .p("mdbs.MinSize", "2")
+            .p("mdbs.StrictPooling", "true")
             .p("mdbs.ActivationSpecClass", SampleActivationSpec.class.getName())
             .p("mdbs.MessageListenerInterface", InboundListener.class.getName())
 
@@ -83,11 +83,6 @@ public class PoolEndpointHandlerTest {
     @Resource(name = "cf")
     private SampleConnectionFactory cf;
 
-    @Before
-    public void resetLatch() {
-        Listener.reset();
-    }
-
     @Test
     public void shouldSendMessage() throws Exception {
         assertNotNull(cf);
@@ -101,11 +96,15 @@ public class PoolEndpointHandlerTest {
             }
         }
 
+        latch = new CountDownLatch(100);
+
         // start MDB delivery
         setControl("start");
 
-        assertTrue(Listener.sync());
-        assertEquals(10, Listener.COUNTER.get());
+        latch.await(30, TimeUnit.SECONDS);
+        System.out.println("Actual instances: " + counter.get());
+        assertTrue("Expected at least 2 instances, actual:" + counter.get(), counter.get()
>= 2);
+        assertTrue("Expected at most 10 instances, actual:" + counter.get(), counter.get()
<= 10);
     }
 
     private void setControl(final String action) throws Exception {
@@ -119,38 +118,22 @@ public class PoolEndpointHandlerTest {
             @ActivationConfigProperty(propertyName = "MdbJMXControl", propertyValue = "default:type=test")
     })
     public static class Listener implements InboundListener {
-        public static CountDownLatch latch;
-        private static final List<Boolean> BOOLEANS = new CopyOnWriteArrayList<>();
-
-        static final AtomicLong COUNTER = new AtomicLong();
-
-        @PostConstruct
-        public void postConstruct() {
-            COUNTER.incrementAndGet();
-        }
 
-        public static void reset() {
-            latch = new CountDownLatch(100);
-            BOOLEANS.clear();
-        }
-
-        public static boolean sync() throws InterruptedException {
-            latch.await(1, TimeUnit.MINUTES);
-            for (boolean result : BOOLEANS) {
-                if(!result) {
-                  return false;
-                }
-            }
-            return true;
+        public Listener() {
+            counter.incrementAndGet();
         }
 
         @Override
         public void receiveMessage(String message) {
+            latch.countDown();
+            if (!TEXT.equals(message)) {
+                throw new IllegalStateException(String.format("Expected %s, received %s",
TEXT, message));
+            }
+
             try {
-                boolean ok = TEXT.equals(message);
-                BOOLEANS.add(ok);
-            } finally {
-                latch.countDown();
+                TimeUnit.MILLISECONDS.sleep(100);
+            } catch (InterruptedException e) {
+                Thread.currentThread().interrupt();
             }
         }
     }


Mime
View raw message