Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
black-adder committed Jan 28, 2019
1 parent 29434dd commit eec5c24
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 25 deletions.
3 changes: 2 additions & 1 deletion integration/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ database:
high: 1.0
`

testData1 = `{"service":"testNamespace","@timestamp":"2019-01-22T13:25:42-08:00","st":true,"sid":1,"tt":"active","tz":-6,"v":1.5}
testData1 = `
{"service":"testNamespace","@timestamp":"2019-01-22T13:25:42-08:00","st":true,"sid":1,"tt":"active","tz":-6,"v":1.5}
{"service":"testNamespace","@timestamp":"2019-01-22T13:26:42-08:00","st":true,"sid":1,"tt":"active","tz":-6,"v":1.5}
{"service":"testNamespace","@timestamp":"2019-01-22T13:27:42-08:00","st":true,"sid":1,"tt":"active","tz":-6,"v":1.5}
{"service":"testNamespace","@timestamp":"2019-01-22T13:28:42-08:00","st":true,"sid":1,"tt":"active","tz":-6,"v":1.5}
Expand Down
5 changes: 3 additions & 2 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package integration

import (
"strings"
"testing"
"time"

Expand Down Expand Up @@ -48,12 +49,12 @@ func TestRawQueryOrderBy(t *testing.T) {
expectedResults: 10,
},
}
ts := newTestServerSetup(t, testConfig1, testData1)
ts := newTestServerSetup(t, testConfig1)
ts.startServer()
defer ts.close(t)
ts.writeTestFixture(t)
client := ts.newClient()
require.NoError(t, ts.waitUntil(10*time.Second, client.serverIsHealthy))
require.NoError(t, client.write([]byte(strings.TrimSpace(testData1))))

for _, test := range tests {
resp, err := client.query([]byte(test.queryJSON))
Expand Down
21 changes: 7 additions & 14 deletions integration/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/m3db/m3x/log"
"github.com/stretchr/testify/require"
"github.com/uber-go/tally"
validator "gopkg.in/validator.v2"
yaml "gopkg.in/yaml.v2"
)

Expand All @@ -24,17 +25,16 @@ var (
)

type testServerSetup struct {
db storage.Database
opts instrument.Options
cfg configuration
testData string
db storage.Database
opts instrument.Options
cfg configuration

// Signals.
doneCh chan struct{}
closedCh chan struct{}
}

func newTestServerSetup(t *testing.T, config, testData string) *testServerSetup {
func newTestServerSetup(t *testing.T, config string) *testServerSetup {
cfg := loadConfig(t, config)

iOpts := instrument.NewOptions().
Expand All @@ -57,7 +57,6 @@ func newTestServerSetup(t *testing.T, config, testData string) *testServerSetup
db: db,
opts: iOpts,
cfg: cfg,
testData: testData,
doneCh: make(chan struct{}),
closedCh: make(chan struct{}),
}
Expand Down Expand Up @@ -116,15 +115,9 @@ func (ts *testServerSetup) waitUntil(timeout time.Duration, condition func() boo
return nil
}

func (ts *testServerSetup) writeTestFixture(t *testing.T) {
client := ts.newClient()
require.NoError(t, ts.waitUntil(10*time.Second, client.serverIsHealthy))
require.NoError(t, client.write([]byte(ts.testData)))
}

func loadConfig(t *testing.T, config string) configuration {
var cfg configuration
err := yaml.UnmarshalStrict([]byte(config), &cfg)
require.NoError(t, err)
require.NoError(t, yaml.UnmarshalStrict([]byte(config), &cfg))
require.NoError(t, validator.Validate(&cfg))
return cfg
}
5 changes: 5 additions & 0 deletions query/raw_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ func (r *RawResults) MergeInPlace(other *RawResults) error {
if other.IsEmpty() {
return nil
}
if r.IsEmpty() {
*r = *other
other.Clear()
return nil
}
if !r.OrderByFieldTypes.Equal(other.OrderByFieldTypes) {
return fmt.Errorf("merging two raw results with different order by field types %v and %v", r.OrderByFieldTypes, other.OrderByFieldTypes)
}
Expand Down
10 changes: 3 additions & 7 deletions storage/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (n *dbNamespace) QueryRaw(
q.StartNanosInclusive = retentionStartNanos
}

var res *query.RawResults
res := q.NewRawResults()
shards := n.getOwnedShards()
for _, shard := range shards {
// NB(xichen): We could pass `res` to each shard-level query but this
Expand All @@ -129,12 +129,8 @@ func (n *dbNamespace) QueryRaw(
if err != nil {
return nil, err
}
if res == nil && !shardRes.IsEmpty() {
res = shardRes
} else {
if err := res.MergeInPlace(shardRes); err != nil {
return nil, err
}
if err := res.MergeInPlace(shardRes); err != nil {
return nil, err
}
if res.IsComplete() {
// We've got enough data, bail early.
Expand Down
2 changes: 1 addition & 1 deletion values/roundtriptest/doc.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package roundtriptest

// Without this file, this directory fails with 'no non-test Go files'
// Without this file, this directory fails with 'no non-test Go files'.

0 comments on commit eec5c24

Please sign in to comment.