Search in sources :

Example 86 with AmqpSession

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

the class ClientDefinedMultiConsumerTest method testAddressDoesntExist.

@Test(timeout = 60000)
public void testAddressDoesntExist() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect("myClientId"));
    AmqpSession session = connection.createSession();
    Source source = createNonSharedSource(TerminusDurability.CONFIGURATION);
    Source source1 = createSharedSource(TerminusDurability.CONFIGURATION);
    AmqpReceiver receiver = session.createMulticastReceiver(source, "myReceiverID", "mySub");
    try {
        session.createMulticastReceiver(source1, "myReceiverID", "mySub|2");
        fail("Exception expected");
    } catch (Exception e) {
    // expected
    } finally {
        receiver.close();
    }
    connection.close();
}
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) Source(org.apache.qpid.proton.amqp.messaging.Source) Test(org.junit.Test)

Example 87 with AmqpSession

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

the class ClientDefinedMultiConsumerTest method test2ConsumersOnSharedDurableAddress.

@Test(timeout = 60000)
public void test2ConsumersOnSharedDurableAddress() throws Exception {
    AddressInfo addressInfo = new AddressInfo(address);
    addressInfo.getRoutingTypes().add(RoutingType.MULTICAST);
    server.addAddressInfo(addressInfo);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect("myClientId"));
    AmqpSession session = connection.createSession();
    Source source = createSharedSource(TerminusDurability.CONFIGURATION);
    AmqpReceiver receiver = session.createMulticastReceiver(source, "myReceiverID", "mySub");
    AmqpReceiver receiver2 = session.createMulticastReceiver(source, "myReceiverID", "mySub|2");
    receiver.flow(1);
    receiver2.flow(1);
    sendMessages(address.toString(), 2);
    AmqpMessage amqpMessage = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(amqpMessage);
    amqpMessage = receiver2.receive(5, TimeUnit.SECONDS);
    assertNotNull(amqpMessage);
    assertEquals(2, ((QueueImpl) server.getPostOffice().getBinding(SimpleString.toSimpleString("myClientId.mySub")).getBindable()).getConsumerCount());
    receiver.close();
    assertNotNull(server.getPostOffice().getBinding(SimpleString.toSimpleString("myClientId.mySub")));
    receiver2.close();
    // check its been deleted
    assertNull(server.getPostOffice().getBinding(SimpleString.toSimpleString("myClientId.mySub")));
    connection.close();
}
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) Source(org.apache.qpid.proton.amqp.messaging.Source) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 88 with AmqpSession

use of org.apache.activemq.transport.amqp.client.AmqpSession 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 89 with AmqpSession

use of org.apache.activemq.transport.amqp.client.AmqpSession 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 90 with AmqpSession

use of org.apache.activemq.transport.amqp.client.AmqpSession 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)

Aggregations

AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)169 AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)168 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)168 Test (org.junit.Test)143 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)123 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)115 AmqpSender (org.apache.activemq.transport.amqp.client.AmqpSender)92 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)15 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)14 Receiver (org.apache.qpid.proton.engine.Receiver)12 Sender (org.apache.qpid.proton.engine.Sender)7 URI (java.net.URI)6 HashMap (java.util.HashMap)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 Map (java.util.Map)5 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)5 ArrayList (java.util.ArrayList)4