TestPvDeltaReadAndWrite: - Write a doc from another hlv aware peer to the bucket - Force import of this doc, then update this doc via rest tester source - Assert that the document hlv is as expected - Update the doc from a new hlv aware peer and force the import of this new write - Assert that the n
(t *testing.T)
| 2998 | // - Assert that the new hlv is as expected, testing that the hlv went through transformation to the persisted delta |
| 2999 | // version and back to the in memory version as expected |
| 3000 | func TestPvDeltaReadAndWrite(t *testing.T) { |
| 3001 | rt := NewRestTester(t, nil) |
| 3002 | defer rt.Close() |
| 3003 | collection, ctx := rt.GetSingleTestDatabaseCollectionWithUser() |
| 3004 | testSource := rt.GetDatabase().EncodedSourceID |
| 3005 | |
| 3006 | const docID = "doc1" |
| 3007 | otherSource := "otherSource" |
| 3008 | hlvHelper := db.NewHLVAgent(t, rt.GetSingleDataStore(), otherSource, "_vv") |
| 3009 | existingHLVKey := docID |
| 3010 | cas := hlvHelper.InsertWithHLV(ctx, existingHLVKey, nil) |
| 3011 | casV1 := cas |
| 3012 | encodedSourceV1 := db.EncodeSource(otherSource) |
| 3013 | |
| 3014 | // force import of this write |
| 3015 | version1, _ := rt.GetDoc(docID) |
| 3016 | |
| 3017 | // update the above doc, this should push CV to PV and adds a new CV |
| 3018 | version2 := rt.UpdateDoc(docID, version1, `{"new": "update!"}`) |
| 3019 | newDoc, _, err := collection.GetDocWithXattrs(ctx, existingHLVKey, db.DocUnmarshalAll) |
| 3020 | require.NoError(t, err) |
| 3021 | casV2 := newDoc.Cas |
| 3022 | encodedSourceV2 := testSource |
| 3023 | |
| 3024 | // assert that we have a prev CV drop to pv and a new CV pair, assert pv values are as expected after delta conversions |
| 3025 | assert.Equal(t, testSource, newDoc.HLV.SourceID) |
| 3026 | assert.Equal(t, version2.CV.Value, newDoc.HLV.Version) |
| 3027 | assert.Len(t, newDoc.HLV.PreviousVersions, 1) |
| 3028 | assert.Equal(t, casV1, newDoc.HLV.PreviousVersions[encodedSourceV1]) |
| 3029 | |
| 3030 | otherSource = "diffSource" |
| 3031 | hlvHelper = db.NewHLVAgent(t, rt.GetSingleDataStore(), otherSource, "_vv") |
| 3032 | cas = hlvHelper.UpdateWithHLV(ctx, existingHLVKey, newDoc.Cas, newDoc.HLV) |
| 3033 | encodedSourceV3 := db.EncodeSource(otherSource) |
| 3034 | casV3 := cas |
| 3035 | |
| 3036 | // import and get raw doc |
| 3037 | _, _ = rt.GetDoc(docID) |
| 3038 | bucketDoc, _, err := collection.GetDocWithXattrs(ctx, docID, db.DocUnmarshalAll) |
| 3039 | require.NoError(t, err) |
| 3040 | |
| 3041 | // assert that we have two entries in previous versions, and they are correctly converted from deltas back to full value |
| 3042 | assert.Equal(t, encodedSourceV3, bucketDoc.HLV.SourceID) |
| 3043 | assert.Equal(t, casV3, bucketDoc.HLV.Version) |
| 3044 | assert.Len(t, bucketDoc.HLV.PreviousVersions, 2) |
| 3045 | assert.Equal(t, casV1, bucketDoc.HLV.PreviousVersions[encodedSourceV1]) |
| 3046 | assert.Equal(t, casV2, bucketDoc.HLV.PreviousVersions[encodedSourceV2]) |
| 3047 | } |
| 3048 | |
| 3049 | // TestPutDocUpdateVersionVector: |
| 3050 | // - Put a doc and assert that the versions and the source for the hlv is correctly updated |
nothing calls this directly
no test coverage detected