(t *testing.T)
| 17 | ) |
| 18 | |
| 19 | func TestCacheFor(t *testing.T) { |
| 20 | reader, _, err := NewCache(&BloomConfig{ |
| 21 | CacheMaxBlockAge: time.Hour, |
| 22 | CacheMinCompactionLevel: 1, |
| 23 | }, nil, nil, test.NewMockProvider(), log.NewNopLogger()) |
| 24 | require.NoError(t, err) |
| 25 | |
| 26 | rw := reader.(*readerWriter) |
| 27 | |
| 28 | // test.MockProvider will return the same cache for all requests. we need |
| 29 | // to override individual caches so that the test can validate the cache returned |
| 30 | rw.footerCache = test.NewMockClient() |
| 31 | rw.columnIdxCache = test.NewMockClient() |
| 32 | rw.offsetIdxCache = test.NewMockClient() |
| 33 | rw.traceIDIdxCache = test.NewMockClient() |
| 34 | rw.bloomCache = test.NewMockClient() |
| 35 | |
| 36 | testCases := []struct { |
| 37 | name string |
| 38 | cacheInfo *backend.CacheInfo |
| 39 | expectedCache cache.Cache |
| 40 | }{ |
| 41 | // first three caches are unconditionally returned |
| 42 | { |
| 43 | name: "footer is always returned", |
| 44 | cacheInfo: &backend.CacheInfo{Role: cache.RoleParquetFooter}, |
| 45 | expectedCache: rw.footerCache, |
| 46 | }, |
| 47 | { |
| 48 | name: "col idx is always returned", |
| 49 | cacheInfo: &backend.CacheInfo{Role: cache.RoleParquetColumnIdx}, |
| 50 | expectedCache: rw.columnIdxCache, |
| 51 | }, |
| 52 | { |
| 53 | name: "offset idx is always returned", |
| 54 | cacheInfo: &backend.CacheInfo{Role: cache.RoleParquetOffsetIdx}, |
| 55 | expectedCache: rw.offsetIdxCache, |
| 56 | }, |
| 57 | { |
| 58 | name: "trace id idx is always returned", |
| 59 | cacheInfo: &backend.CacheInfo{Role: cache.RoleTraceIDIdx}, |
| 60 | expectedCache: rw.traceIDIdxCache, |
| 61 | }, |
| 62 | // bloom cache is returned if the meta is valid given the bloom config |
| 63 | { |
| 64 | name: "bloom - no meta means no cache", |
| 65 | cacheInfo: &backend.CacheInfo{ |
| 66 | Role: cache.RoleBloom, |
| 67 | }, |
| 68 | }, |
| 69 | { |
| 70 | name: "bloom - compaction lvl and start time valid", |
| 71 | cacheInfo: &backend.CacheInfo{ |
| 72 | Role: cache.RoleBloom, |
| 73 | Meta: &backend.BlockMeta{CompactionLevel: 1, StartTime: time.Now()}, |
| 74 | }, |
| 75 | expectedCache: rw.bloomCache, |
| 76 | }, |
nothing calls this directly
no test coverage detected