use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.
the class StompV11Test method testNegotiation.
@Test
public void testNegotiation() throws Exception {
// case 1 accept-version absent. It is a 1.0 connect
ClientStompFrame frame = conn.createFrame(Stomp.Commands.CONNECT).addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1").addHeader(Stomp.Headers.Connect.LOGIN, this.defUser).addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
ClientStompFrame reply = conn.sendFrame(frame);
assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
// reply headers: version, session, server
assertEquals(null, reply.getHeader("version"));
conn.disconnect();
// case 2 accept-version=1.0, result: 1.0
conn = StompClientConnectionFactory.createClientConnection(uri);
frame = conn.createFrame(Stomp.Commands.CONNECT).addHeader(Stomp.Headers.Connect.ACCEPT_VERSION, "1.0").addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1").addHeader(Stomp.Headers.Connect.LOGIN, this.defUser).addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
reply = conn.sendFrame(frame);
assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
// reply headers: version, session, server
assertEquals("1.0", reply.getHeader("version"));
conn.disconnect();
// case 3 accept-version=1.1, result: 1.1
conn = StompClientConnectionFactory.createClientConnection(uri);
frame = conn.createFrame(Stomp.Commands.CONNECT).addHeader(Stomp.Headers.Connect.ACCEPT_VERSION, "1.1").addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1").addHeader(Stomp.Headers.Connect.LOGIN, this.defUser).addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
reply = conn.sendFrame(frame);
assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
// reply headers: version, session, server
assertEquals("1.1", reply.getHeader("version"));
conn.disconnect();
// case 4 accept-version=1.0,1.1,1.2, result 1.1
conn = StompClientConnectionFactory.createClientConnection(uri);
frame = conn.createFrame(Stomp.Commands.CONNECT).addHeader(Stomp.Headers.Connect.ACCEPT_VERSION, "1.0,1.1,1.3").addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1").addHeader(Stomp.Headers.Connect.LOGIN, this.defUser).addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
reply = conn.sendFrame(frame);
assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
// reply headers: version, session, server
assertEquals("1.1", reply.getHeader("version"));
conn.disconnect();
// case 5 accept-version=1.2, result error
conn = StompClientConnectionFactory.createClientConnection(uri);
frame = conn.createFrame(Stomp.Commands.CONNECT).addHeader(Stomp.Headers.Connect.ACCEPT_VERSION, "1.3").addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1").addHeader(Stomp.Headers.Connect.LOGIN, this.defUser).addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
reply = conn.sendFrame(frame);
assertEquals(Stomp.Responses.ERROR, reply.getCommand());
IntegrationTestLogger.LOGGER.info("Got error frame " + reply);
}
use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.
the class StompV11Test method testNackWithWrongMessageId.
@Test
public void testNackWithWrongMessageId() throws Exception {
conn.connect(defUser, defPass);
subscribe(conn, "sub1", Stomp.Headers.Subscribe.AckModeValues.CLIENT);
sendJmsMessage(getName());
ClientStompFrame frame = conn.receiveFrame();
frame.getHeader(Stomp.Headers.Message.MESSAGE_ID);
nack(conn, "sub2", "someother");
ClientStompFrame error = conn.receiveFrame();
IntegrationTestLogger.LOGGER.info("Receiver error: " + error);
unsubscribe(conn, "sub1");
conn.disconnect();
// 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 StompPluginTest method testSendAndReceive.
@Test
public void testSendAndReceive() throws Exception {
URI uri = new URI(scheme + "://localhost:61613");
StompClientConnection newConn = StompClientConnectionFactory.createClientConnection(uri);
newConn.connect(defUser, defPass);
subscribe(newConn, "a-sub");
send(newConn, getQueuePrefix() + getQueueName(), "text/plain", "Hello World 1!");
ClientStompFrame frame = newConn.receiveFrame();
System.out.println("received " + frame);
Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
verifier.validatePluginMethodsAtLeast(1, MESSAGE_ACKED, BEFORE_SEND, AFTER_SEND, BEFORE_MESSAGE_ROUTE, AFTER_MESSAGE_ROUTE, BEFORE_DELIVER, AFTER_DELIVER);
// unsub
unsubscribe(newConn, "a-sub");
newConn.disconnect();
verifier.validatePluginMethodsEquals(0, MESSAGE_EXPIRED, BEFORE_DEPLOY_BRIDGE, AFTER_DEPLOY_BRIDGE, BEFORE_REMOVE_BINDING, AFTER_REMOVE_BINDING);
verifier.validatePluginMethodsAtLeast(1, AFTER_CREATE_CONNECTION, AFTER_DESTROY_CONNECTION, BEFORE_CREATE_SESSION, AFTER_CREATE_SESSION, BEFORE_CLOSE_SESSION, AFTER_CLOSE_SESSION, BEFORE_CREATE_CONSUMER, AFTER_CREATE_CONSUMER, BEFORE_CLOSE_CONSUMER, AFTER_CLOSE_CONSUMER, BEFORE_CREATE_QUEUE, AFTER_CREATE_QUEUE, MESSAGE_ACKED, BEFORE_SEND, AFTER_SEND, BEFORE_MESSAGE_ROUTE, AFTER_MESSAGE_ROUTE, BEFORE_DELIVER, AFTER_DELIVER, BEFORE_ADD_ADDRESS, AFTER_ADD_ADDRESS, BEFORE_ADD_BINDING, AFTER_ADD_BINDING);
}
use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.
the class StompV12Test method testUnsubscribe.
@Test
public void testUnsubscribe() throws Exception {
conn.connect(defUser, defPass);
subscribe(conn, "sub1", Stomp.Headers.Subscribe.AckModeValues.AUTO);
// send a message to our queue
sendJmsMessage("first message");
// receive message from socket
ClientStompFrame frame = conn.receiveFrame();
Assert.assertTrue(frame.getCommand().equals(Stomp.Responses.MESSAGE));
// remove suscription
unsubscribe(conn, "sub1", true);
// send a message to our queue
sendJmsMessage("second message");
frame = conn.receiveFrame(1000);
Assert.assertNull(frame);
conn.disconnect();
}
use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.
the class StompV12Test method testHeartBeat2.
// server ping
@Test
public void testHeartBeat2() throws Exception {
// heart-beat (1,1)
ClientStompFrame frame = conn.createFrame(Stomp.Commands.CONNECT).addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1").addHeader(Stomp.Headers.Connect.LOGIN, this.defUser).addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass).addHeader(Stomp.Headers.Connect.HEART_BEAT, "1,1").addHeader(Stomp.Headers.ACCEPT_VERSION, "1.0,1.1,1.2");
ClientStompFrame reply = conn.sendFrame(frame);
Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
Assert.assertEquals("500,500", reply.getHeader(Stomp.Headers.Connect.HEART_BEAT));
conn.disconnect();
// heart-beat (500,1000)
conn = (StompClientConnectionV12) StompClientConnectionFactory.createClientConnection(uri);
frame = conn.createFrame(Stomp.Commands.CONNECT).addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1").addHeader(Stomp.Headers.Connect.LOGIN, this.defUser).addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass).addHeader(Stomp.Headers.Connect.HEART_BEAT, "500,1000").addHeader(Stomp.Headers.ACCEPT_VERSION, "1.0,1.1,1.2");
reply = conn.sendFrame(frame);
Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
Assert.assertEquals("1000,500", reply.getHeader(Stomp.Headers.Connect.HEART_BEAT));
conn.startPinger(500);
Thread.sleep(10000);
// now check the frame size
int size = conn.getServerPingNumber();
System.out.println("ping received: " + size);
Assert.assertTrue("size: " + size, size > 5);
// now server side should be disconnected because we didn't send ping for 2 sec
// send will be ok
send(conn, getQueuePrefix() + getQueueName(), "text/plain", "Hello World");
conn.disconnect();
}
Aggregations