Search in sources :

Example 96 with ClientStompFrame

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

the class StompV11Test method testNegotiation.

@Test
public void testNegotiation() throws Exception {
    // case 1 accept-version absent. It is a 1.0 connect
    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);
    ClientStompFrame reply = conn.sendFrame(frame);
    assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
    // reply headers: version, session, server
    assertEquals(null, reply.getHeader("version"));
    conn.disconnect();
    // case 2 accept-version=1.0, result: 1.0
    conn = StompClientConnectionFactory.createClientConnection(uri);
    frame = conn.createFrame(Stomp.Commands.CONNECT).addHeader(Stomp.Headers.Connect.ACCEPT_VERSION, "1.0").addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1").addHeader(Stomp.Headers.Connect.LOGIN, this.defUser).addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
    reply = conn.sendFrame(frame);
    assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
    // reply headers: version, session, server
    assertEquals("1.0", reply.getHeader("version"));
    conn.disconnect();
    // case 3 accept-version=1.1, result: 1.1
    conn = StompClientConnectionFactory.createClientConnection(uri);
    frame = conn.createFrame(Stomp.Commands.CONNECT).addHeader(Stomp.Headers.Connect.ACCEPT_VERSION, "1.1").addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1").addHeader(Stomp.Headers.Connect.LOGIN, this.defUser).addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
    reply = conn.sendFrame(frame);
    assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
    // reply headers: version, session, server
    assertEquals("1.1", reply.getHeader("version"));
    conn.disconnect();
    // case 4 accept-version=1.0,1.1,1.2, result 1.1
    conn = StompClientConnectionFactory.createClientConnection(uri);
    frame = conn.createFrame(Stomp.Commands.CONNECT).addHeader(Stomp.Headers.Connect.ACCEPT_VERSION, "1.0,1.1,1.3").addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1").addHeader(Stomp.Headers.Connect.LOGIN, this.defUser).addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
    reply = conn.sendFrame(frame);
    assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
    // reply headers: version, session, server
    assertEquals("1.1", reply.getHeader("version"));
    conn.disconnect();
    // case 5 accept-version=1.2, result error
    conn = StompClientConnectionFactory.createClientConnection(uri);
    frame = conn.createFrame(Stomp.Commands.CONNECT).addHeader(Stomp.Headers.Connect.ACCEPT_VERSION, "1.3").addHeader(Stomp.Headers.Connect.HOST, "127.0.0.1").addHeader(Stomp.Headers.Connect.LOGIN, this.defUser).addHeader(Stomp.Headers.Connect.PASSCODE, this.defPass);
    reply = conn.sendFrame(frame);
    assertEquals(Stomp.Responses.ERROR, reply.getCommand());
    IntegrationTestLogger.LOGGER.info("Got error frame " + reply);
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) Test(org.junit.Test)

Example 97 with ClientStompFrame

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

the class StompV11Test method testNackWithWrongMessageId.

@Test
public void testNackWithWrongMessageId() throws Exception {
    conn.connect(defUser, defPass);
    subscribe(conn, "sub1", Stomp.Headers.Subscribe.AckModeValues.CLIENT);
    sendJmsMessage(getName());
    ClientStompFrame frame = conn.receiveFrame();
    frame.getHeader(Stomp.Headers.Message.MESSAGE_ID);
    nack(conn, "sub2", "someother");
    ClientStompFrame error = conn.receiveFrame();
    IntegrationTestLogger.LOGGER.info("Receiver error: " + error);
    unsubscribe(conn, "sub1");
    conn.disconnect();
    // 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)

Example 98 with ClientStompFrame

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

the class StompPluginTest method testSendAndReceive.

@Test
public void testSendAndReceive() throws Exception {
    URI uri = new URI(scheme + "://localhost:61613");
    StompClientConnection newConn = StompClientConnectionFactory.createClientConnection(uri);
    newConn.connect(defUser, defPass);
    subscribe(newConn, "a-sub");
    send(newConn, getQueuePrefix() + getQueueName(), "text/plain", "Hello World 1!");
    ClientStompFrame frame = newConn.receiveFrame();
    System.out.println("received " + frame);
    Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
    verifier.validatePluginMethodsAtLeast(1, MESSAGE_ACKED, BEFORE_SEND, AFTER_SEND, BEFORE_MESSAGE_ROUTE, AFTER_MESSAGE_ROUTE, BEFORE_DELIVER, AFTER_DELIVER);
    // unsub
    unsubscribe(newConn, "a-sub");
    newConn.disconnect();
    verifier.validatePluginMethodsEquals(0, MESSAGE_EXPIRED, BEFORE_DEPLOY_BRIDGE, AFTER_DEPLOY_BRIDGE, BEFORE_REMOVE_BINDING, AFTER_REMOVE_BINDING);
    verifier.validatePluginMethodsAtLeast(1, AFTER_CREATE_CONNECTION, AFTER_DESTROY_CONNECTION, BEFORE_CREATE_SESSION, AFTER_CREATE_SESSION, BEFORE_CLOSE_SESSION, AFTER_CLOSE_SESSION, BEFORE_CREATE_CONSUMER, AFTER_CREATE_CONSUMER, BEFORE_CLOSE_CONSUMER, AFTER_CLOSE_CONSUMER, BEFORE_CREATE_QUEUE, AFTER_CREATE_QUEUE, MESSAGE_ACKED, BEFORE_SEND, AFTER_SEND, BEFORE_MESSAGE_ROUTE, AFTER_MESSAGE_ROUTE, BEFORE_DELIVER, AFTER_DELIVER, BEFORE_ADD_ADDRESS, AFTER_ADD_ADDRESS, BEFORE_ADD_BINDING, AFTER_ADD_BINDING);
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) StompClientConnection(org.apache.activemq.artemis.tests.integration.stomp.util.StompClientConnection) URI(java.net.URI) Test(org.junit.Test)

Example 99 with ClientStompFrame

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

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

Example 100 with ClientStompFrame

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

the class StompV12Test 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.ACCEPT_VERSION, "1.0,1.1,1.2");
    ClientStompFrame reply = conn.sendFrame(frame);
    Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
    Assert.assertEquals("500,500", reply.getHeader(Stomp.Headers.Connect.HEART_BEAT));
    conn.disconnect();
    // heart-beat (500,1000)
    conn = (StompClientConnectionV12) 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.ACCEPT_VERSION, "1.0,1.1,1.2");
    reply = conn.sendFrame(frame);
    Assert.assertEquals(Stomp.Responses.CONNECTED, reply.getCommand());
    Assert.assertEquals("1000,500", reply.getHeader(Stomp.Headers.Connect.HEART_BEAT));
    conn.startPinger(500);
    Thread.sleep(10000);
    // now check the frame size
    int size = conn.getServerPingNumber();
    System.out.println("ping received: " + size);
    Assert.assertTrue("size: " + size, 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)

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