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