Search in sources :

Example 21 with TransactionInfo

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

the class XARecoveryBrokerTest method testPreparedTransactionRecoveredOnRestart.

public void testPreparedTransactionRecoveredOnRestart() throws Exception {
    ActiveMQDestination destination = createDestination();
    // 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);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // Prepare 4 message sends.
    for (int i = 0; i < 4; i++) {
        // Begin the transaction.
        XATransactionId txid = createXATransaction(sessionInfo);
        connection.send(createBeginTransaction(connectionInfo, txid));
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        message.setTransactionId(txid);
        connection.send(message);
        // Prepare
        connection.send(createPrepareTransaction(connectionInfo, txid));
    }
    // Since prepared but not committed.. they should not get delivered.
    assertNull(receiveMessage(connection));
    assertNoMessagesLeft(connection);
    connection.request(closeConnectionInfo(connectionInfo));
    // restart the broker.
    restartBroker();
    // Setup the consumer and try receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // Since prepared but not committed.. they should not get delivered.
    assertNull(receiveMessage(connection));
    assertNoMessagesLeft(connection);
    Response response = connection.request(new TransactionInfo(connectionInfo.getConnectionId(), null, TransactionInfo.RECOVER));
    assertNotNull(response);
    DataArrayResponse dar = (DataArrayResponse) response;
    assertEquals(4, dar.getData().length);
    // ensure we can close a connection with prepared transactions
    connection.request(closeConnectionInfo(connectionInfo));
    // open again  to deliver outcome
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // Commit the prepared transactions.
    for (int i = 0; i < dar.getData().length; i++) {
        TransactionId transactionId = (TransactionId) dar.getData()[i];
        LOG.info("commit: " + transactionId);
        connection.request(createCommitTransaction2Phase(connectionInfo, transactionId));
    }
    // We should get the committed transactions.
    final int countToReceive = expectedMessageCount(4, destination);
    for (int i = 0; i < countToReceive; i++) {
        Message m = receiveMessage(connection, TimeUnit.SECONDS.toMillis(10));
        LOG.info("received: " + m);
        assertNotNull("Got non null message: " + i, m);
    }
    assertNoMessagesLeft(connection);
    assertEmptyDLQ();
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) XATransactionId(org.apache.activemq.command.XATransactionId) Message(org.apache.activemq.command.Message) SessionInfo(org.apache.activemq.command.SessionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) XATransactionId(org.apache.activemq.command.XATransactionId) TransactionId(org.apache.activemq.command.TransactionId) Response(org.apache.activemq.command.Response) DataArrayResponse(org.apache.activemq.command.DataArrayResponse) TransactionInfo(org.apache.activemq.command.TransactionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) DataArrayResponse(org.apache.activemq.command.DataArrayResponse)

Example 22 with TransactionInfo

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

the class TransactionInfoTest method populateObject.

@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    TransactionInfo info = (TransactionInfo) object;
    info.setConnectionId(createConnectionId("ConnectionId:1"));
    info.setTransactionId(createTransactionId("TransactionId:2"));
    info.setType((byte) 1);
}
Also used : TransactionInfo(org.apache.activemq.command.TransactionInfo)

Example 23 with TransactionInfo

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

the class TransactionInfoTest method createObject.

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

Example 24 with TransactionInfo

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

the class TransactionInfoTest method createObject.

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

Example 25 with TransactionInfo

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

the class TransactionInfoTest method populateObject.

@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    TransactionInfo info = (TransactionInfo) object;
    info.setConnectionId(createConnectionId("ConnectionId:1"));
    info.setTransactionId(createTransactionId("TransactionId:2"));
    info.setType((byte) 1);
}
Also used : TransactionInfo(org.apache.activemq.command.TransactionInfo)

Aggregations

TransactionInfo (org.apache.activemq.command.TransactionInfo)29 XATransactionId (org.apache.activemq.command.XATransactionId)11 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)9 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)9 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)9 DataArrayResponse (org.apache.activemq.command.DataArrayResponse)9 Message (org.apache.activemq.command.Message)9 ProducerInfo (org.apache.activemq.command.ProducerInfo)9 SessionInfo (org.apache.activemq.command.SessionInfo)9 MessageAck (org.apache.activemq.command.MessageAck)5 Response (org.apache.activemq.command.Response)4 TransactionId (org.apache.activemq.command.TransactionId)4 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)3 DestinationViewMBean (org.apache.activemq.broker.jmx.DestinationViewMBean)2 HashSet (java.util.HashSet)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 BrokerService (org.apache.activemq.broker.BrokerService)1 TransportConnection (org.apache.activemq.broker.TransportConnection)1 PersistenceAdapterViewMBean (org.apache.activemq.broker.jmx.PersistenceAdapterViewMBean)1 RecoveredXATransactionViewMBean (org.apache.activemq.broker.jmx.RecoveredXATransactionViewMBean)1