NO-JIRA add STOMP tests

This commit is contained in:
Justin Bertram 2018-03-01 11:25:02 -06:00
parent 5773ad1ea7
commit b5f0225f29
2 changed files with 50 additions and 21 deletions

View File

@ -285,13 +285,11 @@ public class StompTest extends StompTestBase {
}
@Test
public void testSendMessageToNonExistentQueue() throws Exception {
String nonExistentQueue = RandomUtil.randomString();
public void sendMessageToNonExistentQueue(String queuePrefix, String queue, RoutingType routingType) throws Exception {
conn.connect(defUser, defPass);
send(conn, getQueuePrefix() + nonExistentQueue, null, "Hello World", true, RoutingType.ANYCAST);
send(conn, queuePrefix + queue, null, "Hello World", true, routingType);
MessageConsumer consumer = session.createConsumer(ActiveMQJMSClient.createQueue(nonExistentQueue));
MessageConsumer consumer = session.createConsumer(ActiveMQJMSClient.createQueue(queue));
TextMessage message = (TextMessage) consumer.receive(1000);
Assert.assertNotNull(message);
Assert.assertEquals("Hello World", message.getText());
@ -305,26 +303,32 @@ public class StompTest extends StompTestBase {
Assert.assertTrue(Math.abs(tnow - tmsg) < 1500);
// closing the consumer here should trigger auto-deletion
assertNotNull(server.getActiveMQServer()
.getPostOffice()
.getBinding(new SimpleString(nonExistentQueue)));
assertNotNull(server.getActiveMQServer().getPostOffice().getBinding(new SimpleString(queue)));
consumer.close();
assertNull(server.getActiveMQServer()
.getPostOffice()
.getBinding(new SimpleString(nonExistentQueue)));
assertNull(server.getActiveMQServer().getPostOffice().getBinding(new SimpleString(queue)));
}
@Test
public void testSendMessageToNonExistentTopic() throws Exception {
String nonExistentTopic = RandomUtil.randomString();
public void testSendMessageToNonExistentQueue() throws Exception {
sendMessageToNonExistentQueue(getQueuePrefix(), RandomUtil.randomString(), RoutingType.ANYCAST);
}
@Test
public void testSendMessageToNonExistentQueueUsingExplicitDefaultRouting() throws Exception {
String nonExistentQueue = RandomUtil.randomString();
server.getActiveMQServer().getAddressSettingsRepository().addMatch(nonExistentQueue, new AddressSettings().setDefaultAddressRoutingType(RoutingType.ANYCAST).setDefaultQueueRoutingType(RoutingType.ANYCAST));
sendMessageToNonExistentQueue(getQueuePrefix(), nonExistentQueue, null);
}
public void sendMessageToNonExistentTopic(String topicPrefix, String topic, RoutingType routingType) throws Exception {
conn.connect(defUser, defPass);
// first send a message to ensure that sending to a non-existent topic won't throw an error
send(conn, getTopicPrefix() + nonExistentTopic, null, "Hello World", true, RoutingType.MULTICAST);
send(conn, topicPrefix + topic, null, "Hello World", true, routingType);
// create a subscription on the topic and send/receive another message
MessageConsumer consumer = session.createConsumer(ActiveMQJMSClient.createTopic(nonExistentTopic));
send(conn, getTopicPrefix() + nonExistentTopic, null, "Hello World", true);
MessageConsumer consumer = session.createConsumer(ActiveMQJMSClient.createTopic(topic));
send(conn, topicPrefix + topic, null, "Hello World", true, routingType);
TextMessage message = (TextMessage) consumer.receive(1000);
Assert.assertNotNull(message);
Assert.assertEquals("Hello World", message.getText());
@ -337,14 +341,29 @@ public class StompTest extends StompTestBase {
long tmsg = message.getJMSTimestamp();
Assert.assertTrue(Math.abs(tnow - tmsg) < 1500);
assertNotNull(server.getActiveMQServer()
.getAddressInfo(new SimpleString(nonExistentTopic)));
assertNotNull(server.getActiveMQServer().getAddressInfo(new SimpleString(topic)));
// closing the consumer here should trigger auto-deletion of the subscription queue and address
consumer.close();
Thread.sleep(200);
assertNull(server.getActiveMQServer()
.getAddressInfo(new SimpleString(nonExistentTopic)));
assertNull(server.getActiveMQServer().getAddressInfo(new SimpleString(topic)));
}
@Test
public void testSendMessageToNonExistentTopic() throws Exception {
sendMessageToNonExistentTopic(getTopicPrefix(), RandomUtil.randomString(), RoutingType.MULTICAST);
}
@Test
public void testSendMessageToNonExistentTopicUsingExplicitDefaultRouting() throws Exception {
String nonExistentTopic = RandomUtil.randomString();
server.getActiveMQServer().getAddressSettingsRepository().addMatch(nonExistentTopic, new AddressSettings().setDefaultAddressRoutingType(RoutingType.MULTICAST).setDefaultQueueRoutingType(RoutingType.MULTICAST));
sendMessageToNonExistentTopic(getTopicPrefix(), nonExistentTopic, null);
}
@Test
public void testSendMessageToNonExistentTopicUsingImplicitDefaultRouting() throws Exception {
sendMessageToNonExistentTopic(getTopicPrefix(), RandomUtil.randomString(), null);
}
/*

View File

@ -37,6 +37,7 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.activemq.artemis.api.core.RoutingType;
import org.apache.activemq.artemis.api.core.TransportConfiguration;
import org.apache.activemq.artemis.core.config.Configuration;
import org.apache.activemq.artemis.core.protocol.mqtt.MQTTProtocolManagerFactory;
@ -50,7 +51,6 @@ import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants;
import org.apache.activemq.artemis.core.security.Role;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.core.server.ActiveMQServers;
import org.apache.activemq.artemis.api.core.RoutingType;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory;
import org.apache.activemq.artemis.jms.server.JMSServerManager;
@ -65,6 +65,7 @@ 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.unit.util.InVMNamingContext;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@ -159,6 +160,15 @@ public abstract class StompTestBase extends ActiveMQTestBase {
connection.start();
}
@Override
@After
public void tearDown() throws Exception {
if (connection != null) {
connection.close();
}
super.tearDown();
}
/**
* @return