Skip to content

Commit 5c17634

Browse files
committed
sync tests
1 parent f0c7769 commit 5c17634

File tree

1 file changed

+74
-18
lines changed

1 file changed

+74
-18
lines changed

src/test/java/com/arangodb/ArangoDatabaseTest.java

+74-18
Original file line numberDiff line numberDiff line change
@@ -832,25 +832,32 @@ void queryWithMaxWarningCount(ArangoDatabase db) {
832832
@ParameterizedTest(name = "{index}")
833833
@MethodSource("dbs")
834834
void queryCursor(ArangoDatabase db) {
835-
final int numbDocs = 10;
836-
for (int i = 0; i < numbDocs; i++) {
837-
db.collection(CNAME1).insertDocument(new BaseDocument(), null);
838-
}
839-
840-
final int batchSize = 5;
841-
final ArangoCursor<String> cursor = db.query("for i in " + CNAME1 + " return i._id", null,
842-
new AqlQueryOptions().batchSize(batchSize).count(true), String.class);
843-
assertThat((Object) cursor).isNotNull();
844-
assertThat(cursor.getCount()).isGreaterThanOrEqualTo(numbDocs);
845-
846-
final ArangoCursor<String> cursor2 = db.cursor(cursor.getId(), String.class);
847-
assertThat((Object) cursor2).isNotNull();
848-
assertThat(cursor2.getCount()).isGreaterThanOrEqualTo(numbDocs);
849-
assertThat((Iterator<?>) cursor2).hasNext();
835+
ArangoCursor<Integer> cursor = db.query("for i in 1..4 return i", new AqlQueryOptions().batchSize(1), Integer.class);
836+
List<Integer> result = new ArrayList<>();
837+
result.add(cursor.next());
838+
result.add(cursor.next());
839+
ArangoCursor<Integer> cursor2 = db.cursor(cursor.getId(), Integer.class);
840+
result.add(cursor2.next());
841+
result.add(cursor2.next());
842+
assertThat(cursor2.hasNext()).isFalse();
843+
assertThat(result).containsExactly(1, 2, 3, 4);
844+
}
850845

851-
for (int i = 0; i < batchSize; i++, cursor.next()) {
852-
assertThat((Iterator<?>) cursor).hasNext();
853-
}
846+
@ParameterizedTest(name = "{index}")
847+
@MethodSource("dbs")
848+
void queryCursorRetry(ArangoDatabase db) throws IOException {
849+
assumeTrue(isAtLeastVersion(3, 11));
850+
ArangoCursor<Integer> cursor = db.query("for i in 1..4 return i",
851+
new AqlQueryOptions().batchSize(1).allowRetry(true), Integer.class);
852+
List<Integer> result = new ArrayList<>();
853+
result.add(cursor.next());
854+
result.add(cursor.next());
855+
ArangoCursor<Integer> cursor2 = db.cursor(cursor.getId(), Integer.class, cursor.getNextBatchId());
856+
result.add(cursor2.next());
857+
result.add(cursor2.next());
858+
cursor2.close();
859+
assertThat(cursor2.hasNext()).isFalse();
860+
assertThat(result).containsExactly(1, 2, 3, 4);
854861
}
855862

856863
@ParameterizedTest(name = "{index}")
@@ -996,6 +1003,55 @@ void queryAllowDirtyRead(ArangoDatabase db) throws IOException {
9961003
cursor.close();
9971004
}
9981005

1006+
@ParameterizedTest(name = "{index}")
1007+
@MethodSource("arangos")
1008+
void queryAllowRetry(ArangoDB arangoDB) throws IOException {
1009+
assumeTrue(isAtLeastVersion(3, 11));
1010+
final ArangoCursor<String> cursor = arangoDB.db()
1011+
.query("for i in 1..2 return i", new AqlQueryOptions().allowRetry(true).batchSize(1), String.class);
1012+
assertThat(cursor.asListRemaining()).containsExactly("1", "2");
1013+
}
1014+
1015+
@ParameterizedTest(name = "{index}")
1016+
@MethodSource("arangos")
1017+
void queryAllowRetryClose(ArangoDB arangoDB) throws IOException {
1018+
assumeTrue(isAtLeastVersion(3, 11));
1019+
final ArangoCursor<String> cursor = arangoDB.db()
1020+
.query("for i in 1..2 return i", new AqlQueryOptions().allowRetry(true).batchSize(1), String.class);
1021+
assertThat(cursor.hasNext()).isTrue();
1022+
assertThat(cursor.next()).isEqualTo("1");
1023+
assertThat(cursor.hasNext()).isTrue();
1024+
assertThat(cursor.next()).isEqualTo("2");
1025+
assertThat(cursor.hasNext()).isFalse();
1026+
cursor.close();
1027+
}
1028+
1029+
@ParameterizedTest(name = "{index}")
1030+
@MethodSource("arangos")
1031+
void queryAllowRetryCloseBeforeLatestBatch(ArangoDB arangoDB) throws IOException {
1032+
assumeTrue(isAtLeastVersion(3, 11));
1033+
final ArangoCursor<String> cursor = arangoDB.db()
1034+
.query("for i in 1..2 return i", new AqlQueryOptions().allowRetry(true).batchSize(1), String.class);
1035+
assertThat(cursor.hasNext()).isTrue();
1036+
assertThat(cursor.next()).isEqualTo("1");
1037+
assertThat(cursor.hasNext()).isTrue();
1038+
cursor.close();
1039+
}
1040+
1041+
@ParameterizedTest(name = "{index}")
1042+
@MethodSource("arangos")
1043+
void queryAllowRetryCloseSingleBatch(ArangoDB arangoDB) throws IOException {
1044+
assumeTrue(isAtLeastVersion(3, 11));
1045+
final ArangoCursor<String> cursor = arangoDB.db()
1046+
.query("for i in 1..2 return i", new AqlQueryOptions().allowRetry(true), String.class);
1047+
assertThat(cursor.hasNext()).isTrue();
1048+
assertThat(cursor.next()).isEqualTo("1");
1049+
assertThat(cursor.hasNext()).isTrue();
1050+
assertThat(cursor.next()).isEqualTo("2");
1051+
assertThat(cursor.hasNext()).isFalse();
1052+
cursor.close();
1053+
}
1054+
9991055
@ParameterizedTest(name = "{index}")
10001056
@MethodSource("dbs")
10011057
void explainQuery(ArangoDatabase db) {

0 commit comments

Comments
 (0)