use of org.eclipse.hono.client.ReconnectListener 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);
}
Aggregations