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());
}
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());
}
Aggregations