MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestPutDocUpdateVersionVector

Function TestPutDocUpdateVersionVector

rest/api_test.go:3053–3091  ·  view source on GitHub ↗

TestPutDocUpdateVersionVector: - Put a doc and assert that the versions and the source for the hlv is correctly updated - Update that doc and assert HLV has also been updated - Delete the doc and assert that the HLV has been updated in deletion event

(t *testing.T)

Source from the content-addressed store, hash-verified

3051// - Update that doc and assert HLV has also been updated
3052// - Delete the doc and assert that the HLV has been updated in deletion event
3053func TestPutDocUpdateVersionVector(t *testing.T) {
3054 rt := NewRestTester(t, nil)
3055 defer rt.Close()
3056
3057 bucketUUID := rt.GetDatabase().EncodedSourceID
3058
3059 resp := rt.SendAdminRequest(http.MethodPut, "/{{.keyspace}}/doc1", `{"key": "value"}`)
3060 RequireStatus(t, resp, http.StatusCreated)
3061
3062 collection, _ := rt.GetSingleTestDatabaseCollection()
3063 doc, err := collection.GetDocument(base.TestCtx(t), "doc1", db.DocUnmarshalSync)
3064 assert.NoError(t, err)
3065
3066 assert.Equal(t, bucketUUID, doc.HLV.SourceID)
3067 assert.Equal(t, base.HexCasToUint64(doc.SyncData.Cas), doc.HLV.Version)
3068 assert.Equal(t, base.HexCasToUint64(doc.SyncData.Cas), doc.HLV.CurrentVersionCAS)
3069
3070 // Put a new revision of this doc and assert that the version vector SourceID and Version is updated
3071 resp = rt.SendAdminRequest(http.MethodPut, "/{{.keyspace}}/doc1?rev="+doc.SyncData.GetRevTreeID(), `{"key1": "value1"}`)
3072 RequireStatus(t, resp, http.StatusCreated)
3073
3074 doc, err = collection.GetDocument(base.TestCtx(t), "doc1", db.DocUnmarshalSync)
3075 assert.NoError(t, err)
3076
3077 assert.Equal(t, bucketUUID, doc.HLV.SourceID)
3078 assert.Equal(t, base.HexCasToUint64(doc.SyncData.Cas), doc.HLV.Version)
3079 assert.Equal(t, base.HexCasToUint64(doc.SyncData.Cas), doc.HLV.CurrentVersionCAS)
3080
3081 // Delete doc and assert that the version vector SourceID and Version is updated
3082 resp = rt.SendAdminRequest(http.MethodDelete, "/{{.keyspace}}/doc1?rev="+doc.SyncData.GetRevTreeID(), "")
3083 RequireStatus(t, resp, http.StatusOK)
3084
3085 doc, err = collection.GetDocument(base.TestCtx(t), "doc1", db.DocUnmarshalSync)
3086 assert.NoError(t, err)
3087
3088 assert.Equal(t, bucketUUID, doc.HLV.SourceID)
3089 assert.Equal(t, base.HexCasToUint64(doc.SyncData.Cas), doc.HLV.Version)
3090 assert.Equal(t, base.HexCasToUint64(doc.SyncData.Cas), doc.HLV.CurrentVersionCAS)
3091}
3092
3093// TestHLVOnPutWithImportRejection:
3094// - Put a doc successfully and assert the HLV is updated correctly

Callers

nothing calls this directly

Calls 11

CloseMethod · 0.95
GetDatabaseMethod · 0.95
SendAdminRequestMethod · 0.95
TestCtxFunction · 0.92
HexCasToUint64Function · 0.92
NewRestTesterFunction · 0.85
RequireStatusFunction · 0.85
GetDocumentMethod · 0.65
EqualMethod · 0.45
GetRevTreeIDMethod · 0.45

Tested by

no test coverage detected