From e0b3a197d9767be3c31b7e4b2011d8cb73367b15 Mon Sep 17 00:00:00 2001 From: Cory LaNou Date: Tue, 24 Feb 2015 17:18:10 -0700 Subject: [PATCH] adding test for drop measurement that walks through multiple measurements/tags --- server_test.go | 125 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 124 insertions(+), 1 deletion(-) diff --git a/server_test.go b/server_test.go index 6202987c178..f5e09c2fdae 100644 --- a/server_test.go +++ b/server_test.go @@ -892,7 +892,131 @@ func TestServer_DropMeasurement(t *testing.T) { } else if s := mustMarshalJSON(res); s != `{}` { t.Fatalf("unexpected row(0): %s", s) } +} + +// Ensure Drop measurement can: +// write to measurement cpu with tags region=uswest host=serverA +// write to measurement memory with tags region=uswest host=serverB +// drop one of those measurements +// ensure that the dropped measurement is gone +// ensure that we can still query: show measurements +// ensure that we can still make various queries: +// select * from memory where region=uswest and host=serverb +// select * from memory where host=serverb +// select * from memory where region=uswest +func TestServer_DropMeasurementSeriesTagsPreserved(t *testing.T) { + c := NewMessagingClient() + s := OpenServer(c) + defer s.Close() + s.CreateDatabase("foo") + s.CreateRetentionPolicy("foo", &influxdb.RetentionPolicy{Name: "raw", Duration: 1 * time.Hour}) + s.SetDefaultRetentionPolicy("foo", "raw") + s.CreateUser("susy", "pass", false) + + // Write series with one point to the database. + tags := map[string]string{"host": "serverA", "region": "uswest"} + index, err := s.WriteSeries("foo", "raw", []influxdb.Point{{Name: "cpu", Tags: tags, Timestamp: mustParseTime("2000-01-01T00:00:00Z"), Fields: map[string]interface{}{"value": float64(23.2)}}}) + if err != nil { + t.Fatal(err) + } else if err = s.Sync(index); err != nil { + t.Fatalf("sync error: %s", err) + } + + tags = map[string]string{"host": "serverB", "region": "uswest"} + index, err = s.WriteSeries("foo", "raw", []influxdb.Point{{Name: "memory", Tags: tags, Timestamp: mustParseTime("2000-01-01T00:00:01Z"), Fields: map[string]interface{}{"value": float64(33.2)}}}) + if err != nil { + t.Fatal(err) + } else if err = s.Sync(index); err != nil { + t.Fatalf("sync error: %s", err) + } + + // Ensure measurement exists + results := s.ExecuteQuery(MustParseQuery(`SHOW MEASUREMENTS`), "foo", nil) + if res := results.Results[0]; res.Err != nil { + t.Fatalf("unexpected error: %s", res.Err) + } else if len(res.Series) != 1 { + t.Fatalf("unexpected row count: %d", len(res.Series)) + } else if s := mustMarshalJSON(res); s != `{"series":[{"name":"measurements","columns":["name"],"values":[["cpu"],["memory"]]}]}` { + t.Fatalf("unexpected row(0): %s", s) + } + + results = s.ExecuteQuery(MustParseQuery(`SHOW SERIES`), "foo", nil) + if res := results.Results[0]; res.Err != nil { + t.Fatalf("unexpected error: %s", res.Err) + } else if len(res.Series) != 2 { + t.Fatalf("unexpected row count: %d", len(res.Series)) + } else if s := mustMarshalJSON(res); s != `{"series":[{"name":"cpu","columns":["host","region"],"values":[["serverA","uswest"]]},{"name":"memory","columns":["host","region"],"values":[["serverB","uswest"]]}]}` { + t.Fatalf("unexpected row(0): %s", s) + } + + // Ensure we can query for memory with both tags + results = s.ExecuteQuery(MustParseQuery(`SELECT * FROM memory where region='uswest' and host='serverB'`), "foo", nil) + if res := results.Results[0]; res.Err != nil { + t.Fatalf("unexpected error: %s", res.Err) + } else if len(res.Series) != 1 { + t.Fatalf("unexpected row count: %d", len(res.Series)) + } else if s := mustMarshalJSON(res); s != `{"series":[{"name":"memory","columns":["time","value"],"values":[["2000-01-01T00:00:01Z",33.2]]}]}` { + t.Fatalf("unexpected row(0): %s", s) + } + // Drop measurement + results = s.ExecuteQuery(MustParseQuery(`DROP MEASUREMENT cpu`), "foo", nil) + if results.Error() != nil { + t.Fatalf("unexpected error: %s", results.Error()) + } + + // Ensure measurement exists + results = s.ExecuteQuery(MustParseQuery(`SHOW MEASUREMENTS`), "foo", nil) + if res := results.Results[0]; res.Err != nil { + t.Fatalf("unexpected error: %s", res.Err) + } else if len(res.Series) != 1 { + t.Fatalf("unexpected row count: %d", len(res.Series)) + } else if s := mustMarshalJSON(res); s != `{"series":[{"name":"measurements","columns":["name"],"values":[["memory"]]}]}` { + t.Fatalf("unexpected row(0): %s", s) + } + + results = s.ExecuteQuery(MustParseQuery(`SHOW SERIES`), "foo", nil) + if res := results.Results[0]; res.Err != nil { + t.Fatalf("unexpected error: %s", res.Err) + } else if len(res.Series) != 1 { + t.Fatalf("unexpected row count: %d", len(res.Series)) + } else if s := mustMarshalJSON(res); s != `{"series":[{"name":"memory","columns":["host","region"],"values":[["serverB","uswest"]]}]}` { + t.Fatalf("unexpected row(0): %s", s) + } + + results = s.ExecuteQuery(MustParseQuery(`SELECT * FROM cpu`), "foo", nil) + if res := results.Results[0]; res.Err.Error() != `measurement "foo"."raw"."cpu" does not exist.` { + t.Fatalf("unexpected error: %s", res.Err) + } else if len(res.Series) != 0 { + t.Fatalf("unexpected row count: %d", len(res.Series)) + } + + results = s.ExecuteQuery(MustParseQuery(`SELECT * FROM memory where host='serverB'`), "foo", nil) + if res := results.Results[0]; res.Err != nil { + t.Fatalf("unexpected error: %s", res.Err) + } else if len(res.Series) != 1 { + t.Fatalf("unexpected row count: %d", len(res.Series)) + } else if s := mustMarshalJSON(res); s != `{"series":[{"name":"memory","columns":["time","value"],"values":[["2000-01-01T00:00:01Z",33.2]]}]}` { + t.Fatalf("unexpected row(0): %s", s) + } + + results = s.ExecuteQuery(MustParseQuery(`SELECT * FROM memory where region='uswest'`), "foo", nil) + if res := results.Results[0]; res.Err != nil { + t.Fatalf("unexpected error: %s", res.Err) + } else if len(res.Series) != 1 { + t.Fatalf("unexpected row count: %d", len(res.Series)) + } else if s := mustMarshalJSON(res); s != `{"series":[{"name":"memory","columns":["time","value"],"values":[["2000-01-01T00:00:01Z",33.2]]}]}` { + t.Fatalf("unexpected row(0): %s", s) + } + + results = s.ExecuteQuery(MustParseQuery(`SELECT * FROM memory where region='uswest' and host='serverB'`), "foo", nil) + if res := results.Results[0]; res.Err != nil { + t.Fatalf("unexpected error: %s", res.Err) + } else if len(res.Series) != 1 { + t.Fatalf("unexpected row count: %d", len(res.Series)) + } else if s := mustMarshalJSON(res); s != `{"series":[{"name":"memory","columns":["time","value"],"values":[["2000-01-01T00:00:01Z",33.2]]}]}` { + t.Fatalf("unexpected row(0): %s", s) + } } // Ensure the server can drop a series. @@ -938,7 +1062,6 @@ func TestServer_DropSeries(t *testing.T) { } else if s := mustMarshalJSON(res); s != `{"series":[{"name":"cpu","columns":[]}]}` { t.Fatalf("unexpected row(0): %s", s) } - } // Ensure Drop Series can: