-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
server: schema info api of http status server #5256
Changes from 8 commits
61c61db
8479bb7
6cc94e6
007d88d
5d20378
b6aecfb
eca760b
66ef8ce
1ed1548
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,11 +21,13 @@ import ( | |
"fmt" | ||
"math" | ||
"net/http" | ||
"sort" | ||
|
||
. "github.com/pingcap/check" | ||
"github.com/pingcap/kvproto/pkg/kvrpcpb" | ||
"github.com/pingcap/tidb" | ||
"github.com/pingcap/tidb/config" | ||
"github.com/pingcap/tidb/model" | ||
"github.com/pingcap/tidb/store/tikv" | ||
"github.com/pingcap/tidb/store/tikv/mock-tikv" | ||
"github.com/pingcap/tidb/tablecodec" | ||
|
@@ -302,3 +304,60 @@ func (ts *TidbRegionHandlerTestSuite) TestGetMvccNotFound(c *C) { | |
c.Assert(err, IsNil) | ||
c.Assert(p.Info, IsNil) | ||
} | ||
|
||
func (ts *TidbRegionHandlerTestSuite) TestGetSchema(c *C) { | ||
ts.startServer(c) | ||
ts.prepareData(c) | ||
defer ts.stopServer(c) | ||
resp, err := http.Get(fmt.Sprintf("http://127.0.0.1:10090/schema")) | ||
c.Assert(err, IsNil) | ||
decoder := json.NewDecoder(resp.Body) | ||
var dbs []*model.DBInfo | ||
err = decoder.Decode(&dbs) | ||
c.Assert(err, IsNil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check dbs value? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
expects := []string{"information_schema", "mysql", "performance_schema", "test", "tidb"} | ||
names := make([]string, len(dbs)) | ||
for i, v := range dbs { | ||
names[i] = v.Name.L | ||
} | ||
sort.Strings(names) | ||
c.Assert(names, DeepEquals, expects) | ||
|
||
resp, err = http.Get(fmt.Sprintf("http://127.0.0.1:10090/schema?table_id=5")) | ||
c.Assert(err, IsNil) | ||
var t *model.TableInfo | ||
decoder = json.NewDecoder(resp.Body) | ||
err = decoder.Decode(&t) | ||
c.Assert(err, IsNil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
c.Assert(t.Name.L, Equals, "user") | ||
|
||
_, err = http.Get(fmt.Sprintf("http://127.0.0.1:10090/schema?table_id=a")) | ||
c.Assert(err, IsNil) | ||
|
||
_, err = http.Get(fmt.Sprintf("http://127.0.0.1:10090/schema?table_id=1")) | ||
c.Assert(err, IsNil) | ||
|
||
_, err = http.Get(fmt.Sprintf("http://127.0.0.1:10090/schema?table_id=-1")) | ||
c.Assert(err, IsNil) | ||
|
||
resp, err = http.Get(fmt.Sprintf("http://127.0.0.1:10090/schema/tidb")) | ||
c.Assert(err, IsNil) | ||
var lt []*model.TableInfo | ||
decoder = json.NewDecoder(resp.Body) | ||
err = decoder.Decode(<) | ||
c.Assert(err, IsNil) | ||
c.Assert(lt[0].Name.L, Equals, "test") | ||
|
||
_, err = http.Get(fmt.Sprintf("http://127.0.0.1:10090/schema/abc")) | ||
c.Assert(err, IsNil) | ||
|
||
resp, err = http.Get(fmt.Sprintf("http://127.0.0.1:10090/schema/tidb/test")) | ||
c.Assert(err, IsNil) | ||
decoder = json.NewDecoder(resp.Body) | ||
err = decoder.Decode(&t) | ||
c.Assert(err, IsNil) | ||
c.Assert(t.Name.L, Equals, "test") | ||
|
||
_, err = http.Get(fmt.Sprintf("http://127.0.0.1:10090/schema/tidb/abc")) | ||
c.Assert(err, IsNil) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we
return
afterwriteXXX
, since we do not care about this logic anymore?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!