Search in sources :

Example 91 with ClientStompFrame

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();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) Test(org.junit.Test)

Example 92 with ClientStompFrame

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"));
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) StompClientConnectionV11(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnectionV11) StompClientConnection(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection) Test(org.junit.Test)

Example 93 with ClientStompFrame

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();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) StompClientConnection(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Test(org.junit.Test)

Example 94 with ClientStompFrame

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();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) StompClientConnection(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection) Test(org.junit.Test)

Example 95 with ClientStompFrame

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);
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) ClosedChannelException(java.nio.channels.ClosedChannelException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

ClientStompFrame (org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame)195 Test (org.junit.Test)173 MessageConsumer (javax.jms.MessageConsumer)67 TextMessage (javax.jms.TextMessage)62 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)51 BytesMessage (javax.jms.BytesMessage)43 StompClientConnection (org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection)41 Message (javax.jms.Message)37 IOException (java.io.IOException)7 URI (java.net.URI)5 MessageProducer (javax.jms.MessageProducer)5 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)4 ClosedChannelException (java.nio.channels.ClosedChannelException)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)2 LargeMessageTestBase (org.apache.activemq.artemis.tests.integration.largemessage.LargeMessageTestBase)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1