use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.
the class StompV12Test method testAckModeClient2.
@Test
public void testAckModeClient2() throws Exception {
conn.connect(defUser, defPass);
subscribe(conn, "sub1", "client");
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();
Assert.assertNotNull(frame);
// ack the 49th
if (i == num - 2) {
ack(conn, frame);
}
}
unsubscribe(conn, "sub1");
conn.disconnect();
// one can be received.
MessageConsumer consumer = session.createConsumer(queue);
Message message = consumer.receive(1000);
Assert.assertNotNull(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 testTransactionRollback.
@Test
public void testTransactionRollback() throws Exception {
MessageConsumer consumer = session.createConsumer(queue);
conn.connect(defUser, defPass);
beginTransaction(conn, "tx1");
ClientStompFrame frame = conn.createFrame(Stomp.Commands.SEND).addHeader(Stomp.Headers.Subscribe.DESTINATION, getQueuePrefix() + getQueueName()).addHeader(Stomp.Headers.TRANSACTION, "tx1").setBody("first message");
conn.sendFrame(frame);
// rollback first message
abortTransaction(conn, "tx1");
beginTransaction(conn, "tx1");
frame = conn.createFrame(Stomp.Commands.SEND).addHeader(Stomp.Headers.Subscribe.DESTINATION, getQueuePrefix() + getQueueName()).addHeader(Stomp.Headers.TRANSACTION, "tx1").setBody("second message");
conn.sendFrame(frame);
commitTransaction(conn, "tx1", true);
// only second msg should be received since first msg was rolled back
TextMessage message = (TextMessage) consumer.receive(1000);
Assert.assertNotNull(message);
Assert.assertEquals("second message", message.getText());
conn.disconnect();
}
use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.
the class StompV12Test method testAckModeClientIndividual.
@Test
public void testAckModeClientIndividual() throws Exception {
conn.connect(defUser, defPass);
subscribe(conn, "sub1", "client-individual");
int num = 50;
// send a bunch of messages
for (int i = 0; i < num; i++) {
this.sendJmsMessage("client-individual-ack" + i);
}
ClientStompFrame frame = null;
for (int i = 0; i < num; i++) {
frame = conn.receiveFrame();
Assert.assertNotNull(frame);
System.out.println(i + " == received: " + frame);
// ack on even numbers
if (i % 2 == 0) {
ack(conn, frame);
}
}
unsubscribe(conn, "sub1");
conn.disconnect();
// no messages can be received.
MessageConsumer consumer = session.createConsumer(queue);
TextMessage message = null;
for (int i = 0; i < num / 2; i++) {
message = (TextMessage) consumer.receive(1000);
Assert.assertNotNull(message);
System.out.println("Legal: " + message.getText());
}
message = (TextMessage) 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 testTransactionCommit.
@Test
public void testTransactionCommit() throws Exception {
MessageConsumer consumer = session.createConsumer(queue);
conn.connect(defUser, defPass);
beginTransaction(conn, "tx1");
ClientStompFrame frame = conn.createFrame(Stomp.Commands.SEND).addHeader(Stomp.Headers.Subscribe.DESTINATION, getQueuePrefix() + getQueueName()).addHeader(Stomp.Headers.TRANSACTION, "tx1").addHeader(Stomp.Headers.RECEIPT_REQUESTED, "123").setBody("Hello World");
frame = conn.sendFrame(frame);
Assert.assertEquals("123", frame.getHeader("receipt-id"));
// check the message is not committed
Assert.assertNull(consumer.receive(100));
commitTransaction(conn, "tx1", true);
Message message = consumer.receive(1000);
Assert.assertNotNull("Should have received a message", message);
conn.disconnect();
}
use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.
the class StompV12Test method testNegotiation.
@Test
public void testNegotiation() throws Exception {
StompClientConnection conn = StompClientConnectionFactory.createClientConnection(v10Uri);
// case 1 accept-version absent. It is a 1.0 connect
ClientStompFrame frame = conn.createFrame(Stomp.Commands.CONNECT);
frame.addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1");
frame.addHeader(Stomp.Headers.Connect.LOGIN, this.defUser);
frame.addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
ClientStompFrame reply = conn.sendFrame(frame);
Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
// reply headers: version, session, server
Assert.assertEquals(null, reply.getHeader(Stomp.Headers.Error.VERSION));
conn.disconnect();
// case 2 accept-version=1.0, result: 1.0
conn = StompClientConnectionFactory.createClientConnection(v11Uri);
frame = conn.createFrame(Stomp.Commands.CONNECT);
frame.addHeader(Stomp.Headers.ACCEPT_VERSION, "1.0");
frame.addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1");
frame.addHeader(Stomp.Headers.Connect.LOGIN, this.defUser);
frame.addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
reply = conn.sendFrame(frame);
Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
// reply headers: version, session, server
Assert.assertEquals("1.0", reply.getHeader(Stomp.Headers.Error.VERSION));
conn.disconnect();
// case 3 accept-version=1.1, result: 1.1
conn = StompClientConnectionFactory.createClientConnection(v11Uri);
frame = conn.createFrame(Stomp.Commands.CONNECT);
frame.addHeader(Stomp.Headers.ACCEPT_VERSION, "1.1");
frame.addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1");
frame.addHeader(Stomp.Headers.Connect.LOGIN, this.defUser);
frame.addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
reply = conn.sendFrame(frame);
Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
// reply headers: version, session, server
Assert.assertEquals("1.1", reply.getHeader(Stomp.Headers.Error.VERSION));
conn.disconnect();
// case 4 accept-version=1.0,1.1,1.3, result 1.2
conn = StompClientConnectionFactory.createClientConnection(v11Uri);
frame = conn.createFrame(Stomp.Commands.CONNECT);
frame.addHeader(Stomp.Headers.ACCEPT_VERSION, "1.0,1.1,1.3");
frame.addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1");
frame.addHeader(Stomp.Headers.Connect.LOGIN, this.defUser);
frame.addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
reply = conn.sendFrame(frame);
Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
// reply headers: version, session, server
Assert.assertEquals("1.1", reply.getHeader(Stomp.Headers.Error.VERSION));
conn.disconnect();
// case 5 accept-version=1.3, result error
conn = StompClientConnectionFactory.createClientConnection(v11Uri);
frame = conn.createFrame(Stomp.Commands.CONNECT);
frame.addHeader(Stomp.Headers.ACCEPT_VERSION, "1.3");
frame.addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1");
frame.addHeader(Stomp.Headers.Connect.LOGIN, this.defUser);
frame.addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
reply = conn.sendFrame(frame);
Assert.assertEquals(Stomp.Responses.ERROR, reply.getCommand());
conn.disconnect();
System.out.println("Got error frame " + reply);
}
Aggregations