Search in sources :

Example 51 with AmqpConnection

use of org.apache.activemq.transport.amqp.client.AmqpConnection 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"));
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) IOException(java.io.IOException) ResourceAllocationException(javax.jms.ResourceAllocationException)

Example 52 with AmqpConnection

use of org.apache.activemq.transport.amqp.client.AmqpConnection 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();
    }
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) URI(java.net.URI) Test(org.junit.Test)

Example 53 with AmqpConnection

use of org.apache.activemq.transport.amqp.client.AmqpConnection 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();
    }
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Test(org.junit.Test)

Example 54 with AmqpConnection

use of org.apache.activemq.transport.amqp.client.AmqpConnection 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();
    }
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) Connection(org.apache.qpid.proton.engine.Connection) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) Test(org.junit.Test)

Example 55 with AmqpConnection

use of org.apache.activemq.transport.amqp.client.AmqpConnection 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());
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Test(org.junit.Test)

Aggregations

AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)183 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)183 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)168 Test (org.junit.Test)158 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)123 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)114 AmqpSender (org.apache.activemq.transport.amqp.client.AmqpSender)91 Queue (org.apache.activemq.artemis.core.server.Queue)70 Source (org.apache.qpid.proton.amqp.messaging.Source)25 AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)22 AmqpValidator (org.apache.activemq.transport.amqp.client.AmqpValidator)21 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)14 Receiver (org.apache.qpid.proton.engine.Receiver)12 CountDownLatch (java.util.concurrent.CountDownLatch)8 Map (java.util.Map)7 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)7 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)7 Sender (org.apache.qpid.proton.engine.Sender)7 URI (java.net.URI)6 HashMap (java.util.HashMap)6