|
26 | 26 | import org.junit.jupiter.params.ParameterizedTest;
|
27 | 27 | import org.junit.jupiter.params.provider.MethodSource;
|
28 | 28 |
|
| 29 | +import java.io.IOException; |
29 | 30 | import java.util.*;
|
30 | 31 | import java.util.stream.Collectors;
|
31 | 32 | import java.util.stream.IntStream;
|
@@ -785,4 +786,35 @@ void transactionAllowImplicitFalse(ArangoDatabase db) {
|
785 | 786 |
|
786 | 787 | db.abortStreamTransaction(tx.getId());
|
787 | 788 | }
|
| 789 | + |
| 790 | + @ParameterizedTest(name = "{index}") |
| 791 | + @MethodSource("dbs") |
| 792 | + void transactionDirtyRead(ArangoDatabase db) throws IOException { |
| 793 | + assumeTrue(isCluster()); |
| 794 | + assumeTrue(isAtLeastVersion(3, 10)); |
| 795 | + |
| 796 | + ArangoCollection collection = db.collection(COLLECTION_NAME); |
| 797 | + DocumentCreateEntity<?> doc = collection.insertDocument(new BaseDocument()); |
| 798 | + |
| 799 | + StreamTransactionEntity tx = db |
| 800 | + .beginStreamTransaction(new StreamTransactionOptions() |
| 801 | + .readCollections(COLLECTION_NAME) |
| 802 | + .allowDirtyRead(true)); |
| 803 | + |
| 804 | + MultiDocumentEntity<BaseDocument> readDocs = collection.getDocuments(Collections.singletonList(doc.getKey()), |
| 805 | + BaseDocument.class, |
| 806 | + new DocumentReadOptions().streamTransactionId(tx.getId())); |
| 807 | + |
| 808 | + assertThat(readDocs.isPotentialDirtyRead()).isTrue(); |
| 809 | + assertThat(readDocs.getDocuments()).hasSize(1); |
| 810 | + |
| 811 | + final ArangoCursor<BaseDocument> cursor = db.query("FOR i IN @@col RETURN i", |
| 812 | + Collections.singletonMap("@col", COLLECTION_NAME), |
| 813 | + new AqlQueryOptions().streamTransactionId(tx.getId()), BaseDocument.class); |
| 814 | + assertThat(cursor.isPotentialDirtyRead()).isTrue(); |
| 815 | + cursor.close(); |
| 816 | + |
| 817 | + db.abortStreamTransaction(tx.getId()); |
| 818 | + } |
| 819 | + |
788 | 820 | }
|
0 commit comments