You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2017/12/27 22:44:28 UTC

[2/3] qpid-broker-j git commit: QPID-6933: [System Tests] Refactor connection start tests as JMS 1.1 system test

QPID-6933: [System Tests] Refactor connection start tests as JMS 1.1 system test


Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/f3047593
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/f3047593
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/f3047593

Branch: refs/heads/master
Commit: f3047593f077d18a4cf2a1666a4bc54d13879a1a
Parents: f98b029
Author: Alex Rudyy <or...@apache.org>
Authored: Wed Dec 27 20:16:48 2017 +0000
Committer: Alex Rudyy <or...@apache.org>
Committed: Wed Dec 27 20:16:48 2017 +0000

----------------------------------------------------------------------
 .../jms_1_1/connection/ConnectionStartTest.java | 104 ++++++++++++++
 .../client/connection/ConnectionStartTest.java  | 144 -------------------
 2 files changed, 104 insertions(+), 144 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/f3047593/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/connection/ConnectionStartTest.java
----------------------------------------------------------------------
diff --git a/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/connection/ConnectionStartTest.java b/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/connection/ConnectionStartTest.java
new file mode 100644
index 0000000..7169e34
--- /dev/null
+++ b/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/connection/ConnectionStartTest.java
@@ -0,0 +1,104 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.systests.jms_1_1.connection;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicLong;
+
+import javax.jms.Connection;
+import javax.jms.MessageConsumer;
+import javax.jms.Queue;
+import javax.jms.Session;
+
+import org.junit.Test;
+
+import org.apache.qpid.systests.JmsTestBase;
+import org.apache.qpid.systests.Utils;
+
+public class ConnectionStartTest extends JmsTestBase
+{
+    @Test
+    public void testConsumerCanReceiveMessageAfterConnectionStart() throws Exception
+    {
+        Queue queue = createQueue(getTestName());
+        Connection connection = getConnection();
+        try
+        {
+            Utils.sendMessages(connection, queue, 1);
+
+            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            MessageConsumer consumer = session.createConsumer(queue);
+            assertNull("No messages should be delivered when the connection is stopped",
+                       consumer.receive(getReceiveTimeout() / 2));
+            connection.start();
+            assertNotNull("There should be messages waiting for the consumer", consumer.receive(getReceiveTimeout()));
+        }
+        finally
+        {
+            connection.close();
+        }
+    }
+
+    @Test
+    public void testMessageListenerCanReceiveMessageAfterConnectionStart() throws Exception
+    {
+
+        Queue queue = createQueue(getTestName());
+        Connection connection = getConnection();
+        try
+        {
+            Utils.sendMessages(connection, queue, 1);
+
+            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            MessageConsumer consumer = session.createConsumer(queue);
+
+            final CountDownLatch awaitMessage = new CountDownLatch(1);
+            final AtomicLong deliveryTime = new AtomicLong();
+            consumer.setMessageListener(message -> {
+                try
+                {
+                    deliveryTime.set(System.currentTimeMillis());
+                }
+                finally
+                {
+                    awaitMessage.countDown();
+                }
+            });
+
+            long beforeStartTime = System.currentTimeMillis();
+            connection.start();
+
+            assertTrue("Message is not received in timely manner", awaitMessage.await(getReceiveTimeout(), TimeUnit.MILLISECONDS));
+            assertTrue("Message received before connection start", deliveryTime.get() > beforeStartTime);
+        }
+        finally
+        {
+            connection.close();
+        }
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/f3047593/systests/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionStartTest.java
----------------------------------------------------------------------
diff --git a/systests/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionStartTest.java b/systests/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionStartTest.java
deleted file mode 100644
index 1a9df7f..0000000
--- a/systests/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionStartTest.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.test.unit.client.connection;
-
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-import javax.jms.Connection;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageListener;
-import javax.jms.MessageProducer;
-import javax.jms.Queue;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-
-import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.test.utils.QpidBrokerTestCase;
-
-public class ConnectionStartTest extends QpidBrokerTestCase
-{
-
-    private Connection _connection;
-    private Session _consumerSess;
-    private MessageConsumer _consumer;
-
-    @Override
-    public void setUp() throws Exception
-    {
-        super.setUp();
-
-        Connection pubCon = getConnection();
-
-        Session pubSess = pubCon.createSession(false, AMQSession.AUTO_ACKNOWLEDGE);
-        Queue queue = createTestQueue(pubSess);
-
-
-        MessageProducer pub = pubSess.createProducer(queue);
-
-        _connection = getConnection();
-
-        _consumerSess = _connection.createSession(false, AMQSession.AUTO_ACKNOWLEDGE);
-
-        _consumer = _consumerSess.createConsumer(queue);
-
-        //publish after queue is created to ensure it can be routed as expected
-        pub.send(pubSess.createTextMessage("Initial Message"));
-
-        pubCon.close();
-
-
-    }
-
-    @Override
-    public void tearDown() throws Exception
-    {
-        _connection.close();
-        super.tearDown();
-    }
-
-    public void testSimpleReceiveConnection()
-    {
-        try
-        {
-            assertNull("No messages should be delivered when the connection is stopped", _consumer.receive(500));
-            _connection.start();
-            assertTrue("There should be messages waiting for the consumer", _consumer.receive(getReceiveTimeout()) != null);
-
-        }
-        catch (JMSException e)
-        {
-            fail("An error occured during test because:" + e);
-        }
-
-    }
-
-    public void testMessageListenerConnection() throws Exception
-    {
-        final CountDownLatch _gotMessage = new CountDownLatch(1);
-
-        try
-        {
-            _consumer.setMessageListener(new MessageListener()
-            {
-                @Override
-                public void onMessage(Message message)
-                {
-                    try
-                    {
-                        assertEquals("Mesage Received", "Initial Message", ((TextMessage) message).getText());
-                        _gotMessage.countDown();
-                    }
-                    catch (JMSException e)
-                    {
-                        fail("Couldn't get message text because:" + e.getCause());
-                    }
-                }
-            });
-            Thread.sleep(500);
-            assertEquals("No messages should be delivered before connection start", 1L,_gotMessage.getCount());
-            _connection.start();
-
-            try
-            {
-                assertTrue("Listener was never called", _gotMessage.await(10 * 1000, TimeUnit.MILLISECONDS));
-            }
-            catch (InterruptedException e)
-            {
-                fail("Timed out awaiting message via onMessage");
-            }
-
-        }
-        catch (JMSException e)
-        {
-            fail("Failed because:" + e.getCause());
-        }
-
-    }
-
-
-    public static junit.framework.Test suite()
-    {
-        return new junit.framework.TestSuite(ConnectionStartTest.class);
-    }
-}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org