Search in sources :

Example 56 with ClientStompFrame

use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.

the class StompV12Test method testTwoSubscribers.

@Test
public void testTwoSubscribers() throws Exception {
    conn.connect(defUser, defPass, CLIENT_ID);
    subscribeTopic(conn, "sub1", Stomp.Headers.Subscribe.AckModeValues.AUTO, null);
    StompClientConnection newConn = StompClientConnectionFactory.createClientConnection(v11Uri);
    newConn.connect(defUser, defPass, "myclientid2");
    subscribeTopic(newConn, "sub2", Stomp.Headers.Subscribe.AckModeValues.AUTO, null);
    send(conn, getTopicPrefix() + getTopicName(), null, "Hello World");
    // receive message from socket
    ClientStompFrame frame = conn.receiveFrame(1000);
    System.out.println("received frame : " + frame);
    Assert.assertEquals("Hello World", frame.getBody());
    Assert.assertEquals("sub1", frame.getHeader(Stomp.Headers.Message.SUBSCRIPTION));
    frame = newConn.receiveFrame(1000);
    System.out.println("received 2 frame : " + frame);
    Assert.assertEquals("Hello World", frame.getBody());
    Assert.assertEquals("sub2", frame.getHeader(Stomp.Headers.Message.SUBSCRIPTION));
    // remove suscription
    unsubscribe(conn, "sub1", true);
    unsubscribe(newConn, "sub2", true);
    conn.disconnect();
    newConn.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 57 with ClientStompFrame

use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.

the class StompV12Test method testSendAndReceiveWithEscapedCharactersInSenderId.

@Test
public void testSendAndReceiveWithEscapedCharactersInSenderId() throws Exception {
    conn.connect(defUser, defPass);
    ClientStompFrame response = send(conn, getQueuePrefix() + getQueueName(), "text/plain", "Hello World 1!");
    Assert.assertNull(response);
    // subscribe
    subscribe(conn, "ID\\cMYMACHINE-50616-635482262727823605-1\\c1\\c1\\c1");
    ClientStompFrame frame = conn.receiveFrame();
    System.out.println("Received: " + frame);
    Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
    Assert.assertEquals("ID:MYMACHINE-50616-635482262727823605-1:1:1:1", frame.getHeader(Stomp.Headers.Message.SUBSCRIPTION));
    Assert.assertNotNull(frame.getHeader(Stomp.Headers.Message.MESSAGE_ID));
    Assert.assertEquals(getQueuePrefix() + getQueueName(), frame.getHeader(Stomp.Headers.Subscribe.DESTINATION));
    Assert.assertEquals("Hello World 1!", frame.getBody());
    // unsub
    unsubscribe(conn, "ID\\cMYMACHINE-50616-635482262727823605-1\\c1\\c1\\c1");
    conn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) Test(org.junit.Test)

Example 58 with ClientStompFrame

use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.

the class StompV12Test method testSubscribeWithAutoAckAndSelector.

@Test
public void testSubscribeWithAutoAckAndSelector() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, "sub1", Stomp.Headers.Subscribe.AckModeValues.AUTO, null, "foo = 'zzz'");
    sendJmsMessage("Ignored message", "foo", "1234");
    sendJmsMessage("Real message", "foo", "zzz");
    ClientStompFrame frame = conn.receiveFrame();
    Assert.assertTrue("Should have received the real message but got: " + frame, frame.getBody().equals("Real message"));
    conn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) Test(org.junit.Test)

Example 59 with ClientStompFrame

use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.

the class StompV12Test method testBeginSameTransactionTwice.

// ----------------Note: tests below are adapted from StompTest
@Test
public void testBeginSameTransactionTwice() throws Exception {
    conn.connect(defUser, defPass);
    beginTransaction(conn, "tx1");
    beginTransaction(conn, "tx1");
    ClientStompFrame f = conn.receiveFrame();
    Assert.assertTrue(f.getCommand().equals(Stomp.Responses.ERROR));
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) Test(org.junit.Test)

Example 60 with ClientStompFrame

use of org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame in project activemq-artemis by apache.

the class StompV12Test method testAckWithWrongMessageId.

@Test
public void testAckWithWrongMessageId() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, "sub1", "client");
    sendJmsMessage(getName());
    ClientStompFrame frame = conn.receiveFrame();
    Assert.assertNotNull(frame);
    ack(conn, "someother");
    ClientStompFrame error = conn.receiveFrame();
    System.out.println("Receiver error: " + error);
    waitDisconnect(conn);
    Assert.assertFalse("Should be disconnected in STOMP 1.2 after ERROR", conn.isConnected());
    // message should still there
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNotNull(message);
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) BytesMessage(javax.jms.BytesMessage) 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