use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.
the class StompV12Test method testSendAndReceiveOnDifferentConnections.
@Test
public void testSendAndReceiveOnDifferentConnections() throws Exception {
conn.connect(defUser, defPass);
send(conn, getQueuePrefix() + getQueueName(), null, "Hello World");
StompClientConnection connV12_2 = StompClientConnectionFactory.createClientConnection(v11Uri);
connV12_2.connect(defUser, defPass);
subscribe(connV12_2, "sub1", Stomp.Headers.Subscribe.AckModeValues.AUTO);
ClientStompFrame frame = connV12_2.receiveFrame(2000);
Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
Assert.assertEquals("Hello World", frame.getBody());
conn.disconnect();
connV12_2.disconnect();
}
use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.
the class StompV12Test method testHeartBeat.
@Test
public void testHeartBeat() throws Exception {
StompClientConnection conn = StompClientConnectionFactory.createClientConnection(uri);
// no heart beat at all if heat-beat absent
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);
Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
Thread.sleep(5000);
Assert.assertEquals(0, conn.getFrameQueueSize());
conn.disconnect();
// no heart beat for (0,0)
conn = 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, "0,0").addHeader(Stomp.Headers.ACCEPT_VERSION, "1.0,1.1,1.2");
reply = conn.sendFrame(frame);
Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
Assert.assertEquals("0,30000", reply.getHeader(Stomp.Headers.Connect.HEART_BEAT));
Thread.sleep(5000);
Assert.assertEquals(0, conn.getFrameQueueSize());
conn.disconnect();
// heart-beat (1,0), should receive a min client ping accepted by server
conn = 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, "1,0").addHeader(Stomp.Headers.ACCEPT_VERSION, "1.0,1.2");
reply = conn.sendFrame(frame);
Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
Assert.assertEquals("0,500", reply.getHeader(Stomp.Headers.Connect.HEART_BEAT));
Thread.sleep(2000);
// send will fail
try {
send(conn, getQueuePrefix() + getQueueName(), "text/plain", "Hello World");
Assert.fail("connection should have been destroyed by now");
} catch (IOException e) {
// ignore
}
// heart-beat (1,0), start a ping, then send a message, should be ok.
conn = 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, "1,0").addHeader(Stomp.Headers.ACCEPT_VERSION, "1.0,1.1,1.2");
reply = conn.sendFrame(frame);
Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
Assert.assertEquals("0,500", reply.getHeader(Stomp.Headers.Connect.HEART_BEAT));
conn.startPinger(500);
Thread.sleep(2000);
// send will be ok
send(conn, getQueuePrefix() + getQueueName(), "text/plain", "Hello World");
conn.stopPinger();
conn.disconnect();
}
use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.
the class StompV12Test method testDurableSubscriber.
@Test
public void testDurableSubscriber() throws Exception {
conn.connect(defUser, defPass);
subscribe(conn, "sub1", "client", getName());
ClientStompFrame frame = subscribe(conn, "sub1", "client", getName());
Assert.assertTrue(frame.getCommand().equals(Stomp.Responses.ERROR));
waitDisconnect(conn);
Assert.assertFalse("Should be disconnected in STOMP 1.2 after ERROR", conn.isConnected());
}
use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.
the class StompV12Test method testHeaderContentType.
@Test
public void testHeaderContentType() throws Exception {
conn.connect(defUser, defPass);
send(conn, getQueuePrefix() + getQueueName(), "application/xml", "Hello World 1!");
// subscribe
StompClientConnection newConn = StompClientConnectionFactory.createClientConnection(v11Uri);
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("application/xml", frame.getHeader(Stomp.Headers.CONTENT_TYPE));
// 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 testHeadersPadding.
// padding shouldn't be trimmed
@Test
public void testHeadersPadding() throws Exception {
conn.connect(defUser, defPass);
String body = "<p>Hello World!</p>";
String cLen = String.valueOf(body.getBytes(StandardCharsets.UTF_8).length);
ClientStompFrame frame = conn.createFrame(Stomp.Commands.SEND).addHeader(Stomp.Headers.Subscribe.DESTINATION, getQueuePrefix() + getQueueName()).addHeader(Stomp.Headers.CONTENT_TYPE, "application/xml").addHeader(Stomp.Headers.CONTENT_LENGTH, cLen).addHeader(" header1", "value1 ").addHeader(" header2", "value2 ").addHeader("header3 ", " value3").addHeader(" header4 ", " value4 ").addHeader(" header 5 ", " value 5 ").addHeader("header6", "\t value\t 6 \t").setBody(body);
conn.sendFrame(frame);
// subscribe
StompClientConnection newConn = StompClientConnectionFactory.createClientConnection(uri);
newConn.connect(defUser, defPass);
subscribe(newConn, "a-sub");
frame = newConn.receiveFrame();
Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
Assert.assertEquals(body, frame.getBody());
System.out.println("received: " + frame);
Assert.assertEquals(null, frame.getHeader("header1"));
Assert.assertEquals("value1 ", frame.getHeader(" header1"));
Assert.assertEquals("value2 ", frame.getHeader(" header2"));
Assert.assertEquals(" value3", frame.getHeader("header3 "));
Assert.assertEquals(" value4 ", frame.getHeader(" header4 "));
Assert.assertEquals(" value 5 ", frame.getHeader(" header 5 "));
Assert.assertEquals("\t value\t 6 \t", frame.getHeader("header6"));
// unsub
unsubscribe(newConn, "a-sub");
newConn.disconnect();
}
Aggregations