Search in sources :

Example 16 with AmqpValidator

use of org.apache.activemq.transport.amqp.client.AmqpValidator in project activemq-artemis by apache.

the class AmqpReceiverTest method testCreateQueueReceiverWithNoLocalSet.

@Test(timeout = 60000)
public void testCreateQueueReceiverWithNoLocalSet() throws Exception {
    AmqpClient client = createAmqpClient();
    client.setValidator(new AmqpValidator() {

        @SuppressWarnings("unchecked")
        @Override
        public void inspectOpenedResource(Receiver receiver) {
            if (receiver.getRemoteSource() == null) {
                markAsInvalid("Link opened with null source.");
            }
            Source source = (Source) receiver.getRemoteSource();
            Map<Symbol, Object> filters = source.getFilter();
            // Currently don't support noLocal on a Queue
            if (findFilter(filters, NO_LOCAL_FILTER_IDS) != null) {
                markAsInvalid("Broker did not return the NoLocal Filter on Attach");
            }
        }
    });
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    session.createReceiver(getQueueName(), null, true);
    connection.getStateInspector().assertValid();
    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) Receiver(org.apache.qpid.proton.engine.Receiver) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) HashMap(java.util.HashMap) Map(java.util.Map) Source(org.apache.qpid.proton.amqp.messaging.Source) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) Test(org.junit.Test)

Example 17 with AmqpValidator

use of org.apache.activemq.transport.amqp.client.AmqpValidator in project activemq-artemis by apache.

the class AmqpReceiverTest method testUnsupportedFiltersAreNotListedAsSupported.

@Test(timeout = 60000)
public void testUnsupportedFiltersAreNotListedAsSupported() throws Exception {
    AmqpClient client = createAmqpClient();
    client.setValidator(new AmqpValidator() {

        @SuppressWarnings("unchecked")
        @Override
        public void inspectOpenedResource(Receiver receiver) {
            if (receiver.getRemoteSource() == null) {
                markAsInvalid("Link opened with null source.");
            }
            Source source = (Source) receiver.getRemoteSource();
            Map<Symbol, Object> filters = source.getFilter();
            if (findFilter(filters, AmqpUnknownFilterType.UNKNOWN_FILTER_IDS) != null) {
                markAsInvalid("Broker should not return unsupported filter on attach.");
            }
        }
    });
    Map<Symbol, DescribedType> filters = new HashMap<>();
    filters.put(AmqpUnknownFilterType.UNKNOWN_FILTER_NAME, AmqpUnknownFilterType.UNKNOWN_FILTER);
    Source source = new Source();
    source.setAddress(getQueueName());
    source.setFilter(filters);
    source.setDurable(TerminusDurability.NONE);
    source.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    assertEquals(0, server.getTotalConsumerCount());
    session.createReceiver(source);
    assertEquals(1, server.getTotalConsumerCount());
    connection.getStateInspector().assertValid();
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) HashMap(java.util.HashMap) Symbol(org.apache.qpid.proton.amqp.Symbol) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Receiver(org.apache.qpid.proton.engine.Receiver) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) Source(org.apache.qpid.proton.amqp.messaging.Source) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) DescribedType(org.apache.qpid.proton.amqp.DescribedType) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 18 with AmqpValidator

use of org.apache.activemq.transport.amqp.client.AmqpValidator in project activemq-artemis by apache.

the class AmqpReceiverWithFiltersTest method testUnsupportedFiltersAreNotListedAsSupported.

@Test(timeout = 60000)
public void testUnsupportedFiltersAreNotListedAsSupported() throws Exception {
    AmqpClient client = createAmqpClient();
    client.setValidator(new AmqpValidator() {

        @SuppressWarnings("unchecked")
        @Override
        public void inspectOpenedResource(Receiver receiver) {
            if (receiver.getRemoteSource() == null) {
                markAsInvalid("Link opened with null source.");
            }
            Source source = (Source) receiver.getRemoteSource();
            Map<Symbol, Object> filters = source.getFilter();
            if (findFilter(filters, AmqpUnknownFilterType.UNKNOWN_FILTER_IDS) != null) {
                markAsInvalid("Broker should not return unsupported filter on attach.");
            }
        }
    });
    Map<Symbol, DescribedType> filters = new HashMap<>();
    filters.put(AmqpUnknownFilterType.UNKNOWN_FILTER_NAME, AmqpUnknownFilterType.UNKNOWN_FILTER);
    Source source = new Source();
    source.setAddress(getQueueName());
    source.setFilter(filters);
    source.setDurable(TerminusDurability.NONE);
    source.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    session.createReceiver(source);
    assertEquals(1, server.getTotalConsumerCount());
    connection.getStateInspector().assertValid();
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) HashMap(java.util.HashMap) Symbol(org.apache.qpid.proton.amqp.Symbol) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Receiver(org.apache.qpid.proton.engine.Receiver) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) Source(org.apache.qpid.proton.amqp.messaging.Source) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) DescribedType(org.apache.qpid.proton.amqp.DescribedType) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 19 with AmqpValidator

use of org.apache.activemq.transport.amqp.client.AmqpValidator in project activemq-artemis by apache.

the class AmqpInboundConnectionTest method testConnectionCarriesExpectedCapabilities.

@Test(timeout = 60000)
public void testConnectionCarriesExpectedCapabilities() throws Exception {
    AmqpClient client = createAmqpClient();
    assertNotNull(client);
    client.setValidator(new AmqpValidator() {

        @Override
        public void inspectOpenedResource(Connection connection) {
            Symbol[] offered = connection.getRemoteOfferedCapabilities();
            if (!contains(offered, ANONYMOUS_RELAY)) {
                markAsInvalid("Broker did not indicate it support anonymous relay");
                return;
            }
            if (!contains(offered, DELAYED_DELIVERY)) {
                markAsInvalid("Broker did not indicate it support delayed message delivery");
                return;
            }
        }
    });
    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 20 with AmqpValidator

use of org.apache.activemq.transport.amqp.client.AmqpValidator in project activemq-artemis by apache.

the class AmqpInboundConnectionTest method testCannotConnectWithSameContainerId.

@Test(timeout = 60000)
public void testCannotConnectWithSameContainerId() throws Exception {
    AmqpClient client = createAmqpClient();
    List<Symbol> desiredCapabilities = new ArrayList<>(1);
    desiredCapabilities.add(AmqpSupport.SOLE_CONNECTION_CAPABILITY);
    assertNotNull(client);
    AmqpConnection connection1 = addConnection(client.createConnection());
    AmqpConnection connection2 = addConnection(client.createConnection());
    connection1.setDesiredCapabilities(desiredCapabilities);
    connection2.setDesiredCapabilities(desiredCapabilities);
    connection1.setContainerId(getTestName());
    connection2.setContainerId(getTestName());
    connection1.connect();
    assertEquals(1, server.getConnectionCount());
    connection2.setStateInspector(new AmqpValidator() {

        @Override
        public void inspectOpenedResource(Connection connection) {
            if (!connection.getRemoteProperties().containsKey(CONNECTION_OPEN_FAILED)) {
                markAsInvalid("Broker did not set connection establishment failed property");
            }
        }

        @Override
        public void inspectClosedResource(Connection connection) {
            ErrorCondition remoteError = connection.getRemoteCondition();
            if (remoteError == null || remoteError.getCondition() == null) {
                markAsInvalid("Broker did not add error condition for duplicate client ID");
            } else {
                if (!remoteError.getCondition().equals(AmqpError.INVALID_FIELD)) {
                    markAsInvalid("Broker did not set condition to " + AmqpError.INVALID_FIELD);
                }
                if (!remoteError.getCondition().equals(AmqpError.INVALID_FIELD)) {
                    markAsInvalid("Broker did not set condition to " + AmqpError.INVALID_FIELD);
                }
            }
            // Validate the info map contains a hint that the container/client id was the
            // problem
            Map<?, ?> infoMap = remoteError.getInfo();
            if (infoMap == null) {
                markAsInvalid("Broker did not set an info map on condition");
            } else if (!infoMap.containsKey(INVALID_FIELD)) {
                markAsInvalid("Info map does not contain expected key");
            } else {
                Object value = infoMap.get(INVALID_FIELD);
                if (!CONTAINER_ID.equals(value)) {
                    markAsInvalid("Info map does not contain expected value: " + value);
                }
            }
        }
    });
    try {
        connection2.connect();
        fail("Should not be able to connect with same container Id.");
    } catch (Exception ex) {
        LOG.info("Second connection with same container Id failed as expected.");
    }
    connection2.getStateInspector().assertValid();
    connection2.close();
    Wait.assertEquals(1, server::getConnectionCount);
    connection1.close();
    Wait.assertEquals(0, server::getConnectionCount);
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) Symbol(org.apache.qpid.proton.amqp.Symbol) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) ArrayList(java.util.ArrayList) 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) Map(java.util.Map) Test(org.junit.Test)

Aggregations

AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)21 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)21 AmqpValidator (org.apache.activemq.transport.amqp.client.AmqpValidator)21 Test (org.junit.Test)21 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)15 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)8 Receiver (org.apache.qpid.proton.engine.Receiver)8 Map (java.util.Map)7 AmqpSender (org.apache.activemq.transport.amqp.client.AmqpSender)7 Sender (org.apache.qpid.proton.engine.Sender)7 Connection (org.apache.qpid.proton.engine.Connection)6 HashMap (java.util.HashMap)5 Source (org.apache.qpid.proton.amqp.messaging.Source)5 ErrorCondition (org.apache.qpid.proton.amqp.transport.ErrorCondition)5 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)4 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)4 Delivery (org.apache.qpid.proton.engine.Delivery)4 Symbol (org.apache.qpid.proton.amqp.Symbol)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 DescribedType (org.apache.qpid.proton.amqp.DescribedType)2