You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@activemq.apache.org by GitBox <gi...@apache.org> on 2022/05/04 15:10:07 UTC
[GitHub] [activemq] mattrpav commented on a diff in pull request #729: [AMQ-8322] JMS 2.0 Implementation - First phase
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
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org