@@ -1666,6 +1666,40 @@ public void TestConflictResolverReturningBlobFromDifferentDB()
1666
1666
TestConflictResolverExceptionThrown ( blobFromOtherDbResolver , false , true ) ;
1667
1667
}
1668
1668
1669
+ //CBL-623: Revision flags get cleared while saving resolved document
1670
+ [ Fact ]
1671
+ public void TestConflictResolverPreservesFlags ( )
1672
+ {
1673
+ //force conflicts and check flags
1674
+ CreateReplicationConflict ( "doc1" , true ) ;
1675
+
1676
+ var config = CreateConfig ( false , true , false ) ;
1677
+ C4DocumentFlags flags = ( C4DocumentFlags ) 0 ;
1678
+ config . ConflictResolver = new TestConflictResolver ( ( conflict ) =>
1679
+ {
1680
+ unsafe
1681
+ {
1682
+ flags = conflict . LocalDocument . c4Doc . RawDoc ->flags ;
1683
+ flags . HasFlag ( C4DocumentFlags . DocConflicted ) . Should ( ) . BeTrue ( ) ;
1684
+ flags . HasFlag ( C4DocumentFlags . DocExists | C4DocumentFlags . DocHasAttachments ) . Should ( ) . BeTrue ( ) ;
1685
+ return conflict . LocalDocument ;
1686
+ }
1687
+ } ) ;
1688
+
1689
+ RunReplication ( config , 0 , 0 ) ;
1690
+
1691
+ using ( var doc = Db . GetDocument ( "doc1" ) ) {
1692
+ doc . GetBlob ( "blob" ) ? . Content . Should ( ) . ContainInOrder ( new byte [ ] { 6 , 6 , 6 } ) ;
1693
+ unsafe
1694
+ {
1695
+ flags = doc . c4Doc . RawDoc ->flags ;
1696
+ }
1697
+ }
1698
+
1699
+ flags . HasFlag ( C4DocumentFlags . DocConflicted ) . Should ( ) . BeFalse ( ) ;
1700
+ flags . HasFlag ( C4DocumentFlags . DocExists | C4DocumentFlags . DocHasAttachments ) . Should ( ) . BeTrue ( ) ;
1701
+ }
1702
+
1669
1703
private void TestConflictResolverExceptionThrown ( TestConflictResolver resolver , bool continueWithWorkingResolver = false , bool withBlob = false )
1670
1704
{
1671
1705
CreateReplicationConflict ( "doc1" ) ;
@@ -1750,39 +1784,62 @@ private void TestConflictResolverWins(bool returnRemoteDoc)
1750
1784
}
1751
1785
}
1752
1786
1753
- private void CreateReplicationConflict ( string id )
1787
+ private void CreateReplicationConflict ( string id , bool checkFlags = false )
1754
1788
{
1755
- var oddByteArray = new byte [ ] { 1 , 3 , 5 } ;
1756
-
1757
- using ( var doc1 = new MutableDocument ( id ) ) {
1758
- doc1 . SetString ( "name" , "Tiger" ) ;
1759
- doc1 . SetBlob ( "blob" , new Blob ( "text/plaintext" , oddByteArray ) ) ;
1760
- Db . Save ( doc1 ) ;
1761
- }
1762
-
1763
- using ( var doc1 = new MutableDocument ( id ) ) {
1764
- doc1 . SetString ( "name" , "Tiger" ) ;
1765
- doc1 . SetBlob ( "blob" , new Blob ( "text/plaintext" , oddByteArray ) ) ;
1766
- _otherDB . Save ( doc1 ) ;
1767
- }
1768
-
1769
- // Force a conflict
1770
- using ( var doc1a = Db . GetDocument ( id ) )
1771
- using ( var doc1aMutable = doc1a . ToMutable ( ) ) {
1772
- var evilByteArray = new byte [ ] { 6 , 6 , 6 } ;
1789
+ unsafe
1790
+ {
1791
+ var oddByteArray = new byte [ ] { 1 , 3 , 5 } ;
1792
+ C4DocumentFlags flags = ( C4DocumentFlags ) 0 ;
1793
+ using ( var doc1 = new MutableDocument ( id ) )
1794
+ {
1795
+ doc1 . SetString ( "name" , "Tiger" ) ;
1796
+ doc1 . SetBlob ( "blob" , new Blob ( "text/plaintext" , oddByteArray ) ) ;
1797
+ Db . Save ( doc1 ) ;
1798
+ if ( checkFlags ) {
1799
+ flags = doc1 . c4Doc . RawDoc ->flags ;
1800
+ flags . HasFlag ( C4DocumentFlags . DocExists | C4DocumentFlags . DocHasAttachments ) . Should ( ) . BeTrue ( ) ;
1801
+ }
1802
+ }
1773
1803
1774
- doc1aMutable . SetString ( "name" , "Cat" ) ;
1775
- doc1aMutable . SetBlob ( "blob" , new Blob ( "text/plaintext" , evilByteArray ) ) ;
1776
- Db . Save ( doc1aMutable ) ;
1777
- }
1804
+ using ( var doc1 = new MutableDocument ( id ) )
1805
+ {
1806
+ doc1 . SetString ( "name" , "Tiger" ) ;
1807
+ doc1 . SetBlob ( "blob" , new Blob ( "text/plaintext" , oddByteArray ) ) ;
1808
+ _otherDB . Save ( doc1 ) ;
1809
+ if ( checkFlags ) {
1810
+ flags = doc1 . c4Doc . RawDoc ->flags ;
1811
+ flags . HasFlag ( C4DocumentFlags . DocExists | C4DocumentFlags . DocHasAttachments ) . Should ( ) . BeTrue ( ) ;
1812
+ }
1813
+ }
1778
1814
1779
- using ( var doc1a = _otherDB . GetDocument ( id ) )
1780
- using ( var doc1aMutable = doc1a . ToMutable ( ) ) {
1781
- var luckyByteArray = new byte [ ] { 7 , 7 , 7 } ;
1815
+ // Force a conflict
1816
+ using ( var doc1a = Db . GetDocument ( id ) )
1817
+ using ( var doc1aMutable = doc1a . ToMutable ( ) )
1818
+ {
1819
+ var evilByteArray = new byte [ ] { 6 , 6 , 6 } ;
1820
+
1821
+ doc1aMutable . SetString ( "name" , "Cat" ) ;
1822
+ doc1aMutable . SetBlob ( "blob" , new Blob ( "text/plaintext" , evilByteArray ) ) ;
1823
+ Db . Save ( doc1aMutable ) ;
1824
+ if ( checkFlags ) {
1825
+ flags = doc1aMutable . c4Doc . RawDoc ->flags ;
1826
+ flags . HasFlag ( C4DocumentFlags . DocExists | C4DocumentFlags . DocHasAttachments ) . Should ( ) . BeTrue ( ) ;
1827
+ }
1828
+ }
1782
1829
1783
- doc1aMutable . SetString ( "name" , "Lion" ) ;
1784
- doc1aMutable . SetBlob ( "blob" , new Blob ( "text/plaintext" , luckyByteArray ) ) ;
1785
- _otherDB . Save ( doc1aMutable ) ;
1830
+ using ( var doc1a = _otherDB . GetDocument ( id ) )
1831
+ using ( var doc1aMutable = doc1a . ToMutable ( ) )
1832
+ {
1833
+ var luckyByteArray = new byte [ ] { 7 , 7 , 7 } ;
1834
+
1835
+ doc1aMutable . SetString ( "name" , "Lion" ) ;
1836
+ doc1aMutable . SetBlob ( "blob" , new Blob ( "text/plaintext" , luckyByteArray ) ) ;
1837
+ _otherDB . Save ( doc1aMutable ) ;
1838
+ if ( checkFlags ) {
1839
+ flags = doc1aMutable . c4Doc . RawDoc ->flags ;
1840
+ flags . HasFlag ( C4DocumentFlags . DocExists | C4DocumentFlags . DocHasAttachments ) . Should ( ) . BeTrue ( ) ;
1841
+ }
1842
+ }
1786
1843
}
1787
1844
}
1788
1845
0 commit comments