use of org.eclipse.hono.messaging.UpstreamReceiver in project hono by eclipse.
the class ForwardingTelemetryDownstreamAdapterTest method testProcessMessageDiscardsMessageIfNoCreditIsAvailable.
/**
* Verifies that telemetry data is discarded if no downstream credit is available.
*
* @param ctx The test context.
*/
@SuppressWarnings("unchecked")
@Test
public void testProcessMessageDiscardsMessageIfNoCreditIsAvailable(final TestContext ctx) {
final UpstreamReceiver client = TestSupport.newClient();
final ProtonDelivery upstreamDelivery = mock(ProtonDelivery.class);
when(upstreamDelivery.remotelySettled()).thenReturn(Boolean.FALSE);
// GIVEN an adapter with a connection to a downstream container
ProtonSender sender = TestSupport.newMockSender(false);
when(sender.sendQueueFull()).thenReturn(true);
final ForwardingEventDownstreamAdapter adapter = new ForwardingEventDownstreamAdapter(vertx, newMockSenderFactory(sender));
adapter.setMetrics(mock(MessagingMetrics.class));
adapter.setDownstreamConnectionFactory(TestSupport.newMockConnectionFactory(false));
adapter.start(Future.future());
adapter.addSender(client, sender);
// WHEN processing an event
final Message msg = ProtonHelper.message(TELEMETRY_MSG_CONTENT);
MessageHelper.addDeviceId(msg, DEVICE_ID);
adapter.processMessage(client, upstreamDelivery, msg);
// THEN the the message is accepted
verify(upstreamDelivery).disposition(any(Released.class), eq(Boolean.TRUE));
// but is not delivered to the downstream container
verify(sender, never()).send(any(Message.class), any(Handler.class));
}
Aggregations