Search in sources :

Example 16 with ClientStompFrame

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

the class StompTest method testDurableSubscriberWithReconnection.

@Test
public void testDurableSubscriberWithReconnection() throws Exception {
    conn.connect(defUser, defPass, "myclientid");
    subscribeTopic(conn, null, null, getName());
    conn.disconnect();
    Thread.sleep(500);
    // send the message when the durable subscriber is disconnected
    sendJmsMessage(getName(), topic);
    conn.destroy();
    conn = StompClientConnectionFactory.createClientConnection(uri);
    conn.connect(defUser, defPass, "myclientid");
    subscribeTopic(conn, null, null, getName());
    ClientStompFrame frame = conn.receiveFrame(3000);
    assertNotNull("Should have received a message from the durable subscription", frame);
    Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
    Assert.assertEquals(getTopicPrefix() + getTopicName(), frame.getHeader(Stomp.Headers.Send.DESTINATION));
    Assert.assertEquals(getName(), frame.getBody());
    unsubscribe(conn, null, getTopicPrefix() + getTopicName(), true, true);
    conn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) Test(org.junit.Test)

Example 17 with ClientStompFrame

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

the class StompTest method testDurableSubscriber.

@Test
public void testDurableSubscriber() throws Exception {
    conn.connect(defUser, defPass, "myclientid");
    subscribeTopic(conn, null, null, getName(), true);
    ClientStompFrame response = subscribeTopic(conn, null, null, getName(), true);
    // creating a subscriber with the same durable-subscriber-name must fail
    Assert.assertEquals(Stomp.Responses.ERROR, response.getCommand());
    conn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) Test(org.junit.Test)

Example 18 with ClientStompFrame

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

the class StompTest method testSendMessageWithLongHeaders.

@Test
public void testSendMessageWithLongHeaders() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    conn.connect(defUser, defPass);
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < 1024; i++) {
        buffer.append("a");
    }
    ClientStompFrame frame = conn.createFrame(Stomp.Commands.SEND).addHeader(Stomp.Headers.Send.DESTINATION, getQueuePrefix() + getQueueName()).addHeader("foo", "abc").addHeader("bar", "123").addHeader("correlation-id", "c123").addHeader("persistent", "true").addHeader("type", "t345").addHeader("JMSXGroupID", "abc").addHeader("priority", "3").addHeader("longHeader", buffer.toString()).setBody("Hello World");
    conn.sendFrame(frame);
    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("Hello World", message.getText());
    Assert.assertEquals("JMSCorrelationID", "c123", message.getJMSCorrelationID());
    Assert.assertEquals("getJMSType", "t345", message.getJMSType());
    Assert.assertEquals("getJMSPriority", 3, message.getJMSPriority());
    Assert.assertEquals(javax.jms.DeliveryMode.PERSISTENT, message.getJMSDeliveryMode());
    Assert.assertEquals("foo", "abc", message.getStringProperty("foo"));
    Assert.assertEquals("longHeader", 1024, message.getStringProperty("longHeader").length());
    Assert.assertEquals("JMSXGroupID", "abc", message.getStringProperty("JMSXGroupID"));
}
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 19 with ClientStompFrame

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

the class StompTest method testTopicExistsAfterNoUnsubscribeDisconnect.

@Test
public void testTopicExistsAfterNoUnsubscribeDisconnect() throws Exception {
    conn.connect(defUser, defPass);
    subscribeTopic(conn, null, null, null, true);
    // disconnect, _without unsubscribing_
    conn.disconnect();
    Thread.sleep(500);
    conn.destroy();
    // connect again
    conn = StompClientConnectionFactory.createClientConnection(uri);
    conn.connect(defUser, defPass);
    // send a receipted message to the topic
    ClientStompFrame response = send(conn, getTopicPrefix() + getTopicName(), null, "Hello World", true);
    assertEquals(Stomp.Responses.RECEIPT, response.getCommand());
    // ...and nothing else
    ClientStompFrame frame = conn.receiveFrame(2000);
    log.info("Received frame: " + frame);
    Assert.assertNull(frame);
    conn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) Test(org.junit.Test)

Example 20 with ClientStompFrame

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

the class StompTest method testSubscribeWithAutoAckAndSelector.

@Test
public void testSubscribeWithAutoAckAndSelector() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, null, Stomp.Headers.Subscribe.AckModeValues.AUTO, null, "foo = 'zzz'");
    sendJmsMessage("Ignored message", "foo", "1234");
    sendJmsMessage("Real message", "foo", "zzz");
    ClientStompFrame frame = conn.receiveFrame(10000);
    Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
    Assert.assertTrue("Should have received the real message but got: " + frame, frame.getBody().equals("Real message"));
    conn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) 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