Running a few commands through VtctlPipe.

That adds unit test coverage to vtctl.go.
This commit is contained in:
Alain Jobart 2015-05-29 14:12:27 -07:00
Родитель 09538e71fb
Коммит fc3079860e
4 изменённых файлов: 12 добавлений и 7 удалений

Просмотреть файл

@ -20,9 +20,10 @@ import (
)
func TestEmergencyReparentShard(t *testing.T) {
ctx := context.Background()
ts := zktopo.NewTestServer(t, []string{"cell1", "cell2"})
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient(), time.Second)
vp := NewVtctlPipe(t, ts)
defer vp.Close()
// Create a master, a couple good slaves
oldMaster := NewFakeTablet(t, wr, "cell1", 0, topo.TYPE_MASTER)
@ -93,7 +94,7 @@ func TestEmergencyReparentShard(t *testing.T) {
defer goodSlave2.StopActionLoop(t)
// run EmergencyReparentShard
if err := wr.EmergencyReparentShard(ctx, newMaster.Tablet.Keyspace, newMaster.Tablet.Shard, newMaster.Tablet.Alias, 10*time.Second); err != nil {
if err := vp.Run([]string{"EmergencyReparentShard", "-wait_slave_timeout", "10s", newMaster.Tablet.Keyspace + "/" + newMaster.Tablet.Shard, newMaster.Tablet.Alias.String()}); err != nil {
t.Fatalf("EmergencyReparentShard failed: %v", err)
}

Просмотреть файл

@ -25,6 +25,8 @@ func TestInitMasterShard(t *testing.T) {
ctx := context.Background()
ts := zktopo.NewTestServer(t, []string{"cell1", "cell2"})
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient(), time.Second)
vp := NewVtctlPipe(t, ts)
defer vp.Close()
// Create a master, a couple good slaves
master := NewFakeTablet(t, wr, "cell1", 0, topo.TYPE_MASTER)
@ -90,7 +92,7 @@ func TestInitMasterShard(t *testing.T) {
defer goodSlave2.StopActionLoop(t)
// run InitShardMaster
if err := wr.InitShardMaster(ctx, master.Tablet.Keyspace, master.Tablet.Shard, master.Tablet.Alias, false /*force*/, 10*time.Second); err != nil {
if err := vp.Run([]string{"InitShardMaster", "-wait_slave_timeout", "10s", master.Tablet.Keyspace + "/" + master.Tablet.Shard, master.Tablet.Alias.String()}); err != nil {
t.Fatalf("InitShardMaster failed: %v", err)
}

Просмотреть файл

@ -15,15 +15,15 @@ import (
"github.com/youtube/vitess/go/vt/topo"
"github.com/youtube/vitess/go/vt/wrangler"
"github.com/youtube/vitess/go/vt/zktopo"
"golang.org/x/net/context"
"time"
)
func TestPlannedReparentShard(t *testing.T) {
ctx := context.Background()
ts := zktopo.NewTestServer(t, []string{"cell1", "cell2"})
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient(), time.Second)
vp := NewVtctlPipe(t, ts)
defer vp.Close()
// Create a master, a couple good slaves
oldMaster := NewFakeTablet(t, wr, "cell1", 0, topo.TYPE_MASTER)
@ -95,7 +95,7 @@ func TestPlannedReparentShard(t *testing.T) {
defer goodSlave2.StopActionLoop(t)
// run PlannedReparentShard
if err := wr.PlannedReparentShard(ctx, newMaster.Tablet.Keyspace, newMaster.Tablet.Shard, newMaster.Tablet.Alias, 10*time.Second); err != nil {
if err := vp.Run([]string{"PlannedReparentShard", "-wait_slave_timeout", "10s", newMaster.Tablet.Keyspace + "/" + newMaster.Tablet.Shard, newMaster.Tablet.Alias.String()}); err != nil {
t.Fatalf("PlannedReparentShard failed: %v", err)
}

Просмотреть файл

@ -37,6 +37,8 @@ func testTabletExternallyReparented(t *testing.T, fast bool) {
ctx := context.Background()
ts := zktopo.NewTestServer(t, []string{"cell1", "cell2"})
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient(), time.Second)
vp := NewVtctlPipe(t, ts)
defer vp.Close()
// Create an old master, a new master, two good slaves, one bad slave
oldMaster := NewFakeTablet(t, wr, "cell1", 0, topo.TYPE_MASTER)
@ -121,7 +123,7 @@ func testTabletExternallyReparented(t *testing.T, fast bool) {
if err != nil {
t.Fatalf("GetTablet failed: %v", err)
}
if err := tmc.TabletExternallyReparented(context.Background(), ti, ""); err != nil {
if err := vp.Run([]string{"TabletExternallyReparented", oldMaster.Tablet.Alias.String()}); err != nil {
t.Fatalf("TabletExternallyReparented(same master) should have worked")
}