use of org.apache.activemq.transport.amqp.client.AmqpSender in project activemq-artemis by apache.
the class AmqpFlowControlTest method testCreditsAreAllocatedOnceOnLinkCreated.
@Test(timeout = 60000)
public void testCreditsAreAllocatedOnceOnLinkCreated() throws Exception {
AmqpClient client = createAmqpClient(new URI(singleCreditAcceptorURI));
AmqpConnection connection = addConnection(client.connect());
try {
AmqpSession session = connection.createSession();
AmqpSender sender = session.createSender(getQueueName());
assertEquals("Should only be issued one credit", 1, sender.getSender().getCredit());
} finally {
connection.close();
}
}
use of org.apache.activemq.transport.amqp.client.AmqpSender in project activemq-artemis by apache.
the class AmqpFlowControlTest method fillAddress.
/*
* Fills an address. Careful when using this method. Only use when rejected messages are switched on.
*/
private void fillAddress(String address) throws Exception {
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
Exception exception = null;
try {
AmqpSession session = connection.createSession();
AmqpSender sender = session.createSender(address);
sendUntilFull(sender);
} catch (Exception e) {
exception = e;
} finally {
connection.close();
}
// Should receive a rejected error
assertNotNull(exception);
assertTrue(exception.getMessage().contains("amqp:resource-limit-exceeded"));
}
use of org.apache.activemq.transport.amqp.client.AmqpSender in project activemq-artemis by apache.
the class AmqpFlowControlTest method testCreditsAreNotAllocatedWhenAddressIsFull.
@Test(timeout = 60000)
public void testCreditsAreNotAllocatedWhenAddressIsFull() throws Exception {
AmqpClient client = createAmqpClient(new URI(singleCreditAcceptorURI));
AmqpConnection connection = addConnection(client.connect());
try {
AmqpSession session = connection.createSession();
AmqpSender sender = session.createSender(getQueueName());
// Use blocking send to ensure buffered messages do not interfere with credit.
sender.setSendTimeout(-1);
sendUntilFull(sender);
// This should be -1. A single message is buffered in the client, and 0 credit has been allocated.
assertTrue(sender.getSender().getCredit() == -1);
long addressSize = server.getPagingManager().getPageStore(new SimpleString(getQueueName())).getAddressSize();
assertTrue(addressSize >= MAX_SIZE_BYTES && addressSize <= MAX_SIZE_BYTES_REJECT_THRESHOLD);
} finally {
connection.close();
}
}
use of org.apache.activemq.transport.amqp.client.AmqpSender in project activemq-artemis by apache.
the class AmqpLargeMessageTest method sendMessages.
private void sendMessages(int nMsgs, AmqpConnection connection) throws Exception {
connection.connect();
AmqpSession session = connection.createSession();
AmqpSender sender = session.createSender(testQueueName);
for (int i = 0; i < nMsgs; ++i) {
AmqpMessage message = createAmqpMessage((byte) 'A', PAYLOAD);
message.setApplicationProperty("i", (Integer) i);
message.setDurable(true);
sender.send(message);
}
session.close();
}
use of org.apache.activemq.transport.amqp.client.AmqpSender in project activemq-artemis by apache.
the class AmqpMessagePriorityTest method testMessagePriorityPreservedAfterServerRestart.
@Test(timeout = 60000)
public void testMessagePriorityPreservedAfterServerRestart() throws Exception {
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
AmqpSender sender = session.createSender(getQueueName());
AmqpMessage message = new AmqpMessage();
message.setDurable(true);
message.setMessageId("MessageID:1");
message.setPriority((short) 7);
sender.send(message);
sender.close();
connection.close();
server.stop();
server.start();
client = createAmqpClient();
connection = addConnection(client.connect());
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);
assertEquals((short) 7, receive.getPriority());
receiver.close();
assertEquals(1, queueView.getMessageCount());
connection.close();
}
Aggregations