Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request vitessio#733 from youtube/log
Browse files Browse the repository at this point in the history
Using right DBA abstraction in copy_schema_shard_test.go.
  • Loading branch information
alainjobart committed May 29, 2015
2 parents 73514f0 + 8058dd0 commit a7ef3b1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 42 deletions.
3 changes: 0 additions & 3 deletions go/vt/mysqlctl/mysql_daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
60 changes: 21 additions & 39 deletions go/vt/wrangler/testlib/copy_schema_shard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -158,10 +126,24 @@ func TestCopySchemaShard(t *testing.T) {
},
}

destinationMaster.FakeMysqlDaemon.DbaConnectionFactory = DestinationsFactory(t)

if err := wr.CopySchemaShard(context.Background(), sourceRdonly.Tablet.Alias, nil, nil, true, "ks", "-40"); err != nil {
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 := vp.Run([]string{"CopySchemaShard", "-include-views", sourceRdonly.Tablet.Alias.String(), "ks/-40"}); err != nil {
t.Fatalf("CopySchemaShard failed: %v", err)
}

}

0 comments on commit a7ef3b1

Please sign in to comment.