small improvement on org.apache.activemq.JmsQueueCompositeSendReceiveTest

This commit is contained in:
Clebert Suconic 2015-08-05 09:32:09 -04:00
parent ee84d7efdf
commit 2ad821a0ca
1 changed files with 12 additions and 17 deletions

View File

@ -20,26 +20,24 @@ import javax.jms.DeliveryMode;
import javax.jms.Destination; import javax.jms.Destination;
import javax.jms.Message; import javax.jms.Message;
import javax.jms.MessageConsumer; import javax.jms.MessageConsumer;
import javax.jms.Session;
import javax.jms.Topic; import javax.jms.Topic;
import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.api.core.client.ClientSession; import org.apache.activemq.artemis.api.core.client.ClientSession;
import org.apache.activemq.artemis.jms.client.ActiveMQSession; import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
import org.apache.activemq.artemis.uri.ConnectionFactoryParser; import org.apache.activemq.artemis.api.core.client.ServerLocator;
import org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl;
import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.test.JmsTopicSendReceiveTest; import org.apache.activemq.test.JmsTopicSendReceiveTest;
import java.net.URI;
/** /**
* *
*/ */
public class JmsQueueCompositeSendReceiveTest extends JmsTopicSendReceiveTest { public class JmsQueueCompositeSendReceiveTest extends JmsTopicSendReceiveTest {
private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
.getLog(JmsQueueCompositeSendReceiveTest.class); .getLog(JmsQueueCompositeSendReceiveTest.class);
/** /**
* Sets a test to have a queue destination and non-persistent delivery mode. * Sets a test to have a queue destination and non-persistent delivery mode.
* *
@ -70,7 +68,7 @@ public class JmsQueueCompositeSendReceiveTest extends JmsTopicSendReceiveTest {
protected String getProducerSubject() { protected String getProducerSubject() {
return "FOO.BAR.HUMBUG,FOO.BAR.HUMBUG2"; return "FOO.BAR.HUMBUG,FOO.BAR.HUMBUG2";
} }
/** /**
* Test if all the messages sent are being received. * Test if all the messages sent are being received.
* *
@ -93,7 +91,7 @@ public class JmsQueueCompositeSendReceiveTest extends JmsTopicSendReceiveTest {
assertMessagesAreReceived(); assertMessagesAreReceived();
LOG.info("" + data.length + " messages(s) received, closing down connections"); LOG.info("" + data.length + " messages(s) received, closing down connections");
} }
public void testDuplicate() throws Exception { public void testDuplicate() throws Exception {
ActiveMQDestination queue = (ActiveMQDestination)session.createQueue("TEST,TEST"); ActiveMQDestination queue = (ActiveMQDestination)session.createQueue("TEST,TEST");
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
@ -104,18 +102,15 @@ public class JmsQueueCompositeSendReceiveTest extends JmsTopicSendReceiveTest {
} }
producer.send(queue, message); producer.send(queue, message);
} }
Thread.sleep(200); // wait for messages to be queue; Thread.sleep(200); // wait for messages to be queue;
org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory factory = new org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory("tcp://localhost:61616?type=CF"); try (ServerLocator locator = ServerLocatorImpl.newLocator("tcp://localhost:61616");
org.apache.activemq.artemis.jms.client.ActiveMQConnection conn = (org.apache.activemq.artemis.jms.client.ActiveMQConnection) factory.createConnection(); ClientSessionFactory factory = locator.createSessionFactory();
try { ClientSession session = factory.createSession()) {
ActiveMQSession session = (ActiveMQSession) conn.createSession(false, Session.AUTO_ACKNOWLEDGE); ClientSession.QueueQuery query = session.queueQuery(new SimpleString("jms.queue.TEST"));
ClientSession.QueueQuery query = session.getCoreSession().queueQuery(new SimpleString("jms.queue.TEST"));
assertNotNull(query); assertNotNull(query);
assertEquals(data.length, query.getMessageCount()); assertEquals(data.length, query.getMessageCount());
} finally {
conn.close();
} }
} }
} }