Incorporate feedback on #36

Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
This commit is contained in:
Goutham Veeramachaneni 2017-04-22 01:38:26 +05:30
parent 239f8b9eb5
commit 725b69caa1
No known key found for this signature in database
GPG key ID: F1C217E8E9023CAD
3 changed files with 118 additions and 111 deletions

View file

@ -1,8 +1,7 @@
package tsdb package tsdb
import ( import (
"errors" "github.com/pkg/errors"
"github.com/prometheus/tsdb/chunks" "github.com/prometheus/tsdb/chunks"
) )

View file

@ -138,7 +138,7 @@ func TestMultiMerge(t *testing.T) {
} }
} }
func TestMerge(t *testing.T) { func TestMergedPostings(t *testing.T) {
var cases = []struct { var cases = []struct {
a, b []uint32 a, b []uint32
res []uint32 res []uint32
@ -169,72 +169,73 @@ func TestMerge(t *testing.T) {
require.Equal(t, c.res, res) require.Equal(t, c.res, res)
} }
t.Run("Seek", func(t *testing.T) { }
var cases = []struct {
a, b []uint32
seek uint32 func TestMergedPostingsSeek(t *testing.T) {
success bool var cases = []struct {
res []uint32 a, b []uint32
}{
{
a: []uint32{1, 2, 3, 4, 5},
b: []uint32{6, 7, 8, 9, 10},
seek: 0, seek uint32
success: true, success bool
res: []uint32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, res []uint32
}, }{
{ {
a: []uint32{1, 2, 3, 4, 5}, a: []uint32{1, 2, 3, 4, 5},
b: []uint32{6, 7, 8, 9, 10}, b: []uint32{6, 7, 8, 9, 10},
seek: 2, seek: 0,
success: true, success: true,
res: []uint32{2, 3, 4, 5, 6, 7, 8, 9, 10}, res: []uint32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
}, },
{ {
a: []uint32{1, 2, 3, 4, 5}, a: []uint32{1, 2, 3, 4, 5},
b: []uint32{4, 5, 6, 7, 8}, b: []uint32{6, 7, 8, 9, 10},
seek: 9, seek: 2,
success: false, success: true,
res: nil, res: []uint32{2, 3, 4, 5, 6, 7, 8, 9, 10},
}, },
{ {
a: []uint32{1, 2, 3, 4, 9, 10}, a: []uint32{1, 2, 3, 4, 5},
b: []uint32{1, 4, 5, 6, 7, 8, 10, 11}, b: []uint32{4, 5, 6, 7, 8},
seek: 10, seek: 9,
success: true, success: false,
res: []uint32{10, 11}, res: nil,
}, },
} {
a: []uint32{1, 2, 3, 4, 9, 10},
b: []uint32{1, 4, 5, 6, 7, 8, 10, 11},
for _, c := range cases { seek: 10,
a := newListPostings(c.a) success: true,
b := newListPostings(c.b) res: []uint32{10, 11},
},
}
p := newMergedPostings(a, b) for _, c := range cases {
a := newListPostings(c.a)
b := newListPostings(c.b)
require.Equal(t, c.success, p.Seek(c.seek)) p := newMergedPostings(a, b)
if c.success { require.Equal(t, c.success, p.Seek(c.seek))
// check the current element and then proceed to check the rest.
i := 0
require.Equal(t, c.res[i], p.At())
for p.Next() { if c.success {
i++ // check the current element and then proceed to check the rest.
require.Equal(t, int(c.res[i]), int(p.At())) i := 0
} require.Equal(t, c.res[i], p.At())
require.Equal(t, len(c.res)-1, i) for p.Next() {
i++
require.Equal(t, int(c.res[i]), int(p.At()))
} }
}
return require.Equal(t, len(c.res)-1, i)
}) }
}
return
} }
func TestBigEndian(t *testing.T) { func TestBigEndian(t *testing.T) {

View file

@ -261,12 +261,26 @@ func TestBlockQuerier(t *testing.T) {
} }
} }
// Build the querier on data first. Then execute queries on it. type query struct {
basedata := [][]struct { dataIdx int
lset map[string]string
chunks [][]sample mint, maxt int64
ms []labels.Matcher
exp SeriesSet
}
cases := struct {
data []struct {
lset map[string]string
chunks [][]sample
}
queries []query
}{ }{
{ data: []struct {
lset map[string]string
chunks [][]sample
}{
{ {
lset: map[string]string{ lset: map[string]string{
"a": "a", "a": "a",
@ -308,65 +322,58 @@ func TestBlockQuerier(t *testing.T) {
}, },
}, },
}, },
}
cases := []struct { queries: []query{
dataIdx int {
dataIdx: 0,
mint, maxt int64 mint: 0,
ms []labels.Matcher maxt: 0,
exp SeriesSet ms: []labels.Matcher{},
}{ exp: newListSeriesSet([]Series{}),
{ },
dataIdx: 0, {
dataIdx: 0,
mint: 0, mint: 0,
maxt: 0, maxt: 0,
ms: []labels.Matcher{}, ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")},
exp: newListSeriesSet([]Series{}), exp: newListSeriesSet([]Series{}),
}, },
{ {
dataIdx: 0, dataIdx: 0,
mint: 0, mint: 1,
maxt: 0, maxt: 0,
ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")}, ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")},
exp: newListSeriesSet([]Series{}), exp: newListSeriesSet([]Series{}),
}, },
{ {
dataIdx: 0, dataIdx: 0,
mint: 1, mint: 2,
maxt: 0, maxt: 6,
ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")}, ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")},
exp: newListSeriesSet([]Series{}), exp: newListSeriesSet([]Series{
}, newSeries(map[string]string{
{ "a": "a",
dataIdx: 0, },
[]sample{{2, 3}, {3, 4}, {5, 2}, {6, 3}},
mint: 2, ),
maxt: 6, newSeries(map[string]string{
ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")}, "a": "a",
exp: newListSeriesSet([]Series{ "b": "b",
newSeries(map[string]string{ },
"a": "a", []sample{{2, 2}, {3, 3}, {5, 3}, {6, 6}},
}, ),
[]sample{{2, 3}, {3, 4}, {5, 2}, {6, 3}}, }),
), },
newSeries(map[string]string{
"a": "a",
"b": "b",
},
[]sample{{2, 2}, {3, 3}, {5, 3}, {6, 6}},
),
}),
}, },
} }
Outer: Outer:
for _, c := range cases { for _, c := range cases.queries {
ir, cr := createIdxChkReaders(basedata[c.dataIdx]) ir, cr := createIdxChkReaders(cases.data)
querier := &blockQuerier{ querier := &blockQuerier{
index: ir, index: ir,
chunks: cr, chunks: cr,