Search in sources :

Example 16 with LocalTransactionId

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

the class LocalTransactionIdTest method populateObject.

@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    LocalTransactionId info = (LocalTransactionId) object;
    info.setValue(1);
    info.setConnectionId(createConnectionId("ConnectionId:1"));
}
Also used : LocalTransactionId(org.apache.activemq.command.LocalTransactionId)

Example 17 with LocalTransactionId

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

the class LocalTransactionIdTest method createObject.

@Override
public Object createObject() throws Exception {
    LocalTransactionId info = new LocalTransactionId();
    populateObject(info);
    return info;
}
Also used : LocalTransactionId(org.apache.activemq.command.LocalTransactionId)

Example 18 with LocalTransactionId

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

the class LocalTransactionIdTest method populateObject.

@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    LocalTransactionId info = (LocalTransactionId) object;
    info.setValue(1);
    info.setConnectionId(createConnectionId("ConnectionId:1"));
}
Also used : LocalTransactionId(org.apache.activemq.command.LocalTransactionId)

Example 19 with LocalTransactionId

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

the class BrokerTest method testQueueTransactedAck.

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);
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) LocalTransactionId(org.apache.activemq.command.LocalTransactionId) SessionInfo(org.apache.activemq.command.SessionInfo) MessageAck(org.apache.activemq.command.MessageAck) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ArtemisBrokerWrapper(org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper)

Example 20 with LocalTransactionId

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

the class MessageExpirationTest method testMessagesInLongTransactionExpire.

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

Aggregations

LocalTransactionId (org.apache.activemq.command.LocalTransactionId)26 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)8 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)8 Message (org.apache.activemq.command.Message)8 ProducerInfo (org.apache.activemq.command.ProducerInfo)8 SessionInfo (org.apache.activemq.command.SessionInfo)8 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)4 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)4 MessageAck (org.apache.activemq.command.MessageAck)4 ArtemisBrokerWrapper (org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper)1