Search in sources :

Example 96 with AmqpConnection

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

the class AmqpPluginTest method testQueueReceiverAutoCreatedQueue.

@Test(timeout = 60000)
public void testQueueReceiverAutoCreatedQueue() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpReceiver receiver = session.createReceiver("autoCreated");
    receiver.close();
    connection.close();
    verifier.validatePluginMethodsAtLeast(1, BEFORE_ADD_ADDRESS, AFTER_ADD_ADDRESS);
    // should fire once for the auto created address being removed
    verifier.validatePluginMethodsEquals(1, BEFORE_REMOVE_ADDRESS, AFTER_REMOVE_ADDRESS);
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Test(org.junit.Test)

Example 97 with AmqpConnection

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

the class AmqpPluginTest method testQueueReceiverReadAndAckMessage.

@Test(timeout = 60000)
public void testQueueReceiverReadAndAckMessage() throws Exception {
    sendMessages(getQueueName(), 1);
    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 message = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(message);
    message.accept();
    receiver.close();
    connection.close();
    verifier.validatePluginMethodsEquals(0, MESSAGE_EXPIRED, BEFORE_DEPLOY_BRIDGE, AFTER_DEPLOY_BRIDGE, BEFORE_REMOVE_BINDING, AFTER_REMOVE_BINDING);
    verifier.validatePluginMethodsAtLeast(1, AFTER_CREATE_CONNECTION, AFTER_DESTROY_CONNECTION, BEFORE_CREATE_SESSION, AFTER_CREATE_SESSION, BEFORE_CLOSE_SESSION, AFTER_CLOSE_SESSION, BEFORE_CREATE_CONSUMER, AFTER_CREATE_CONSUMER, BEFORE_CLOSE_CONSUMER, AFTER_CLOSE_CONSUMER, BEFORE_CREATE_QUEUE, AFTER_CREATE_QUEUE, MESSAGE_ACKED, BEFORE_SEND, AFTER_SEND, BEFORE_MESSAGE_ROUTE, AFTER_MESSAGE_ROUTE, BEFORE_DELIVER, AFTER_DELIVER, BEFORE_ADD_ADDRESS, AFTER_ADD_ADDRESS, BEFORE_ADD_BINDING, AFTER_ADD_BINDING);
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Queue(org.apache.activemq.artemis.core.server.Queue) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Example 98 with AmqpConnection

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

the class AmqpSecurityTest method testSendAndRejected.

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

        @Override
        public void inspectOpenedResource(Sender sender) {
            ErrorCondition condition = sender.getRemoteCondition();
            if (condition != null && condition.getCondition() != null) {
                if (!condition.getCondition().equals(AmqpError.UNAUTHORIZED_ACCESS)) {
                    markAsInvalid("Should have been tagged with unauthorized access error");
                }
            } else {
                markAsInvalid("Sender should have been opened with an error");
            }
        }
    });
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    try {
        try {
            session.createSender(getQueueName());
            fail("Should not be able to consume here.");
        } catch (Exception ex) {
            IntegrationTestLogger.LOGGER.info("Caught expected exception");
        }
        connection.getStateInspector().assertValid();
    } finally {
        connection.close();
    }
}
Also used : AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) Sender(org.apache.qpid.proton.engine.Sender) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) Test(org.junit.Test)

Example 99 with AmqpConnection

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

the class AmqpSecurityTest method testConsumerNotAuthorizedToCreateQueues.

@Test(timeout = 30000)
public void testConsumerNotAuthorizedToCreateQueues() throws Exception {
    AmqpClient client = createAmqpClient(noprivUser, noprivPass);
    client.setValidator(new AmqpValidator() {

        @Override
        public void inspectOpenedResource(Sender sender) {
            ErrorCondition condition = sender.getRemoteCondition();
            if (condition != null && condition.getCondition() != null) {
                if (!condition.getCondition().equals(AmqpError.UNAUTHORIZED_ACCESS)) {
                    markAsInvalid("Should have been tagged with unauthorized access error");
                }
            } else {
                markAsInvalid("Sender should have been opened with an error");
            }
        }
    });
    AmqpConnection connection = client.connect();
    try {
        AmqpSession session = connection.createSession();
        try {
            session.createReceiver(getQueueName(getPrecreatedQueueSize() + 1));
            fail("Should not be able to consume here.");
        } catch (Exception ex) {
            IntegrationTestLogger.LOGGER.info("Caught expected exception");
        }
        connection.getStateInspector().assertValid();
    } finally {
        connection.close();
    }
}
Also used : AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) Sender(org.apache.qpid.proton.engine.Sender) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) Test(org.junit.Test)

Example 100 with AmqpConnection

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

the class AmqpSecurityTest method testReceiverNotAuthorized.

@Test(timeout = 30000)
public void testReceiverNotAuthorized() throws Exception {
    AmqpClient client = createAmqpClient(noprivUser, noprivPass);
    client.setValidator(new AmqpValidator() {

        @Override
        public void inspectOpenedResource(Receiver receiver) {
            ErrorCondition condition = receiver.getRemoteCondition();
            if (condition != null && condition.getCondition() != null) {
                if (!condition.getCondition().equals(AmqpError.UNAUTHORIZED_ACCESS)) {
                    markAsInvalid("Should have been tagged with unauthorized access error");
                }
            } else {
                markAsInvalid("Receiver should have been opened with an error");
            }
        }
    });
    AmqpConnection connection = client.connect();
    try {
        AmqpSession session = connection.createSession();
        try {
            session.createReceiver(getQueueName());
            fail("Should not be able to consume here.");
        } catch (Exception ex) {
            IntegrationTestLogger.LOGGER.info("Caught expected exception");
        }
        connection.getStateInspector().assertValid();
    } finally {
        connection.close();
    }
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Receiver(org.apache.qpid.proton.engine.Receiver) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) 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