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

Function TestGetRemoved

db/database_test.go:1576–1647  ·  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

1574
1575// Test retrieval of a channel removal revision, when the revision is not otherwise available
1576func TestGetRemoved(t *testing.T) {
1577
1578 db, ctx := setupTestDB(t)
1579 defer db.Close(ctx)
1580 collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)
1581 backingStoreMap := CreateTestSingleBackingStoreMap(collection, collection.GetCollectionID())
1582
1583 rev1body := Body{
1584 "key1": 1234,
1585 "channels": []string{"ABC"},
1586 }
1587 rev1id, _, err := collection.Put(ctx, "doc1", rev1body)
1588 assert.NoError(t, err, "Put")
1589
1590 rev2body := Body{
1591 "key1": 1234,
1592 "channels": []string{"NBC"},
1593 BodyRev: rev1id,
1594 }
1595 rev2id, _, err := collection.Put(ctx, "doc1", rev2body)
1596 assert.NoError(t, err, "Put Rev 2")
1597
1598 // Add another revision, so that rev 2 is obsolete
1599 rev3body := Body{
1600 "key1": 12345,
1601 "channels": []string{"NBC"},
1602 BodyRev: rev2id,
1603 }
1604 _, _, err = collection.Put(ctx, "doc1", rev3body)
1605 assert.NoError(t, err, "Put Rev 3")
1606
1607 // Get the deleted doc with its history; equivalent to GET with ?revs=true, while still resident in the rev cache
1608 body, err := collection.Get1xRevBody(ctx, "doc1", rev2id, true, nil)
1609 assert.NoError(t, err, "Get1xRevBody")
1610 rev2digest := rev2id[2:]
1611 rev1digest := rev1id[2:]
1612 expectedResult := Body{
1613 "key1": 1234,
1614 "channels": []string{"NBC"},
1615 BodyRevisions: Revisions{
1616 RevisionsStart: 2,
1617 RevisionsIds: []string{rev2digest, rev1digest}},
1618 BodyId: "doc1",
1619 BodyRev: rev2id,
1620 }
1621 AssertEqualBodies(t, expectedResult, body)
1622
1623 // Manually remove the temporary backup doc from the bucket
1624 // Manually flush the rev cache
1625 // After expiry from the rev cache and removal of doc backup, try again
1626 cacheHitCounter, cacheMissCounter, cacheNumItems, memoryCacheStat := db.DatabaseContext.DbStats.Cache().RevisionCacheHits, db.DatabaseContext.DbStats.Cache().RevisionCacheMisses, db.DatabaseContext.DbStats.Cache().RevisionCacheNumItems, db.DatabaseContext.DbStats.Cache().RevisionCacheTotalMemory
1627 cacheOptions := &RevisionCacheOptions{
1628 MaxBytes: 0,
1629 MaxItemCount: DefaultRevisionCacheSize,
1630 ShardCount: DefaultRevisionCacheShardCount,
1631 }
1632 collection.dbCtx.revisionCache = NewShardedLRURevisionCache(cacheOptions, backingStoreMap, cacheHitCounter, cacheMissCounter, cacheNumItems, memoryCacheStat)
1633 err = collection.PurgeOldRevisionJSON(ctx, "doc1", rev2id)

Callers

nothing calls this directly

Calls 12

setupTestDBFunction · 0.85
AssertEqualBodiesFunction · 0.85
Get1xRevBodyMethod · 0.80
CacheMethod · 0.80
PurgeOldRevisionJSONMethod · 0.80
assertHTTPErrorFunction · 0.70
CloseMethod · 0.65
PutMethod · 0.65
GetCollectionIDMethod · 0.45

Tested by

no test coverage detected