MCPcopy
hub / github.com/grafana/tempo / TestLogClusterCache_Values

Function TestLogClusterCache_Values

pkg/drain/log_cluster_cache_test.go:138–172  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

136}
137
138func TestLogClusterCache_Values(t *testing.T) {
139 t.Parallel()
140
141 evictions := prometheus.NewCounter(prometheus.CounterOpts{Name: "evictions"})
142 expired := prometheus.NewCounter(prometheus.CounterOpts{Name: "expired"})
143
144 cache := newLogClusterCache(1*time.Hour, 100, evictions, expired)
145
146 // Add multiple clusters
147 clusters := []*LogCluster{
148 {id: 1, Tokens: []string{"GET", "/users"}, ParamString: "<_>"},
149 {id: 2, Tokens: []string{"POST", "/users"}, ParamString: "<_>"},
150 {id: 3, Tokens: []string{"PUT", "/users"}, ParamString: "<_>"},
151 }
152
153 for _, cluster := range clusters {
154 cache.Put(cluster)
155 }
156
157 // Values() should return all clusters
158 values := []*LogCluster{}
159 for cluster := range cache.Values() {
160 values = append(values, cluster)
161 }
162
163 assert.Len(t, values, 3)
164 // Verify all clusters are present
165 ids := make(map[int]bool)
166 for _, cluster := range values {
167 ids[cluster.id] = true
168 }
169 assert.True(t, ids[1])
170 assert.True(t, ids[2])
171 assert.True(t, ids[3])
172}

Callers

nothing calls this directly

Calls 5

newLogClusterCacheFunction · 0.85
NewCounterMethod · 0.65
LenMethod · 0.65
PutMethod · 0.45
ValuesMethod · 0.45

Tested by

no test coverage detected