|
15 | 15 | import static org.assertj.core.api.Assertions.assertThat;
|
16 | 16 |
|
17 | 17 | import java.time.Duration;
|
| 18 | +import java.util.concurrent.TimeUnit; |
18 | 19 | import java.util.function.Consumer;
|
19 | 20 |
|
20 | 21 | import org.eclipse.ditto.base.model.acks.AcknowledgementLabel;
|
|
23 | 24 | import org.eclipse.ditto.base.model.common.ResponseType;
|
24 | 25 | import org.eclipse.ditto.base.model.headers.DittoHeaderDefinition;
|
25 | 26 | import org.eclipse.ditto.base.model.headers.DittoHeaders;
|
26 |
| -import org.eclipse.ditto.internal.models.acks.config.DefaultAcknowledgementConfig; |
27 |
| -import org.eclipse.ditto.things.model.ThingId; |
28 |
| -import org.eclipse.ditto.protocol.HeaderTranslator; |
29 | 27 | import org.eclipse.ditto.base.model.signals.acks.Acknowledgement;
|
30 | 28 | import org.eclipse.ditto.base.model.signals.acks.Acknowledgements;
|
31 | 29 | import org.eclipse.ditto.base.model.signals.commands.exceptions.GatewayCommandTimeoutException;
|
| 30 | +import org.eclipse.ditto.internal.models.acks.config.DefaultAcknowledgementConfig; |
| 31 | +import org.eclipse.ditto.protocol.HeaderTranslator; |
| 32 | +import org.eclipse.ditto.things.model.ThingId; |
32 | 33 | import org.eclipse.ditto.things.model.signals.commands.ThingErrorResponse;
|
33 | 34 | import org.eclipse.ditto.things.model.signals.commands.modify.DeleteThing;
|
34 | 35 | import org.eclipse.ditto.things.model.signals.commands.modify.DeleteThingResponse;
|
@@ -188,6 +189,49 @@ public void keepCommandHeaders() {
|
188 | 189 | .build()
|
189 | 190 | );
|
190 | 191 | assertThat(acks.getSize()).isEqualTo(2);
|
| 192 | + assertThat(acks.getAcknowledgement(label1).map(Acknowledgement::getHttpStatus)).contains( |
| 193 | + HttpStatus.UNAUTHORIZED); |
| 194 | + assertThat(acks.getAcknowledgement(label2).map(Acknowledgement::getHttpStatus)).contains( |
| 195 | + HttpStatus.PAYMENT_REQUIRED); |
| 196 | + }}; |
| 197 | + } |
| 198 | + |
| 199 | + @Test |
| 200 | + public void awaitsOnlyUntilTimeout() throws InterruptedException { |
| 201 | + new TestKit(actorSystem) {{ |
| 202 | + // GIVEN |
| 203 | + final Duration timeout = Duration.ofSeconds(5); |
| 204 | + final String tag = "tag"; |
| 205 | + final String correlationId = "awaitsOnlyUntilTimeout"; |
| 206 | + final ThingId thingId = ThingId.of("thing:id"); |
| 207 | + final AcknowledgementLabel label1 = AcknowledgementLabel.of("ack1"); |
| 208 | + final AcknowledgementLabel label2 = AcknowledgementLabel.of("ack2"); |
| 209 | + final ThingModifyCommand<?> command = DeleteThing.of(thingId, DittoHeaders.newBuilder() |
| 210 | + .correlationId(correlationId) |
| 211 | + .timeout(timeout) |
| 212 | + .acknowledgementRequest(AcknowledgementRequest.of(label1), AcknowledgementRequest.of(label2)) |
| 213 | + .build()); |
| 214 | + final ActorRef underTest = childActorOf(getAcknowledgementAggregatorProps(command, this)); |
| 215 | + |
| 216 | + // WHEN |
| 217 | + final Acknowledgement ack1 = Acknowledgement.of(label1, thingId, HttpStatus.UNAUTHORIZED, |
| 218 | + DittoHeaders.newBuilder().correlationId(correlationId).putHeader(tag, label1.toString()).build()); |
| 219 | + final Acknowledgement ack2 = Acknowledgement.of(label2, thingId, HttpStatus.PAYMENT_REQUIRED, |
| 220 | + DittoHeaders.newBuilder().correlationId(correlationId).putHeader(tag, label2.toString()).build()); |
| 221 | + TimeUnit.SECONDS.sleep( |
| 222 | + timeout.toSeconds() / 2 + 1); // Wait more than half the time before sending first ack |
| 223 | + underTest.tell(ack1, ActorRef.noSender()); |
| 224 | + TimeUnit.SECONDS.sleep(timeout.toSeconds() / 2 + |
| 225 | + 1); // Wait more than half the time before sending second ack. This should not be taken into account. |
| 226 | + underTest.tell(ack2, ActorRef.noSender()); |
| 227 | + |
| 228 | + // THEN |
| 229 | + final Acknowledgements acks = expectMsgClass(Acknowledgements.class); |
| 230 | + assertThat(acks.getSize()).isEqualTo(2); |
| 231 | + assertThat(acks.getAcknowledgement(label1).map(Acknowledgement::getHttpStatus)).contains( |
| 232 | + HttpStatus.UNAUTHORIZED); |
| 233 | + assertThat(acks.getAcknowledgement(label2).map(Acknowledgement::getHttpStatus)).contains( |
| 234 | + HttpStatus.REQUEST_TIMEOUT); |
191 | 235 | }};
|
192 | 236 | }
|
193 | 237 |
|
|
0 commit comments