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

Function TestCreateBlockBoundaries

pkg/blockboundary/blockboundary_test.go:12–79  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestCreateBlockBoundaries(t *testing.T) {
13 tests := []struct {
14 name string
15 queryShards int
16 expected [][]byte
17 }{
18 {
19 name: "single shard",
20 queryShards: 1,
21 expected: [][]byte{
22 {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
23 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
24 },
25 },
26 {
27 name: "multiple shards",
28 queryShards: 4,
29 expected: [][]byte{
30 {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
31 {0x40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
32 {0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
33 {0xc0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
34 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
35 },
36 },
37 {
38 name: "large number of evenly divisible shards",
39 queryShards: 255,
40 },
41 {
42 name: "large number of not evenly divisible shards",
43 queryShards: 1111,
44 },
45 }
46 for _, tt := range tests {
47 t.Run(tt.name, func(t *testing.T) {
48 bb := CreateBlockBoundaries(tt.queryShards)
49
50 if len(tt.expected) > 0 {
51 require.Len(t, bb, len(tt.expected))
52 for i := 0; i < len(bb); i++ {
53 require.Equal(t, tt.expected[i], bb[i])
54 }
55 }
56
57 maxDist := uint64(0)
58 minDist := uint64(math.MaxUint64)
59
60 // test that the boundaries are in order
61 for i := 1; i < len(bb); i++ {
62 require.True(t, bytes.Compare(bb[i-1], bb[i]) < 0)
63
64 prev := binary.BigEndian.Uint64(bb[i-1][:8])
65 cur := binary.BigEndian.Uint64(bb[i][:8])
66 dist := cur - prev
67 if dist > maxDist {
68 maxDist = dist
69 }

Callers

nothing calls this directly

Calls 5

CreateBlockBoundariesFunction · 0.85
LenMethod · 0.65
RunMethod · 0.45
EqualMethod · 0.45
CompareMethod · 0.45

Tested by

no test coverage detected