Search in sources :

Example 51 with Rejected

use of org.apache.qpid.proton.amqp.messaging.Rejected in project hono by eclipse.

the class GenericSenderLinkTest method testSendAndWaitForOutcomeFailsForRejectedOutcome.

private void testSendAndWaitForOutcomeFailsForRejectedOutcome(final Symbol errorCondition, final Consumer<Throwable> failureAssertions) {
    // GIVEN a sender that has credit
    when(sender.sendQueueFull()).thenReturn(Boolean.FALSE);
    // WHEN trying to send a message
    final Span span = mock(Span.class);
    final Message message = ProtonHelper.message("some payload");
    message.setContentType("text/plain");
    MessageHelper.addDeviceId(message, "device");
    final Future<ProtonDelivery> result = messageSender.sendAndWaitForOutcome(message, span);
    // THEN the message has been sent
    final ArgumentCaptor<Handler<ProtonDelivery>> deliveryUpdateHandler = VertxMockSupport.argumentCaptorHandler();
    verify(sender).send(any(Message.class), deliveryUpdateHandler.capture());
    // but the request is not completed
    assertThat(result.isComplete()).isFalse();
    // and when the peer rejects the message
    final var condition = new ErrorCondition();
    condition.setCondition(errorCondition);
    final var error = new Rejected();
    error.setError(condition);
    final ProtonDelivery rejected = mock(ProtonDelivery.class);
    when(rejected.remotelySettled()).thenReturn(Boolean.TRUE);
    when(rejected.getRemoteState()).thenReturn(error);
    deliveryUpdateHandler.getValue().handle(rejected);
    // the request is failed
    assertThat(result.failed()).isTrue();
    // with the expected error
    failureAssertions.accept(result.cause());
}
Also used : Message(org.apache.qpid.proton.message.Message) ProtonDelivery(io.vertx.proton.ProtonDelivery) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) Handler(io.vertx.core.Handler) Rejected(org.apache.qpid.proton.amqp.messaging.Rejected) Span(io.opentracing.Span)

Example 52 with Rejected

use of org.apache.qpid.proton.amqp.messaging.Rejected in project hono by eclipse.

the class GenericSenderLinkTest method testSendSucceedsForRejectedOutcome.

/**
 * Verifies that the sender does not wait for the peer to settle and
 * accept a message before succeeding.
 */
@Test
public void testSendSucceedsForRejectedOutcome() {
    // GIVEN a sender that has credit
    when(sender.sendQueueFull()).thenReturn(Boolean.FALSE);
    // WHEN trying to send a message
    final Span span = mock(Span.class);
    final Message message = ProtonHelper.message("some payload");
    message.setContentType("text/plain");
    MessageHelper.addDeviceId(message, "device");
    final Future<ProtonDelivery> result = messageSender.send(message, span);
    // which gets rejected by the peer
    final ArgumentCaptor<Handler<ProtonDelivery>> deliveryUpdateHandler = VertxMockSupport.argumentCaptorHandler();
    verify(sender).send(any(Message.class), deliveryUpdateHandler.capture());
    final ProtonDelivery rejected = mock(ProtonDelivery.class);
    when(rejected.remotelySettled()).thenReturn(Boolean.TRUE);
    when(rejected.getRemoteState()).thenReturn(new Rejected());
    deliveryUpdateHandler.getValue().handle(rejected);
    // THEN the resulting future is succeeded nevertheless
    assertThat(result.succeeded()).isTrue();
    // and the span has been finished
    verify(span).finish();
}
Also used : Message(org.apache.qpid.proton.message.Message) ProtonDelivery(io.vertx.proton.ProtonDelivery) Handler(io.vertx.core.Handler) Rejected(org.apache.qpid.proton.amqp.messaging.Rejected) Span(io.opentracing.Span) Test(org.junit.jupiter.api.Test)

Example 53 with Rejected

use of org.apache.qpid.proton.amqp.messaging.Rejected in project hono by eclipse.

the class GenericSenderLinkTest method testSendAndWaitForRawOutcomeSucceedsForRejectedOutcome.

/**
 * Verifies that the sender succeeds if the peer rejects a message and no mapping of the
 * delivery output should be done.
 */
@Test
public void testSendAndWaitForRawOutcomeSucceedsForRejectedOutcome() {
    // GIVEN a sender that has credit
    when(sender.sendQueueFull()).thenReturn(Boolean.FALSE);
    // WHEN trying to send a message
    final Span span = mock(Span.class);
    final Message message = ProtonHelper.message("some payload");
    message.setContentType("text/plain");
    MessageHelper.addDeviceId(message, "device");
    final Future<ProtonDelivery> result = messageSender.sendAndWaitForRawOutcome(message, span);
    // THEN the message has been sent
    final ArgumentCaptor<Handler<ProtonDelivery>> deliveryUpdateHandler = VertxMockSupport.argumentCaptorHandler();
    verify(sender).send(any(Message.class), deliveryUpdateHandler.capture());
    // but the request is not completed
    assertThat(result.isComplete()).isFalse();
    // and when the peer rejects the message
    final ProtonDelivery rejected = mock(ProtonDelivery.class);
    when(rejected.remotelySettled()).thenReturn(Boolean.TRUE);
    when(rejected.getRemoteState()).thenReturn(new Rejected());
    deliveryUpdateHandler.getValue().handle(rejected);
    // the request is succeeded
    assertThat(result.succeeded()).isTrue();
}
Also used : Message(org.apache.qpid.proton.message.Message) ProtonDelivery(io.vertx.proton.ProtonDelivery) Handler(io.vertx.core.Handler) Rejected(org.apache.qpid.proton.amqp.messaging.Rejected) Span(io.opentracing.Span) Test(org.junit.jupiter.api.Test)

Example 54 with Rejected

use of org.apache.qpid.proton.amqp.messaging.Rejected in project hono by eclipse.

the class MessageHelper method rejected.

/**
 * Rejects and settles an AMQP 1.0 message.
 *
 * @param delivery The message's delivery handle.
 * @param error The error condition to set as the reason for rejecting the message (may be {@code null}.
 * @throws NullPointerException if delivery is {@code null}.
 */
public static void rejected(final ProtonDelivery delivery, final ErrorCondition error) {
    Objects.requireNonNull(delivery);
    final Rejected rejected = new Rejected();
    // doesn't matter if null
    rejected.setError(error);
    delivery.disposition(rejected, true);
}
Also used : Rejected(org.apache.qpid.proton.amqp.messaging.Rejected)

Example 55 with Rejected

use of org.apache.qpid.proton.amqp.messaging.Rejected in project hono by eclipse.

the class ProtonBasedMappingAndDelegatingCommandHandlerTest method testMapWithNoAdapterInstanceFoundAndMessageInvalid.

/**
 * Verifies the behaviour of the <em>mapAndDelegateIncomingCommandMessage</em> method in a scenario where
 * no command handling adapter instance is found for the command message device and the command message
 * is invalid.
 */
@Test
public void testMapWithNoAdapterInstanceFoundAndMessageInvalid() {
    final String deviceId = "4711";
    // GIVEN a deviceId commandHandler registered for some adapter instance
    when(commandTargetMapper.getTargetGatewayAndAdapterInstance(anyString(), anyString(), any())).thenReturn(Future.succeededFuture(createTargetAdapterInstanceJson(deviceId, "someAdapterInstanceId")));
    // WHEN mapping and delegating an invalid command message
    final Message message = getValidCommandMessage(deviceId);
    // make the message invalid
    message.setSubject(null);
    final ProtonDelivery delivery = mock(ProtonDelivery.class);
    mappingAndDelegatingCommandHandler.mapAndDelegateIncomingCommandMessage(tenantId, delivery, message);
    // THEN the disposition is REJECTED
    verify(delivery).disposition(any(Rejected.class), eq(true));
}
Also used : Message(org.apache.qpid.proton.message.Message) ProtonDelivery(io.vertx.proton.ProtonDelivery) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Rejected(org.apache.qpid.proton.amqp.messaging.Rejected) Test(org.junit.jupiter.api.Test)

Aggregations

Rejected (org.apache.qpid.proton.amqp.messaging.Rejected)59 Message (org.apache.qpid.proton.message.Message)32 ProtonDelivery (io.vertx.proton.ProtonDelivery)28 Handler (io.vertx.core.Handler)27 DeliveryState (org.apache.qpid.proton.amqp.transport.DeliveryState)23 ErrorCondition (org.apache.qpid.proton.amqp.transport.ErrorCondition)23 Accepted (org.apache.qpid.proton.amqp.messaging.Accepted)21 Span (io.opentracing.Span)19 Test (org.junit.jupiter.api.Test)19 ProtonHelper (io.vertx.proton.ProtonHelper)18 ProtonSender (io.vertx.proton.ProtonSender)18 Released (org.apache.qpid.proton.amqp.messaging.Released)18 Future (io.vertx.core.Future)17 HttpURLConnection (java.net.HttpURLConnection)17 MessageHelper (org.eclipse.hono.util.MessageHelper)17 ProtonQoS (io.vertx.proton.ProtonQoS)16 ClientErrorException (org.eclipse.hono.client.ClientErrorException)16 ProtonReceiver (io.vertx.proton.ProtonReceiver)15 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)15 Truth.assertThat (com.google.common.truth.Truth.assertThat)14