use of org.apache.activemq.transport.amqp.client.AmqpClient in project activemq-artemis by apache.
the class AmqpSendReceiveTest method testReceiveMessageBeyondAckedAmountQueue.
@Test(timeout = 60000)
public void testReceiveMessageBeyondAckedAmountQueue() throws Exception {
final int MSG_COUNT = 50;
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
final String address = getQueueName();
AmqpReceiver receiver = session.createReceiver(address);
AmqpSender sender = session.createSender(address);
final Queue destinationView = getProxyToQueue(address);
for (int i = 0; i < MSG_COUNT; i++) {
AmqpMessage message = new AmqpMessage();
message.setMessageId("msg" + i);
sender.send(message);
}
List<AmqpMessage> pendingAcks = new ArrayList<>();
for (int i = 0; i < MSG_COUNT; i++) {
receiver.flow(1);
AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS);
assertNotNull(received);
pendingAcks.add(received);
}
// Send one more to check in-flight stays at zero with no credit and all
// pending messages settled.
AmqpMessage message = new AmqpMessage();
message.setMessageId("msg-final");
sender.send(message);
for (AmqpMessage pendingAck : pendingAcks) {
pendingAck.accept();
}
Wait.assertEquals(0, destinationView::getDeliveringCount);
sender.close();
receiver.close();
connection.close();
}
use of org.apache.activemq.transport.amqp.client.AmqpClient in project activemq-artemis by apache.
the class AmqpSendReceiveTest method testSimpleSendOneReceiveOne.
@Test(timeout = 60000)
public void testSimpleSendOneReceiveOne() throws Exception {
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
AmqpSender sender = session.createSender(getQueueName());
AmqpMessage message = new AmqpMessage();
message.setMessageId("msg" + 1);
message.setMessageAnnotation("serialNo", 1);
message.setText("Test-Message");
sender.send(message);
sender.close();
LOG.info("Attempting to read message with receiver");
AmqpReceiver receiver = session.createReceiver(getQueueName());
receiver.flow(2);
AmqpMessage received = receiver.receive(10, TimeUnit.SECONDS);
assertNotNull("Should have read message", received);
assertEquals("msg1", received.getMessageId());
received.accept();
receiver.close();
connection.close();
}
use of org.apache.activemq.transport.amqp.client.AmqpClient in project activemq-artemis by apache.
the class AmqpSendReceiveTest method testSecondReceiverOnQueueGetsAllUnconsumedMessages.
@Test(timeout = 60000)
public void testSecondReceiverOnQueueGetsAllUnconsumedMessages() throws Exception {
int MSG_COUNT = 20;
sendMessages(getQueueName(), MSG_COUNT);
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
AmqpReceiver receiver1 = session.createReceiver(getQueueName());
final Queue queueView = getProxyToQueue(getQueueName());
assertEquals(MSG_COUNT, queueView.getMessageCount());
receiver1.flow(20);
assertTrue("Should have dispatch to prefetch", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisfied() throws Exception {
return queueView.getDeliveringCount() >= 2;
}
}, TimeUnit.SECONDS.toMillis(5), TimeUnit.MILLISECONDS.toMillis(50)));
receiver1.close();
AmqpReceiver receiver2 = session.createReceiver(getQueueName());
assertEquals(1, server.getTotalConsumerCount());
receiver2.flow(MSG_COUNT * 2);
AmqpMessage message = receiver2.receive(5, TimeUnit.SECONDS);
assertNotNull(message);
message.accept();
message = receiver2.receive(5, TimeUnit.SECONDS);
assertNotNull(message);
message.accept();
assertTrue("Should have ack'd two", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisfied() throws Exception {
return queueView.getMessagesAcknowledged() == 2;
}
}, TimeUnit.SECONDS.toMillis(5), TimeUnit.MILLISECONDS.toMillis(50)));
receiver2.close();
assertEquals(MSG_COUNT - 2, queueView.getMessageCount());
connection.close();
}
use of org.apache.activemq.transport.amqp.client.AmqpClient in project activemq-artemis by apache.
the class AmqpSendReceiveTest method testMessageDurableFalse.
@Test(timeout = 60000)
public void testMessageDurableFalse() throws Exception {
sendMessages(getQueueName(), 1, false);
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
AmqpReceiver receiver = session.createReceiver(getQueueName());
Queue queueView = getProxyToQueue(getQueueName());
assertEquals(1, queueView.getMessageCount());
receiver.flow(1);
AmqpMessage receive = receiver.receive(5, TimeUnit.SECONDS);
assertNotNull(receive);
assertFalse(receive.isDurable());
receiver.close();
assertEquals(1, queueView.getMessageCount());
connection.close();
}
use of org.apache.activemq.transport.amqp.client.AmqpClient in project activemq-artemis by apache.
the class AmqpSendReceiveTest method testLinkDetatchErrorIsCorrectWhenQueueDoesNotExists.
@Test(timeout = 60000)
public void testLinkDetatchErrorIsCorrectWhenQueueDoesNotExists() throws Exception {
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
Exception expectedException = null;
try {
session.createSender("AnAddressThatDoesNotExist");
fail("Creating a sender here on an address that doesn't exist should fail");
} catch (Exception e) {
expectedException = e;
}
assertNotNull(expectedException);
assertTrue(expectedException.getMessage().contains("amqp:not-found"));
assertTrue(expectedException.getMessage().contains("target address does not exist"));
connection.close();
}
Aggregations