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

Function TestBypassRevisionCache

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

Source from the content-addressed store, hash-verified

628}
629
630func TestBypassRevisionCache(t *testing.T) {
631 base.SetUpTestLogging(t, base.LevelDebug, base.KeyCRUD)
632
633 db, ctx := setupTestDB(t)
634 defer db.Close(ctx)
635
636 collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)
637 backingStoreMap := CreateTestSingleBackingStoreMap(collection, testCollectionID)
638
639 docBody := Body{
640 "value": 1234,
641 }
642 key := "doc1"
643 rev1, _, err := collection.Put(ctx, key, docBody)
644 assert.NoError(t, err)
645
646 docBody["_rev"] = rev1
647 docBody["value"] = 5678
648 rev2, _, err := collection.Put(ctx, key, docBody)
649 assert.NoError(t, err)
650
651 bypassStat := base.SgwIntStat{}
652 rc := NewBypassRevisionCache(backingStoreMap, &bypassStat)
653
654 // Peek always returns false for BypassRevisionCache
655 _, ok := rc.Peek(ctx, key, rev1, 0)
656 assert.False(t, ok)
657 _, ok = rc.Peek(ctx, key, rev2, 0)
658 assert.False(t, ok)
659
660 // Get non-existing doc
661 _, err = rc.GetWithRev(base.TestCtx(t), "invalid", rev1, testCollectionID, RevCacheOmitDelta)
662 assert.True(t, base.IsDocNotFoundError(err))
663
664 // Get non-existing revision
665 _, err = rc.GetWithRev(base.TestCtx(t), key, "3-abc", testCollectionID, RevCacheOmitDelta)
666 assertHTTPError(t, err, 404)
667
668 // Get specific revision
669 doc, err := rc.GetWithRev(base.TestCtx(t), key, rev1, testCollectionID, RevCacheOmitDelta)
670 assert.NoError(t, err)
671 require.NotNil(t, doc)
672 assert.Equal(t, `{"value":1234}`, string(doc.BodyBytes))
673
674 // Check peek is still returning false for "Get"
675 _, ok = rc.Peek(ctx, key, rev1, testCollectionID)
676 assert.False(t, ok)
677
678 // Put no-ops
679 rc.Put(ctx, doc, testCollectionID)
680
681 // Check peek is still returning false for "Put"
682 _, ok = rc.Peek(ctx, key, rev1, testCollectionID)
683 assert.False(t, ok)
684
685 // Get active revision
686 doc, err = rc.GetActive(ctx, key, testCollectionID)
687 assert.NoError(t, err)

Callers

nothing calls this directly

Calls 15

PeekMethod · 0.95
GetWithRevMethod · 0.95
PutMethod · 0.95
GetActiveMethod · 0.95
SetUpTestLoggingFunction · 0.92
TestCtxFunction · 0.92
IsDocNotFoundErrorFunction · 0.92
setupTestDBFunction · 0.85
NewBypassRevisionCacheFunction · 0.85
assertHTTPErrorFunction · 0.70

Tested by

no test coverage detected