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