|
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;
|
@@ -788,4 +789,35 @@ void transactionAllowImplicitFalse(ArangoDatabase db) {
|
788 | 789 |
|
789 | 790 | db.abortStreamTransaction(tx.getId());
|
790 | 791 | }
|
| 792 | + |
| 793 | + @ParameterizedTest(name = "{index}") |
| 794 | + @MethodSource("dbs") |
| 795 | + void transactionDirtyRead(ArangoDatabase db) throws IOException { |
| 796 | + assumeTrue(isCluster()); |
| 797 | + assumeTrue(isAtLeastVersion(3, 10)); |
| 798 | + |
| 799 | + ArangoCollection collection = db.collection(COLLECTION_NAME); |
| 800 | + DocumentCreateEntity<BaseDocument> doc = collection.insertDocument(new BaseDocument()); |
| 801 | + |
| 802 | + StreamTransactionEntity tx = db |
| 803 | + .beginStreamTransaction(new StreamTransactionOptions() |
| 804 | + .readCollections(COLLECTION_NAME) |
| 805 | + .allowDirtyRead(true)); |
| 806 | + |
| 807 | + MultiDocumentEntity<BaseDocument> readDocs = collection.getDocuments(Collections.singletonList(doc.getKey()), |
| 808 | + BaseDocument.class, |
| 809 | + new DocumentReadOptions().streamTransactionId(tx.getId())); |
| 810 | + |
| 811 | + assertThat(readDocs.isPotentialDirtyRead()).isTrue(); |
| 812 | + assertThat(readDocs.getDocuments()).hasSize(1); |
| 813 | + |
| 814 | + final ArangoCursor<BaseDocument> cursor = db.query("FOR i IN @@col RETURN i", |
| 815 | + Collections.singletonMap("@col", COLLECTION_NAME), |
| 816 | + new AqlQueryOptions().streamTransactionId(tx.getId()), BaseDocument.class); |
| 817 | + assertThat(cursor.isPotentialDirtyRead()).isTrue(); |
| 818 | + cursor.close(); |
| 819 | + |
| 820 | + db.abortStreamTransaction(tx.getId()); |
| 821 | + } |
| 822 | + |
791 | 823 | }
|
0 commit comments