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

Function TestGetRemovedAsUser

db/database_test.go:765–846  ·  view source on GitHub ↗

Test retrieval of a channel removal revision, when the revision is not otherwise available

(t *testing.T)

Source from the content-addressed store, hash-verified

763
764// Test retrieval of a channel removal revision, when the revision is not otherwise available
765func TestGetRemovedAsUser(t *testing.T) {
766
767 db, ctx := setupTestDB(t)
768 defer db.Close(ctx)
769 collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)
770 collection.ChannelMapper = channels.NewChannelMapper(ctx, channels.DocChannelsSyncFunction, db.Options.JavascriptTimeout)
771 backingStoreMap := CreateTestSingleBackingStoreMap(collection, collection.GetCollectionID())
772
773 rev1body := Body{
774 "key1": 1234,
775 "channels": []string{"ABC"},
776 }
777 rev1id, _, err := collection.Put(ctx, "doc1", rev1body)
778 assert.NoError(t, err, "Put")
779
780 rev2body := Body{
781 "key1": 1234,
782 "channels": []string{"NBC"},
783 BodyRev: rev1id,
784 }
785 rev2id, _, err := collection.Put(ctx, "doc1", rev2body)
786 assert.NoError(t, err, "Put Rev 2")
787
788 // Add another revision, so that rev 2 is obsolete
789 rev3body := Body{
790 "key1": 12345,
791 "channels": []string{"NBC"},
792 BodyRev: rev2id,
793 }
794 _, _, err = collection.Put(ctx, "doc1", rev3body)
795 assert.NoError(t, err, "Put Rev 3")
796
797 // Get the deleted doc with its history; equivalent to GET with ?revs=true, while still resident in the rev cache
798 body, err := collection.Get1xRevBody(ctx, "doc1", rev2id, true, nil)
799 assert.NoError(t, err, "Get1xRevBody")
800 rev2digest := rev2id[2:]
801 rev1digest := rev1id[2:]
802 expectedResult := Body{
803 "key1": 1234,
804 "channels": []string{"NBC"},
805 BodyRevisions: Revisions{
806 RevisionsStart: 2,
807 RevisionsIds: []string{rev2digest, rev1digest}},
808 BodyId: "doc1",
809 BodyRev: rev2id,
810 }
811 AssertEqualBodies(t, expectedResult, body)
812
813 // Manually remove the temporary backup doc from the bucket
814 // Manually flush the rev cache
815 // After expiry from the rev cache and removal of doc backup, try again
816 cacheHitCounter, cacheMissCounter, cacheNumItems, memoryCacheStat := db.DatabaseContext.DbStats.Cache().RevisionCacheHits, db.DatabaseContext.DbStats.Cache().RevisionCacheMisses, db.DatabaseContext.DbStats.Cache().RevisionCacheNumItems, db.DatabaseContext.DbStats.Cache().RevisionCacheTotalMemory
817 cacheOptions := &RevisionCacheOptions{
818 MaxBytes: 0,
819 MaxItemCount: DefaultRevisionCacheSize,
820 ShardCount: DefaultRevisionCacheShardCount,
821 }
822 collection.dbCtx.revisionCache = NewShardedLRURevisionCache(cacheOptions, backingStoreMap, cacheHitCounter, cacheMissCounter, cacheNumItems, memoryCacheStat)

Callers

nothing calls this directly

Calls 15

GetUserMethod · 0.95
NewChannelMapperFunction · 0.92
NewAuthenticatorFunction · 0.92
AtSequenceFunction · 0.92
SetOfFunction · 0.92
setupTestDBFunction · 0.85
AssertEqualBodiesFunction · 0.85
Get1xRevBodyMethod · 0.80
CacheMethod · 0.80

Tested by

no test coverage detected