use of org.apache.activemq.command.ProducerInfo in project activemq-artemis by apache.
the class XARecoveryBrokerTest method testQueuePersistentPreparedAcksAvailableAfterRestartAndRollback.
public void testQueuePersistentPreparedAcksAvailableAfterRestartAndRollback() 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);
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));
ConsumerInfo consumerInfo;
Message message = 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 < 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));
// 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 while prepared
message = receiveMessage(connection);
assertNull(message);
assertNoMessagesLeft(connection);
// rollback so we get redelivery
connection.request(createRollbackTransaction(connectionInfo, txid));
LOG.info("new tx for redelivery");
txid = createXATransaction(sessionInfo);
connection.send(createBeginTransaction(connectionInfo, txid));
for (ActiveMQDestination dest : destinationList(destination)) {
// Setup the consumer and receive the message.
consumerInfo = createConsumerInfo(sessionInfo, dest);
connection.send(consumerInfo);
for (int i = 0; i < numMessages; i++) {
message = receiveMessage(connection);
assertNotNull("unexpected null on:" + i, message);
}
MessageAck ack = createAck(consumerInfo, message, numMessages, MessageAck.STANDARD_ACK_TYPE);
ack.setTransactionId(txid);
connection.send(ack);
}
// Commit
connection.request(createCommitTransaction1Phase(connectionInfo, txid));
// validate recovery complete
dataArrayResponse = (DataArrayResponse) connection.request(recoverInfo);
assertEquals("there are no prepared tx", 0, dataArrayResponse.getData().length);
}
use of org.apache.activemq.command.ProducerInfo in project activemq-artemis by apache.
the class BrokerTest method testTransactedSend.
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);
}
use of org.apache.activemq.command.ProducerInfo in project activemq-artemis by apache.
the class BrokerTest method testConsumerPrefetchAndDeliveredAck.
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));
}
use of org.apache.activemq.command.ProducerInfo in project activemq-artemis by apache.
the class BrokerTest method testTopicConsumerOnlySeeMessagesAfterCreation.
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);
}
use of org.apache.activemq.command.ProducerInfo in project activemq-artemis by apache.
the class BrokerTest method testCompositeSend.
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));
}
Aggregations