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

Function TestCorrectHLVWhenFetchingBackupRev

db/revision_cache_test.go:2305–2345  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2303}
2304
2305func TestCorrectHLVWhenFetchingBackupRev(t *testing.T) {
2306 db, ctx := SetupTestDBWithOptions(t, DatabaseContextOptions{
2307 // enable delta sync so CV revs are backed up
2308 DeltaSyncOptions: DeltaSyncOptions{
2309 Enabled: true,
2310 RevMaxAgeSeconds: DefaultDeltaSyncRevMaxAge,
2311 },
2312 })
2313 defer db.Close(ctx)
2314 collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)
2315
2316 docID := t.Name()
2317 agent := NewHLVAgent(t, collection.dataStore, "someSourceID", base.VvXattrName)
2318
2319 _ = agent.InsertWithHLV(ctx, docID, nil)
2320
2321 docRev, err := collection.getRev(ctx, docID, "", 0, nil)
2322 require.NoError(t, err)
2323 cv := docRev.CV.String()
2324
2325 _, _, err = collection.Put(ctx, docID, Body{"foo": "bar", BodyRev: docRev.RevID})
2326 require.NoError(t, err)
2327
2328 // flush cache
2329 db.FlushRevisionCacheForTest()
2330
2331 // fetch backup rev and assert that the HLV is correct
2332 _, err = collection.getRev(ctx, docID, docRev.CV.String(), 0, nil)
2333 require.ErrorContains(t, err, "missing")
2334
2335 // flush cache
2336 db.FlushRevisionCacheForTest()
2337
2338 // fetch using lower level cache fetch with load from bucket bool true to get the backup rev
2339 docRev, err = collection.revisionCache.GetWithCV(ctx, docID, docRev.CV, RevCacheOmitDelta, true)
2340 require.NoError(t, err)
2341
2342 // hlv history should be empty as we are fetching from backup rev
2343 assert.Empty(t, docRev.HlvHistory)
2344 assert.Equal(t, cv, docRev.CV.String())
2345}
2346
2347func TestRemoveFromRevLookup(t *testing.T) {
2348 cacheHitCounter, cacheMissCounter, cacheNumItems, memoryBytesCounted := base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{}

Callers

nothing calls this directly

Calls 12

InsertWithHLVMethod · 0.95
SetupTestDBWithOptionsFunction · 0.85
NewHLVAgentFunction · 0.85
getRevMethod · 0.80
CloseMethod · 0.65
NameMethod · 0.65
StringMethod · 0.65
PutMethod · 0.65
GetWithCVMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected