Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[integration] Expose TestIndexWrite methods #2956

Merged
merged 2 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dbnode/integration/disk_coldflush_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestDiskColdFlushSimple(t *testing.T) {
// Test setup with cold-writes-enabled namespace.
nsOpts := namespace.NewOptions().
SetRepairEnabled(false).
SetRetentionOptions(defaultIntegrationTestRetentionOpts.
SetRetentionOptions(DefaultIntegrationTestRetentionOpts.
SetRetentionPeriod(12 * time.Hour)).
SetColdWritesEnabled(true)
nsID := ident.StringID("testColdWriteNs1")
Expand Down
47 changes: 27 additions & 20 deletions src/dbnode/integration/index_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ import (
)

// TestIndexWrites holds index writes for testing.
type TestIndexWrites []testIndexWrite
type TestIndexWrites []TestIndexWrite

// MatchesSeriesIters matches index writes with expected series.
func (w TestIndexWrites) MatchesSeriesIters(t *testing.T, seriesIters encoding.SeriesIterators) {
writesByID := make(map[string]TestIndexWrites)
for _, wi := range w {
writesByID[wi.id.String()] = append(writesByID[wi.id.String()], wi)
writesByID[wi.id.String()] = append(writesByID[wi.ID.String()], wi)
}
require.Equal(t, len(writesByID), seriesIters.Len())
iters := seriesIters.Iters()
Expand All @@ -68,10 +68,10 @@ func (w TestIndexWrites) matchesSeriesIter(t *testing.T, iter encoding.SeriesIte
continue
}
wi := w[i]
if !ident.NewTagIterMatcher(wi.tags.Duplicate()).Matches(iter.Tags().Duplicate()) {
if !ident.NewTagIterMatcher(wi.Tags.Duplicate()).Matches(iter.Tags().Duplicate()) {
require.FailNow(t, "tags don't match provided id", iter.ID().String())
}
if dp.Timestamp.Equal(wi.ts) && dp.Value == wi.value {
if dp.Timestamp.Equal(wi.Timestamp) && dp.Value == wi.Value {
found[i] = true
break
}
Expand All @@ -88,7 +88,14 @@ func (w TestIndexWrites) matchesSeriesIter(t *testing.T, iter encoding.SeriesIte
func (w TestIndexWrites) Write(t *testing.T, ns ident.ID, s client.Session) {
for i := 0; i < len(w); i++ {
wi := w[i]
require.NoError(t, s.WriteTagged(ns, wi.id, wi.tags.Duplicate(), wi.ts, wi.value, xtime.Second, nil), "%v", wi)
require.NoError(t, s.WriteTagged(ns,
wi.ID,
wi.Tags.Duplicate(),
wi.Timestamp,
wi.Value,
xtime.Second,
nil,
), "%v", wi)
}
}

Expand All @@ -97,10 +104,10 @@ func (w TestIndexWrites) NumIndexed(t *testing.T, ns ident.ID, s client.Session)
numFound := 0
for i := 0; i < len(w); i++ {
wi := w[i]
q := newQuery(t, wi.tags)
q := newQuery(t, wi.Tags)
iter, _, err := s.FetchTaggedIDs(ns, index.Query{Query: q}, index.QueryOptions{
StartInclusive: wi.ts.Add(-1 * time.Second),
EndExclusive: wi.ts.Add(1 * time.Second),
StartInclusive: wi.Timestamp.Add(-1 * time.Second),
EndExclusive: wi.Timestamp.Add(1 * time.Second),
SeriesLimit: 10})
if err != nil {
continue
Expand All @@ -112,35 +119,35 @@ func (w TestIndexWrites) NumIndexed(t *testing.T, ns ident.ID, s client.Session)
if ns.String() != cuNs.String() {
continue
}
if wi.id.String() != cuID.String() {
if wi.ID.String() != cuID.String() {
continue
}
if !ident.NewTagIterMatcher(wi.tags).Matches(cuTag) {
if !ident.NewTagIterMatcher(wi.Tags).Matches(cuTag) {
continue
}
numFound++
}
return numFound
}

type testIndexWrite struct {
id ident.ID
tags ident.TagIterator
ts time.Time
value float64
type TestIndexWrite struct {
ID ident.ID
Tags ident.TagIterator
Timestamp time.Time
Value float64
}

// GenerateTestIndexWrite generates test index writes.
func GenerateTestIndexWrite(periodID, numWrites, numTags int, startTime, endTime time.Time) TestIndexWrites {
writes := make([]testIndexWrite, 0, numWrites)
writes := make([]TestIndexWrite, 0, numWrites)
step := endTime.Sub(startTime) / time.Duration(numWrites+1)
for i := 0; i < numWrites; i++ {
id, tags := genIDTags(periodID, i, numTags)
writes = append(writes, testIndexWrite{
id: id,
tags: tags,
ts: startTime.Add(time.Duration(i) * step).Truncate(time.Second),
value: float64(i),
ID: id,
Tags: tags,
Timestamp: startTime.Add(time.Duration(i) * step).Truncate(time.Second),
Value: float64(i),
})
}
return writes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func testIndexSingleNodeHighConcurrency(
// Test setup
md, err := namespace.NewMetadata(testNamespaces[0],
namespace.NewOptions().
SetRetentionOptions(defaultIntegrationTestRetentionOpts).
SetRetentionOptions(DefaultIntegrationTestRetentionOpts).
SetCleanupEnabled(false).
SetSnapshotEnabled(false).
SetFlushEnabled(false).
Expand Down
5 changes: 3 additions & 2 deletions src/dbnode/integration/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ const (
)

var (
defaultIntegrationTestRetentionOpts = retention.NewOptions().SetRetentionPeriod(6 * time.Hour)
// DefaultIntegrationTestRetentionOpts are default integration test retention options.
DefaultIntegrationTestRetentionOpts = retention.NewOptions().SetRetentionPeriod(6 * time.Hour)
)

// TestOptions contains integration test options.
Expand Down Expand Up @@ -333,7 +334,7 @@ func NewTestOptions(t *testing.T) TestOptions {
var namespaces []namespace.Metadata
nsOpts := namespace.NewOptions().
SetRepairEnabled(false).
SetRetentionOptions(defaultIntegrationTestRetentionOpts)
SetRetentionOptions(DefaultIntegrationTestRetentionOpts)

for _, ns := range testNamespaces {
md, err := namespace.NewMetadata(ns, nsOpts)
Expand Down
12 changes: 6 additions & 6 deletions src/dbnode/integration/wide_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func TestWideFetch(t *testing.T) {
nsOpts := namespace.NewOptions().
SetIndexOptions(idxOpts).
SetRepairEnabled(false).
SetRetentionOptions(defaultIntegrationTestRetentionOpts)
SetRetentionOptions(DefaultIntegrationTestRetentionOpts)

nsID := testNamespaces[0]
nsMetadata, err := namespace.NewMetadata(nsID, nsOpts)
Expand Down Expand Up @@ -212,11 +212,11 @@ func TestWideFetch(t *testing.T) {
for i := 0; i < seriesCount; i++ {
id := fmt.Sprintf("id-%05d", i)
ids = append(ids, id)
indexWrites = append(indexWrites, testIndexWrite{
id: ident.StringID(id),
tags: ident.MustNewTagStringsIterator(wideTagName, fmt.Sprintf(wideTagValFmt, i)),
ts: now,
value: float64(i),
indexWrites = append(indexWrites, TestIndexWrite{
ID: ident.StringID(id),
Tags: ident.MustNewTagStringsIterator(wideTagName, fmt.Sprintf(wideTagValFmt, i)),
Timestamp: now,
Value: float64(i),
})
}

Expand Down