Search in sources :

Example 11 with ProtonReceiver

use of io.vertx.proton.ProtonReceiver 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 12 with ProtonReceiver

use of io.vertx.proton.ProtonReceiver in project hono by eclipse.

the class EventConsumerImplTest method testHandlerCallsCloseHook.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void testHandlerCallsCloseHook(final TestContext ctx, final BiConsumer<ProtonReceiver, ArgumentCaptor<Handler>> handlerCaptor) {
    // GIVEN an open event consumer
    final Async consumerCreation = ctx.async();
    final BiConsumer<ProtonDelivery, Message> eventConsumer = mock(BiConsumer.class);
    final RecordImpl attachments = new RecordImpl();
    final Source source = mock(Source.class);
    when(source.getAddress()).thenReturn("source/address");
    final ProtonReceiver receiver = mock(ProtonReceiver.class);
    when(receiver.isOpen()).thenReturn(Boolean.TRUE);
    when(receiver.getSource()).thenReturn(source);
    when(receiver.attachments()).thenReturn(attachments);
    when(receiver.open()).then(answer -> {
        attachments.set(EventConsumerImpl.KEY_LINK_ESTABLISHED, Boolean.class, Boolean.TRUE);
        consumerCreation.complete();
        return receiver;
    });
    final ProtonConnection con = mock(ProtonConnection.class);
    when(con.createReceiver(anyString())).thenReturn(receiver);
    final Handler<String> closeHook = mock(Handler.class);
    final ArgumentCaptor<Handler> captor = ArgumentCaptor.forClass(Handler.class);
    EventConsumerImpl.create(vertx.getOrCreateContext(), new ClientConfigProperties(), con, "source/address", eventConsumer, ok -> {
    }, closeHook);
    consumerCreation.await();
    handlerCaptor.accept(receiver, captor);
    // WHEN the receiver link is closed
    captor.getValue().handle(Future.succeededFuture(receiver));
    // THEN the close hook is called
    verify(closeHook).handle(any());
    // and the receiver link is closed
    verify(receiver).close();
}
Also used : ProtonReceiver(io.vertx.proton.ProtonReceiver) ProtonDelivery(io.vertx.proton.ProtonDelivery) Message(org.apache.qpid.proton.message.Message) ProtonMessageHandler(io.vertx.proton.ProtonMessageHandler) Handler(io.vertx.core.Handler) RecordImpl(org.apache.qpid.proton.engine.impl.RecordImpl) Source(org.apache.qpid.proton.amqp.transport.Source) ProtonConnection(io.vertx.proton.ProtonConnection) Async(io.vertx.ext.unit.Async) ClientConfigProperties(org.eclipse.hono.config.ClientConfigProperties)

Example 13 with ProtonReceiver

use of io.vertx.proton.ProtonReceiver in project hono by eclipse.

the class EventEndpointTest method testOnLinkAttachDisconnectsClientsUsingWrongQos.

/**
 * Verifies that the endpoint rejects a client's attempt to create a link using <em>AT_MOST_ONCE</em>
 * delivery mode.
 */
@Test
public void testOnLinkAttachDisconnectsClientsUsingWrongQos() {
    ProtonConnection con = mock(ProtonConnection.class);
    ProtonReceiver receiver = mock(ProtonReceiver.class);
    when(receiver.getRemoteQoS()).thenReturn(ProtonQoS.AT_MOST_ONCE);
    ResourceIdentifier targetAddress = ResourceIdentifier.from("event", "tenant", null);
    endpoint.onLinkAttach(con, receiver, targetAddress);
    ArgumentCaptor<ErrorCondition> errorCondition = ArgumentCaptor.forClass(ErrorCondition.class);
    verify(receiver).setCondition(errorCondition.capture());
    assertThat(errorCondition.getValue(), is(ErrorConditions.ERROR_UNSUPPORTED_DELIVERY_MODE));
    verify(receiver).close();
}
Also used : ProtonReceiver(io.vertx.proton.ProtonReceiver) ProtonConnection(io.vertx.proton.ProtonConnection) ResourceIdentifier(org.eclipse.hono.util.ResourceIdentifier) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) Test(org.junit.Test)

Example 14 with ProtonReceiver

use of io.vertx.proton.ProtonReceiver in project hono by eclipse.

the class HonoClientUnitTestHelper method mockProtonReceiver.

/**
 * Creates a mocked Proton receiver which always returns {@code true} when its isOpen method is called.
 *
 * @return The mocked receiver.
 */
public static final ProtonReceiver mockProtonReceiver() {
    final ProtonReceiver receiver = mock(ProtonReceiver.class);
    when(receiver.isOpen()).thenReturn(Boolean.TRUE);
    return receiver;
}
Also used : ProtonReceiver(io.vertx.proton.ProtonReceiver)

Example 15 with ProtonReceiver

use of io.vertx.proton.ProtonReceiver in project hono by eclipse.

the class RegistrationClientImplTest method setUp.

/**
 * Sets up the fixture.
 */
@SuppressWarnings("unchecked")
@Before
public void setUp() {
    vertx = mock(Vertx.class);
    context = HonoClientUnitTestHelper.mockContext(vertx);
    final ProtonReceiver receiver = HonoClientUnitTestHelper.mockProtonReceiver();
    sender = HonoClientUnitTestHelper.mockProtonSender();
    cache = mock(ExpiringValueCache.class);
    final RequestResponseClientConfigProperties config = new RequestResponseClientConfigProperties();
    client = new RegistrationClientImpl(context, config, "tenant", sender, receiver);
}
Also used : ProtonReceiver(io.vertx.proton.ProtonReceiver) RequestResponseClientConfigProperties(org.eclipse.hono.client.RequestResponseClientConfigProperties) ExpiringValueCache(org.eclipse.hono.cache.ExpiringValueCache) Vertx(io.vertx.core.Vertx) Before(org.junit.Before)

Aggregations

ProtonReceiver (io.vertx.proton.ProtonReceiver)17 ProtonConnection (io.vertx.proton.ProtonConnection)9 Test (org.junit.Test)9 ResourceIdentifier (org.eclipse.hono.util.ResourceIdentifier)7 Handler (io.vertx.core.Handler)5 Vertx (io.vertx.core.Vertx)4 ProtonDelivery (io.vertx.proton.ProtonDelivery)4 ProtonMessageHandler (io.vertx.proton.ProtonMessageHandler)4 ErrorCondition (org.apache.qpid.proton.amqp.transport.ErrorCondition)4 Message (org.apache.qpid.proton.message.Message)4 RecordImpl (org.apache.qpid.proton.engine.impl.RecordImpl)3 ServiceConfigProperties (org.eclipse.hono.config.ServiceConfigProperties)3 AuthorizationService (org.eclipse.hono.service.auth.AuthorizationService)3 AsyncResult (io.vertx.core.AsyncResult)2 Future (io.vertx.core.Future)2 Async (io.vertx.ext.unit.Async)2 ProtonHelper (io.vertx.proton.ProtonHelper)2 ProtonQoS (io.vertx.proton.ProtonQoS)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Source (org.apache.qpid.proton.amqp.transport.Source)2