Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
Signed-off-by: rleungx <rleungx@gmail.com>
  • Loading branch information
rleungx committed Dec 18, 2018
1 parent 28f324d commit 706b71a
Showing 1 changed file with 68 additions and 81 deletions.
149 changes: 68 additions & 81 deletions pkg/integration_test/pdctl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ func (s *integrationTestSuite) TestConfig(c *C) {
func (s *integrationTestSuite) TestOperator(c *C) {
c.Parallel()

var err error
cluster, err := newTestCluster(3, func(conf *server.Config) { conf.Replication.MaxReplicas = 2 })
c.Assert(err, IsNil)
err = cluster.RunInitialServers()
Expand Down Expand Up @@ -776,72 +777,79 @@ func (s *integrationTestSuite) TestOperator(c *C) {
}))
defer cluster.Destroy()

// operator add add-peer <region_id> <to_store_id>
args := []string{"-u", pdAddr, "operator", "add", "add-peer", "1", "3"}
_, _, err = executeCommandC(cmd, args...)
c.Assert(err, IsNil)
args = []string{"-u", pdAddr, "operator", "show"}
_, output, err := executeCommandC(cmd, args...)
c.Assert(err, IsNil)
c.Assert(strings.Contains(string(output), "promote learner peer 1 on store 3"), IsTrue)
args = []string{"-u", pdAddr, "operator", "remove", "1"}
_, _, err = executeCommandC(cmd, args...)
c.Assert(err, IsNil)

// operator add remove-peer <region_id> <to_store_id>
args = []string{"-u", pdAddr, "operator", "add", "remove-peer", "1", "2"}
_, _, err = executeCommandC(cmd, args...)
c.Assert(err, IsNil)
args = []string{"-u", pdAddr, "operator", "show"}
_, output, err = executeCommandC(cmd, args...)
c.Assert(err, IsNil)
c.Assert(strings.Contains(string(output), "remove peer on store 2"), IsTrue)
args = []string{"-u", pdAddr, "operator", "remove", "1"}
_, _, err = executeCommandC(cmd, args...)
c.Assert(err, IsNil)

// operator add transfer-leader <region_id> <to_store_id>
args = []string{"-u", pdAddr, "operator", "add", "transfer-leader", "1", "2"}
_, _, err = executeCommandC(cmd, args...)
c.Assert(err, IsNil)
args = []string{"-u", pdAddr, "operator", "show", "leader"}
_, output, err = executeCommandC(cmd, args...)
c.Assert(err, IsNil)
c.Assert(strings.Contains(string(output), "transfer leader from store 1 to store 2"), IsTrue)
args = []string{"-u", pdAddr, "operator", "remove", "1"}
_, _, err = executeCommandC(cmd, args...)
c.Assert(err, IsNil)

// operator add transfer-region <region_id> <to_store_id>...
args = []string{"-u", pdAddr, "operator", "add", "transfer-region", "1", "2", "3"}
_, _, err = executeCommandC(cmd, args...)
c.Assert(err, IsNil)
args = []string{"-u", pdAddr, "operator", "show", "region"}
_, output, err = executeCommandC(cmd, args...)
c.Assert(err, IsNil)
c.Assert(strings.Contains(string(output), "remove peer on store 1"), IsTrue)
args = []string{"-u", pdAddr, "operator", "remove", "1"}
_, _, err = executeCommandC(cmd, args...)
c.Assert(err, IsNil)
var testCases = []struct {
cmd []string
show []string
expect string
reset []string
}{
{
// operator add add-peer <region_id> <to_store_id>
cmd: []string{"-u", pdAddr, "operator", "add", "add-peer", "1", "3"},
show: []string{"-u", pdAddr, "operator", "show"},
expect: "promote learner peer 1 on store 3",
reset: []string{"-u", pdAddr, "operator", "remove", "1"},
},
{
// operator add remove-peer <region_id> <to_store_id>
cmd: []string{"-u", pdAddr, "operator", "add", "remove-peer", "1", "2"},
show: []string{"-u", pdAddr, "operator", "show"},
expect: "remove peer on store 2",
reset: []string{"-u", pdAddr, "operator", "remove", "1"},
},
{
// operator add transfer-leader <region_id> <to_store_id>
cmd: []string{"-u", pdAddr, "operator", "add", "transfer-leader", "1", "2"},
show: []string{"-u", pdAddr, "operator", "show", "leader"},
expect: "transfer leader from store 1 to store 2",
reset: []string{"-u", pdAddr, "operator", "remove", "1"},
},
{
// operator add transfer-region <region_id> <to_store_id>...
cmd: []string{"-u", pdAddr, "operator", "add", "transfer-region", "1", "2", "3"},
show: []string{"-u", pdAddr, "operator", "show", "region"},
expect: "remove peer on store 1",
reset: []string{"-u", pdAddr, "operator", "remove", "1"},
},
{
// operator add transfer-peer <region_id> <from_store_id> <to_store_id>
cmd: []string{"-u", pdAddr, "operator", "add", "transfer-peer", "1", "2", "3"},
show: []string{"-u", pdAddr, "operator", "show"},
expect: "remove peer on store 2",
reset: []string{"-u", pdAddr, "operator", "remove", "1"},
},
{
// operator add split-region <region_id> [--policy=scan|approximate]
cmd: []string{"-u", pdAddr, "operator", "add", "split-region", "3", "--policy=scan"},
show: []string{"-u", pdAddr, "operator", "show"},
expect: "split region with policy SCAN",
reset: []string{"-u", pdAddr, "operator", "remove", "3"},
},
{
// operator add split-region <region_id> [--policy=scan|approximate]
cmd: []string{"-u", pdAddr, "operator", "add", "split-region", "3", "--policy=approximate"},
show: []string{"-u", pdAddr, "operator", "show"},
expect: "split region with policy APPROXIMATE",
reset: []string{"-u", pdAddr, "operator", "remove", "3"},
},
}

// operator add transfer-peer <region_id> <from_store_id> <to_store_id>
args = []string{"-u", pdAddr, "operator", "add", "transfer-peer", "1", "2", "3"}
_, _, err = executeCommandC(cmd, args...)
c.Assert(err, IsNil)
args = []string{"-u", pdAddr, "operator", "show"}
_, output, err = executeCommandC(cmd, args...)
c.Assert(err, IsNil)
c.Assert(strings.Contains(string(output), "remove peer on store 2"), IsTrue)
args = []string{"-u", pdAddr, "operator", "remove", "1"}
_, _, err = executeCommandC(cmd, args...)
c.Assert(err, IsNil)
for _, testCase := range testCases {
_, _, e := executeCommandC(cmd, testCase.cmd...)
c.Assert(e, IsNil)
_, output, e := executeCommandC(cmd, testCase.show...)
c.Assert(e, IsNil)
c.Assert(strings.Contains(string(output), testCase.expect), IsTrue)
_, _, e = executeCommandC(cmd, testCase.reset...)
c.Assert(e, IsNil)
}

// operator add merge-region <source_region_id> <target_region_id>
args = []string{"-u", pdAddr, "operator", "add", "merge-region", "1", "3"}
args := []string{"-u", pdAddr, "operator", "add", "merge-region", "1", "3"}
_, _, err = executeCommandC(cmd, args...)
c.Assert(err, IsNil)
args = []string{"-u", pdAddr, "operator", "show"}
_, output, err = executeCommandC(cmd, args...)
_, output, err := executeCommandC(cmd, args...)
c.Assert(err, IsNil)
c.Assert(strings.Contains(string(output), "merge region 1 into region 3"), IsTrue)
args = []string{"-u", pdAddr, "operator", "remove", "1"}
Expand All @@ -850,27 +858,6 @@ func (s *integrationTestSuite) TestOperator(c *C) {
args = []string{"-u", pdAddr, "operator", "remove", "3"}
_, _, err = executeCommandC(cmd, args...)
c.Assert(err, IsNil)

// operator add split-region <region_id> [--policy=scan|approximate]
args = []string{"-u", pdAddr, "operator", "add", "split-region", "3", "--policy=scan"}
_, _, err = executeCommandC(cmd, args...)
c.Assert(err, IsNil)
args = []string{"-u", pdAddr, "operator", "show"}
_, output, err = executeCommandC(cmd, args...)
c.Assert(err, IsNil)
c.Assert(strings.Contains(string(output), "split region with policy SCAN"), IsTrue)
args = []string{"-u", pdAddr, "operator", "remove", "3"}
_, _, err = executeCommandC(cmd, args...)
c.Assert(err, IsNil)

// operator add split-region <region_id> [--policy=scan|approximate]
args = []string{"-u", pdAddr, "operator", "add", "split-region", "3", "--policy=approximate"}
_, _, err = executeCommandC(cmd, args...)
c.Assert(err, IsNil)
args = []string{"-u", pdAddr, "operator", "show"}
_, output, err = executeCommandC(cmd, args...)
c.Assert(err, IsNil)
c.Assert(strings.Contains(string(output), "split region with policy APPROXIMATE"), IsTrue)
}

func initCommand() *cobra.Command {
Expand Down

0 comments on commit 706b71a

Please sign in to comment.