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

Function TestItemResidentInCacheBackupRevLoaded

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

Source from the content-addressed store, hash-verified

2786}
2787
2788func TestItemResidentInCacheBackupRevLoaded(t *testing.T) {
2789 testCases := []struct {
2790 name string
2791 useRevID bool
2792 }{
2793 {"FetchByRevID", true},
2794 {"FetchByCV", false},
2795 }
2796 for _, tc := range testCases {
2797 t.Run(tc.name, func(t *testing.T) {
2798 db, ctx := SetupTestDBWithOptions(t, DatabaseContextOptions{
2799 OldRevExpirySeconds: base.DefaultOldRevExpirySeconds,
2800 RevisionCacheOptions: &RevisionCacheOptions{
2801 ShardCount: 1, // turn off sharding for simplicity
2802 MaxItemCount: 10, // turn off size based eviction
2803 MaxBytes: 0, // turn off memory limit
2804 },
2805 DeltaSyncOptions: DeltaSyncOptions{
2806 Enabled: true,
2807 RevMaxAgeSeconds: DefaultDeltaSyncRevMaxAge,
2808 },
2809 })
2810 defer db.Close(ctx)
2811 collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)
2812
2813 docID := SafeDocumentName(t, t.Name())
2814 var firstRevisionID, firstCV string
2815 _, doc1, err := collection.Put(ctx, docID, Body{"foo": "bar"})
2816 require.NoError(t, err)
2817
2818 firstRevisionID = doc1.GetRevTreeID()
2819 firstCV = doc1.HLV.GetCurrentVersionString()
2820
2821 // make revision 2
2822 _, doc1, err = collection.Put(ctx, docID, Body{BodyRev: firstRevisionID, "foo": "baz"})
2823 require.NoError(t, err)
2824
2825 // flush cache, this can be removed pending CBG-4542
2826 db.FlushRevisionCacheForTest()
2827 // grab current version of the doc
2828 if tc.useRevID {
2829 _, err = collection.getRev(ctx, docID, doc1.GetRevTreeID(), 0, nil)
2830 } else {
2831 _, err = collection.getRev(ctx, docID, doc1.HLV.GetCurrentVersionString(), 0, nil)
2832 }
2833 require.NoError(t, err)
2834
2835 // now fetch for backup rev, should load rev and only populate CV map and not revID map when fetching
2836 // by CV and vice versa for fetch by revID
2837 if tc.useRevID {
2838 _, err = collection.getRev(ctx, docID, firstRevisionID, 0, nil)
2839 require.NoError(t, err)
2840 assert.Equal(t, int64(2), db.DbStats.Cache().RevisionCacheNumItems.Value())
2841 } else {
2842 _, err = collection.getRev(ctx, docID, firstCV, 0, nil)
2843 require.Error(t, err)
2844 require.ErrorContains(t, err, "missing")
2845 assert.Equal(t, int64(1), db.DbStats.Cache().RevisionCacheNumItems.Value())

Callers

nothing calls this directly

Calls 15

SetupTestDBWithOptionsFunction · 0.85
getRevMethod · 0.80
CacheMethod · 0.80
SafeDocumentNameFunction · 0.70
RunMethod · 0.65
CloseMethod · 0.65
NameMethod · 0.65
PutMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected