Search in sources :

Example 51 with ActiveMQQueue

use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.

the class ConfigUsingDestinationOptionsTest method testInvalidSelectorConfig.

@Test(timeout = 60000)
public void testInvalidSelectorConfig() throws JMSException {
    ActiveMQQueue queue = new ActiveMQQueue("TEST.FOO?consumer.selector=test||1");
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost");
    Connection conn = factory.createConnection();
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQMessageConsumer cons;
    // JMS selector should be priority
    try {
        cons = (ActiveMQMessageConsumer) sess.createConsumer(queue, "test||1");
        fail("Selector should be invalid" + cons);
    } catch (InvalidSelectorException e) {
    }
    // Test setting using JMS destinations
    try {
        cons = (ActiveMQMessageConsumer) sess.createConsumer(queue);
        fail("Selector should be invalid" + cons);
    } catch (InvalidSelectorException e) {
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) InvalidSelectorException(javax.jms.InvalidSelectorException) ActiveMQMessageConsumer(org.apache.activemq.ActiveMQMessageConsumer) Connection(javax.jms.Connection) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Session(javax.jms.Session) Test(org.junit.Test)

Example 52 with ActiveMQQueue

use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.

the class DestinationMapTest method testQueueAndTopicWithSameName.

public void testQueueAndTopicWithSameName() throws Exception {
    ActiveMQQueue q1 = new ActiveMQQueue("foo");
    ActiveMQTopic t1 = new ActiveMQTopic("foo");
    map.put(q1, v1);
    map.put(t1, v2);
    assertMapValue(q1, v1);
    assertMapValue(t1, v2);
}
Also used : ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue)

Example 53 with ActiveMQQueue

use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.

the class ActiveMQInitialContextFactoryTest method testDestinationsArePresent.

public void testDestinationsArePresent() throws NamingException {
    // Retrieving destinations context is not yet implemented on the broker.
    // For this test, a jndi file properties will be used.
    InitialContext context = new InitialContext();
    Object topicDestination = context.lookup("MyTopic");
    // check if MyTopic is an ActiveMQTopic
    assertTrue("Should have found a topic but found: " + topicDestination, topicDestination instanceof ActiveMQTopic);
    Object queueDestination = context.lookup("MyQueue");
    // check if MyQueue is an ActiveMQueue
    assertTrue("Should have found a queue but found: " + queueDestination, queueDestination instanceof ActiveMQQueue);
}
Also used : ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) InitialContext(javax.naming.InitialContext)

Example 54 with ActiveMQQueue

use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.

the class ActiveMQInitialContextFactoryTest method testDynamicallyGrowing.

public void testDynamicallyGrowing() throws Exception {
    Object answer = context.lookup("dynamicQueues/FOO.BAR");
    assertTrue("Should have found a queue but found: " + answer, answer instanceof ActiveMQQueue);
    ActiveMQQueue queue = (ActiveMQQueue) answer;
    assertEquals("queue name", "FOO.BAR", queue.getPhysicalName());
    answer = context.lookup("dynamicTopics/A.B.C");
    assertTrue("Should have found a topic but found: " + answer, answer instanceof ActiveMQTopic);
    ActiveMQTopic topic = (ActiveMQTopic) answer;
    assertEquals("topic name", "A.B.C", topic.getPhysicalName());
}
Also used : ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue)

Example 55 with ActiveMQQueue

use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.

the class BasicSecurityTest method testSendnReceiveAuthorization.

@Test
public void testSendnReceiveAuthorization() throws Exception {
    Connection sendingConn = null;
    Connection receivingConn = null;
    // Sender
    try {
        Destination dest = new ActiveMQQueue(queueName);
        receivingConn = factory.createConnection("openwireReceiver", "ReCeIvEr");
        receivingConn.start();
        sendingConn = factory.createConnection("openwireSender", "SeNdEr");
        sendingConn.start();
        Session sendingSession = sendingConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Session receivingSession = receivingConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        TextMessage message = sendingSession.createTextMessage("Hello World");
        MessageProducer producer = null;
        producer = receivingSession.createProducer(dest);
        try {
            producer.send(message);
        } catch (JMSSecurityException e) {
            // expected
            producer.close();
        }
        producer = sendingSession.createProducer(dest);
        producer.send(message);
        MessageConsumer consumer;
        try {
            consumer = sendingSession.createConsumer(dest);
            Assert.fail("exception expected");
        } catch (JMSSecurityException e) {
            e.printStackTrace();
        // expected
        }
        consumer = receivingSession.createConsumer(dest);
        TextMessage received = (TextMessage) consumer.receive(5000);
        assertNotNull(received);
        assertEquals("Hello World", received.getText());
    } finally {
        if (sendingConn != null) {
            sendingConn.close();
        }
        if (receivingConn != null) {
            receivingConn.close();
        }
    }
}
Also used : Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) JMSSecurityException(javax.jms.JMSSecurityException) Connection(javax.jms.Connection) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)239 Session (javax.jms.Session)81 MessageProducer (javax.jms.MessageProducer)78 MessageConsumer (javax.jms.MessageConsumer)76 TextMessage (javax.jms.TextMessage)73 Test (org.junit.Test)66 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)54 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)44 Message (javax.jms.Message)36 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)33 Connection (javax.jms.Connection)32 Destination (javax.jms.Destination)27 CountDownLatch (java.util.concurrent.CountDownLatch)20 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)18 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)18 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)18 SessionInfo (org.apache.activemq.command.SessionInfo)18 Message (org.apache.activemq.command.Message)17 BasicOpenWireTest (org.apache.activemq.artemis.tests.integration.openwire.BasicOpenWireTest)16 ProducerInfo (org.apache.activemq.command.ProducerInfo)16