Search in sources :

Example 1 with ForwardingEventDownstreamAdapter

use of org.eclipse.hono.event.impl.ForwardingEventDownstreamAdapter 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));
}
Also used : ProtonSender(io.vertx.proton.ProtonSender) Released(org.apache.qpid.proton.amqp.messaging.Released) ProtonDelivery(io.vertx.proton.ProtonDelivery) Message(org.apache.qpid.proton.message.Message) ForwardingEventDownstreamAdapter(org.eclipse.hono.event.impl.ForwardingEventDownstreamAdapter) Handler(io.vertx.core.Handler) UpstreamReceiver(org.eclipse.hono.messaging.UpstreamReceiver) MessagingMetrics(org.eclipse.hono.messaging.MessagingMetrics) Test(org.junit.Test)

Aggregations

Handler (io.vertx.core.Handler)1 ProtonDelivery (io.vertx.proton.ProtonDelivery)1 ProtonSender (io.vertx.proton.ProtonSender)1 Released (org.apache.qpid.proton.amqp.messaging.Released)1 Message (org.apache.qpid.proton.message.Message)1 ForwardingEventDownstreamAdapter (org.eclipse.hono.event.impl.ForwardingEventDownstreamAdapter)1 MessagingMetrics (org.eclipse.hono.messaging.MessagingMetrics)1 UpstreamReceiver (org.eclipse.hono.messaging.UpstreamReceiver)1 Test (org.junit.Test)1