Search in sources :

Example 11 with Sender

use of org.apache.qpid.proton.engine.Sender in project activemq-artemis by apache.

the class AmqpTransactionTest method testSentTransactionalMessageIsSettleWithTransactionalDisposition.

@Test(timeout = 30000)
public void testSentTransactionalMessageIsSettleWithTransactionalDisposition() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    assertNotNull(session);
    AmqpSender sender = session.createSender(getQueueName());
    sender.setStateInspector(new AmqpValidator() {

        @Override
        public void inspectDeliveryUpdate(Sender sender, Delivery delivery) {
            if (delivery.remotelySettled()) {
                DeliveryState state = delivery.getRemoteState();
                if (state instanceof TransactionalState) {
                    LOG.debug("Remote settled with TX state: {}", state);
                } else {
                    LOG.warn("Remote settled with non-TX state: {}", state);
                    markAsInvalid("Remote did not settled with TransactionState.");
                }
            }
        }
    });
    session.begin();
    assertTrue(session.isInTransaction());
    AmqpMessage message = new AmqpMessage();
    message.setText("Test-Message");
    sender.send(message);
    session.commit();
    sender.getStateInspector().assertValid();
    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) DeliveryState(org.apache.qpid.proton.amqp.transport.DeliveryState) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Delivery(org.apache.qpid.proton.engine.Delivery) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) TransactionalState(org.apache.qpid.proton.amqp.transaction.TransactionalState) Test(org.junit.Test)

Example 12 with Sender

use of org.apache.qpid.proton.engine.Sender in project vertx-proton by vert-x3.

the class ProtonDeliveryImplTest method testAttachments.

@Test
public void testAttachments() {
    Connection conn = Connection.Factory.create();
    Session sess = conn.session();
    Sender s = sess.sender("name");
    Delivery d = s.delivery("myTag".getBytes(StandardCharsets.UTF_8));
    ProtonDeliveryImpl delivery = new ProtonDeliveryImpl(d);
    Record attachments = delivery.attachments();
    assertNotNull("Expected attachments but got null", attachments);
    assertSame("Got different attachments on subsequent call", attachments, delivery.attachments());
    String key = "My-Connection-Key";
    assertNull("Expected attachment to be null", attachments.get(key, Connection.class));
    attachments.set(key, Connection.class, conn);
    assertNotNull("Expected attachment to be returned", attachments.get(key, Connection.class));
    assertSame("Expected attachment to be given object", conn, attachments.get(key, Connection.class));
}
Also used : Sender(org.apache.qpid.proton.engine.Sender) Connection(org.apache.qpid.proton.engine.Connection) Record(org.apache.qpid.proton.engine.Record) Delivery(org.apache.qpid.proton.engine.Delivery) Session(org.apache.qpid.proton.engine.Session) Test(org.junit.Test)

Example 13 with Sender

use of org.apache.qpid.proton.engine.Sender in project vertx-proton by vert-x3.

the class ProtonSenderImplTest method testAutoSettleIsEnabledByDefault.

@Test
public void testAutoSettleIsEnabledByDefault() {
    Connection conn = Connection.Factory.create();
    Session sess = conn.session();
    Sender s = sess.sender("name");
    ProtonSenderImpl sender = new ProtonSenderImpl(s);
    assertTrue(sender.isAutoSettle());
}
Also used : Sender(org.apache.qpid.proton.engine.Sender) Connection(org.apache.qpid.proton.engine.Connection) Session(org.apache.qpid.proton.engine.Session) Test(org.junit.Test)

Example 14 with Sender

use of org.apache.qpid.proton.engine.Sender in project vertx-proton by vert-x3.

the class ProtonSenderImplTest method testAttachments.

@Test
public void testAttachments() {
    Connection conn = Connection.Factory.create();
    Session sess = conn.session();
    Sender s = sess.sender("name");
    ProtonSenderImpl sender = new ProtonSenderImpl(s);
    Record attachments = sender.attachments();
    assertNotNull("Expected attachments but got null", attachments);
    assertSame("Got different attachments on subsequent call", attachments, sender.attachments());
    String key = "My-Connection-Key";
    assertNull("Expected attachment to be null", attachments.get(key, Connection.class));
    attachments.set(key, Connection.class, conn);
    assertNotNull("Expected attachment to be returned", attachments.get(key, Connection.class));
    assertSame("Expected attachment to be given object", conn, attachments.get(key, Connection.class));
}
Also used : Sender(org.apache.qpid.proton.engine.Sender) Connection(org.apache.qpid.proton.engine.Connection) Record(org.apache.qpid.proton.engine.Record) Session(org.apache.qpid.proton.engine.Session) Test(org.junit.Test)

Example 15 with Sender

use of org.apache.qpid.proton.engine.Sender 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

Sender (org.apache.qpid.proton.engine.Sender)22 Test (org.junit.Test)10 AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)7 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)7 AmqpSender (org.apache.activemq.transport.amqp.client.AmqpSender)7 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)7 AmqpValidator (org.apache.activemq.transport.amqp.client.AmqpValidator)7 Delivery (org.apache.qpid.proton.engine.Delivery)7 Source (org.apache.qpid.proton.amqp.messaging.Source)5 Connection (org.apache.qpid.proton.engine.Connection)5 Session (org.apache.qpid.proton.engine.Session)5 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)4 Symbol (org.apache.qpid.proton.amqp.Symbol)4 Target (org.apache.qpid.proton.amqp.messaging.Target)4 IAmqpSender (com.microsoft.azure.servicebus.amqp.IAmqpSender)3 ErrorCondition (org.apache.qpid.proton.amqp.transport.ErrorCondition)3 Receiver (org.apache.qpid.proton.engine.Receiver)3 SendLinkHandler (com.microsoft.azure.servicebus.amqp.SendLinkHandler)2 SessionHandler (com.microsoft.azure.servicebus.amqp.SessionHandler)2 HashMap (java.util.HashMap)2