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

Function TestRevCacheHitMultiCollection

db/revision_cache_test.go:1378–1419  ·  view source on GitHub ↗

TestRevCacheHitMultiCollection: - Create db with two collections - Add docs of the same ID to each collection the database - Perform a Get for each doc in each collection - Assert each doc returned is the correct one (correct rev ID etc) - Assert that each doc is found at the rev cache and no misses

(t *testing.T)

Source from the content-addressed store, hash-verified

1376// - Assert each doc returned is the correct one (correct rev ID etc)
1377// - Assert that each doc is found at the rev cache and no misses are reported
1378func TestRevCacheHitMultiCollection(t *testing.T) {
1379 base.TestRequiresCollections(t)
1380
1381 tb := base.GetTestBucket(t)
1382 defer tb.Close(base.TestCtx(t))
1383 dbOptions := DatabaseContextOptions{}
1384 dbOptions.Scopes = GetScopesOptions(t, tb, 2)
1385
1386 db, ctx := SetupTestDBForBucketWithOptions(t, tb, dbOptions)
1387 defer db.Close(ctx)
1388
1389 var collectionList []*DatabaseCollectionWithUser
1390 var revList []string
1391 // add a doc with the same docs id to each collection on the database
1392 for _, collection := range db.CollectionByID {
1393 collWIthUser := &DatabaseCollectionWithUser{
1394 DatabaseCollection: collection,
1395 }
1396 collectionList = append(collectionList, collWIthUser)
1397 }
1398
1399 // add a doc to each collection on the db with the same document id (testing the cache still gets unique keys)
1400 for i, collection := range collectionList {
1401 ctx := collection.AddCollectionContext(ctx)
1402 docRevID, _, err := collection.Put(ctx, "doc", Body{"test": fmt.Sprintf("doc%d", i)})
1403 require.NoError(t, err)
1404 revList = append(revList, docRevID)
1405 }
1406
1407 // Perform a get for the doc in each collection
1408 for i, collection := range collectionList {
1409 ctx := collection.AddCollectionContext(ctx)
1410 docRev, err := collection.GetRev(ctx, "doc", revList[i], false, nil)
1411 require.NoError(t, err)
1412 assert.Equal(t, "doc", docRev.DocID)
1413 assert.Equal(t, revList[i], docRev.RevID)
1414 }
1415
1416 // assert that both docs were found in rev cache and no cache misses are being reported
1417 assert.Equal(t, int64(2), db.DbStats.Cache().RevisionCacheHits.Value())
1418 assert.Equal(t, int64(0), db.DbStats.Cache().RevisionCacheMisses.Value())
1419}
1420
1421// TestRevCacheHitMultiCollectionLoadFromBucket:
1422// - Create db with two collections and have rev cache size of 1

Callers

nothing calls this directly

Calls 12

TestRequiresCollectionsFunction · 0.92
GetTestBucketFunction · 0.92
TestCtxFunction · 0.92
GetScopesOptionsFunction · 0.85
AddCollectionContextMethod · 0.80
GetRevMethod · 0.80
CacheMethod · 0.80
CloseMethod · 0.65
PutMethod · 0.65
EqualMethod · 0.45
ValueMethod · 0.45

Tested by

no test coverage detected