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

Function TestChannelCacheStatsOnPrune

db/channel_cache_single_test.go:582–619  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

580}
581
582func TestChannelCacheStatsOnPrune(t *testing.T) {
583
584 base.SetUpTestLogging(t, base.LevelInfo, base.KeyCache)
585
586 db, ctx := setupTestDB(t)
587 defer db.Close(ctx)
588
589 stats, err := base.NewSyncGatewayStats()
590 require.NoError(t, err)
591
592 dbstats, err := stats.NewDBStats("", false, false, false, nil, nil)
593 require.NoError(t, err)
594
595 collection := GetSingleDatabaseCollection(t, db.DatabaseContext)
596 collectionID := collection.GetCollectionID()
597
598 testStats := dbstats.Cache()
599 cache := newSingleChannelCache(collection, channels.NewID("Test1", collectionID), 0, testStats)
600 cache.options.ChannelCacheMaxLength = 5
601
602 // Add more than ChannelCacheMaxLength entries to cache
603 cache.addToCache(ctx, testLogEntry(1, "doc1", "1-a"), false)
604 cache.addToCache(ctx, testLogEntry(2, "doc2", "1-a"), true)
605 cache.addToCache(ctx, testLogEntry(3, "doc3", "1-a"), false)
606 cache.addToCache(ctx, testLogEntry(4, "doc4", "1-a"), true)
607 cache.addToCache(ctx, testLogEntry(5, "doc5", "1-a"), false)
608 cache.addToCache(ctx, testLogEntry(6, "doc6", "1-a"), true)
609 cache.addToCache(ctx, testLogEntry(7, "doc7", "1-a"), false)
610 cache.addToCache(ctx, testLogEntry(8, "doc8", "1-a"), true)
611 cache.addToCache(ctx, testLogEntry(9, "doc9", "1-a"), false)
612 cache.addToCache(ctx, testLogEntry(10, "doc10", "1-a"), true)
613
614 active, tombstones, removals := getCacheUtilization(testStats)
615 assert.Equal(t, 2, active)
616 assert.Equal(t, 0, tombstones)
617 assert.Equal(t, 3, removals)
618
619}
620
621func TestChannelCacheStatsOnPrepend(t *testing.T) {
622

Callers

nothing calls this directly

Calls 14

SetUpTestLoggingFunction · 0.92
NewSyncGatewayStatsFunction · 0.92
NewIDFunction · 0.92
setupTestDBFunction · 0.85
newSingleChannelCacheFunction · 0.85
testLogEntryFunction · 0.85
getCacheUtilizationFunction · 0.85
NewDBStatsMethod · 0.80
CacheMethod · 0.80
addToCacheMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected