From 7ebed0345c8b5b7ee80ff87fea0e236209438e67 Mon Sep 17 00:00:00 2001 From: Ryan Allen Date: Fri, 27 Nov 2020 13:38:51 -0500 Subject: [PATCH] [integration] Expose TestIndexWrite methods (#2956) --- src/dbnode/integration/disk_coldflush_test.go | 2 +- src/dbnode/integration/index_helpers.go | 49 +++++++++++-------- ...index_single_node_high_concurrency_test.go | 2 +- src/dbnode/integration/options.go | 5 +- src/dbnode/integration/wide_query_test.go | 12 ++--- 5 files changed, 39 insertions(+), 31 deletions(-) diff --git a/src/dbnode/integration/disk_coldflush_test.go b/src/dbnode/integration/disk_coldflush_test.go index 0ae350919a..8de59b8bd8 100644 --- a/src/dbnode/integration/disk_coldflush_test.go +++ b/src/dbnode/integration/disk_coldflush_test.go @@ -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") diff --git a/src/dbnode/integration/index_helpers.go b/src/dbnode/integration/index_helpers.go index e66f380060..e5fe95e15e 100644 --- a/src/dbnode/integration/index_helpers.go +++ b/src/dbnode/integration/index_helpers.go @@ -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() @@ -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 } @@ -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) } } @@ -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 @@ -112,10 +119,10 @@ 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++ @@ -123,24 +130,24 @@ func (w TestIndexWrites) NumIndexed(t *testing.T, ns ident.ID, s client.Session) 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), + writes = append(writes, TestIndexWrite{ + ID: id, + Tags: tags, + Timestamp: startTime.Add(time.Duration(i) * step).Truncate(time.Second), + Value: float64(i), }) } return writes diff --git a/src/dbnode/integration/index_single_node_high_concurrency_test.go b/src/dbnode/integration/index_single_node_high_concurrency_test.go index 2480f28b02..684c2281a5 100644 --- a/src/dbnode/integration/index_single_node_high_concurrency_test.go +++ b/src/dbnode/integration/index_single_node_high_concurrency_test.go @@ -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). diff --git a/src/dbnode/integration/options.go b/src/dbnode/integration/options.go index 29e3ffbc1a..355b745c59 100644 --- a/src/dbnode/integration/options.go +++ b/src/dbnode/integration/options.go @@ -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. @@ -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) diff --git a/src/dbnode/integration/wide_query_test.go b/src/dbnode/integration/wide_query_test.go index 17192d9841..3719432847 100644 --- a/src/dbnode/integration/wide_query_test.go +++ b/src/dbnode/integration/wide_query_test.go @@ -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) @@ -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), }) }