use of io.vertx.core.Handler in project hono by eclipse.
the class AbstractHonoClientTest method setUp.
/**
* Sets up the fixture.
*/
@SuppressWarnings("unchecked")
@Before
public void setUp() {
props = new ClientConfigProperties();
context = mock(Context.class);
doAnswer(invocation -> {
final Handler<Void> handler = invocation.getArgument(0);
handler.handle(null);
return null;
}).when(context).runOnContext(any(Handler.class));
}
use of io.vertx.core.Handler 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()));
}
use of io.vertx.core.Handler in project hono by eclipse.
the class AbstractRequestResponseClientTest method testCreateAndSendRequestFailsWithServerErrorExceptionIfSendQueueFull.
/**
* Verifies that the client fails the handler for sending a request message
* with a {@link ServerErrorException} if the link to the peer has no credit left.
*
* @param ctx The vert.x test context.
*/
@Test
public void testCreateAndSendRequestFailsWithServerErrorExceptionIfSendQueueFull(final TestContext ctx) {
// GIVEN a request-response client with a full send queue
when(sender.sendQueueFull()).thenReturn(Boolean.TRUE);
// WHEN sending a request message
final Async sendFailure = ctx.async();
client.createAndSendRequest("get", null, ctx.asyncAssertFailure(t -> {
ctx.assertTrue(ServerErrorException.class.isInstance(t));
sendFailure.complete();
}));
// THEN the message is not sent and the request result handler is failed
sendFailure.await();
verify(sender, never()).send(any(Message.class));
}
use of io.vertx.core.Handler in project hono by eclipse.
the class AbstractRequestResponseClientTest method testCreateAndSendRequestFailsIfReceiverIsNotOpen.
/**
* Verifies that a response handler is immediately failed with a
* {@link ServerErrorException} when the receiver link is not open (yet).
*
* @param ctx The vert.x test context.
*/
@Test
public void testCreateAndSendRequestFailsIfReceiverIsNotOpen(final TestContext ctx) {
// GIVEN a client whose sender and receiver are not open
when(receiver.isOpen()).thenReturn(Boolean.FALSE);
// WHEN sending a request
Async requestFailure = ctx.async();
client.createAndSendRequest("get", null, ctx.asyncAssertFailure(t -> {
ctx.assertTrue(ServerErrorException.class.isInstance(t));
requestFailure.complete();
}));
// THEN the request fails immediately
requestFailure.await();
}
use of io.vertx.core.Handler in project hono by eclipse.
the class AbstractRequestResponseClientTest method testCreateAndSendRequestFailsIfSenderIsNotOpen.
/**
* Verifies that a response handler is immediately failed with a
* {@link ServerErrorException} when the sender link is not open (yet).
*
* @param ctx The vert.x test context.
*/
@Test
public void testCreateAndSendRequestFailsIfSenderIsNotOpen(final TestContext ctx) {
// GIVEN a client whose sender and receiver are not open
when(sender.isOpen()).thenReturn(Boolean.FALSE);
// WHEN sending a request
Async requestFailure = ctx.async();
client.createAndSendRequest("get", null, ctx.asyncAssertFailure(t -> {
ctx.assertTrue(ServerErrorException.class.isInstance(t));
requestFailure.complete();
}));
// THEN the request fails immediately
requestFailure.await();
}
Aggregations