org.apache.activemq.command.ProducerInfo

Here are the examples of the java api class org.apache.activemq.command.ProducerInfo taken from open source projects.

1. ProducerInfoTest#populateObject()

View license
@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ProducerInfo info = (ProducerInfo) object;
    info.setProducerId(createProducerId("ProducerId:1"));
    info.setDestination(createActiveMQDestination("Destination:2"));
    {
        BrokerId value[] = new BrokerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createBrokerId("BrokerPath:3");
        }
        info.setBrokerPath(value);
    }
    info.setDispatchAsync(true);
    info.setWindowSize(1);
}

2. ProducerInfoTest#populateObject()

View license
@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ProducerInfo info = (ProducerInfo) object;
    info.setProducerId(createProducerId("ProducerId:1"));
    info.setDestination(createActiveMQDestination("Destination:2"));
    {
        BrokerId value[] = new BrokerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createBrokerId("BrokerPath:3");
        }
        info.setBrokerPath(value);
    }
    info.setDispatchAsync(true);
}

3. ProducerInfoTest#populateObject()

View license
@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ProducerInfo info = (ProducerInfo) object;
    info.setProducerId(createProducerId("ProducerId:1"));
    info.setDestination(createActiveMQDestination("Destination:2"));
    {
        BrokerId value[] = new BrokerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createBrokerId("BrokerPath:3");
        }
        info.setBrokerPath(value);
    }
}

4. RecoverExpiredMessagesTest#sendSomeMessagesThatWillExpireIn5AndThenOne()

View license
private void sendSomeMessagesThatWillExpireIn5AndThenOne() throws Exception {
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    int MESSAGE_COUNT = 10;
    for (int i = 0; i < MESSAGE_COUNT; i++) {
        Message message = createMessage(producerInfo, destination);
        message.setExpiration(System.currentTimeMillis() + 5000);
        message.setPersistent(true);
        connection.send(message);
    }
    Message message = createMessage(producerInfo, destination);
    message.setPersistent(true);
    connection.send(message);
    expected.add(message.getMessageId().toString());
    connection.request(closeConnectionInfo(connectionInfo));
}

5. BrokerTest#testQueueSendThenAddConsumer()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testQueueSendThenAddConsumer() throws Exception {
    // Start a producer
    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);
    // Send a message to the broker.
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    // Start the consumer
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // Make sure the message was delivered.
    Message m = receiveMessage(connection);
    assertNotNull(m);
}

6. BrokerTest#testAddConsumerThenSend()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testAddConsumerThenSend() 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);
    connection.send(consumerInfo);
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    // Make sure the message was delivered.
    Message m = receiveMessage(connection);
    assertNotNull(m);
}

7. BrokerTest#testTopicNoLocal()

Project: activemq-artemis
Source File: BrokerTest.java
View license
// https://issues.apache.org/jira/browse/ARTEMIS-402
public void testTopicNoLocal() throws Exception {
    ActiveMQDestination destination = new ActiveMQTopic("TEST");
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setRetroactive(true);
    consumerInfo1.setPrefetchSize(100);
    consumerInfo1.setNoLocal(true);
    connection1.send(consumerInfo1);
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ProducerInfo producerInfo2 = createProducerInfo(sessionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(producerInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setRetroactive(true);
    consumerInfo2.setPrefetchSize(100);
    consumerInfo2.setNoLocal(true);
    connection2.send(consumerInfo2);
    // Send the messages
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    // The 2nd connection should get the messages.
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection2);
        assertNotNull(m1);
    }
    // Send a message with the 2nd connection
    Message message = createMessage(producerInfo2, destination, deliveryMode);
    connection2.send(message);
    // The first connection should not see the initial 4 local messages sent
    // but should
    // see the messages from connection 2.
    Message m = receiveMessage(connection1);
    assertNotNull(m);
    assertEquals(message.getMessageId(), m.getMessageId());
    assertNoMessagesLeft(connection1);
    assertNoMessagesLeft(connection2);
}

8. BrokerTest#testConsumerClose()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testConsumerClose() throws Exception {
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    consumerInfo1.setNoLocal(true);
    connection1.request(consumerInfo1);
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ProducerInfo producerInfo2 = createProducerInfo(sessionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(producerInfo2);
    // Send the messages
    connection2.send(createMessage(producerInfo2, destination, deliveryMode));
    connection2.send(createMessage(producerInfo2, destination, deliveryMode));
    connection2.send(createMessage(producerInfo2, destination, deliveryMode));
    connection2.send(createMessage(producerInfo2, destination, deliveryMode));
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull(m1);
        connection1.send(createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE));
    }
    // give the async ack a chance to perculate and validate all are currently consumed
    // use receive rather than poll as broker info is sent async and may still need to be dequeued
    Message result = receiveMessage(connection1, MAX_NULL_WAIT);
    assertNull("no more messages " + result, result);
    // Close the consumer.
    connection1.request(closeConsumerInfo(consumerInfo1));
    // Send another message, connection1 should not get the message.
    connection2.request(createMessage(producerInfo2, destination, deliveryMode));
    result = receiveMessage(connection1, MAX_NULL_WAIT);
    assertNull("no message received after close " + result, result);
}

9. BrokerTest#testSessionCloseCascades()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testSessionCloseCascades() throws Exception {
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    consumerInfo1.setNoLocal(true);
    connection1.request(consumerInfo1);
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ProducerInfo producerInfo2 = createProducerInfo(sessionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(producerInfo2);
    // Send the messages
    connection2.send(createMessage(producerInfo2, destination, deliveryMode));
    connection2.send(createMessage(producerInfo2, destination, deliveryMode));
    connection2.send(createMessage(producerInfo2, destination, deliveryMode));
    connection2.send(createMessage(producerInfo2, destination, deliveryMode));
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull(m1);
        connection1.send(createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE));
    }
    // Close the session, this should in turn close the consumer.
    connection1.request(closeSessionInfo(sessionInfo1));
    // Send another message, connection1 should not get the message.
    connection2.request(createMessage(producerInfo2, destination, deliveryMode));
    Message msg = receiveMessage(connection1, MAX_NULL_WAIT);
    assertNull("no message received from connection1 after session close", msg);
}

10. BrokerTest#testConnectionCloseCascades()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testConnectionCloseCascades() throws Exception {
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    consumerInfo1.setNoLocal(true);
    connection1.request(consumerInfo1);
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ProducerInfo producerInfo2 = createProducerInfo(sessionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(producerInfo2);
    // Send the messages
    connection2.send(createMessage(producerInfo2, destination, deliveryMode));
    connection2.send(createMessage(producerInfo2, destination, deliveryMode));
    connection2.send(createMessage(producerInfo2, destination, deliveryMode));
    connection2.send(createMessage(producerInfo2, destination, deliveryMode));
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull(m1);
        connection1.send(createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE));
    }
    // give the async ack a chance to perculate and validate all are currently consumed
    Message msg = receiveMessage(connection1, MAX_NULL_WAIT);
    assertNull("all messages were received " + msg, msg);
    // Close the connection, this should in turn close the consumer.
    connection1.request(closeConnectionInfo(connectionInfo1));
    // Send another message, connection1 should not get the message.
    connection2.request(createMessage(producerInfo2, destination, deliveryMode));
    assertNull("no message received", receiveMessage(connection1, MAX_NULL_WAIT));
}

11. AdvisoryBrokerTest#testProducerAdvisories()

View license
public void testProducerAdvisories() throws Exception {
    ActiveMQDestination queue = new ActiveMQQueue("test");
    ActiveMQDestination destination = AdvisorySupport.getProducerAdvisoryTopic(queue);
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(consumerInfo1);
    assertNoMessagesLeft(connection1);
    // Setup a producer.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ProducerInfo producerInfo2 = createProducerInfo(sessionInfo2);
    producerInfo2.setDestination(queue);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(producerInfo2);
    // We should get an advisory of the new produver.
    Message m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ProducerInfo) m1.getDataStructure()).getProducerId(), producerInfo2.getProducerId());
    // Close the second connection.
    connection2.request(closeConnectionInfo(connectionInfo2));
    connection2.stop();
    // We should get an advisory of the producer closing
    m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    RemoveInfo r = (RemoveInfo) m1.getDataStructure();
    assertEquals(r.getObjectId(), producerInfo2.getProducerId());
    assertNoMessagesLeft(connection2);
}

12. AdvisoryBrokerTest#testProducerAdvisoriesReplayedOnlyTargetNewConsumer()

View license
public void testProducerAdvisoriesReplayedOnlyTargetNewConsumer() throws Exception {
    ActiveMQDestination queue = new ActiveMQQueue("test");
    ActiveMQDestination destination = AdvisorySupport.getProducerAdvisoryTopic(queue);
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    // Create the first consumer..
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    // Setup a producer.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ProducerInfo producerInfo2 = createProducerInfo(sessionInfo2);
    producerInfo2.setDestination(queue);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(producerInfo2);
    Message m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ProducerInfo) m1.getDataStructure()).getProducerId(), producerInfo2.getProducerId());
    // Create the 2nd consumer..
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(100);
    connection2.send(consumerInfo2);
    // The second consumer should se a replay
    m1 = receiveMessage(connection2);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ProducerInfo) m1.getDataStructure()).getProducerId(), producerInfo2.getProducerId());
    // But the first consumer should not see the replay.
    assertNoMessagesLeft(connection1);
}

13. AdvisoryBrokerTest#testProducerAdvisoriesReplayed()

View license
public void testProducerAdvisoriesReplayed() throws Exception {
    ActiveMQDestination queue = new ActiveMQQueue("test");
    ActiveMQDestination destination = AdvisorySupport.getProducerAdvisoryTopic(queue);
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    // Setup a producer.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ProducerInfo producerInfo2 = createProducerInfo(sessionInfo2);
    producerInfo2.setDestination(queue);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(producerInfo2);
    // Create the advisory consumer.. it should see the previous producer
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    Message m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ProducerInfo) m1.getDataStructure()).getProducerId(), producerInfo2.getProducerId());
    // Close the second connection.
    connection2.request(closeConnectionInfo(connectionInfo2));
    connection2.stop();
    // We should get an advisory of the producer closing
    m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    RemoveInfo r = (RemoveInfo) m1.getDataStructure();
    assertEquals(r.getObjectId(), producerInfo2.getProducerId());
    assertNoMessagesLeft(connection2);
}

14. RecoveryBrokerTest#testQueuePersistentCommittedMessagesNotLostOnRestart()

View license
public void testQueuePersistentCommittedMessagesNotLostOnRestart() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    // Begin the transaction.
    LocalTransactionId txid = createLocalTransaction(sessionInfo);
    connection.send(createBeginTransaction(connectionInfo, txid));
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        message.setTransactionId(txid);
        connection.send(message);
    }
    // Commit
    connection.send(createCommitTransaction1Phase(connectionInfo, txid));
    connection.request(closeConnectionInfo(connectionInfo));
    // restart the broker.
    restartBroker();
    // Setup the consumer and receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    for (int i = 0; i < 4; i++) {
        Message m = receiveMessage(connection);
        assertNotNull(m);
    }
    assertNoMessagesLeft(connection);
}

15. RecoveryBrokerTest#testQueuePersistentCommittedAcksNotLostOnRestart()

View license
public void testQueuePersistentCommittedAcksNotLostOnRestart() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        connection.send(message);
    }
    // Setup the consumer and receive the message.
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // Begin the transaction.
    LocalTransactionId txid = createLocalTransaction(sessionInfo);
    connection.send(createBeginTransaction(connectionInfo, txid));
    for (int i = 0; i < 4; i++) {
        Message m = receiveMessage(connection);
        assertNotNull(m);
        MessageAck ack = createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE);
        ack.setTransactionId(txid);
        connection.send(ack);
    }
    // Commit
    connection.send(createCommitTransaction1Phase(connectionInfo, txid));
    connection.request(closeConnectionInfo(connectionInfo));
    // restart the broker.
    restartBroker();
    // Setup the consumer and receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // No messages should be delivered.
    Message m = receiveMessage(connection);
    assertNull(m);
}

16. RecoveryBrokerTest#testQueueNonPersistentMessagesLostOnRestart()

View license
public void testQueueNonPersistentMessagesLostOnRestart() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    Message message = createMessage(producerInfo, destination);
    message.setPersistent(false);
    connection.send(message);
    // restart the broker.
    restartBroker();
    // Setup the consumer and receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // Message should have been dropped due to broker restart.
    assertNoMessagesLeft(connection);
}

17. RecoveryBrokerTest#testQueuePersistentMessagesNotLostOnRestart()

View license
public void testQueuePersistentMessagesNotLostOnRestart() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    Message message = createMessage(producerInfo, destination);
    message.setPersistent(true);
    connection.send(message);
    connection.request(closeConnectionInfo(connectionInfo));
    // restart the broker.
    restartBroker();
    // Setup the consumer and receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // Message should have been dropped due to broker restart.
    Message m = receiveMessage(connection);
    assertNotNull("Should have received a message by now!", m);
    assertEquals(m.getMessageId(), message.getMessageId());
}

18. RecoveryBrokerTest#testTopicDurableConsumerHoldsPersistentMessageAfterRestart()

View license
public void testTopicDurableConsumerHoldsPersistentMessageAfterRestart() throws Exception {
    ActiveMQDestination destination = new ActiveMQTopic("TEST");
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    connectionInfo1.setClientId("A");
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    // Create the durable subscription.
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setSubscriptionName("test");
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    // Close the subscription.
    connection1.send(closeConsumerInfo(consumerInfo1));
    // Send the messages
    connection1.send(createMessage(producerInfo1, destination, DeliveryMode.PERSISTENT));
    connection1.send(createMessage(producerInfo1, destination, DeliveryMode.PERSISTENT));
    connection1.send(createMessage(producerInfo1, destination, DeliveryMode.PERSISTENT));
    connection1.send(createMessage(producerInfo1, destination, DeliveryMode.PERSISTENT));
    connection1.request(closeConnectionInfo(connectionInfo1));
    // Restart the broker.
    restartBroker();
    // Get a connection to the new broker.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    connectionInfo2.setClientId("A");
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    // Re-open the subscription.
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setSubscriptionName("test");
    consumerInfo2.setPrefetchSize(100);
    connection2.send(consumerInfo2);
    // The we should get the messages.
    for (int i = 0; i < 4; i++) {
        Message m2 = receiveMessage(connection2);
        assertNotNull("Did not get message " + i, m2);
    }
    assertNoMessagesLeft(connection2);
}

19. RecoveryBrokerTest#testQueuePersistentUncommitedAcksLostOnRestart()

View license
public void testQueuePersistentUncommitedAcksLostOnRestart() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        connection.send(message);
    }
    // Setup the consumer and receive the message.
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // Begin the transaction.
    LocalTransactionId txid = createLocalTransaction(sessionInfo);
    connection.send(createBeginTransaction(connectionInfo, txid));
    for (int i = 0; i < 4; i++) {
        Message m = receiveMessage(connection);
        assertNotNull(m);
        MessageAck ack = createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE);
        ack.setTransactionId(txid);
        connection.send(ack);
    }
    // Don't commit
    // restart the broker.
    restartBroker();
    // Setup the consumer and receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // All messages should be re-delivered.
    for (int i = 0; i < 4; i++) {
        Message m = receiveMessage(connection);
        assertNotNull(m);
    }
    assertNoMessagesLeft(connection);
}

20. RecoveryBrokerTest#testQueuePersistentXAUncommitedAcksLostOnRestart()

View license
public void testQueuePersistentXAUncommitedAcksLostOnRestart() throws Exception {
    int NUMBER = 100;
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    for (int i = 0; i < NUMBER; i++) {
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        connection.send(message);
    }
    // Setup the consumer and receive the message.
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // Begin the transaction.
    XATransactionId txid = createXATransaction(sessionInfo);
    connection.send(createBeginTransaction(connectionInfo, txid));
    Message m = null;
    for (int i = 0; i < NUMBER; i++) {
        m = receiveMessage(connection);
        assertNotNull(m);
    }
    MessageAck ack = createAck(consumerInfo, m, NUMBER, MessageAck.STANDARD_ACK_TYPE);
    ack.setTransactionId(txid);
    connection.send(ack);
    // Don't commit
    // restart the broker.
    restartBroker();
    // Setup the consumer and receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // All messages should be re-delivered.
    for (int i = 0; i < NUMBER; i++) {
        m = receiveMessage(connection);
        assertNotNull(m);
    }
    assertNoMessagesLeft(connection);
}

21. RecoveryBrokerTest#testQueuePersistentUncommitedMessagesLostOnRestart()

View license
public void testQueuePersistentUncommitedMessagesLostOnRestart() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    // Begin the transaction.
    LocalTransactionId txid = createLocalTransaction(sessionInfo);
    connection.send(createBeginTransaction(connectionInfo, txid));
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        message.setTransactionId(txid);
        connection.send(message);
    }
    // Don't commit
    // restart the broker.
    restartBroker();
    // Setup the consumer and receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // No messages should be delivered.
    Message m = receiveMessage(connection);
    assertNull(m);
}

22. QueueOptimizedDispatchExceptionTest#TestOptimizedDispatchCME()

View license
@Test
public void TestOptimizedDispatchCME() throws Exception {
    final PersistenceAdapter persistenceAdapter = broker.getPersistenceAdapter();
    final MessageStore queueMessageStore = persistenceAdapter.createQueueMessageStore(destination);
    final ConnectionContext contextNotInTx = new ConnectionContext();
    contextNotInTx.setConnection(new Connection() {

        @Override
        public void stop() throws Exception {
        }

        @Override
        public void start() throws Exception {
        }

        @Override
        public void updateClient(ConnectionControl control) {
        }

        @Override
        public void serviceExceptionAsync(IOException e) {
        }

        @Override
        public void serviceException(Throwable error) {
        }

        @Override
        public Response service(Command command) {
            return null;
        }

        @Override
        public boolean isSlow() {
            return false;
        }

        @Override
        public boolean isNetworkConnection() {
            return false;
        }

        @Override
        public boolean isManageable() {
            return false;
        }

        @Override
        public boolean isFaultTolerantConnection() {
            return false;
        }

        @Override
        public boolean isConnected() {
            return true;
        }

        @Override
        public boolean isBlocked() {
            return false;
        }

        @Override
        public boolean isActive() {
            return false;
        }

        @Override
        public ConnectionStatistics getStatistics() {
            return null;
        }

        @Override
        public String getRemoteAddress() {
            return null;
        }

        @Override
        public int getDispatchQueueSize() {
            return 0;
        }

        @Override
        public Connector getConnector() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getConnectionId() {
            return null;
        }

        @Override
        public void dispatchSync(Command message) {
        }

        @Override
        public void dispatchAsync(Command command) {
        }

        @Override
        public int getActiveTransactionCount() {
            return 0;
        }

        @Override
        public Long getOldestActiveTransactionDuration() {
            return null;
        }
    });
    final DestinationStatistics destinationStatistics = new DestinationStatistics();
    final Queue queue = new Queue(broker, destination, queueMessageStore, destinationStatistics, broker.getTaskRunnerFactory());
    final MockMemoryUsage usage = new MockMemoryUsage();
    queue.setOptimizedDispatch(true);
    queue.initialize();
    queue.start();
    queue.memoryUsage = usage;
    ProducerBrokerExchange producerExchange = new ProducerBrokerExchange();
    ProducerInfo producerInfo = new ProducerInfo();
    ProducerState producerState = new ProducerState(producerInfo);
    producerExchange.setProducerState(producerState);
    producerExchange.setConnectionContext(contextNotInTx);
    // populate the queue store, exceed memory limit so that cache is disabled
    for (int i = 0; i < count; i++) {
        Message message = getMessage(i);
        queue.send(producerExchange, message);
    }
    usage.setFull(false);
    try {
        queue.wakeup();
    } catch (Exception e) {
        LOG.error("Queue threw an unexpected exception: " + e.toString());
        fail("Should not throw an exception.");
    }
}

23. FanoutTransportBrokerTest#createProducerInfo()

View license
protected ProducerInfo createProducerInfo(SessionInfo sessionInfo) throws Exception {
    ProducerInfo info = new ProducerInfo(sessionInfo, ++idGenerator);
    return info;
}

24. RecoveryBrokerTest#testConsumedQueuePersistentMessagesLostOnRestart()

View license
public void testConsumedQueuePersistentMessagesLostOnRestart() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        connection.send(message);
    }
    // Setup the consumer and receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // The we should get the messages.
    for (int i = 0; i < 4; i++) {
        Message m2 = receiveMessage(connection);
        assertNotNull(m2);
    }
    // restart the broker.
    restartBroker();
    // No messages should be delivered.
    Message m = receiveMessage(connection);
    assertNull(m);
}

25. BrokerNetworkWithStuckMessagesTest#createProducerInfo()

View license
protected ProducerInfo createProducerInfo(SessionInfo sessionInfo) throws Exception {
    ProducerInfo info = new ProducerInfo(sessionInfo, ++idGenerator);
    return info;
}

26. DemandForwardingBridgeTest#testSendThenAddConsumer()

View license
public void testSendThenAddConsumer() throws Exception {
    // Start a producer on local broker
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    destination = createDestinationInfo(connection1, connectionInfo1, destinationType);
    // Start a consumer on a remote broker
    final StubConnection connection2 = createRemoteConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    // Send the message to the local broker.
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    // Verify that the message stayed on the local broker.
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    connection1.send(consumerInfo1);
    Message m = receiveMessage(connection1);
    assertNotNull(m);
    // Close consumer to cause the message to rollback.
    connection1.send(consumerInfo1.createRemoveCommand());
    final DestinationStatistics destinationStatistics = broker.getDestination(destination).getDestinationStatistics();
    assertEquals("broker dest stat dispatched", 1, destinationStatistics.getDispatched().getCount());
    assertEquals("broker dest stat dequeues", 0, destinationStatistics.getDequeues().getCount());
    assertEquals("broker dest stat forwards", 0, destinationStatistics.getForwards().getCount());
    // Now create remote consumer that should cause message to move to this
    // remote consumer.
    final ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    connection2.request(consumerInfo2);
    // Make sure the message was delivered via the remote.
    assertTrue("message was received", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            Message msg = receiveMessage(connection2);
            if (msg != null) {
                connection2.request(createAck(consumerInfo2, msg, 1, MessageAck.STANDARD_ACK_TYPE));
                return true;
            }
            return false;
        }
    }));
    assertTrue("broker dest stat forwards", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return 1 == destinationStatistics.getForwards().getCount();
        }
    }));
    assertEquals("broker dest stat dequeues", 1, destinationStatistics.getDequeues().getCount());
}

27. DemandForwardingBridgeTest#testAddConsumerThenSend()

View license
public void testAddConsumerThenSend() throws Exception {
    // Start a producer on local broker
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    destination = createDestinationInfo(connection1, connectionInfo1, destinationType);
    // Start a consumer on a remote broker
    StubConnection connection2 = createRemoteConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo2, destination);
    connection2.send(consumerInfo);
    // subscriptions.
    try {
        Thread.sleep(1000);
    } catch (InterruptedException ie) {
        ie.printStackTrace();
    }
    // Send the message to the local boker.
    connection1.request(createMessage(producerInfo, destination, deliveryMode));
    // Make sure the message was delivered via the remote.
    receiveMessage(connection2);
}

28. ForwardingBridgeTest#testForwardMessageCompressed()

View license
public void testForwardMessageCompressed() throws Exception {
    bridge.setUseCompression(true);
    // Start a producer on local broker
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    destination = createDestinationInfo(connection1, connectionInfo1, destinationType);
    // Start a consumer on a remote broker
    StubConnection connection2 = createRemoteConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo2, destination);
    connection2.send(consumerInfo);
    Thread.sleep(1000);
    // Give forwarding bridge a chance to finish setting up
    try {
        Thread.sleep(1000);
    } catch (InterruptedException ie) {
        ie.printStackTrace();
    }
    // Send the message to the local boker.
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    // Make sure the message was delivered via the remote.
    Message m = receiveMessage(connection2);
    assertNotNull(m);
    // Make sure its compressed now
    ActiveMQMessage message = (ActiveMQMessage) m;
    assertTrue(message.isCompressed());
}

29. ForwardingBridgeTest#testAddConsumerThenSend()

View license
public void testAddConsumerThenSend() throws Exception {
    // Start a producer on local broker
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    destination = createDestinationInfo(connection1, connectionInfo1, destinationType);
    // Start a consumer on a remote broker
    StubConnection connection2 = createRemoteConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo2, destination);
    connection2.send(consumerInfo);
    Thread.sleep(1000);
    // Give forwarding bridge a chance to finish setting up
    try {
        Thread.sleep(1000);
    } catch (InterruptedException ie) {
        ie.printStackTrace();
    }
    // Send the message to the local boker.
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    // Make sure the message was delivered via the remote.
    Message m = receiveMessage(connection2);
    assertNotNull(m);
}

30. ProducerInfoTest#createObject()

View license
@Override
public Object createObject() throws Exception {
    ProducerInfo info = new ProducerInfo();
    populateObject(info);
    return info;
}

31. ProducerInfoTest#createObject()

View license
@Override
public Object createObject() throws Exception {
    ProducerInfo info = new ProducerInfo();
    populateObject(info);
    return info;
}

32. ProducerInfoTest#createObject()

View license
@Override
public Object createObject() throws Exception {
    ProducerInfo info = new ProducerInfo();
    populateObject(info);
    return info;
}

33. ProxyConnectorTest#testSendAndConsume()

View license
public void testSendAndConsume() throws Exception {
    // Start a producer on local broker using the proxy
    StubConnection connection1 = createProxyConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    destination = createDestinationInfo(connection1, connectionInfo1, destinationType);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    connection1.send(consumerInfo1);
    // Start a consumer on a remote broker using a proxy connection.
    StubConnection connection2 = createRemoteProxyConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    connection2.send(consumerInfo2);
    // Either that or make consumer retroactive
    try {
        Thread.sleep(2000);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // Send the message to the local broker.
    connection1.request(createMessage(producerInfo, destination, deliveryMode));
    // Verify that the message Was sent to the remote broker and the local
    // broker.
    Message m;
    m = receiveMessage(connection1);
    assertNotNull(m);
    assertNoMessagesLeft(connection1);
    m = receiveMessage(connection2);
    assertNotNull(m);
    assertNoMessagesLeft(connection2);
}

34. DiscoveryTransportBrokerTest#testPublisherFailsOver()

View license
public void testPublisherFailsOver() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    int deliveryMode = DeliveryMode.NON_PERSISTENT;
    // Start a normal consumer on the local broker
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.request(consumerInfo1);
    // Start a normal consumer on a remote broker
    StubConnection connection2 = createRemoteConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(consumerInfo2);
    // Start a failover publisher.
    StubConnection connection3 = createFailoverConnection();
    ConnectionInfo connectionInfo3 = createConnectionInfo();
    SessionInfo sessionInfo3 = createSessionInfo(connectionInfo3);
    ProducerInfo producerInfo3 = createProducerInfo(sessionInfo3);
    connection3.send(connectionInfo3);
    connection3.send(sessionInfo3);
    connection3.send(producerInfo3);
    // Send the message using the fail over publisher.
    connection3.request(createMessage(producerInfo3, destination, deliveryMode));
    // The message will be sent to one of the brokers.
    FailoverTransport ft = connection3.getTransport().narrow(FailoverTransport.class);
    // See which broker we were connected to.
    StubConnection connectionA;
    StubConnection connectionB;
    TransportConnector serverA;
    if (connector.getServer().getConnectURI().getPort() == ft.getConnectedTransportURI().getPort()) {
        connectionA = connection1;
        connectionB = connection2;
        serverA = connector;
    } else {
        connectionA = connection2;
        connectionB = connection1;
        serverA = remoteConnector;
    }
    assertNotNull(receiveMessage(connectionA));
    assertNoMessagesLeft(connectionB);
    // Dispose the server so that it fails over to the other server.
    LOG.info("Disconnecting active server");
    serverA.stop();
    LOG.info("Sending request that should failover");
    connection3.request(createMessage(producerInfo3, destination, deliveryMode));
    assertNotNull(receiveMessage(connectionB));
    assertNoMessagesLeft(connectionA);
}

35. FailoverTransportBrokerTest#createProducerInfo()

View license
protected ProducerInfo createProducerInfo(SessionInfo sessionInfo) throws Exception {
    ProducerInfo info = new ProducerInfo(sessionInfo, ++idGenerator);
    return info;
}

36. FailoverTransportBrokerTest#testPublisherFailsOver()

View license
@Test
public void testPublisherFailsOver() throws Exception {
    // Start a normal consumer on the local broker
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.request(consumerInfo1);
    // Start a normal consumer on a remote broker
    StubConnection connection2 = createRemoteConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(consumerInfo2);
    // Start a failover publisher.
    LOG.info("Starting the failover connection.");
    StubConnection connection3 = createFailoverConnection(null);
    ConnectionInfo connectionInfo3 = createConnectionInfo();
    SessionInfo sessionInfo3 = createSessionInfo(connectionInfo3);
    ProducerInfo producerInfo3 = createProducerInfo(sessionInfo3);
    connection3.send(connectionInfo3);
    connection3.send(sessionInfo3);
    connection3.send(producerInfo3);
    // Send the message using the fail over publisher.
    connection3.request(createMessage(producerInfo3, destination, deliveryMode));
    // The message will be sent to one of the brokers.
    FailoverTransport ft = connection3.getTransport().narrow(FailoverTransport.class);
    // See which broker we were connected to.
    StubConnection connectionA;
    StubConnection connectionB;
    EmbeddedJMS serverA;
    if (new URI(newURI(0)).equals(ft.getConnectedTransportURI())) {
        connectionA = connection1;
        connectionB = connection2;
        serverA = server;
    } else {
        connectionA = connection2;
        connectionB = connection1;
        serverA = remoteServer;
    }
    Assert.assertNotNull(receiveMessage(connectionA));
    assertNoMessagesLeft(connectionB);
    // Dispose the server so that it fails over to the other server.
    LOG.info("Disconnecting the active connection");
    serverA.stop();
    connection3.request(createMessage(producerInfo3, destination, deliveryMode));
    Assert.assertNotNull(receiveMessage(connectionB));
    assertNoMessagesLeft(connectionA);
}

37. FanoutTransportBrokerTest#testPublisherFansout()

View license
@Test
public void testPublisherFansout() throws Exception {
    // Start a normal consumer on the local broker
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.request(consumerInfo1);
    // Start a normal consumer on a remote broker
    StubConnection connection2 = createRemoteConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(consumerInfo2);
    // Start a fanout publisher.
    LOG.info("Starting the fanout connection.");
    StubConnection connection3 = createFanoutConnection();
    ConnectionInfo connectionInfo3 = createConnectionInfo();
    SessionInfo sessionInfo3 = createSessionInfo(connectionInfo3);
    ProducerInfo producerInfo3 = createProducerInfo(sessionInfo3);
    connection3.send(connectionInfo3);
    connection3.send(sessionInfo3);
    connection3.send(producerInfo3);
    // Send the message using the fail over publisher.
    connection3.request(createMessage(producerInfo3, destination, deliveryMode));
    Assert.assertNotNull(receiveMessage(connection1));
    assertNoMessagesLeft(connection1);
    Assert.assertNotNull(receiveMessage(connection2));
    assertNoMessagesLeft(connection2);
}

38. FanoutTransportBrokerTest#testPublisherWaitsForServerToBeUp()

View license
/*
   public void initCombosForTestPublisherWaitsForServerToBeUp() {
      addCombinationValues("deliveryMode", new Object[]{Integer.valueOf(DeliveryMode.NON_PERSISTENT), Integer.valueOf(DeliveryMode.PERSISTENT)});
      addCombinationValues("destination", new Object[]{new ActiveMQTopic("TEST")});
   }
*/
@Test
public void testPublisherWaitsForServerToBeUp() throws Exception {
    if (name.getMethodName().contains("test-0") || name.getMethodName().contains("test-2")) {
        System.out.println("Discarding invalid test: " + name.getMethodName());
        return;
    }
    // Start a normal consumer on the local broker
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.request(consumerInfo1);
    // Start a normal consumer on a remote broker
    StubConnection connection2 = createRemoteConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(consumerInfo2);
    // Start a fanout publisher.
    LOG.info("Starting the fanout connection.");
    final StubConnection connection3 = createFanoutConnection();
    ConnectionInfo connectionInfo3 = createConnectionInfo();
    SessionInfo sessionInfo3 = createSessionInfo(connectionInfo3);
    final ProducerInfo producerInfo3 = createProducerInfo(sessionInfo3);
    connection3.send(connectionInfo3);
    connection3.send(sessionInfo3);
    connection3.send(producerInfo3);
    // Send the message using the fail over publisher.
    connection3.request(createMessage(producerInfo3, destination, deliveryMode));
    Assert.assertNotNull(receiveMessage(connection1));
    assertNoMessagesLeft(connection1);
    Assert.assertNotNull(receiveMessage(connection2));
    assertNoMessagesLeft(connection2);
    final CountDownLatch publishDone = new CountDownLatch(1);
    // The MockTransport is on the remote connection.
    // Slip in a new transport filter after the MockTransport
    MockTransport mt = (MockTransport) connection3.getTransport().narrow(MockTransport.class);
    mt.install(new TransportFilter(mt.getNext()) {

        @Override
        public void oneway(Object command) throws IOException {
            LOG.info("Dropping: " + command);
        // just eat it! to simulate a recent failure.
        }
    });
    // Send a message (async) as this will block
    new Thread() {

        @Override
        public void run() {
            // Send the message using the fail over publisher.
            try {
                connection3.request(createMessage(producerInfo3, destination, deliveryMode));
            } catch (Throwable e) {
                e.printStackTrace();
            }
            publishDone.countDown();
        }
    }.start();
    // Assert that we block:
    Assert.assertFalse(publishDone.await(3, TimeUnit.SECONDS));
    // Restart the remote server. State should be re-played and the publish
    // should continue.
    LOG.info("Restarting Broker");
    restartRemoteBroker();
    LOG.info("Broker Restarted");
    // This should reconnect, and resend
    Assert.assertTrue(publishDone.await(20, TimeUnit.SECONDS));
}

39. BrokerTest#testWildcardConsume()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testWildcardConsume() throws Exception {
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    // setup the wildcard consumer.
    ActiveMQDestination compositeDestination = ActiveMQDestination.createDestination("WILD.*.TEST", destinationType);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, compositeDestination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    // These two message should NOT match the wild card.
    connection1.send(createMessage(producerInfo1, ActiveMQDestination.createDestination("WILD.CARD", destinationType), deliveryMode));
    connection1.send(createMessage(producerInfo1, ActiveMQDestination.createDestination("WILD.TEST", destinationType), deliveryMode));
    // These two message should match the wild card.
    ActiveMQDestination d1 = ActiveMQDestination.createDestination("WILD.CARD.TEST", destinationType);
    connection1.send(createMessage(producerInfo1, d1, deliveryMode));
    Message m = receiveMessage(connection1);
    assertNotNull(m);
    assertEquals(d1, m.getDestination());
    ActiveMQDestination d2 = ActiveMQDestination.createDestination("WILD.FOO.TEST", destinationType);
    connection1.request(createMessage(producerInfo1, d2, deliveryMode));
    m = receiveMessage(connection1);
    assertNotNull(m);
    assertEquals(d2, m.getDestination());
    assertNoMessagesLeft(connection1);
    connection1.send(closeConnectionInfo(connectionInfo1));
}

40. BrokerTest#testQueueOnlyOnceDeliveryWith2Consumers()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testQueueOnlyOnceDeliveryWith2Consumers() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(1);
    connection1.request(consumerInfo1);
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(1);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(consumerInfo2);
    // Send the messages
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.request(createMessage(producerInfo, destination, deliveryMode));
    for (int i = 0; i < 2; i++) {
        Message m1 = receiveMessage(connection1);
        Message m2 = receiveMessage(connection2);
        assertNotNull("m1 is null for index: " + i, m1);
        assertNotNull("m2 is null for index: " + i, m2);
        assertNotSame(m1.getMessageId(), m2.getMessageId());
        connection1.send(createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE));
        connection2.send(createAck(consumerInfo2, m2, 1, MessageAck.STANDARD_ACK_TYPE));
    }
    assertNoMessagesLeft(connection1);
    assertNoMessagesLeft(connection2);
}

41. BrokerTest#testQueueBrowserWith2Consumers()

Project: activemq-artemis
Source File: BrokerTest.java
View license
//https://issues.apache.org/jira/browse/ARTEMIS-384
public void testQueueBrowserWith2Consumers() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(10);
    connection1.request(consumerInfo1);
    // Send the messages
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    //as the messages are sent async - need to synchronize the last
    //one to ensure they arrive in the order we want
    connection1.request(createMessage(producerInfo, destination, deliveryMode));
    // Setup a second connection with a queue browser.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(1);
    consumerInfo2.setBrowser(true);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(consumerInfo2);
    List<Message> messages = new ArrayList<>();
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull("m1 is null for index: " + i, m1);
        messages.add(m1);
    }
    for (int i = 0; i < 4; i++) {
        Message m1 = messages.get(i);
        Message m2 = receiveMessage(connection2);
        assertNotNull("m2 is null for index: " + i, m2);
        assertEquals(m1.getMessageId(), m2.getMessageId());
        connection2.send(createAck(consumerInfo2, m2, 1, MessageAck.DELIVERED_ACK_TYPE));
    }
    assertNoMessagesLeft(connection1);
    assertNoMessagesLeft(connection2);
}

42. BrokerTest#testQueueBrowserWith2ConsumersBrowseFirst()

Project: activemq-artemis
Source File: BrokerTest.java
View license
/*
    * change the order of the above test
    */
public void testQueueBrowserWith2ConsumersBrowseFirst() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    deliveryMode = DeliveryMode.NON_PERSISTENT;
    // Setup a second connection with a queue browser.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(10);
    consumerInfo2.setBrowser(true);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(consumerInfo2);
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(10);
    connection1.request(consumerInfo1);
    // Send the messages
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    //as the messages are sent async - need to synchronize the last
    //one to ensure they arrive in the order we want
    connection1.request(createMessage(producerInfo, destination, deliveryMode));
    List<Message> messages = new ArrayList<>();
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull("m1 is null for index: " + i, m1);
        messages.add(m1);
    }
    // no messages present in queue browser as there were no messages when it
    // was created
    assertNoMessagesLeft(connection1);
    assertNoMessagesLeft(connection2);
}

43. BrokerTest#testQueueBrowserWith2ConsumersInterleaved()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testQueueBrowserWith2ConsumersInterleaved() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    deliveryMode = DeliveryMode.NON_PERSISTENT;
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(10);
    connection1.request(consumerInfo1);
    // Send the messages
    connection1.request(createMessage(producerInfo, destination, deliveryMode));
    // Setup a second connection with a queue browser.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(1);
    consumerInfo2.setBrowser(true);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(consumerInfo2);
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    //as the messages are sent async - need to synchronize the last
    //one to ensure they arrive in the order we want
    connection1.request(createMessage(producerInfo, destination, deliveryMode));
    List<Message> messages = new ArrayList<>();
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull("m1 is null for index: " + i, m1);
        messages.add(m1);
    }
    for (int i = 0; i < 4; i++) {
        Message m1 = messages.get(i);
        Message m2 = receiveMessage(connection2);
        assertNotNull("m2 is null for index: " + i, m2);
        assertEquals(m1.getMessageId(), m2.getMessageId());
        connection2.send(createAck(consumerInfo2, m2, 1, MessageAck.DELIVERED_ACK_TYPE));
    }
    assertNoMessagesLeft(connection1);
    assertNoMessagesLeft(connection2);
}

44. BrokerTest#testConsumerPrefetchAndStandardAck()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testConsumerPrefetchAndStandardAck() 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);
    // Send 3 messages to the broker.
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    connection.request(createMessage(producerInfo, destination, deliveryMode));
    // Make sure only 1 message was delivered.
    Message m1 = receiveMessage(connection);
    assertNotNull(m1);
    assertNoMessagesLeft(connection);
    // Acknowledge the first message. This should cause the next message to
    // get dispatched.
    connection.send(createAck(consumerInfo, m1, 1, MessageAck.STANDARD_ACK_TYPE));
    Message m2 = receiveMessage(connection);
    assertNotNull(m2);
    connection.send(createAck(consumerInfo, m2, 1, MessageAck.STANDARD_ACK_TYPE));
    Message m3 = receiveMessage(connection);
    assertNotNull(m3);
    connection.send(createAck(consumerInfo, m3, 1, MessageAck.STANDARD_ACK_TYPE));
    connection.send(closeConnectionInfo(connectionInfo));
}

45. BrokerTest#testTransactedAckWithPrefetchOfOne()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testTransactedAckWithPrefetchOfOne() throws Exception {
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    destination = createDestinationInfo(connection1, connectionInfo1, destinationType);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(1);
    connection1.send(consumerInfo1);
    // Send the messages
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo1, destination, deliveryMode);
        connection1.send(message);
    }
    // Now get the messages.
    for (int i = 0; i < 4; i++) {
        // Begin the transaction.
        LocalTransactionId txid = createLocalTransaction(sessionInfo1);
        connection1.send(createBeginTransaction(connectionInfo1, txid));
        Message m1 = receiveMessage(connection1);
        assertNotNull(m1);
        MessageAck ack = createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE);
        ack.setTransactionId(txid);
        connection1.send(ack);
        // Commit the transaction.
        connection1.send(createCommitTransaction1Phase(connectionInfo1, txid));
    }
    assertNoMessagesLeft(connection1);
}

46. BrokerTest#testTransactedSend()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testTransactedSend() throws Exception {
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    destination = createDestinationInfo(connection1, connectionInfo1, destinationType);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    // Begin the transaction.
    LocalTransactionId txid = createLocalTransaction(sessionInfo1);
    connection1.send(createBeginTransaction(connectionInfo1, txid));
    // Send the messages
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo1, destination, deliveryMode);
        message.setTransactionId(txid);
        connection1.request(message);
    }
    // The point of this test is that message should not be delivered until
    // send is committed.
    assertNull(receiveMessage(connection1, MAX_NULL_WAIT));
    // Commit the transaction.
    connection1.send(createCommitTransaction1Phase(connectionInfo1, txid));
    // Now get the messages.
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull(m1);
    }
    assertNoMessagesLeft(connection1);
}

47. BrokerTest#testQueueTransactedAck()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testQueueTransactedAck() throws Exception {
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    destination = createDestinationInfo(connection1, connectionInfo1, destinationType);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    // Send the messages
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo1, destination, deliveryMode);
        connection1.send(message);
    }
    // Begin the transaction.
    LocalTransactionId txid = createLocalTransaction(sessionInfo1);
    connection1.send(createBeginTransaction(connectionInfo1, txid));
    // Acknowledge the first 2 messages.
    for (int i = 0; i < 2; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull("m1 is null for index: " + i, m1);
        MessageAck ack = createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE);
        ack.setTransactionId(txid);
        connection1.request(ack);
    }
    // Commit the transaction.
    connection1.send(createCommitTransaction1Phase(connectionInfo1, txid));
    //due to async tx operations, we need some time for message count to go down
    Thread.sleep(1000);
    ArtemisBrokerWrapper wrapper = (ArtemisBrokerWrapper) broker.getBroker();
    long messageCount = wrapper.getAMQueueMessageCount(destination);
    // The queue should now only have the remaining 2 messages
    assertEquals(2, messageCount);
}

48. BrokerTest#testConsumerCloseCausesRedelivery()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testConsumerCloseCausesRedelivery() throws Exception {
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.request(consumerInfo1);
    // Send the messages
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    // Receive the messages.
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull("m1 is null for index: " + i, m1);
        assertFalse(m1.isRedelivered());
    }
    // Close the consumer without acking.. this should cause re-delivery of
    // the messages.
    connection1.send(consumerInfo1.createRemoveCommand());
    // Create another consumer that should get the messages again.
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo2.setPrefetchSize(100);
    connection1.request(consumerInfo2);
    // Receive the messages.
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull("m1 is null for index: " + i, m1);
        assertTrue(m1.isRedelivered());
    }
    assertNoMessagesLeft(connection1);
}

49. BrokerTest#testTopicDurableSubscriptionCanBeRestored()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testTopicDurableSubscriptionCanBeRestored() throws Exception {
    ActiveMQDestination destination = new ActiveMQTopic("TEST");
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    connectionInfo1.setClientId("clientid1");
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    consumerInfo1.setSubscriptionName("test");
    connection1.send(consumerInfo1);
    // Send the messages
    connection1.send(createMessage(producerInfo1, destination, DeliveryMode.PERSISTENT));
    connection1.send(createMessage(producerInfo1, destination, DeliveryMode.PERSISTENT));
    connection1.send(createMessage(producerInfo1, destination, DeliveryMode.PERSISTENT));
    connection1.request(createMessage(producerInfo1, destination, DeliveryMode.PERSISTENT));
    // Get the messages
    Message m = null;
    for (int i = 0; i < 2; i++) {
        m = receiveMessage(connection1);
        assertNotNull(m);
    }
    // Ack the last message.
    connection1.send(createAck(consumerInfo1, m, 2, MessageAck.STANDARD_ACK_TYPE));
    // Close the connection.
    connection1.request(closeConnectionInfo(connectionInfo1));
    connection1.stop();
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    connectionInfo2.setClientId("clientid1");
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(100);
    consumerInfo2.setSubscriptionName("test");
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(consumerInfo2);
    // Get the rest of the messages
    for (int i = 0; i < 2; i++) {
        Message m1 = receiveMessage(connection2);
        assertNotNull("m1 is null for index: " + i, m1);
    }
    assertNoMessagesLeft(connection2);
}

50. BrokerTest#testGroupedMessagesDeliveredToOnlyOneConsumer()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testGroupedMessagesDeliveredToOnlyOneConsumer() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(1);
    connection1.send(consumerInfo1);
    // Send the messages.
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo, destination, deliveryMode);
        message.setGroupID("TEST-GROUP");
        message.setGroupSequence(i + 1);
        connection1.request(message);
    }
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(1);
    connection2.send(consumerInfo2);
    // the first 3
    for (int i = 0; i < 3; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull("m1 is null for index: " + i, m1);
        connection1.send(createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE));
    }
    // Close the first consumer.
    connection1.request(closeConsumerInfo(consumerInfo1));
    // The last messages should now go the the second consumer.
    for (int i = 0; i < 1; i++) {
        Message m1 = receiveMessage(connection2);
        assertNotNull("m1 is null for index: " + i, m1);
        connection2.request(createAck(consumerInfo2, m1, 1, MessageAck.STANDARD_ACK_TYPE));
    }
    assertNoMessagesLeft(connection2);
}

51. BrokerTest#testTopicConsumerOnlySeeMessagesAfterCreation()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testTopicConsumerOnlySeeMessagesAfterCreation() throws Exception {
    ActiveMQDestination destination = new ActiveMQTopic("TEST");
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    connectionInfo1.setClientId("A");
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    // Send the 1st message
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    // Create the durable subscription.
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    if (durableConsumer) {
        consumerInfo1.setSubscriptionName("test");
    }
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    Message m = createMessage(producerInfo1, destination, deliveryMode);
    connection1.send(m);
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    // Subscription should skip over the first message
    Message m2 = receiveMessage(connection1);
    assertNotNull(m2);
    assertEquals(m.getMessageId(), m2.getMessageId());
    m2 = receiveMessage(connection1);
    assertNotNull(m2);
    assertNoMessagesLeft(connection1);
}

52. BrokerTest#testTopicRetroactiveConsumerSeeMessagesBeforeCreation()

Project: activemq-artemis
Source File: BrokerTest.java
View license
// https://issues.apache.org/jira/browse/ARTEMIS-402
public void testTopicRetroactiveConsumerSeeMessagesBeforeCreation() throws Exception {
    ActiveMQDestination destination = new ActiveMQTopic("TEST");
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    connectionInfo1.setClientId("A");
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    // Send the messages
    Message m = createMessage(producerInfo1, destination, deliveryMode);
    connection1.send(m);
    // Create the durable subscription.
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    if (durableConsumer) {
        consumerInfo1.setSubscriptionName("test");
    }
    consumerInfo1.setPrefetchSize(100);
    consumerInfo1.setRetroactive(true);
    connection1.send(consumerInfo1);
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    connection1.request(createMessage(producerInfo1, destination, deliveryMode));
    // the behavior is VERY dependent on the recovery policy used.
    // But the default broker settings try to make it as consistent as
    // possible
    // Subscription should see all messages sent.
    Message m2 = receiveMessage(connection1);
    assertNotNull(m2);
    assertEquals(m.getMessageId(), m2.getMessageId());
    for (int i = 0; i < 2; i++) {
        m2 = receiveMessage(connection1);
        assertNotNull(m2);
    }
    assertNoMessagesLeft(connection1);
}

53. BrokerTest#testExclusiveQueueDeliversToOnlyOneConsumer()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testExclusiveQueueDeliversToOnlyOneConsumer() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(1);
    consumerInfo1.setExclusive(true);
    connection1.send(consumerInfo1);
    // Send a message.. this should make consumer 1 the exclusive owner.
    connection1.request(createMessage(producerInfo, destination, deliveryMode));
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(1);
    consumerInfo2.setExclusive(true);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(consumerInfo2);
    // Second message should go to consumer 1 even though consumer 2 is
    // ready
    // for dispatch.
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    // Acknowledge the first 2 messages
    for (int i = 0; i < 2; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull(m1);
        connection1.send(createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE));
    }
    // Close the first consumer.
    connection1.send(closeConsumerInfo(consumerInfo1));
    // The last two messages should now go the the second consumer.
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    for (int i = 0; i < 2; i++) {
        Message m1 = receiveMessage(connection2);
        assertNotNull(m1);
        connection2.send(createAck(consumerInfo2, m1, 1, MessageAck.STANDARD_ACK_TYPE));
    }
    assertNoMessagesLeft(connection2);
}

54. MessageExpirationTest#testMessagesInSubscriptionPendingListExpire()

View license
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));
}

55. BrokerTest#testCompositeConsume()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testCompositeConsume() throws Exception {
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    // setup the composite consumer.
    ActiveMQDestination compositeDestination = ActiveMQDestination.createDestination("A,B", destinationType);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, compositeDestination);
    consumerInfo1.setRetroactive(true);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    // Publish to the two destinations
    ActiveMQDestination destinationA = ActiveMQDestination.createDestination("A", destinationType);
    ActiveMQDestination destinationB = ActiveMQDestination.createDestination("B", destinationType);
    // Send a message to each destination .
    connection1.send(createMessage(producerInfo1, destinationA, deliveryMode));
    connection1.send(createMessage(producerInfo1, destinationB, deliveryMode));
    // The consumer should get both messages.
    for (int i = 0; i < 2; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull(m1);
    }
    assertNoMessagesLeft(connection1);
    connection1.send(closeConnectionInfo(connectionInfo1));
}

56. BrokerTest#testCompositeSend()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testCompositeSend() throws Exception {
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    ActiveMQDestination destinationA = ActiveMQDestination.createDestination("A", destinationType);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destinationA);
    consumerInfo1.setRetroactive(true);
    consumerInfo1.setPrefetchSize(100);
    connection1.request(consumerInfo1);
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    ActiveMQDestination destinationB = ActiveMQDestination.createDestination("B", destinationType);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destinationB);
    consumerInfo2.setRetroactive(true);
    consumerInfo2.setPrefetchSize(100);
    connection2.request(consumerInfo2);
    // Send the messages to the composite destination.
    ActiveMQDestination compositeDestination = ActiveMQDestination.createDestination("A,B", destinationType);
    for (int i = 0; i < 4; i++) {
        connection1.request(createMessage(producerInfo1, compositeDestination, deliveryMode));
    }
    // destination.
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        Message m2 = receiveMessage(connection2);
        assertNotNull(m1);
        assertNotNull(m2);
        assertEquals(m1.getMessageId(), m2.getMessageId());
        assertEquals(compositeDestination, m1.getOriginalDestination());
        assertEquals(compositeDestination, m2.getOriginalDestination());
        connection1.request(createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE));
        connection2.request(createAck(consumerInfo2, m2, 1, MessageAck.STANDARD_ACK_TYPE));
    }
    assertNoMessagesLeft(connection1);
    assertNoMessagesLeft(connection2);
    connection1.send(closeConnectionInfo(connectionInfo1));
    connection2.send(closeConnectionInfo(connectionInfo2));
}

57. BrokerTest#testTopicDispatchIsBroadcast()

Project: activemq-artemis
Source File: BrokerTest.java
View license
//https://issues.apache.org/jira/browse/ARTEMIS-402
public void testTopicDispatchIsBroadcast() throws Exception {
    ActiveMQDestination destination = new ActiveMQTopic("TEST");
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setRetroactive(true);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setRetroactive(true);
    consumerInfo2.setPrefetchSize(100);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(consumerInfo2);
    // Send the messages
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    // Get the messages
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull(m1);
        m1 = receiveMessage(connection2);
        assertNotNull(m1);
    }
}

58. BrokerTest#testQueueDispatchedAreRedeliveredOnConsumerClose()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testQueueDispatchedAreRedeliveredOnConsumerClose() throws Exception {
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    destination = createDestinationInfo(connection1, connectionInfo1, destinationType);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    // Send the messages
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    // Get the messages
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull(m1);
        assertFalse(m1.isRedelivered());
    }
    // Close the consumer without sending any ACKS.
    connection1.send(closeConsumerInfo(consumerInfo1));
    // Drain any in flight messages..
    while (connection1.getDispatchQueue().poll(0, TimeUnit.MILLISECONDS) != null) {
    }
    // Add the second consumer
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo2.setPrefetchSize(100);
    connection1.send(consumerInfo2);
    // Make sure the messages were re delivered to the 2nd consumer.
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull(m1);
        assertTrue(m1.isRedelivered());
    }
}

59. BrokerTest#testQueueBrowseMessages()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testQueueBrowseMessages() 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);
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    // Use selector to skip first message.
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    consumerInfo.setBrowser(true);
    connection.send(consumerInfo);
    for (int i = 0; i < 4; i++) {
        Message m = receiveMessage(connection);
        assertNotNull(m);
        connection.send(createAck(consumerInfo, m, 1, MessageAck.DELIVERED_ACK_TYPE));
    }
    assertNoMessagesLeft(connection);
}

60. BrokerTest#testQueueAckRemovesMessage()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testQueueAckRemovesMessage() 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);
    Message message1 = createMessage(producerInfo, destination, deliveryMode);
    Message message2 = createMessage(producerInfo, destination, deliveryMode);
    connection.send(message1);
    connection.send(message2);
    // Make sure the message was delivered.
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.request(consumerInfo);
    Message m = receiveMessage(connection);
    assertNotNull(m);
    assertEquals(m.getMessageId(), message1.getMessageId());
    ArtemisBrokerWrapper wrapper = (ArtemisBrokerWrapper) broker.getBroker();
    long messageCount = wrapper.getAMQueueMessageCount(destination);
    assertTrue(messageCount == 2);
    connection.send(createAck(consumerInfo, m, 1, MessageAck.DELIVERED_ACK_TYPE));
    messageCount = wrapper.getAMQueueMessageCount(destination);
    assertTrue(messageCount == 2);
    connection.send(createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE));
    //give some time for broker to count down
    Thread.sleep(2000);
    messageCount = wrapper.getAMQueueMessageCount(destination);
    assertTrue(messageCount == 1);
}

61. BrokerTest#testSelectorSkipsMessages()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testSelectorSkipsMessages() 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.setSelector("JMSType='last'");
    connection.send(consumerInfo);
    Message message1 = createMessage(producerInfo, destination, deliveryMode);
    message1.setType("first");
    Message message2 = createMessage(producerInfo, destination, deliveryMode);
    message2.setType("last");
    connection.send(message1);
    connection.send(message2);
    // Use selector to skip first message.
    Message m = receiveMessage(connection);
    assertNotNull(m);
    assertEquals(m.getMessageId(), message2.getMessageId());
    connection.send(createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE));
    connection.send(closeConsumerInfo(consumerInfo));
    assertNoMessagesLeft(connection);
}

62. BrokerTest#testConsumerPrefetchAtOne()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testConsumerPrefetchAtOne() 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);
    // Send 2 messages to the broker.
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    // Make sure only 1 message was delivered.
    Message m = receiveMessage(connection);
    assertNotNull(m);
    assertNoMessagesLeft(connection);
}

63. BrokerTest#testConsumerPrefetchAtTwo()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testConsumerPrefetchAtTwo() 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(2);
    connection.send(consumerInfo);
    // Send 3 messages to the broker.
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    // Make sure only 1 message was delivered.
    Message m = receiveMessage(connection);
    assertNotNull(m);
    m = receiveMessage(connection);
    assertNotNull(m);
    assertNoMessagesLeft(connection);
}

64. BrokerTest#testConsumerPrefetchAndDeliveredAck()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testConsumerPrefetchAndDeliveredAck() 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.request(consumerInfo);
    // Send 3 messages to the broker.
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    connection.send(createMessage(producerInfo, destination, deliveryMode));
    connection.request(createMessage(producerInfo, destination, deliveryMode));
    // Make sure only 1 message was delivered.
    Message m1 = receiveMessage(connection);
    assertNotNull(m1);
    assertNoMessagesLeft(connection);
    // Acknowledge the first message. This should cause the next message to
    // get dispatched.
    connection.request(createAck(consumerInfo, m1, 1, MessageAck.DELIVERED_ACK_TYPE));
    Message m2 = receiveMessage(connection);
    assertNotNull(m2);
    connection.request(createAck(consumerInfo, m2, 1, MessageAck.DELIVERED_ACK_TYPE));
    Message m3 = receiveMessage(connection);
    assertNotNull(m3);
    connection.request(createAck(consumerInfo, m3, 1, MessageAck.DELIVERED_ACK_TYPE));
}

65. BrokerTestSupport#createProducerInfo()

View license
protected ProducerInfo createProducerInfo(SessionInfo sessionInfo) throws Exception {
    ProducerInfo info = new ProducerInfo(sessionInfo, ++idGenerator);
    return info;
}

66. DoubleSubscriptionTest#testDoubleSubscription()

View license
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);
}

67. MessageExpirationTest#testMessagesWaitingForUsageDecreaseExpire()

View license
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));
}

68. MessageExpirationTest#testMessagesInLongTransactionExpire()

View license
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));
}