Skip to content

Commit 4d3c13d

Browse files
committed
Add tests for FullBatchBackPressureHandler (#1251)
1 parent 0da12ab commit 4d3c13d

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package io.awspring.cloud.sqs.listener;
2+
3+
import org.junit.jupiter.api.BeforeEach;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static org.assertj.core.api.Assertions.assertThat;
7+
8+
class FullBatchBackPressureHandlerTest {
9+
10+
private FullBatchBackPressureHandler handler;
11+
12+
private final int batchSize = 10;
13+
14+
@BeforeEach
15+
void setUp() {
16+
handler = FullBatchBackPressureHandler.builder()
17+
.batchSize(batchSize)
18+
.build();
19+
}
20+
21+
@Test
22+
void request_withExactBatchSize_shouldReturnBatchSize() throws InterruptedException {
23+
assertThat(handler.request(batchSize)).isEqualTo(batchSize);
24+
}
25+
26+
@Test
27+
void request_withNonBatchSize_shouldReturnZero() throws InterruptedException {
28+
int permits = handler.request(batchSize - 1);
29+
assertThat(permits).isZero();
30+
permits = handler.request(batchSize + 1);
31+
assertThat(permits).isZero();
32+
}
33+
34+
@Test
35+
void requestBatch_shouldReturnBatchSize() throws InterruptedException {
36+
assertThat(handler.requestBatch()).isEqualTo(batchSize);
37+
}
38+
}
39+

0 commit comments

Comments
 (0)