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

Function testAppendBlockStartEnd

tempodb/wal/wal_test.go:39–86  ·  view source on GitHub ↗
(t *testing.T, e encoding.VersionedEncoding)

Source from the content-addressed store, hash-verified

37}
38
39func testAppendBlockStartEnd(t *testing.T, e encoding.VersionedEncoding) {
40 wal, err := New(&Config{
41 Filepath: t.TempDir(),
42 IngestionSlack: 3 * time.Minute,
43 Version: encoding.DefaultEncoding().Version(),
44 })
45 require.NoError(t, err, "unexpected error creating temp wal")
46
47 blockID := uuid.New()
48 meta := backend.NewBlockMeta("fake", blockID, e.Version())
49 block, err := wal.NewBlock(meta, model.CurrentEncoding)
50 require.NoError(t, err, "unexpected error creating block")
51
52 enc := model.MustNewSegmentDecoder(model.CurrentEncoding)
53
54 // create a new block and confirm start/end times are correct
55 blockStart := uint32(time.Now().Add(-time.Minute).Unix())
56 blockEnd := uint32(time.Now().Add(time.Minute).Unix())
57
58 for i := 0; i < 10; i++ {
59 id := make([]byte, 16)
60 _, err := crand.Read(id)
61 require.NoError(t, err)
62 obj := test.MakeTrace(rand.Int()%10+1, id)
63
64 b1, err := enc.PrepareForWrite(obj, blockStart, blockEnd)
65 require.NoError(t, err)
66
67 b2, err := enc.ToObject([][]byte{b1})
68 require.NoError(t, err)
69
70 err = block.Append(id, b2, blockStart, blockEnd, true)
71 require.NoError(t, err, "unexpected error writing req")
72 }
73
74 require.NoError(t, block.Flush())
75
76 require.Equal(t, blockStart, uint32(block.BlockMeta().StartTime.Unix()))
77 require.Equal(t, blockEnd, uint32(block.BlockMeta().EndTime.Unix()))
78
79 // rescan the block and make sure the start/end times are the same
80 blocks, err := wal.RescanBlocks(time.Hour, log.NewNopLogger())
81 require.NoError(t, err, "unexpected error getting blocks")
82 require.Len(t, blocks, 1)
83
84 require.Equal(t, blockStart, uint32(blocks[0].BlockMeta().StartTime.Unix()))
85 require.Equal(t, blockEnd, uint32(blocks[0].BlockMeta().EndTime.Unix()))
86}
87
88func TestIngestionSlack(t *testing.T) {
89 for _, e := range encoding.AllEncodingsForWrites() {

Callers 1

TestAppendBlockStartEndFunction · 0.85

Calls 15

BlockMetaMethod · 0.95
DefaultEncodingFunction · 0.92
NewBlockMetaFunction · 0.92
MustNewSegmentDecoderFunction · 0.92
MakeTraceFunction · 0.92
NewBlockMethod · 0.80
IntMethod · 0.80
RescanBlocksMethod · 0.80
NewFunction · 0.70
VersionMethod · 0.65
AddMethod · 0.65
NowMethod · 0.65

Tested by

no test coverage detected