You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2017/12/20 21:06:36 UTC
[4/6] activemq-artemis git commit: ARTEMIS-1532 Enable tests which
are unintentionally skipped by Surefire
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/aa730fda/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/ra/OutgoingConnectionTestJTA.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/ra/OutgoingConnectionTestJTA.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/ra/OutgoingConnectionTestJTA.java
deleted file mode 100644
index ab32ad3..0000000
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/ra/OutgoingConnectionTestJTA.java
+++ /dev/null
@@ -1,256 +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.activemq.artemis.tests.integration.ra;
-
-import javax.jms.Connection;
-import javax.jms.JMSContext;
-import javax.jms.JMSException;
-import javax.jms.JMSProducer;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.Queue;
-import javax.jms.QueueConnection;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.activemq.artemis.api.core.client.ClientConsumer;
-import org.apache.activemq.artemis.api.core.client.ClientMessage;
-import org.apache.activemq.artemis.api.core.client.ClientSession;
-import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
-import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
-import org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory;
-import org.apache.activemq.artemis.core.security.Role;
-import org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory;
-import org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl;
-import org.apache.activemq.artemis.ra.ActiveMQRAConnectionManager;
-import org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory;
-import org.apache.activemq.artemis.ra.ActiveMQResourceAdapter;
-import org.apache.activemq.artemis.service.extensions.ServiceUtils;
-import org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-public class OutgoingConnectionTestJTA extends ActiveMQRATestBase {
-
- protected ActiveMQResourceAdapter resourceAdapter;
- protected ActiveMQRAConnectionFactory qraConnectionFactory;
- protected ActiveMQRAManagedConnectionFactory mcf;
- ActiveMQRAConnectionManager qraConnectionManager = new ActiveMQRAConnectionManager();
-
- @Override
- public boolean useSecurity() {
- return true;
- }
-
- @Override
- @Before
- public void setUp() throws Exception {
- useDummyTransactionManager();
- super.setUp();
- ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addUser("testuser", "testpassword");
- ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addUser("guest", "guest");
- ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().setDefaultUser("guest");
- ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addRole("testuser", "arole");
- ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addRole("guest", "arole");
- Role role = new Role("arole", true, true, true, true, true, true, true, true, true, true);
- Set<Role> roles = new HashSet<>();
- roles.add(role);
- server.getSecurityRepository().addMatch(MDBQUEUEPREFIXED, roles);
-
- resourceAdapter = new ActiveMQResourceAdapter();
- resourceAdapter.setEntries("[\"java://jmsXA\"]");
-
- resourceAdapter.setConnectorClassName(InVMConnectorFactory.class.getName());
- MyBootstrapContext ctx = new MyBootstrapContext();
- resourceAdapter.start(ctx);
- mcf = new ActiveMQRAManagedConnectionFactory();
- mcf.setResourceAdapter(resourceAdapter);
- qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
- }
-
- @Override
- @After
- public void tearDown() throws Exception {
- ((DummyTransactionManager) ServiceUtils.getTransactionManager()).tx = null;
- if (resourceAdapter != null) {
- resourceAdapter.stop();
- }
-
- qraConnectionManager.stop();
- super.tearDown();
- }
-
- @Test
- public void testSimpleMessageSendAndReceiveTransacted() throws Exception {
- setDummyTX();
- setupDLQ(10);
- resourceAdapter = newResourceAdapter();
- MyBootstrapContext ctx = new MyBootstrapContext();
- resourceAdapter.start(ctx);
- ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
- mcf.setResourceAdapter(resourceAdapter);
- ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
- QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
- Session s = queueConnection.createSession(true, Session.AUTO_ACKNOWLEDGE);
- Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
- MessageProducer mp = s.createProducer(q);
- MessageConsumer consumer = s.createConsumer(q);
- Message message = s.createTextMessage("test");
- mp.send(message);
- s.commit();
- queueConnection.start();
- TextMessage textMessage = (TextMessage) consumer.receive(1000);
- assertNotNull(textMessage);
- assertEquals(textMessage.getText(), "test");
- s.rollback();
- textMessage = (TextMessage) consumer.receive(1000);
- assertNotNull(textMessage);
- assertEquals(textMessage.getText(), "test");
- s.commit();
- }
-
- public void testQueuSessionAckMode(boolean inTx) throws Exception {
- if (inTx) {
- setDummyTX();
- }
- QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
-
- Session s = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- if (inTx) {
- assertEquals(Session.SESSION_TRANSACTED, s.getAcknowledgeMode());
- } else {
- assertEquals(Session.AUTO_ACKNOWLEDGE, s.getAcknowledgeMode());
- }
- s.close();
-
- s = queueConnection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
- if (inTx) {
- assertEquals(Session.SESSION_TRANSACTED, s.getAcknowledgeMode());
- } else {
- assertEquals(Session.DUPS_OK_ACKNOWLEDGE, s.getAcknowledgeMode());
- }
- s.close();
-
- //exception should be thrown if ack mode is SESSION_TRANSACTED or
- //CLIENT_ACKNOWLEDGE when in a JTA else ackmode should bee ignored
- try {
- s = queueConnection.createSession(false, Session.SESSION_TRANSACTED);
- if (inTx) {
- assertEquals(s.getAcknowledgeMode(), Session.SESSION_TRANSACTED);
- } else {
- fail("didn't get expected exception creating session with SESSION_TRANSACTED mode ");
- }
- s.close();
- } catch (JMSException e) {
- if (inTx) {
- fail("shouldn't throw exception " + e);
- }
- }
-
- try {
- s = queueConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
- if (inTx) {
- assertEquals(s.getAcknowledgeMode(), Session.SESSION_TRANSACTED);
- } else {
- fail("didn't get expected exception creating session with CLIENT_ACKNOWLEDGE mode");
- }
- } catch (JMSException e) {
- if (inTx) {
- fail("shouldn't throw exception " + e);
- }
- }
-
- }
-
- @Test
- public void testSimpleSendNoXAJMSContext() throws Exception {
- Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
-
- try (ClientSessionFactory sf = locator.createSessionFactory();
- ClientSession session = sf.createSession();
- ClientConsumer consVerify = session.createConsumer(MDBQUEUE);
- JMSContext jmsctx = qraConnectionFactory.createContext();
- ) {
- session.start();
- // These next 4 lines could be written in a single line however it makes difficult for debugging
- JMSProducer producer = jmsctx.createProducer();
- producer.setProperty("strvalue", "hello");
- TextMessage msgsend = jmsctx.createTextMessage("hello");
- producer.send(q, msgsend);
-
- ClientMessage msg = consVerify.receive(1000);
- assertNotNull(msg);
- assertEquals("hello", msg.getStringProperty("strvalue"));
- }
- }
-
- @Test
- public void testQueueSessionAckModeJTA() throws Exception {
- testQueuSessionAckMode(true);
- }
-
- @Test
- public void testSessionAckModeNoJTA() throws Exception {
- testQueuSessionAckMode(false);
- }
-
- @Test
- public void testSimpleMessageSendAndReceive() throws Exception {
- QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
- Session s = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
- MessageProducer mp = s.createProducer(q);
- MessageConsumer consumer = s.createConsumer(q);
- Message message = s.createTextMessage("test");
- mp.send(message);
- queueConnection.start();
- TextMessage textMessage = (TextMessage) consumer.receive(1000);
- assertNotNull(textMessage);
- assertEquals(textMessage.getText(), "test");
- }
-
- @Test
- public void testSimpleSendNoXAJMS1() throws Exception {
- Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
- try (ClientSessionFactory sf = locator.createSessionFactory();
- ClientSession session = sf.createSession();
- ClientConsumer consVerify = session.createConsumer(MDBQUEUE);
- Connection conn = qraConnectionFactory.createConnection();
- ) {
- Session jmsSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- session.start();
- MessageProducer producer = jmsSess.createProducer(q);
- // These next 4 lines could be written in a single line however it makes difficult for debugging
- TextMessage msgsend = jmsSess.createTextMessage("hello");
- msgsend.setStringProperty("strvalue", "hello");
- producer.send(msgsend);
-
- ClientMessage msg = consVerify.receive(1000);
- assertNotNull(msg);
- assertEquals("hello", msg.getStringProperty("strvalue"));
- }
- }
-
- private void setDummyTX() {
- ((DummyTransactionManager) ServiceUtils.getTransactionManager()).tx = new DummyTransaction();
- }
-}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/aa730fda/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/ra/OutgoingConnectionTestNoJTA.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/ra/OutgoingConnectionTestNoJTA.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/ra/OutgoingConnectionTestNoJTA.java
deleted file mode 100644
index 7b2ba8d..0000000
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/ra/OutgoingConnectionTestNoJTA.java
+++ /dev/null
@@ -1,271 +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.activemq.artemis.tests.integration.ra;
-
-import org.apache.activemq.artemis.api.core.client.ClientConsumer;
-import org.apache.activemq.artemis.api.core.client.ClientMessage;
-import org.apache.activemq.artemis.api.core.client.ClientSession;
-import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
-import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
-import org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory;
-import org.apache.activemq.artemis.core.security.Role;
-import org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory;
-import org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl;
-import org.apache.activemq.artemis.ra.ActiveMQRAConnectionManager;
-import org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory;
-import org.apache.activemq.artemis.ra.ActiveMQResourceAdapter;
-import org.apache.activemq.artemis.service.extensions.ServiceUtils;
-import org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import javax.jms.Connection;
-import javax.jms.JMSContext;
-import javax.jms.JMSProducer;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.Queue;
-import javax.jms.QueueConnection;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import java.util.HashSet;
-import java.util.Set;
-
-public class OutgoingConnectionTestNoJTA extends ActiveMQRATestBase {
-
- protected ActiveMQResourceAdapter resourceAdapter;
- protected ActiveMQRAConnectionFactory qraConnectionFactory;
- protected ActiveMQRAManagedConnectionFactory mcf;
- ActiveMQRAConnectionManager qraConnectionManager = new ActiveMQRAConnectionManager();
-
- @Override
- public boolean useSecurity() {
- return true;
- }
-
- @Override
- @Before
- public void setUp() throws Exception {
- useDummyTransactionManager();
- super.setUp();
- ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addUser("testuser", "testpassword");
- ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addUser("guest", "guest");
- ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().setDefaultUser("guest");
- ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addRole("testuser", "arole");
- ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addRole("guest", "arole");
- Role role = new Role("arole", true, true, true, true, true, true, true, true);
- Set<Role> roles = new HashSet<>();
- roles.add(role);
- server.getSecurityRepository().addMatch(MDBQUEUEPREFIXED, roles);
-
- resourceAdapter = new ActiveMQResourceAdapter();
- resourceAdapter.setEntries("[\"java://jmsXA\"]");
- resourceAdapter.setConnectorClassName(InVMConnectorFactory.class.getName());
- MyBootstrapContext ctx = new MyBootstrapContext();
- resourceAdapter.start(ctx);
- mcf = new ActiveMQRAManagedConnectionFactory();
- mcf.setAllowLocalTransactions(true);
- mcf.setResourceAdapter(resourceAdapter);
- qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
- }
-
- @Override
- @After
- public void tearDown() throws Exception {
- ((DummyTransactionManager) ServiceUtils.getTransactionManager()).tx = null;
- if (resourceAdapter != null) {
- resourceAdapter.stop();
- }
-
- qraConnectionManager.stop();
- super.tearDown();
- }
-
- @Test
- public void testSimpleMessageSendAndReceiveSessionTransacted() throws Exception {
- setupDLQ(10);
- resourceAdapter = newResourceAdapter();
- MyBootstrapContext ctx = new MyBootstrapContext();
- resourceAdapter.start(ctx);
- ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
- mcf.setAllowLocalTransactions(true);
- mcf.setResourceAdapter(resourceAdapter);
- ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
- QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
- Session s = queueConnection.createSession(true, Session.SESSION_TRANSACTED);
- Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
- MessageProducer mp = s.createProducer(q);
- MessageConsumer consumer = s.createConsumer(q);
- Message message = s.createTextMessage("test");
- mp.send(message);
- s.commit();
- queueConnection.start();
- TextMessage textMessage = (TextMessage) consumer.receive(1000);
- assertNotNull(textMessage);
- assertEquals(textMessage.getText(), "test");
- s.rollback();
- textMessage = (TextMessage) consumer.receive(1000);
- assertNotNull(textMessage);
- assertEquals(textMessage.getText(), "test");
- s.commit();
- textMessage = (TextMessage) consumer.receiveNoWait();
- assertNull(textMessage);
- }
-
- @Test
- public void testSimpleMessageSendAndReceiveNotTransacted() throws Exception {
- setupDLQ(10);
- resourceAdapter = newResourceAdapter();
- MyBootstrapContext ctx = new MyBootstrapContext();
- resourceAdapter.start(ctx);
- ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
- mcf.setAllowLocalTransactions(true);
- mcf.setResourceAdapter(resourceAdapter);
- ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
- QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
- Session s = queueConnection.createSession(false, Session.SESSION_TRANSACTED);
- Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
- MessageProducer mp = s.createProducer(q);
- MessageConsumer consumer = s.createConsumer(q);
- Message message = s.createTextMessage("test");
- mp.send(message);
- s.commit();
- queueConnection.start();
- TextMessage textMessage = (TextMessage) consumer.receive(1000);
- assertNotNull(textMessage);
- assertEquals(textMessage.getText(), "test");
- s.rollback();
- textMessage = (TextMessage) consumer.receive(1000);
- assertNotNull(textMessage);
- assertEquals(textMessage.getText(), "test");
- s.commit();
- textMessage = (TextMessage) consumer.receiveNoWait();
- assertNull(textMessage);
- }
-
- @Test
- public void testSimpleMessageSendAndReceiveSessionTransacted2() throws Exception {
- setupDLQ(10);
- resourceAdapter = newResourceAdapter();
- MyBootstrapContext ctx = new MyBootstrapContext();
- resourceAdapter.start(ctx);
- ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
- mcf.setAllowLocalTransactions(true);
- mcf.setResourceAdapter(resourceAdapter);
- ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
- QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
- Session s = queueConnection.createSession(Session.SESSION_TRANSACTED);
- Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
- MessageProducer mp = s.createProducer(q);
- MessageConsumer consumer = s.createConsumer(q);
- Message message = s.createTextMessage("test");
- mp.send(message);
- s.commit();
- queueConnection.start();
- TextMessage textMessage = (TextMessage) consumer.receive(1000);
- assertNotNull(textMessage);
- assertEquals(textMessage.getText(), "test");
- s.rollback();
- textMessage = (TextMessage) consumer.receive(1000);
- assertNotNull(textMessage);
- assertEquals(textMessage.getText(), "test");
- s.commit();
- textMessage = (TextMessage) consumer.receiveNoWait();
- assertNull(textMessage);
- }
-
- @Test
- public void sessionTransactedTestNoActiveJTATx() throws Exception {
- JMSContext context = qraConnectionFactory.createContext(JMSContext.SESSION_TRANSACTED);
- assertEquals(context.getSessionMode(), JMSContext.AUTO_ACKNOWLEDGE);
- }
-
-
- @Test
- public void testQueuSessionAckMode() throws Exception {
-
- QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
-
- Session s = queueConnection.createSession(false, Session.SESSION_TRANSACTED);
-
- s.close();
- }
-
-
-
- @Test
- public void testSimpleSendNoXAJMSContext() throws Exception {
- Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
-
- try (ClientSessionFactory sf = locator.createSessionFactory();
- ClientSession session = sf.createSession();
- ClientConsumer consVerify = session.createConsumer("jms.queue." + MDBQUEUE);
- JMSContext jmsctx = qraConnectionFactory.createContext();
- ) {
- session.start();
- // These next 4 lines could be written in a single line however it makes difficult for debugging
- JMSProducer producer = jmsctx.createProducer();
- producer.setProperty("strvalue", "hello");
- TextMessage msgsend = jmsctx.createTextMessage("hello");
- producer.send(q, msgsend);
-
- ClientMessage msg = consVerify.receive(1000);
- assertNotNull(msg);
- assertEquals("hello", msg.getStringProperty("strvalue"));
- }
- }
-
- @Test
- public void testSimpleMessageSendAndReceive() throws Exception {
- QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
- Session s = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
- MessageProducer mp = s.createProducer(q);
- MessageConsumer consumer = s.createConsumer(q);
- Message message = s.createTextMessage("test");
- mp.send(message);
- queueConnection.start();
- TextMessage textMessage = (TextMessage) consumer.receive(1000);
- assertNotNull(textMessage);
- assertEquals(textMessage.getText(), "test");
- }
-
- @Test
- public void testSimpleSendNoXAJMS1() throws Exception {
- Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
- try (ClientSessionFactory sf = locator.createSessionFactory();
- ClientSession session = sf.createSession();
- ClientConsumer consVerify = session.createConsumer("jms.queue." + MDBQUEUE);
- Connection conn = qraConnectionFactory.createConnection();
- ) {
- Session jmsSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- session.start();
- MessageProducer producer = jmsSess.createProducer(q);
- // These next 4 lines could be written in a single line however it makes difficult for debugging
- TextMessage msgsend = jmsSess.createTextMessage("hello");
- msgsend.setStringProperty("strvalue", "hello");
- producer.send(msgsend);
-
- ClientMessage msg = consVerify.receive(1000);
- assertNotNull(msg);
- assertEquals("hello", msg.getStringProperty("strvalue"));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/aa730fda/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompPropertiesInterceptorTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompPropertiesInterceptorTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompPropertiesInterceptorTest.java
new file mode 100644
index 0000000..f5656f5
--- /dev/null
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompPropertiesInterceptorTest.java
@@ -0,0 +1,108 @@
+/*
+ * 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.artemis.tests.integration.stomp;
+
+import org.apache.activemq.artemis.core.protocol.stomp.StompFrame;
+import org.apache.activemq.artemis.core.protocol.stomp.StompFrameInterceptor;
+import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
+import org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame;
+import org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection;
+import org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnectionFactory;
+import org.apache.felix.resolver.util.ArrayMap;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+@RunWith(value = Parameterized.class)
+public class StompPropertiesInterceptorTest extends StompTestBase {
+
+ @Parameterized.Parameters(name = "{0}")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][]{{"ws+v12.stomp"}, {"tcp+v12.stomp"}});
+ }
+
+ @Override
+ public List<String> getIncomingInterceptors() {
+ List<String> stompIncomingInterceptor = new ArrayList<>();
+ stompIncomingInterceptor.add("org.apache.activemq.artemis.tests.integration.stomp.StompPropertiesInterceptorTest$StompFramePropertiesInterceptor");
+ return stompIncomingInterceptor;
+ }
+
+ @Override
+ public List<String> getOutgoingInterceptors() {
+ List<String> stompOutgoingInterceptor = new ArrayList<>();
+ stompOutgoingInterceptor.add("org.apache.activemq.artemis.tests.integration.stomp.StompPropertiesInterceptorTest$StompFramePropertiesInterceptor");
+
+ return stompOutgoingInterceptor;
+ }
+
+ public static class StompFramePropertiesInterceptor implements StompFrameInterceptor {
+
+ @Override
+ public boolean intercept(StompFrame stompFrame, RemotingConnection connection) {
+ if (stompFrame.getCommand().equals("CONNECT") || stompFrame.getCommand().equals("CONNECTED")) {
+ return true;
+ }
+ System.out.println("Checking properties in interceptor");
+ assertNotNull(stompFrame);
+ assertEquals(stompFrame.getHeader(MY_HEADER), expectedProperties.get(MY_HEADER));
+ assertEquals(stompFrame.getBody(), expectedProperties.get(MESSAGE_TEXT));
+ return true;
+ }
+ }
+
+
+ private static final String MESSAGE_TEXT = "messageText";
+ private static final String MY_HEADER = "my-header";
+ private static Map<String, Object> expectedProperties = new ArrayMap<>();
+
+ @Test(timeout = 60000)
+ public void testCheckInterceptedStompMessageProperties() throws Exception {
+ final String msgText = "Test intercepted message";
+ final String myHeader = "TestInterceptedHeader";
+ expectedProperties.put(MESSAGE_TEXT, msgText);
+ expectedProperties.put(MY_HEADER, myHeader);
+
+ StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
+ conn.connect(defUser, defPass);
+
+ ClientStompFrame subFrame = conn.createFrame("SUBSCRIBE");
+
+ subFrame.addHeader("subscription-type", "ANYCAST");
+ subFrame.addHeader("destination", name.getMethodName());
+ subFrame.addHeader("ack", "auto");
+ subFrame.addHeader(MY_HEADER, myHeader);
+ subFrame.setBody(msgText);
+
+ conn.sendFrame(subFrame);
+
+ ClientStompFrame frame = conn.createFrame("SEND");
+ frame.addHeader("destination", name.getMethodName());
+ frame.addHeader("ack", "auto");
+ frame.addHeader(MY_HEADER, myHeader);
+ conn.sendFrame(frame);
+
+ conn.disconnect();
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/aa730fda/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTestPropertiesInterceptor.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTestPropertiesInterceptor.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTestPropertiesInterceptor.java
deleted file mode 100644
index 62fa1b5..0000000
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTestPropertiesInterceptor.java
+++ /dev/null
@@ -1,108 +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.activemq.artemis.tests.integration.stomp;
-
-import org.apache.activemq.artemis.core.protocol.stomp.StompFrame;
-import org.apache.activemq.artemis.core.protocol.stomp.StompFrameInterceptor;
-import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
-import org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame;
-import org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection;
-import org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnectionFactory;
-import org.apache.felix.resolver.util.ArrayMap;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-@RunWith(value = Parameterized.class)
-public class StompTestPropertiesInterceptor extends StompTestBase {
-
- @Parameterized.Parameters(name = "{0}")
- public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][]{{"ws+v12.stomp"}, {"tcp+v12.stomp"}});
- }
-
- @Override
- public List<String> getIncomingInterceptors() {
- List<String> stompIncomingInterceptor = new ArrayList<>();
- stompIncomingInterceptor.add("org.apache.activemq.artemis.tests.integration.stomp.StompTestPropertiesInterceptor$StompFramePropertiesInterceptor");
- return stompIncomingInterceptor;
- }
-
- @Override
- public List<String> getOutgoingInterceptors() {
- List<String> stompOutgoingInterceptor = new ArrayList<>();
- stompOutgoingInterceptor.add("org.apache.activemq.artemis.tests.integration.stomp.StompTestPropertiesInterceptor$StompFramePropertiesInterceptor");
-
- return stompOutgoingInterceptor;
- }
-
- public static class StompFramePropertiesInterceptor implements StompFrameInterceptor {
-
- @Override
- public boolean intercept(StompFrame stompFrame, RemotingConnection connection) {
- if (stompFrame.getCommand().equals("CONNECT") || stompFrame.getCommand().equals("CONNECTED")) {
- return true;
- }
- System.out.println("Checking properties in interceptor");
- assertNotNull(stompFrame);
- assertEquals(stompFrame.getHeader(MY_HEADER), expectedProperties.get(MY_HEADER));
- assertEquals(stompFrame.getBody(), expectedProperties.get(MESSAGE_TEXT));
- return true;
- }
- }
-
-
- private static final String MESSAGE_TEXT = "messageText";
- private static final String MY_HEADER = "my-header";
- private static Map<String, Object> expectedProperties = new ArrayMap<>();
-
- @Test(timeout = 60000)
- public void testCheckInterceptedStompMessageProperties() throws Exception {
- final String msgText = "Test intercepted message";
- final String myHeader = "TestInterceptedHeader";
- expectedProperties.put(MESSAGE_TEXT, msgText);
- expectedProperties.put(MY_HEADER, myHeader);
-
- StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
- conn.connect(defUser, defPass);
-
- ClientStompFrame subFrame = conn.createFrame("SUBSCRIBE");
-
- subFrame.addHeader("subscription-type", "ANYCAST");
- subFrame.addHeader("destination", name.getMethodName());
- subFrame.addHeader("ack", "auto");
- subFrame.addHeader(MY_HEADER, myHeader);
- subFrame.setBody(msgText);
-
- conn.sendFrame(subFrame);
-
- ClientStompFrame frame = conn.createFrame("SEND");
- frame.addHeader("destination", name.getMethodName());
- frame.addHeader("ack", "auto");
- frame.addHeader(MY_HEADER, myHeader);
- conn.sendFrame(frame);
-
- conn.disconnect();
-
- }
-}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/aa730fda/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTestWithInterceptors.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTestWithInterceptors.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTestWithInterceptors.java
deleted file mode 100644
index b4e2217..0000000
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTestWithInterceptors.java
+++ /dev/null
@@ -1,166 +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.activemq.artemis.tests.integration.stomp;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.activemq.artemis.api.core.Interceptor;
-import org.apache.activemq.artemis.core.protocol.core.Packet;
-import org.apache.activemq.artemis.core.protocol.stomp.StompFrame;
-import org.apache.activemq.artemis.core.protocol.stomp.StompFrameInterceptor;
-import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
-import org.apache.activemq.artemis.tests.integration.IntegrationTestLogger;
-import org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame;
-import org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection;
-import org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnectionFactory;
-import org.apache.activemq.artemis.tests.util.Wait;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class StompTestWithInterceptors extends StompTestBase {
-
- @Override
- public List<String> getIncomingInterceptors() {
- List<String> stompIncomingInterceptor = new ArrayList<>();
- stompIncomingInterceptor.add("org.apache.activemq.artemis.tests.integration.stomp.StompTestWithInterceptors$MyIncomingStompFrameInterceptor");
- stompIncomingInterceptor.add("org.apache.activemq.artemis.tests.integration.stomp.StompTestWithInterceptors$MyCoreInterceptor");
-
- return stompIncomingInterceptor;
- }
-
- @Override
- public List<String> getOutgoingInterceptors() {
- List<String> stompOutgoingInterceptor = new ArrayList<>();
- stompOutgoingInterceptor.add("org.apache.activemq.artemis.tests.integration.stomp.StompTestWithInterceptors$MyOutgoingStompFrameInterceptor");
-
- return stompOutgoingInterceptor;
- }
-
- @Test
- public void stompFrameInterceptor() throws Exception {
- MyIncomingStompFrameInterceptor.incomingInterceptedFrames.clear();
- MyOutgoingStompFrameInterceptor.outgoingInterceptedFrames.clear();
-
- Thread.sleep(200);
-
- // So we clear them here
- MyCoreInterceptor.incomingInterceptedFrames.clear();
-
- StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
- conn.connect(defUser, defPass);
-
- ClientStompFrame subFrame = conn.createFrame("SUBSCRIBE");
- subFrame.addHeader("subscription-type", "ANYCAST");
- subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
- subFrame.addHeader("ack", "auto");
- conn.sendFrame(subFrame);
-
- assertEquals(0, MyCoreInterceptor.incomingInterceptedFrames.size());
- sendJmsMessage(getName());
-
- // Something was supposed to be called on sendMessages
- assertTrue("core interceptor is not working", MyCoreInterceptor.incomingInterceptedFrames.size() > 0);
-
- conn.receiveFrame(10000);
-
- ClientStompFrame frame = conn.createFrame("SEND");
- frame.addHeader("destination", getQueuePrefix() + getQueueName());
- frame.setBody("Hello World");
- conn.sendFrame(frame);
-
- conn.disconnect();
-
- List<String> incomingCommands = new ArrayList<>(4);
- incomingCommands.add("CONNECT");
- incomingCommands.add("SUBSCRIBE");
- incomingCommands.add("SEND");
- incomingCommands.add("DISCONNECT");
-
- List<String> outgoingCommands = new ArrayList<>(3);
- outgoingCommands.add("CONNECTED");
- outgoingCommands.add("MESSAGE");
- outgoingCommands.add("MESSAGE");
-
- long timeout = System.currentTimeMillis() + 1000;
-
- // Things are async, giving some time to things arrive before we actually assert
- while (MyIncomingStompFrameInterceptor.incomingInterceptedFrames.size() < 4 &&
- MyOutgoingStompFrameInterceptor.outgoingInterceptedFrames.size() < 3 &&
- timeout > System.currentTimeMillis()) {
- Thread.sleep(10);
- }
-
- Wait.waitFor(() -> {
- return MyIncomingStompFrameInterceptor.incomingInterceptedFrames.size() == 4;
- });
- Assert.assertEquals(4, MyIncomingStompFrameInterceptor.incomingInterceptedFrames.size());
- Wait.waitFor(() -> {
- return MyOutgoingStompFrameInterceptor.outgoingInterceptedFrames.size() == 3;
- });
- Assert.assertEquals(3, MyOutgoingStompFrameInterceptor.outgoingInterceptedFrames.size());
-
- for (int i = 0; i < MyIncomingStompFrameInterceptor.incomingInterceptedFrames.size(); i++) {
- Assert.assertEquals(incomingCommands.get(i), MyIncomingStompFrameInterceptor.incomingInterceptedFrames.get(i).getCommand());
- Assert.assertEquals("incomingInterceptedVal", MyIncomingStompFrameInterceptor.incomingInterceptedFrames.get(i).getHeader("incomingInterceptedProp"));
- }
-
- for (int i = 0; i < MyOutgoingStompFrameInterceptor.outgoingInterceptedFrames.size(); i++) {
- Assert.assertEquals(outgoingCommands.get(i), MyOutgoingStompFrameInterceptor.outgoingInterceptedFrames.get(i).getCommand());
- }
-
- Assert.assertEquals("incomingInterceptedVal", MyOutgoingStompFrameInterceptor.outgoingInterceptedFrames.get(2).getHeader("incomingInterceptedProp"));
- Assert.assertEquals("outgoingInterceptedVal", MyOutgoingStompFrameInterceptor.outgoingInterceptedFrames.get(2).getHeader("outgoingInterceptedProp"));
- }
-
- public static class MyCoreInterceptor implements Interceptor {
-
- static List<Packet> incomingInterceptedFrames = new ArrayList<>();
-
- @Override
- public boolean intercept(Packet packet, RemotingConnection connection) {
- IntegrationTestLogger.LOGGER.info("Core intercepted: " + packet);
- incomingInterceptedFrames.add(packet);
- return true;
- }
- }
-
- public static class MyIncomingStompFrameInterceptor implements StompFrameInterceptor {
-
- static List<StompFrame> incomingInterceptedFrames = new ArrayList<>();
-
- @Override
- public boolean intercept(StompFrame stompFrame, RemotingConnection connection) {
- incomingInterceptedFrames.add(stompFrame);
- stompFrame.addHeader("incomingInterceptedProp", "incomingInterceptedVal");
- return true;
- }
- }
-
- public static class MyOutgoingStompFrameInterceptor implements StompFrameInterceptor {
-
- static List<StompFrame> outgoingInterceptedFrames = new ArrayList<>();
-
- @Override
- public boolean intercept(StompFrame stompFrame, RemotingConnection connection) {
- outgoingInterceptedFrames.add(stompFrame);
- stompFrame.addHeader("outgoingInterceptedProp", "outgoingInterceptedVal");
- return true;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/aa730fda/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTestWithLargeMessages.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTestWithLargeMessages.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTestWithLargeMessages.java
deleted file mode 100644
index 89eefdc..0000000
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTestWithLargeMessages.java
+++ /dev/null
@@ -1,466 +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.activemq.artemis.tests.integration.stomp;
-
-import java.util.Arrays;
-import java.util.Collection;
-
-import org.apache.activemq.artemis.api.core.RoutingType;
-import org.apache.activemq.artemis.api.core.SimpleString;
-import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
-import org.apache.activemq.artemis.core.protocol.stomp.Stomp;
-import org.apache.activemq.artemis.tests.integration.largemessage.LargeMessageTestBase;
-import org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame;
-import org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection;
-import org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnectionFactory;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-@RunWith(Parameterized.class)
-@Ignore
-public class StompTestWithLargeMessages extends StompTestBase {
-
- // Web Socket has max frame size of 64kb. Large message tests only available over TCP.
- @Parameterized.Parameters(name = "{0}")
- public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][]{{"tcp+v10.stomp"}, {"tcp+v12.stomp"}});
- }
-
- @Override
- @Before
- public void setUp() throws Exception {
- super.setUp();
- }
-
- @Override
- public boolean isCompressLargeMessages() {
- return true;
- }
-
- @Override
- public boolean isPersistenceEnabled() {
- return true;
- }
-
- @Override
- public Integer getStompMinLargeMessageSize() {
- return 2048;
- }
-
- @Test
- public void testSendReceiveLargeMessage() throws Exception {
- StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
-
- String address = "testLargeMessageAddress";
- server.getActiveMQServer().createQueue(SimpleString.toSimpleString(address), RoutingType.ANYCAST, SimpleString.toSimpleString(address), null, true, false);
-
- // STOMP default is UTF-8 == 1 byte per char.
- int largeMessageStringSize = 10 * 1024 * 1024; // 10MB
- StringBuilder b = new StringBuilder(largeMessageStringSize);
- for (int i = 0; i < largeMessageStringSize; i++) {
- b.append('t');
- }
- String payload = b.toString();
-
- // Set up STOMP subscription
- conn.connect(defUser, defPass);
- subscribe(conn, null, Stomp.Headers.Subscribe.AckModeValues.AUTO, null, null, address, true);
-
- // Send Large Message
- System.out.println("Sending Message Size: " + largeMessageStringSize);
- send(conn, address, null, payload);
-
- // Receive STOMP Message
- ClientStompFrame frame = conn.receiveFrame();
- System.out.println(frame.getBody().length());
- assertTrue(frame.getBody().equals(payload));
- }
-
- //stomp sender -> large -> stomp receiver
- @Test
- public void testSendReceiveLargePersistentMessages() throws Exception {
- StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
- conn.connect(defUser, defPass);
-
- int count = 10;
- int msgSize = 1024 * 1024;
- char[] contents = new char[msgSize];
- for (int i = 0; i < msgSize; i++) {
- contents[i] = 'A';
- }
- String body = new String(contents);
-
- for (int i = 0; i < count; i++) {
- ClientStompFrame frame = conn.createFrame("SEND");
- frame.addHeader("destination", getQueuePrefix() + getQueueName());
- frame.addHeader("persistent", "true");
- frame.setBody(body);
- conn.sendFrame(frame);
- }
-
- ClientStompFrame subFrame = conn.createFrame("SUBSCRIBE");
- subFrame.addHeader("subscription-type", "ANYCAST");
- subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
- subFrame.addHeader("ack", "auto");
- conn.sendFrame(subFrame);
-
- for (int i = 0; i < count; i++) {
- ClientStompFrame frame = conn.receiveFrame(60000);
- Assert.assertNotNull(frame);
- System.out.println("part of frame: " + frame.getBody().substring(0, 200));
- Assert.assertTrue(frame.getCommand().equals("MESSAGE"));
- Assert.assertTrue(frame.getHeader("destination").equals(getQueuePrefix() + getQueueName()));
- int index = frame.getBody().indexOf("AAAA");
- assertEquals(msgSize, (frame.getBody().length() - index));
- }
-
- ClientStompFrame unsubFrame = conn.createFrame("UNSUBSCRIBE");
- unsubFrame.addHeader("destination", getQueuePrefix() + getQueueName());
- unsubFrame.addHeader("receipt", "567");
- ClientStompFrame response = conn.sendFrame(unsubFrame);
- assertNotNull(response);
- assertNotNull(response.getCommand().equals("RECEIPT"));
-
- conn.disconnect();
- }
-
- //core sender -> large -> stomp receiver
- @Test
- public void testReceiveLargePersistentMessagesFromCore() throws Exception {
- StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
- conn.connect(defUser, defPass);
-
- int msgSize = 3 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE;
- char[] contents = new char[msgSize];
- for (int i = 0; i < msgSize; i++) {
- contents[i] = 'B';
- }
- String msg = new String(contents);
-
- int count = 10;
- for (int i = 0; i < count; i++) {
- this.sendJmsMessage(msg);
- }
-
- ClientStompFrame subFrame = conn.createFrame("SUBSCRIBE");
- subFrame.addHeader("subscription-type", "ANYCAST");
- subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
- subFrame.addHeader("ack", "auto");
- conn.sendFrame(subFrame);
-
- for (int i = 0; i < count; i++) {
- ClientStompFrame frame = conn.receiveFrame(60000);
- Assert.assertNotNull(frame);
- System.out.println("part of frame: " + frame.getBody().substring(0, 200));
- Assert.assertTrue(frame.getCommand().equals("MESSAGE"));
- Assert.assertTrue(frame.getHeader("destination").equals(getQueuePrefix() + getQueueName()));
- int index = frame.getBody().indexOf("BBB");
- assertEquals(msgSize, (frame.getBody().length() - index));
- }
-
- ClientStompFrame unsubFrame = conn.createFrame("UNSUBSCRIBE");
- unsubFrame.addHeader("destination", getQueuePrefix() + getQueueName());
- unsubFrame.addHeader("receipt", "567");
- ClientStompFrame response = conn.sendFrame(unsubFrame);
- assertNotNull(response);
- assertNotNull(response.getCommand().equals("RECEIPT"));
-
- conn.disconnect();
- }
-
-// //stomp v12 sender -> large -> stomp v12 receiver
-// @Test
-// public void testSendReceiveLargePersistentMessagesV12() throws Exception {
-// StompClientConnection connV12 = StompClientConnectionFactory.createClientConnection("1.2", "localhost", port);
-// connV12.connect(defUser, defPass);
-//
-// int count = 10;
-// int szBody = 1024 * 1024;
-// char[] contents = new char[szBody];
-// for (int i = 0; i < szBody; i++) {
-// contents[i] = 'A';
-// }
-// String body = new String(contents);
-//
-// ClientStompFrame frame = connV12.createFrame("SEND");
-// frame.addHeader("destination-type", "ANYCAST");
-// frame.addHeader("destination", getQueuePrefix() + getQueueName());
-// frame.addHeader("persistent", "true");
-// frame.setBody(body);
-//
-// for (int i = 0; i < count; i++) {
-// connV12.sendFrame(frame);
-// }
-//
-// ClientStompFrame subFrame = connV12.createFrame("SUBSCRIBE");
-// subFrame.addHeader("id", "a-sub");
-// subFrame.addHeader("subscription-type", "ANYCAST");
-// subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
-// subFrame.addHeader("ack", "auto");
-//
-// connV12.sendFrame(subFrame);
-//
-// for (int i = 0; i < count; i++) {
-// ClientStompFrame receiveFrame = connV12.receiveFrame(30000);
-//
-// Assert.assertNotNull(receiveFrame);
-// System.out.println("part of frame: " + receiveFrame.getBody().substring(0, 20));
-// Assert.assertTrue(receiveFrame.getCommand().equals("MESSAGE"));
-// Assert.assertEquals(receiveFrame.getHeader("destination"), getQueuePrefix() + getQueueName());
-// assertEquals(szBody, receiveFrame.getBody().length());
-// }
-//
-// // remove susbcription
-// ClientStompFrame unsubFrame = connV12.createFrame("UNSUBSCRIBE");
-// unsubFrame.addHeader("id", "a-sub");
-// connV12.sendFrame(unsubFrame);
-//
-// connV12.disconnect();
-// }
-//
-// //core sender -> large -> stomp v12 receiver
-// @Test
-// public void testReceiveLargePersistentMessagesFromCoreV12() throws Exception {
-// int msgSize = 3 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE;
-// char[] contents = new char[msgSize];
-// for (int i = 0; i < msgSize; i++) {
-// contents[i] = 'B';
-// }
-// String msg = new String(contents);
-//
-// int count = 10;
-// for (int i = 0; i < count; i++) {
-// this.sendJmsMessage(msg);
-// }
-//
-// StompClientConnection connV12 = StompClientConnectionFactory.createClientConnection("1.2", "localhost", port);
-// connV12.connect(defUser, defPass);
-//
-// ClientStompFrame subFrame = connV12.createFrame("SUBSCRIBE");
-// subFrame.addHeader("id", "a-sub");
-// subFrame.addHeader("subscription-type", "ANYCAST");
-// subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
-// subFrame.addHeader("ack", "auto");
-// connV12.sendFrame(subFrame);
-//
-// for (int i = 0; i < count; i++) {
-// ClientStompFrame receiveFrame = connV12.receiveFrame(30000);
-//
-// Assert.assertNotNull(receiveFrame);
-// System.out.println("part of frame: " + receiveFrame.getBody().substring(0, 20));
-// Assert.assertTrue(receiveFrame.getCommand().equals("MESSAGE"));
-// Assert.assertEquals(receiveFrame.getHeader("destination"), getQueuePrefix() + getQueueName());
-// assertEquals(msgSize, receiveFrame.getBody().length());
-// }
-//
-// // remove susbcription
-// ClientStompFrame unsubFrame = connV12.createFrame("UNSUBSCRIBE");
-// unsubFrame.addHeader("id", "a-sub");
-// connV12.sendFrame(unsubFrame);
-//
-// connV12.disconnect();
-// }
-
- //core sender -> large (compressed regular) -> stomp v10 receiver
- @Test
- public void testReceiveLargeCompressedToRegularPersistentMessagesFromCore() throws Exception {
- StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
- conn.connect(defUser, defPass);
-
- LargeMessageTestBase.TestLargeMessageInputStream input = new LargeMessageTestBase.TestLargeMessageInputStream(ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, true);
- LargeMessageTestBase.adjustLargeCompression(true, input, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
-
- char[] contents = input.toArray();
- String msg = new String(contents);
-
- String leadingPart = msg.substring(0, 100);
-
- int count = 10;
- for (int i = 0; i < count; i++) {
- this.sendJmsMessage(msg);
- }
-
- ClientStompFrame subFrame = conn.createFrame("SUBSCRIBE");
- subFrame.addHeader("subscription-type", "ANYCAST");
- subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
- subFrame.addHeader("ack", "auto");
- conn.sendFrame(subFrame);
-
- for (int i = 0; i < count; i++) {
- ClientStompFrame receiveFrame = conn.receiveFrame(30000);
- Assert.assertNotNull(receiveFrame);
- System.out.println("part of frame: " + receiveFrame.getBody().substring(0, 250));
- Assert.assertTrue(receiveFrame.getCommand().equals("MESSAGE"));
- Assert.assertEquals(receiveFrame.getHeader("destination"), getQueuePrefix() + getQueueName());
- int index = receiveFrame.getBody().indexOf(leadingPart);
- assertEquals(msg.length(), (receiveFrame.getBody().length() - index));
- }
-
- // remove suscription
- ClientStompFrame unsubFrame = conn.createFrame("UNSUBSCRIBE");
- unsubFrame.addHeader("destination", getQueuePrefix() + getQueueName());
- unsubFrame.addHeader("receipt", "567");
- ClientStompFrame response = conn.sendFrame(unsubFrame);
- assertNotNull(response);
- assertNotNull(response.getCommand().equals("RECEIPT"));
-
- conn.disconnect();
- }
-
-// //core sender -> large (compressed regular) -> stomp v12 receiver
-// @Test
-// public void testReceiveLargeCompressedToRegularPersistentMessagesFromCoreV12() throws Exception {
-// LargeMessageTestBase.TestLargeMessageInputStream input = new LargeMessageTestBase.TestLargeMessageInputStream(ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, true);
-// LargeMessageTestBase.adjustLargeCompression(true, input, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
-//
-// char[] contents = input.toArray();
-// String msg = new String(contents);
-//
-// int count = 10;
-// for (int i = 0; i < count; i++) {
-// this.sendJmsMessage(msg);
-// }
-//
-// StompClientConnection connV12 = StompClientConnectionFactory.createClientConnection("1.2", "localhost", port);
-// connV12.connect(defUser, defPass);
-//
-// ClientStompFrame subFrame = connV12.createFrame("SUBSCRIBE");
-// subFrame.addHeader("id", "a-sub");
-// subFrame.addHeader("subscription-type", "ANYCAST");
-// subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
-// subFrame.addHeader("ack", "auto");
-//
-// connV12.sendFrame(subFrame);
-//
-// for (int i = 0; i < count; i++) {
-// ClientStompFrame receiveFrame = connV12.receiveFrame(30000);
-//
-// Assert.assertNotNull(receiveFrame);
-// System.out.println("part of frame: " + receiveFrame.getBody().substring(0, 20));
-// Assert.assertTrue(receiveFrame.getCommand().equals("MESSAGE"));
-// Assert.assertEquals(receiveFrame.getHeader("destination"), getQueuePrefix() + getQueueName());
-// assertEquals(contents.length, receiveFrame.getBody().length());
-// }
-//
-// // remove susbcription
-// ClientStompFrame unsubFrame = connV12.createFrame("UNSUBSCRIBE");
-// unsubFrame.addHeader("id", "a-sub");
-// connV12.sendFrame(unsubFrame);
-//
-// connV12.disconnect();
-// }
-//
-// //core sender -> large (compressed large) -> stomp v12 receiver
-// @Test
-// public void testReceiveLargeCompressedToLargePersistentMessagesFromCoreV12() throws Exception {
-// LargeMessageTestBase.TestLargeMessageInputStream input = new LargeMessageTestBase.TestLargeMessageInputStream(ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, true);
-// input.setSize(10 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
-// LargeMessageTestBase.adjustLargeCompression(false, input, 10 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
-//
-// char[] contents = input.toArray();
-// String msg = new String(contents);
-//
-// int count = 10;
-// for (int i = 0; i < count; i++) {
-// this.sendJmsMessage(msg);
-// }
-//
-// IntegrationTestLogger.LOGGER.info("Message count for " + getQueueName() + ": " + server.getActiveMQServer().locateQueue(SimpleString.toSimpleString(getQueueName())).getMessageCount());
-//
-// StompClientConnection connV12 = StompClientConnectionFactory.createClientConnection("1.2", hostname, port);
-// connV12.connect(defUser, defPass);
-//
-// ClientStompFrame subFrame = connV12.createFrame("SUBSCRIBE");
-// subFrame.addHeader("id", "a-sub");
-// subFrame.addHeader("subscription-type", "ANYCAST");
-// subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
-// subFrame.addHeader("ack", "auto");
-//
-// connV12.sendFrame(subFrame);
-//
-// for (int i = 0; i < count; i++) {
-// ClientStompFrame receiveFrame = connV12.receiveFrame(30000);
-//
-// Assert.assertNotNull(receiveFrame);
-// System.out.println("part of frame: " + receiveFrame.getBody().substring(0, 20));
-// Assert.assertTrue(receiveFrame.getCommand().equals("MESSAGE"));
-// Assert.assertEquals(receiveFrame.getHeader("destination"), getQueuePrefix() + getQueueName());
-// assertEquals(contents.length, receiveFrame.getBody().length());
-// }
-//
-// // remove susbcription
-// ClientStompFrame unsubFrame = connV12.createFrame("UNSUBSCRIBE");
-// unsubFrame.addHeader("id", "a-sub");
-// connV12.sendFrame(unsubFrame);
-//
-// connV12.disconnect();
-// }
-
- //core sender -> large (compressed large) -> stomp v10 receiver
- @Test
- public void testReceiveLargeCompressedToLargePersistentMessagesFromCore() throws Exception {
-
- StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
- try {
- LargeMessageTestBase.TestLargeMessageInputStream input = new LargeMessageTestBase.TestLargeMessageInputStream(ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, true);
- input.setSize(10 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
- LargeMessageTestBase.adjustLargeCompression(false, input, 10 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
-
- char[] contents = input.toArray();
- String msg = new String(contents);
-
- String leadingPart = msg.substring(0, 100);
-
- int count = 10;
- for (int i = 0; i < count; i++) {
- this.sendJmsMessage(msg);
- }
-
- conn.connect(defUser, defPass);
-
- ClientStompFrame subFrame = conn.createFrame("SUBSCRIBE");
- subFrame.addHeader("subscription-type", "ANYCAST");
- subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
- subFrame.addHeader("ack", "auto");
- conn.sendFrame(subFrame);
-
- for (int i = 0; i < count; i++) {
- ClientStompFrame frame = conn.receiveFrame(60000);
- Assert.assertNotNull(frame);
- System.out.println(frame.toString());
- System.out.println("part of frame: " + frame.getBody().substring(0, 250));
- Assert.assertTrue(frame.getCommand().equals("MESSAGE"));
- Assert.assertTrue(frame.getHeader("destination").equals(getQueuePrefix() + getQueueName()));
- int index = frame.getBody().toString().indexOf(leadingPart);
- assertEquals(msg.length(), (frame.getBody().toString().length() - index));
- }
-
- ClientStompFrame unsubFrame = conn.createFrame("UNSUBSCRIBE");
- unsubFrame.addHeader("destination", getQueuePrefix() + getQueueName());
- unsubFrame.addHeader("receipt", "567");
- conn.sendFrame(unsubFrame);
- } finally {
- conn.disconnect();
- conn.closeTransport();
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/aa730fda/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTestWithMessageID.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTestWithMessageID.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTestWithMessageID.java
deleted file mode 100644
index a82df0d..0000000
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTestWithMessageID.java
+++ /dev/null
@@ -1,80 +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.activemq.artemis.tests.integration.stomp;
-
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.QueueBrowser;
-import javax.jms.TextMessage;
-import java.util.Enumeration;
-
-import org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame;
-import org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection;
-import org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnectionFactory;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class StompTestWithMessageID extends StompTestBase {
-
- @Override
- public boolean isEnableStompMessageId() {
- return true;
- }
-
- @Test
- public void testEnableMessageID() throws Exception {
- StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
- conn.connect(defUser, defPass);
-
- ClientStompFrame frame = conn.createFrame("SEND");
- frame.addHeader("destination", getQueuePrefix() + getQueueName());
- frame.setBody("Hello World 1");
- conn.sendFrame(frame);
-
- frame = conn.createFrame("SEND");
- frame.addHeader("destination", getQueuePrefix() + getQueueName());
- frame.setBody("Hello World 2");
- conn.sendFrame(frame);
-
- QueueBrowser browser = session.createBrowser(queue);
-
- Enumeration enu = browser.getEnumeration();
-
- while (enu.hasMoreElements()) {
- Message msg = (Message) enu.nextElement();
- String msgId = msg.getStringProperty("amqMessageId");
- assertNotNull(msgId);
- assertTrue(msgId.indexOf("STOMP") == 0);
- }
-
- browser.close();
-
- MessageConsumer consumer = session.createConsumer(queue);
-
- TextMessage message = (TextMessage) consumer.receive(1000);
- Assert.assertNotNull(message);
-
- message = (TextMessage) consumer.receive(1000);
- Assert.assertNotNull(message);
-
- message = (TextMessage) consumer.receive(2000);
- Assert.assertNull(message);
-
- conn.disconnect();
- }
-}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/aa730fda/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTestWithSecurity.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTestWithSecurity.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTestWithSecurity.java
deleted file mode 100644
index ead1522..0000000
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTestWithSecurity.java
+++ /dev/null
@@ -1,64 +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.activemq.artemis.tests.integration.stomp;
-
-import javax.jms.MessageConsumer;
-import javax.jms.TextMessage;
-
-import org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame;
-import org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection;
-import org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnectionFactory;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class StompTestWithSecurity extends StompTestBase {
-
- @Override
- public boolean isSecurityEnabled() {
- return true;
- }
-
- @Test
- public void testJMSXUserID() throws Exception {
- server.getActiveMQServer().getConfiguration().setPopulateValidatedUser(true);
-
- MessageConsumer consumer = session.createConsumer(queue);
-
- StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
- conn.connect(defUser, defPass);
-
- ClientStompFrame frame = conn.createFrame("SEND");
- frame.addHeader("destination", getQueuePrefix() + getQueueName());
- frame.setBody("Hello World");
- conn.sendFrame(frame);
-
- conn.disconnect();
-
- TextMessage message = (TextMessage) consumer.receive(1000);
- Assert.assertNotNull(message);
- Assert.assertEquals("Hello World", message.getText());
- // Assert default priority 4 is used when priority header is not set
- Assert.assertEquals("getJMSPriority", 4, message.getJMSPriority());
- Assert.assertEquals("JMSXUserID", "brianm", message.getStringProperty("JMSXUserID"));
-
- // Make sure that the timestamp is valid - should
- // be very close to the current time.
- long tnow = System.currentTimeMillis();
- long tmsg = message.getJMSTimestamp();
- Assert.assertTrue(Math.abs(tnow - tmsg) < 1000);
- }
-}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/aa730fda/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompWithInterceptorsTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompWithInterceptorsTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompWithInterceptorsTest.java
new file mode 100644
index 0000000..f795ad3
--- /dev/null
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompWithInterceptorsTest.java
@@ -0,0 +1,166 @@
+/**
+ * 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.artemis.tests.integration.stomp;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.activemq.artemis.api.core.Interceptor;
+import org.apache.activemq.artemis.core.protocol.core.Packet;
+import org.apache.activemq.artemis.core.protocol.stomp.StompFrame;
+import org.apache.activemq.artemis.core.protocol.stomp.StompFrameInterceptor;
+import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
+import org.apache.activemq.artemis.tests.integration.IntegrationTestLogger;
+import org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame;
+import org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection;
+import org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnectionFactory;
+import org.apache.activemq.artemis.tests.util.Wait;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class StompWithInterceptorsTest extends StompTestBase {
+
+ @Override
+ public List<String> getIncomingInterceptors() {
+ List<String> stompIncomingInterceptor = new ArrayList<>();
+ stompIncomingInterceptor.add("org.apache.activemq.artemis.tests.integration.stomp.StompWithInterceptorsTest$MyIncomingStompFrameInterceptor");
+ stompIncomingInterceptor.add("org.apache.activemq.artemis.tests.integration.stomp.StompWithInterceptorsTest$MyCoreInterceptor");
+
+ return stompIncomingInterceptor;
+ }
+
+ @Override
+ public List<String> getOutgoingInterceptors() {
+ List<String> stompOutgoingInterceptor = new ArrayList<>();
+ stompOutgoingInterceptor.add("org.apache.activemq.artemis.tests.integration.stomp.StompWithInterceptorsTest$MyOutgoingStompFrameInterceptor");
+
+ return stompOutgoingInterceptor;
+ }
+
+ @Test
+ public void stompFrameInterceptor() throws Exception {
+ MyIncomingStompFrameInterceptor.incomingInterceptedFrames.clear();
+ MyOutgoingStompFrameInterceptor.outgoingInterceptedFrames.clear();
+
+ Thread.sleep(200);
+
+ // So we clear them here
+ MyCoreInterceptor.incomingInterceptedFrames.clear();
+
+ StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
+ conn.connect(defUser, defPass);
+
+ ClientStompFrame subFrame = conn.createFrame("SUBSCRIBE");
+ subFrame.addHeader("subscription-type", "ANYCAST");
+ subFrame.addHeader("destination", getQueuePrefix() + getQueueName());
+ subFrame.addHeader("ack", "auto");
+ conn.sendFrame(subFrame);
+
+ assertEquals(0, MyCoreInterceptor.incomingInterceptedFrames.size());
+ sendJmsMessage(getName());
+
+ // Something was supposed to be called on sendMessages
+ assertTrue("core interceptor is not working", MyCoreInterceptor.incomingInterceptedFrames.size() > 0);
+
+ conn.receiveFrame(10000);
+
+ ClientStompFrame frame = conn.createFrame("SEND");
+ frame.addHeader("destination", getQueuePrefix() + getQueueName());
+ frame.setBody("Hello World");
+ conn.sendFrame(frame);
+
+ conn.disconnect();
+
+ List<String> incomingCommands = new ArrayList<>(4);
+ incomingCommands.add("CONNECT");
+ incomingCommands.add("SUBSCRIBE");
+ incomingCommands.add("SEND");
+ incomingCommands.add("DISCONNECT");
+
+ List<String> outgoingCommands = new ArrayList<>(3);
+ outgoingCommands.add("CONNECTED");
+ outgoingCommands.add("MESSAGE");
+ outgoingCommands.add("MESSAGE");
+
+ long timeout = System.currentTimeMillis() + 1000;
+
+ // Things are async, giving some time to things arrive before we actually assert
+ while (MyIncomingStompFrameInterceptor.incomingInterceptedFrames.size() < 4 &&
+ MyOutgoingStompFrameInterceptor.outgoingInterceptedFrames.size() < 3 &&
+ timeout > System.currentTimeMillis()) {
+ Thread.sleep(10);
+ }
+
+ Wait.waitFor(() -> {
+ return MyIncomingStompFrameInterceptor.incomingInterceptedFrames.size() == 4;
+ });
+ Assert.assertEquals(4, MyIncomingStompFrameInterceptor.incomingInterceptedFrames.size());
+ Wait.waitFor(() -> {
+ return MyOutgoingStompFrameInterceptor.outgoingInterceptedFrames.size() == 3;
+ });
+ Assert.assertEquals(3, MyOutgoingStompFrameInterceptor.outgoingInterceptedFrames.size());
+
+ for (int i = 0; i < MyIncomingStompFrameInterceptor.incomingInterceptedFrames.size(); i++) {
+ Assert.assertEquals(incomingCommands.get(i), MyIncomingStompFrameInterceptor.incomingInterceptedFrames.get(i).getCommand());
+ Assert.assertEquals("incomingInterceptedVal", MyIncomingStompFrameInterceptor.incomingInterceptedFrames.get(i).getHeader("incomingInterceptedProp"));
+ }
+
+ for (int i = 0; i < MyOutgoingStompFrameInterceptor.outgoingInterceptedFrames.size(); i++) {
+ Assert.assertEquals(outgoingCommands.get(i), MyOutgoingStompFrameInterceptor.outgoingInterceptedFrames.get(i).getCommand());
+ }
+
+ Assert.assertEquals("incomingInterceptedVal", MyOutgoingStompFrameInterceptor.outgoingInterceptedFrames.get(2).getHeader("incomingInterceptedProp"));
+ Assert.assertEquals("outgoingInterceptedVal", MyOutgoingStompFrameInterceptor.outgoingInterceptedFrames.get(2).getHeader("outgoingInterceptedProp"));
+ }
+
+ public static class MyCoreInterceptor implements Interceptor {
+
+ static List<Packet> incomingInterceptedFrames = new ArrayList<>();
+
+ @Override
+ public boolean intercept(Packet packet, RemotingConnection connection) {
+ IntegrationTestLogger.LOGGER.info("Core intercepted: " + packet);
+ incomingInterceptedFrames.add(packet);
+ return true;
+ }
+ }
+
+ public static class MyIncomingStompFrameInterceptor implements StompFrameInterceptor {
+
+ static List<StompFrame> incomingInterceptedFrames = new ArrayList<>();
+
+ @Override
+ public boolean intercept(StompFrame stompFrame, RemotingConnection connection) {
+ incomingInterceptedFrames.add(stompFrame);
+ stompFrame.addHeader("incomingInterceptedProp", "incomingInterceptedVal");
+ return true;
+ }
+ }
+
+ public static class MyOutgoingStompFrameInterceptor implements StompFrameInterceptor {
+
+ static List<StompFrame> outgoingInterceptedFrames = new ArrayList<>();
+
+ @Override
+ public boolean intercept(StompFrame stompFrame, RemotingConnection connection) {
+ outgoingInterceptedFrames.add(stompFrame);
+ stompFrame.addHeader("outgoingInterceptedProp", "outgoingInterceptedVal");
+ return true;
+ }
+ }
+}