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

Function TestChannelCacheSimpleCompact

db/channel_cache_test.go:124–162  ·  view source on GitHub ↗

Test Cases - simple compact - validate compaction stops at LWM - validate compaction continues - multiple calls to start - compact with concurrent additions to cache - getChanges when cache full

(t *testing.T)

Source from the content-addressed store, hash-verified

122// - getChanges when cache full
123
124func TestChannelCacheSimpleCompact(t *testing.T) {
125
126 base.SetUpTestLogging(t, base.LevelInfo, base.KeyCache)
127
128 // Define cache with max channels 20, hwm will be 16, low water mark will be 12
129 options := DefaultCacheOptions().ChannelCacheOptions
130 options.MaxNumChannels = 20
131
132 stats, err := base.NewSyncGatewayStats()
133 require.NoError(t, err)
134 dbstats, err := stats.NewDBStats("", false, false, false, nil, nil)
135 require.NoError(t, err)
136 testStats := dbstats.Cache()
137 activeChannelStat := &base.SgwIntStat{}
138 activeChannels := channels.NewActiveChannels(activeChannelStat)
139 ctx := base.TestCtx(t)
140 cache, err := newChannelCache(base.TestCtx(t), "testDb", options, testQueryHandlerFactory, activeChannels, testStats)
141 require.NoError(t, err, "Background task error whilst creating channel cache")
142 defer cache.Stop(ctx)
143
144 require.NoError(t, err)
145
146 // Add 16 channels to the cache. Shouldn't trigger compaction (hwm is not exceeded)
147 for i := 1; i <= 16; i++ {
148 channelName := fmt.Sprintf("chan_%d", i)
149 cache.addChannelCache(ctx, channels.NewID(channelName, base.DefaultCollectionID))
150 }
151 // Validate cache size
152 assert.Equal(t, 16, cache.channelCaches.Length())
153
154 // Add another channel to cache
155 cache.addChannelCache(ctx, channels.NewID("chan_17", base.DefaultCollectionID))
156
157 assert.True(t, waitForCompaction(cache), "Compaction didn't complete in expected time")
158
159 // Validate cache size
160 assert.Equal(t, 12, cache.channelCaches.Length())
161
162}
163
164func TestChannelCacheCompactInactiveChannels(t *testing.T) {
165

Callers

nothing calls this directly

Calls 14

SetUpTestLoggingFunction · 0.92
NewSyncGatewayStatsFunction · 0.92
NewActiveChannelsFunction · 0.92
TestCtxFunction · 0.92
NewIDFunction · 0.92
DefaultCacheOptionsFunction · 0.85
newChannelCacheFunction · 0.85
waitForCompactionFunction · 0.85
NewDBStatsMethod · 0.80
CacheMethod · 0.80
addChannelCacheMethod · 0.80
LengthMethod · 0.80

Tested by

no test coverage detected