本文整理汇总了Golang中github.com/youtube/vitess/go/vt/binlog/binlogplayer.RegisterClientFactory函数的典型用法代码示例。如果您正苦于以下问题:Golang RegisterClientFactory函数的具体用法?Golang RegisterClientFactory怎么用?Golang RegisterClientFactory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RegisterClientFactory函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestBinlogPlayerMapVerticalSplit
func TestBinlogPlayerMapVerticalSplit(t *testing.T) {
ts := zktestserver.New(t, []string{"cell1"})
ctx := context.Background()
// create the keyspaces, with one shard each
if err := ts.CreateKeyspace(ctx, "source", &topodatapb.Keyspace{}); err != nil {
t.Fatalf("CreateKeyspace failed: %v", err)
}
if err := ts.CreateKeyspace(ctx, "destination", &topodatapb.Keyspace{}); err != nil {
t.Fatalf("CreateKeyspace failed: %v", err)
}
for _, keyspace := range []string{"source", "destination"} {
if err := ts.CreateShard(ctx, keyspace, "0"); err != nil {
t.Fatalf("CreateShard failed: %v", err)
}
}
// create one replica remote tablet in source keyspace, we will
// use it as a source for filtered replication.
createSourceTablet(t, "test_vertical", ts, "source", "0")
// register a binlog player factory that will return the instances
// we want
clientSyncChannel := make(chan *fakeBinlogClient)
binlogplayer.RegisterClientFactory("test_vertical", func() binlogplayer.Client {
return <-clientSyncChannel
})
flag.Lookup("binlog_player_protocol").Value.Set("test_vertical")
// create the BinlogPlayerMap on the local tablet
// (note that local tablet is never in the topology, we don't
// need it there at all)
// The schema will be used to resolve the table wildcards.
mysqlDaemon := &mysqlctl.FakeMysqlDaemon{
MysqlPort: 3306,
Schema: &tabletmanagerdatapb.SchemaDefinition{
DatabaseSchema: "",
TableDefinitions: []*tabletmanagerdatapb.TableDefinition{
{
Name: "table1",
Columns: []string{"id", "msg", "keyspace_id"},
PrimaryKeyColumns: []string{"id"},
Type: tmutils.TableBaseTable,
},
{
Name: "funtables_one",
Columns: []string{"id", "msg", "keyspace_id"},
PrimaryKeyColumns: []string{"id"},
Type: tmutils.TableBaseTable,
},
{
Name: "excluded_table",
Columns: []string{"id", "msg", "keyspace_id"},
PrimaryKeyColumns: []string{"id"},
Type: tmutils.TableBaseTable,
},
},
},
}
vtClientSyncChannel := make(chan *binlogplayer.VtClientMock)
bpm := NewBinlogPlayerMap(ts, mysqlDaemon, func() binlogplayer.VtClient {
return <-vtClientSyncChannel
})
tablet := &topodatapb.Tablet{
Alias: &topodatapb.TabletAlias{
Cell: "cell1",
Uid: 1,
},
Keyspace: "destination",
Shard: "0",
}
si, err := ts.GetShard(ctx, "destination", "0")
if err != nil {
t.Fatalf("GetShard failed: %v", err)
}
si.SourceShards = []*topodatapb.Shard_SourceShard{
{
Uid: 1,
Keyspace: "source",
Shard: "0",
Tables: []string{
"table1",
"funtables_*",
},
},
}
if err := ts.UpdateShard(ctx, si); err != nil {
t.Fatalf("UpdateShard failed: %v", err)
}
// now we have a source, adding players
bpm.RefreshMap(ctx, tablet, si)
if !bpm.isRunningFilteredReplication() {
t.Errorf("isRunningFilteredReplication should be true")
}
// write a mocked vtClientMock that will be used to read the
// start position at first. Note this also synchronizes the player,
//.........这里部分代码省略.........
示例2: init
// Registration as a factory
func init() {
binlogplayer.RegisterClientFactory("grpc", func() binlogplayer.Client {
return &client{}
})
}
示例3: TestBinlogPlayerMapHorizontalSplitStopStartUntil
func TestBinlogPlayerMapHorizontalSplitStopStartUntil(t *testing.T) {
ts := zktestserver.New(t, []string{"cell1"})
ctx := context.Background()
// create the keyspace, a full set of covering shards,
// and a new split destination shard.
if err := ts.CreateKeyspace(ctx, "ks", &topodatapb.Keyspace{
ShardingColumnType: topodatapb.KeyspaceIdType_UINT64,
ShardingColumnName: "sharding_key",
}); err != nil {
t.Fatalf("CreateKeyspace failed: %v", err)
}
for _, shard := range []string{"-80", "80-", "40-60"} {
if err := ts.CreateShard(ctx, "ks", shard); err != nil {
t.Fatalf("CreateShard failed: %v", err)
}
}
// create one replica remote tablet in source shard, we will
// use it as a source for filtered replication.
createSourceTablet(t, "test_horizontal_until", ts, "ks", "-80")
// register a binlog player factory that will return the instances
// we want
clientSyncChannel := make(chan *fakeBinlogClient)
binlogplayer.RegisterClientFactory("test_horizontal_until", func() binlogplayer.Client {
return <-clientSyncChannel
})
flag.Lookup("binlog_player_protocol").Value.Set("test_horizontal_until")
// create the BinlogPlayerMap on the local tablet
// (note that local tablet is never in the topology, we don't
// need it there at all)
mysqlDaemon := &mysqlctl.FakeMysqlDaemon{MysqlPort: 3306}
vtClientSyncChannel := make(chan *binlogplayer.VtClientMock)
bpm := NewBinlogPlayerMap(ts, mysqlDaemon, func() binlogplayer.VtClient {
return <-vtClientSyncChannel
})
tablet := &topodatapb.Tablet{
Alias: &topodatapb.TabletAlias{
Cell: "cell1",
Uid: 1,
},
KeyRange: &topodatapb.KeyRange{
Start: []byte{0x40},
End: []byte{0x60},
},
Keyspace: "ks",
Shard: "40-60",
}
si, err := ts.GetShard(ctx, "ks", "40-60")
if err != nil {
t.Fatalf("GetShard failed: %v", err)
}
si.SourceShards = []*topodatapb.Shard_SourceShard{
{
Uid: 1,
Keyspace: "ks",
Shard: "-80",
KeyRange: &topodatapb.KeyRange{
End: []byte{0x80},
},
},
}
if err := ts.UpdateShard(ctx, si); err != nil {
t.Fatalf("UpdateShard failed: %v", err)
}
// now we have a source, adding players
bpm.RefreshMap(ctx, tablet, si)
if !bpm.isRunningFilteredReplication() {
t.Errorf("isRunningFilteredReplication should be true")
}
// write a mocked vtClientMock that will be used to read the
// start position at first. Note this also synchronizes the player,
// so we can then check mysqlDaemon.BinlogPlayerEnabled.
vtClientMock := binlogplayer.NewVtClientMock()
vtClientMock.Result = &sqltypes.Result{
Fields: nil,
RowsAffected: 1,
InsertID: 0,
Rows: [][]sqltypes.Value{
{
sqltypes.MakeString([]byte("MariaDB/0-1-1234")),
sqltypes.MakeString([]byte("")),
},
},
}
vtClientSyncChannel <- vtClientMock
if !mysqlDaemon.BinlogPlayerEnabled {
t.Errorf("mysqlDaemon.BinlogPlayerEnabled should be true")
}
// the client will then try to connect to the remote tablet.
// give it what it needs.
fbc := newFakeBinlogClient(t, 100)
fbc.expectedKeyRange = "40-60"
//.........这里部分代码省略.........