use of org.apache.activemq.transport.amqp.client.AmqpClient 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.AmqpClient 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.AmqpClient in project activemq-artemis by apache.
the class AmqpInboundConnectionTest method testCloseIsSentOnConnectionClose.
@Test(timeout = 60000)
public void testCloseIsSentOnConnectionClose() throws Exception {
AmqpClient client = createAmqpClient();
AmqpConnection amqpConnection = client.connect();
try {
for (RemotingConnection connection : server.getRemotingService().getConnections()) {
server.getRemotingService().removeConnection(connection);
connection.disconnect(true);
}
Wait.assertTrue(amqpConnection::isClosed);
assertEquals(AmqpSupport.CONNECTION_FORCED, amqpConnection.getConnection().getRemoteCondition().getCondition());
} finally {
amqpConnection.close();
}
}
use of org.apache.activemq.transport.amqp.client.AmqpClient in project activemq-artemis by apache.
the class AmqpInboundConnectionTest method testBrokerContainerId.
@Test(timeout = 60000)
public void testBrokerContainerId() throws Exception {
AmqpClient client = createAmqpClient();
assertNotNull(client);
client.setValidator(new AmqpValidator() {
@Override
public void inspectOpenedResource(Connection connection) {
if (!BROKER_NAME.equals(connection.getRemoteContainer())) {
markAsInvalid("Broker did not send the expected container ID");
}
}
});
AmqpConnection connection = addConnection(client.connect());
try {
assertNotNull(connection);
connection.getStateInspector().assertValid();
} finally {
connection.close();
}
}
use of org.apache.activemq.transport.amqp.client.AmqpClient in project activemq-artemis by apache.
the class AmqpInboundConnectionTest method testCanConnectWithDifferentContainerIds.
@Test(timeout = 60000)
public void testCanConnectWithDifferentContainerIds() throws Exception {
AmqpClient client = createAmqpClient();
assertNotNull(client);
AmqpConnection connection1 = addConnection(client.createConnection());
AmqpConnection connection2 = addConnection(client.createConnection());
connection1.setContainerId(getTestName() + "-Client:1");
connection2.setContainerId(getTestName() + "-Client:2");
connection1.connect();
assertEquals(1, server.getConnectionCount());
connection2.connect();
assertEquals(2, server.getConnectionCount());
connection1.close();
assertEquals(1, server.getConnectionCount());
connection2.close();
assertEquals(0, server.getConnectionCount());
}
Aggregations