|
45 | 45 | import java.util.ArrayList;
|
46 | 46 | import java.util.List;
|
47 | 47 | import java.util.concurrent.CountDownLatch;
|
| 48 | +import java.util.concurrent.ForkJoinPool; |
48 | 49 | import java.util.concurrent.TimeUnit;
|
49 | 50 | import java.util.concurrent.atomic.AtomicInteger;
|
50 | 51 | import java.util.stream.Collectors;
|
@@ -299,6 +300,24 @@ void testLimitWithGetMore() {
|
299 | 300 | assertTrue(cursor.isClosed());
|
300 | 301 | }
|
301 | 302 |
|
| 303 | + @Test |
| 304 | + void attemptJava5516() { |
| 305 | + BsonDocument commandResult = executeFindCommand(5, 2); |
| 306 | + cursor = new AsyncCommandBatchCursor<>(commandResult, 2, 0, DOCUMENT_DECODER, |
| 307 | + null, connectionSource, connection); |
| 308 | + assertNotNull(cursorNext()); |
| 309 | + // Calling `close` twice is the key to reproducing. |
| 310 | + // It does not matter whether we call `close` twice from the same thread or not. |
| 311 | + ForkJoinPool.commonPool().execute(() -> cursor.close()); |
| 312 | + ForkJoinPool.commonPool().execute(() -> cursor.close()); |
| 313 | + try { |
| 314 | + assertNotNull(cursorNext()); |
| 315 | + assertNotNull(cursorNext()); |
| 316 | + } catch (IllegalStateException e) { |
| 317 | + // one of the expected outcomes, because we call `cursorNext` concurrently with `close` |
| 318 | + } |
| 319 | + } |
| 320 | + |
302 | 321 | @Test
|
303 | 322 | @DisplayName("test limit with large documents")
|
304 | 323 | void testLimitWithLargeDocuments() {
|
|
0 commit comments