@@ -53,6 +53,7 @@ use crate::{
53
53
fake_retention_validator:: FakeRetentionValidator ,
54
54
ConflictStrategy ,
55
55
DocumentLogEntry ,
56
+ DocumentPrevTsQuery ,
56
57
LatestDocument ,
57
58
NoopRetentionValidator ,
58
59
Persistence ,
@@ -221,10 +222,13 @@ macro_rules! run_persistence_test_suite {
221
222
}
222
223
223
224
#[ tokio:: test]
224
- async fn test_persistence_documents_multiget ( ) -> anyhow:: Result <( ) > {
225
+ async fn test_persistence_previous_revisions_of_documents ( ) -> anyhow:: Result <( ) > {
225
226
let $db = $create_db;
226
227
let p = $create_persistence;
227
- persistence_test_suite:: persistence_documents_multiget( :: std:: sync:: Arc :: new( p) ) . await
228
+ persistence_test_suite:: persistence_previous_revisions_of_documents(
229
+ :: std:: sync:: Arc :: new( p) ,
230
+ )
231
+ . await
228
232
}
229
233
230
234
#[ tokio:: test]
@@ -1756,7 +1760,9 @@ pub async fn persistence_delete_documents<P: Persistence>(p: Arc<P>) -> anyhow::
1756
1760
Ok ( ( ) )
1757
1761
}
1758
1762
1759
- pub async fn persistence_documents_multiget < P : Persistence > ( p : Arc < P > ) -> anyhow:: Result < ( ) > {
1763
+ pub async fn persistence_previous_revisions_of_documents < P : Persistence > (
1764
+ p : Arc < P > ,
1765
+ ) -> anyhow:: Result < ( ) > {
1760
1766
let mut id_generator = TestIdGenerator :: new ( ) ;
1761
1767
let table: TableName = str:: parse ( "table" ) ?;
1762
1768
let id1 = id_generator. user_generate ( & table) ;
@@ -1806,38 +1812,87 @@ pub async fn persistence_documents_multiget<P: Persistence>(p: Arc<P>) -> anyhow
1806
1812
id_generator. generate_internal ( ) ,
1807
1813
) ;
1808
1814
1815
+ // For the purposes of testing, set `ts` to be anything, because only `prev_ts`
1816
+ // is used.
1809
1817
let queries = btreeset ! [
1810
1818
// Latest revision
1811
- ( id1. into( ) , Timestamp :: must( 3 ) ) ,
1812
- // Non-latest revision
1813
- ( id1. into( ) , Timestamp :: must( 1 ) ) ,
1814
- // Tombstone
1815
- ( id2. into( ) , Timestamp :: must( 2 ) ) ,
1816
- // Nonexistent revision
1817
- ( id2. into( ) , Timestamp :: must( 3 ) ) ,
1819
+ DocumentPrevTsQuery {
1820
+ id: id1. into( ) ,
1821
+ ts: Timestamp :: must( 4 ) ,
1822
+ prev_ts: Timestamp :: must( 3 ) ,
1823
+ } ,
1824
+ // Previous revision of latest revision
1825
+ DocumentPrevTsQuery {
1826
+ id: id1. into( ) ,
1827
+ ts: Timestamp :: must( 3 ) ,
1828
+ prev_ts: Timestamp :: must( 1 )
1829
+ } ,
1830
+ // Tombstone (in this case ts doesn't actually exist but it's fine)
1831
+ DocumentPrevTsQuery {
1832
+ id: id2. into( ) ,
1833
+ ts: Timestamp :: must( 3 ) ,
1834
+ prev_ts: Timestamp :: must( 2 )
1835
+ } ,
1836
+ // Nonexistent revision at both ts and prev_ts
1837
+ DocumentPrevTsQuery {
1838
+ id: id2. into( ) ,
1839
+ ts: Timestamp :: must( 4 ) ,
1840
+ prev_ts: Timestamp :: must( 3 )
1841
+ } ,
1818
1842
// Unchanged document
1819
- ( id3. into( ) , Timestamp :: must( 1 ) ) ,
1843
+ DocumentPrevTsQuery {
1844
+ id: id3. into( ) ,
1845
+ ts: Timestamp :: must( 2 ) ,
1846
+ prev_ts: Timestamp :: must( 1 ) ,
1847
+ } ,
1820
1848
// Nonexistent document
1821
- ( nonexistent_id, Timestamp :: must( 1 ) )
1849
+ DocumentPrevTsQuery {
1850
+ id: nonexistent_id,
1851
+ ts: Timestamp :: must( 2 ) ,
1852
+ prev_ts: Timestamp :: must( 1 ) ,
1853
+ } ,
1822
1854
] ;
1823
1855
1824
1856
// Test with NoopRetentionValidator
1825
1857
// Note: Proper retention validation testing will be added in a separate PR
1826
1858
let results = p
1827
1859
. reader ( )
1828
- . documents_multiget ( queries. clone ( ) , Arc :: new ( NoopRetentionValidator ) )
1860
+ . previous_revisions_of_documents ( queries. clone ( ) , Arc :: new ( NoopRetentionValidator ) )
1829
1861
. await ?;
1830
1862
1831
1863
// Should get exact matches only
1832
1864
assert_eq ! ( results. len( ) , 4 ) ; // id1@3, id1@1, id2@2, id3@1
1833
- assert ! ( results. contains_key( & ( id1. into( ) , Timestamp :: must( 3 ) ) ) ) ;
1834
- assert ! ( results. contains_key( & ( id1. into( ) , Timestamp :: must( 1 ) ) ) ) ;
1835
- assert ! ( results. contains_key( & ( id2. into( ) , Timestamp :: must( 2 ) ) ) ) ;
1836
- assert ! ( results. contains_key( & ( id3. into( ) , Timestamp :: must( 1 ) ) ) ) ;
1865
+ assert ! ( results. contains_key( & DocumentPrevTsQuery {
1866
+ id: id1. into( ) ,
1867
+ ts: Timestamp :: must( 3 ) ,
1868
+ prev_ts: Timestamp :: must( 1 )
1869
+ } ) ) ;
1870
+ assert ! ( results. contains_key( & DocumentPrevTsQuery {
1871
+ id: id2. into( ) ,
1872
+ ts: Timestamp :: must( 3 ) ,
1873
+ prev_ts: Timestamp :: must( 2 )
1874
+ } ) ) ;
1875
+ assert ! ( results. contains_key( & DocumentPrevTsQuery {
1876
+ id: id3. into( ) ,
1877
+ ts: Timestamp :: must( 2 ) ,
1878
+ prev_ts: Timestamp :: must( 1 )
1879
+ } ) ) ;
1837
1880
1838
1881
// Verify document contents
1839
- let id1_at_3 = results. get ( & ( id1. into ( ) , Timestamp :: must ( 3 ) ) ) . unwrap ( ) ;
1840
- let id1_at_1 = results. get ( & ( id1. into ( ) , Timestamp :: must ( 1 ) ) ) . unwrap ( ) ;
1882
+ let id1_at_3 = results
1883
+ . get ( & DocumentPrevTsQuery {
1884
+ id : id1. into ( ) ,
1885
+ ts : Timestamp :: must ( 4 ) ,
1886
+ prev_ts : Timestamp :: must ( 3 ) ,
1887
+ } )
1888
+ . unwrap ( ) ;
1889
+ let id1_at_1 = results
1890
+ . get ( & DocumentPrevTsQuery {
1891
+ id : id1. into ( ) ,
1892
+ ts : Timestamp :: must ( 3 ) ,
1893
+ prev_ts : Timestamp :: must ( 1 ) ,
1894
+ } )
1895
+ . unwrap ( ) ;
1841
1896
1842
1897
// Verify id1@3 has the correct document and prev_ts pointing to id1@1
1843
1898
assert_eq ! ( id1_at_3. value, Some ( doc( id1) ) ) ;
@@ -1853,7 +1908,11 @@ pub async fn persistence_documents_multiget<P: Persistence>(p: Arc<P>) -> anyhow
1853
1908
// Verify tombstone
1854
1909
assert_eq ! (
1855
1910
results
1856
- . get( & ( id2. into( ) , Timestamp :: must( 2 ) ) )
1911
+ . get( & DocumentPrevTsQuery {
1912
+ id: id2. into( ) ,
1913
+ ts: Timestamp :: must( 3 ) ,
1914
+ prev_ts: Timestamp :: must( 2 )
1915
+ } )
1857
1916
. unwrap( )
1858
1917
. value,
1859
1918
None
@@ -1862,21 +1921,25 @@ pub async fn persistence_documents_multiget<P: Persistence>(p: Arc<P>) -> anyhow
1862
1921
let retention_validator = FakeRetentionValidator :: new ( Timestamp :: must ( 4 ) , Timestamp :: must ( 0 ) ) ;
1863
1922
// Min ts queried is 1, and min_document_ts is 0, so it's a valid query.
1864
1923
p. reader ( )
1865
- . documents_multiget ( queries. clone ( ) , Arc :: new ( retention_validator) )
1924
+ . previous_revisions_of_documents ( queries. clone ( ) , Arc :: new ( retention_validator) )
1866
1925
. await ?;
1867
1926
1868
1927
let retention_validator = FakeRetentionValidator :: new ( Timestamp :: must ( 4 ) , Timestamp :: must ( 4 ) ) ;
1869
1928
// Min ts queried is 1, and min_document_ts is 4, so it's an invalid query.
1870
1929
assert ! ( p
1871
1930
. reader( )
1872
- . documents_multiget ( queries, Arc :: new( retention_validator) )
1931
+ . previous_revisions_of_documents ( queries, Arc :: new( retention_validator) )
1873
1932
. await
1874
1933
. is_err( ) ) ;
1875
1934
// Errors even if there is no document at the timestamp.
1876
1935
assert ! ( p
1877
1936
. reader( )
1878
- . documents_multiget(
1879
- btreeset![ ( nonexistent_id, Timestamp :: must( 1 ) ) ] ,
1937
+ . previous_revisions_of_documents(
1938
+ btreeset![ DocumentPrevTsQuery {
1939
+ id: nonexistent_id,
1940
+ ts: Timestamp :: must( 1 ) ,
1941
+ prev_ts: Timestamp :: must( 1 )
1942
+ } ] ,
1880
1943
Arc :: new( retention_validator)
1881
1944
)
1882
1945
. await
0 commit comments