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

Function TestChannelCacheMaxSize

db/channel_cache_test.go:26–54  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24)
25
26func TestChannelCacheMaxSize(t *testing.T) {
27 db, ctx := setupTestDB(t)
28 defer db.Close(ctx)
29
30 cache := db.changeCache.getChannelCache()
31
32 collectionID := GetSingleDatabaseCollection(t, db.DatabaseContext).GetCollectionID()
33
34 // Make channels active
35 _, err := cache.GetChanges(ctx, channels.NewID("TestA", collectionID), getChangesOptionsWithCtxOnly(t))
36 require.NoError(t, err)
37 _, err = cache.GetChanges(ctx, channels.NewID("TestB", collectionID), getChangesOptionsWithCtxOnly(t))
38 require.NoError(t, err)
39 _, err = cache.GetChanges(ctx, channels.NewID("TestC", collectionID), getChangesOptionsWithCtxOnly(t))
40 require.NoError(t, err)
41 _, err = cache.GetChanges(ctx, channels.NewID("TestD", collectionID), getChangesOptionsWithCtxOnly(t))
42 require.NoError(t, err)
43
44 // Add some entries to caches, leaving some empty caches
45 cache.AddToCache(ctx, logEntry(1, "doc1", "1-a", []string{"TestB", "TestC", "TestD"}, collectionID))
46 cache.AddToCache(ctx, logEntry(2, "doc2", "1-a", []string{"TestB", "TestC", "TestD"}, collectionID))
47 cache.AddToCache(ctx, logEntry(3, "doc3", "1-a", []string{"TestB", "TestC", "TestD"}, collectionID))
48 cache.AddToCache(ctx, logEntry(4, "doc4", "1-a", []string{"TestC"}, collectionID))
49
50 db.UpdateCalculatedStats(ctx)
51
52 maxEntries := db.DbStats.Cache().ChannelCacheMaxEntries.Value()
53 assert.Equal(t, 4, int(maxEntries))
54}
55
56// TestChannelCacheCurrentVersion:
57// - Makes channel channels active for channels used in test by requesting changes on each channel

Callers

nothing calls this directly

Calls 14

NewIDFunction · 0.92
setupTestDBFunction · 0.85
logEntryFunction · 0.85
UpdateCalculatedStatsMethod · 0.80
CacheMethod · 0.80
CloseMethod · 0.65
GetChangesMethod · 0.65
AddToCacheMethod · 0.65
getChannelCacheMethod · 0.45
GetCollectionIDMethod · 0.45

Tested by

no test coverage detected