use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.
the class StompV11Test method testSubscribeToTopicWithNoLocal.
@Test
public void testSubscribeToTopicWithNoLocal() throws Exception {
conn.connect(defUser, defPass);
subscribeTopic(conn, "sub1", null, null, true, true);
send(conn, getTopicPrefix() + getTopicName(), null, "Hello World");
ClientStompFrame frame = conn.receiveFrame(2000);
assertNull(frame);
// send message on another JMS connection => it should be received
sendJmsMessage(getName(), topic);
frame = conn.receiveFrame();
Assert.assertTrue(frame.getCommand().equals(Stomp.Responses.MESSAGE));
Assert.assertTrue(frame.getHeader(Stomp.Headers.Message.DESTINATION).equals(getTopicPrefix() + getTopicName()));
Assert.assertTrue(frame.getBody().equals(getName()));
unsubscribe(conn, "sub1");
conn.disconnect();
}
use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.
the class StompV11Test method testConnection.
@Test
public void testConnection() throws Exception {
server.getActiveMQServer().getConfiguration().setSecurityEnabled(true);
StompClientConnection connection = StompClientConnectionFactory.createClientConnection(v10Uri);
connection.connect(defUser, defPass);
assertTrue(connection.isConnected());
assertEquals("1.0", connection.getVersion());
connection.disconnect();
connection = StompClientConnectionFactory.createClientConnection(uri);
connection.connect(defUser, defPass);
assertTrue(connection.isConnected());
assertEquals("1.1", connection.getVersion());
connection.disconnect();
connection = StompClientConnectionFactory.createClientConnection(uri);
connection.connect();
assertFalse(connection.isConnected());
// new way of connection
StompClientConnectionV11 conn = (StompClientConnectionV11) StompClientConnectionFactory.createClientConnection(uri);
conn.connect1(defUser, defPass);
assertTrue(conn.isConnected());
conn.disconnect();
// invalid user
conn = (StompClientConnectionV11) StompClientConnectionFactory.createClientConnection(uri);
ClientStompFrame frame = conn.connect("invaliduser", defPass);
assertFalse(conn.isConnected());
assertTrue(Stomp.Responses.ERROR.equals(frame.getCommand()));
assertTrue(frame.getBody().contains("Security Error occurred"));
}
use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.
the class StompV11Test method testSendAndReceive.
@Test
public void testSendAndReceive() throws Exception {
conn.connect(defUser, defPass);
ClientStompFrame response = send(conn, getQueuePrefix() + getQueueName(), "text/plain", "Hello World 1!");
assertNull(response);
String uuid = UUID.randomUUID().toString();
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();
IntegrationTestLogger.LOGGER.info("received " + frame);
assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
assertEquals("a-sub", frame.getHeader(Stomp.Headers.Ack.SUBSCRIPTION));
assertNotNull(frame.getHeader(Stomp.Headers.Message.MESSAGE_ID));
assertEquals(getQueuePrefix() + getQueueName(), frame.getHeader(Stomp.Headers.Message.DESTINATION));
assertEquals("Hello World 1!", frame.getBody());
frame = newConn.receiveFrame();
IntegrationTestLogger.LOGGER.info("received " + frame);
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 StompV11Test method testSendAndReceiveOnDifferentConnections.
@Test
public void testSendAndReceiveOnDifferentConnections() throws Exception {
conn.connect(defUser, defPass);
send(conn, getQueuePrefix() + getQueueName(), null, "Hello World");
StompClientConnection connV11_2 = StompClientConnectionFactory.createClientConnection(uri);
connV11_2.connect(defUser, defPass);
subscribe(connV11_2, "sub1", Stomp.Headers.Subscribe.AckModeValues.AUTO);
ClientStompFrame frame = connV11_2.receiveFrame(2000);
assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
assertEquals("Hello World", frame.getBody());
conn.disconnect();
connV11_2.disconnect();
}
use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.
the class StompV11Test method testDisconnectAndError.
@Test
public void testDisconnectAndError() throws Exception {
conn.connect(defUser, defPass);
subscribe(conn, getName(), Stomp.Headers.Subscribe.AckModeValues.CLIENT);
String uuid = UUID.randomUUID().toString();
ClientStompFrame frame = conn.createFrame(Stomp.Commands.DISCONNECT).addHeader(Stomp.Headers.RECEIPT_REQUESTED, uuid);
ClientStompFrame result = conn.sendFrame(frame);
if (result == null || (!Stomp.Responses.RECEIPT.equals(result.getCommand())) || (!uuid.equals(result.getHeader(Stomp.Headers.Response.RECEIPT_ID)))) {
fail("Disconnect failed! " + result);
}
final CountDownLatch latch = new CountDownLatch(1);
Thread thr = new Thread() {
@Override
public void run() {
while (latch.getCount() != 0) {
try {
send(conn, getQueuePrefix() + getQueueName(), null, "Hello World");
Thread.sleep(500);
} catch (InterruptedException e) {
// retry
} catch (ClosedChannelException e) {
// ok.
latch.countDown();
break;
} catch (IOException e) {
// ok.
latch.countDown();
break;
} finally {
conn.destroy();
}
}
}
};
thr.start();
latch.await(10, TimeUnit.SECONDS);
long count = latch.getCount();
if (count != 0) {
latch.countDown();
}
thr.join();
assertTrue("Server failed to disconnect.", count == 0);
}
Aggregations