Search in sources :

Example 21 with ProtonSender

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

the class ForwardingDownstreamAdapterTest method testOnClientDisconnectClosesDownstreamSenders.

/**
 * Verifies that corresponding sender links to the downstream container are closed when
 * a connection to an upstream client is lost/closed.
 */
@Test
public void testOnClientDisconnectClosesDownstreamSenders() {
    final String upstreamConnection = "upstream-connection-id";
    final String linkId = "link-id";
    final UpstreamReceiver client = newClient(linkId, upstreamConnection);
    final ProtonSender downstreamSender = newMockSender(false);
    givenADownstreamAdapter(downstreamSender);
    adapter.setDownstreamConnectionFactory(connectionFactory);
    adapter.start(Future.future());
    adapter.addSender(client, downstreamSender);
    // WHEN the upstream client disconnects
    adapter.onClientDisconnect(upstreamConnection);
    // THEN the downstream sender is closed and removed from the sender list
    verify(downstreamSender).close();
    assertTrue(adapter.isActiveSendersEmpty());
    assertTrue(adapter.isSendersPerConnectionEmpty());
}
Also used : ProtonSender(io.vertx.proton.ProtonSender) Test(org.junit.Test)

Example 22 with ProtonSender

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

the class ForwardingDownstreamAdapterTest method testDownstreamDisconnectFailsClientAttachRequests.

/**
 * Verifies that all requests from upstream clients to attach are failed when the connection to the
 * downstream container is lost.
 *
 * @param ctx The Vert.x test context.
 */
@Test
public void testDownstreamDisconnectFailsClientAttachRequests(final TestContext ctx) {
    when(con.isDisconnected()).thenReturn(Boolean.FALSE);
    final UpstreamReceiver client = newClient();
    when(client.getTargetAddress()).thenReturn(targetAddress.toString());
    final HandlerCapturingConnectionFactory factory = new HandlerCapturingConnectionFactory(con);
    final SenderFactory senderFactory = (con, address, qos, drainHandler, closeHook) -> {
        Future<ProtonSender> result = Future.future();
        return result;
    };
    final Async disconnected = ctx.async();
    // GIVEN an adapter connected to a downstream container with a client trying to attach
    givenADownstreamAdapter(senderFactory);
    adapter.setDownstreamConnectionFactory(factory);
    adapter.start(Future.future());
    assertTrue(adapter.isConnected());
    adapter.onClientAttach(client, attachAttempt -> {
        if (attachAttempt.failed()) {
            disconnected.countDown();
        } else {
            fail("client attach should not have succeeded");
        }
    });
    // WHEN the downstream connection fails
    factory.getDisconnectHandler().handle(con);
    // THEN the adapter tries to reconnect to the downstream container and has closed all upstream receivers
    disconnected.await(1000);
    assertTrue(adapter.isActiveSendersEmpty());
    assertTrue(adapter.isSendersPerConnectionEmpty());
}
Also used : TestContext(io.vertx.ext.unit.TestContext) ProtonConnection(io.vertx.proton.ProtonConnection) Async(io.vertx.ext.unit.Async) ProtonDelivery(io.vertx.proton.ProtonDelivery) RunWith(org.junit.runner.RunWith) Constants(org.eclipse.hono.util.Constants) ConnectionFactory(org.eclipse.hono.connection.ConnectionFactory) ProtonSession(io.vertx.proton.ProtonSession) TelemetryConstants(org.eclipse.hono.util.TelemetryConstants) ArgumentCaptor(org.mockito.ArgumentCaptor) ProtonClientOptions(io.vertx.proton.ProtonClientOptions) BiConsumer(java.util.function.BiConsumer) Assert.fail(org.junit.Assert.fail) Message(org.apache.qpid.proton.message.Message) ResourceIdentifier(org.eclipse.hono.util.ResourceIdentifier) AsyncResult(io.vertx.core.AsyncResult) Before(org.junit.Before) Vertx(io.vertx.core.Vertx) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ProtonQoS(io.vertx.proton.ProtonQoS) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Future(io.vertx.core.Future) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) CountDownLatch(java.util.concurrent.CountDownLatch) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) TestSupport(org.eclipse.hono.TestSupport) ProtonSender(io.vertx.proton.ProtonSender) Handler(io.vertx.core.Handler) Record(org.apache.qpid.proton.engine.Record) Async(io.vertx.ext.unit.Async) Future(io.vertx.core.Future) Test(org.junit.Test)

Aggregations

ProtonSender (io.vertx.proton.ProtonSender)22 Handler (io.vertx.core.Handler)11 Message (org.apache.qpid.proton.message.Message)9 Test (org.junit.Test)9 ProtonDelivery (io.vertx.proton.ProtonDelivery)8 ProtonConnection (io.vertx.proton.ProtonConnection)6 MessagingMetrics (org.eclipse.hono.messaging.MessagingMetrics)5 UpstreamReceiver (org.eclipse.hono.messaging.UpstreamReceiver)5 Vertx (io.vertx.core.Vertx)4 Future (io.vertx.core.Future)3 Async (io.vertx.ext.unit.Async)3 ProtonQoS (io.vertx.proton.ProtonQoS)3 ErrorCondition (org.apache.qpid.proton.amqp.transport.ErrorCondition)3 Record (org.apache.qpid.proton.engine.Record)3 Constants (org.eclipse.hono.util.Constants)3 ResourceIdentifier (org.eclipse.hono.util.ResourceIdentifier)3 AsyncResult (io.vertx.core.AsyncResult)2 ProtonClientOptions (io.vertx.proton.ProtonClientOptions)2 ProtonHelper (io.vertx.proton.ProtonHelper)2 ProtonSession (io.vertx.proton.ProtonSession)2