|
20 | 20 |
|
21 | 21 | package com.arangodb.async;
|
22 | 22 |
|
23 |
| -import com.arangodb.ArangoDBException; |
24 |
| -import com.arangodb.DbName; |
| 23 | +import com.arangodb.*; |
25 | 24 | import com.arangodb.entity.AqlExecutionExplainEntity.ExecutionPlan;
|
26 | 25 | import com.arangodb.entity.*;
|
27 | 26 | import com.arangodb.entity.AqlParseEntity.AstNode;
|
@@ -627,28 +626,32 @@ void queryWithCache() throws InterruptedException, ExecutionException {
|
627 | 626 |
|
628 | 627 | @Test
|
629 | 628 | void queryCursor() throws InterruptedException, ExecutionException {
|
630 |
| - try { |
631 |
| - db.createCollection(COLLECTION_NAME, null).get(); |
632 |
| - final int numbDocs = 10; |
633 |
| - for (int i = 0; i < numbDocs; i++) { |
634 |
| - db.collection(COLLECTION_NAME).insertDocument(new BaseDocument(), null).get(); |
635 |
| - } |
636 |
| - |
637 |
| - final int batchSize = 5; |
638 |
| - final ArangoCursorAsync<String> cursor = db.query("for i in db_test return i._id", null, |
639 |
| - new AqlQueryOptions().batchSize(batchSize).count(true), String.class).get(); |
640 |
| - assertThat(cursor.getCount()).isEqualTo(numbDocs); |
641 |
| - |
642 |
| - final ArangoCursorAsync<String> cursor2 = db.cursor(cursor.getId(), String.class).get(); |
643 |
| - assertThat(cursor2.getCount()).isEqualTo(numbDocs); |
644 |
| - assertThat(cursor2.hasNext()).isTrue(); |
645 |
| - |
646 |
| - for (int i = 0; i < batchSize; i++, cursor.next()) { |
647 |
| - assertThat(cursor.hasNext()).isTrue(); |
648 |
| - } |
649 |
| - } finally { |
650 |
| - db.collection(COLLECTION_NAME).drop().get(); |
651 |
| - } |
| 629 | + ArangoCursor<Integer> cursor = db.query("for i in 1..4 return i", new AqlQueryOptions().batchSize(1), |
| 630 | + Integer.class).get(); |
| 631 | + List<Integer> result = new ArrayList<>(); |
| 632 | + result.add(cursor.next()); |
| 633 | + result.add(cursor.next()); |
| 634 | + ArangoCursor<Integer> cursor2 = db.cursor(cursor.getId(), Integer.class).get(); |
| 635 | + result.add(cursor2.next()); |
| 636 | + result.add(cursor2.next()); |
| 637 | + assertThat(cursor2.hasNext()).isFalse(); |
| 638 | + assertThat(result).containsExactly(1, 2, 3, 4); |
| 639 | + } |
| 640 | + |
| 641 | + @Test |
| 642 | + void queryCursorRetry() throws IOException, ExecutionException, InterruptedException { |
| 643 | + assumeTrue(isAtLeastVersion(3, 11)); |
| 644 | + ArangoCursor<Integer> cursor = db.query("for i in 1..4 return i", |
| 645 | + new AqlQueryOptions().batchSize(1).allowRetry(true), Integer.class).get(); |
| 646 | + List<Integer> result = new ArrayList<>(); |
| 647 | + result.add(cursor.next()); |
| 648 | + result.add(cursor.next()); |
| 649 | + ArangoCursor<Integer> cursor2 = db.cursor(cursor.getId(), Integer.class, cursor.getNextBatchId()).get(); |
| 650 | + result.add(cursor2.next()); |
| 651 | + result.add(cursor2.next()); |
| 652 | + cursor2.close(); |
| 653 | + assertThat(cursor2.hasNext()).isFalse(); |
| 654 | + assertThat(result).containsExactly(1, 2, 3, 4); |
652 | 655 | }
|
653 | 656 |
|
654 | 657 | @Test
|
@@ -724,6 +727,51 @@ void queryClose() throws IOException, InterruptedException, ExecutionException {
|
724 | 727 |
|
725 | 728 | }
|
726 | 729 |
|
| 730 | + @Test |
| 731 | + void queryAllowRetry() throws IOException, ExecutionException, InterruptedException { |
| 732 | + assumeTrue(isAtLeastVersion(3, 11)); |
| 733 | + final ArangoCursor<String> cursor = arangoDB.db() |
| 734 | + .query("for i in 1..2 return i", new AqlQueryOptions().allowRetry(true).batchSize(1), String.class).get(); |
| 735 | + assertThat(cursor.asListRemaining()).containsExactly("1", "2"); |
| 736 | + } |
| 737 | + |
| 738 | + @Test |
| 739 | + void queryAllowRetryClose() throws IOException, ExecutionException, InterruptedException { |
| 740 | + assumeTrue(isAtLeastVersion(3, 11)); |
| 741 | + final ArangoCursor<String> cursor = arangoDB.db() |
| 742 | + .query("for i in 1..2 return i", new AqlQueryOptions().allowRetry(true).batchSize(1), String.class).get(); |
| 743 | + assertThat(cursor.hasNext()).isTrue(); |
| 744 | + assertThat(cursor.next()).isEqualTo("1"); |
| 745 | + assertThat(cursor.hasNext()).isTrue(); |
| 746 | + assertThat(cursor.next()).isEqualTo("2"); |
| 747 | + assertThat(cursor.hasNext()).isFalse(); |
| 748 | + cursor.close(); |
| 749 | + } |
| 750 | + |
| 751 | + @Test |
| 752 | + void queryAllowRetryCloseBeforeLatestBatch() throws IOException, ExecutionException, InterruptedException { |
| 753 | + assumeTrue(isAtLeastVersion(3, 11)); |
| 754 | + final ArangoCursor<String> cursor = arangoDB.db() |
| 755 | + .query("for i in 1..2 return i", new AqlQueryOptions().allowRetry(true).batchSize(1), String.class).get(); |
| 756 | + assertThat(cursor.hasNext()).isTrue(); |
| 757 | + assertThat(cursor.next()).isEqualTo("1"); |
| 758 | + assertThat(cursor.hasNext()).isTrue(); |
| 759 | + cursor.close(); |
| 760 | + } |
| 761 | + |
| 762 | + @Test |
| 763 | + void queryAllowRetryCloseSingleBatch() throws IOException, ExecutionException, InterruptedException { |
| 764 | + assumeTrue(isAtLeastVersion(3, 11)); |
| 765 | + final ArangoCursor<String> cursor = arangoDB.db() |
| 766 | + .query("for i in 1..2 return i", new AqlQueryOptions().allowRetry(true), String.class).get(); |
| 767 | + assertThat(cursor.hasNext()).isTrue(); |
| 768 | + assertThat(cursor.next()).isEqualTo("1"); |
| 769 | + assertThat(cursor.hasNext()).isTrue(); |
| 770 | + assertThat(cursor.next()).isEqualTo("2"); |
| 771 | + assertThat(cursor.hasNext()).isFalse(); |
| 772 | + cursor.close(); |
| 773 | + } |
| 774 | + |
727 | 775 | @Test
|
728 | 776 | void explainQuery() throws InterruptedException, ExecutionException {
|
729 | 777 | arangoDB.db().explainQuery("for i in 1..1 return i", null, null)
|
|
0 commit comments