Search in sources :

Example 21 with ClientStompFrame

use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.

the class StompTest method testSubscribeToNonExistentQueue.

@Test
public void testSubscribeToNonExistentQueue() throws Exception {
    String nonExistentQueue = RandomUtil.randomString();
    conn.connect(defUser, defPass);
    subscribe(conn, null, null, null, null, getQueuePrefix() + nonExistentQueue, true);
    sendJmsMessage(getName(), ActiveMQJMSClient.createQueue(nonExistentQueue));
    ClientStompFrame frame = conn.receiveFrame(1000);
    Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
    Assert.assertEquals(getQueuePrefix() + nonExistentQueue, frame.getHeader(Stomp.Headers.Send.DESTINATION));
    Assert.assertEquals(getName(), frame.getBody());
    assertNotNull(server.getActiveMQServer().getPostOffice().getBinding(new SimpleString(nonExistentQueue)));
    final Queue subscription = ((LocalQueueBinding) server.getActiveMQServer().getPostOffice().getBinding(new SimpleString(nonExistentQueue))).getQueue();
    assertTrue(Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisfied() throws Exception {
            if (subscription.getMessageCount() == 0)
                return true;
            else
                return false;
        }
    }, 1000, 50));
    unsubscribe(conn, null, getQueuePrefix() + nonExistentQueue, true, false);
    assertNull(server.getActiveMQServer().getPostOffice().getBinding(new SimpleString(nonExistentQueue)));
    sendJmsMessage(getName(), ActiveMQJMSClient.createQueue(nonExistentQueue));
    frame = conn.receiveFrame(1000);
    log.info("Received frame: " + frame);
    Assert.assertNull("No message should have been received since subscription was removed", frame);
    conn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Queue(org.apache.activemq.artemis.core.server.Queue) Test(org.junit.Test)

Example 22 with ClientStompFrame

use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.

the class StompTest method testSendMessageWithCustomHeadersAndHyphenatedSelector.

@Test
public void testSendMessageWithCustomHeadersAndHyphenatedSelector() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue, "hyphenated_props:b-ar = '123'");
    conn.connect(defUser, defPass);
    ClientStompFrame frame = conn.createFrame(Stomp.Commands.SEND).addHeader(Stomp.Headers.Send.DESTINATION, getQueuePrefix() + getQueueName()).addHeader("foo", "abc").addHeader("b-ar", "123").setBody("Hello World");
    conn.sendFrame(frame);
    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("Hello World", message.getText());
    Assert.assertEquals("foo", "abc", message.getStringProperty("foo"));
    Assert.assertEquals("b-ar", "123", message.getStringProperty("b-ar"));
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 23 with ClientStompFrame

use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.

the class StompTest method testRoutingSemantics.

public void testRoutingSemantics(String routingType, String destination) throws Exception {
    conn.connect(defUser, defPass);
    String uuid = UUID.randomUUID().toString();
    ClientStompFrame frame = conn.createFrame(Stomp.Commands.SUBSCRIBE).addHeader(Stomp.Headers.Subscribe.SUBSCRIPTION_TYPE, routingType).addHeader(Stomp.Headers.Subscribe.DESTINATION, destination).addHeader(Stomp.Headers.RECEIPT_REQUESTED, uuid);
    frame = conn.sendFrame(frame);
    assertEquals(Stomp.Responses.ERROR, frame.getCommand());
    uuid = UUID.randomUUID().toString();
    frame = conn.createFrame(Stomp.Commands.SEND).addHeader(Stomp.Headers.Send.DESTINATION_TYPE, RoutingType.MULTICAST.toString()).addHeader(Stomp.Headers.Send.DESTINATION, getQueuePrefix() + getQueueName()).addHeader(Stomp.Headers.RECEIPT_REQUESTED, uuid);
    frame = conn.sendFrame(frame);
    assertEquals(Stomp.Responses.ERROR, frame.getCommand());
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Example 24 with ClientStompFrame

use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.

the class StompTest method testInvokeOperationFromStomp.

@Test
public void testInvokeOperationFromStomp() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, null);
    ClientStompFrame frame = conn.createFrame(Stomp.Commands.SEND).addHeader(Stomp.Headers.Send.DESTINATION, ActiveMQDefaultConfiguration.getDefaultManagementAddress().toString()).addHeader(Stomp.Headers.Send.REPLY_TO, getQueuePrefix() + getQueueName()).addHeader(ManagementHelper.HDR_RESOURCE_NAME.toString(), ResourceNames.QUEUE + getQueuePrefix() + getQueueName()).addHeader(ManagementHelper.HDR_OPERATION_NAME.toString(), "countMessages").setBody("[\"color = 'blue'\"]");
    conn.sendFrame(frame);
    frame = conn.receiveFrame(10000);
    IntegrationTestLogger.LOGGER.info("Received: " + frame);
    Assert.assertEquals(Boolean.TRUE.toString(), frame.getHeader(ManagementHelper.HDR_OPERATION_SUCCEEDED.toString()));
    // there is no such messages => 0 returned in a JSON array
    Assert.assertEquals("[0]", frame.getBody());
    unsubscribe(conn, null);
    conn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) Test(org.junit.Test)

Example 25 with ClientStompFrame

use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.

the class StompTest method testMessagesAreInOrder.

@Test
public void testMessagesAreInOrder() throws Exception {
    int ctr = 10;
    String[] data = new String[ctr];
    conn.connect(defUser, defPass);
    subscribe(conn, null, Stomp.Headers.Subscribe.AckModeValues.AUTO);
    for (int i = 0; i < ctr; ++i) {
        data[i] = getName() + i;
        sendJmsMessage(data[i]);
    }
    for (int i = 0; i < ctr; ++i) {
        ClientStompFrame frame = conn.receiveFrame(1000);
        Assert.assertTrue("Message not in order", frame.getBody().equals(data[i]));
    }
    // sleep a while before publishing another set of messages
    Thread.sleep(200);
    for (int i = 0; i < ctr; ++i) {
        data[i] = getName() + Stomp.Headers.SEPARATOR + "second:" + i;
        sendJmsMessage(data[i]);
    }
    for (int i = 0; i < ctr; ++i) {
        ClientStompFrame frame = conn.receiveFrame(1000);
        Assert.assertTrue("Message not in order", frame.getBody().equals(data[i]));
    }
    conn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Test(org.junit.Test)

Aggregations

ClientStompFrame (org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame)195 Test (org.junit.Test)173 MessageConsumer (javax.jms.MessageConsumer)67 TextMessage (javax.jms.TextMessage)62 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)51 BytesMessage (javax.jms.BytesMessage)43 StompClientConnection (org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection)41 Message (javax.jms.Message)37 IOException (java.io.IOException)7 URI (java.net.URI)5 MessageProducer (javax.jms.MessageProducer)5 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)4 ClosedChannelException (java.nio.channels.ClosedChannelException)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)2 LargeMessageTestBase (org.apache.activemq.artemis.tests.integration.largemessage.LargeMessageTestBase)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1