Search in sources :

Example 6 with Record

use of org.apache.qpid.proton.engine.Record in project hono by eclipse.

the class AmqpServiceBaseTest method newConnection.

private static ProtonConnection newConnection(final HonoUser user) {
    final Record attachments = new RecordImpl();
    attachments.set(Constants.KEY_CONNECTION_ID, String.class, CON_ID);
    attachments.set(Constants.KEY_CLIENT_PRINCIPAL, HonoUser.class, user);
    final ProtonConnection con = mock(ProtonConnection.class);
    when(con.attachments()).thenReturn(attachments);
    when(con.getRemoteContainer()).thenReturn("test-client");
    return con;
}
Also used : ProtonConnection(io.vertx.proton.ProtonConnection) Record(org.apache.qpid.proton.engine.Record) RecordImpl(org.apache.qpid.proton.engine.impl.RecordImpl)

Example 7 with Record

use of org.apache.qpid.proton.engine.Record in project hono by eclipse.

the class AbstractHonoClientTest method testCreateSenderFails.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void testCreateSenderFails(final Supplier<ErrorCondition> errorSupplier, final Predicate<Throwable> failureAssertion) {
    final Record attachments = new RecordImpl();
    final ProtonSender sender = mock(ProtonSender.class);
    when(sender.getRemoteCondition()).thenReturn(errorSupplier.get());
    when(sender.attachments()).thenReturn(attachments);
    final ProtonConnection con = mock(ProtonConnection.class);
    when(con.createSender(anyString())).thenReturn(sender);
    final Future<ProtonSender> result = AbstractHonoClient.createSender(context, props, con, "target", ProtonQoS.AT_LEAST_ONCE, null);
    final ArgumentCaptor<Handler> openHandler = ArgumentCaptor.forClass(Handler.class);
    verify(sender).openHandler(openHandler.capture());
    openHandler.getValue().handle(Future.failedFuture(new IllegalStateException()));
    assertTrue(result.failed());
    assertTrue(failureAssertion.test(result.cause()));
}
Also used : ProtonSender(io.vertx.proton.ProtonSender) ProtonConnection(io.vertx.proton.ProtonConnection) Handler(io.vertx.core.Handler) Record(org.apache.qpid.proton.engine.Record) RecordImpl(org.apache.qpid.proton.engine.impl.RecordImpl)

Example 8 with Record

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

the class ProtonReceiverImplTest method testAttachments.

@Test
public void testAttachments() {
    Connection conn = Connection.Factory.create();
    Session sess = conn.session();
    Receiver r = sess.receiver("name");
    ProtonReceiverImpl receiver = new ProtonReceiverImpl(r);
    Record attachments = receiver.attachments();
    assertNotNull("Expected attachments but got null", attachments);
    assertSame("Got different attachments on subsequent call", attachments, receiver.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 : Connection(org.apache.qpid.proton.engine.Connection) ProtonReceiver(io.vertx.proton.ProtonReceiver) Receiver(org.apache.qpid.proton.engine.Receiver) Record(org.apache.qpid.proton.engine.Record) Session(org.apache.qpid.proton.engine.Session) Test(org.junit.Test)

Example 9 with Record

use of org.apache.qpid.proton.engine.Record in project hono by eclipse.

the class AbstractHonoClientTest method testCreateReceiverFails.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void testCreateReceiverFails(final Supplier<ErrorCondition> errorSupplier, final Predicate<Throwable> failureAssertion) {
    final Record attachments = new RecordImpl();
    final ProtonReceiver receiver = mock(ProtonReceiver.class);
    when(receiver.getRemoteCondition()).thenReturn(errorSupplier.get());
    when(receiver.attachments()).thenReturn(attachments);
    final ProtonConnection con = mock(ProtonConnection.class);
    when(con.createReceiver(anyString())).thenReturn(receiver);
    final Future<ProtonReceiver> result = AbstractHonoClient.createReceiver(context, props, con, "source", ProtonQoS.AT_LEAST_ONCE, (delivery, msg) -> {
    }, null);
    final ArgumentCaptor<Handler> openHandler = ArgumentCaptor.forClass(Handler.class);
    verify(receiver).openHandler(openHandler.capture());
    openHandler.getValue().handle(Future.failedFuture(new IllegalStateException()));
    assertTrue(result.failed());
    assertTrue(failureAssertion.test(result.cause()));
}
Also used : ProtonReceiver(io.vertx.proton.ProtonReceiver) ProtonConnection(io.vertx.proton.ProtonConnection) Handler(io.vertx.core.Handler) Record(org.apache.qpid.proton.engine.Record) RecordImpl(org.apache.qpid.proton.engine.impl.RecordImpl)

Example 10 with Record

use of org.apache.qpid.proton.engine.Record in project hono by eclipse.

the class HonoMessagingTest method newConnection.

private static ProtonConnection newConnection(final HonoUser user) {
    final Record attachments = new RecordImpl();
    attachments.set(Constants.KEY_CONNECTION_ID, String.class, CON_ID);
    attachments.set(Constants.KEY_CLIENT_PRINCIPAL, HonoUser.class, user);
    final ProtonConnection con = mock(ProtonConnection.class);
    when(con.attachments()).thenReturn(attachments);
    when(con.getRemoteContainer()).thenReturn("test-client");
    return con;
}
Also used : ProtonConnection(io.vertx.proton.ProtonConnection) Record(org.apache.qpid.proton.engine.Record) RecordImpl(org.apache.qpid.proton.engine.impl.RecordImpl)

Aggregations

Record (org.apache.qpid.proton.engine.Record)11 Test (org.junit.Test)5 ProtonConnection (io.vertx.proton.ProtonConnection)4 Connection (org.apache.qpid.proton.engine.Connection)4 Session (org.apache.qpid.proton.engine.Session)4 RecordImpl (org.apache.qpid.proton.engine.impl.RecordImpl)4 Handler (io.vertx.core.Handler)3 ProtonReceiver (io.vertx.proton.ProtonReceiver)2 ProtonSender (io.vertx.proton.ProtonSender)2 Sender (org.apache.qpid.proton.engine.Sender)2 Vertx (io.vertx.core.Vertx)1 Target (org.apache.qpid.proton.amqp.messaging.Target)1 Delivery (org.apache.qpid.proton.engine.Delivery)1 Receiver (org.apache.qpid.proton.engine.Receiver)1