Search in sources :

Example 66 with ClientStompFrame

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

the class StompV12Test method testSubscribeToTopicWithNoLocal.

@Test
public void testSubscribeToTopicWithNoLocal() throws Exception {
    conn.connect(defUser, defPass);
    subscribeTopic(conn, "sub1", null, null, true, true);
    // send a message on the same connection => it should not be received
    send(conn, getTopicPrefix() + getTopicName(), null, "Hello World");
    ClientStompFrame frame = conn.receiveFrame(2000);
    Assert.assertNull(frame);
    // send message on another JMS connection => it should be received
    sendJmsMessage(getName(), topic);
    frame = conn.receiveFrame();
    Assert.assertTrue(frame.getCommand().equals(Stomp.Responses.MESSAGE));
    Assert.assertTrue(frame.getHeader(Stomp.Headers.Subscribe.DESTINATION).equals(getTopicPrefix() + getTopicName()));
    Assert.assertTrue(frame.getBody().equals(getName()));
    unsubscribe(conn, "sub1");
    conn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) Test(org.junit.Test)

Example 67 with ClientStompFrame

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

the class ExtraStompTest method testNoGarbageOnPersistentRedelivery.

public void testNoGarbageOnPersistentRedelivery(StompClientConnection conn) throws Exception {
    ClientStompFrame frame = conn.createFrame(Stomp.Commands.SEND);
    frame.addHeader(Stomp.Headers.Subscribe.DESTINATION, getQueuePrefix() + getQueueName());
    frame.addHeader(Stomp.Headers.CONTENT_LENGTH, "11");
    frame.addHeader(Stomp.Headers.Send.PERSISTENT, Boolean.TRUE.toString());
    frame.setBody("Hello World");
    conn.sendFrame(frame);
    frame = conn.createFrame(Stomp.Commands.SEND);
    frame.addHeader(Stomp.Headers.Subscribe.DESTINATION, getQueuePrefix() + getQueueName());
    frame.addHeader(Stomp.Headers.CONTENT_LENGTH, "11");
    frame.addHeader(Stomp.Headers.Send.PERSISTENT, Boolean.TRUE.toString());
    frame.setBody("Hello World");
    conn.sendFrame(frame);
    frame = subscribe(conn, "a-sub", Stomp.Headers.Subscribe.AckModeValues.CLIENT);
    // receive but don't ack
    frame = conn.receiveFrame(10000);
    System.out.println(frame);
    frame = conn.receiveFrame(10000);
    System.out.println(frame);
    unsubscribe(conn, "a-sub");
    frame = subscribe(conn, "a-sub");
    frame = conn.receiveFrame(10000);
    // second receive will get problem if trailing bytes
    assertEquals("Hello World", frame.getBody());
    // unsub
    unsubscribe(conn, "a-sub");
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame)

Example 68 with ClientStompFrame

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

the class StompV11Test method testAck.

@Test
public void testAck() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, "sub1", Stomp.Headers.Subscribe.AckModeValues.CLIENT);
    sendJmsMessage(getName());
    ClientStompFrame frame = conn.receiveFrame();
    String messageID = frame.getHeader(Stomp.Headers.Message.MESSAGE_ID);
    ack(conn, "sub1", messageID, null);
    unsubscribe(conn, "sub1");
    conn.disconnect();
    // Nack makes the message be dropped.
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNull(message);
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) BytesMessage(javax.jms.BytesMessage) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Test(org.junit.Test)

Example 69 with ClientStompFrame

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

the class StompV11Test method testAckModeClient2.

@Test
public void testAckModeClient2() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, "sub1", Stomp.Headers.Subscribe.AckModeValues.CLIENT);
    Thread.sleep(1000);
    int num = 50;
    // send a bunch of messages
    for (int i = 0; i < num; i++) {
        this.sendJmsMessage("client-ack" + i);
    }
    ClientStompFrame frame = null;
    for (int i = 0; i < num; i++) {
        frame = conn.receiveFrame();
        assertNotNull(frame);
        // ack the 49th
        if (i == num - 2) {
            ack(conn, "sub1", frame);
        }
    }
    unsubscribe(conn, "sub1");
    conn.disconnect();
    // no messages can be received.
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(10000);
    Assert.assertNotNull(message);
    message = consumer.receive(1000);
    Assert.assertNull(message);
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) BytesMessage(javax.jms.BytesMessage) Test(org.junit.Test)

Example 70 with ClientStompFrame

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

the class StompV11Test method testSubscribeWithAutoAckAndSelector.

@Test
public void testSubscribeWithAutoAckAndSelector() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, "sub1", Stomp.Headers.Subscribe.AckModeValues.AUTO, null, "foo = 'zzz'");
    sendJmsMessage("Ignored message", "foo", "1234");
    sendJmsMessage("Real message", "foo", "zzz");
    ClientStompFrame frame = conn.receiveFrame();
    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