Skip to content

Commit 2288a2c

Browse files
committed
async tests
1 parent 5c17634 commit 2288a2c

File tree

1 file changed

+72
-24
lines changed

1 file changed

+72
-24
lines changed

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

+72-24
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020

2121
package com.arangodb.async;
2222

23-
import com.arangodb.ArangoDBException;
24-
import com.arangodb.DbName;
23+
import com.arangodb.*;
2524
import com.arangodb.entity.AqlExecutionExplainEntity.ExecutionPlan;
2625
import com.arangodb.entity.*;
2726
import com.arangodb.entity.AqlParseEntity.AstNode;
@@ -627,28 +626,32 @@ void queryWithCache() throws InterruptedException, ExecutionException {
627626

628627
@Test
629628
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);
652655
}
653656

654657
@Test
@@ -724,6 +727,51 @@ void queryClose() throws IOException, InterruptedException, ExecutionException {
724727

725728
}
726729

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+
727775
@Test
728776
void explainQuery() throws InterruptedException, ExecutionException {
729777
arangoDB.db().explainQuery("for i in 1..1 return i", null, null)

0 commit comments

Comments
 (0)