activemq-artemis git commit: ARTEMIS-2135 Test avoiding NPE under race

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

activemq-artemis git commit: ARTEMIS-2135 Test avoiding NPE under race

clebertsuconic-2
Repository: activemq-artemis
Updated Branches:
  refs/heads/master 66d5e4fbd -> 48d8a5413


ARTEMIS-2135 Test avoiding NPE under race


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/48d8a541
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/48d8a541
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/48d8a541

Branch: refs/heads/master
Commit: 48d8a54135732b2b34251f571aa3a5cadc44d3a9
Parents: 66d5e4f
Author: Clebert Suconic <[hidden email]>
Authored: Wed Oct 17 17:19:29 2018 -0400
Committer: Clebert Suconic <[hidden email]>
Committed: Wed Oct 17 17:24:51 2018 -0400

----------------------------------------------------------------------
 .../protocol/amqp/broker/AMQPMessageTest.java   | 63 ++++++++++++++++++++
 1 file changed, 63 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/48d8a541/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessageTest.java
----------------------------------------------------------------------
diff --git a/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessageTest.java b/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessageTest.java
index 1e5d3d1..953dd0b 100644
--- a/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessageTest.java
+++ b/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessageTest.java
@@ -33,6 +33,9 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
 import org.apache.activemq.artemis.api.core.ActiveMQBuffers;
@@ -170,6 +173,66 @@ public class AMQPMessageTest {
 
    //----- Test Connection ID access -----------------------------------------//
 
+
+   @Test
+   public void testDecodeMultiThreaded() throws Exception {
+      MessageImpl protonMessage = (MessageImpl) Message.Factory.create();
+      protonMessage.setHeader( new Header());
+      Properties properties = new Properties();
+      properties.setTo("someNiceLocal");
+      protonMessage.setProperties(properties);
+      protonMessage.getHeader().setDeliveryCount(new UnsignedInteger(7));
+      protonMessage.getHeader().setDurable(Boolean.TRUE);
+      protonMessage.setApplicationProperties(new ApplicationProperties(new HashMap<>()));
+
+      final AtomicInteger failures = new AtomicInteger(0);
+
+
+      for (int testTry = 0; testTry < 100; testTry++) {
+         AMQPMessage decoded = encodeAndDecodeMessage(protonMessage);
+         Thread[] threads = new Thread[100];
+
+         CountDownLatch latchAlign = new CountDownLatch(threads.length);
+         CountDownLatch go = new CountDownLatch(1);
+
+         Runnable run = new Runnable() {
+            @Override
+            public void run() {
+               try {
+
+                  latchAlign.countDown();
+                  go.await();
+
+                  Assert.assertNotNull(decoded.getHeader());
+                  // this is a method used by Core Converter
+                  decoded.getProtonMessage();
+                  Assert.assertNotNull(decoded.getHeader());
+
+               } catch (Throwable e) {
+                  e.printStackTrace();
+                  failures.incrementAndGet();
+               }
+            }
+         };
+
+         for (int i = 0; i < threads.length; i++) {
+            threads[i] = new Thread(run);
+            threads[i].start();
+         }
+
+         Assert.assertTrue(latchAlign.await(10, TimeUnit.SECONDS));
+         go.countDown();
+
+         for (Thread thread : threads) {
+            thread.join(5000);
+            Assert.assertFalse(thread.isAlive());
+         }
+
+         Assert.assertEquals(0, failures.get());
+      }
+   }
+
+
    @Test
    public void testGetConnectionID() {
       MessageImpl protonMessage = (MessageImpl) Message.Factory.create();