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

Function TestCacheKeys

tempodb/backend/cache/cache_test.go:272–307  ·  tempodb/backend/cache/cache_test.go::TestCacheKeys
(t *testing.T)

Source from the content-addressed store, hash-verified

270}
271
272func TestCacheKeys(t *testing.T) {
273 provider := test.NewMockProvider()
274 reader, _, err := NewCache(&BloomConfig{
275 CacheMaxBlockAge: time.Hour,
276 CacheMinCompactionLevel: 1,
277 }, nil, nil, provider, log.NewNopLogger())
278 require.NoError(t, err)
279
280 ctx := context.Background()
281 role := cache.RoleParquetFooter // role doesn't matter b/c the mock provider always returns the same cache
282
283 // Read : seed data at expected key
284 expectedKey := "bar:baz:foo" // keypath + object name
285 expectedData := []byte("test-read")
286 provider.CacheFor(role).Store(ctx, []string{expectedKey}, [][]byte{expectedData})
287
288 // make request and confirm it returns
289 actualReader, actualBytes, err := reader.Read(ctx, "foo", backend.KeyPath{"bar", "baz"}, &backend.CacheInfo{Role: role})
290 require.NoError(t, err)
291 require.Equal(t, len(expectedData), int(actualBytes))
292
293 actualData, err := io.ReadAll(actualReader)
294 require.NoError(t, err)
295 require.Equal(t, expectedData, actualData)
296
297 // ReadRange : seed data at expected key
298 expectedKey = "bar:baz:foo:10:10" // keypath + object name + offset + length
299 expectedData = []byte("test-range")
300 provider.CacheFor(role).Store(ctx, []string{expectedKey}, [][]byte{expectedData})
301
302 // make request and confirm it returns
303 actualBuffer := make([]byte, 10)
304 err = reader.ReadRange(ctx, "foo", backend.KeyPath{"bar", "baz"}, 10, actualBuffer, &backend.CacheInfo{Role: role})
305 require.NoError(t, err)
306 require.Equal(t, expectedData, actualBuffer)
307}

Callers

nothing calls this directly

Calls 8

NewMockProviderFunction · 0.92
NewCacheFunction · 0.85
StoreMethod · 0.65
CacheForMethod · 0.65
ReadMethod · 0.65
ReadAllMethod · 0.65
ReadRangeMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected