Skip to content

Commit

Permalink
Add test case for BloomStore.FetchMetas()
Browse files Browse the repository at this point in the history
and fix incorrect empty response

Signed-off-by: Christian Haudum <[email protected]>
  • Loading branch information
chaudum committed Feb 5, 2024
1 parent 1acfe94 commit 5f211a0
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
6 changes: 4 additions & 2 deletions pkg/storage/stores/shipper/bloomshipper/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,15 @@ func (b *BloomStore) FetchMetas(ctx context.Context, params MetaSearchParams) ([
return nil, errors.New("metaRefs and fetchers have unequal length")
}

var metas []Meta
metas := []Meta{}
for i := range fetchers {
res, err := fetchers[i].FetchMetas(ctx, metaRefs[i])
if err != nil {
return nil, err
}
metas = append(metas, res...)
if len(res) > 0 {
metas = append(metas, res...)
}
}
return metas, nil
}
Expand Down
53 changes: 52 additions & 1 deletion pkg/storage/stores/shipper/bloomshipper/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,58 @@ func TestBloomStore_ResolveMetas(t *testing.T) {
})
}

func TestBloomStore_FetchMetas(t *testing.T) {}
func TestBloomStore_FetchMetas(t *testing.T) {
store, _ := newMockBloomStore(t)

// schema 1
// outside of interval, outside of bounds
_, _ = createMetaInStorage(store, "tenant", parseTime("2024-01-19 00:00"), 0x00010000, 0x0001ffff)
// outside of interval, inside of bounds
_, _ = createMetaInStorage(store, "tenant", parseTime("2024-01-19 00:00"), 0x00000000, 0x0000ffff)
// inside of interval, outside of bounds
_, _ = createMetaInStorage(store, "tenant", parseTime("2024-01-20 00:00"), 0x00010000, 0x0001ffff)
// inside of interval, inside of bounds
m1, _ := createMetaInStorage(store, "tenant", parseTime("2024-01-20 00:00"), 0x00000000, 0x0000ffff)

// schema 2
// inside of interval, inside of bounds
m2, _ := createMetaInStorage(store, "tenant", parseTime("2024-02-05 00:00"), 0x00000000, 0x0000ffff)
// inside of interval, outside of bounds
_, _ = createMetaInStorage(store, "tenant", parseTime("2024-02-05 00:00"), 0x00010000, 0x0001ffff)
// outside of interval, inside of bounds
_, _ = createMetaInStorage(store, "tenant", parseTime("2024-02-11 00:00"), 0x00000000, 0x0000ffff)
// outside of interval, outside of bounds
_, _ = createMetaInStorage(store, "tenant", parseTime("2024-02-11 00:00"), 0x00010000, 0x0001ffff)

t.Run("tenant matches", func(t *testing.T) {
ctx := context.Background()
params := MetaSearchParams{
"tenant",
NewInterval(parseTime("2024-01-20 00:00"), parseTime("2024-02-10 00:00")),
v1.NewBounds(0x00000000, 0x0000ffff),
}

metas, err := store.FetchMetas(ctx, params)
require.NoError(t, err)
require.Len(t, metas, 2)

require.Equal(t, []Meta{m1, m2}, metas)
})

t.Run("tenant does not match", func(t *testing.T) {
ctx := context.Background()
params := MetaSearchParams{
"other",
NewInterval(parseTime("2024-01-20 00:00"), parseTime("2024-02-10 00:00")),
v1.NewBounds(0x00000000, 0x0000ffff),
}

metas, err := store.FetchMetas(ctx, params)
require.NoError(t, err)
require.Len(t, metas, 0)
require.Equal(t, []Meta{}, metas)
})
}

func TestBloomStore_FetchBlocks(t *testing.T) {}

Expand Down

0 comments on commit 5f211a0

Please sign in to comment.