TestPutExistingCurrentVersionWithConflict: - Put a document in a db - Assert on the update to HLV after that PUT - Construct a HLV to represent the doc created locally being updated on a client - Call PutExistingCurrentVersion simulating doc update arriving over replicator - Assert conflict between
(t *testing.T)
| 1852 | // - Assert conflict between the local HLV for the doc and the incoming mutation is correctly identified |
| 1853 | // - Assert that the doc's HLV in the bucket hasn't been updated |
| 1854 | func TestPutExistingCurrentVersionWithConflict(t *testing.T) { |
| 1855 | db, ctx := setupTestDB(t) |
| 1856 | defer db.Close(ctx) |
| 1857 | |
| 1858 | bucketUUID := db.EncodedSourceID |
| 1859 | collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db) |
| 1860 | |
| 1861 | // create a new doc |
| 1862 | key := "doc1" |
| 1863 | body := Body{"key1": "value1"} |
| 1864 | |
| 1865 | _, _, err := collection.Put(ctx, key, body) |
| 1866 | require.NoError(t, err) |
| 1867 | |
| 1868 | // assert on the HLV values after the above creation of the doc |
| 1869 | doc, err := collection.GetDocument(ctx, "doc1", DocUnmarshalSync) |
| 1870 | require.NoError(t, err) |
| 1871 | assert.Equal(t, bucketUUID, doc.HLV.SourceID) |
| 1872 | assert.Equal(t, base.HexCasToUint64(doc.SyncData.Cas), doc.HLV.Version) |
| 1873 | assert.Equal(t, base.HexCasToUint64(doc.SyncData.Cas), doc.HLV.CurrentVersionCAS) |
| 1874 | |
| 1875 | // create a new doc update to simulate a doc update arriving over replicator from, client |
| 1876 | body = Body{"key1": "value2"} |
| 1877 | newDoc := CreateTestDocument(key, "", body, false, 0) |
| 1878 | incomingHLV := &HybridLogicalVector{ |
| 1879 | SourceID: "test", |
| 1880 | Version: 1234, |
| 1881 | } |
| 1882 | |
| 1883 | opts := PutDocOptions{ |
| 1884 | NewDoc: newDoc, |
| 1885 | NewDocHLV: incomingHLV, |
| 1886 | } |
| 1887 | // assert that a conflict is correctly identified and the doc and cv are nil |
| 1888 | doc, cv, _, err := collection.PutExistingCurrentVersion(ctx, opts) |
| 1889 | assertHTTPError(t, err, 409) |
| 1890 | require.Nil(t, doc) |
| 1891 | require.Nil(t, cv) |
| 1892 | |
| 1893 | // assert persisted doc hlv hasn't been updated |
| 1894 | doc, err = collection.GetDocument(ctx, "doc1", DocUnmarshalSync) |
| 1895 | assert.NoError(t, err) |
| 1896 | assert.Equal(t, bucketUUID, doc.HLV.SourceID) |
| 1897 | assert.Equal(t, base.HexCasToUint64(doc.SyncData.Cas), doc.HLV.Version) |
| 1898 | assert.Equal(t, base.HexCasToUint64(doc.SyncData.Cas), doc.HLV.CurrentVersionCAS) |
| 1899 | } |
| 1900 | |
| 1901 | // TestPutExistingCurrentVersionWithNoExistingDoc: |
| 1902 | // - Purpose of this test is to test PutExistingRevWithBody code pathway where an |
nothing calls this directly
no test coverage detected