Search in sources :

Example 26 with XATransactionId

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

the class XARecoveryBrokerTest method testTopicPersistentPreparedAcksAvailableAfterRollback.

public void testTopicPersistentPreparedAcksAvailableAfterRollback() throws Exception {
    ActiveMQDestination destination = new ActiveMQTopic("TryTopic");
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    connectionInfo.setClientId("durable");
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    // setup durable subs
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    consumerInfo.setSubscriptionName("durable");
    connection.send(consumerInfo);
    int numMessages = 4;
    for (int i = 0; i < numMessages; i++) {
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        connection.send(message);
    }
    // Begin the transaction.
    XATransactionId txid = createXATransaction(sessionInfo);
    connection.send(createBeginTransaction(connectionInfo, txid));
    Message message = null;
    for (int i = 0; i < numMessages; i++) {
        message = receiveMessage(connection);
        assertNotNull(message);
    }
    // one ack with last received, mimic a beforeEnd synchronization
    MessageAck ack = createAck(consumerInfo, message, numMessages, MessageAck.STANDARD_ACK_TYPE);
    ack.setTransactionId(txid);
    connection.send(ack);
    connection.request(createPrepareTransaction(connectionInfo, txid));
    // rollback so we get redelivery
    connection.request(createRollbackTransaction(connectionInfo, txid));
    LOG.info("new consumer/tx for redelivery");
    connection.request(closeConnectionInfo(connectionInfo));
    connectionInfo = createConnectionInfo();
    connectionInfo.setClientId("durable");
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    // setup durable subs
    consumerInfo = createConsumerInfo(sessionInfo, destination);
    consumerInfo.setSubscriptionName("durable");
    connection.send(consumerInfo);
    txid = createXATransaction(sessionInfo);
    connection.send(createBeginTransaction(connectionInfo, txid));
    for (int i = 0; i < numMessages; i++) {
        message = receiveMessage(connection);
        assertNotNull("unexpected null on:" + i, message);
    }
    ack = createAck(consumerInfo, message, numMessages, MessageAck.STANDARD_ACK_TYPE);
    ack.setTransactionId(txid);
    connection.send(ack);
    // Commit
    connection.request(createCommitTransaction1Phase(connectionInfo, txid));
}
Also used : ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) 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) MessageAck(org.apache.activemq.command.MessageAck) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 27 with XATransactionId

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

the class XARecoveryBrokerTest method testTopicPreparedTransactionRecoveredOnRestart.

public void testTopicPreparedTransactionRecoveredOnRestart() throws Exception {
    ActiveMQDestination destination = new ActiveMQTopic("TryTopic");
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    connectionInfo.setClientId("durable");
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    consumerInfo.setSubscriptionName("durable");
    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();
    connectionInfo.setClientId("durable");
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    consumerInfo = createConsumerInfo(sessionInfo, destination);
    consumerInfo.setSubscriptionName("durable");
    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();
    connectionInfo.setClientId("durable");
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    consumerInfo = createConsumerInfo(sessionInfo, destination);
    consumerInfo.setSubscriptionName("durable");
    connection.send(consumerInfo);
    // Commit the prepared transactions.
    for (int i = 0; i < dar.getData().length; i++) {
        connection.request(createCommitTransaction2Phase(connectionInfo, (TransactionId) dar.getData()[i]));
    }
    // We should get the committed transactions.
    for (int i = 0; i < expectedMessageCount(4, destination); i++) {
        Message m = receiveMessage(connection, TimeUnit.SECONDS.toMillis(10));
        assertNotNull(m);
    }
    assertNoMessagesLeft(connection);
}
Also used : ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) 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 28 with XATransactionId

use of org.apache.activemq.command.XATransactionId 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 29 with XATransactionId

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

the class XARecoveryBrokerTest method testQueuePersistentCommittedMessagesNotLostOnRestart.

public void testQueuePersistentCommittedMessagesNotLostOnRestart() 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);
    // Begin the transaction.
    XATransactionId txid = createXATransaction(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 < expectedMessageCount(4, destination); i++) {
        Message m = receiveMessage(connection);
        assertNotNull(m);
    }
    assertNoMessagesLeft(connection);
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) XATransactionId(org.apache.activemq.command.XATransactionId) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 30 with XATransactionId

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

the class XARecoveryBrokerTest method testQueuePersistentUncommittedAcksLostOnRestart.

public void testQueuePersistentUncommittedAcksLostOnRestart() 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);
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        connection.send(message);
    }
    // Begin the transaction.
    XATransactionId txid = createXATransaction(sessionInfo);
    connection.send(createBeginTransaction(connectionInfo, txid));
    Message message = null;
    for (ActiveMQDestination dest : destinationList(destination)) {
        // Setup the consumer and receive the message.
        ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, dest);
        connection.send(consumerInfo);
        for (int i = 0; i < 4; i++) {
            message = receiveMessage(connection);
            assertNotNull(message);
        }
        MessageAck ack = createAck(consumerInfo, message, 4, MessageAck.STANDARD_ACK_TYPE);
        ack.setTransactionId(txid);
        connection.request(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);
    for (ActiveMQDestination dest : destinationList(destination)) {
        // Setup the consumer and receive the message.
        ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, dest);
        connection.send(consumerInfo);
        for (int i = 0; i < 4; i++) {
            message = receiveMessage(connection);
            assertNotNull(message);
        }
    }
    assertNoMessagesLeft(connection);
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) XATransactionId(org.apache.activemq.command.XATransactionId) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) SessionInfo(org.apache.activemq.command.SessionInfo) MessageAck(org.apache.activemq.command.MessageAck) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Aggregations

XATransactionId (org.apache.activemq.command.XATransactionId)37 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)15 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)15 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)15 Message (org.apache.activemq.command.Message)15 ProducerInfo (org.apache.activemq.command.ProducerInfo)15 SessionInfo (org.apache.activemq.command.SessionInfo)15 TransactionInfo (org.apache.activemq.command.TransactionInfo)11 DataArrayResponse (org.apache.activemq.command.DataArrayResponse)9 MessageAck (org.apache.activemq.command.MessageAck)9 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)4 Response (org.apache.activemq.command.Response)4 TransactionId (org.apache.activemq.command.TransactionId)4 BrokerService (org.apache.activemq.broker.BrokerService)2 DestinationViewMBean (org.apache.activemq.broker.jmx.DestinationViewMBean)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 HashSet (java.util.HashSet)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 XAException (javax.transaction.xa.XAException)1