Search in sources :

Example 21 with ProtonReceiver

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

the class ProtonBasedApplicationClientTest method setUp.

/**
 * Sets up the fixture.
 */
@BeforeEach
void setUp() {
    final var vertx = mock(Vertx.class);
    when(vertx.eventBus()).thenReturn(mock(EventBus.class));
    connection = AmqpClientUnitTestHelper.mockHonoConnection(vertx);
    final ProtonReceiver receiver = AmqpClientUnitTestHelper.mockProtonReceiver();
    when(connection.createReceiver(anyString(), any(ProtonQoS.class), any(ProtonMessageHandler.class), anyInt(), anyBoolean(), VertxMockSupport.anyHandler())).thenReturn(Future.succeededFuture(receiver));
    final ProtonSender sender = AmqpClientUnitTestHelper.mockProtonSender();
    when(connection.createSender(anyString(), any(), any())).thenReturn(Future.succeededFuture(sender));
    client = new ProtonBasedApplicationClient(connection);
}
Also used : ProtonReceiver(io.vertx.proton.ProtonReceiver) ProtonSender(io.vertx.proton.ProtonSender) ProtonQoS(io.vertx.proton.ProtonQoS) ProtonMessageHandler(io.vertx.proton.ProtonMessageHandler) EventBus(io.vertx.core.eventbus.EventBus) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 22 with ProtonReceiver

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

the class ProtonBasedRequestResponseCommandClientTest method setUp.

/**
 * Sets up the fixture.
 */
@BeforeEach
void setUp() {
    vertx = mock(Vertx.class);
    connection = AmqpClientUnitTestHelper.mockHonoConnection(vertx);
    final ProtonReceiver receiver = AmqpClientUnitTestHelper.mockProtonReceiver();
    when(connection.createReceiver(anyString(), any(ProtonQoS.class), any(ProtonMessageHandler.class), VertxMockSupport.anyHandler())).thenReturn(Future.succeededFuture(receiver));
    protonDelivery = mock(ProtonDelivery.class);
    sender = AmqpClientUnitTestHelper.mockProtonSender();
    when(sender.send(any(Message.class), VertxMockSupport.anyHandler())).thenReturn(protonDelivery);
    when(connection.createSender(anyString(), any(), any())).thenReturn(Future.succeededFuture(sender));
    requestResponseCommandClient = new ProtonBasedRequestResponseCommandClient(connection, SendMessageSampler.Factory.noop());
    tenantId = UUID.randomUUID().toString();
    deviceId = UUID.randomUUID().toString();
}
Also used : ProtonReceiver(io.vertx.proton.ProtonReceiver) ProtonQoS(io.vertx.proton.ProtonQoS) ProtonMessageHandler(io.vertx.proton.ProtonMessageHandler) ProtonDelivery(io.vertx.proton.ProtonDelivery) Message(org.apache.qpid.proton.message.Message) Vertx(io.vertx.core.Vertx) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 23 with ProtonReceiver

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

the class ProtonBasedNotificationReceiverTest method setUp.

/**
 * Sets up the fixture.
 */
@BeforeEach
public void setUp() {
    final Tracer tracer = TracingMockSupport.mockTracer(TracingMockSupport.mockSpan());
    final EventBus eventBus = mock(EventBus.class);
    final Vertx vertx = mock(Vertx.class);
    when(vertx.eventBus()).thenReturn(eventBus);
    final RequestResponseClientConfigProperties config = new RequestResponseClientConfigProperties();
    // don't let requestTimeout timer be started
    config.setRequestTimeout(0);
    connection = AmqpClientUnitTestHelper.mockHonoConnection(vertx, config, tracer);
    when(connection.connect()).thenReturn(Future.succeededFuture(connection));
    final ProtonReceiver receiver = AmqpClientUnitTestHelper.mockProtonReceiver();
    when(connection.createReceiver(anyString(), any(ProtonQoS.class), any(ProtonMessageHandler.class), VertxMockSupport.anyHandler())).thenReturn(Future.succeededFuture(receiver));
    client = new ProtonBasedNotificationReceiver(connection);
}
Also used : ProtonReceiver(io.vertx.proton.ProtonReceiver) ProtonQoS(io.vertx.proton.ProtonQoS) ProtonMessageHandler(io.vertx.proton.ProtonMessageHandler) RequestResponseClientConfigProperties(org.eclipse.hono.client.RequestResponseClientConfigProperties) Tracer(io.opentracing.Tracer) EventBus(io.vertx.core.eventbus.EventBus) Vertx(io.vertx.core.Vertx) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 24 with ProtonReceiver

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

the class AmqpAdapterClientCommandConsumerTest method testReceiverIsRecreatedOnConnectionFailure.

/**
 * Verifies that the proton receiver is recreated after a reconnect.
 */
@Test
public void testReceiverIsRecreatedOnConnectionFailure() {
    final AtomicReference<ReconnectListener<HonoConnection>> reconnectListener = new AtomicReference<>();
    doAnswer(invocation -> {
        reconnectListener.set(invocation.getArgument(0));
        return null;
    }).when(connection).addReconnectListener(any());
    // GIVEN a connected command consumer
    @SuppressWarnings("unchecked") final Future<CommandConsumer> consumerFuture = AmqpAdapterClientCommandConsumer.create(connection, mock(BiConsumer.class));
    final AmqpAdapterClientCommandConsumer commandConsumer = (AmqpAdapterClientCommandConsumer) consumerFuture.result();
    // WHEN the connection is re-established
    final ProtonReceiver newReceiver = createNewProtonReceiver(connection);
    reconnectListener.get().onReconnect(null);
    // THEN the receiver is recreated
    verify(connection, times(2)).createReceiver(eq("command"), eq(ProtonQoS.AT_LEAST_ONCE), any(ProtonMessageHandler.class), VertxMockSupport.anyHandler());
    final ProtonReceiver actual = commandConsumer.getReceiver();
    assertThat(actual).isNotEqualTo(originalReceiver);
    assertThat(actual).isEqualTo(newReceiver);
}
Also used : ProtonReceiver(io.vertx.proton.ProtonReceiver) ProtonMessageHandler(io.vertx.proton.ProtonMessageHandler) CommandConsumer(org.eclipse.hono.client.command.CommandConsumer) AtomicReference(java.util.concurrent.atomic.AtomicReference) ReconnectListener(org.eclipse.hono.client.ReconnectListener) BiConsumer(java.util.function.BiConsumer) Test(org.junit.jupiter.api.Test)

Example 25 with ProtonReceiver

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

the class AmqpAdapterClientCommandConsumerTest method createNewProtonReceiver.

private ProtonReceiver createNewProtonReceiver(final HonoConnection honoConnectionMock) {
    final ProtonReceiver receiver = mock(ProtonReceiver.class);
    when(honoConnectionMock.createReceiver(any(), any(), any(), any())).thenReturn(Future.succeededFuture(receiver));
    return receiver;
}
Also used : ProtonReceiver(io.vertx.proton.ProtonReceiver)

Aggregations

ProtonReceiver (io.vertx.proton.ProtonReceiver)45 ProtonConnection (io.vertx.proton.ProtonConnection)19 ProtonMessageHandler (io.vertx.proton.ProtonMessageHandler)19 Vertx (io.vertx.core.Vertx)17 ProtonQoS (io.vertx.proton.ProtonQoS)16 Handler (io.vertx.core.Handler)13 ProtonSender (io.vertx.proton.ProtonSender)13 ErrorCondition (org.apache.qpid.proton.amqp.transport.ErrorCondition)13 Message (org.apache.qpid.proton.message.Message)12 Future (io.vertx.core.Future)11 BeforeEach (org.junit.jupiter.api.BeforeEach)11 ProtonDelivery (io.vertx.proton.ProtonDelivery)10 HttpURLConnection (java.net.HttpURLConnection)10 ClientErrorException (org.eclipse.hono.client.ClientErrorException)10 ResourceIdentifier (org.eclipse.hono.util.ResourceIdentifier)10 Test (org.junit.jupiter.api.Test)10 AsyncResult (io.vertx.core.AsyncResult)9 Promise (io.vertx.core.Promise)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)9