Integration tests for drop measurement

pull/2941/head
Cory LaNou 2015-06-11 15:04:23 -05:00
parent f6442d0556
commit 2373d9a68f
1 changed files with 107 additions and 0 deletions

View File

@ -2277,3 +2277,110 @@ func TestServer_Query_Fill(t *testing.T) {
}
}
}
func TestServer_Query_DropMeasurement(t *testing.T) {
t.Parallel()
s := OpenServer(NewConfig(), "")
defer s.Close()
if err := s.CreateDatabaseAndRetentionPolicy("db0", newRetentionPolicyInfo("rp0", 1, 0)); err != nil {
t.Fatal(err)
}
if err := s.MetaStore.SetDefaultRetentionPolicy("db0", "rp0"); err != nil {
t.Fatal(err)
}
writes := []string{
fmt.Sprintf(`cpu,host=serverA,region=uswest val=23.2 %d`, mustParseTime(time.RFC3339Nano, "2000-01-01T00:00:00Z").UnixNano()),
fmt.Sprintf(`memory,host=serverB,region=uswest val=33.2 %d`, mustParseTime(time.RFC3339Nano, "2000-01-01T00:00:01Z").UnixNano()),
}
test := NewTest("db0", "rp0")
test.write = strings.Join(writes, "\n")
test.addQueries([]*Query{
&Query{
name: "Drop Measurement, series tags preserved tests",
command: `SHOW MEASUREMENTS`,
exp: `{"results":[{"series":[{"name":"measurements","columns":["name"],"values":[["cpu"],["memory"]]}]}]}`,
params: url.Values{"db": []string{"db0"}},
},
&Query{
name: "show series",
command: `SHOW SERIES`,
exp: `{"results":[{"series":[{"name":"cpu","columns":["_key","host","region"],"values":[["cpu,host=serverA,region=uswest","serverA","uswest"]]},{"name":"memory","columns":["_key","host","region"],"values":[["memory,host=serverB,region=uswest","serverB","uswest"]]}]}]}`,
params: url.Values{"db": []string{"db0"}},
},
&Query{
name: "ensure we can query for memory with both tags",
command: `SELECT * FROM memory where region='uswest' and host='serverB'`,
exp: `{"results":[{"series":[{"name":"memory","tags":{"host":"serverB","region":"uswest"},"columns":["time","val"],"values":[["2000-01-01T00:00:01Z",33.2]]}]}]}`,
params: url.Values{"db": []string{"db0"}},
},
&Query{
name: "drop measurement cpu",
command: `DROP MEASUREMENT cpu`,
exp: `{"results":[{}]}`,
params: url.Values{"db": []string{"db0"}},
},
&Query{
name: "verify measurements",
command: `SHOW MEASUREMENTS`,
exp: `{"results":[{"series":[{"name":"measurements","columns":["name"],"values":[["memory"]]}]}]}`,
params: url.Values{"db": []string{"db0"}},
},
&Query{
name: "verify series",
command: `SHOW SERIES`,
exp: `{"results":[{"series":[{"name":"memory","columns":["_key","host","region"],"values":[["memory,host=serverB,region=uswest","serverB","uswest"]]}]}]}`,
params: url.Values{"db": []string{"db0"}},
},
&Query{
name: "verify cpu measurement is gone",
command: `SELECT * FROM cpu`,
exp: `{"results":[{"error":"measurement not found: \"db0\".\"rp0\".cpu"}]}`,
params: url.Values{"db": []string{"db0"}},
},
&Query{
name: "verify selecting from a tag 'host' still works",
command: `SELECT * FROM memory where host='serverB'`,
exp: `{"results":[{"series":[{"name":"memory","tags":{"host":"serverB","region":"uswest"},"columns":["time","val"],"values":[["2000-01-01T00:00:01Z",33.2]]}]}]}`,
params: url.Values{"db": []string{"db0"}},
},
&Query{
name: "verify selecting from a tag 'region' still works",
command: `SELECT * FROM memory where region='uswest'`,
exp: `{"results":[{"series":[{"name":"memory","tags":{"host":"serverB","region":"uswest"},"columns":["time","val"],"values":[["2000-01-01T00:00:01Z",33.2]]}]}]}`,
params: url.Values{"db": []string{"db0"}},
},
&Query{
name: "verify selecting from a tag 'host' and 'region' still works",
command: `SELECT * FROM memory where region='uswest' and host='serverB'`,
exp: `{"results":[{"series":[{"name":"memory","tags":{"host":"serverB","region":"uswest"},"columns":["time","val"],"values":[["2000-01-01T00:00:01Z",33.2]]}]}]}`,
params: url.Values{"db": []string{"db0"}},
},
&Query{
name: "Drop non-existant measurement",
command: `DROP MEASUREMENT doesntexist`,
exp: `{"results":[{"error":"measurement not found: doesntexist"}]}`,
params: url.Values{"db": []string{"db0"}},
},
}...)
for i, query := range test.queries {
if i == 0 {
if err := test.init(s); err != nil {
t.Fatalf("test init failed: %s", err)
}
}
if query.skip {
t.Logf("SKIP:: %s", query.name)
continue
}
if err := query.Execute(s); err != nil {
t.Error(query.Error(err))
} else if !query.success() {
t.Error(query.failureMessage())
}
}
}