|
15 | 15 | package com.rabbitmq.stream.impl;
|
16 | 16 |
|
17 | 17 | import static com.rabbitmq.stream.impl.TestUtils.waitAtMost;
|
| 18 | +import static java.util.stream.IntStream.range; |
18 | 19 | import static org.assertj.core.api.Assertions.assertThat;
|
19 | 20 | import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
20 | 21 | import static org.mockito.ArgumentMatchers.*;
|
|
43 | 44 | import java.util.concurrent.atomic.AtomicBoolean;
|
44 | 45 | import java.util.concurrent.atomic.AtomicInteger;
|
45 | 46 | import java.util.function.ToLongFunction;
|
46 |
| -import java.util.stream.IntStream; |
47 | 47 | import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
|
| 48 | +import org.assertj.core.data.Offset; |
48 | 49 | import org.junit.jupiter.api.AfterEach;
|
49 | 50 | import org.junit.jupiter.api.BeforeEach;
|
50 | 51 | import org.junit.jupiter.params.ParameterizedTest;
|
@@ -184,26 +185,33 @@ void confirmTimeoutTaskShouldFailMessagesAfterTimeout(
|
184 | 185 | null,
|
185 | 186 | env);
|
186 | 187 |
|
187 |
| - IntStream.range(0, messageCount) |
| 188 | + range(0, messageCount) |
188 | 189 | .forEach(
|
189 | 190 | i ->
|
190 | 191 | producer.send(
|
191 | 192 | producer.messageBuilder().addData("".getBytes()).build(), confirmationHandler));
|
192 | 193 |
|
193 |
| - IntStream.range(0, confirmedPart).forEach(publishingId -> producer.confirm(publishingId)); |
194 |
| - assertThat(confirmedCount.get()).isEqualTo(expectedConfirmed); |
| 194 | + waitAtMost(() -> producer.unconfirmedCount() >= messageCount / subEntrySize); |
| 195 | + range(0, confirmedPart).forEach(producer::confirm); |
| 196 | + if (subEntrySize == 1) { |
| 197 | + assertThat(confirmedCount.get()).isEqualTo(expectedConfirmed); |
| 198 | + } else { |
| 199 | + assertThat(confirmedCount.get()).isCloseTo(confirmedCount.get(), Offset.offset(subEntrySize)); |
| 200 | + } |
195 | 201 | assertThat(erroredCount.get()).isZero();
|
| 202 | + int confirmedPreviously = confirmedCount.get(); |
196 | 203 |
|
197 | 204 | executorService.scheduleAtFixedRate(() -> clock.refresh(), 100, 100, TimeUnit.MILLISECONDS);
|
198 | 205 |
|
199 | 206 | Thread.sleep(waitTime.toMillis());
|
200 |
| - assertThat(confirmedCount.get()).isEqualTo(expectedConfirmed); |
| 207 | + assertThat(confirmedCount.get()).isEqualTo(confirmedPreviously); |
201 | 208 | if (confirmTimeout.isZero()) {
|
202 | 209 | assertThat(erroredCount.get()).isZero();
|
203 | 210 | assertThat(responseCodes).isEmpty();
|
204 | 211 | } else {
|
205 | 212 | waitAtMost(
|
206 |
| - waitTime.multipliedBy(2), () -> erroredCount.get() == (messageCount - expectedConfirmed)); |
| 213 | + waitTime.multipliedBy(2), |
| 214 | + () -> erroredCount.get() == (messageCount - confirmedPreviously)); |
207 | 215 | assertThat(responseCodes).hasSize(1).contains(Constants.CODE_PUBLISH_CONFIRM_TIMEOUT);
|
208 | 216 | }
|
209 | 217 | }
|
|
0 commit comments