Skip to content

Commit

Permalink
Fix #469. Dropping a db should remove all its CQ
Browse files Browse the repository at this point in the history
  • Loading branch information
jvshahid committed Apr 30, 2014
1 parent fcfa518 commit 483952d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
5 changes: 5 additions & 0 deletions src/cluster/cluster_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ func (self *ClusterConfiguration) DropDatabase(name string) error {

delete(self.DatabaseReplicationFactors, name)

self.continuousQueriesLock.Lock()
defer self.continuousQueriesLock.Unlock()
delete(self.continuousQueries, name)
delete(self.ParsedContinuousQueries, name)

self.usersLock.Lock()
defer self.usersLock.Unlock()

Expand Down
37 changes: 17 additions & 20 deletions src/integration/single_server_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package integration

import (
h "api/http"
"bytes"
"crypto/tls"
"encoding/json"
"fmt"
. "integration/helpers"
"io/ioutil"
Expand Down Expand Up @@ -268,20 +266,12 @@ func (self *SingleServerSuite) TestDataResurrectionAfterRestart(c *C) {

// issue #360
func (self *SingleServerSuite) TestContinuousQueriesAfterCompaction(c *C) {
defer self.server.RemoveAllContinuousQueries("db1", c)
resp, err := http.Post("http://localhost:8086/db/db1/continuous_queries?u=root&p=root", "application/json",
bytes.NewBufferString(`{"query": "select * from foo into bar"}`))
c.Assert(err, IsNil)
c.Assert(resp.StatusCode, Equals, http.StatusOK)
resp, err = http.Get("http://localhost:8086/db/db1/continuous_queries?u=root&p=root")
c.Assert(err, IsNil)
defer resp.Body.Close()
c.Assert(resp.StatusCode, Equals, http.StatusOK)
body, err := ioutil.ReadAll(resp.Body)
c.Assert(err, IsNil)
queries := []*h.ContinuousQuery{}
err = json.Unmarshal(body, &queries)
c.Assert(err, IsNil)
c.Assert(queries, HasLen, 1)
self.server.AssertContinuousQueryCount("db1", 1, c)

resp, err = http.Post("http://localhost:8086/raft/force_compaction?u=root&p=root", "", nil)
c.Assert(err, IsNil)
Expand All @@ -291,16 +281,23 @@ func (self *SingleServerSuite) TestContinuousQueriesAfterCompaction(c *C) {
c.Assert(self.server.Start(), IsNil)
self.server.WaitForServerToStart()

resp, err = http.Get("http://localhost:8086/db/db1/continuous_queries?u=root&p=root")
self.server.AssertContinuousQueryCount("db1", 1, c)
}

// issue #469
func (self *SingleServerSuite) TestContinuousQueriesAfterDroppingDatabase(c *C) {
defer self.server.RemoveAllContinuousQueries("db2", c)
self.server.AssertContinuousQueryCount("db2", 0, c)
client := self.server.GetClient("", c)
c.Assert(client.CreateDatabase("db2"), IsNil)
self.server.WaitForServerToSync()
resp, err := http.Post("http://localhost:8086/db/db2/continuous_queries?u=root&p=root", "application/json",
bytes.NewBufferString(`{"query": "select * from foo into bar"}`))
c.Assert(err, IsNil)
defer resp.Body.Close()
c.Assert(resp.StatusCode, Equals, http.StatusOK)
body, err = ioutil.ReadAll(resp.Body)
c.Assert(err, IsNil)
queries = []*h.ContinuousQuery{}
err = json.Unmarshal(body, &queries)
c.Assert(err, IsNil)
c.Assert(queries, HasLen, 1)
self.server.AssertContinuousQueryCount("db2", 1, c)
c.Assert(client.DeleteDatabase("db2"), IsNil)
self.server.AssertContinuousQueryCount("db2", 0, c)
}

func (self *SingleServerSuite) TestDbUserAuthentication(c *C) {
Expand Down

0 comments on commit 483952d

Please sign in to comment.