commit
a22f1043a2
|
@ -225,8 +225,8 @@ func runTests_Errors(t *testing.T, nodes Cluster) {
|
|||
}
|
||||
}
|
||||
|
||||
// runTests tests write and query of data.
|
||||
func runTestsData(t *testing.T, testName string, nodes Cluster, database, retention string) {
|
||||
// runTests tests write and query of data. Setting testNumbers allows only a subset of tests to be run.
|
||||
func runTestsData(t *testing.T, testName string, nodes Cluster, database, retention string, testNums ...int) {
|
||||
t.Logf("Running tests against %d-node cluster", len(nodes))
|
||||
|
||||
// Start by ensuring database and retention policy exist.
|
||||
|
@ -267,6 +267,65 @@ func runTestsData(t *testing.T, testName string, nodes Cluster, database, retent
|
|||
expected: `{"results":[{"error":"field not found: abc"}]}`,
|
||||
},
|
||||
|
||||
// WHERE fields queries
|
||||
{
|
||||
reset: true,
|
||||
name: "WHERE fields",
|
||||
write: `{"database" : "%DB%", "retentionPolicy" : "%RP%", "points": [{"name": "cpu", "timestamp": "2015-02-28T01:03:36.703820946Z", "fields": {"alert_id": "alert", "tenant_id": "tenant"}}]}`,
|
||||
query: `SELECT alert_id FROM "%DB%"."%RP%".cpu WHERE alert_id='alert'`,
|
||||
expected: `{"results":[{"series":[{"name":"cpu","columns":["time","alert_id"],"values":[["2015-02-28T01:03:36.703820946Z","alert"]]}]}]}`,
|
||||
},
|
||||
{
|
||||
name: "WHERE fields with AND query, all fields in SELECT",
|
||||
write: `{"database" : "%DB%", "retentionPolicy" : "%RP%", "points": [{"name": "cpu", "timestamp": "2015-02-28T01:03:36.703820946Z", "fields": {"alert_id": "alert", "tenant_id": "tenant"}}]}`,
|
||||
query: `SELECT alert_id,tenant_id FROM "%DB%"."%RP%".cpu WHERE alert_id='alert' AND tenant_id='tenant'`,
|
||||
expected: `{"results":[{"series":[{"name":"cpu","columns":["time","alert_id","tenant_id"],"values":[["2015-02-28T01:03:36.703820946Z","alert","tenant"]]}]}]}`,
|
||||
},
|
||||
{
|
||||
write: `{"database" : "%DB%", "retentionPolicy" : "%RP%", "points": [{"name": "cpu", "timestamp": "2009-11-10T23:00:02Z", "fields": {"load": 100}},
|
||||
{"name": "cpu", "timestamp": "2009-11-10T23:01:02Z", "fields": {"load": 80}}]}`,
|
||||
query: `select load from "%DB%"."%RP%".cpu where load > 100`,
|
||||
expected: `{"results":[{}]}`,
|
||||
},
|
||||
{
|
||||
query: `select load from "%DB%"."%RP%".cpu where load >= 100`,
|
||||
expected: `{"results":[{"series":[{"name":"cpu","columns":["time","load"],"values":[["2009-11-10T23:00:02Z",100]]}]}]}`,
|
||||
},
|
||||
{
|
||||
query: `select load from "%DB%"."%RP%".cpu where load = 100`,
|
||||
expected: `{"results":[{"series":[{"name":"cpu","columns":["time","load"],"values":[["2009-11-10T23:00:02Z",100]]}]}]}`,
|
||||
},
|
||||
{
|
||||
query: `select load from "%DB%"."%RP%".cpu where load <= 100`,
|
||||
expected: `{"results":[{"series":[{"name":"cpu","columns":["time","load"],"values":[["2009-11-10T23:00:02Z",100],["2009-11-10T23:01:02Z",80]]}]}]}`,
|
||||
},
|
||||
{
|
||||
query: `select load from "%DB%"."%RP%".cpu where load > 99`,
|
||||
expected: `{"results":[{"series":[{"name":"cpu","columns":["time","load"],"values":[["2009-11-10T23:00:02Z",100]]}]}]}`,
|
||||
},
|
||||
{
|
||||
query: `select load from "%DB%"."%RP%".cpu where load = 99`,
|
||||
expected: `{"results":[{}]}`,
|
||||
},
|
||||
{
|
||||
query: `select load from "%DB%"."%RP%".cpu where load < 99`,
|
||||
expected: `{"results":[{"series":[{"name":"cpu","columns":["time","load"],"values":[["2009-11-10T23:01:02Z",80]]}]}]}`,
|
||||
},
|
||||
{
|
||||
query: `select load from "%DB%"."%RP%".cpu where load < 80`,
|
||||
expected: `{"results":[{}]}`,
|
||||
},
|
||||
{
|
||||
write: `{"database" : "%DB%", "retentionPolicy" : "%RP%", "points": [{"name": "logs", "timestamp": "2009-11-10T23:00:02Z","fields": {"event": "disk full"}}]}`,
|
||||
query: `select event from "%DB%"."%RP%".logs where event = 'disk full'`,
|
||||
expected: `{"results":[{"series":[{"name":"logs","columns":["time","event"],"values":[["2009-11-10T23:00:02Z","disk full"]]}]}]}`,
|
||||
},
|
||||
{
|
||||
write: `{"database" : "%DB%", "retentionPolicy" : "%RP%", "points": [{"name": "logs", "timestamp": "2009-11-10T23:00:02Z","fields": {"event": "disk full"}}]}`,
|
||||
query: `select event from "%DB%"."%RP%".logs where event = 'nonsense'`,
|
||||
expected: `{"results":[{}]}`,
|
||||
},
|
||||
|
||||
// User control tests
|
||||
{
|
||||
name: "show users, no actual users",
|
||||
|
@ -337,7 +396,27 @@ func runTestsData(t *testing.T, testName string, nodes Cluster, database, retent
|
|||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
for i, tt := range tests {
|
||||
// If tests were explicitly requested, only run those tests.
|
||||
if len(testNums) > 0 {
|
||||
var found bool
|
||||
for _, t := range testNums {
|
||||
if i == t {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
name := tt.name
|
||||
if name == "" {
|
||||
name = tt.query
|
||||
}
|
||||
t.Logf("Running test %d: %s", i, name)
|
||||
|
||||
if tt.reset {
|
||||
t.Logf(`reseting for test "%s"`, tt.name)
|
||||
deleteDatabase(t, testName, nodes, database)
|
||||
|
@ -352,10 +431,6 @@ func runTestsData(t *testing.T, testName string, nodes Cluster, database, retent
|
|||
if tt.query != "" {
|
||||
got, ok := query(t, nodes, rewriteDbRp(tt.query, database, retention), rewriteDbRp(tt.expected, database, retention))
|
||||
if !ok {
|
||||
name := tt.name
|
||||
if name == "" {
|
||||
name = tt.query
|
||||
}
|
||||
t.Errorf(`Test "%s" failed, expected: %s, got: %s`, name, rewriteDbRp(tt.expected, database, retention), got)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1284,154 +1284,6 @@ func TestHandler_serveWriteSeriesBoolValues(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestHandler_serveWriteSeriesWhereIntField(t *testing.T) {
|
||||
srvr := OpenAuthlessServer(NewMessagingClient())
|
||||
srvr.CreateDatabase("foo")
|
||||
srvr.CreateRetentionPolicy("foo", influxdb.NewRetentionPolicy("bar"))
|
||||
srvr.SetDefaultRetentionPolicy("foo", "bar")
|
||||
|
||||
s := NewHTTPServer(srvr)
|
||||
defer s.Close()
|
||||
|
||||
status, body := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "timestamp": "2009-11-10T23:00:02Z", "fields": {"load": 100}},
|
||||
{"name": "cpu", "timestamp": "2009-11-10T23:01:02Z", "fields": {"load": 80}}]}`)
|
||||
if status != http.StatusOK {
|
||||
t.Logf("body %s\n", body)
|
||||
t.Fatalf("unexpected status: %d", status)
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond) // Ensure data node picks up write.
|
||||
|
||||
srvr.Restart() // Ensure data is queryable across restarts.
|
||||
|
||||
query := map[string]string{"db": "foo", "q": "select load from cpu where load > 100"}
|
||||
status, body = MustHTTP("GET", s.URL+`/query`, query, nil, "")
|
||||
if status != http.StatusOK {
|
||||
t.Logf("query %s\n", query)
|
||||
t.Log(body)
|
||||
t.Errorf("unexpected status: %d", status)
|
||||
}
|
||||
if string(body) != `{"results":[{}]}` {
|
||||
t.Fatalf("unexpected results, got %s", string(body))
|
||||
}
|
||||
|
||||
query = map[string]string{"db": "foo", "q": "select load from cpu where load >= 100"}
|
||||
status, body = MustHTTP("GET", s.URL+`/query`, query, nil, "")
|
||||
if status != http.StatusOK {
|
||||
t.Logf("query %s\n", query)
|
||||
t.Log(body)
|
||||
t.Errorf("unexpected status: %d", status)
|
||||
}
|
||||
if string(body) != `{"results":[{"series":[{"name":"cpu","columns":["time","load"],"values":[["2009-11-10T23:00:02Z",100]]}]}]}` {
|
||||
t.Fatalf("unexpected results, got %s", string(body))
|
||||
}
|
||||
|
||||
query = map[string]string{"db": "foo", "q": "select load from cpu where load = 100"}
|
||||
status, body = MustHTTP("GET", s.URL+`/query`, query, nil, "")
|
||||
if status != http.StatusOK {
|
||||
t.Logf("query %s\n", query)
|
||||
t.Log(body)
|
||||
t.Errorf("unexpected status: %d", status)
|
||||
}
|
||||
if string(body) != `{"results":[{"series":[{"name":"cpu","columns":["time","load"],"values":[["2009-11-10T23:00:02Z",100]]}]}]}` {
|
||||
t.Fatalf("unexpected results, got %s", string(body))
|
||||
}
|
||||
|
||||
query = map[string]string{"db": "foo", "q": "select load from cpu where load <= 100"}
|
||||
status, body = MustHTTP("GET", s.URL+`/query`, query, nil, "")
|
||||
if status != http.StatusOK {
|
||||
t.Logf("query %s\n", query)
|
||||
t.Log(body)
|
||||
t.Errorf("unexpected status: %d", status)
|
||||
}
|
||||
if string(body) != `{"results":[{"series":[{"name":"cpu","columns":["time","load"],"values":[["2009-11-10T23:00:02Z",100],["2009-11-10T23:01:02Z",80]]}]}]}` {
|
||||
t.Fatalf("unexpected results, got %s", string(body))
|
||||
}
|
||||
|
||||
query = map[string]string{"db": "foo", "q": "select load from cpu where load > 99"}
|
||||
status, body = MustHTTP("GET", s.URL+`/query`, query, nil, "")
|
||||
if status != http.StatusOK {
|
||||
t.Logf("query %s\n", query)
|
||||
t.Log(body)
|
||||
t.Errorf("unexpected status: %d", status)
|
||||
}
|
||||
if string(body) != `{"results":[{"series":[{"name":"cpu","columns":["time","load"],"values":[["2009-11-10T23:00:02Z",100]]}]}]}` {
|
||||
t.Fatalf("unexpected results, got %s", string(body))
|
||||
}
|
||||
|
||||
query = map[string]string{"db": "foo", "q": "select load from cpu where load = 99"}
|
||||
status, body = MustHTTP("GET", s.URL+`/query`, query, nil, "")
|
||||
if status != http.StatusOK {
|
||||
t.Logf("query %s\n", query)
|
||||
t.Log(body)
|
||||
t.Errorf("unexpected status: %d", status)
|
||||
}
|
||||
if string(body) != `{"results":[{}]}` {
|
||||
t.Fatalf("unexpected results, got %s", string(body))
|
||||
}
|
||||
|
||||
query = map[string]string{"db": "foo", "q": "select load from cpu where load < 99"}
|
||||
status, body = MustHTTP("GET", s.URL+`/query`, query, nil, "")
|
||||
if status != http.StatusOK {
|
||||
t.Logf("query %s\n", query)
|
||||
t.Log(body)
|
||||
t.Errorf("unexpected status: %d", status)
|
||||
}
|
||||
if string(body) != `{"results":[{"series":[{"name":"cpu","columns":["time","load"],"values":[["2009-11-10T23:01:02Z",80]]}]}]}` {
|
||||
t.Fatalf("unexpected results, got %s", string(body))
|
||||
}
|
||||
|
||||
query = map[string]string{"db": "foo", "q": "select load from cpu where load < 80"}
|
||||
status, body = MustHTTP("GET", s.URL+`/query`, query, nil, "")
|
||||
if status != http.StatusOK {
|
||||
t.Logf("query %s\n", query)
|
||||
t.Log(body)
|
||||
t.Errorf("unexpected status: %d", status)
|
||||
}
|
||||
if string(body) != `{"results":[{}]}` {
|
||||
t.Fatalf("unexpected results, got %s", string(body))
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandler_serveWriteSeriesWhereStringField(t *testing.T) {
|
||||
srvr := OpenAuthlessServer(NewMessagingClient())
|
||||
srvr.CreateDatabase("foo")
|
||||
srvr.CreateRetentionPolicy("foo", influxdb.NewRetentionPolicy("bar"))
|
||||
srvr.SetDefaultRetentionPolicy("foo", "bar")
|
||||
|
||||
s := NewHTTPServer(srvr)
|
||||
defer s.Close()
|
||||
|
||||
status, _ := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "logs", "timestamp": "2009-11-10T23:00:02Z","fields": {"event": "disk full"}}]}`)
|
||||
if status != http.StatusOK {
|
||||
t.Fatalf("unexpected status: %d", status)
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond) // Ensure data node picks up write.
|
||||
|
||||
srvr.Restart() // Ensure data is queryable across restarts.
|
||||
|
||||
query := map[string]string{"db": "foo", "q": "select event from logs where event = 'disk full'"}
|
||||
status, body := MustHTTP("GET", s.URL+`/query`, query, nil, "")
|
||||
if status != http.StatusOK {
|
||||
t.Logf("query %s\n", query)
|
||||
t.Log(body)
|
||||
t.Errorf("unexpected status: %d", status)
|
||||
}
|
||||
if string(body) != `{"results":[{"series":[{"name":"logs","columns":["time","event"],"values":[["2009-11-10T23:00:02Z","disk full"]]}]}]}` {
|
||||
t.Fatalf("unexpected results, got %s", string(body))
|
||||
}
|
||||
|
||||
query = map[string]string{"db": "foo", "q": "select event from logs where event = 'nonsense'"}
|
||||
status, body = MustHTTP("GET", s.URL+`/query`, query, nil, "")
|
||||
if status != http.StatusOK {
|
||||
t.Logf("query %s\n", query)
|
||||
t.Log(body)
|
||||
t.Errorf("unexpected status: %d", status)
|
||||
}
|
||||
if string(body) != `{"results":[{}]}` {
|
||||
t.Fatalf("unexpected results, got %s", string(body))
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandler_serveWriteSeriesBatch(t *testing.T) {
|
||||
srvr := OpenAuthlessServer(NewMessagingClient())
|
||||
srvr.CreateDatabase("foo")
|
||||
|
|
Loading…
Reference in New Issue