Search in sources :

Example 51 with ClientStompFrame

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

the class StompV12Test method testAckModeClient2.

@Test
public void testAckModeClient2() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, "sub1", "client");
    int num = 50;
    // send a bunch of messages
    for (int i = 0; i < num; i++) {
        this.sendJmsMessage("client-ack" + i);
    }
    ClientStompFrame frame = null;
    for (int i = 0; i < num; i++) {
        frame = conn.receiveFrame();
        Assert.assertNotNull(frame);
        // ack the 49th
        if (i == num - 2) {
            ack(conn, frame);
        }
    }
    unsubscribe(conn, "sub1");
    conn.disconnect();
    // one can be received.
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(1000);
    Assert.assertNotNull(message);
    message = consumer.receive(1000);
    Assert.assertNull(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)

Example 52 with ClientStompFrame

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

the class StompV12Test method testTransactionRollback.

@Test
public void testTransactionRollback() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    conn.connect(defUser, defPass);
    beginTransaction(conn, "tx1");
    ClientStompFrame frame = conn.createFrame(Stomp.Commands.SEND).addHeader(Stomp.Headers.Subscribe.DESTINATION, getQueuePrefix() + getQueueName()).addHeader(Stomp.Headers.TRANSACTION, "tx1").setBody("first message");
    conn.sendFrame(frame);
    // rollback first message
    abortTransaction(conn, "tx1");
    beginTransaction(conn, "tx1");
    frame = conn.createFrame(Stomp.Commands.SEND).addHeader(Stomp.Headers.Subscribe.DESTINATION, getQueuePrefix() + getQueueName()).addHeader(Stomp.Headers.TRANSACTION, "tx1").setBody("second message");
    conn.sendFrame(frame);
    commitTransaction(conn, "tx1", true);
    // only second msg should be received since first msg was rolled back
    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message);
    Assert.assertEquals("second message", message.getText());
    conn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 53 with ClientStompFrame

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

the class StompV12Test 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();
        Assert.assertNotNull(frame);
        System.out.println(i + " == received: " + frame);
        // ack on even numbers
        if (i % 2 == 0) {
            ack(conn, 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);
        System.out.println("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)

Example 54 with ClientStompFrame

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

the class StompV12Test method testTransactionCommit.

@Test
public void testTransactionCommit() throws Exception {
    MessageConsumer consumer = session.createConsumer(queue);
    conn.connect(defUser, defPass);
    beginTransaction(conn, "tx1");
    ClientStompFrame frame = conn.createFrame(Stomp.Commands.SEND).addHeader(Stomp.Headers.Subscribe.DESTINATION, getQueuePrefix() + getQueueName()).addHeader(Stomp.Headers.TRANSACTION, "tx1").addHeader(Stomp.Headers.RECEIPT_REQUESTED, "123").setBody("Hello World");
    frame = conn.sendFrame(frame);
    Assert.assertEquals("123", frame.getHeader("receipt-id"));
    // check the message is not committed
    Assert.assertNull(consumer.receive(100));
    commitTransaction(conn, "tx1", true);
    Message message = consumer.receive(1000);
    Assert.assertNotNull("Should have received a message", message);
    conn.disconnect();
}
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 55 with ClientStompFrame

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

the class StompV12Test method testNegotiation.

@Test
public void testNegotiation() throws Exception {
    StompClientConnection conn = StompClientConnectionFactory.createClientConnection(v10Uri);
    // case 1 accept-version absent. It is a 1.0 connect
    ClientStompFrame frame = conn.createFrame(Stomp.Commands.CONNECT);
    frame.addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1");
    frame.addHeader(Stomp.Headers.Connect.LOGIN, this.defUser);
    frame.addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
    ClientStompFrame reply = conn.sendFrame(frame);
    Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
    // reply headers: version, session, server
    Assert.assertEquals(null, reply.getHeader(Stomp.Headers.Error.VERSION));
    conn.disconnect();
    // case 2 accept-version=1.0, result: 1.0
    conn = StompClientConnectionFactory.createClientConnection(v11Uri);
    frame = conn.createFrame(Stomp.Commands.CONNECT);
    frame.addHeader(Stomp.Headers.ACCEPT_VERSION, "1.0");
    frame.addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1");
    frame.addHeader(Stomp.Headers.Connect.LOGIN, this.defUser);
    frame.addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
    reply = conn.sendFrame(frame);
    Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
    // reply headers: version, session, server
    Assert.assertEquals("1.0", reply.getHeader(Stomp.Headers.Error.VERSION));
    conn.disconnect();
    // case 3 accept-version=1.1, result: 1.1
    conn = StompClientConnectionFactory.createClientConnection(v11Uri);
    frame = conn.createFrame(Stomp.Commands.CONNECT);
    frame.addHeader(Stomp.Headers.ACCEPT_VERSION, "1.1");
    frame.addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1");
    frame.addHeader(Stomp.Headers.Connect.LOGIN, this.defUser);
    frame.addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
    reply = conn.sendFrame(frame);
    Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
    // reply headers: version, session, server
    Assert.assertEquals("1.1", reply.getHeader(Stomp.Headers.Error.VERSION));
    conn.disconnect();
    // case 4 accept-version=1.0,1.1,1.3, result 1.2
    conn = StompClientConnectionFactory.createClientConnection(v11Uri);
    frame = conn.createFrame(Stomp.Commands.CONNECT);
    frame.addHeader(Stomp.Headers.ACCEPT_VERSION, "1.0,1.1,1.3");
    frame.addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1");
    frame.addHeader(Stomp.Headers.Connect.LOGIN, this.defUser);
    frame.addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
    reply = conn.sendFrame(frame);
    Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
    // reply headers: version, session, server
    Assert.assertEquals("1.1", reply.getHeader(Stomp.Headers.Error.VERSION));
    conn.disconnect();
    // case 5 accept-version=1.3, result error
    conn = StompClientConnectionFactory.createClientConnection(v11Uri);
    frame = conn.createFrame(Stomp.Commands.CONNECT);
    frame.addHeader(Stomp.Headers.ACCEPT_VERSION, "1.3");
    frame.addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1");
    frame.addHeader(Stomp.Headers.Connect.LOGIN, this.defUser);
    frame.addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
    reply = conn.sendFrame(frame);
    Assert.assertEquals(Stomp.Responses.ERROR, reply.getCommand());
    conn.disconnect();
    System.out.println("Got error frame " + reply);
}
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)

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