|
6 | 6 | import org.mockito.ArgumentCaptor; |
7 | 7 |
|
8 | 8 | import java.util.ArrayList; |
9 | | -import java.util.Collections; |
10 | 9 | import java.util.List; |
11 | 10 | import java.util.concurrent.CompletableFuture; |
12 | | -import java.util.concurrent.CountDownLatch; |
13 | 11 | import java.util.concurrent.ExecutionException; |
14 | | -import java.util.concurrent.TimeUnit; |
15 | 12 | import java.util.concurrent.atomic.AtomicInteger; |
16 | 13 | import java.util.concurrent.atomic.AtomicReference; |
17 | 14 | import java.util.function.Function; |
18 | 15 | import java.util.stream.Collectors; |
19 | 16 |
|
20 | 17 | import com.salesforce.multicloudj.common.exceptions.FailedPreconditionException; |
21 | 18 | import com.salesforce.multicloudj.common.exceptions.InvalidArgumentException; |
22 | | -import com.salesforce.multicloudj.common.exceptions.SubstrateSdkException; |
23 | 19 |
|
24 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; |
25 | 21 | import static org.junit.jupiter.api.Assertions.assertFalse; |
@@ -124,54 +120,20 @@ void testMaxBatchSize() throws Exception { |
124 | 120 | // Assert |
125 | 121 | ArgumentCaptor<List<SizableString>> captor = ArgumentCaptor.forClass(List.class); |
126 | 122 | verify(mockHandler, atLeastOnce()).apply(captor.capture()); |
127 | | - |
| 123 | + |
128 | 124 | List<List<SizableString>> allBatches = captor.getAllValues(); |
129 | | - |
| 125 | + |
130 | 126 | // Verify all items were processed |
131 | 127 | int totalItems = allBatches.stream().mapToInt(List::size).sum(); |
132 | 128 | assertEquals(3, totalItems); |
133 | | - |
| 129 | + |
134 | 130 | // Verify no batch exceeds maxBatchSize |
135 | 131 | for (List<SizableString> batch : allBatches) { |
136 | 132 | assertTrue(batch.size() <= 2, "Batch size should not exceed maxBatchSize of 2"); |
137 | 133 | } |
138 | 134 | batcher.shutdownAndDrain(); |
139 | 135 | } |
140 | 136 |
|
141 | | - @Test |
142 | | - @Timeout(10) // Waits for batch completion with .get() |
143 | | - void testMaxBatchSizeWithMinBatchSize() throws Exception { |
144 | | - // Arrange - This test demonstrates actual batching behavior |
145 | | - Batcher.Options options = new Batcher.Options().setMinBatchSize(2).setMaxBatchSize(3); |
146 | | - Batcher<SizableString> batcher = new Batcher<>(options, mockHandler); |
147 | | - |
148 | | - // Act - Add 5 items |
149 | | - CompletableFuture<Void> future1 = batcher.addNoWait(new SizableString("item1")); |
150 | | - CompletableFuture<Void> future2 = batcher.addNoWait(new SizableString("item2")); |
151 | | - CompletableFuture<Void> future3 = batcher.addNoWait(new SizableString("item3")); |
152 | | - CompletableFuture<Void> future4 = batcher.addNoWait(new SizableString("item4")); |
153 | | - CompletableFuture<Void> future5 = batcher.addNoWait(new SizableString("item5")); |
154 | | - |
155 | | - CompletableFuture.allOf(future1, future2, future3, future4, future5).get(); |
156 | | - |
157 | | - // Assert |
158 | | - ArgumentCaptor<List<SizableString>> captor = ArgumentCaptor.forClass(List.class); |
159 | | - verify(mockHandler, atLeastOnce()).apply(captor.capture()); |
160 | | - |
161 | | - List<List<SizableString>> allBatches = captor.getAllValues(); |
162 | | - |
163 | | - // Verify all items were processed |
164 | | - int totalItems = allBatches.stream().mapToInt(List::size).sum(); |
165 | | - assertEquals(5, totalItems); |
166 | | - |
167 | | - // Verify each batch meets minBatchSize requirement and doesn't exceed maxBatchSize |
168 | | - for (List<SizableString> batch : allBatches) { |
169 | | - assertTrue(batch.size() >= 2, "Batch size should meet minBatchSize of 2"); |
170 | | - assertTrue(batch.size() <= 3, "Batch size should not exceed maxBatchSize of 3"); |
171 | | - } |
172 | | - batcher.shutdownAndDrain(); |
173 | | - } |
174 | | - |
175 | 137 | @Test |
176 | 138 | @Timeout(10) // Waits for batch completion with .get() |
177 | 139 | void testSizableItemBatching() throws Exception { |
|
0 commit comments