MCPcopy
hub / github.com/prometheus/prometheus / TestBufferedSeriesIterator

Function TestBufferedSeriesIterator

storage/buffer_test.go:231–299  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

229}
230
231func TestBufferedSeriesIterator(t *testing.T) {
232 var it *BufferedSeriesIterator
233
234 bufferEq := func(exp []fSample) {
235 var b []fSample
236 bit := it.Buffer()
237 for bit.Next() == chunkenc.ValFloat {
238 t, f := bit.At()
239 st := bit.AtST()
240 b = append(b, fSample{st: st, t: t, f: f})
241 }
242 require.Equal(t, exp, b, "buffer mismatch")
243 }
244 sampleEq := func(est, ets int64, ev float64) {
245 ts, v := it.At()
246 st := it.AtST()
247 require.Equal(t, est, st, "start timestamp mismatch")
248 require.Equal(t, ets, ts, "timestamp mismatch")
249 require.Equal(t, ev, v, "value mismatch")
250 }
251 prevSampleEq := func(est, ets int64, ev float64, eok bool) {
252 s, ok := it.PeekBack(1)
253 require.Equal(t, eok, ok, "exist mismatch")
254 require.Equal(t, est, s.ST(), "start timestamp mismatch")
255 require.Equal(t, ets, s.T(), "timestamp mismatch")
256 require.Equal(t, ev, s.F(), "value mismatch")
257 }
258
259 it = NewBufferIterator(NewListSeriesIterator(samples{
260 fSample{st: -1, t: 1, f: 2},
261 fSample{st: 1, t: 2, f: 3},
262 fSample{st: 2, t: 3, f: 4},
263 fSample{st: 3, t: 4, f: 5},
264 fSample{st: 3, t: 5, f: 6},
265 fSample{st: 50, t: 99, f: 8},
266 fSample{st: 99, t: 100, f: 9},
267 fSample{st: 100, t: 101, f: 10},
268 }), 2)
269
270 require.Equal(t, chunkenc.ValFloat, it.Seek(-123), "seek failed")
271 sampleEq(-1, 1, 2)
272 prevSampleEq(0, 0, 0, false)
273 bufferEq(nil)
274
275 require.Equal(t, chunkenc.ValFloat, it.Next(), "next failed")
276 sampleEq(1, 2, 3)
277 prevSampleEq(-1, 1, 2, true)
278 bufferEq([]fSample{{st: -1, t: 1, f: 2}})
279
280 require.Equal(t, chunkenc.ValFloat, it.Next(), "next failed")
281 require.Equal(t, chunkenc.ValFloat, it.Next(), "next failed")
282 require.Equal(t, chunkenc.ValFloat, it.Next(), "next failed")
283 sampleEq(3, 5, 6)
284 prevSampleEq(3, 4, 5, true)
285 bufferEq([]fSample{{st: 1, t: 2, f: 3}, {st: 2, t: 3, f: 4}, {st: 3, t: 4, f: 5}})
286
287 require.Equal(t, chunkenc.ValFloat, it.Seek(5), "seek failed")
288 sampleEq(3, 5, 6)

Callers

nothing calls this directly

Calls 14

BufferMethod · 0.95
AtMethod · 0.95
AtSTMethod · 0.95
PeekBackMethod · 0.95
SeekMethod · 0.95
NextMethod · 0.95
NewBufferIteratorFunction · 0.85
NewListSeriesIteratorFunction · 0.85
NextMethod · 0.65
AtMethod · 0.65
AtSTMethod · 0.65
STMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…