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