Search in sources :

Example 11 with DataArrayResponse

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

the class XARecoveryBrokerTest method testPreparedJmxView.

public void testPreparedJmxView() 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));
    }
    Response response = connection.request(new TransactionInfo(connectionInfo.getConnectionId(), null, TransactionInfo.RECOVER));
    assertNotNull(response);
    DataArrayResponse dar = (DataArrayResponse) response;
    assertEquals(4, dar.getData().length);
    // view prepared in kahadb view
    if (broker.getPersistenceAdapter() instanceof KahaDBPersistenceAdapter) {
        PersistenceAdapterViewMBean kahadbView = getProxyToPersistenceAdapter(broker.getPersistenceAdapter().toString());
        String txFromView = kahadbView.getTransactions();
        LOG.info("Tx view fromm PA:" + txFromView);
        assertTrue("xid with our dud format in transaction string " + txFromView, txFromView.contains("XID:[55,"));
    }
    // restart the broker.
    restartBroker();
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    connection.send(connectionInfo);
    response = connection.request(new TransactionInfo(connectionInfo.getConnectionId(), null, TransactionInfo.RECOVER));
    assertNotNull(response);
    dar = (DataArrayResponse) response;
    assertEquals(4, dar.getData().length);
    // validate destination depth via jmx
    DestinationViewMBean destinationView = getProxyToDestination(destinationList(destination)[0]);
    assertEquals("enqueue count does not see prepared", 0, destinationView.getQueueSize());
    TransactionId first = (TransactionId) dar.getData()[0];
    int commitCount = 0;
    // via jmx, force outcome
    for (int i = 0; i < 4; i++) {
        RecoveredXATransactionViewMBean mbean = getProxyToPreparedTransactionViewMBean((TransactionId) dar.getData()[i]);
        if (i % 2 == 0) {
            mbean.heuristicCommit();
            commitCount++;
        } else {
            mbean.heuristicRollback();
        }
    }
    // verify all completed
    response = connection.request(new TransactionInfo(connectionInfo.getConnectionId(), null, TransactionInfo.RECOVER));
    assertNotNull(response);
    dar = (DataArrayResponse) response;
    assertEquals(0, dar.getData().length);
    // verify messages available
    assertEquals("enqueue count reflects outcome", commitCount, destinationView.getQueueSize());
    // verify mbeans gone
    try {
        RecoveredXATransactionViewMBean gone = getProxyToPreparedTransactionViewMBean(first);
        gone.heuristicRollback();
        fail("Excepted not found");
    } catch (InstanceNotFoundException expectedNotfound) {
    }
}
Also used : DestinationViewMBean(org.apache.activemq.broker.jmx.DestinationViewMBean) ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) XATransactionId(org.apache.activemq.command.XATransactionId) Message(org.apache.activemq.command.Message) InstanceNotFoundException(javax.management.InstanceNotFoundException) SessionInfo(org.apache.activemq.command.SessionInfo) PersistenceAdapterViewMBean(org.apache.activemq.broker.jmx.PersistenceAdapterViewMBean) 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) RecoveredXATransactionViewMBean(org.apache.activemq.broker.jmx.RecoveredXATransactionViewMBean) DataArrayResponse(org.apache.activemq.command.DataArrayResponse) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)

Example 12 with DataArrayResponse

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

the class XARecoveryBrokerTest method testQueuePersistentPreparedAcksNotLostOnRestart.

public void testQueuePersistentPreparedAcksNotLostOnRestart() 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));
    ConsumerInfo consumerInfo;
    Message m = null;
    for (ActiveMQDestination dest : destinationList(destination)) {
        // Setup the consumer and receive the message.
        consumerInfo = createConsumerInfo(sessionInfo, dest);
        connection.send(consumerInfo);
        for (int i = 0; i < 4; i++) {
            m = receiveMessage(connection);
            assertNotNull(m);
        }
        // one ack with last received, mimic a beforeEnd synchronization
        MessageAck ack = createAck(consumerInfo, m, 4, MessageAck.STANDARD_ACK_TYPE);
        ack.setTransactionId(txid);
        connection.send(ack);
    }
    connection.request(createPrepareTransaction(connectionInfo, txid));
    // restart the broker.
    restartBroker();
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    connection.send(connectionInfo);
    // validate recovery
    TransactionInfo recoverInfo = new TransactionInfo(connectionInfo.getConnectionId(), null, TransactionInfo.RECOVER);
    DataArrayResponse dataArrayResponse = (DataArrayResponse) connection.request(recoverInfo);
    assertEquals("there is a prepared tx", 1, dataArrayResponse.getData().length);
    assertEquals("it matches", txid, dataArrayResponse.getData()[0]);
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(sessionInfo);
    consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // no redelivery, exactly once semantics unless there is rollback
    m = receiveMessage(connection);
    assertNull(m);
    assertNoMessagesLeft(connection);
    // validate destination depth via jmx
    DestinationViewMBean destinationView = getProxyToDestination(destinationList(destination)[0]);
    assertEquals("enqueue count does not see prepared acks", 4, destinationView.getQueueSize());
    assertEquals("enqueue count does not see prepared acks", 0, destinationView.getDequeueCount());
    connection.request(createCommitTransaction2Phase(connectionInfo, txid));
    // validate recovery complete
    dataArrayResponse = (DataArrayResponse) connection.request(recoverInfo);
    assertEquals("there are no prepared tx", 0, dataArrayResponse.getData().length);
    assertEquals("enqueue count does not see committed acks", 0, destinationView.getQueueSize());
    assertEquals("enqueue count does not see committed acks", 4, destinationView.getDequeueCount());
}
Also used : DestinationViewMBean(org.apache.activemq.broker.jmx.DestinationViewMBean) 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) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) TransactionInfo(org.apache.activemq.command.TransactionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) DataArrayResponse(org.apache.activemq.command.DataArrayResponse)

Example 13 with DataArrayResponse

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

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

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

the class DataArrayResponseTest method createObject.

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

Aggregations

DataArrayResponse (org.apache.activemq.command.DataArrayResponse)27 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)9 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)9 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)9 Message (org.apache.activemq.command.Message)9 ProducerInfo (org.apache.activemq.command.ProducerInfo)9 SessionInfo (org.apache.activemq.command.SessionInfo)9 TransactionInfo (org.apache.activemq.command.TransactionInfo)9 XATransactionId (org.apache.activemq.command.XATransactionId)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 PersistenceAdapterViewMBean (org.apache.activemq.broker.jmx.PersistenceAdapterViewMBean)1 RecoveredXATransactionViewMBean (org.apache.activemq.broker.jmx.RecoveredXATransactionViewMBean)1 KahaDBPersistenceAdapter (org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)1