use of org.apache.activemq.transport.amqp.client.AmqpMessage in project activemq-artemis by apache.
the class AmqpPresettledReceiverTest method testPresettledReceiverWithinBoundsOfActiveTXWithSendAndRollback.
@Test(timeout = 60000)
public void testPresettledReceiverWithinBoundsOfActiveTXWithSendAndRollback() throws Exception {
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
AmqpSender sender = session.createSender(getQueueName());
final Queue queue = getProxyToQueue(getQueueName());
AmqpMessage message = new AmqpMessage();
message.setText("Test-Message");
sender.send(message);
Wait.assertEquals(1, queue::getMessageCount);
AmqpReceiver receiver = session.createReceiver(getQueueName(), null, false, true);
session.begin();
receiver.flow(1);
AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS);
assertNotNull(received);
assertTrue(received.getWrappedDelivery().remotelySettled());
message = new AmqpMessage();
message.setText("Test-Message - Rolled Back");
sender.send(message);
session.rollback();
assertEquals(0, queue.getMessageCount());
sender.close();
connection.close();
}
use of org.apache.activemq.transport.amqp.client.AmqpMessage in project activemq-artemis by apache.
the class AmqpPresettledReceiverTest method doTestPresettledReceiverWithinBoundsOfActiveTX.
private void doTestPresettledReceiverWithinBoundsOfActiveTX(boolean commit) throws Exception {
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
AmqpSender sender = session.createSender(getQueueName());
final Queue queue = getProxyToQueue(getQueueName());
AmqpMessage message = new AmqpMessage();
message.setText("Test-Message");
sender.send(message);
Wait.assertEquals(1, queue::getMessageCount);
AmqpReceiver receiver = session.createReceiver(getQueueName(), null, false, true);
session.begin();
receiver.flow(1);
AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS);
assertNotNull(received);
assertTrue(received.getWrappedDelivery().remotelySettled());
if (commit) {
session.commit();
} else {
session.rollback();
}
assertEquals(0, queue.getMessageCount());
sender.close();
connection.close();
}
use of org.apache.activemq.transport.amqp.client.AmqpMessage in project activemq-artemis by apache.
the class AmqpReceiverDispositionTest method doModifiedDispositionTestImpl.
private void doModifiedDispositionTestImpl(Boolean deliveryFailed, Boolean undeliverableHere) throws Exception {
sendMessages(getQueueName(), 1);
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
AmqpReceiver receiver1 = session.createReceiver(getQueueName());
receiver1.flow(1);
AmqpMessage message = receiver1.receive(5, TimeUnit.SECONDS);
assertNotNull("did not receive message first time", message);
Message protonMessage = message.getWrappedMessage();
assertNotNull(protonMessage);
assertEquals("Unexpected initial value for AMQP delivery-count", 0, protonMessage.getDeliveryCount());
message.modified(deliveryFailed, undeliverableHere);
// Remote must not redispatch to the client if undeliverable here is true
if (Boolean.TRUE.equals(undeliverableHere)) {
receiver1.flow(1);
message = receiver1.receive(1, TimeUnit.SECONDS);
assertNull("Should not receive message again", message);
}
AmqpReceiver receiver2 = session.createReceiver(getQueueName());
receiver2.flow(1);
message = receiver2.receive(5, TimeUnit.SECONDS);
assertNotNull("did not receive message again", message);
int expectedDeliveryCount = 0;
if (Boolean.TRUE.equals(deliveryFailed)) {
expectedDeliveryCount = 1;
}
message.accept();
Message protonMessage2 = message.getWrappedMessage();
assertNotNull(protonMessage2);
assertEquals("Unexpected updated value for AMQP delivery-count", expectedDeliveryCount, protonMessage2.getDeliveryCount());
connection.close();
}
use of org.apache.activemq.transport.amqp.client.AmqpMessage in project activemq-artemis by apache.
the class AmqpReceiverDispositionTest method testReleasedDisposition.
@Test(timeout = 30000)
public void testReleasedDisposition() throws Exception {
sendMessages(getQueueName(), 1);
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
AmqpReceiver receiver1 = session.createReceiver(getQueueName());
receiver1.flow(1);
AmqpMessage message = receiver1.receive(5, TimeUnit.SECONDS);
AmqpReceiver receiver2 = session.createReceiver(getQueueName());
assertNotNull("did not receive message first time", message);
assertEquals("MessageID:0", message.getMessageId());
Message protonMessage = message.getWrappedMessage();
assertNotNull(protonMessage);
assertEquals("Unexpected initial value for AMQP delivery-count", 0, protonMessage.getDeliveryCount());
receiver2.flow(1);
message.release();
// Read the message again and validate its state
message = receiver2.receive(10, TimeUnit.SECONDS);
assertNotNull("did not receive message again", message);
assertEquals("MessageID:0", message.getMessageId());
message.accept();
protonMessage = message.getWrappedMessage();
assertNotNull(protonMessage);
assertEquals("Unexpected updated value for AMQP delivery-count", 0, protonMessage.getDeliveryCount());
connection.close();
}
use of org.apache.activemq.transport.amqp.client.AmqpMessage in project activemq-artemis by apache.
the class AmqpReceiverDrainTest method doTestReceiverCanDrainMessages.
private void doTestReceiverCanDrainMessages(boolean topic) throws Exception {
final String destinationName;
if (topic) {
destinationName = getTopicName();
} else {
destinationName = getQueueName();
}
int MSG_COUNT = 20;
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
AmqpReceiver receiver = session.createReceiver(destinationName);
sendMessages(destinationName, MSG_COUNT);
Queue queueView = getProxyToQueue(destinationName);
Wait.assertEquals(MSG_COUNT, queueView::getMessageCount);
Wait.assertEquals(0, queueView::getDeliveringCount);
receiver.drain(MSG_COUNT);
for (int i = 0; i < MSG_COUNT; ++i) {
AmqpMessage message = receiver.receive(5, TimeUnit.SECONDS);
assertNotNull("Failed to read message: " + (i + 1), message);
IntegrationTestLogger.LOGGER.info("Read message: " + message.getMessageId());
message.accept();
}
receiver.close();
connection.close();
}
Aggregations