Using right DBA abstraction in copy_schema_shard_test.go.

Also using VtctlPipe.
This commit is contained in:
Alain Jobart 2015-05-28 16:16:28 -07:00
Родитель 73514f0603
Коммит 8058dd0359
2 изменённых файлов: 20 добавлений и 41 удалений

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

@ -160,9 +160,6 @@ type FakeMysqlDaemon struct {
// If nil we'll return an error.
ApplySchemaChangeResult *proto.SchemaChangeResult
// DbaConnectionFactory is the factory for making fake dba connections
DbaConnectionFactory func() (dbconnpool.PoolConnection, error)
// DbAppConnectionFactory is the factory for making fake db app connections
DbAppConnectionFactory func() (dbconnpool.PoolConnection, error)

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

@ -6,12 +6,10 @@ package testlib
import (
"fmt"
"sync/atomic"
"testing"
"time"
mproto "github.com/youtube/vitess/go/mysql/proto"
"github.com/youtube/vitess/go/vt/dbconnpool"
"github.com/youtube/vitess/go/vt/logutil"
myproto "github.com/youtube/vitess/go/vt/mysqlctl/proto"
_ "github.com/youtube/vitess/go/vt/tabletmanager/gorpctmclient"
@ -21,7 +19,6 @@ import (
"github.com/youtube/vitess/go/vt/vttest/fakesqldb"
"github.com/youtube/vitess/go/vt/wrangler"
"github.com/youtube/vitess/go/vt/zktopo"
"golang.org/x/net/context"
)
type ExpectedExecuteFetch struct {
@ -93,41 +90,12 @@ func (fpc *FakePoolConnection) Reconnect() error {
return nil
}
// on the destinations
func DestinationsFactory(t *testing.T) func() (dbconnpool.PoolConnection, error) {
var queryIndex int64 = -1
return func() (dbconnpool.PoolConnection, error) {
qi := atomic.AddInt64(&queryIndex, 1)
switch {
case qi == 0:
return NewFakePoolConnectionQuery(t, "CREATE DATABASE `vt_ks` /*!40100 DEFAULT CHARACTER SET utf8 */"), nil
case qi == 1:
return NewFakePoolConnectionQuery(t, "CREATE TABLE `vt_ks`.`resharding1` (\n"+
" `id` bigint(20) NOT NULL AUTO_INCREMENT,\n"+
" `msg` varchar(64) DEFAULT NULL,\n"+
" `keyspace_id` bigint(20) unsigned NOT NULL,\n"+
" PRIMARY KEY (`id`),\n"+
" KEY `by_msg` (`msg`)\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8"), nil
case qi == 2:
return NewFakePoolConnectionQuery(t, "CREATE TABLE `view1` (\n"+
" `id` bigint(20) NOT NULL AUTO_INCREMENT,\n"+
" `msg` varchar(64) DEFAULT NULL,\n"+
" `keyspace_id` bigint(20) unsigned NOT NULL,\n"+
" PRIMARY KEY (`id`),\n"+
" KEY `by_msg` (`msg`)\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8"), nil
}
return nil, fmt.Errorf("Unexpected connection")
}
}
func TestCopySchemaShard(t *testing.T) {
fakesqldb.Register()
db := fakesqldb.Register()
ts := zktopo.NewTestServer(t, []string{"cell1", "cell2"})
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient(), time.Second)
vp := NewVtctlPipe(t, ts)
defer vp.Close()
sourceMaster := NewFakeTablet(t, wr, "cell1", 0,
topo.TYPE_MASTER, TabletKeyspaceShard(t, "ks", "-80"))
@ -158,10 +126,24 @@ func TestCopySchemaShard(t *testing.T) {
},
}
destinationMaster.FakeMysqlDaemon.DbaConnectionFactory = DestinationsFactory(t)
db.AddQuery("USE vt_ks", &mproto.QueryResult{})
db.AddQuery("CREATE DATABASE `vt_ks` /*!40100 DEFAULT CHARACTER SET utf8 */", &mproto.QueryResult{})
db.AddQuery("CREATE TABLE `vt_ks`.`resharding1` (\n"+
" `id` bigint(20) NOT NULL AUTO_INCREMENT,\n"+
" `msg` varchar(64) DEFAULT NULL,\n"+
" `keyspace_id` bigint(20) unsigned NOT NULL,\n"+
" PRIMARY KEY (`id`),\n"+
" KEY `by_msg` (`msg`)\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8", &mproto.QueryResult{})
db.AddQuery("CREATE TABLE `view1` (\n"+
" `id` bigint(20) NOT NULL AUTO_INCREMENT,\n"+
" `msg` varchar(64) DEFAULT NULL,\n"+
" `keyspace_id` bigint(20) unsigned NOT NULL,\n"+
" PRIMARY KEY (`id`),\n"+
" KEY `by_msg` (`msg`)\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8", &mproto.QueryResult{})
if err := wr.CopySchemaShard(context.Background(), sourceRdonly.Tablet.Alias, nil, nil, true, "ks", "-40"); err != nil {
if err := vp.Run([]string{"CopySchemaShard", "-include-views", sourceRdonly.Tablet.Alias.String(), "ks/-40"}); err != nil {
t.Fatalf("CopySchemaShard failed: %v", err)
}
}