diff --git a/server/api/region.go b/server/api/region.go index 5b929734fd4..957f83e3386 100644 --- a/server/api/region.go +++ b/server/api/region.go @@ -130,11 +130,10 @@ func (h *regionsHandler) GetAll(w http.ResponseWriter, r *http.Request) { h.rd.JSON(w, http.StatusInternalServerError, server.ErrNotBootstrapped.Error()) return } - - regions := cluster.GetMetaRegions() + regions := cluster.GetRegions() regionInfos := make([]*regionInfo, len(regions)) for i, r := range regions { - regionInfos[i] = newRegionInfo(core.NewRegionInfo(r, nil)) + regionInfos[i] = newRegionInfo(r) } regionsInfo := ®ionsInfo{ Count: len(regions), diff --git a/server/api/region_test.go b/server/api/region_test.go index 4dd100d0749..09ac9c72aea 100644 --- a/server/api/region_test.go +++ b/server/api/region_test.go @@ -83,6 +83,32 @@ func (s *testRegionSuite) TestRegion(c *C) { c.Assert(r2, DeepEquals, newRegionInfo(r)) } +func (s *testRegionSuite) TestRegions(c *C) { + rs := []*core.RegionInfo{ + newTestRegionInfo(2, 1, []byte("a"), []byte("b")), + newTestRegionInfo(3, 1, []byte("b"), []byte("c")), + newTestRegionInfo(4, 2, []byte("c"), []byte("d")), + } + regions := make([]*regionInfo, 0, len(rs)) + for _, r := range rs { + regions = append(regions, newRegionInfo(r)) + mustRegionHeartbeat(c, s.svr, r) + } + url := fmt.Sprintf("%s/regions", s.urlPrefix) + regionsInfo := ®ionsInfo{} + err := readJSONWithURL(url, regionsInfo) + c.Assert(err, IsNil) + c.Assert(regionsInfo.Count, Equals, len(regions)) + sort.Slice(regionsInfo.Regions, func(i, j int) bool { + return regionsInfo.Regions[i].ID < regionsInfo.Regions[j].ID + }) + for i, r := range regionsInfo.Regions { + c.Assert(r.ID, Equals, regions[i].ID) + c.Assert(r.ApproximateSize, Equals, regions[i].ApproximateSize) + c.Assert(r.ApproximateKeys, Equals, regions[i].ApproximateKeys) + } +} + func (s *testRegionSuite) TestStoreRegions(c *C) { r1 := newTestRegionInfo(2, 1, []byte("a"), []byte("b")) r2 := newTestRegionInfo(3, 1, []byte("b"), []byte("c"))