finally got some engine tests to pass
parent
258336d7f9
commit
31bfc03728
|
|
@ -39,7 +39,7 @@ func (checker *SeriesEqualsChecker) Check(params []interface{}, names []string)
|
|||
return false, "second parameter isn't a series"
|
||||
}
|
||||
|
||||
areEqual := checkEquality(p1, p2)
|
||||
areEqual := CheckEquality(p1, p2)
|
||||
if areEqual {
|
||||
return true, ""
|
||||
}
|
||||
|
|
@ -47,13 +47,13 @@ func (checker *SeriesEqualsChecker) Check(params []interface{}, names []string)
|
|||
return false, "series aren't equal"
|
||||
}
|
||||
|
||||
func checkEquality(s1, s2 []*protocol.Series) bool {
|
||||
func CheckEquality(s1, s2 []*protocol.Series) bool {
|
||||
if len(s1) != len(s2) {
|
||||
return false
|
||||
}
|
||||
|
||||
for idx, series := range s1 {
|
||||
if !checkSeriesEquality(series, s2[idx]) {
|
||||
if !CheckSeriesEquality(series, s2[idx]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
@ -65,7 +65,7 @@ func checkEquality(s1, s2 []*protocol.Series) bool {
|
|||
// points with the same timestamp. Two points can have the same
|
||||
// sequence number if the user issue a query with group by time(1h)
|
||||
// and some_column.
|
||||
func checkSeriesEquality(s1, s2 *protocol.Series) bool {
|
||||
func CheckSeriesEquality(s1, s2 *protocol.Series) bool {
|
||||
if len(s1.Points) != len(s2.Points) {
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -131,6 +131,8 @@ func ConvertToDataStoreSeries(s *SerializedSeries, precision TimePrecision) (*pr
|
|||
return series, nil
|
||||
}
|
||||
|
||||
// takes a slice of protobuf series and convert them to the format
|
||||
// that the http api expect
|
||||
func SerializeSeries(memSeries map[string]*protocol.Series, precision TimePrecision) []*SerializedSeries {
|
||||
serializedSeries := []*SerializedSeries{}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"protocol"
|
||||
"reflect"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
@ -43,13 +42,14 @@ func (self *EngineSuite) TearDownSuite(c *C) {
|
|||
}
|
||||
|
||||
func (self *EngineSuite) createEngine(c *C, seriesString string) {
|
||||
seriesString = convertToDataStoreSeries(seriesString, c)
|
||||
seriesString = convertFromDataStoreSeries(seriesString, c)
|
||||
fmt.Printf("new series string: %s\n", seriesString)
|
||||
resp := self.server.Post("/db/test_db/series?u=user&p=pass", seriesString, c)
|
||||
c.Assert(resp.StatusCode, Equals, http.StatusOK)
|
||||
}
|
||||
|
||||
func convertToDataStoreSeries(seriesString string, c *C) string {
|
||||
// convert from data store internal series format to the api format
|
||||
func convertFromDataStoreSeries(seriesString string, c *C) string {
|
||||
series := []*protocol.Series{}
|
||||
c.Assert(json.Unmarshal([]byte(seriesString), &series), IsNil)
|
||||
apiSeries := []*SerializedSeries{}
|
||||
|
|
@ -69,23 +69,27 @@ func convertToDataStoreSeries(seriesString string, c *C) string {
|
|||
// expectedSeries must be a json array, e.g. time series must by
|
||||
// enclosed in '[' and ']'
|
||||
func (self *EngineSuite) runQuery(query string, c *C, expectedSeries string) {
|
||||
series, err := StringToSeriesArray(expectedSeries)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
result := self.server.QueryWithUsername("test_db", query, false, c, "user", "pass")
|
||||
var expected []*protocol.Series
|
||||
err := json.Unmarshal([]byte(expectedSeries), &expected)
|
||||
c.Assert(err, IsNil)
|
||||
actual := []*protocol.Series{}
|
||||
for _, s := range result.Members {
|
||||
dataStoreS, err := ConvertToDataStoreSeries(s, MillisecondPrecision)
|
||||
c.Assert(err, IsNil)
|
||||
actual = append(actual, dataStoreS)
|
||||
}
|
||||
|
||||
fmt.Printf("result: %s\n", result)
|
||||
|
||||
if !reflect.DeepEqual(result.Members[0], series) {
|
||||
resultData, _ := json.MarshalIndent(result, "", " ")
|
||||
seriesData, _ := json.MarshalIndent(series, "", " ")
|
||||
if !CheckEquality(actual, expected) {
|
||||
actualString, _ := json.MarshalIndent(actual, "", " ")
|
||||
expectedString, _ := json.MarshalIndent(expected, "", " ")
|
||||
|
||||
fmt.Fprintf(os.Stderr,
|
||||
"===============\nThe two series aren't equal.\nExpected: %s\nActual: %s\n===============\n",
|
||||
seriesData, resultData)
|
||||
expectedString, actualString)
|
||||
}
|
||||
|
||||
c.Assert(result, SeriesEquals, series)
|
||||
c.Assert(actual, SeriesEquals, expected)
|
||||
}
|
||||
|
||||
func (self *EngineSuite) TestBasicQuery(c *C) {
|
||||
|
|
@ -1239,8 +1243,8 @@ func (self *EngineSuite) TestStddevQuery(c *C) {
|
|||
c.Assert(result[0].Name, Equals, "foo")
|
||||
c.Assert(result[0].Columns, DeepEquals, []string{"stddev"})
|
||||
c.Assert(result[0].Points, HasLen, 2)
|
||||
c.Assert(result[0].Points[0].Values[0], InRange, 0.4714, 0.4715)
|
||||
c.Assert(result[0].Points[1].Values[1], InRange, 0.9999, 1.0001)
|
||||
c.Assert(result[0].Points[0][0], InRange, 0.4714, 0.4715)
|
||||
c.Assert(result[0].Points[1][1], InRange, 0.9999, 1.0001)
|
||||
}
|
||||
|
||||
func (self *EngineSuite) TestDerivativeQuery(c *C) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package integration
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"common"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
|
@ -70,35 +71,18 @@ func (self *ServerProcess) Stop() {
|
|||
self.p = nil
|
||||
}
|
||||
|
||||
func ResultsToSeriesCollection(results []interface{}) *SeriesCollection {
|
||||
collection := &SeriesCollection{Members: make([]*Series, 0)}
|
||||
for _, result := range results {
|
||||
seriesResult := result.(map[string]interface{})
|
||||
series := &Series{}
|
||||
series.Name = seriesResult["name"].(string)
|
||||
columns := seriesResult["columns"].([]interface{})
|
||||
series.Columns = make([]string, 0)
|
||||
for _, col := range columns {
|
||||
series.Columns = append(series.Columns, col.(string))
|
||||
}
|
||||
points := seriesResult["points"].([]interface{})
|
||||
series.Points = make([]*Point, 0)
|
||||
for _, point := range points {
|
||||
series.Points = append(series.Points, &Point{Values: point.([]interface{})})
|
||||
}
|
||||
collection.Members = append(collection.Members, series)
|
||||
}
|
||||
return collection
|
||||
func ResultsToSeriesCollection(results []*common.SerializedSeries) *SeriesCollection {
|
||||
return &SeriesCollection{Members: results}
|
||||
}
|
||||
|
||||
type SeriesCollection struct {
|
||||
Members []*Series
|
||||
Members []*common.SerializedSeries
|
||||
}
|
||||
|
||||
func (self *SeriesCollection) GetSeries(name string, c *C) *Series {
|
||||
for _, s := range self.Members {
|
||||
if s.Name == name {
|
||||
return s
|
||||
return &Series{s}
|
||||
}
|
||||
}
|
||||
c.Fatalf("Couldn't find series '%s' in:\n", name, self)
|
||||
|
|
@ -106,9 +90,7 @@ func (self *SeriesCollection) GetSeries(name string, c *C) *Series {
|
|||
}
|
||||
|
||||
type Series struct {
|
||||
Name string
|
||||
Columns []string
|
||||
Points []*Point
|
||||
*common.SerializedSeries
|
||||
}
|
||||
|
||||
func (self *Series) GetValueForPointAndColumn(pointIndex int, columnName string, c *C) interface{} {
|
||||
|
|
@ -125,7 +107,7 @@ func (self *Series) GetValueForPointAndColumn(pointIndex int, columnName string,
|
|||
if pointIndex > len(self.Points)-1 {
|
||||
c.Errorf("Fewer than %d points in series '%s':\n", pointIndex+1, self.Name, self)
|
||||
}
|
||||
return self.Points[pointIndex].Values[columnIndex]
|
||||
return self.Points[pointIndex][columnIndex]
|
||||
}
|
||||
|
||||
type Point struct {
|
||||
|
|
@ -152,7 +134,7 @@ func (self *ServerProcess) QueryWithUsername(database, query string, onlyLocal b
|
|||
c.Assert(resp.StatusCode, Equals, http.StatusOK)
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
c.Assert(err, IsNil)
|
||||
var js []interface{}
|
||||
var js []*common.SerializedSeries
|
||||
err = json.Unmarshal(body, &js)
|
||||
if err != nil {
|
||||
fmt.Println("NOT JSON: ", string(body))
|
||||
|
|
@ -473,7 +455,7 @@ func (self *ServerSuite) TestSslSupport(c *C) {
|
|||
c.Assert(resp.StatusCode, Equals, http.StatusOK)
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
c.Assert(err, IsNil)
|
||||
var js []interface{}
|
||||
var js []*common.SerializedSeries
|
||||
err = json.Unmarshal(body, &js)
|
||||
c.Assert(err, IsNil)
|
||||
collection := ResultsToSeriesCollection(js)
|
||||
|
|
|
|||
Loading…
Reference in New Issue