Search in sources :

Example 71 with ClientStompFrame

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

the class StompV11Test 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);
    assertNull(frame);
    conn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) Test(org.junit.Test)

Example 72 with ClientStompFrame

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

the class StompV11Test method testRedeliveryWithClientAck.

@Test
public void testRedeliveryWithClientAck() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, "subscriptionId", Stomp.Headers.Subscribe.AckModeValues.CLIENT);
    sendJmsMessage(getName());
    ClientStompFrame frame = conn.receiveFrame();
    assertTrue(frame.getCommand().equals(Stomp.Responses.MESSAGE));
    conn.disconnect();
    // message should be received since message was not acknowledged
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertTrue(message.getJMSRedelivered());
}
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)

Example 73 with ClientStompFrame

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

the class StompV11Test method testNackWithWrongSubId.

@Test
public void testNackWithWrongSubId() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, "sub1", Stomp.Headers.Subscribe.AckModeValues.CLIENT);
    sendJmsMessage(getName());
    ClientStompFrame frame = conn.receiveFrame();
    String messageID = frame.getHeader(Stomp.Headers.Message.MESSAGE_ID);
    nack(conn, "sub2", messageID);
    ClientStompFrame error = conn.receiveFrame();
    IntegrationTestLogger.LOGGER.info("Receiver error: " + error);
    unsubscribe(conn, "sub1");
    conn.disconnect();
    // message should be 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) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Test(org.junit.Test)

Example 74 with ClientStompFrame

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

the class StompV11Test 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.Connect.ACCEPT_VERSION, "1.0,1.1");
    ClientStompFrame reply = conn.sendFrame(frame);
    assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
    assertEquals("500,500", reply.getHeader(Stomp.Headers.Connect.HEART_BEAT));
    conn.disconnect();
    // heart-beat (500,1000)
    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, "500,1000").addHeader(Stomp.Headers.Connect.ACCEPT_VERSION, "1.0,1.1");
    reply = conn.sendFrame(frame);
    assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
    assertEquals("1000,500", reply.getHeader(Stomp.Headers.Connect.HEART_BEAT));
    IntegrationTestLogger.LOGGER.info("========== start pinger!");
    conn.startPinger(500);
    Thread.sleep(10000);
    // now check the frame size
    int size = conn.getServerPingNumber();
    IntegrationTestLogger.LOGGER.info("ping received: " + size);
    assertTrue(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();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) Test(org.junit.Test)

Example 75 with ClientStompFrame

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

the class StompV11Test method testAckModeClientIndividual.

@Test
public void testAckModeClientIndividual() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, "sub1", "client-individual");
    int num = 50;
    // send a bunch of messages
    for (int i = 0; i < num; i++) {
        this.sendJmsMessage("client-individual-ack" + i);
    }
    ClientStompFrame frame = null;
    for (int i = 0; i < num; i++) {
        frame = conn.receiveFrame();
        assertNotNull(frame);
        IntegrationTestLogger.LOGGER.info(i + " == received: " + frame);
        // ack on even numbers
        if (i % 2 == 0) {
            ack(conn, "sub1", frame);
        }
    }
    unsubscribe(conn, "sub1");
    conn.disconnect();
    // no messages can be received.
    MessageConsumer consumer = session.createConsumer(queue);
    TextMessage message = null;
    for (int i = 0; i < num / 2; i++) {
        message = (TextMessage) consumer.receive(1000);
        Assert.assertNotNull(message);
        IntegrationTestLogger.LOGGER.info("Legal: " + message.getText());
    }
    message = (TextMessage) consumer.receive(1000);
    Assert.assertNull(message);
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) 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