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);
}
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);
}
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);
}
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();
}
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();
}
Aggregations