Search in sources :

Example 41 with ClientStompFrame

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

the class StompV12Test method testErrorWithReceipt2.

@Test
public void testErrorWithReceipt2() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, "sub1", "client");
    sendJmsMessage(getName());
    ClientStompFrame frame = conn.receiveFrame();
    String messageID = frame.getHeader(Stomp.Headers.Message.MESSAGE_ID);
    ClientStompFrame ackFrame = conn.createFrame(Stomp.Commands.ACK);
    // give it a wrong sub id
    ackFrame.addHeader(Stomp.Headers.Message.SUBSCRIPTION, "sub1");
    ackFrame.addHeader(Stomp.Headers.Message.MESSAGE_ID, String.valueOf(Long.valueOf(messageID) + 1));
    ackFrame.addHeader(Stomp.Headers.RECEIPT_REQUESTED, "answer-me");
    ClientStompFrame error = conn.sendFrame(ackFrame);
    System.out.println("Receiver error: " + error);
    Assert.assertEquals(Stomp.Responses.ERROR, error.getCommand());
    Assert.assertEquals("answer-me", error.getHeader("receipt-id"));
    waitDisconnect(conn);
    Assert.assertFalse("Should be disconnected in STOMP 1.2 after ERROR", conn.isConnected());
    // message should still there
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNotNull(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 42 with ClientStompFrame

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

the class StompV12Test method testErrorWithReceipt.

@Test
public void testErrorWithReceipt() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, "sub1", "client");
    sendJmsMessage(getName());
    ClientStompFrame frame = conn.receiveFrame();
    String messageID = frame.getHeader(Stomp.Headers.Message.MESSAGE_ID);
    ClientStompFrame ackFrame = conn.createFrame(Stomp.Commands.ACK);
    // give it a wrong sub id
    ackFrame.addHeader(Stomp.Headers.Message.SUBSCRIPTION, "sub2");
    ackFrame.addHeader(Stomp.Headers.Message.MESSAGE_ID, messageID);
    ackFrame.addHeader(Stomp.Headers.RECEIPT_REQUESTED, "answer-me");
    ClientStompFrame error = conn.sendFrame(ackFrame);
    System.out.println("Receiver error: " + error);
    Assert.assertEquals(Stomp.Responses.ERROR, error.getCommand());
    Assert.assertEquals("answer-me", error.getHeader("receipt-id"));
    waitDisconnect(conn);
    Assert.assertFalse("Should be disconnected in STOMP 1.2 after ERROR", conn.isConnected());
    // message should still there
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNotNull(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 43 with ClientStompFrame

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

the class StompV12Test method testSubscribeWithAutoAck.

@Test
public void testSubscribeWithAutoAck() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, "sub1", Stomp.Headers.Subscribe.AckModeValues.AUTO);
    sendJmsMessage(getName());
    ClientStompFrame frame = conn.receiveFrame();
    Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
    Assert.assertNotNull(frame.getHeader(Stomp.Headers.Subscribe.DESTINATION));
    Assert.assertEquals(getName(), frame.getBody());
    conn.disconnect();
    // message should not be received as it was auto-acked
    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) Test(org.junit.Test)

Example 44 with ClientStompFrame

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

the class StompV12Test method testSendAndReceive.

@Test
public void testSendAndReceive() throws Exception {
    conn.connect(defUser, defPass);
    ClientStompFrame response = send(conn, getQueuePrefix() + getQueueName(), "text/plain", "Hello World 1!");
    Assert.assertNull(response);
    send(conn, getQueuePrefix() + getQueueName(), "text/plain", "Hello World 2!", true);
    // subscribe
    StompClientConnection newConn = StompClientConnectionFactory.createClientConnection(uri);
    newConn.connect(defUser, defPass);
    subscribe(newConn, "a-sub");
    ClientStompFrame frame = newConn.receiveFrame();
    System.out.println("received " + frame);
    Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
    Assert.assertEquals("a-sub", frame.getHeader(Stomp.Headers.Message.SUBSCRIPTION));
    // 'auto' ack mode doesn't require 'ack' header
    Assert.assertNull(frame.getHeader(Stomp.Headers.Subscribe.ACK_MODE));
    Assert.assertEquals(getQueuePrefix() + getQueueName(), frame.getHeader(Stomp.Headers.Subscribe.DESTINATION));
    Assert.assertEquals("Hello World 1!", frame.getBody());
    frame = newConn.receiveFrame();
    System.out.println("received " + frame);
    // unsub
    unsubscribe(newConn, "a-sub");
    newConn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) StompClientConnection(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection) Test(org.junit.Test)

Example 45 with ClientStompFrame

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

the class StompV12Test method testMessagesAreInOrder.

@Test
public void testMessagesAreInOrder() throws Exception {
    int ctr = 10;
    String[] data = new String[ctr];
    conn.connect(defUser, defPass);
    subscribe(conn, "sub1", Stomp.Headers.Subscribe.AckModeValues.AUTO);
    for (int i = 0; i < ctr; ++i) {
        data[i] = getName() + i;
        sendJmsMessage(data[i]);
    }
    ClientStompFrame frame = null;
    for (int i = 0; i < ctr; ++i) {
        frame = conn.receiveFrame();
        Assert.assertTrue("Message not in order", frame.getBody().equals(data[i]));
    }
    for (int i = 0; i < ctr; ++i) {
        data[i] = getName() + ":second:" + i;
        sendJmsMessage(data[i]);
    }
    for (int i = 0; i < ctr; ++i) {
        frame = conn.receiveFrame();
        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