Search in sources :

Example 86 with ConnectionInfo

use of org.apache.activemq.command.ConnectionInfo in project activemq-artemis by apache.

the class BrokerTestSupport method createConnectionInfo.

protected ConnectionInfo createConnectionInfo() throws Exception {
    ConnectionInfo info = new ConnectionInfo();
    info.setConnectionId(new ConnectionId("connection:" + (++idGenerator)));
    info.setClientId(info.getConnectionId().getValue());
    return info;
}
Also used : ConnectionId(org.apache.activemq.command.ConnectionId) ConnectionInfo(org.apache.activemq.command.ConnectionInfo)

Example 87 with ConnectionInfo

use of org.apache.activemq.command.ConnectionInfo in project activemq-artemis by apache.

the class DoubleSubscriptionTest method testDoubleSubscription.

public void testDoubleSubscription() throws Exception {
    // Start a normal consumer on the remote broker
    StubConnection connection1 = createRemoteConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.request(consumerInfo1);
    // Start a normal producer on a remote broker
    StubConnection connection2 = createRemoteConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ProducerInfo producerInfo2 = createProducerInfo(sessionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(producerInfo2);
    // Send a message to make sure the basics are working
    connection2.request(createMessage(producerInfo2, destination, DeliveryMode.PERSISTENT));
    Message m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNoMessagesLeft(connection1);
    connection1.send(createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE));
    // Send a message to sit on the broker while we mess with it
    connection2.request(createMessage(producerInfo2, destination, DeliveryMode.PERSISTENT));
    // Now we're going to resend the same consumer commands again and see if
    // the broker
    // can handle it.
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.request(consumerInfo1);
    // After this there should be 2 messages on the broker...
    connection2.request(createMessage(producerInfo2, destination, DeliveryMode.PERSISTENT));
    // ... let's start a fresh consumer...
    connection1.stop();
    StubConnection connection3 = createRemoteConnection();
    ConnectionInfo connectionInfo3 = createConnectionInfo();
    SessionInfo sessionInfo3 = createSessionInfo(connectionInfo3);
    ConsumerInfo consumerInfo3 = createConsumerInfo(sessionInfo3, destination);
    connection3.send(connectionInfo3);
    connection3.send(sessionInfo3);
    connection3.request(consumerInfo3);
    // ... and then grab the 2 that should be there.
    assertNotNull(receiveMessage(connection3));
    assertNotNull(receiveMessage(connection3));
    assertNoMessagesLeft(connection3);
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) ProducerInfo(org.apache.activemq.command.ProducerInfo) Message(org.apache.activemq.command.Message) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo)

Example 88 with ConnectionInfo

use of org.apache.activemq.command.ConnectionInfo in project activemq-artemis by apache.

the class MessageExpirationTest method testMessagesInSubscriptionPendingListExpire.

public void testMessagesInSubscriptionPendingListExpire() throws Exception {
    // Start a producer and consumer
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    destination = createDestinationInfo(connection, connectionInfo, destinationType);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    consumerInfo.setPrefetchSize(1);
    connection.send(consumerInfo);
    // m1 and m3 should not expire.. but the others should.
    Message m1 = createMessage(producerInfo, destination, deliveryMode);
    connection.send(m1);
    connection.send(createMessage(producerInfo, destination, deliveryMode, 1000));
    Message m3 = createMessage(producerInfo, destination, deliveryMode);
    connection.send(m3);
    connection.send(createMessage(producerInfo, destination, deliveryMode, 1000));
    // Make sure only 1 message was delivered due to prefetch == 1
    Message m = receiveMessage(connection);
    assertNotNull(m);
    assertEquals(m1.getMessageId(), m.getMessageId());
    assertNoMessagesLeft(connection);
    // Sleep before we ack so that the messages expire on the pending list..
    Thread.sleep(1500);
    connection.send(createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE));
    // 2nd message received should be m3.. it should have expired 2nd
    // message sent.
    m = receiveMessage(connection);
    assertNotNull(m);
    assertEquals(m3.getMessageId(), m.getMessageId());
    connection.send(createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE));
    // And there should be no messages left now..
    assertNoMessagesLeft(connection);
    connection.send(closeConnectionInfo(connectionInfo));
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo)

Example 89 with ConnectionInfo

use of org.apache.activemq.command.ConnectionInfo in project activemq-artemis by apache.

the class MessageExpirationTest method testMessagesInLongTransactionExpire.

public void testMessagesInLongTransactionExpire() throws Exception {
    // Start a producer and consumer
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    destination = createDestinationInfo(connection, connectionInfo, destinationType);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    consumerInfo.setPrefetchSize(1000);
    connection.send(consumerInfo);
    // Start the tx..
    LocalTransactionId txid = createLocalTransaction(sessionInfo);
    connection.send(createBeginTransaction(connectionInfo, txid));
    // m1 and m3 should not expire.. but the others should.
    Message m1 = createMessage(producerInfo, destination, deliveryMode);
    m1.setTransactionId(txid);
    connection.send(m1);
    Message m = createMessage(producerInfo, destination, deliveryMode, 1000);
    m.setTransactionId(txid);
    connection.send(m);
    Message m3 = createMessage(producerInfo, destination, deliveryMode);
    m3.setTransactionId(txid);
    connection.send(m3);
    m = createMessage(producerInfo, destination, deliveryMode, 1000);
    m.setTransactionId(txid);
    connection.send(m);
    // Sleep before we commit so that the messages expire on the commit
    // list..
    Thread.sleep(1500);
    connection.send(createCommitTransaction1Phase(connectionInfo, txid));
    m = receiveMessage(connection);
    assertNotNull(m);
    assertEquals(m1.getMessageId(), m.getMessageId());
    connection.send(createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE));
    // 2nd message received should be m3.. it should have expired 2nd
    // message sent.
    m = receiveMessage(connection);
    assertNotNull(m);
    assertEquals(m3.getMessageId(), m.getMessageId());
    connection.send(createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE));
    // And there should be no messages left now..
    assertNoMessagesLeft(connection);
    connection.send(closeConnectionInfo(connectionInfo));
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) LocalTransactionId(org.apache.activemq.command.LocalTransactionId) Message(org.apache.activemq.command.Message) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo)

Example 90 with ConnectionInfo

use of org.apache.activemq.command.ConnectionInfo in project activemq-artemis by apache.

the class MessageExpirationTest method testMessagesWaitingForUsageDecreaseExpire.

public void testMessagesWaitingForUsageDecreaseExpire() throws Exception {
    // Start a producer
    final StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    final ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    // Start a consumer..
    final StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    destination = createDestinationInfo(connection2, connectionInfo2, destinationType);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(1);
    connection2.request(consumerInfo2);
    // Reduce the limit so that only 1 message can flow through the broker
    // at a time.
    broker.getSystemUsage().getMemoryUsage().setLimit(1);
    final Message m1 = createMessage(producerInfo, destination, deliveryMode);
    final Message m2 = createMessage(producerInfo, destination, deliveryMode, 1000);
    final Message m3 = createMessage(producerInfo, destination, deliveryMode);
    final Message m4 = createMessage(producerInfo, destination, deliveryMode, 1000);
    // Produce in an async thread since the producer will be getting blocked
    // by the usage manager..
    new Thread() {

        @Override
        public void run() {
            // m1 and m3 should not expire.. but the others should.
            try {
                connection.send(m1);
                connection.send(m2);
                connection.send(m3);
                connection.send(m4);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }.start();
    // Make sure only 1 message was delivered due to prefetch == 1
    Message m = receiveMessage(connection2);
    assertNotNull(m);
    assertEquals(m1.getMessageId(), m.getMessageId());
    assertNoMessagesLeft(connection);
    // Sleep before we ack so that the messages expire on the usage manager
    Thread.sleep(1500);
    connection2.send(createAck(consumerInfo2, m, 1, MessageAck.STANDARD_ACK_TYPE));
    // 2nd message received should be m3.. it should have expired 2nd
    // message sent.
    m = receiveMessage(connection2);
    assertNotNull(m);
    assertEquals(m3.getMessageId(), m.getMessageId());
    // Sleep before we ack so that the messages expire on the usage manager
    Thread.sleep(1500);
    connection2.send(createAck(consumerInfo2, m, 1, MessageAck.STANDARD_ACK_TYPE));
    // And there should be no messages left now..
    assertNoMessagesLeft(connection2);
    connection.send(closeConnectionInfo(connectionInfo));
    connection.send(closeConnectionInfo(connectionInfo2));
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo)

Aggregations

ConnectionInfo (org.apache.activemq.command.ConnectionInfo)110 SessionInfo (org.apache.activemq.command.SessionInfo)77 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)76 ProducerInfo (org.apache.activemq.command.ProducerInfo)72 Message (org.apache.activemq.command.Message)71 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)44 StubConnection (org.apache.activemq.broker.StubConnection)18 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)18 MessageAck (org.apache.activemq.command.MessageAck)15 XATransactionId (org.apache.activemq.command.XATransactionId)15 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)12 DataArrayResponse (org.apache.activemq.command.DataArrayResponse)10 TransactionInfo (org.apache.activemq.command.TransactionInfo)9 LocalTransactionId (org.apache.activemq.command.LocalTransactionId)8 ConnectionId (org.apache.activemq.command.ConnectionId)6 RemoveInfo (org.apache.activemq.command.RemoveInfo)6 IOException (java.io.IOException)5 Response (org.apache.activemq.command.Response)5 Test (org.junit.Test)5 ConnectionContext (org.apache.activemq.broker.ConnectionContext)4