[ 
https://issues.apache.org/jira/browse/AMQ-8322?focusedWorklogId=766079&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-766079
 ]

ASF GitHub Bot logged work on AMQ-8322:
---------------------------------------

                Author: ASF GitHub Bot
            Created on: 04/May/22 15:10
            Start Date: 04/May/22 15:10
    Worklog Time Spent: 10m 
      Work Description: mattrpav commented on code in PR #729:
URL: https://github.com/apache/activemq/pull/729#discussion_r864958409


##########
activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2ContextTest.java:
##########
@@ -0,0 +1,302 @@
+/**
+ * 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.activemq.jms2;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.Enumeration;
+
+import javax.jms.CompletionListener;
+import javax.jms.Destination;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSException;
+import javax.jms.JMSProducer;
+import javax.jms.JMSRuntimeException;
+import javax.jms.QueueBrowser;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.apache.activemq.ActiveMQContext;
+import org.junit.Test;
+
+public class ActiveMQJMS2ContextTest extends ActiveMQJMS2TestBase {
+
+    @Test
+    public void testConnectionFactoryCreateContext() {
+        try(JMSContext jmsContext = activemqConnectionFactory.createContext()) 
{
+            assertNotNull(jmsContext);
+            jmsContext.start();
+            
assertTrue(ActiveMQContext.class.isAssignableFrom(jmsContext.getClass()));
+            sendMessage(jmsContext, methodNameDestinationName);
+            recvMessage(jmsContext, methodNameDestinationName, "Test-" + 
methodNameDestinationName);
+        } catch (JMSException e) {
+            fail(e.getMessage());
+        }
+    }
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testConnectionFactoryCreateContextSession() {
+        activemqConnectionFactory.createContext(Session.AUTO_ACKNOWLEDGE);
+    }
+
+    @Test
+    public void testConnectionFactoryCreateContextUserPass() {
+        try(JMSContext jmsContext = 
activemqConnectionFactory.createContext("admin", "admin")) {
+            assertNotNull(jmsContext);
+            jmsContext.start();
+            
assertTrue(ActiveMQContext.class.isAssignableFrom(jmsContext.getClass()));
+            sendMessage(jmsContext, methodNameDestinationName);
+            recvMessage(jmsContext, methodNameDestinationName, "Test-" + 
methodNameDestinationName);
+        } catch (JMSException e) {
+            fail(e.getMessage());
+        }
+    }
+
+    @Test
+    public void testConnectionFactoryCreateContextUserPassSession() {
+        try(JMSContext jmsContext = 
activemqConnectionFactory.createContext("admin", "admin", 
Session.AUTO_ACKNOWLEDGE)) {
+            assertNotNull(jmsContext);
+            
assertTrue(ActiveMQContext.class.isAssignableFrom(jmsContext.getClass()));
+        }
+    }
+
+    @Test
+    public void testConnectionFactoryCreateContexMultiContext() {
+        JMSContext secondJMSContext = null;
+        JMSContext thirdJMSContext = null;
+
+        try(JMSContext jmsContext = 
activemqConnectionFactory.createContext("admin", "admin")) {
+            assertNotNull(jmsContext);
+            jmsContext.start();
+            
assertTrue(ActiveMQContext.class.isAssignableFrom(jmsContext.getClass()));
+            sendMessage(jmsContext, methodNameDestinationName);
+            recvMessage(jmsContext, methodNameDestinationName, "Test-" + 
methodNameDestinationName);
+            
+            secondJMSContext = 
jmsContext.createContext(Session.AUTO_ACKNOWLEDGE);
+        } catch (JMSException e) {
+            fail(e.getMessage());
+        }
+
+        // First context closed
+        String secondTestDestinationName = methodNameDestinationName + 
".SECOND";
+        try {
+            sendMessage(secondJMSContext, secondTestDestinationName);
+            recvMessage(secondJMSContext, secondTestDestinationName, "Test-" + 
secondTestDestinationName);
+        } catch (JMSException e) {
+            fail(e.getMessage());
+        } finally {
+            if(secondJMSContext != null) {
+                try { secondJMSContext.close(); } catch (JMSRuntimeException 
e) { fail(e.getMessage()); }
+            }
+        }
+        
+        // Attempt to obtain a third context after all contexts have been 
closed
+        boolean caught = false;
+        try {
+            thirdJMSContext = 
secondJMSContext.createContext(Session.AUTO_ACKNOWLEDGE);
+            fail("JMSRuntimeException expected");
+        } catch (JMSRuntimeException e) {
+            caught = true;
+            assertEquals("Context already closed", e.getMessage());
+        }
+        assertTrue(caught);
+    }
+
+    @Test
+    public void testConnectionFactoryCreateContextBrowse() {
+        try(JMSContext jmsContext = activemqConnectionFactory.createContext()) 
{
+            assertNotNull(jmsContext);
+            jmsContext.start();
+            
assertTrue(ActiveMQContext.class.isAssignableFrom(jmsContext.getClass()));
+            sendMessage(jmsContext, methodNameDestinationName);
+            browseMessage(jmsContext, methodNameDestinationName, "Test-" + 
methodNameDestinationName, true);
+        } catch (JMSException e) {
+            fail(e.getMessage());
+        }
+    }
+
+    @Test
+    public void testConnectionFactoryCreateContextBrowseAutoStart() {
+        try(JMSContext jmsContext = activemqConnectionFactory.createContext()) 
{
+            assertNotNull(jmsContext);
+            
assertTrue(ActiveMQContext.class.isAssignableFrom(jmsContext.getClass()));
+            sendMessage(jmsContext, methodNameDestinationName);
+            browseMessage(jmsContext, methodNameDestinationName, "Test-" + 
methodNameDestinationName, true);
+        } catch (JMSException e) {
+            fail(e.getMessage());
+        }
+    }
+
+    @Test
+    public void testConnectionFactoryCreateContextBrowseAutoStartFalse() {
+        try(JMSContext jmsContext = activemqConnectionFactory.createContext()) 
{
+            assertNotNull(jmsContext);
+            jmsContext.setAutoStart(false);
+            
assertTrue(ActiveMQContext.class.isAssignableFrom(jmsContext.getClass()));
+            sendMessage(jmsContext, methodNameDestinationName);
+            browseMessage(jmsContext, methodNameDestinationName, "Test-" + 
methodNameDestinationName, false);
+        } catch (JMSException e) {
+            fail(e.getMessage());
+        }
+    }
+
+    @Test
+    public void 
testConnectionFactoryCreateContextBrowseAutoStartFalseStartDelayed() {
+        try(JMSContext jmsContext = activemqConnectionFactory.createContext()) 
{
+            assertNotNull(jmsContext);
+            jmsContext.setAutoStart(false);
+            
assertTrue(ActiveMQContext.class.isAssignableFrom(jmsContext.getClass()));
+            sendMessage(jmsContext, methodNameDestinationName);
+            jmsContext.start();
+            browseMessage(jmsContext, methodNameDestinationName, "Test-" + 
methodNameDestinationName, true);
+        } catch (JMSException e) {
+            fail(e.getMessage());
+        }
+    }
+
+    @Test
+    public void testDisableMessageID() {

Review Comment:
   This is done, unit tests have been added





Issue Time Tracking
-------------------

    Worklog Id:     (was: 766079)
    Time Spent: 12h  (was: 11h 50m)

> Implement JMS 2.0 Connection createContext methods
> --------------------------------------------------
>
>                 Key: AMQ-8322
>                 URL: https://issues.apache.org/jira/browse/AMQ-8322
>             Project: ActiveMQ
>          Issue Type: New Feature
>            Reporter: Matt Pavlovich
>            Assignee: Matt Pavlovich
>            Priority: Major
>              Labels: #jms2
>             Fix For: 5.18.0
>
>          Time Spent: 12h
>  Remaining Estimate: 0h
>
> Add support for JMSContext, JMSProducer and JMSConsumer for working with 
> queues



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to