From b69dc160eac155b5667e699fb670758775bd8c24 Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Tue, 3 Mar 2015 14:30:59 -0800 Subject: [PATCH 1/5] Add failing test case for WHERE AND --- cmd/influxd/server_integration_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmd/influxd/server_integration_test.go b/cmd/influxd/server_integration_test.go index fc6a89b3f5..71f6e32e24 100644 --- a/cmd/influxd/server_integration_test.go +++ b/cmd/influxd/server_integration_test.go @@ -267,6 +267,15 @@ 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 with AND query", + 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' AND tenant_id='tenant'`, + expected: `{"results":[{"series":[{"name":"cpu","columns":["time","alert_id"],"values":[["2015-02-28T01:03:36.703820946Z","alert"]]}]}]}`, + }, + // User control tests { name: "show users, no actual users", From f422fbdebe14b4d0cd320ef5a4822fb573bfe483 Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Tue, 3 Mar 2015 14:53:31 -0800 Subject: [PATCH 2/5] Support only running certain integration tests --- cmd/influxd/server_integration_test.go | 30 ++++++++++++++++++++------ 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/cmd/influxd/server_integration_test.go b/cmd/influxd/server_integration_test.go index 71f6e32e24..de6029cd6a 100644 --- a/cmd/influxd/server_integration_test.go +++ b/cmd/influxd/server_integration_test.go @@ -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. @@ -346,7 +346,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) @@ -361,10 +381,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) } } From 6ceae8ba3ca610314aec6ad1f4631688311d0fab Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Tue, 3 Mar 2015 15:02:42 -0800 Subject: [PATCH 3/5] Add WHERE field test, on 1 field --- cmd/influxd/server_integration_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmd/influxd/server_integration_test.go b/cmd/influxd/server_integration_test.go index de6029cd6a..d18085f7cf 100644 --- a/cmd/influxd/server_integration_test.go +++ b/cmd/influxd/server_integration_test.go @@ -270,6 +270,12 @@ func runTestsData(t *testing.T, testName string, nodes Cluster, database, retent // 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", 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' AND tenant_id='tenant'`, From 89bed24505d14cc1773583146b7961f07e1dfe5f Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Tue, 3 Mar 2015 15:26:02 -0800 Subject: [PATCH 4/5] Tighten WHERE fields test case --- cmd/influxd/server_integration_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/influxd/server_integration_test.go b/cmd/influxd/server_integration_test.go index d18085f7cf..e7790e50fa 100644 --- a/cmd/influxd/server_integration_test.go +++ b/cmd/influxd/server_integration_test.go @@ -276,10 +276,10 @@ func runTestsData(t *testing.T, testName string, nodes Cluster, database, retent expected: `{"results":[{"series":[{"name":"cpu","columns":["time","alert_id"],"values":[["2015-02-28T01:03:36.703820946Z","alert"]]}]}]}`, }, { - name: "WHERE fields with AND query", + 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 FROM "%DB%"."%RP%".cpu WHERE alert_id='alert' AND tenant_id='tenant'`, - expected: `{"results":[{"series":[{"name":"cpu","columns":["time","alert_id"],"values":[["2015-02-28T01:03:36.703820946Z","alert"]]}]}]}`, + 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"]]}]}]}`, }, // User control tests From 0e3e0f6a387d6d5b408f85cd74ec3faab40527f3 Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Tue, 3 Mar 2015 15:48:03 -0800 Subject: [PATCH 5/5] Transplant more tests from httpd --- cmd/influxd/server_integration_test.go | 44 ++++++++ httpd/handler_test.go | 148 ------------------------- 2 files changed, 44 insertions(+), 148 deletions(-) diff --git a/cmd/influxd/server_integration_test.go b/cmd/influxd/server_integration_test.go index e7790e50fa..0d7e3f40da 100644 --- a/cmd/influxd/server_integration_test.go +++ b/cmd/influxd/server_integration_test.go @@ -281,6 +281,50 @@ func runTestsData(t *testing.T, testName string, nodes Cluster, database, retent 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 { diff --git a/httpd/handler_test.go b/httpd/handler_test.go index 7a9503c0a3..e69463e7cc 100644 --- a/httpd/handler_test.go +++ b/httpd/handler_test.go @@ -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")