use of org.eclipse.ditto.base.model.signals.acks.Acknowledgement in project ditto by eclipse.
the class DittoProtocolAdapterTest method acknowledgementToAdaptable.
@Test
public void acknowledgementToAdaptable() {
final Acknowledgement acknowledgement = Acknowledgement.of(AcknowledgementLabel.of("my-twin-persisted"), ThingId.of("thing:id"), HttpStatus.CONTINUE, DittoHeaders.empty());
final Adaptable adaptable = underTest.toAdaptable((Signal<?>) acknowledgement);
assertThat(adaptable.getTopicPath()).isEqualTo(ProtocolFactory.newTopicPath("thing/id/things/twin/acks/my-twin-persisted"));
assertThat((Iterable<?>) adaptable.getPayload().getPath()).isEmpty();
assertThat(adaptable.getPayload().getHttpStatus()).contains(HttpStatus.CONTINUE);
}
use of org.eclipse.ditto.base.model.signals.acks.Acknowledgement in project ditto by eclipse.
the class DittoProtocolAdapterTest method acknowledgementsToAdaptable.
@Test
public void acknowledgementsToAdaptable() {
final Acknowledgement ack1 = Acknowledgement.of(TWIN_PERSISTED, ThingId.of("thing:id"), HttpStatus.CONTINUE, DittoHeaders.empty());
final Acknowledgement ack2 = Acknowledgement.of(AcknowledgementLabel.of("the-ack-label"), ThingId.of("thing:id"), HttpStatus.LOOP_DETECTED, DittoHeaders.empty());
final Acknowledgements acks = Acknowledgements.of(Arrays.asList(ack1, ack2), DittoHeaders.empty());
final Adaptable adaptable = underTest.toAdaptable((Signal<?>) acks);
final JsonObject expectedPayloadJson = JsonObject.of("{\n" + " \"twin-persisted\":{\"status\":100,\"headers\":{\"response-required\":false}},\n" + " \"the-ack-label\":{\"status\":508,\"headers\":{\"response-required\":false}}\n" + "}");
assertThat(adaptable.getTopicPath()).isEqualTo(ProtocolFactory.newTopicPath("thing/id/things/twin/acks"));
assertThat((Iterable<?>) adaptable.getPayload().getPath()).isEmpty();
assertThat(adaptable.getPayload().getHttpStatus()).contains(HttpStatus.FAILED_DEPENDENCY);
assertThat(adaptable.getPayload().getValue()).contains(expectedPayloadJson);
}
use of org.eclipse.ditto.base.model.signals.acks.Acknowledgement in project ditto by eclipse.
the class AcknowledgementAdapterTest method acknowledgementFromAdaptable.
@Test
public void acknowledgementFromAdaptable() {
final DittoHeaders dittoHeaders = DittoHeaders.newBuilder().randomCorrelationId().build();
final JsonValue customAckPayload = JsonValue.of("Custom Ack payload");
final HttpStatus status = HttpStatus.CREATED;
final Adaptable adaptable = Adaptable.newBuilder(topicPathMyCustomAck).withHeaders(dittoHeaders).withPayload(Payload.newBuilder(JsonPointer.empty()).withValue(customAckPayload).withStatus(status).build()).build();
final Acknowledgement expected = ThingAcknowledgementFactory.newAcknowledgement(KNOWN_CUSTOM_LABEL, TestConstants.THING_ID, status, dittoHeaders, customAckPayload);
final Acknowledgement actual = underTest.fromAdaptable(adaptable);
assertWithExternalHeadersThat(actual).isEqualTo(expected);
}
use of org.eclipse.ditto.base.model.signals.acks.Acknowledgement in project ditto by eclipse.
the class RabbitMQPublisherActor method buildResponse.
private static SendResult buildResponse(final Signal<?> signal, @Nullable final Target autoAckTarget, final HttpStatus httpStatus, @Nullable final String message, final ExpressionResolver connectionIdResolver) {
final var autoAckLabel = Optional.ofNullable(autoAckTarget).flatMap(Target::getIssuedAcknowledgementLabel).flatMap(ackLabel -> resolveConnectionIdPlaceholder(connectionIdResolver, ackLabel));
final Optional<EntityId> entityIdOptional = WithEntityId.getEntityIdOfType(EntityId.class, signal);
final Acknowledgement issuedAck;
if (autoAckLabel.isPresent() && entityIdOptional.isPresent()) {
issuedAck = Acknowledgement.of(autoAckLabel.get(), entityIdOptional.get(), httpStatus, signal.getDittoHeaders(), message == null ? null : JsonValue.of(message));
} else {
issuedAck = null;
}
return new SendResult(issuedAck, signal.getDittoHeaders());
}
use of org.eclipse.ditto.base.model.signals.acks.Acknowledgement in project ditto by eclipse.
the class StreamingSessionActor method declareAcknowledgementLabels.
/**
* Attempt to declare the acknowledgement labels (they must be unique cluster wide).
* Only need to be done once per actor.
*
* @param acknowledgementLabels the acknowledgement labels to declare.
*/
private void declareAcknowledgementLabels(final Collection<AcknowledgementLabel> acknowledgementLabels) {
final ActorRef self = getSelf();
logger.info("Declaring acknowledgement labels <{}>", acknowledgementLabels);
dittoProtocolSub.declareAcknowledgementLabels(acknowledgementLabels, self, null).thenAccept(unused -> logger.info("Acknowledgement label declaration successful for labels: <{}>", acknowledgementLabels)).exceptionally(error -> {
final var dittoRuntimeException = DittoRuntimeException.asDittoRuntimeException(error, cause -> AcknowledgementLabelNotUniqueException.newBuilder().cause(cause).build());
logger.info("Acknowledgement label declaration failed for labels: <{}> - cause: {} {}", acknowledgementLabels, error.getClass().getSimpleName(), error.getMessage());
self.tell(dittoRuntimeException, ActorRef.noSender());
return null;
});
}
Aggregations