зеркало из https://github.com/github/vitess-gh.git
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
Коммит
0b6b29f9d2
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/youtube/vitess/go/vt/tabletmanager/tmclient"
|
||||
"github.com/youtube/vitess/go/vt/tabletserver/grpcqueryservice"
|
||||
"github.com/youtube/vitess/go/vt/tabletserver/queryservice"
|
||||
"github.com/youtube/vitess/go/vt/vttest/fakesqldb"
|
||||
"github.com/youtube/vitess/go/vt/wrangler"
|
||||
"github.com/youtube/vitess/go/vt/wrangler/testlib"
|
||||
"github.com/youtube/vitess/go/vt/zktopo"
|
||||
|
@ -77,10 +78,11 @@ func (s *streamHealthTabletServer) BroadcastHealth(terTimestamp int64, stats *pb
|
|||
}
|
||||
|
||||
func TestTabletData(t *testing.T) {
|
||||
db := fakesqldb.Register()
|
||||
ts := zktopo.NewTestServer(t, []string{"cell1", "cell2"})
|
||||
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient(), time.Second)
|
||||
|
||||
tablet1 := testlib.NewFakeTablet(t, wr, "cell1", 0, pbt.TabletType_MASTER, testlib.TabletKeyspaceShard(t, "ks", "-80"))
|
||||
tablet1 := testlib.NewFakeTablet(t, wr, "cell1", 0, pbt.TabletType_MASTER, db, testlib.TabletKeyspaceShard(t, "ks", "-80"))
|
||||
tablet1.StartActionLoop(t, wr)
|
||||
defer tablet1.StopActionLoop(t)
|
||||
shsq := newStreamHealthTabletServer(t)
|
||||
|
|
|
@ -16,8 +16,7 @@ import (
|
|||
"github.com/youtube/vitess/go/vt/vtgate/bsonp3vtgateservice"
|
||||
)
|
||||
|
||||
// TestGoRPCGoClient tests the go client using goRPC
|
||||
func TestGoRPCGoClient(t *testing.T) {
|
||||
func TestBSONRPCP3GoClient(t *testing.T) {
|
||||
service := services.CreateServices()
|
||||
|
||||
// listen on a random port
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
// Copyright 2015 Google Inc. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package goclienttest
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/youtube/vitess/go/cmd/vtgateclienttest/services"
|
||||
"github.com/youtube/vitess/go/vt/callerid"
|
||||
"github.com/youtube/vitess/go/vt/vtgate/vtgateconn"
|
||||
"golang.org/x/net/context"
|
||||
|
||||
pb "github.com/youtube/vitess/go/vt/proto/topodata"
|
||||
)
|
||||
|
||||
// testCallerID adds a caller ID to a context, and makes sure the server
|
||||
// gets it.
|
||||
func testCallerID(t *testing.T, conn *vtgateconn.VTGateConn) {
|
||||
t.Log("testCallerID")
|
||||
ctx := context.Background()
|
||||
callerID := callerid.NewEffectiveCallerID("test_principal", "test_component", "test_subcomponent")
|
||||
ctx = callerid.NewContext(ctx, callerID, nil)
|
||||
|
||||
data, err := json.Marshal(callerID)
|
||||
if err != nil {
|
||||
t.Errorf("failed to marshal callerid: %v", err)
|
||||
return
|
||||
}
|
||||
query := services.CallerIDPrefix + string(data)
|
||||
|
||||
// test Execute forwards the callerID
|
||||
if _, err := conn.Execute(ctx, query, nil, pb.TabletType_MASTER); err != nil {
|
||||
if !strings.Contains(err.Error(), "SUCCESS: ") {
|
||||
t.Errorf("failed to pass callerid: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME(alainjobart) add all function calls
|
||||
}
|
|
@ -0,0 +1,384 @@
|
|||
// Copyright 2015 Google Inc. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package goclienttest
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/youtube/vitess/go/vt/callerid"
|
||||
"github.com/youtube/vitess/go/vt/key"
|
||||
"github.com/youtube/vitess/go/vt/vtgate/vtgateconn"
|
||||
|
||||
mproto "github.com/youtube/vitess/go/mysql/proto"
|
||||
tproto "github.com/youtube/vitess/go/vt/tabletserver/proto"
|
||||
gproto "github.com/youtube/vitess/go/vt/vtgate/proto"
|
||||
|
||||
pbt "github.com/youtube/vitess/go/vt/proto/topodata"
|
||||
pbg "github.com/youtube/vitess/go/vt/proto/vtgate"
|
||||
)
|
||||
|
||||
var (
|
||||
echoPrefix = "echo://"
|
||||
|
||||
query = "test query"
|
||||
keyspace = "test_keyspace"
|
||||
|
||||
shards = []string{"-80", "80-"}
|
||||
shardsEcho = "[-80 80-]"
|
||||
|
||||
keyspaceIDs = [][]byte{
|
||||
[]byte{1, 2, 3, 4},
|
||||
[]byte{5, 6, 7, 8},
|
||||
}
|
||||
keyspaceIDsEcho = "[[1 2 3 4] [5 6 7 8]]"
|
||||
keyspaceIDsEchoOld = "[01020304 05060708]"
|
||||
|
||||
keyRanges = []*pbt.KeyRange{
|
||||
&pbt.KeyRange{Start: []byte{1, 2, 3, 4}, End: []byte{5, 6, 7, 8}},
|
||||
}
|
||||
keyRangesEcho = "[start:\"\\001\\002\\003\\004\" end:\"\\005\\006\\007\\010\" ]"
|
||||
|
||||
entityKeyspaceIDs = []*pbg.ExecuteEntityIdsRequest_EntityId{
|
||||
&pbg.ExecuteEntityIdsRequest_EntityId{
|
||||
KeyspaceId: []byte{1, 2, 3},
|
||||
XidType: pbg.ExecuteEntityIdsRequest_EntityId_TYPE_INT,
|
||||
XidInt: 123,
|
||||
},
|
||||
&pbg.ExecuteEntityIdsRequest_EntityId{
|
||||
KeyspaceId: []byte{4, 5, 6},
|
||||
XidType: pbg.ExecuteEntityIdsRequest_EntityId_TYPE_FLOAT,
|
||||
XidFloat: 2.0,
|
||||
},
|
||||
&pbg.ExecuteEntityIdsRequest_EntityId{
|
||||
KeyspaceId: []byte{7, 8, 9},
|
||||
XidType: pbg.ExecuteEntityIdsRequest_EntityId_TYPE_BYTES,
|
||||
XidBytes: []byte{1, 2, 3},
|
||||
},
|
||||
}
|
||||
entityKeyspaceIDsEcho = "[xid_type:TYPE_INT xid_int:123 keyspace_id:\"\\001\\002\\003\" xid_type:TYPE_FLOAT xid_float:2 keyspace_id:\"\\004\\005\\006\" xid_type:TYPE_BYTES xid_bytes:\"\\001\\002\\003\" keyspace_id:\"\\007\\010\\t\" ]"
|
||||
|
||||
tabletType = pbt.TabletType_REPLICA
|
||||
tabletTypeEcho = pbt.TabletType_name[int32(tabletType)]
|
||||
|
||||
bindVars = map[string]interface{}{
|
||||
"int": 123,
|
||||
"float": 2.0,
|
||||
"bytes": []byte{1, 2, 3},
|
||||
}
|
||||
bindVarsEcho = "map[bytes:[1 2 3] float:2 int:123]"
|
||||
|
||||
sessionEcho = "InTransaction: true, ShardSession: []"
|
||||
|
||||
callerID = callerid.NewEffectiveCallerID("test_principal", "test_component", "test_subcomponent")
|
||||
callerIDEcho = "principal:\"test_principal\" component:\"test_component\" subcomponent:\"test_subcomponent\" "
|
||||
)
|
||||
|
||||
// testEcho exercises the test cases provided by the "echo" service.
|
||||
func testEcho(t *testing.T, conn *vtgateconn.VTGateConn) {
|
||||
testEchoExecute(t, conn)
|
||||
testEchoStreamExecute(t, conn)
|
||||
testEchoTransactionExecute(t, conn)
|
||||
testEchoSplitQuery(t, conn)
|
||||
}
|
||||
|
||||
func testEchoExecute(t *testing.T, conn *vtgateconn.VTGateConn) {
|
||||
var qr *mproto.QueryResult
|
||||
var err error
|
||||
|
||||
ctx := callerid.NewContext(context.Background(), callerID, nil)
|
||||
|
||||
qr, err = conn.Execute(ctx, echoPrefix+query, bindVars, tabletType)
|
||||
checkEcho(t, "Execute", qr, err, map[string]string{
|
||||
"callerId": callerIDEcho,
|
||||
"query": echoPrefix + query,
|
||||
"bindVars": bindVarsEcho,
|
||||
"tabletType": tabletTypeEcho,
|
||||
})
|
||||
|
||||
qr, err = conn.ExecuteShards(ctx, echoPrefix+query, keyspace, shards, bindVars, tabletType)
|
||||
checkEcho(t, "ExecuteShards", qr, err, map[string]string{
|
||||
"callerId": callerIDEcho,
|
||||
"query": echoPrefix + query,
|
||||
"keyspace": keyspace,
|
||||
"shards": shardsEcho,
|
||||
"bindVars": bindVarsEcho,
|
||||
"tabletType": tabletTypeEcho,
|
||||
})
|
||||
|
||||
qr, err = conn.ExecuteKeyspaceIds(ctx, echoPrefix+query, keyspace, keyspaceIDs, bindVars, tabletType)
|
||||
checkEcho(t, "ExecuteKeyspaceIds", qr, err, map[string]string{
|
||||
"callerId": callerIDEcho,
|
||||
"query": echoPrefix + query,
|
||||
"keyspace": keyspace,
|
||||
"keyspaceIds": keyspaceIDsEcho,
|
||||
"bindVars": bindVarsEcho,
|
||||
"tabletType": tabletTypeEcho,
|
||||
})
|
||||
|
||||
qr, err = conn.ExecuteKeyRanges(ctx, echoPrefix+query, keyspace, keyRanges, bindVars, tabletType)
|
||||
checkEcho(t, "ExecuteKeyRanges", qr, err, map[string]string{
|
||||
"callerId": callerIDEcho,
|
||||
"query": echoPrefix + query,
|
||||
"keyspace": keyspace,
|
||||
"keyRanges": keyRangesEcho,
|
||||
"bindVars": bindVarsEcho,
|
||||
"tabletType": tabletTypeEcho,
|
||||
})
|
||||
|
||||
qr, err = conn.ExecuteEntityIds(ctx, echoPrefix+query, keyspace, "column1", entityKeyspaceIDs, bindVars, tabletType)
|
||||
checkEcho(t, "ExecuteEntityIds", qr, err, map[string]string{
|
||||
"callerId": callerIDEcho,
|
||||
"query": echoPrefix + query,
|
||||
"keyspace": keyspace,
|
||||
"entityColumnName": "column1",
|
||||
"entityIds": entityKeyspaceIDsEcho,
|
||||
"bindVars": bindVarsEcho,
|
||||
"tabletType": tabletTypeEcho,
|
||||
})
|
||||
|
||||
var qrs []mproto.QueryResult
|
||||
|
||||
qrs, err = conn.ExecuteBatchShards(ctx, []gproto.BoundShardQuery{
|
||||
gproto.BoundShardQuery{
|
||||
Sql: echoPrefix + query,
|
||||
Keyspace: keyspace,
|
||||
Shards: shards,
|
||||
BindVariables: bindVars,
|
||||
},
|
||||
}, tabletType, true)
|
||||
checkEcho(t, "ExecuteBatchShards", &qrs[0], err, map[string]string{
|
||||
"callerId": callerIDEcho,
|
||||
"query": echoPrefix + query,
|
||||
"keyspace": keyspace,
|
||||
"shards": shardsEcho,
|
||||
"bindVars": bindVarsEcho,
|
||||
"tabletType": tabletTypeEcho,
|
||||
"asTransaction": "true",
|
||||
})
|
||||
|
||||
qrs, err = conn.ExecuteBatchKeyspaceIds(ctx, []gproto.BoundKeyspaceIdQuery{
|
||||
gproto.BoundKeyspaceIdQuery{
|
||||
Sql: echoPrefix + query,
|
||||
Keyspace: keyspace,
|
||||
KeyspaceIds: key.ProtoToKeyspaceIds(keyspaceIDs),
|
||||
BindVariables: bindVars,
|
||||
},
|
||||
}, tabletType, true)
|
||||
checkEcho(t, "ExecuteBatchKeyspaceIds", &qrs[0], err, map[string]string{
|
||||
"callerId": callerIDEcho,
|
||||
"query": echoPrefix + query,
|
||||
"keyspace": keyspace,
|
||||
"keyspaceIds": keyspaceIDsEchoOld,
|
||||
"bindVars": bindVarsEcho,
|
||||
"tabletType": tabletTypeEcho,
|
||||
"asTransaction": "true",
|
||||
})
|
||||
}
|
||||
|
||||
func testEchoStreamExecute(t *testing.T, conn *vtgateconn.VTGateConn) {
|
||||
var qrc <-chan *mproto.QueryResult
|
||||
var err error
|
||||
|
||||
ctx := callerid.NewContext(context.Background(), callerID, nil)
|
||||
|
||||
qrc, _, err = conn.StreamExecute(ctx, echoPrefix+query, bindVars, tabletType)
|
||||
checkEcho(t, "StreamExecute", <-qrc, err, map[string]string{
|
||||
"callerId": callerIDEcho,
|
||||
"query": echoPrefix + query,
|
||||
"bindVars": bindVarsEcho,
|
||||
"tabletType": tabletTypeEcho,
|
||||
})
|
||||
|
||||
qrc, _, err = conn.StreamExecuteShards(ctx, echoPrefix+query, keyspace, shards, bindVars, tabletType)
|
||||
checkEcho(t, "StreamExecuteShards", <-qrc, err, map[string]string{
|
||||
"callerId": callerIDEcho,
|
||||
"query": echoPrefix + query,
|
||||
"keyspace": keyspace,
|
||||
"shards": shardsEcho,
|
||||
"bindVars": bindVarsEcho,
|
||||
"tabletType": tabletTypeEcho,
|
||||
})
|
||||
|
||||
qrc, _, err = conn.StreamExecuteKeyspaceIds(ctx, echoPrefix+query, keyspace, keyspaceIDs, bindVars, tabletType)
|
||||
checkEcho(t, "StreamExecuteKeyspaceIds", <-qrc, err, map[string]string{
|
||||
"callerId": callerIDEcho,
|
||||
"query": echoPrefix + query,
|
||||
"keyspace": keyspace,
|
||||
"keyspaceIds": keyspaceIDsEcho,
|
||||
"bindVars": bindVarsEcho,
|
||||
"tabletType": tabletTypeEcho,
|
||||
})
|
||||
|
||||
qrc, _, err = conn.StreamExecuteKeyRanges(ctx, echoPrefix+query, keyspace, keyRanges, bindVars, tabletType)
|
||||
checkEcho(t, "StreamExecuteKeyRanges", <-qrc, err, map[string]string{
|
||||
"callerId": callerIDEcho,
|
||||
"query": echoPrefix + query,
|
||||
"keyspace": keyspace,
|
||||
"keyRanges": keyRangesEcho,
|
||||
"bindVars": bindVarsEcho,
|
||||
"tabletType": tabletTypeEcho,
|
||||
})
|
||||
}
|
||||
|
||||
func testEchoTransactionExecute(t *testing.T, conn *vtgateconn.VTGateConn) {
|
||||
var qr *mproto.QueryResult
|
||||
var err error
|
||||
|
||||
ctx := callerid.NewContext(context.Background(), callerID, nil)
|
||||
|
||||
tx, err := conn.Begin(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("Begin error: %v", err)
|
||||
}
|
||||
|
||||
qr, err = tx.Execute(ctx, echoPrefix+query, bindVars, tabletType, true)
|
||||
checkEcho(t, "Execute", qr, err, map[string]string{
|
||||
"callerId": callerIDEcho,
|
||||
"query": echoPrefix + query,
|
||||
"bindVars": bindVarsEcho,
|
||||
"tabletType": tabletTypeEcho,
|
||||
"session": sessionEcho,
|
||||
"notInTransaction": "true",
|
||||
})
|
||||
|
||||
qr, err = tx.ExecuteShards(ctx, echoPrefix+query, keyspace, shards, bindVars, tabletType, true)
|
||||
checkEcho(t, "ExecuteShards", qr, err, map[string]string{
|
||||
"callerId": callerIDEcho,
|
||||
"query": echoPrefix + query,
|
||||
"keyspace": keyspace,
|
||||
"shards": shardsEcho,
|
||||
"bindVars": bindVarsEcho,
|
||||
"tabletType": tabletTypeEcho,
|
||||
"session": sessionEcho,
|
||||
"notInTransaction": "true",
|
||||
})
|
||||
|
||||
qr, err = tx.ExecuteKeyspaceIds(ctx, echoPrefix+query, keyspace, keyspaceIDs, bindVars, tabletType, true)
|
||||
checkEcho(t, "ExecuteKeyspaceIds", qr, err, map[string]string{
|
||||
"callerId": callerIDEcho,
|
||||
"query": echoPrefix + query,
|
||||
"keyspace": keyspace,
|
||||
"keyspaceIds": keyspaceIDsEcho,
|
||||
"bindVars": bindVarsEcho,
|
||||
"tabletType": tabletTypeEcho,
|
||||
"session": sessionEcho,
|
||||
"notInTransaction": "true",
|
||||
})
|
||||
|
||||
qr, err = tx.ExecuteKeyRanges(ctx, echoPrefix+query, keyspace, keyRanges, bindVars, tabletType, true)
|
||||
checkEcho(t, "ExecuteKeyRanges", qr, err, map[string]string{
|
||||
"callerId": callerIDEcho,
|
||||
"query": echoPrefix + query,
|
||||
"keyspace": keyspace,
|
||||
"keyRanges": keyRangesEcho,
|
||||
"bindVars": bindVarsEcho,
|
||||
"tabletType": tabletTypeEcho,
|
||||
"session": sessionEcho,
|
||||
"notInTransaction": "true",
|
||||
})
|
||||
|
||||
qr, err = tx.ExecuteEntityIds(ctx, echoPrefix+query, keyspace, "column1", entityKeyspaceIDs, bindVars, tabletType, true)
|
||||
checkEcho(t, "ExecuteEntityIds", qr, err, map[string]string{
|
||||
"callerId": callerIDEcho,
|
||||
"query": echoPrefix + query,
|
||||
"keyspace": keyspace,
|
||||
"entityColumnName": "column1",
|
||||
"entityIds": entityKeyspaceIDsEcho,
|
||||
"bindVars": bindVarsEcho,
|
||||
"tabletType": tabletTypeEcho,
|
||||
"session": sessionEcho,
|
||||
"notInTransaction": "true",
|
||||
})
|
||||
|
||||
if err := tx.Rollback(ctx); err != nil {
|
||||
t.Fatalf("Rollback error: %v", err)
|
||||
}
|
||||
tx, err = conn.Begin(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("Begin (again) error: %v", err)
|
||||
}
|
||||
|
||||
var qrs []mproto.QueryResult
|
||||
|
||||
qrs, err = tx.ExecuteBatchShards(ctx, []gproto.BoundShardQuery{
|
||||
gproto.BoundShardQuery{
|
||||
Sql: echoPrefix + query,
|
||||
Keyspace: keyspace,
|
||||
Shards: shards,
|
||||
BindVariables: bindVars,
|
||||
},
|
||||
}, tabletType, true)
|
||||
checkEcho(t, "ExecuteBatchShards", &qrs[0], err, map[string]string{
|
||||
"callerId": callerIDEcho,
|
||||
"query": echoPrefix + query,
|
||||
"keyspace": keyspace,
|
||||
"shards": shardsEcho,
|
||||
"bindVars": bindVarsEcho,
|
||||
"tabletType": tabletTypeEcho,
|
||||
"session": sessionEcho,
|
||||
"asTransaction": "true",
|
||||
})
|
||||
|
||||
qrs, err = tx.ExecuteBatchKeyspaceIds(ctx, []gproto.BoundKeyspaceIdQuery{
|
||||
gproto.BoundKeyspaceIdQuery{
|
||||
Sql: echoPrefix + query,
|
||||
Keyspace: keyspace,
|
||||
KeyspaceIds: key.ProtoToKeyspaceIds(keyspaceIDs),
|
||||
BindVariables: bindVars,
|
||||
},
|
||||
}, tabletType, true)
|
||||
checkEcho(t, "ExecuteBatchKeyspaceIds", &qrs[0], err, map[string]string{
|
||||
"callerId": callerIDEcho,
|
||||
"query": echoPrefix + query,
|
||||
"keyspace": keyspace,
|
||||
"keyspaceIds": keyspaceIDsEchoOld,
|
||||
"bindVars": bindVarsEcho,
|
||||
"tabletType": tabletTypeEcho,
|
||||
"session": sessionEcho,
|
||||
"asTransaction": "true",
|
||||
})
|
||||
}
|
||||
|
||||
func testEchoSplitQuery(t *testing.T, conn *vtgateconn.VTGateConn) {
|
||||
want := &pbg.SplitQueryResponse_Part{
|
||||
Query: tproto.BoundQueryToProto3(echoPrefix+query+":split_column:123", bindVars),
|
||||
KeyRangePart: &pbg.SplitQueryResponse_KeyRangePart{Keyspace: keyspace},
|
||||
}
|
||||
got, err := conn.SplitQuery(context.Background(), keyspace, echoPrefix+query, bindVars, "split_column", 123)
|
||||
if err != nil {
|
||||
t.Fatalf("SplitQuery error: %v", err)
|
||||
}
|
||||
// For some reason, proto.Equal() is calling them unequal even though no diffs
|
||||
// are found.
|
||||
gotstr, wantstr := got[0].String(), want.String()
|
||||
if gotstr != wantstr {
|
||||
t.Errorf("SplitQuery() = %v, want %v", gotstr, wantstr)
|
||||
}
|
||||
}
|
||||
|
||||
// getEcho extracts the echoed field values from a query result.
|
||||
func getEcho(qr *mproto.QueryResult) map[string]string {
|
||||
values := map[string]string{}
|
||||
for i, field := range qr.Fields {
|
||||
values[field.Name] = qr.Rows[0][i].String()
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
// checkEcho verifies that the values present in 'want' are equal to those in
|
||||
// 'got'. Note that extra values in 'got' are fine.
|
||||
func checkEcho(t *testing.T, name string, qr *mproto.QueryResult, err error, want map[string]string) {
|
||||
if err != nil {
|
||||
t.Fatalf("%v error: %v", name, err)
|
||||
}
|
||||
got := getEcho(qr)
|
||||
for k, v := range want {
|
||||
if got[k] != v {
|
||||
t.Errorf("%v: %v = %q, want %q", name, k, got[k], v)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright 2015 Google Inc. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package goclienttest
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/youtube/vitess/go/vt/vtgate/vtgateconn"
|
||||
)
|
||||
|
||||
// testErrors exercises the test cases provided by the "errors" service.
|
||||
func testErrors(t *testing.T, conn *vtgateconn.VTGateConn) {
|
||||
|
||||
}
|
|
@ -5,17 +5,11 @@
|
|||
package goclienttest
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/youtube/vitess/go/cmd/vtgateclienttest/services"
|
||||
"github.com/youtube/vitess/go/vt/callerid"
|
||||
"github.com/youtube/vitess/go/vt/vtgate/vtgateconn"
|
||||
"golang.org/x/net/context"
|
||||
|
||||
pb "github.com/youtube/vitess/go/vt/proto/topodata"
|
||||
)
|
||||
|
||||
// This file contains the reference test for clients. It tests
|
||||
|
@ -26,31 +20,6 @@ import (
|
|||
//
|
||||
// TODO(team) add more unit test cases.
|
||||
|
||||
// testCallerID adds a caller ID to a context, and makes sure the server
|
||||
// gets it.
|
||||
func testCallerID(t *testing.T, conn *vtgateconn.VTGateConn) {
|
||||
t.Log("testCallerID")
|
||||
ctx := context.Background()
|
||||
callerID := callerid.NewEffectiveCallerID("test_principal", "test_component", "test_subcomponent")
|
||||
ctx = callerid.NewContext(ctx, callerID, nil)
|
||||
|
||||
data, err := json.Marshal(callerID)
|
||||
if err != nil {
|
||||
t.Errorf("failed to marshal callerid: %v", err)
|
||||
return
|
||||
}
|
||||
query := services.CallerIDPrefix + string(data)
|
||||
|
||||
// test Execute forwards the callerID
|
||||
if _, err := conn.Execute(ctx, query, nil, pb.TabletType_MASTER); err != nil {
|
||||
if !strings.Contains(err.Error(), "SUCCESS: ") {
|
||||
t.Errorf("failed to pass callerid: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME(alainjobart) add all function calls
|
||||
}
|
||||
|
||||
// TestGoClient runs the test suite for the provided client
|
||||
func TestGoClient(t *testing.T, protocol, addr string) {
|
||||
// Create a client connecting to the server
|
||||
|
@ -61,6 +30,9 @@ func TestGoClient(t *testing.T, protocol, addr string) {
|
|||
}
|
||||
|
||||
testCallerID(t, conn)
|
||||
testEcho(t, conn)
|
||||
testErrors(t, conn)
|
||||
testSuccess(t, conn)
|
||||
|
||||
// and clean up
|
||||
conn.Close()
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
// Copyright 2015 Google Inc. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package goclienttest
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/youtube/vitess/go/vt/vtgate/vtgateconn"
|
||||
|
||||
pbt "github.com/youtube/vitess/go/vt/proto/topodata"
|
||||
)
|
||||
|
||||
// testSuccess exercises the test cases provided by the "success" service.
|
||||
func testSuccess(t *testing.T, conn *vtgateconn.VTGateConn) {
|
||||
testGetSrvKeyspace(t, conn)
|
||||
}
|
||||
|
||||
func testGetSrvKeyspace(t *testing.T, conn *vtgateconn.VTGateConn) {
|
||||
want := &pbt.SrvKeyspace{
|
||||
Partitions: []*pbt.SrvKeyspace_KeyspacePartition{
|
||||
&pbt.SrvKeyspace_KeyspacePartition{
|
||||
ServedType: pbt.TabletType_REPLICA,
|
||||
ShardReferences: []*pbt.ShardReference{
|
||||
&pbt.ShardReference{
|
||||
Name: "shard0",
|
||||
KeyRange: &pbt.KeyRange{
|
||||
Start: []byte{0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
End: []byte{0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
ShardingColumnName: "sharding_column_name",
|
||||
ShardingColumnType: pbt.KeyspaceIdType_UINT64,
|
||||
ServedFrom: []*pbt.SrvKeyspace_ServedFrom{
|
||||
&pbt.SrvKeyspace_ServedFrom{
|
||||
TabletType: pbt.TabletType_MASTER,
|
||||
Keyspace: "other_keyspace",
|
||||
},
|
||||
},
|
||||
SplitShardCount: 128,
|
||||
}
|
||||
got, err := conn.GetSrvKeyspace(context.Background(), "big")
|
||||
if err != nil {
|
||||
t.Fatalf("GetSrvKeyspace error: %v", err)
|
||||
}
|
||||
if !proto.Equal(got, want) {
|
||||
t.Errorf("GetSrvKeyspace() = %v, want %v", proto.MarshalTextString(got), proto.MarshalTextString(want))
|
||||
}
|
||||
}
|
|
@ -34,7 +34,7 @@ const (
|
|||
func init() {
|
||||
// This needs to be called before threads begin to spawn.
|
||||
C.vt_library_init()
|
||||
sqldb.Register("mysql", Connect)
|
||||
sqldb.RegisterDefault(Connect)
|
||||
}
|
||||
|
||||
const (
|
||||
|
|
|
@ -17,13 +17,13 @@ import (
|
|||
// using given ConnParams.
|
||||
type NewConnFunc func(params ConnParams) (Conn, error)
|
||||
|
||||
// conns stores all supported db connection.
|
||||
var conns = make(map[string]NewConnFunc)
|
||||
var (
|
||||
defaultConn NewConnFunc
|
||||
|
||||
var mu sync.Mutex
|
||||
|
||||
// DefaultDB decides the default db connection.
|
||||
var DefaultDB string
|
||||
// mu protects conns.
|
||||
mu sync.Mutex
|
||||
conns = make(map[string]NewConnFunc)
|
||||
)
|
||||
|
||||
// Conn defines the behavior for the low level db connection
|
||||
type Conn interface {
|
||||
|
@ -61,7 +61,16 @@ type Conn interface {
|
|||
SetCharset(cs proto.Charset) error
|
||||
}
|
||||
|
||||
// Register a db connection.
|
||||
// RegisterDefault registers the default connection function.
|
||||
// Only one default can be registered.
|
||||
func RegisterDefault(fn NewConnFunc) {
|
||||
if defaultConn != nil {
|
||||
panic("default connection initialized more than once")
|
||||
}
|
||||
defaultConn = fn
|
||||
}
|
||||
|
||||
// Register registers a db connection.
|
||||
func Register(name string, fn NewConnFunc) {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
@ -73,20 +82,15 @@ func Register(name string, fn NewConnFunc) {
|
|||
|
||||
// Connect returns a sqldb.Conn using the default connection creation function.
|
||||
func Connect(params ConnParams) (Conn, error) {
|
||||
// Use a lock-free fast path for default.
|
||||
if params.Engine == "" {
|
||||
return defaultConn(params)
|
||||
}
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if DefaultDB == "" {
|
||||
if len(conns) == 1 {
|
||||
for _, fn := range conns {
|
||||
return fn(params)
|
||||
}
|
||||
}
|
||||
panic("there are more than one conn func " +
|
||||
"registered but no default db has been given.")
|
||||
}
|
||||
fn, ok := conns[DefaultDB]
|
||||
fn, ok := conns[params.Engine]
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("connection function for given default db: %s is not found.", DefaultDB))
|
||||
panic(fmt.Sprintf("connection function not found for engine: %s", params.Engine))
|
||||
}
|
||||
return fn(params)
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ package sqldb
|
|||
|
||||
// ConnParams contains all the parameters to use to connect to mysql
|
||||
type ConnParams struct {
|
||||
Engine string `json:"engine"`
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
Uname string `json:"uname"`
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
"github.com/youtube/vitess/go/stats"
|
||||
"github.com/youtube/vitess/go/vt/dbconnpool"
|
||||
"github.com/youtube/vitess/go/vt/mysqlctl/proto"
|
||||
"github.com/youtube/vitess/go/vt/vttest/fakesqldb"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
@ -87,6 +88,8 @@ type MysqlDaemon interface {
|
|||
// FakeMysqlDaemon implements MysqlDaemon and allows the user to fake
|
||||
// everything.
|
||||
type FakeMysqlDaemon struct {
|
||||
db *fakesqldb.DB
|
||||
|
||||
// Mycnf will be returned by Cnf()
|
||||
Mycnf *Mycnf
|
||||
|
||||
|
@ -185,8 +188,9 @@ type FakeMysqlDaemon struct {
|
|||
|
||||
// NewFakeMysqlDaemon returns a FakeMysqlDaemon where mysqld appears
|
||||
// to be running
|
||||
func NewFakeMysqlDaemon() *FakeMysqlDaemon {
|
||||
func NewFakeMysqlDaemon(db *fakesqldb.DB) *FakeMysqlDaemon {
|
||||
return &FakeMysqlDaemon{
|
||||
db: db,
|
||||
Running: true,
|
||||
}
|
||||
}
|
||||
|
@ -417,5 +421,5 @@ func (fmd *FakeMysqlDaemon) GetAppConnection() (dbconnpool.PoolConnection, error
|
|||
|
||||
// GetDbaConnection is part of the MysqlDaemon interface.
|
||||
func (fmd *FakeMysqlDaemon) GetDbaConnection() (*dbconnpool.DBConnection, error) {
|
||||
return dbconnpool.NewDBConnection(&sqldb.ConnParams{}, stats.NewTimings(""))
|
||||
return dbconnpool.NewDBConnection(&sqldb.ConnParams{Engine: fmd.db.Name}, stats.NewTimings(""))
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/youtube/vitess/go/history"
|
||||
"github.com/youtube/vitess/go/stats"
|
||||
"github.com/youtube/vitess/go/vt/mysqlctl"
|
||||
"github.com/youtube/vitess/go/vt/vttest/fakesqldb"
|
||||
"github.com/youtube/vitess/go/vt/zktopo"
|
||||
"golang.org/x/net/context"
|
||||
|
||||
|
@ -24,6 +25,7 @@ import (
|
|||
// so this has to be in one test.
|
||||
func TestInitTablet(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db := fakesqldb.Register()
|
||||
ts := zktopo.NewTestServer(t, []string{"cell1", "cell2"})
|
||||
tabletAlias := &pb.TabletAlias{
|
||||
Cell: "cell1",
|
||||
|
@ -33,7 +35,7 @@ func TestInitTablet(t *testing.T) {
|
|||
// start with idle, and a tablet record that doesn't exist
|
||||
port := int32(1234)
|
||||
gRPCPort := int32(3456)
|
||||
mysqlDaemon := mysqlctl.NewFakeMysqlDaemon()
|
||||
mysqlDaemon := mysqlctl.NewFakeMysqlDaemon(db)
|
||||
agent := &ActionAgent{
|
||||
TopoServer: ts,
|
||||
TabletAlias: tabletAlias,
|
||||
|
|
|
@ -14,10 +14,10 @@ import (
|
|||
)
|
||||
|
||||
func TestConnPoolGet(t *testing.T) {
|
||||
fakesqldb.Register()
|
||||
db := fakesqldb.Register()
|
||||
testUtils := newTestUtils()
|
||||
appParams := &sqldb.ConnParams{}
|
||||
dbaParams := &sqldb.ConnParams{}
|
||||
appParams := &sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := &sqldb.ConnParams{Engine: db.Name}
|
||||
connPool := testUtils.newConnPool()
|
||||
connPool.Open(appParams, dbaParams)
|
||||
defer connPool.Close()
|
||||
|
@ -44,10 +44,10 @@ func TestConnPoolPutWhilePoolIsClosed(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestConnPoolSetCapacity(t *testing.T) {
|
||||
fakesqldb.Register()
|
||||
db := fakesqldb.Register()
|
||||
testUtils := newTestUtils()
|
||||
appParams := &sqldb.ConnParams{}
|
||||
dbaParams := &sqldb.ConnParams{}
|
||||
appParams := &sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := &sqldb.ConnParams{Engine: db.Name}
|
||||
connPool := testUtils.newConnPool()
|
||||
connPool.Open(appParams, dbaParams)
|
||||
defer connPool.Close()
|
||||
|
@ -65,14 +65,14 @@ func TestConnPoolSetCapacity(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestConnPoolStatJSON(t *testing.T) {
|
||||
fakesqldb.Register()
|
||||
db := fakesqldb.Register()
|
||||
testUtils := newTestUtils()
|
||||
connPool := testUtils.newConnPool()
|
||||
if connPool.StatsJSON() != "{}" {
|
||||
t.Fatalf("pool is closed, stats json should be empty: {}")
|
||||
}
|
||||
appParams := &sqldb.ConnParams{}
|
||||
dbaParams := &sqldb.ConnParams{}
|
||||
appParams := &sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := &sqldb.ConnParams{Engine: db.Name}
|
||||
connPool.Open(appParams, dbaParams)
|
||||
defer connPool.Close()
|
||||
statsJSON := connPool.StatsJSON()
|
||||
|
@ -106,10 +106,10 @@ func TestConnPoolStateWhilePoolIsClosed(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestConnPoolStateWhilePoolIsOpen(t *testing.T) {
|
||||
fakesqldb.Register()
|
||||
db := fakesqldb.Register()
|
||||
testUtils := newTestUtils()
|
||||
appParams := &sqldb.ConnParams{}
|
||||
dbaParams := &sqldb.ConnParams{}
|
||||
appParams := &sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := &sqldb.ConnParams{Engine: db.Name}
|
||||
idleTimeout := 10 * time.Second
|
||||
connPool := testUtils.newConnPool()
|
||||
connPool.Open(appParams, dbaParams)
|
||||
|
|
|
@ -28,8 +28,8 @@ func TestDBConnExec(t *testing.T) {
|
|||
}
|
||||
db.AddQuery(sql, expectedResult)
|
||||
connPool := testUtils.newConnPool()
|
||||
appParams := &sqldb.ConnParams{}
|
||||
dbaParams := &sqldb.ConnParams{}
|
||||
appParams := &sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := &sqldb.ConnParams{Engine: db.Name}
|
||||
connPool.Open(appParams, dbaParams)
|
||||
defer connPool.Close()
|
||||
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(10*time.Second))
|
||||
|
@ -57,8 +57,8 @@ func TestDBConnKill(t *testing.T) {
|
|||
db := fakesqldb.Register()
|
||||
testUtils := newTestUtils()
|
||||
connPool := testUtils.newConnPool()
|
||||
appParams := &sqldb.ConnParams{}
|
||||
dbaParams := &sqldb.ConnParams{}
|
||||
appParams := &sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := &sqldb.ConnParams{Engine: db.Name}
|
||||
connPool.Open(appParams, dbaParams)
|
||||
defer connPool.Close()
|
||||
queryServiceStats := NewQueryServiceStats("", false)
|
||||
|
@ -102,8 +102,8 @@ func TestDBConnStream(t *testing.T) {
|
|||
}
|
||||
db.AddQuery(sql, expectedResult)
|
||||
connPool := testUtils.newConnPool()
|
||||
appParams := &sqldb.ConnParams{}
|
||||
dbaParams := &sqldb.ConnParams{}
|
||||
appParams := &sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := &sqldb.ConnParams{Engine: db.Name}
|
||||
connPool.Open(appParams, dbaParams)
|
||||
defer connPool.Close()
|
||||
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(10*time.Second))
|
||||
|
|
|
@ -38,7 +38,7 @@ func TestQueryExecutorPlanDDL(t *testing.T) {
|
|||
}
|
||||
db.AddQuery(query, want)
|
||||
ctx := context.Background()
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
defer tsv.StopService()
|
||||
checkPlanID(t, planbuilder.PLAN_DDL, qre.plan.PlanId)
|
||||
|
@ -60,7 +60,7 @@ func TestQueryExecutorPlanPassDmlStrictMode(t *testing.T) {
|
|||
db.AddQuery(query, want)
|
||||
ctx := context.Background()
|
||||
// non strict mode
|
||||
tsv := newTestTabletServer(ctx, noFlags)
|
||||
tsv := newTestTabletServer(ctx, noFlags, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, newTransaction(tsv))
|
||||
checkPlanID(t, planbuilder.PLAN_PASS_DML, qre.plan.PlanId)
|
||||
got, err := qre.Execute()
|
||||
|
@ -74,7 +74,7 @@ func TestQueryExecutorPlanPassDmlStrictMode(t *testing.T) {
|
|||
tsv.StopService()
|
||||
|
||||
// strict mode
|
||||
tsv = newTestTabletServer(ctx, enableRowCache|enableStrict)
|
||||
tsv = newTestTabletServer(ctx, enableRowCache|enableStrict, db)
|
||||
qre = newTestQueryExecutor(ctx, tsv, query, newTransaction(tsv))
|
||||
defer tsv.StopService()
|
||||
defer testCommitHelper(t, tsv, qre)
|
||||
|
@ -101,7 +101,7 @@ func TestQueryExecutorPlanPassDmlStrictModeAutoCommit(t *testing.T) {
|
|||
db.AddQuery(query, want)
|
||||
// non strict mode
|
||||
ctx := context.Background()
|
||||
tsv := newTestTabletServer(ctx, noFlags)
|
||||
tsv := newTestTabletServer(ctx, noFlags, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
checkPlanID(t, planbuilder.PLAN_PASS_DML, qre.plan.PlanId)
|
||||
got, err := qre.Execute()
|
||||
|
@ -115,7 +115,7 @@ func TestQueryExecutorPlanPassDmlStrictModeAutoCommit(t *testing.T) {
|
|||
|
||||
// strict mode
|
||||
// update should fail because strict mode is not enabled
|
||||
tsv = newTestTabletServer(ctx, enableRowCache|enableStrict)
|
||||
tsv = newTestTabletServer(ctx, enableRowCache|enableStrict, db)
|
||||
qre = newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
defer tsv.StopService()
|
||||
checkPlanID(t, planbuilder.PLAN_PASS_DML, qre.plan.PlanId)
|
||||
|
@ -140,7 +140,7 @@ func TestQueryExecutorPlanInsertPk(t *testing.T) {
|
|||
}
|
||||
query := "insert into test_table values(1)"
|
||||
ctx := context.Background()
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
defer tsv.StopService()
|
||||
checkPlanID(t, planbuilder.PLAN_INSERT_PK, qre.plan.PlanId)
|
||||
|
@ -172,7 +172,7 @@ func TestQueryExecutorPlanInsertSubQueryAutoCommmit(t *testing.T) {
|
|||
|
||||
db.AddQuery(insertQuery, &mproto.QueryResult{})
|
||||
ctx := context.Background()
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
defer tsv.StopService()
|
||||
checkPlanID(t, planbuilder.PLAN_INSERT_SUBQUERY, qre.plan.PlanId)
|
||||
|
@ -204,7 +204,7 @@ func TestQueryExecutorPlanInsertSubQuery(t *testing.T) {
|
|||
|
||||
db.AddQuery(insertQuery, &mproto.QueryResult{})
|
||||
ctx := context.Background()
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, newTransaction(tsv))
|
||||
|
||||
defer tsv.StopService()
|
||||
|
@ -227,7 +227,7 @@ func TestQueryExecutorPlanUpsertPk(t *testing.T) {
|
|||
}
|
||||
query := "insert into test_table values(1) on duplicate key update val=1"
|
||||
ctx := context.Background()
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
defer tsv.StopService()
|
||||
checkPlanID(t, planbuilder.PLAN_UPSERT_PK, qre.plan.PlanId)
|
||||
|
@ -283,7 +283,7 @@ func TestQueryExecutorPlanDmlPk(t *testing.T) {
|
|||
want := &mproto.QueryResult{}
|
||||
db.AddQuery(query, want)
|
||||
ctx := context.Background()
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, newTransaction(tsv))
|
||||
defer tsv.StopService()
|
||||
defer testCommitHelper(t, tsv, qre)
|
||||
|
@ -303,7 +303,7 @@ func TestQueryExecutorPlanDmlAutoCommit(t *testing.T) {
|
|||
want := &mproto.QueryResult{}
|
||||
db.AddQuery(query, want)
|
||||
ctx := context.Background()
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
defer tsv.StopService()
|
||||
checkPlanID(t, planbuilder.PLAN_DML_PK, qre.plan.PlanId)
|
||||
|
@ -324,7 +324,7 @@ func TestQueryExecutorPlanDmlSubQuery(t *testing.T) {
|
|||
db.AddQuery(query, want)
|
||||
db.AddQuery(expandedQuery, want)
|
||||
ctx := context.Background()
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, newTransaction(tsv))
|
||||
defer tsv.StopService()
|
||||
defer testCommitHelper(t, tsv, qre)
|
||||
|
@ -346,7 +346,7 @@ func TestQueryExecutorPlanDmlSubQueryAutoCommit(t *testing.T) {
|
|||
db.AddQuery(query, want)
|
||||
db.AddQuery(expandedQuery, want)
|
||||
ctx := context.Background()
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
defer tsv.StopService()
|
||||
checkPlanID(t, planbuilder.PLAN_DML_SUBQUERY, qre.plan.PlanId)
|
||||
|
@ -369,7 +369,7 @@ func TestQueryExecutorPlanOtherWithinATransaction(t *testing.T) {
|
|||
}
|
||||
db.AddQuery(query, want)
|
||||
ctx := context.Background()
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableSchemaOverrides|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableSchemaOverrides|enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, newTransaction(tsv))
|
||||
defer tsv.StopService()
|
||||
defer testCommitHelper(t, tsv, qre)
|
||||
|
@ -401,7 +401,7 @@ func TestQueryExecutorPlanPassSelectWithInATransaction(t *testing.T) {
|
|||
Fields: fields,
|
||||
})
|
||||
ctx := context.Background()
|
||||
tsv := newTestTabletServer(ctx, enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, newTransaction(tsv))
|
||||
defer tsv.StopService()
|
||||
defer testCommitHelper(t, tsv, qre)
|
||||
|
@ -427,7 +427,7 @@ func TestQueryExecutorPlanPassSelectWithLockOutsideATransaction(t *testing.T) {
|
|||
Fields: getTestTableFields(),
|
||||
})
|
||||
ctx := context.Background()
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableSchemaOverrides|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableSchemaOverrides|enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
defer tsv.StopService()
|
||||
checkPlanID(t, planbuilder.PLAN_PASS_SELECT, qre.plan.PlanId)
|
||||
|
@ -456,7 +456,7 @@ func TestQueryExecutorPlanPassSelect(t *testing.T) {
|
|||
Fields: getTestTableFields(),
|
||||
})
|
||||
ctx := context.Background()
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableSchemaOverrides|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableSchemaOverrides|enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
defer tsv.StopService()
|
||||
checkPlanID(t, planbuilder.PLAN_PASS_SELECT, qre.plan.PlanId)
|
||||
|
@ -490,7 +490,7 @@ func TestQueryExecutorPlanPKIn(t *testing.T) {
|
|||
Fields: getTestTableFields(),
|
||||
})
|
||||
ctx := context.Background()
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableSchemaOverrides|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableSchemaOverrides|enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
defer tsv.StopService()
|
||||
checkPlanID(t, planbuilder.PLAN_PK_IN, qre.plan.PlanId)
|
||||
|
@ -542,7 +542,7 @@ func TestQueryExecutorPlanSelectSubQuery(t *testing.T) {
|
|||
Fields: getTestTableFields(),
|
||||
})
|
||||
ctx := context.Background()
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableSchemaOverrides|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableSchemaOverrides|enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
defer tsv.StopService()
|
||||
checkPlanID(t, planbuilder.PLAN_SELECT_SUBQUERY, qre.plan.PlanId)
|
||||
|
@ -560,7 +560,7 @@ func TestQueryExecutorPlanSet(t *testing.T) {
|
|||
setQuery := "set unknown_key = 1"
|
||||
db.AddQuery(setQuery, &mproto.QueryResult{})
|
||||
ctx := context.Background()
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict, db)
|
||||
defer tsv.StopService()
|
||||
qre := newTestQueryExecutor(ctx, tsv, setQuery, 0)
|
||||
checkPlanID(t, planbuilder.PLAN_SET, qre.plan.PlanId)
|
||||
|
@ -780,12 +780,12 @@ func TestQueryExecutorPlanSet(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestQueryExecutorPlanSetMaxResultSize(t *testing.T) {
|
||||
setUpQueryExecutorTest()
|
||||
db := setUpQueryExecutorTest()
|
||||
want := &mproto.QueryResult{}
|
||||
vtMaxResultSize := int64(128)
|
||||
query := fmt.Sprintf("set vt_max_result_size = %d", vtMaxResultSize)
|
||||
ctx := context.Background()
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
defer tsv.StopService()
|
||||
checkPlanID(t, planbuilder.PLAN_SET, qre.plan.PlanId)
|
||||
|
@ -802,10 +802,10 @@ func TestQueryExecutorPlanSetMaxResultSize(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestQueryExecutorPlanSetMaxResultSizeFail(t *testing.T) {
|
||||
setUpQueryExecutorTest()
|
||||
db := setUpQueryExecutorTest()
|
||||
query := "set vt_max_result_size = 0"
|
||||
ctx := context.Background()
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
defer tsv.StopService()
|
||||
checkPlanID(t, planbuilder.PLAN_SET, qre.plan.PlanId)
|
||||
|
@ -824,12 +824,12 @@ func TestQueryExecutorPlanSetMaxResultSizeFail(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestQueryExecutorPlanSetMaxDmlRows(t *testing.T) {
|
||||
setUpQueryExecutorTest()
|
||||
db := setUpQueryExecutorTest()
|
||||
want := &mproto.QueryResult{}
|
||||
vtMaxDmlRows := int64(256)
|
||||
query := fmt.Sprintf("set vt_max_dml_rows = %d", vtMaxDmlRows)
|
||||
ctx := context.Background()
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
defer tsv.StopService()
|
||||
checkPlanID(t, planbuilder.PLAN_SET, qre.plan.PlanId)
|
||||
|
@ -846,10 +846,10 @@ func TestQueryExecutorPlanSetMaxDmlRows(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestQueryExecutorPlanSetMaxDmlRowsFail(t *testing.T) {
|
||||
setUpQueryExecutorTest()
|
||||
db := setUpQueryExecutorTest()
|
||||
query := "set vt_max_dml_rows = 0"
|
||||
ctx := context.Background()
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
defer tsv.StopService()
|
||||
checkPlanID(t, planbuilder.PLAN_SET, qre.plan.PlanId)
|
||||
|
@ -867,12 +867,12 @@ func TestQueryExecutorPlanSetMaxDmlRowsFail(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestQueryExecutorPlanSetStreamBufferSize(t *testing.T) {
|
||||
setUpQueryExecutorTest()
|
||||
db := setUpQueryExecutorTest()
|
||||
want := &mproto.QueryResult{}
|
||||
vtStreamBufferSize := int64(2048)
|
||||
query := fmt.Sprintf("set vt_stream_buffer_size = %d", vtStreamBufferSize)
|
||||
ctx := context.Background()
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
defer tsv.StopService()
|
||||
checkPlanID(t, planbuilder.PLAN_SET, qre.plan.PlanId)
|
||||
|
@ -889,10 +889,10 @@ func TestQueryExecutorPlanSetStreamBufferSize(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestQueryExecutorPlanSetStreamBufferSizeFail(t *testing.T) {
|
||||
setUpQueryExecutorTest()
|
||||
db := setUpQueryExecutorTest()
|
||||
query := "set vt_stream_buffer_size = 128"
|
||||
ctx := context.Background()
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
defer tsv.StopService()
|
||||
checkPlanID(t, planbuilder.PLAN_SET, qre.plan.PlanId)
|
||||
|
@ -919,7 +919,7 @@ func TestQueryExecutorPlanOther(t *testing.T) {
|
|||
}
|
||||
db.AddQuery(query, want)
|
||||
ctx := context.Background()
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableSchemaOverrides|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableSchemaOverrides|enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
defer tsv.StopService()
|
||||
checkPlanID(t, planbuilder.PLAN_OTHER, qre.plan.PlanId)
|
||||
|
@ -964,7 +964,7 @@ func TestQueryExecutorTableAcl(t *testing.T) {
|
|||
t.Fatalf("unable to load tableacl config, error: %v", err)
|
||||
}
|
||||
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableSchemaOverrides|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableSchemaOverrides|enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
defer tsv.StopService()
|
||||
checkPlanID(t, planbuilder.PLAN_PASS_SELECT, qre.plan.PlanId)
|
||||
|
@ -1010,7 +1010,7 @@ func TestQueryExecutorTableAclNoPermission(t *testing.T) {
|
|||
t.Fatalf("unable to load tableacl config, error: %v", err)
|
||||
}
|
||||
// without enabling Config.StrictTableAcl
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableSchemaOverrides|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableSchemaOverrides|enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
checkPlanID(t, planbuilder.PLAN_PASS_SELECT, qre.plan.PlanId)
|
||||
got, err := qre.Execute()
|
||||
|
@ -1023,7 +1023,7 @@ func TestQueryExecutorTableAclNoPermission(t *testing.T) {
|
|||
tsv.StopService()
|
||||
|
||||
// enable Config.StrictTableAcl
|
||||
tsv = newTestTabletServer(ctx, enableRowCache|enableSchemaOverrides|enableStrict|enableStrictTableAcl)
|
||||
tsv = newTestTabletServer(ctx, enableRowCache|enableSchemaOverrides|enableStrict|enableStrictTableAcl, db)
|
||||
qre = newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
defer tsv.StopService()
|
||||
checkPlanID(t, planbuilder.PLAN_PASS_SELECT, qre.plan.PlanId)
|
||||
|
@ -1076,7 +1076,7 @@ func TestQueryExecutorTableAclExemptACL(t *testing.T) {
|
|||
}
|
||||
|
||||
// enable Config.StrictTableAcl
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableSchemaOverrides|enableStrict|enableStrictTableAcl)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableSchemaOverrides|enableStrict|enableStrictTableAcl, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
defer tsv.StopService()
|
||||
checkPlanID(t, planbuilder.PLAN_PASS_SELECT, qre.plan.PlanId)
|
||||
|
@ -1152,7 +1152,7 @@ func TestQueryExecutorTableAclDryRun(t *testing.T) {
|
|||
username,
|
||||
}, ".")
|
||||
// enable Config.StrictTableAcl
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableSchemaOverrides|enableStrict|enableStrictTableAcl)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableSchemaOverrides|enableStrict|enableStrictTableAcl, db)
|
||||
tsv.qe.enableTableAclDryRun = true
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
defer tsv.StopService()
|
||||
|
@ -1210,7 +1210,7 @@ func TestQueryExecutorBlacklistQRFail(t *testing.T) {
|
|||
username: bannedUser,
|
||||
}
|
||||
ctx := callinfo.NewContext(context.Background(), callInfo)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
defer tsv.StopService()
|
||||
checkPlanID(t, planbuilder.PLAN_SELECT_SUBQUERY, qre.plan.PlanId)
|
||||
|
@ -1269,7 +1269,7 @@ func TestQueryExecutorBlacklistQRRetry(t *testing.T) {
|
|||
username: bannedUser,
|
||||
}
|
||||
ctx := callinfo.NewContext(context.Background(), callInfo)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict)
|
||||
tsv := newTestTabletServer(ctx, enableRowCache|enableStrict, db)
|
||||
qre := newTestQueryExecutor(ctx, tsv, query, 0)
|
||||
defer tsv.StopService()
|
||||
checkPlanID(t, planbuilder.PLAN_SELECT_SUBQUERY, qre.plan.PlanId)
|
||||
|
@ -1297,7 +1297,7 @@ const (
|
|||
)
|
||||
|
||||
// newTestQueryExecutor uses a package level variable testTabletServer defined in tabletserver_test.go
|
||||
func newTestTabletServer(ctx context.Context, flags executorFlags) *TabletServer {
|
||||
func newTestTabletServer(ctx context.Context, flags executorFlags, db *fakesqldb.DB) *TabletServer {
|
||||
randID := rand.Int63()
|
||||
config := DefaultQsConfig
|
||||
config.StatsPrefix = fmt.Sprintf("Stats-%d-", randID)
|
||||
|
@ -1326,7 +1326,7 @@ func newTestTabletServer(ctx context.Context, flags executorFlags) *TabletServer
|
|||
}
|
||||
tsv := NewTabletServer(config)
|
||||
testUtils := newTestUtils()
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
if flags&enableRowCache > 0 {
|
||||
dbconfigs.App.EnableRowcache = true
|
||||
} else {
|
||||
|
|
|
@ -31,8 +31,8 @@ func TestSchemaInfoStrictMode(t *testing.T) {
|
|||
}
|
||||
schemaInfo := newTestSchemaInfo(10, 1*time.Second, 1*time.Second, false)
|
||||
t.Log(schemaInfo)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
schemaInfo.cachePool.Open()
|
||||
defer schemaInfo.cachePool.Close()
|
||||
defer handleAndVerifyTabletError(
|
||||
|
@ -55,8 +55,8 @@ func TestSchemaInfoOpenFailedDueToMissMySQLTime(t *testing.T) {
|
|||
},
|
||||
})
|
||||
schemaInfo := newTestSchemaInfo(10, 1*time.Second, 1*time.Second, false)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
schemaInfo.cachePool.Open()
|
||||
defer schemaInfo.cachePool.Close()
|
||||
defer handleAndVerifyTabletError(
|
||||
|
@ -78,8 +78,8 @@ func TestSchemaInfoOpenFailedDueToIncorrectMysqlRowNum(t *testing.T) {
|
|||
},
|
||||
})
|
||||
schemaInfo := newTestSchemaInfo(10, 1*time.Second, 1*time.Second, false)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
schemaInfo.cachePool.Open()
|
||||
defer schemaInfo.cachePool.Close()
|
||||
defer handleAndVerifyTabletError(
|
||||
|
@ -101,8 +101,8 @@ func TestSchemaInfoOpenFailedDueToInvalidTimeFormat(t *testing.T) {
|
|||
},
|
||||
})
|
||||
schemaInfo := newTestSchemaInfo(10, 1*time.Second, 1*time.Second, false)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
schemaInfo.cachePool.Open()
|
||||
defer schemaInfo.cachePool.Close()
|
||||
defer handleAndVerifyTabletError(
|
||||
|
@ -124,8 +124,8 @@ func TestSchemaInfoOpenFailedDueToExecErr(t *testing.T) {
|
|||
RowsAffected: math.MaxUint64,
|
||||
})
|
||||
schemaInfo := newTestSchemaInfo(10, 1*time.Second, 1*time.Second, false)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
schemaInfo.cachePool.Open()
|
||||
defer schemaInfo.cachePool.Close()
|
||||
defer handleAndVerifyTabletError(
|
||||
|
@ -153,8 +153,8 @@ func TestSchemaInfoOpenFailedDueToTableInfoErr(t *testing.T) {
|
|||
RowsAffected: math.MaxUint64,
|
||||
})
|
||||
schemaInfo := newTestSchemaInfo(10, 1*time.Second, 1*time.Second, false)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
schemaInfo.cachePool.Open()
|
||||
defer schemaInfo.cachePool.Close()
|
||||
defer handleAndVerifyTabletError(
|
||||
|
@ -172,8 +172,8 @@ func TestSchemaInfoOpenWithSchemaOverride(t *testing.T) {
|
|||
db.AddQuery(query, result)
|
||||
}
|
||||
schemaInfo := newTestSchemaInfo(10, 10*time.Second, 10*time.Second, false)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
schemaInfo.cachePool.Open()
|
||||
defer schemaInfo.cachePool.Close()
|
||||
schemaOverrides := getSchemaInfoTestSchemaOverride()
|
||||
|
@ -201,8 +201,8 @@ func TestSchemaInfoReload(t *testing.T) {
|
|||
}
|
||||
idleTimeout := 10 * time.Second
|
||||
schemaInfo := newTestSchemaInfo(10, 10*time.Second, idleTimeout, false)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
schemaInfo.cachePool.Open()
|
||||
defer schemaInfo.cachePool.Close()
|
||||
// test cache type RW
|
||||
|
@ -284,8 +284,8 @@ func TestSchemaInfoCreateOrUpdateTableFailedDuetoExecErr(t *testing.T) {
|
|||
},
|
||||
})
|
||||
schemaInfo := newTestSchemaInfo(10, 1*time.Second, 1*time.Second, false)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
schemaInfo.cachePool.Open()
|
||||
defer schemaInfo.cachePool.Close()
|
||||
defer handleAndVerifyTabletError(
|
||||
|
@ -313,8 +313,8 @@ func TestSchemaInfoCreateOrUpdateTable(t *testing.T) {
|
|||
},
|
||||
})
|
||||
schemaInfo := newTestSchemaInfo(10, 1*time.Second, 1*time.Second, false)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
schemaInfo.cachePool.Open()
|
||||
defer schemaInfo.cachePool.Close()
|
||||
schemaInfo.Open(&appParams, &dbaParams, getSchemaInfoTestSchemaOverride(), false)
|
||||
|
@ -337,8 +337,8 @@ func TestSchemaInfoDropTable(t *testing.T) {
|
|||
},
|
||||
})
|
||||
schemaInfo := newTestSchemaInfo(10, 1*time.Second, 1*time.Second, false)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
schemaInfo.cachePool.Open()
|
||||
defer schemaInfo.cachePool.Close()
|
||||
schemaInfo.Open(&appParams, &dbaParams, getSchemaInfoTestSchemaOverride(), false)
|
||||
|
@ -361,8 +361,8 @@ func TestSchemaInfoGetPlanPanicDuetoEmptyQuery(t *testing.T) {
|
|||
db.AddQuery(query, result)
|
||||
}
|
||||
schemaInfo := newTestSchemaInfo(10, 10*time.Second, 10*time.Second, false)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
schemaInfo.cachePool.Open()
|
||||
defer schemaInfo.cachePool.Close()
|
||||
schemaOverrides := getSchemaInfoTestSchemaOverride()
|
||||
|
@ -387,8 +387,8 @@ func TestSchemaInfoQueryCacheFailDueToInvalidCacheSize(t *testing.T) {
|
|||
db.AddQuery(query, result)
|
||||
}
|
||||
schemaInfo := newTestSchemaInfo(10, 10*time.Second, 10*time.Second, false)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
schemaInfo.cachePool.Open()
|
||||
defer schemaInfo.cachePool.Close()
|
||||
schemaOverrides := getSchemaInfoTestSchemaOverride()
|
||||
|
@ -416,8 +416,8 @@ func TestSchemaInfoQueryCache(t *testing.T) {
|
|||
db.AddQuery("select * from test_table_02 where 1 != 1", &mproto.QueryResult{})
|
||||
|
||||
schemaInfo := newTestSchemaInfo(10, 10*time.Second, 10*time.Second, true)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
schemaInfo.cachePool.Open()
|
||||
defer schemaInfo.cachePool.Close()
|
||||
schemaOverrides := getSchemaInfoTestSchemaOverride()
|
||||
|
@ -449,8 +449,8 @@ func TestSchemaInfoExportVars(t *testing.T) {
|
|||
db.AddQuery(query, result)
|
||||
}
|
||||
schemaInfo := newTestSchemaInfo(10, 1*time.Second, 1*time.Second, true)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
schemaInfo.cachePool.Open()
|
||||
defer schemaInfo.cachePool.Close()
|
||||
schemaInfo.Open(&appParams, &dbaParams, []SchemaOverride{}, true)
|
||||
|
@ -468,8 +468,8 @@ func TestUpdatedMysqlStats(t *testing.T) {
|
|||
}
|
||||
idleTimeout := 10 * time.Second
|
||||
schemaInfo := newTestSchemaInfo(10, 10*time.Second, idleTimeout, false)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
schemaInfo.cachePool.Open()
|
||||
defer schemaInfo.cachePool.Close()
|
||||
schemaInfo.Open(&appParams, &dbaParams, nil, true)
|
||||
|
@ -537,8 +537,8 @@ func TestSchemaInfoStatsURL(t *testing.T) {
|
|||
query := "select * from test_table_01"
|
||||
db.AddQuery("select * from test_table_01 where 1 != 1", &mproto.QueryResult{})
|
||||
schemaInfo := newTestSchemaInfo(10, 1*time.Second, 1*time.Second, false)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
schemaInfo.cachePool.Open()
|
||||
defer schemaInfo.cachePool.Close()
|
||||
schemaInfo.Open(&appParams, &dbaParams, []SchemaOverride{}, true)
|
||||
|
|
|
@ -30,7 +30,7 @@ func TestTableInfoNew(t *testing.T) {
|
|||
cachePool := newTestTableInfoCachePool()
|
||||
cachePool.Open()
|
||||
defer cachePool.Close()
|
||||
tableInfo, err := newTestTableInfo(cachePool, "USER_TABLE", "test table")
|
||||
tableInfo, err := newTestTableInfo(cachePool, "USER_TABLE", "test table", db)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create a test table info")
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ func TestTableInfoFailBecauseUnableToRetrieveTableIndex(t *testing.T) {
|
|||
cachePool := newTestTableInfoCachePool()
|
||||
cachePool.Open()
|
||||
defer cachePool.Close()
|
||||
_, err := newTestTableInfo(cachePool, "USER_TABLE", "test table")
|
||||
_, err := newTestTableInfo(cachePool, "USER_TABLE", "test table", db)
|
||||
if err == nil {
|
||||
t.Fatalf("table info creation should fail because it is unable to get test_table index")
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ func TestTableInfoWithoutRowCacheViaComment(t *testing.T) {
|
|||
cachePool := newTestTableInfoCachePool()
|
||||
cachePool.Open()
|
||||
defer cachePool.Close()
|
||||
tableInfo, err := newTestTableInfo(cachePool, "USER_TABLE", "vtocc_nocache")
|
||||
tableInfo, err := newTestTableInfo(cachePool, "USER_TABLE", "vtocc_nocache", db)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create a test table info")
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ func TestTableInfoWithoutRowCacheViaTableType(t *testing.T) {
|
|||
cachePool := newTestTableInfoCachePool()
|
||||
cachePool.Open()
|
||||
defer cachePool.Close()
|
||||
tableInfo, err := newTestTableInfo(cachePool, "VIEW", "test table")
|
||||
tableInfo, err := newTestTableInfo(cachePool, "VIEW", "test table", db)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create a test table info")
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ func TestTableInfoWithoutRowCacheViaNoPKColumn(t *testing.T) {
|
|||
cachePool := newTestTableInfoCachePool()
|
||||
cachePool.Open()
|
||||
defer cachePool.Close()
|
||||
tableInfo, err := newTestTableInfo(cachePool, "USER_TABLE", "test table")
|
||||
tableInfo, err := newTestTableInfo(cachePool, "USER_TABLE", "test table", db)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create a test table info")
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ func TestTableInfoWithoutRowCacheViaUnknownPKColumnType(t *testing.T) {
|
|||
cachePool := newTestTableInfoCachePool()
|
||||
cachePool.Open()
|
||||
defer cachePool.Close()
|
||||
tableInfo, err := newTestTableInfo(cachePool, "USER_TABLE", "test table")
|
||||
tableInfo, err := newTestTableInfo(cachePool, "USER_TABLE", "test table", db)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create a test table info")
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ func TestTableInfoReplacePKColumn(t *testing.T) {
|
|||
cachePool := newTestTableInfoCachePool()
|
||||
cachePool.Open()
|
||||
defer cachePool.Close()
|
||||
tableInfo, err := newTestTableInfo(cachePool, "USER_TABLE", "test table")
|
||||
tableInfo, err := newTestTableInfo(cachePool, "USER_TABLE", "test table", db)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create a table info")
|
||||
}
|
||||
|
@ -219,7 +219,7 @@ func TestTableInfoSetPKColumn(t *testing.T) {
|
|||
cachePool := newTestTableInfoCachePool()
|
||||
cachePool.Open()
|
||||
defer cachePool.Close()
|
||||
tableInfo, err := newTestTableInfo(cachePool, "USER_TABLE", "test table")
|
||||
tableInfo, err := newTestTableInfo(cachePool, "USER_TABLE", "test table", db)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create a table info")
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ func TestTableInfoInvalidCardinalityInIndex(t *testing.T) {
|
|||
cachePool := newTestTableInfoCachePool()
|
||||
cachePool.Open()
|
||||
defer cachePool.Close()
|
||||
tableInfo, err := newTestTableInfo(cachePool, "USER_TABLE", "test table")
|
||||
tableInfo, err := newTestTableInfo(cachePool, "USER_TABLE", "test table", db)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create a table info")
|
||||
}
|
||||
|
@ -267,10 +267,10 @@ func TestTableInfoInvalidCardinalityInIndex(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func newTestTableInfo(cachePool *CachePool, tableType string, comment string) (*TableInfo, error) {
|
||||
func newTestTableInfo(cachePool *CachePool, tableType string, comment string, db *fakesqldb.DB) (*TableInfo, error) {
|
||||
ctx := context.Background()
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
queryServiceStats := NewQueryServiceStats("", false)
|
||||
connPoolIdleTimeout := 10 * time.Second
|
||||
connPool := NewConnPool("", 2, connPoolIdleTimeout, false, queryServiceStats)
|
||||
|
|
|
@ -57,7 +57,7 @@ func TestTabletServerAllowQueriesFailBadConn(t *testing.T) {
|
|||
config := testUtils.newQueryServiceConfig()
|
||||
tsv := NewTabletServer(config)
|
||||
checkTabletServerState(t, tsv, StateNotConnected)
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
err := tsv.StartService(nil, &dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
|
||||
if err == nil {
|
||||
t.Fatalf("TabletServer.StartService should fail")
|
||||
|
@ -66,14 +66,14 @@ func TestTabletServerAllowQueriesFailBadConn(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTabletServerAllowQueriesFailStrictModeConflictWithRowCache(t *testing.T) {
|
||||
setUpTabletServerTest()
|
||||
db := setUpTabletServerTest()
|
||||
testUtils := newTestUtils()
|
||||
config := testUtils.newQueryServiceConfig()
|
||||
// disable strict mode
|
||||
config.StrictMode = false
|
||||
tsv := NewTabletServer(config)
|
||||
checkTabletServerState(t, tsv, StateNotConnected)
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
// enable rowcache
|
||||
dbconfigs.App.EnableRowcache = true
|
||||
err := tsv.StartService(nil, &dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
|
||||
|
@ -84,12 +84,12 @@ func TestTabletServerAllowQueriesFailStrictModeConflictWithRowCache(t *testing.T
|
|||
}
|
||||
|
||||
func TestTabletServerAllowQueries(t *testing.T) {
|
||||
setUpTabletServerTest()
|
||||
db := setUpTabletServerTest()
|
||||
testUtils := newTestUtils()
|
||||
config := testUtils.newQueryServiceConfig()
|
||||
tsv := NewTabletServer(config)
|
||||
checkTabletServerState(t, tsv, StateNotConnected)
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
tsv.setState(StateServing)
|
||||
err := tsv.StartService(nil, &dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
|
||||
tsv.StopService()
|
||||
|
@ -106,7 +106,7 @@ func TestTabletServerAllowQueries(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTabletServerInitDBConfig(t *testing.T) {
|
||||
setUpTabletServerTest()
|
||||
_ = setUpTabletServerTest()
|
||||
testUtils := newTestUtils()
|
||||
config := testUtils.newQueryServiceConfig()
|
||||
tsv := NewTabletServer(config)
|
||||
|
@ -124,7 +124,7 @@ func TestTabletServerInitDBConfig(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDecideAction(t *testing.T) {
|
||||
setUpTabletServerTest()
|
||||
_ = setUpTabletServerTest()
|
||||
testUtils := newTestUtils()
|
||||
config := testUtils.newQueryServiceConfig()
|
||||
tsv := NewTabletServer(config)
|
||||
|
@ -227,11 +227,11 @@ func TestDecideAction(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSetServingType(t *testing.T) {
|
||||
setUpTabletServerTest()
|
||||
db := setUpTabletServerTest()
|
||||
testUtils := newTestUtils()
|
||||
config := testUtils.newQueryServiceConfig()
|
||||
tsv := NewTabletServer(config)
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
|
||||
err := tsv.InitDBConfig(nil, &dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
|
||||
if err != nil {
|
||||
|
@ -279,11 +279,11 @@ func TestSetServingType(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTabletServerCheckMysql(t *testing.T) {
|
||||
setUpTabletServerTest()
|
||||
db := setUpTabletServerTest()
|
||||
testUtils := newTestUtils()
|
||||
config := testUtils.newQueryServiceConfig()
|
||||
tsv := NewTabletServer(config)
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
target := &pb.Target{}
|
||||
err := tsv.StartService(target, &dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
|
||||
defer tsv.StopService()
|
||||
|
@ -308,7 +308,7 @@ func TestTabletServerCheckMysqlFailInvalidConn(t *testing.T) {
|
|||
testUtils := newTestUtils()
|
||||
config := testUtils.newQueryServiceConfig()
|
||||
tsv := NewTabletServer(config)
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
err := tsv.StartService(nil, &dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
|
||||
defer tsv.StopService()
|
||||
if err != nil {
|
||||
|
@ -322,11 +322,11 @@ func TestTabletServerCheckMysqlFailInvalidConn(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTabletServerCheckMysqlFailUninitializedQueryEngine(t *testing.T) {
|
||||
setUpTabletServerTest()
|
||||
db := setUpTabletServerTest()
|
||||
testUtils := newTestUtils()
|
||||
config := testUtils.newQueryServiceConfig()
|
||||
tsv := NewTabletServer(config)
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
// this causes QueryEngine not being initialized properly
|
||||
tsv.setState(StateServing)
|
||||
err := tsv.StartService(nil, &dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
|
||||
|
@ -342,7 +342,7 @@ func TestTabletServerCheckMysqlFailUninitializedQueryEngine(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTabletServerCheckMysqlInUnintialized(t *testing.T) {
|
||||
setUpTabletServerTest()
|
||||
_ = setUpTabletServerTest()
|
||||
testUtils := newTestUtils()
|
||||
config := testUtils.newQueryServiceConfig()
|
||||
config.EnablePublishStats = true
|
||||
|
@ -367,7 +367,7 @@ func TestTabletServerCheckMysqlInUnintialized(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTabletServerGetSessionId(t *testing.T) {
|
||||
setUpTabletServerTest()
|
||||
db := setUpTabletServerTest()
|
||||
testUtils := newTestUtils()
|
||||
config := testUtils.newQueryServiceConfig()
|
||||
tsv := NewTabletServer(config)
|
||||
|
@ -376,7 +376,7 @@ func TestTabletServerGetSessionId(t *testing.T) {
|
|||
}
|
||||
keyspace := "test_keyspace"
|
||||
shard := "0"
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
err := tsv.StartService(nil, &dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
|
||||
if err != nil {
|
||||
t.Fatalf("StartService failed: %v", err)
|
||||
|
@ -412,11 +412,11 @@ func TestTabletServerGetSessionId(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTabletServerCommandFailUnMatchedSessionId(t *testing.T) {
|
||||
setUpTabletServerTest()
|
||||
db := setUpTabletServerTest()
|
||||
testUtils := newTestUtils()
|
||||
config := testUtils.newQueryServiceConfig()
|
||||
tsv := NewTabletServer(config)
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
err := tsv.StartService(nil, &dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
|
||||
if err != nil {
|
||||
t.Fatalf("StartService failed: %v", err)
|
||||
|
@ -515,7 +515,7 @@ func TestTabletServerCommitTransaciton(t *testing.T) {
|
|||
db.AddQuery(executeSQL, executeSQLResult)
|
||||
config := testUtils.newQueryServiceConfig()
|
||||
tsv := NewTabletServer(config)
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
err := tsv.StartService(nil, &dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
|
||||
if err != nil {
|
||||
t.Fatalf("StartService failed: %v", err)
|
||||
|
@ -560,7 +560,7 @@ func TestTabletServerRollback(t *testing.T) {
|
|||
db.AddQuery(executeSQL, executeSQLResult)
|
||||
config := testUtils.newQueryServiceConfig()
|
||||
tsv := NewTabletServer(config)
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
err := tsv.StartService(nil, &dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
|
||||
if err != nil {
|
||||
t.Fatalf("StartService failed: %v", err)
|
||||
|
@ -606,7 +606,7 @@ func TestTabletServerStreamExecute(t *testing.T) {
|
|||
|
||||
config := testUtils.newQueryServiceConfig()
|
||||
tsv := NewTabletServer(config)
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
err := tsv.StartService(nil, &dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
|
||||
if err != nil {
|
||||
t.Fatalf("StartService failed: %v", err)
|
||||
|
@ -653,7 +653,7 @@ func TestTabletServerExecuteBatch(t *testing.T) {
|
|||
db.AddQuery(expanedSQL, sqlResult)
|
||||
config := testUtils.newQueryServiceConfig()
|
||||
tsv := NewTabletServer(config)
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
err := tsv.StartService(nil, &dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
|
||||
if err != nil {
|
||||
t.Fatalf("StartService failed: %v", err)
|
||||
|
@ -685,11 +685,11 @@ func TestTabletServerExecuteBatch(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTabletServerExecuteBatchFailEmptyQueryList(t *testing.T) {
|
||||
setUpTabletServerTest()
|
||||
db := setUpTabletServerTest()
|
||||
testUtils := newTestUtils()
|
||||
config := testUtils.newQueryServiceConfig()
|
||||
tsv := NewTabletServer(config)
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
err := tsv.StartService(nil, &dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
|
||||
if err != nil {
|
||||
t.Fatalf("StartService failed: %v", err)
|
||||
|
@ -709,11 +709,11 @@ func TestTabletServerExecuteBatchFailEmptyQueryList(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTabletServerExecuteBatchFailAsTransaction(t *testing.T) {
|
||||
setUpTabletServerTest()
|
||||
db := setUpTabletServerTest()
|
||||
testUtils := newTestUtils()
|
||||
config := testUtils.newQueryServiceConfig()
|
||||
tsv := NewTabletServer(config)
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
err := tsv.StartService(nil, &dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
|
||||
if err != nil {
|
||||
t.Fatalf("StartService failed: %v", err)
|
||||
|
@ -746,7 +746,7 @@ func TestTabletServerExecuteBatchBeginFail(t *testing.T) {
|
|||
db.AddRejectedQuery("begin", errRejected)
|
||||
config := testUtils.newQueryServiceConfig()
|
||||
tsv := NewTabletServer(config)
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
err := tsv.StartService(nil, &dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
|
||||
if err != nil {
|
||||
t.Fatalf("StartService failed: %v", err)
|
||||
|
@ -780,7 +780,7 @@ func TestTabletServerExecuteBatchCommitFail(t *testing.T) {
|
|||
db.AddRejectedQuery("commit", errRejected)
|
||||
config := testUtils.newQueryServiceConfig()
|
||||
tsv := NewTabletServer(config)
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
err := tsv.StartService(nil, &dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
|
||||
if err != nil {
|
||||
t.Fatalf("StartService failed: %v", err)
|
||||
|
@ -828,7 +828,7 @@ func TestTabletServerExecuteBatchSqlExecFailInTransaction(t *testing.T) {
|
|||
|
||||
config := testUtils.newQueryServiceConfig()
|
||||
tsv := NewTabletServer(config)
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
err := tsv.StartService(nil, &dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
|
||||
if err != nil {
|
||||
t.Fatalf("StartService failed: %v", err)
|
||||
|
@ -883,7 +883,7 @@ func TestTabletServerExecuteBatchSqlSucceedInTransaction(t *testing.T) {
|
|||
config := testUtils.newQueryServiceConfig()
|
||||
config.EnableAutoCommit = true
|
||||
tsv := NewTabletServer(config)
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
err := tsv.StartService(nil, &dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
|
||||
if err != nil {
|
||||
t.Fatalf("StartService failed: %v", err)
|
||||
|
@ -911,11 +911,11 @@ func TestTabletServerExecuteBatchSqlSucceedInTransaction(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTabletServerExecuteBatchCallCommitWithoutABegin(t *testing.T) {
|
||||
setUpTabletServerTest()
|
||||
db := setUpTabletServerTest()
|
||||
testUtils := newTestUtils()
|
||||
config := testUtils.newQueryServiceConfig()
|
||||
tsv := NewTabletServer(config)
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
err := tsv.StartService(nil, &dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
|
||||
if err != nil {
|
||||
t.Fatalf("StartService failed: %v", err)
|
||||
|
@ -953,7 +953,7 @@ func TestExecuteBatchNestedTransaction(t *testing.T) {
|
|||
db.AddQuery(expanedSQL, sqlResult)
|
||||
config := testUtils.newQueryServiceConfig()
|
||||
tsv := NewTabletServer(config)
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
err := tsv.StartService(nil, &dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
|
||||
if err != nil {
|
||||
t.Fatalf("StartService failed: %v", err)
|
||||
|
@ -1029,7 +1029,7 @@ func TestTabletServerSplitQuery(t *testing.T) {
|
|||
testUtils := newTestUtils()
|
||||
config := testUtils.newQueryServiceConfig()
|
||||
tsv := NewTabletServer(config)
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
err := tsv.StartService(nil, &dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
|
||||
if err != nil {
|
||||
t.Fatalf("StartService failed: %v", err)
|
||||
|
@ -1090,7 +1090,7 @@ func TestTabletServerSplitQueryInvalidQuery(t *testing.T) {
|
|||
testUtils := newTestUtils()
|
||||
config := testUtils.newQueryServiceConfig()
|
||||
tsv := NewTabletServer(config)
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
err := tsv.StartService(nil, &dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
|
||||
if err != nil {
|
||||
t.Fatalf("StartService failed: %v", err)
|
||||
|
@ -1155,7 +1155,7 @@ func TestTabletServerSplitQueryInvalidMinMax(t *testing.T) {
|
|||
|
||||
config := testUtils.newQueryServiceConfig()
|
||||
tsv := NewTabletServer(config)
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
err := tsv.StartService(nil, &dbconfigs, []SchemaOverride{}, testUtils.newMysqld(&dbconfigs))
|
||||
if err != nil {
|
||||
t.Fatalf("StartService failed: %v", err)
|
||||
|
@ -1299,7 +1299,8 @@ func TestTerseErrors3(t *testing.T) {
|
|||
|
||||
func TestNeedInvalidator(t *testing.T) {
|
||||
testUtils := newTestUtils()
|
||||
dbconfigs := testUtils.newDBConfigs()
|
||||
db := setUpTabletServerTest()
|
||||
dbconfigs := testUtils.newDBConfigs(db)
|
||||
|
||||
// EnableRowCache is false
|
||||
if needInvalidator(nil, &dbconfigs) {
|
||||
|
|
|
@ -16,6 +16,7 @@ import (
|
|||
"github.com/youtube/vitess/go/sqldb"
|
||||
"github.com/youtube/vitess/go/vt/dbconfigs"
|
||||
"github.com/youtube/vitess/go/vt/mysqlctl"
|
||||
"github.com/youtube/vitess/go/vt/vttest/fakesqldb"
|
||||
)
|
||||
|
||||
type fakeCallInfo struct {
|
||||
|
@ -101,9 +102,9 @@ func (util *testUtils) newMysqld(dbconfigs *dbconfigs.DBConfigs) mysqlctl.MysqlD
|
|||
)
|
||||
}
|
||||
|
||||
func (util *testUtils) newDBConfigs() dbconfigs.DBConfigs {
|
||||
func (util *testUtils) newDBConfigs(db *fakesqldb.DB) dbconfigs.DBConfigs {
|
||||
appDBConfig := dbconfigs.DBConfig{
|
||||
ConnParams: sqldb.ConnParams{},
|
||||
ConnParams: sqldb.ConnParams{Engine: db.Name},
|
||||
Keyspace: "test_keyspace",
|
||||
Shard: "0",
|
||||
EnableRowcache: false,
|
||||
|
|
|
@ -26,8 +26,8 @@ func TestTxPoolExecuteCommit(t *testing.T) {
|
|||
txPool := newTxPool(true)
|
||||
txPool.SetTimeout(1 * time.Second)
|
||||
txPool.SetPoolTimeout(1 * time.Second)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
txPool.Open(&appParams, &dbaParams)
|
||||
defer txPool.Close()
|
||||
ctx := context.Background()
|
||||
|
@ -58,8 +58,8 @@ func TestTxPoolExecuteRollback(t *testing.T) {
|
|||
db.AddQuery("rollback", &proto.QueryResult{})
|
||||
|
||||
txPool := newTxPool(false)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
txPool.Open(&appParams, &dbaParams)
|
||||
defer txPool.Close()
|
||||
ctx := context.Background()
|
||||
|
@ -83,8 +83,8 @@ func TestTxPoolTransactionKiller(t *testing.T) {
|
|||
txPool := newTxPool(false)
|
||||
// make sure transaction killer will run frequent enough
|
||||
txPool.SetTimeout(time.Duration(10))
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
txPool.Open(&appParams, &dbaParams)
|
||||
defer txPool.Close()
|
||||
ctx := context.Background()
|
||||
|
@ -102,11 +102,11 @@ func TestTxPoolTransactionKiller(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTxPoolBeginAfterConnPoolClosed(t *testing.T) {
|
||||
fakesqldb.Register()
|
||||
db := fakesqldb.Register()
|
||||
txPool := newTxPool(false)
|
||||
txPool.SetTimeout(time.Duration(10))
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
txPool.Open(&appParams, &dbaParams)
|
||||
txPool.Close()
|
||||
ctx := context.Background()
|
||||
|
@ -128,8 +128,8 @@ func TestTxPoolBeginWithPoolTimeout(t *testing.T) {
|
|||
db.AddQuery("begin", &proto.QueryResult{})
|
||||
|
||||
txPool := newTxPool(false)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
txPool.Open(&appParams, &dbaParams)
|
||||
// set pool capacity to 1
|
||||
txPool.pool.SetCapacity(1)
|
||||
|
@ -144,10 +144,10 @@ func TestTxPoolBeginWithPoolTimeout(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTxPoolBeginWithShortDeadline(t *testing.T) {
|
||||
fakesqldb.Register()
|
||||
db := fakesqldb.Register()
|
||||
txPool := newTxPool(false)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
txPool.Open(&appParams, &dbaParams)
|
||||
// set pool capacity to 1
|
||||
txPool.pool.SetCapacity(1)
|
||||
|
@ -163,8 +163,8 @@ func TestTxPoolBeginWithPoolConnectionError(t *testing.T) {
|
|||
db := fakesqldb.Register()
|
||||
db.EnableConnFail()
|
||||
txPool := newTxPool(false)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
txPool.Open(&appParams, &dbaParams)
|
||||
defer txPool.Close()
|
||||
defer handleAndVerifyTabletError(t, "expect to get an error", ErrFatal)
|
||||
|
@ -176,8 +176,8 @@ func TestTxPoolBeginWithExecError(t *testing.T) {
|
|||
db := fakesqldb.Register()
|
||||
db.AddRejectedQuery("begin", errRejected)
|
||||
txPool := newTxPool(false)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
txPool.Open(&appParams, &dbaParams)
|
||||
defer txPool.Close()
|
||||
defer handleAndVerifyTabletError(t, "expect to get an error", ErrFail)
|
||||
|
@ -192,8 +192,8 @@ func TestTxPoolSafeCommitFail(t *testing.T) {
|
|||
db.AddQuery(sql, &proto.QueryResult{})
|
||||
db.AddRejectedQuery("commit", errRejected)
|
||||
txPool := newTxPool(false)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
txPool.Open(&appParams, &dbaParams)
|
||||
defer txPool.Close()
|
||||
ctx := context.Background()
|
||||
|
@ -218,8 +218,8 @@ func TestTxPoolRollbackFail(t *testing.T) {
|
|||
db.AddRejectedQuery("rollback", errRejected)
|
||||
|
||||
txPool := newTxPool(false)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
txPool.Open(&appParams, &dbaParams)
|
||||
defer txPool.Close()
|
||||
ctx := context.Background()
|
||||
|
@ -236,10 +236,10 @@ func TestTxPoolRollbackFail(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTxPoolGetConnFail(t *testing.T) {
|
||||
fakesqldb.Register()
|
||||
db := fakesqldb.Register()
|
||||
txPool := newTxPool(false)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
txPool.Open(&appParams, &dbaParams)
|
||||
defer txPool.Close()
|
||||
defer handleAndVerifyTabletError(t, "txpool.Get should fail", ErrNotInTx)
|
||||
|
@ -251,8 +251,8 @@ func TestTxPoolExecFailDueToConnFail(t *testing.T) {
|
|||
db.AddQuery("begin", &proto.QueryResult{})
|
||||
|
||||
txPool := newTxPool(false)
|
||||
appParams := sqldb.ConnParams{}
|
||||
dbaParams := sqldb.ConnParams{}
|
||||
appParams := sqldb.ConnParams{Engine: db.Name}
|
||||
dbaParams := sqldb.ConnParams{Engine: db.Name}
|
||||
txPool.Open(&appParams, &dbaParams)
|
||||
defer txPool.Close()
|
||||
ctx := context.Background()
|
||||
|
|
|
@ -49,7 +49,7 @@ func TestBsonP3VTGateConn(t *testing.T) {
|
|||
vtgateconntest.RegisterTestDialProtocol(client)
|
||||
|
||||
// run the test suite
|
||||
// vtgateconntest.TestSuite(t, client, service)
|
||||
vtgateconntest.TestSuite(t, client, service)
|
||||
vtgateconntest.TestErrorSuite(t, service)
|
||||
|
||||
// and clean up
|
||||
|
|
|
@ -29,6 +29,7 @@ type Conn struct {
|
|||
|
||||
// DB is a fake database and all its methods are thread safe.
|
||||
type DB struct {
|
||||
Name string
|
||||
isConnFail bool
|
||||
data map[string]*proto.QueryResult
|
||||
rejectedData map[string]error
|
||||
|
@ -112,8 +113,8 @@ func (db *DB) IsConnFail() bool {
|
|||
return db.isConnFail
|
||||
}
|
||||
|
||||
// NewFakeSqlDBConn creates a new FakeSqlDBConn instance
|
||||
func NewFakeSqlDBConn(db *DB) *Conn {
|
||||
// NewFakeSQLDBConn creates a new FakeSqlDBConn instance
|
||||
func NewFakeSQLDBConn(db *DB) *Conn {
|
||||
return &Conn{
|
||||
db: db,
|
||||
isClosed: false,
|
||||
|
@ -271,6 +272,7 @@ func (conn *Conn) SetCharset(cs proto.Charset) error {
|
|||
func Register() *DB {
|
||||
name := fmt.Sprintf("fake-%d", rand.Int63())
|
||||
db := &DB{
|
||||
Name: name,
|
||||
data: make(map[string]*proto.QueryResult),
|
||||
rejectedData: make(map[string]error),
|
||||
queryCalled: make(map[string]int),
|
||||
|
@ -279,9 +281,8 @@ func Register() *DB {
|
|||
if db.IsConnFail() {
|
||||
return nil, newConnError()
|
||||
}
|
||||
return NewFakeSqlDBConn(db), nil
|
||||
return NewFakeSQLDBConn(db), nil
|
||||
})
|
||||
sqldb.DefaultDB = name
|
||||
return db
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"github.com/youtube/vitess/go/vt/tabletserver/grpcqueryservice"
|
||||
"github.com/youtube/vitess/go/vt/tabletserver/proto"
|
||||
"github.com/youtube/vitess/go/vt/tabletserver/queryservice"
|
||||
"github.com/youtube/vitess/go/vt/vttest/fakesqldb"
|
||||
"github.com/youtube/vitess/go/vt/wrangler"
|
||||
"github.com/youtube/vitess/go/vt/wrangler/testlib"
|
||||
"github.com/youtube/vitess/go/vt/zktopo"
|
||||
|
@ -243,25 +244,26 @@ func TestSplitClonePopulateBlpCheckpoint(t *testing.T) {
|
|||
}
|
||||
|
||||
func testSplitClone(t *testing.T, strategy string) {
|
||||
db := fakesqldb.Register()
|
||||
ts := zktopo.NewTestServer(t, []string{"cell1", "cell2"})
|
||||
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient(), time.Second)
|
||||
|
||||
sourceMaster := testlib.NewFakeTablet(t, wr, "cell1", 0,
|
||||
pbt.TabletType_MASTER, testlib.TabletKeyspaceShard(t, "ks", "-80"))
|
||||
pbt.TabletType_MASTER, db, testlib.TabletKeyspaceShard(t, "ks", "-80"))
|
||||
sourceRdonly1 := testlib.NewFakeTablet(t, wr, "cell1", 1,
|
||||
pbt.TabletType_RDONLY, testlib.TabletKeyspaceShard(t, "ks", "-80"))
|
||||
pbt.TabletType_RDONLY, db, testlib.TabletKeyspaceShard(t, "ks", "-80"))
|
||||
sourceRdonly2 := testlib.NewFakeTablet(t, wr, "cell1", 2,
|
||||
pbt.TabletType_RDONLY, testlib.TabletKeyspaceShard(t, "ks", "-80"))
|
||||
pbt.TabletType_RDONLY, db, testlib.TabletKeyspaceShard(t, "ks", "-80"))
|
||||
|
||||
leftMaster := testlib.NewFakeTablet(t, wr, "cell1", 10,
|
||||
pbt.TabletType_MASTER, testlib.TabletKeyspaceShard(t, "ks", "-40"))
|
||||
pbt.TabletType_MASTER, db, testlib.TabletKeyspaceShard(t, "ks", "-40"))
|
||||
leftRdonly := testlib.NewFakeTablet(t, wr, "cell1", 11,
|
||||
pbt.TabletType_RDONLY, testlib.TabletKeyspaceShard(t, "ks", "-40"))
|
||||
pbt.TabletType_RDONLY, db, testlib.TabletKeyspaceShard(t, "ks", "-40"))
|
||||
|
||||
rightMaster := testlib.NewFakeTablet(t, wr, "cell1", 20,
|
||||
pbt.TabletType_MASTER, testlib.TabletKeyspaceShard(t, "ks", "40-80"))
|
||||
pbt.TabletType_MASTER, db, testlib.TabletKeyspaceShard(t, "ks", "40-80"))
|
||||
rightRdonly := testlib.NewFakeTablet(t, wr, "cell1", 21,
|
||||
pbt.TabletType_RDONLY, testlib.TabletKeyspaceShard(t, "ks", "40-80"))
|
||||
pbt.TabletType_RDONLY, db, testlib.TabletKeyspaceShard(t, "ks", "40-80"))
|
||||
|
||||
for _, ft := range []*testlib.FakeTablet{sourceMaster, sourceRdonly1, sourceRdonly2, leftMaster, leftRdonly, rightMaster, rightRdonly} {
|
||||
ft.StartActionLoop(t, wr)
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
"github.com/youtube/vitess/go/vt/tabletserver/grpcqueryservice"
|
||||
"github.com/youtube/vitess/go/vt/tabletserver/proto"
|
||||
"github.com/youtube/vitess/go/vt/tabletserver/queryservice"
|
||||
"github.com/youtube/vitess/go/vt/vttest/fakesqldb"
|
||||
"github.com/youtube/vitess/go/vt/wrangler"
|
||||
"github.com/youtube/vitess/go/vt/wrangler/testlib"
|
||||
"github.com/youtube/vitess/go/vt/zktopo"
|
||||
|
@ -146,6 +147,7 @@ func (sq *sourceTabletServer) StreamExecute(ctx context.Context, target *pb.Targ
|
|||
// TODO(aaijazi): Create a test in which source and destination data does not match
|
||||
|
||||
func TestSplitDiff(t *testing.T) {
|
||||
db := fakesqldb.Register()
|
||||
ts := zktopo.NewTestServer(t, []string{"cell1", "cell2"})
|
||||
// We need to use FakeTabletManagerClient because we don't have a good way to fake the binlog player yet,
|
||||
// which is necessary for synchronizing replication.
|
||||
|
@ -153,18 +155,18 @@ func TestSplitDiff(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
sourceMaster := testlib.NewFakeTablet(t, wr, "cell1", 0,
|
||||
pbt.TabletType_MASTER, testlib.TabletKeyspaceShard(t, "ks", "-80"))
|
||||
pbt.TabletType_MASTER, db, testlib.TabletKeyspaceShard(t, "ks", "-80"))
|
||||
sourceRdonly1 := testlib.NewFakeTablet(t, wr, "cell1", 1,
|
||||
pbt.TabletType_RDONLY, testlib.TabletKeyspaceShard(t, "ks", "-80"))
|
||||
pbt.TabletType_RDONLY, db, testlib.TabletKeyspaceShard(t, "ks", "-80"))
|
||||
sourceRdonly2 := testlib.NewFakeTablet(t, wr, "cell1", 2,
|
||||
pbt.TabletType_RDONLY, testlib.TabletKeyspaceShard(t, "ks", "-80"))
|
||||
pbt.TabletType_RDONLY, db, testlib.TabletKeyspaceShard(t, "ks", "-80"))
|
||||
|
||||
leftMaster := testlib.NewFakeTablet(t, wr, "cell1", 10,
|
||||
pbt.TabletType_MASTER, testlib.TabletKeyspaceShard(t, "ks", "-40"))
|
||||
pbt.TabletType_MASTER, db, testlib.TabletKeyspaceShard(t, "ks", "-40"))
|
||||
leftRdonly1 := testlib.NewFakeTablet(t, wr, "cell1", 11,
|
||||
pbt.TabletType_RDONLY, testlib.TabletKeyspaceShard(t, "ks", "-40"))
|
||||
pbt.TabletType_RDONLY, db, testlib.TabletKeyspaceShard(t, "ks", "-40"))
|
||||
leftRdonly2 := testlib.NewFakeTablet(t, wr, "cell1", 12,
|
||||
pbt.TabletType_RDONLY, testlib.TabletKeyspaceShard(t, "ks", "-40"))
|
||||
pbt.TabletType_RDONLY, db, testlib.TabletKeyspaceShard(t, "ks", "-40"))
|
||||
|
||||
for _, ft := range []*testlib.FakeTablet{sourceMaster, sourceRdonly1, sourceRdonly2, leftMaster, leftRdonly1, leftRdonly2} {
|
||||
ft.StartActionLoop(t, wr)
|
||||
|
|
|
@ -17,6 +17,7 @@ import (
|
|||
"github.com/youtube/vitess/go/vt/tabletserver/grpcqueryservice"
|
||||
"github.com/youtube/vitess/go/vt/tabletserver/proto"
|
||||
"github.com/youtube/vitess/go/vt/tabletserver/queryservice"
|
||||
"github.com/youtube/vitess/go/vt/vttest/fakesqldb"
|
||||
"github.com/youtube/vitess/go/vt/wrangler"
|
||||
"github.com/youtube/vitess/go/vt/wrangler/testlib"
|
||||
"github.com/youtube/vitess/go/vt/zktopo"
|
||||
|
@ -70,6 +71,7 @@ func (sq *sqlDifferTabletServer) StreamExecute(ctx context.Context, target *pb.T
|
|||
// TODO(aaijazi): Create a test in which source and destination data does not match
|
||||
// TODO(aaijazi): This test is reallly slow; investigate why.
|
||||
func TestSqlDiffer(t *testing.T) {
|
||||
db := fakesqldb.Register()
|
||||
ts := zktopo.NewTestServer(t, []string{"cell1", "cell2"})
|
||||
// We need to use FakeTabletManagerClient because we don't have a good way to fake the binlog player yet,
|
||||
// which is necessary for synchronizing replication.
|
||||
|
@ -77,18 +79,18 @@ func TestSqlDiffer(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
supersetMaster := testlib.NewFakeTablet(t, wr, "cell1", 0,
|
||||
pbt.TabletType_MASTER, testlib.TabletKeyspaceShard(t, "source_ks", "0"))
|
||||
pbt.TabletType_MASTER, db, testlib.TabletKeyspaceShard(t, "source_ks", "0"))
|
||||
supersetRdonly1 := testlib.NewFakeTablet(t, wr, "cell1", 1,
|
||||
pbt.TabletType_RDONLY, testlib.TabletKeyspaceShard(t, "source_ks", "0"))
|
||||
pbt.TabletType_RDONLY, db, testlib.TabletKeyspaceShard(t, "source_ks", "0"))
|
||||
supersetRdonly2 := testlib.NewFakeTablet(t, wr, "cell1", 2,
|
||||
pbt.TabletType_RDONLY, testlib.TabletKeyspaceShard(t, "source_ks", "0"))
|
||||
pbt.TabletType_RDONLY, db, testlib.TabletKeyspaceShard(t, "source_ks", "0"))
|
||||
|
||||
subsetMaster := testlib.NewFakeTablet(t, wr, "cell1", 10,
|
||||
pbt.TabletType_MASTER, testlib.TabletKeyspaceShard(t, "destination_ks", "0"))
|
||||
pbt.TabletType_MASTER, db, testlib.TabletKeyspaceShard(t, "destination_ks", "0"))
|
||||
subsetRdonly1 := testlib.NewFakeTablet(t, wr, "cell1", 11,
|
||||
pbt.TabletType_RDONLY, testlib.TabletKeyspaceShard(t, "destination_ks", "0"))
|
||||
pbt.TabletType_RDONLY, db, testlib.TabletKeyspaceShard(t, "destination_ks", "0"))
|
||||
subsetRdonly2 := testlib.NewFakeTablet(t, wr, "cell1", 12,
|
||||
pbt.TabletType_RDONLY, testlib.TabletKeyspaceShard(t, "destination_ks", "0"))
|
||||
pbt.TabletType_RDONLY, db, testlib.TabletKeyspaceShard(t, "destination_ks", "0"))
|
||||
|
||||
for _, ft := range []*testlib.FakeTablet{supersetMaster, supersetRdonly1, supersetRdonly2, subsetMaster, subsetRdonly1, subsetRdonly2} {
|
||||
ft.StartActionLoop(t, wr)
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"github.com/youtube/vitess/go/vt/tabletserver/grpcqueryservice"
|
||||
"github.com/youtube/vitess/go/vt/tabletserver/proto"
|
||||
"github.com/youtube/vitess/go/vt/tabletserver/queryservice"
|
||||
"github.com/youtube/vitess/go/vt/vttest/fakesqldb"
|
||||
"github.com/youtube/vitess/go/vt/wrangler"
|
||||
"github.com/youtube/vitess/go/vt/wrangler/testlib"
|
||||
"github.com/youtube/vitess/go/vt/zktopo"
|
||||
|
@ -228,15 +229,16 @@ func TestVerticalSplitClonePopulateBlpCheckpoint(t *testing.T) {
|
|||
}
|
||||
|
||||
func testVerticalSplitClone(t *testing.T, strategy string) {
|
||||
db := fakesqldb.Register()
|
||||
ts := zktopo.NewTestServer(t, []string{"cell1", "cell2"})
|
||||
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient(), time.Second)
|
||||
|
||||
sourceMaster := testlib.NewFakeTablet(t, wr, "cell1", 0,
|
||||
pbt.TabletType_MASTER, testlib.TabletKeyspaceShard(t, "source_ks", "0"))
|
||||
pbt.TabletType_MASTER, db, testlib.TabletKeyspaceShard(t, "source_ks", "0"))
|
||||
sourceRdonly1 := testlib.NewFakeTablet(t, wr, "cell1", 1,
|
||||
pbt.TabletType_RDONLY, testlib.TabletKeyspaceShard(t, "source_ks", "0"))
|
||||
pbt.TabletType_RDONLY, db, testlib.TabletKeyspaceShard(t, "source_ks", "0"))
|
||||
sourceRdonly2 := testlib.NewFakeTablet(t, wr, "cell1", 2,
|
||||
pbt.TabletType_RDONLY, testlib.TabletKeyspaceShard(t, "source_ks", "0"))
|
||||
pbt.TabletType_RDONLY, db, testlib.TabletKeyspaceShard(t, "source_ks", "0"))
|
||||
|
||||
// Create the destination keyspace with the appropriate ServedFromMap
|
||||
ki := &pbt.Keyspace{
|
||||
|
@ -259,9 +261,9 @@ func testVerticalSplitClone(t *testing.T, strategy string) {
|
|||
wr.TopoServer().CreateKeyspace(ctx, "destination_ks", ki)
|
||||
|
||||
destMaster := testlib.NewFakeTablet(t, wr, "cell1", 10,
|
||||
pbt.TabletType_MASTER, testlib.TabletKeyspaceShard(t, "destination_ks", "0"))
|
||||
pbt.TabletType_MASTER, db, testlib.TabletKeyspaceShard(t, "destination_ks", "0"))
|
||||
destRdonly := testlib.NewFakeTablet(t, wr, "cell1", 11,
|
||||
pbt.TabletType_RDONLY, testlib.TabletKeyspaceShard(t, "destination_ks", "0"))
|
||||
pbt.TabletType_RDONLY, db, testlib.TabletKeyspaceShard(t, "destination_ks", "0"))
|
||||
|
||||
for _, ft := range []*testlib.FakeTablet{sourceMaster, sourceRdonly1, sourceRdonly2, destMaster, destRdonly} {
|
||||
ft.StartActionLoop(t, wr)
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
"github.com/youtube/vitess/go/vt/tabletserver/grpcqueryservice"
|
||||
"github.com/youtube/vitess/go/vt/tabletserver/proto"
|
||||
"github.com/youtube/vitess/go/vt/tabletserver/queryservice"
|
||||
"github.com/youtube/vitess/go/vt/vttest/fakesqldb"
|
||||
"github.com/youtube/vitess/go/vt/wrangler"
|
||||
"github.com/youtube/vitess/go/vt/wrangler/testlib"
|
||||
"github.com/youtube/vitess/go/vt/zktopo"
|
||||
|
@ -81,6 +82,7 @@ func (sq *verticalDiffTabletServer) StreamExecute(ctx context.Context, target *p
|
|||
// TODO(aaijazi): Create a test in which source and destination data does not match
|
||||
|
||||
func TestVerticalSplitDiff(t *testing.T) {
|
||||
db := fakesqldb.Register()
|
||||
ts := zktopo.NewTestServer(t, []string{"cell1", "cell2"})
|
||||
// We need to use FakeTabletManagerClient because we don't have a good way to fake the binlog player yet,
|
||||
// which is necessary for synchronizing replication.
|
||||
|
@ -88,11 +90,11 @@ func TestVerticalSplitDiff(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
sourceMaster := testlib.NewFakeTablet(t, wr, "cell1", 0,
|
||||
pbt.TabletType_MASTER, testlib.TabletKeyspaceShard(t, "source_ks", "0"))
|
||||
pbt.TabletType_MASTER, db, testlib.TabletKeyspaceShard(t, "source_ks", "0"))
|
||||
sourceRdonly1 := testlib.NewFakeTablet(t, wr, "cell1", 1,
|
||||
pbt.TabletType_RDONLY, testlib.TabletKeyspaceShard(t, "source_ks", "0"))
|
||||
pbt.TabletType_RDONLY, db, testlib.TabletKeyspaceShard(t, "source_ks", "0"))
|
||||
sourceRdonly2 := testlib.NewFakeTablet(t, wr, "cell1", 2,
|
||||
pbt.TabletType_RDONLY, testlib.TabletKeyspaceShard(t, "source_ks", "0"))
|
||||
pbt.TabletType_RDONLY, db, testlib.TabletKeyspaceShard(t, "source_ks", "0"))
|
||||
|
||||
// Create the destination keyspace with the appropriate ServedFromMap
|
||||
ki := &pbt.Keyspace{
|
||||
|
@ -114,11 +116,11 @@ func TestVerticalSplitDiff(t *testing.T) {
|
|||
wr.TopoServer().CreateKeyspace(ctx, "destination_ks", ki)
|
||||
|
||||
destMaster := testlib.NewFakeTablet(t, wr, "cell1", 10,
|
||||
pbt.TabletType_MASTER, testlib.TabletKeyspaceShard(t, "destination_ks", "0"))
|
||||
pbt.TabletType_MASTER, db, testlib.TabletKeyspaceShard(t, "destination_ks", "0"))
|
||||
destRdonly1 := testlib.NewFakeTablet(t, wr, "cell1", 11,
|
||||
pbt.TabletType_RDONLY, testlib.TabletKeyspaceShard(t, "destination_ks", "0"))
|
||||
pbt.TabletType_RDONLY, db, testlib.TabletKeyspaceShard(t, "destination_ks", "0"))
|
||||
destRdonly2 := testlib.NewFakeTablet(t, wr, "cell1", 12,
|
||||
pbt.TabletType_RDONLY, testlib.TabletKeyspaceShard(t, "destination_ks", "0"))
|
||||
pbt.TabletType_RDONLY, db, testlib.TabletKeyspaceShard(t, "destination_ks", "0"))
|
||||
|
||||
for _, ft := range []*testlib.FakeTablet{sourceMaster, sourceRdonly1, sourceRdonly2, destMaster, destRdonly1, destRdonly2} {
|
||||
ft.StartActionLoop(t, wr)
|
||||
|
|
|
@ -19,6 +19,7 @@ import (
|
|||
myproto "github.com/youtube/vitess/go/vt/mysqlctl/proto"
|
||||
"github.com/youtube/vitess/go/vt/tabletmanager/tmclient"
|
||||
"github.com/youtube/vitess/go/vt/topo/topoproto"
|
||||
"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"
|
||||
|
@ -29,6 +30,7 @@ import (
|
|||
func TestBackupRestore(t *testing.T) {
|
||||
// Initialize our environment
|
||||
ctx := context.Background()
|
||||
db := fakesqldb.Register()
|
||||
ts := zktopo.NewTestServer(t, []string{"cell1", "cell2"})
|
||||
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient(), time.Second)
|
||||
vp := NewVtctlPipe(t, ts)
|
||||
|
@ -67,10 +69,10 @@ func TestBackupRestore(t *testing.T) {
|
|||
}
|
||||
|
||||
// create a master tablet, not started, just for shard health
|
||||
master := NewFakeTablet(t, wr, "cell1", 0, pb.TabletType_MASTER)
|
||||
master := NewFakeTablet(t, wr, "cell1", 0, pb.TabletType_MASTER, db)
|
||||
|
||||
// create a single tablet, set it up so we can do backups
|
||||
sourceTablet := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_REPLICA)
|
||||
sourceTablet := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_REPLICA, db)
|
||||
sourceTablet.FakeMysqlDaemon.ReadOnly = true
|
||||
sourceTablet.FakeMysqlDaemon.Replicating = true
|
||||
sourceTablet.FakeMysqlDaemon.CurrentMasterPosition = myproto.ReplicationPosition{
|
||||
|
@ -109,7 +111,7 @@ func TestBackupRestore(t *testing.T) {
|
|||
}
|
||||
|
||||
// create a destination tablet, set it up so we can do restores
|
||||
destTablet := NewFakeTablet(t, wr, "cell1", 2, pb.TabletType_REPLICA)
|
||||
destTablet := NewFakeTablet(t, wr, "cell1", 2, pb.TabletType_REPLICA, db)
|
||||
destTablet.FakeMysqlDaemon.ReadOnly = true
|
||||
destTablet.FakeMysqlDaemon.Replicating = true
|
||||
destTablet.FakeMysqlDaemon.CurrentMasterPosition = myproto.ReplicationPosition{
|
||||
|
|
|
@ -106,12 +106,12 @@ func copySchema(t *testing.T, useShardAsSource bool) {
|
|||
defer vp.Close()
|
||||
|
||||
sourceMaster := NewFakeTablet(t, wr, "cell1", 0,
|
||||
pb.TabletType_MASTER, TabletKeyspaceShard(t, "ks", "-80"))
|
||||
pb.TabletType_MASTER, db, TabletKeyspaceShard(t, "ks", "-80"))
|
||||
sourceRdonly := NewFakeTablet(t, wr, "cell1", 1,
|
||||
pb.TabletType_RDONLY, TabletKeyspaceShard(t, "ks", "-80"))
|
||||
pb.TabletType_RDONLY, db, TabletKeyspaceShard(t, "ks", "-80"))
|
||||
|
||||
destinationMaster := NewFakeTablet(t, wr, "cell1", 10,
|
||||
pb.TabletType_MASTER, TabletKeyspaceShard(t, "ks", "-40"))
|
||||
pb.TabletType_MASTER, db, TabletKeyspaceShard(t, "ks", "-40"))
|
||||
|
||||
for _, ft := range []*FakeTablet{sourceMaster, sourceRdonly, destinationMaster} {
|
||||
ft.StartActionLoop(t, wr)
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
myproto "github.com/youtube/vitess/go/vt/mysqlctl/proto"
|
||||
"github.com/youtube/vitess/go/vt/tabletmanager/tmclient"
|
||||
"github.com/youtube/vitess/go/vt/topo/topoproto"
|
||||
"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"
|
||||
|
@ -22,16 +23,17 @@ import (
|
|||
)
|
||||
|
||||
func TestEmergencyReparentShard(t *testing.T) {
|
||||
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()
|
||||
|
||||
// Create a master, a couple good slaves
|
||||
oldMaster := NewFakeTablet(t, wr, "cell1", 0, pb.TabletType_MASTER)
|
||||
newMaster := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_REPLICA)
|
||||
goodSlave1 := NewFakeTablet(t, wr, "cell1", 2, pb.TabletType_REPLICA)
|
||||
goodSlave2 := NewFakeTablet(t, wr, "cell2", 3, pb.TabletType_REPLICA)
|
||||
oldMaster := NewFakeTablet(t, wr, "cell1", 0, pb.TabletType_MASTER, db)
|
||||
newMaster := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_REPLICA, db)
|
||||
goodSlave1 := NewFakeTablet(t, wr, "cell1", 2, pb.TabletType_REPLICA, db)
|
||||
goodSlave2 := NewFakeTablet(t, wr, "cell2", 3, pb.TabletType_REPLICA, db)
|
||||
|
||||
// new master
|
||||
newMaster.FakeMysqlDaemon.ReadOnly = true
|
||||
|
@ -142,13 +144,14 @@ func TestEmergencyReparentShard(t *testing.T) {
|
|||
// to a host that is not the latest in replication position.
|
||||
func TestEmergencyReparentShardMasterElectNotBest(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db := fakesqldb.Register()
|
||||
ts := zktopo.NewTestServer(t, []string{"cell1", "cell2"})
|
||||
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient(), time.Second)
|
||||
|
||||
// Create a master, a couple good slaves
|
||||
oldMaster := NewFakeTablet(t, wr, "cell1", 0, pb.TabletType_MASTER)
|
||||
newMaster := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_REPLICA)
|
||||
moreAdvancedSlave := NewFakeTablet(t, wr, "cell1", 2, pb.TabletType_REPLICA)
|
||||
oldMaster := NewFakeTablet(t, wr, "cell1", 0, pb.TabletType_MASTER, db)
|
||||
newMaster := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_REPLICA, db)
|
||||
moreAdvancedSlave := NewFakeTablet(t, wr, "cell1", 2, pb.TabletType_REPLICA, db)
|
||||
|
||||
// new master
|
||||
newMaster.FakeMysqlDaemon.Replicating = true
|
||||
|
|
|
@ -24,6 +24,7 @@ import (
|
|||
"github.com/youtube/vitess/go/vt/tabletmanager/tmclient"
|
||||
"github.com/youtube/vitess/go/vt/tabletserver/tabletconn"
|
||||
"github.com/youtube/vitess/go/vt/topo"
|
||||
"github.com/youtube/vitess/go/vt/vttest/fakesqldb"
|
||||
"github.com/youtube/vitess/go/vt/wrangler"
|
||||
|
||||
pb "github.com/youtube/vitess/go/vt/proto/topodata"
|
||||
|
@ -101,7 +102,7 @@ func StartHTTPServer() TabletOption {
|
|||
// has to be between 0 and 99. All the tablet info will be derived
|
||||
// from that. Look at the implementation if you need values.
|
||||
// Use TabletOption implementations if you need to change values at creation.
|
||||
func NewFakeTablet(t *testing.T, wr *wrangler.Wrangler, cell string, uid uint32, tabletType pb.TabletType, options ...TabletOption) *FakeTablet {
|
||||
func NewFakeTablet(t *testing.T, wr *wrangler.Wrangler, cell string, uid uint32, tabletType pb.TabletType, db *fakesqldb.DB, options ...TabletOption) *FakeTablet {
|
||||
if uid < 0 || uid > 99 {
|
||||
t.Fatalf("uid has to be between 0 and 99: %v", uid)
|
||||
}
|
||||
|
@ -130,7 +131,7 @@ func NewFakeTablet(t *testing.T, wr *wrangler.Wrangler, cell string, uid uint32,
|
|||
}
|
||||
|
||||
// create a FakeMysqlDaemon with the right information by default
|
||||
fakeMysqlDaemon := mysqlctl.NewFakeMysqlDaemon()
|
||||
fakeMysqlDaemon := mysqlctl.NewFakeMysqlDaemon(db)
|
||||
fakeMysqlDaemon.MysqlPort = 3300 + int32(uid)
|
||||
|
||||
return &FakeTablet{
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
myproto "github.com/youtube/vitess/go/vt/mysqlctl/proto"
|
||||
"github.com/youtube/vitess/go/vt/tabletmanager/tmclient"
|
||||
"github.com/youtube/vitess/go/vt/topo/topoproto"
|
||||
"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"
|
||||
|
@ -24,15 +25,16 @@ import (
|
|||
// works as planned
|
||||
func TestInitMasterShard(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
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()
|
||||
|
||||
// Create a master, a couple good slaves
|
||||
master := NewFakeTablet(t, wr, "cell1", 0, pb.TabletType_MASTER)
|
||||
goodSlave1 := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_REPLICA)
|
||||
goodSlave2 := NewFakeTablet(t, wr, "cell2", 2, pb.TabletType_REPLICA)
|
||||
master := NewFakeTablet(t, wr, "cell1", 0, pb.TabletType_MASTER, db)
|
||||
goodSlave1 := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_REPLICA, db)
|
||||
goodSlave2 := NewFakeTablet(t, wr, "cell2", 2, pb.TabletType_REPLICA, db)
|
||||
|
||||
// Master: set a plausible ReplicationPosition to return,
|
||||
// and expect to add entry in _vt.reparent_journal
|
||||
|
@ -122,10 +124,11 @@ func TestInitMasterShard(t *testing.T) {
|
|||
// TestInitMasterShardChecks makes sure the safety checks work
|
||||
func TestInitMasterShardChecks(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db := fakesqldb.Register()
|
||||
ts := zktopo.NewTestServer(t, []string{"cell1", "cell2"})
|
||||
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient(), time.Second)
|
||||
|
||||
master := NewFakeTablet(t, wr, "cell1", 0, pb.TabletType_MASTER)
|
||||
master := NewFakeTablet(t, wr, "cell1", 0, pb.TabletType_MASTER, db)
|
||||
|
||||
// InitShardMaster with an unknown tablet
|
||||
if err := wr.InitShardMaster(ctx, master.Tablet.Keyspace, master.Tablet.Shard, &pb.TabletAlias{
|
||||
|
@ -138,7 +141,7 @@ func TestInitMasterShardChecks(t *testing.T) {
|
|||
// InitShardMaster with two masters in the shard, no force flag
|
||||
// (master2 needs to run InitTablet with -force, as it is the second
|
||||
// master in the same shard)
|
||||
master2 := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_MASTER, ForceInitTablet())
|
||||
master2 := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_MASTER, db, ForceInitTablet())
|
||||
if err := wr.InitShardMaster(ctx, master2.Tablet.Keyspace, master2.Tablet.Shard, master2.Tablet.Alias, false /*force*/, 10*time.Second); err == nil || !strings.Contains(err.Error(), "is not the only master in the shard") {
|
||||
t.Errorf("InitShardMaster with two masters returned wrong error: %v", err)
|
||||
}
|
||||
|
@ -159,13 +162,14 @@ func TestInitMasterShardChecks(t *testing.T) {
|
|||
// proceed, the action completes anyway
|
||||
func TestInitMasterShardOneSlaveFails(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db := fakesqldb.Register()
|
||||
ts := zktopo.NewTestServer(t, []string{"cell1", "cell2"})
|
||||
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient(), time.Second)
|
||||
|
||||
// Create a master, a couple slaves
|
||||
master := NewFakeTablet(t, wr, "cell1", 0, pb.TabletType_MASTER)
|
||||
goodSlave := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_REPLICA)
|
||||
badSlave := NewFakeTablet(t, wr, "cell2", 2, pb.TabletType_REPLICA)
|
||||
master := NewFakeTablet(t, wr, "cell1", 0, pb.TabletType_MASTER, db)
|
||||
goodSlave := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_REPLICA, db)
|
||||
badSlave := NewFakeTablet(t, wr, "cell2", 2, pb.TabletType_REPLICA, db)
|
||||
|
||||
// Master: set a plausible ReplicationPosition to return,
|
||||
// and expect to add entry in _vt.reparent_journal
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/youtube/vitess/go/vt/logutil"
|
||||
myproto "github.com/youtube/vitess/go/vt/mysqlctl/proto"
|
||||
"github.com/youtube/vitess/go/vt/tabletmanager/tmclient"
|
||||
"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"
|
||||
|
@ -23,17 +24,18 @@ import (
|
|||
|
||||
func TestMigrateServedFrom(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
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()
|
||||
|
||||
// create the source keyspace tablets
|
||||
sourceMaster := NewFakeTablet(t, wr, "cell1", 10, pb.TabletType_MASTER,
|
||||
sourceMaster := NewFakeTablet(t, wr, "cell1", 10, pb.TabletType_MASTER, db,
|
||||
TabletKeyspaceShard(t, "source", "0"))
|
||||
sourceReplica := NewFakeTablet(t, wr, "cell1", 11, pb.TabletType_REPLICA,
|
||||
sourceReplica := NewFakeTablet(t, wr, "cell1", 11, pb.TabletType_REPLICA, db,
|
||||
TabletKeyspaceShard(t, "source", "0"))
|
||||
sourceRdonly := NewFakeTablet(t, wr, "cell1", 12, pb.TabletType_RDONLY,
|
||||
sourceRdonly := NewFakeTablet(t, wr, "cell1", 12, pb.TabletType_RDONLY, db,
|
||||
TabletKeyspaceShard(t, "source", "0"))
|
||||
|
||||
// create the destination keyspace, served form source
|
||||
|
@ -50,11 +52,11 @@ func TestMigrateServedFrom(t *testing.T) {
|
|||
}
|
||||
|
||||
// create the destination keyspace tablets
|
||||
destMaster := NewFakeTablet(t, wr, "cell1", 20, pb.TabletType_MASTER,
|
||||
destMaster := NewFakeTablet(t, wr, "cell1", 20, pb.TabletType_MASTER, db,
|
||||
TabletKeyspaceShard(t, "dest", "0"))
|
||||
destReplica := NewFakeTablet(t, wr, "cell1", 21, pb.TabletType_REPLICA,
|
||||
destReplica := NewFakeTablet(t, wr, "cell1", 21, pb.TabletType_REPLICA, db,
|
||||
TabletKeyspaceShard(t, "dest", "0"))
|
||||
destRdonly := NewFakeTablet(t, wr, "cell1", 22, pb.TabletType_RDONLY,
|
||||
destRdonly := NewFakeTablet(t, wr, "cell1", 22, pb.TabletType_RDONLY, db,
|
||||
TabletKeyspaceShard(t, "dest", "0"))
|
||||
|
||||
// sourceRdonly will see the refresh
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
myproto "github.com/youtube/vitess/go/vt/mysqlctl/proto"
|
||||
"github.com/youtube/vitess/go/vt/tabletmanager/tmclient"
|
||||
"github.com/youtube/vitess/go/vt/topo"
|
||||
"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"
|
||||
|
@ -33,33 +34,34 @@ func checkShardServedTypes(t *testing.T, ts topo.Server, shard string, expected
|
|||
}
|
||||
|
||||
func TestMigrateServedTypes(t *testing.T) {
|
||||
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()
|
||||
|
||||
// create the source shard
|
||||
sourceMaster := NewFakeTablet(t, wr, "cell1", 10, pb.TabletType_MASTER,
|
||||
sourceMaster := NewFakeTablet(t, wr, "cell1", 10, pb.TabletType_MASTER, db,
|
||||
TabletKeyspaceShard(t, "ks", "0"))
|
||||
sourceReplica := NewFakeTablet(t, wr, "cell1", 11, pb.TabletType_REPLICA,
|
||||
sourceReplica := NewFakeTablet(t, wr, "cell1", 11, pb.TabletType_REPLICA, db,
|
||||
TabletKeyspaceShard(t, "ks", "0"))
|
||||
sourceRdonly := NewFakeTablet(t, wr, "cell1", 12, pb.TabletType_RDONLY,
|
||||
sourceRdonly := NewFakeTablet(t, wr, "cell1", 12, pb.TabletType_RDONLY, db,
|
||||
TabletKeyspaceShard(t, "ks", "0"))
|
||||
|
||||
// create the first destination shard
|
||||
dest1Master := NewFakeTablet(t, wr, "cell1", 20, pb.TabletType_MASTER,
|
||||
dest1Master := NewFakeTablet(t, wr, "cell1", 20, pb.TabletType_MASTER, db,
|
||||
TabletKeyspaceShard(t, "ks", "-80"))
|
||||
dest1Replica := NewFakeTablet(t, wr, "cell1", 21, pb.TabletType_REPLICA,
|
||||
dest1Replica := NewFakeTablet(t, wr, "cell1", 21, pb.TabletType_REPLICA, db,
|
||||
TabletKeyspaceShard(t, "ks", "-80"))
|
||||
dest1Rdonly := NewFakeTablet(t, wr, "cell1", 22, pb.TabletType_RDONLY,
|
||||
dest1Rdonly := NewFakeTablet(t, wr, "cell1", 22, pb.TabletType_RDONLY, db,
|
||||
TabletKeyspaceShard(t, "ks", "-80"))
|
||||
|
||||
// create the second destination shard
|
||||
dest2Master := NewFakeTablet(t, wr, "cell1", 30, pb.TabletType_MASTER,
|
||||
dest2Master := NewFakeTablet(t, wr, "cell1", 30, pb.TabletType_MASTER, db,
|
||||
TabletKeyspaceShard(t, "ks", "80-"))
|
||||
dest2Replica := NewFakeTablet(t, wr, "cell1", 31, pb.TabletType_REPLICA,
|
||||
dest2Replica := NewFakeTablet(t, wr, "cell1", 31, pb.TabletType_REPLICA, db,
|
||||
TabletKeyspaceShard(t, "ks", "80-"))
|
||||
dest2Rdonly := NewFakeTablet(t, wr, "cell1", 32, pb.TabletType_RDONLY,
|
||||
dest2Rdonly := NewFakeTablet(t, wr, "cell1", 32, pb.TabletType_RDONLY, db,
|
||||
TabletKeyspaceShard(t, "ks", "80-"))
|
||||
|
||||
// double check the shards have the right served types
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/youtube/vitess/go/sqltypes"
|
||||
"github.com/youtube/vitess/go/vt/logutil"
|
||||
"github.com/youtube/vitess/go/vt/tabletmanager/tmclient"
|
||||
"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"
|
||||
|
@ -23,13 +24,14 @@ import (
|
|||
func TestPermissions(t *testing.T) {
|
||||
// Initialize our environment
|
||||
ctx := context.Background()
|
||||
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()
|
||||
|
||||
master := NewFakeTablet(t, wr, "cell1", 0, pb.TabletType_MASTER)
|
||||
replica := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_REPLICA)
|
||||
master := NewFakeTablet(t, wr, "cell1", 0, pb.TabletType_MASTER, db)
|
||||
replica := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_REPLICA, db)
|
||||
|
||||
// mark the master inside the shard
|
||||
si, err := ts.GetShard(ctx, master.Tablet.Keyspace, master.Tablet.Shard)
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/youtube/vitess/go/vt/tabletmanager/tmclient"
|
||||
"github.com/youtube/vitess/go/vt/tabletserver"
|
||||
"github.com/youtube/vitess/go/vt/topo/topoproto"
|
||||
"github.com/youtube/vitess/go/vt/vttest/fakesqldb"
|
||||
"github.com/youtube/vitess/go/vt/wrangler"
|
||||
"github.com/youtube/vitess/go/vt/zktopo"
|
||||
|
||||
|
@ -21,16 +22,17 @@ import (
|
|||
)
|
||||
|
||||
func TestPlannedReparentShard(t *testing.T) {
|
||||
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()
|
||||
|
||||
// Create a master, a couple good slaves
|
||||
oldMaster := NewFakeTablet(t, wr, "cell1", 0, pb.TabletType_MASTER)
|
||||
newMaster := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_REPLICA)
|
||||
goodSlave1 := NewFakeTablet(t, wr, "cell1", 2, pb.TabletType_REPLICA)
|
||||
goodSlave2 := NewFakeTablet(t, wr, "cell2", 3, pb.TabletType_REPLICA)
|
||||
oldMaster := NewFakeTablet(t, wr, "cell1", 0, pb.TabletType_MASTER, db)
|
||||
newMaster := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_REPLICA, db)
|
||||
goodSlave1 := NewFakeTablet(t, wr, "cell1", 2, pb.TabletType_REPLICA, db)
|
||||
goodSlave2 := NewFakeTablet(t, wr, "cell2", 3, pb.TabletType_REPLICA, db)
|
||||
|
||||
// new master
|
||||
newMaster.FakeMysqlDaemon.ReadOnly = true
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"github.com/youtube/vitess/go/vt/topo/topoproto"
|
||||
"github.com/youtube/vitess/go/vt/topotools"
|
||||
"github.com/youtube/vitess/go/vt/topotools/events"
|
||||
"github.com/youtube/vitess/go/vt/vttest/fakesqldb"
|
||||
"github.com/youtube/vitess/go/vt/wrangler"
|
||||
"github.com/youtube/vitess/go/vt/zktopo"
|
||||
|
||||
|
@ -30,17 +31,18 @@ func TestTabletExternallyReparented(t *testing.T) {
|
|||
tabletmanager.SetReparentFlags(time.Minute /* finalizeTimeout */)
|
||||
|
||||
ctx := context.Background()
|
||||
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()
|
||||
|
||||
// Create an old master, a new master, two good slaves, one bad slave
|
||||
oldMaster := NewFakeTablet(t, wr, "cell1", 0, pb.TabletType_MASTER)
|
||||
newMaster := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_REPLICA)
|
||||
goodSlave1 := NewFakeTablet(t, wr, "cell1", 2, pb.TabletType_REPLICA)
|
||||
goodSlave2 := NewFakeTablet(t, wr, "cell2", 3, pb.TabletType_REPLICA)
|
||||
badSlave := NewFakeTablet(t, wr, "cell1", 4, pb.TabletType_REPLICA)
|
||||
oldMaster := NewFakeTablet(t, wr, "cell1", 0, pb.TabletType_MASTER, db)
|
||||
newMaster := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_REPLICA, db)
|
||||
goodSlave1 := NewFakeTablet(t, wr, "cell1", 2, pb.TabletType_REPLICA, db)
|
||||
goodSlave2 := NewFakeTablet(t, wr, "cell2", 3, pb.TabletType_REPLICA, db)
|
||||
badSlave := NewFakeTablet(t, wr, "cell1", 4, pb.TabletType_REPLICA, db)
|
||||
|
||||
// Add a new Cell to the Shard, that doesn't map to any read topo cell,
|
||||
// to simulate a data center being unreachable.
|
||||
|
@ -165,13 +167,14 @@ func TestTabletExternallyReparentedWithDifferentMysqlPort(t *testing.T) {
|
|||
tabletmanager.SetReparentFlags(time.Minute /* finalizeTimeout */)
|
||||
|
||||
ctx := context.Background()
|
||||
db := fakesqldb.Register()
|
||||
ts := zktopo.NewTestServer(t, []string{"cell1"})
|
||||
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient(), time.Second)
|
||||
|
||||
// Create an old master, a new master, two good slaves, one bad slave
|
||||
oldMaster := NewFakeTablet(t, wr, "cell1", 0, pb.TabletType_MASTER)
|
||||
newMaster := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_REPLICA)
|
||||
goodSlave := NewFakeTablet(t, wr, "cell1", 2, pb.TabletType_REPLICA)
|
||||
oldMaster := NewFakeTablet(t, wr, "cell1", 0, pb.TabletType_MASTER, db)
|
||||
newMaster := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_REPLICA, db)
|
||||
goodSlave := NewFakeTablet(t, wr, "cell1", 2, pb.TabletType_REPLICA, db)
|
||||
|
||||
// Now we're restarting mysql on a different port, 3301->3303
|
||||
// but without updating the Tablet record in topology.
|
||||
|
@ -211,13 +214,14 @@ func TestTabletExternallyReparentedContinueOnUnexpectedMaster(t *testing.T) {
|
|||
tabletmanager.SetReparentFlags(time.Minute /* finalizeTimeout */)
|
||||
|
||||
ctx := context.Background()
|
||||
db := fakesqldb.Register()
|
||||
ts := zktopo.NewTestServer(t, []string{"cell1"})
|
||||
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient(), time.Second)
|
||||
|
||||
// Create an old master, a new master, two good slaves, one bad slave
|
||||
oldMaster := NewFakeTablet(t, wr, "cell1", 0, pb.TabletType_MASTER)
|
||||
newMaster := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_REPLICA)
|
||||
goodSlave := NewFakeTablet(t, wr, "cell1", 2, pb.TabletType_REPLICA)
|
||||
oldMaster := NewFakeTablet(t, wr, "cell1", 0, pb.TabletType_MASTER, db)
|
||||
newMaster := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_REPLICA, db)
|
||||
goodSlave := NewFakeTablet(t, wr, "cell1", 2, pb.TabletType_REPLICA, db)
|
||||
|
||||
// On the elected master, we will respond to
|
||||
// TabletActionSlaveWasPromoted, so we need a MysqlDaemon
|
||||
|
@ -251,13 +255,14 @@ func TestTabletExternallyReparentedFailedOldMaster(t *testing.T) {
|
|||
tabletmanager.SetReparentFlags(time.Minute /* finalizeTimeout */)
|
||||
|
||||
ctx := context.Background()
|
||||
db := fakesqldb.Register()
|
||||
ts := zktopo.NewTestServer(t, []string{"cell1", "cell2"})
|
||||
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient(), time.Second)
|
||||
|
||||
// Create an old master, a new master, and a good slave.
|
||||
oldMaster := NewFakeTablet(t, wr, "cell1", 0, pb.TabletType_MASTER)
|
||||
newMaster := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_REPLICA)
|
||||
goodSlave := NewFakeTablet(t, wr, "cell1", 2, pb.TabletType_REPLICA)
|
||||
oldMaster := NewFakeTablet(t, wr, "cell1", 0, pb.TabletType_MASTER, db)
|
||||
newMaster := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_REPLICA, db)
|
||||
goodSlave := NewFakeTablet(t, wr, "cell1", 2, pb.TabletType_REPLICA, db)
|
||||
|
||||
// Reparent to a replica, and pretend the old master is not responding.
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
myproto "github.com/youtube/vitess/go/vt/mysqlctl/proto"
|
||||
"github.com/youtube/vitess/go/vt/tabletmanager/tmclient"
|
||||
"github.com/youtube/vitess/go/vt/topo/topoproto"
|
||||
"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"
|
||||
|
@ -22,6 +23,7 @@ import (
|
|||
|
||||
func TestShardReplicationStatuses(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db := fakesqldb.Register()
|
||||
ts := zktopo.NewTestServer(t, []string{"cell1", "cell2"})
|
||||
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient(), time.Second)
|
||||
|
||||
|
@ -29,8 +31,8 @@ func TestShardReplicationStatuses(t *testing.T) {
|
|||
if err := ts.CreateShard(ctx, "test_keyspace", "0"); err != nil {
|
||||
t.Fatalf("CreateShard failed: %v", err)
|
||||
}
|
||||
master := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_MASTER)
|
||||
slave := NewFakeTablet(t, wr, "cell1", 2, pb.TabletType_REPLICA)
|
||||
master := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_MASTER, db)
|
||||
slave := NewFakeTablet(t, wr, "cell1", 2, pb.TabletType_REPLICA, db)
|
||||
|
||||
// mark the master inside the shard
|
||||
si, err := ts.GetShard(ctx, "test_keyspace", "0")
|
||||
|
@ -90,6 +92,7 @@ func TestShardReplicationStatuses(t *testing.T) {
|
|||
|
||||
func TestReparentTablet(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db := fakesqldb.Register()
|
||||
ts := zktopo.NewTestServer(t, []string{"cell1", "cell2"})
|
||||
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient(), time.Second)
|
||||
|
||||
|
@ -97,8 +100,8 @@ func TestReparentTablet(t *testing.T) {
|
|||
if err := ts.CreateShard(ctx, "test_keyspace", "0"); err != nil {
|
||||
t.Fatalf("CreateShard failed: %v", err)
|
||||
}
|
||||
master := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_MASTER)
|
||||
slave := NewFakeTablet(t, wr, "cell1", 2, pb.TabletType_REPLICA)
|
||||
master := NewFakeTablet(t, wr, "cell1", 1, pb.TabletType_MASTER, db)
|
||||
slave := NewFakeTablet(t, wr, "cell1", 2, pb.TabletType_REPLICA, db)
|
||||
|
||||
// mark the master inside the shard
|
||||
si, err := ts.GetShard(ctx, "test_keyspace", "0")
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
|
||||
"github.com/youtube/vitess/go/vt/logutil"
|
||||
"github.com/youtube/vitess/go/vt/tabletmanager/tmclient"
|
||||
"github.com/youtube/vitess/go/vt/vttest/fakesqldb"
|
||||
"github.com/youtube/vitess/go/vt/wrangler"
|
||||
"github.com/youtube/vitess/go/vt/zktopo"
|
||||
|
||||
|
@ -49,16 +50,17 @@ func TestVersion(t *testing.T) {
|
|||
wrangler.ResetDebugVarsGetVersion()
|
||||
|
||||
// Initialize our environment
|
||||
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()
|
||||
|
||||
// couple tablets is enough
|
||||
sourceMaster := NewFakeTablet(t, wr, "cell1", 10, pb.TabletType_MASTER,
|
||||
sourceMaster := NewFakeTablet(t, wr, "cell1", 10, pb.TabletType_MASTER, db,
|
||||
TabletKeyspaceShard(t, "source", "0"),
|
||||
StartHTTPServer())
|
||||
sourceReplica := NewFakeTablet(t, wr, "cell1", 11, pb.TabletType_REPLICA,
|
||||
sourceReplica := NewFakeTablet(t, wr, "cell1", 11, pb.TabletType_REPLICA, db,
|
||||
TabletKeyspaceShard(t, "source", "0"),
|
||||
StartHTTPServer())
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
"github.com/youtube/vitess/go/vt/tabletmanager/tmclient"
|
||||
"github.com/youtube/vitess/go/vt/tabletserver"
|
||||
"github.com/youtube/vitess/go/vt/tabletserver/grpcqueryservice"
|
||||
"github.com/youtube/vitess/go/vt/vttest/fakesqldb"
|
||||
"github.com/youtube/vitess/go/vt/wrangler"
|
||||
"github.com/youtube/vitess/go/vt/zktopo"
|
||||
|
||||
|
@ -77,16 +78,17 @@ func TestWaitForFilteredReplication_unhealthy(t *testing.T) {
|
|||
}
|
||||
|
||||
func waitForFilteredReplication(t *testing.T, expectedErr string, initialStats *pbq.RealtimeStats, broadcastStatsFunc func() *pbq.RealtimeStats) {
|
||||
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()
|
||||
|
||||
// source of the filtered replication. We don't start its loop because we don't connect to it.
|
||||
source := NewFakeTablet(t, wr, "cell1", 0, pbt.TabletType_MASTER,
|
||||
source := NewFakeTablet(t, wr, "cell1", 0, pbt.TabletType_MASTER, db,
|
||||
TabletKeyspaceShard(t, keyspace, "0"))
|
||||
// dest is the master of the dest shard which receives filtered replication events.
|
||||
dest := NewFakeTablet(t, wr, "cell1", 1, pbt.TabletType_MASTER,
|
||||
dest := NewFakeTablet(t, wr, "cell1", 1, pbt.TabletType_MASTER, db,
|
||||
TabletKeyspaceShard(t, keyspace, destShard))
|
||||
dest.StartActionLoop(t, wr)
|
||||
defer dest.StopActionLoop(t)
|
||||
|
|
|
@ -96,6 +96,18 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>test-jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,359 @@
|
|||
package com.youtube.vitess.client;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.protobuf.ByteString;
|
||||
|
||||
import com.youtube.vitess.proto.Query.QueryResult;
|
||||
import com.youtube.vitess.proto.Topodata.KeyRange;
|
||||
import com.youtube.vitess.proto.Topodata.KeyspaceIdType;
|
||||
import com.youtube.vitess.proto.Topodata.ShardReference;
|
||||
import com.youtube.vitess.proto.Topodata.SrvKeyspace;
|
||||
import com.youtube.vitess.proto.Topodata.SrvKeyspace.KeyspacePartition;
|
||||
import com.youtube.vitess.proto.Topodata.TabletType;
|
||||
import com.youtube.vitess.proto.Vtgate.SplitQueryResponse;
|
||||
import com.youtube.vitess.proto.Vtrpc.CallerID;
|
||||
|
||||
import org.joda.time.Duration;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* RpcClientTest tests a given implementation of RpcClient
|
||||
* against a mock vtgate server (go/cmd/vtgateclienttest).
|
||||
*
|
||||
* Each implementation should extend this class and add a @BeforeClass method that starts the
|
||||
* vtgateclienttest server with the necessary parameters, and then sets 'client'.
|
||||
*/
|
||||
public abstract class RpcClientTest {
|
||||
protected static RpcClient client;
|
||||
protected static String vtRoot;
|
||||
|
||||
private Context ctx;
|
||||
private VTGateConn conn;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeSubclass() {
|
||||
vtRoot = System.getenv("VTROOT");
|
||||
if (vtRoot == null) {
|
||||
throw new RuntimeException("cannot find env variable VTROOT; make sure to source dev.env");
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
ctx = Context.getDefault().withDeadlineAfter(Duration.millis(5000)).withCallerId(CALLER_ID);
|
||||
conn = new VTGateConn(client);
|
||||
}
|
||||
|
||||
private static final String ECHO_PREFIX = "echo://";
|
||||
|
||||
private static final String QUERY = "test query";
|
||||
private static final String KEYSPACE = "test_keyspace";
|
||||
|
||||
private static final List<String> SHARDS = Arrays.asList("-80", "80-");
|
||||
private static final String SHARDS_ECHO = "[-80 80-]";
|
||||
|
||||
private static final List<byte[]> KEYSPACE_IDS =
|
||||
Arrays.asList(new byte[] {1, 2, 3, 4}, new byte[] {5, 6, 7, 8});
|
||||
private static final String KEYSPACE_IDS_ECHO = "[[1 2 3 4] [5 6 7 8]]";
|
||||
private static final String KEYSPACE_IDS_ECHO_OLD = "[01020304 05060708]";
|
||||
|
||||
private static final List<KeyRange> KEY_RANGES = Arrays.asList(
|
||||
KeyRange.newBuilder()
|
||||
.setStart(ByteString.copyFrom(new byte[] {1, 2, 3, 4}))
|
||||
.setEnd(ByteString.copyFrom(new byte[] {5, 6, 7, 8}))
|
||||
.build());
|
||||
private static final String KEY_RANGES_ECHO =
|
||||
"[start:\"\\001\\002\\003\\004\" end:\"\\005\\006\\007\\010\" ]";
|
||||
|
||||
private static final Map<byte[], Object> ENTITY_KEYSPACE_IDS =
|
||||
new ImmutableMap.Builder<byte[], Object>()
|
||||
.put(new byte[] {1, 2, 3}, 123)
|
||||
.put(new byte[] {4, 5, 6}, 2.0)
|
||||
.put(new byte[] {7, 8, 9}, new byte[] {1, 2, 3})
|
||||
.build();
|
||||
private static final String ENTITY_KEYSPACE_IDS_ECHO =
|
||||
"[xid_type:TYPE_INT xid_int:123 keyspace_id:\"\\001\\002\\003\" xid_type:TYPE_FLOAT xid_float:2 keyspace_id:\"\\004\\005\\006\" xid_type:TYPE_BYTES xid_bytes:\"\\001\\002\\003\" keyspace_id:\"\\007\\010\\t\" ]";
|
||||
|
||||
private static final TabletType TABLET_TYPE = TabletType.REPLICA;
|
||||
private static final String TABLET_TYPE_ECHO = TABLET_TYPE.toString();
|
||||
|
||||
private static final Map<String, Object> BIND_VARS =
|
||||
new ImmutableMap.Builder<String, Object>()
|
||||
.put("int", 123)
|
||||
.put("float", 2.0)
|
||||
.put("bytes", new byte[] {1, 2, 3})
|
||||
.build();
|
||||
private static final String BIND_VARS_ECHO = "map[bytes:[1 2 3] float:2 int:123]";
|
||||
|
||||
private static final String SESSION_ECHO = "InTransaction: true, ShardSession: []";
|
||||
|
||||
private static final CallerID CALLER_ID =
|
||||
CallerID.newBuilder()
|
||||
.setPrincipal("test_principal")
|
||||
.setComponent("test_component")
|
||||
.setSubcomponent("test_subcomponent")
|
||||
.build();
|
||||
private static final String CALLER_ID_ECHO =
|
||||
"principal:\"test_principal\" component:\"test_component\" subcomponent:\"test_subcomponent\" ";
|
||||
|
||||
private static Map<String, String> getEcho(QueryResult result) {
|
||||
Map<String, String> fields = new HashMap<String, String>();
|
||||
for (int i = 0; i < result.getFieldsCount(); i++) {
|
||||
fields.put(result.getFields(i).getName(), result.getRows(0).getValues(i).toStringUtf8());
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEchoExecute() throws Exception {
|
||||
Map<String, String> echo;
|
||||
|
||||
echo = getEcho(conn.execute(ctx, ECHO_PREFIX + QUERY, BIND_VARS, TABLET_TYPE));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
|
||||
echo = getEcho(
|
||||
conn.executeShards(ctx, ECHO_PREFIX + QUERY, KEYSPACE, SHARDS, BIND_VARS, TABLET_TYPE));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(SHARDS_ECHO, echo.get("shards"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
|
||||
echo = getEcho(conn.executeKeyspaceIds(
|
||||
ctx, ECHO_PREFIX + QUERY, KEYSPACE, KEYSPACE_IDS, BIND_VARS, TABLET_TYPE));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(KEYSPACE_IDS_ECHO, echo.get("keyspaceIds"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
|
||||
echo = getEcho(conn.executeKeyRanges(
|
||||
ctx, ECHO_PREFIX + QUERY, KEYSPACE, KEY_RANGES, BIND_VARS, TABLET_TYPE));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(KEY_RANGES_ECHO, echo.get("keyRanges"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
|
||||
echo = getEcho(conn.executeEntityIds(ctx, ECHO_PREFIX + QUERY, KEYSPACE, "column1",
|
||||
ENTITY_KEYSPACE_IDS, BIND_VARS, TABLET_TYPE));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals("column1", echo.get("entityColumnName"));
|
||||
Assert.assertEquals(ENTITY_KEYSPACE_IDS_ECHO, echo.get("entityIds"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
|
||||
echo = getEcho(conn.executeBatchShards(ctx, Arrays.asList(Proto.bindShardQuery(KEYSPACE, SHARDS,
|
||||
ECHO_PREFIX + QUERY, BIND_VARS)),
|
||||
TABLET_TYPE, true).get(0));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(SHARDS_ECHO, echo.get("shards"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
Assert.assertEquals("true", echo.get("asTransaction"));
|
||||
|
||||
echo = getEcho(
|
||||
conn.executeBatchKeyspaceIds(ctx, Arrays.asList(Proto.bindKeyspaceIdQuery(KEYSPACE,
|
||||
KEYSPACE_IDS, ECHO_PREFIX + QUERY, BIND_VARS)),
|
||||
TABLET_TYPE, true).get(0));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(KEYSPACE_IDS_ECHO_OLD, echo.get("keyspaceIds"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
Assert.assertEquals("true", echo.get("asTransaction"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEchoStreamExecute() throws Exception {
|
||||
Map<String, String> echo;
|
||||
|
||||
echo = getEcho(conn.streamExecute(ctx, ECHO_PREFIX + QUERY, BIND_VARS, TABLET_TYPE).next());
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
|
||||
echo = getEcho(
|
||||
conn.streamExecuteShards(ctx, ECHO_PREFIX + QUERY, KEYSPACE, SHARDS, BIND_VARS, TABLET_TYPE)
|
||||
.next());
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(SHARDS_ECHO, echo.get("shards"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
|
||||
echo = getEcho(conn.streamExecuteKeyspaceIds(ctx, ECHO_PREFIX + QUERY, KEYSPACE, KEYSPACE_IDS,
|
||||
BIND_VARS, TABLET_TYPE).next());
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(KEYSPACE_IDS_ECHO, echo.get("keyspaceIds"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
|
||||
echo = getEcho(conn.streamExecuteKeyRanges(ctx, ECHO_PREFIX + QUERY, KEYSPACE, KEY_RANGES,
|
||||
BIND_VARS, TABLET_TYPE).next());
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(KEY_RANGES_ECHO, echo.get("keyRanges"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEchoTransactionExecute() throws Exception {
|
||||
Map<String, String> echo;
|
||||
|
||||
VTGateTx tx = conn.begin(ctx);
|
||||
|
||||
echo = getEcho(tx.execute(ctx, ECHO_PREFIX + QUERY, BIND_VARS, TABLET_TYPE, true));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
Assert.assertEquals(SESSION_ECHO, echo.get("session"));
|
||||
Assert.assertEquals("true", echo.get("notInTransaction"));
|
||||
|
||||
echo = getEcho(
|
||||
tx.executeShards(ctx, ECHO_PREFIX + QUERY, KEYSPACE, SHARDS, BIND_VARS, TABLET_TYPE, true));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(SHARDS_ECHO, echo.get("shards"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
Assert.assertEquals(SESSION_ECHO, echo.get("session"));
|
||||
Assert.assertEquals("true", echo.get("notInTransaction"));
|
||||
|
||||
echo = getEcho(tx.executeKeyspaceIds(
|
||||
ctx, ECHO_PREFIX + QUERY, KEYSPACE, KEYSPACE_IDS, BIND_VARS, TABLET_TYPE, true));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(KEYSPACE_IDS_ECHO, echo.get("keyspaceIds"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
Assert.assertEquals(SESSION_ECHO, echo.get("session"));
|
||||
Assert.assertEquals("true", echo.get("notInTransaction"));
|
||||
|
||||
echo = getEcho(tx.executeKeyRanges(
|
||||
ctx, ECHO_PREFIX + QUERY, KEYSPACE, KEY_RANGES, BIND_VARS, TABLET_TYPE, true));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(KEY_RANGES_ECHO, echo.get("keyRanges"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
Assert.assertEquals(SESSION_ECHO, echo.get("session"));
|
||||
Assert.assertEquals("true", echo.get("notInTransaction"));
|
||||
|
||||
echo = getEcho(tx.executeEntityIds(ctx, ECHO_PREFIX + QUERY, KEYSPACE, "column1",
|
||||
ENTITY_KEYSPACE_IDS, BIND_VARS, TABLET_TYPE, true));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals("column1", echo.get("entityColumnName"));
|
||||
Assert.assertEquals(ENTITY_KEYSPACE_IDS_ECHO, echo.get("entityIds"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
Assert.assertEquals(SESSION_ECHO, echo.get("session"));
|
||||
Assert.assertEquals("true", echo.get("notInTransaction"));
|
||||
|
||||
tx.rollback(ctx);
|
||||
tx = conn.begin(ctx);
|
||||
|
||||
echo = getEcho(tx.executeBatchShards(ctx, Arrays.asList(Proto.bindShardQuery(KEYSPACE, SHARDS,
|
||||
ECHO_PREFIX + QUERY, BIND_VARS)),
|
||||
TABLET_TYPE, true).get(0));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(SHARDS_ECHO, echo.get("shards"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
Assert.assertEquals(SESSION_ECHO, echo.get("session"));
|
||||
Assert.assertEquals("true", echo.get("asTransaction"));
|
||||
|
||||
echo =
|
||||
getEcho(tx.executeBatchKeyspaceIds(ctx, Arrays.asList(Proto.bindKeyspaceIdQuery(KEYSPACE,
|
||||
KEYSPACE_IDS, ECHO_PREFIX + QUERY, BIND_VARS)),
|
||||
TABLET_TYPE, true).get(0));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(KEYSPACE_IDS_ECHO_OLD, echo.get("keyspaceIds"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
Assert.assertEquals(SESSION_ECHO, echo.get("session"));
|
||||
Assert.assertEquals("true", echo.get("asTransaction"));
|
||||
|
||||
tx.commit(ctx);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEchoSplitQuery() throws Exception {
|
||||
SplitQueryResponse.Part expected =
|
||||
SplitQueryResponse.Part.newBuilder()
|
||||
.setQuery(Proto.bindQuery(ECHO_PREFIX + QUERY + ":split_column:123", BIND_VARS))
|
||||
.setKeyRangePart(
|
||||
SplitQueryResponse.KeyRangePart.newBuilder().setKeyspace(KEYSPACE).build())
|
||||
.build();
|
||||
SplitQueryResponse.Part actual =
|
||||
conn.splitQuery(ctx, KEYSPACE, ECHO_PREFIX + QUERY, BIND_VARS, "split_column", 123).get(0);
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSrvKeyspace() throws Exception {
|
||||
SrvKeyspace expected =
|
||||
SrvKeyspace.newBuilder()
|
||||
.addPartitions(
|
||||
KeyspacePartition.newBuilder()
|
||||
.setServedType(TabletType.REPLICA)
|
||||
.addShardReferences(
|
||||
ShardReference.newBuilder()
|
||||
.setName("shard0")
|
||||
.setKeyRange(
|
||||
KeyRange.newBuilder()
|
||||
.setStart(
|
||||
ByteString.copyFrom(new byte[] {0x40, 0, 0, 0, 0, 0, 0, 0}))
|
||||
.setEnd(ByteString.copyFrom(
|
||||
new byte[] {(byte) 0x80, 0, 0, 0, 0, 0, 0, 0}))
|
||||
.build())
|
||||
.build())
|
||||
.build())
|
||||
.setShardingColumnName("sharding_column_name")
|
||||
.setShardingColumnType(KeyspaceIdType.UINT64)
|
||||
.addServedFrom(
|
||||
SrvKeyspace.ServedFrom.newBuilder()
|
||||
.setTabletType(TabletType.MASTER)
|
||||
.setKeyspace("other_keyspace")
|
||||
.build())
|
||||
.setSplitShardCount(128)
|
||||
.build();
|
||||
SrvKeyspace actual = conn.getSrvKeyspace(ctx, "big");
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
}
|
|
@ -16,6 +16,13 @@
|
|||
<artifactId>client</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.youtube.vitess</groupId>
|
||||
<artifactId>client</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-all</artifactId>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.youtube.vitess.client.grpc;
|
||||
|
||||
import com.youtube.vitess.client.Context;
|
||||
import com.youtube.vitess.client.Proto;
|
||||
import com.youtube.vitess.client.RpcClient;
|
||||
import com.youtube.vitess.client.StreamIterator;
|
||||
import com.youtube.vitess.client.VitessException;
|
||||
|
@ -218,8 +217,7 @@ public class GrpcClient implements RpcClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BeginResponse begin(Context ctx, BeginRequest request)
|
||||
throws VitessRpcException {
|
||||
public BeginResponse begin(Context ctx, BeginRequest request) throws VitessRpcException {
|
||||
try (GrpcContext gctx = new GrpcContext(ctx)) {
|
||||
return blockingStub.begin(request);
|
||||
} catch (Exception e) {
|
||||
|
@ -228,8 +226,7 @@ public class GrpcClient implements RpcClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CommitResponse commit(Context ctx, CommitRequest request)
|
||||
throws VitessRpcException {
|
||||
public CommitResponse commit(Context ctx, CommitRequest request) throws VitessRpcException {
|
||||
try (GrpcContext gctx = new GrpcContext(ctx)) {
|
||||
return blockingStub.commit(request);
|
||||
} catch (Exception e) {
|
||||
|
@ -238,8 +235,7 @@ public class GrpcClient implements RpcClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public RollbackResponse rollback(Context ctx, RollbackRequest request)
|
||||
throws VitessRpcException {
|
||||
public RollbackResponse rollback(Context ctx, RollbackRequest request) throws VitessRpcException {
|
||||
try (GrpcContext gctx = new GrpcContext(ctx)) {
|
||||
return blockingStub.rollback(request);
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -1,52 +1,25 @@
|
|||
package com.youtube.vitess.client.grpc;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.protobuf.ByteString;
|
||||
|
||||
import com.youtube.vitess.client.Context;
|
||||
import com.youtube.vitess.client.Proto;
|
||||
import com.youtube.vitess.client.RpcClient;
|
||||
import com.youtube.vitess.client.VTGateConn;
|
||||
import com.youtube.vitess.client.VTGateTx;
|
||||
import com.youtube.vitess.proto.Query.QueryResult;
|
||||
import com.youtube.vitess.proto.Topodata.KeyRange;
|
||||
import com.youtube.vitess.proto.Topodata.KeyspaceIdType;
|
||||
import com.youtube.vitess.proto.Topodata.ShardReference;
|
||||
import com.youtube.vitess.proto.Topodata.SrvKeyspace;
|
||||
import com.youtube.vitess.proto.Topodata.SrvKeyspace.KeyspacePartition;
|
||||
import com.youtube.vitess.proto.Topodata.TabletType;
|
||||
import com.youtube.vitess.proto.Vtgate.SplitQueryResponse;
|
||||
import com.youtube.vitess.proto.Vtrpc.CallerID;
|
||||
import com.youtube.vitess.client.RpcClientTest;
|
||||
|
||||
import org.joda.time.Duration;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This tests GrpcClient with a mock vtgate server (go/cmd/vtgateclienttest).
|
||||
*/
|
||||
public class GrpcClientTest {
|
||||
public class GrpcClientTest extends RpcClientTest {
|
||||
private static Process vtgateclienttest;
|
||||
private static int port;
|
||||
private static RpcClient client;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
String vtRoot = System.getenv("VTROOT");
|
||||
if (vtRoot == null) {
|
||||
throw new RuntimeException("cannot find env variable VTROOT; make sure to source dev.env");
|
||||
}
|
||||
|
||||
ServerSocket socket = new ServerSocket(0);
|
||||
port = socket.getLocalPort();
|
||||
socket.close();
|
||||
|
@ -70,313 +43,4 @@ public class GrpcClientTest {
|
|||
vtgateclienttest.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
private Context ctx;
|
||||
private VTGateConn conn;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
ctx = Context.getDefault().withDeadlineAfter(Duration.millis(5000)).withCallerId(CALLER_ID);
|
||||
conn = new VTGateConn(client);
|
||||
}
|
||||
|
||||
private static final String ECHO_PREFIX = "echo://";
|
||||
|
||||
private static final String QUERY = "test query";
|
||||
private static final String KEYSPACE = "test_keyspace";
|
||||
|
||||
private static final List<String> SHARDS = Arrays.asList("-80", "80-");
|
||||
private static final String SHARDS_ECHO = "[-80 80-]";
|
||||
|
||||
private static final List<byte[]> KEYSPACE_IDS =
|
||||
Arrays.asList(new byte[] {1, 2, 3, 4}, new byte[] {5, 6, 7, 8});
|
||||
private static final String KEYSPACE_IDS_ECHO = "[[1 2 3 4] [5 6 7 8]]";
|
||||
private static final String KEYSPACE_IDS_ECHO_OLD = "[01020304 05060708]";
|
||||
|
||||
private static final List<KeyRange> KEY_RANGES = Arrays.asList(
|
||||
KeyRange.newBuilder()
|
||||
.setStart(ByteString.copyFrom(new byte[] {1, 2, 3, 4}))
|
||||
.setEnd(ByteString.copyFrom(new byte[] {5, 6, 7, 8}))
|
||||
.build());
|
||||
private static final String KEY_RANGES_ECHO = "[start:\"\\001\\002\\003\\004\" end:\"\\005\\006\\007\\010\" ]";
|
||||
|
||||
private static final Map<byte[], Object> ENTITY_KEYSPACE_IDS =
|
||||
new ImmutableMap.Builder<byte[], Object>()
|
||||
.put(new byte[] {1, 2, 3}, 123)
|
||||
.put(new byte[] {4, 5, 6}, 2.0)
|
||||
.put(new byte[] {7, 8, 9}, new byte[] {1, 2, 3})
|
||||
.build();
|
||||
private static final String ENTITY_KEYSPACE_IDS_ECHO =
|
||||
"[xid_type:TYPE_INT xid_int:123 keyspace_id:\"\\001\\002\\003\" xid_type:TYPE_FLOAT xid_float:2 keyspace_id:\"\\004\\005\\006\" xid_type:TYPE_BYTES xid_bytes:\"\\001\\002\\003\" keyspace_id:\"\\007\\010\\t\" ]";
|
||||
|
||||
private static final TabletType TABLET_TYPE = TabletType.REPLICA;
|
||||
private static final String TABLET_TYPE_ECHO = TABLET_TYPE.toString();
|
||||
|
||||
private static final Map<String, Object> BIND_VARS =
|
||||
new ImmutableMap.Builder<String, Object>()
|
||||
.put("int", 123)
|
||||
.put("float", 2.0)
|
||||
.put("bytes", new byte[] {1, 2, 3})
|
||||
.build();
|
||||
private static final String BIND_VARS_ECHO = "map[bytes:[1 2 3] float:2 int:123]";
|
||||
|
||||
private static final String SESSION_ECHO = "InTransaction: true, ShardSession: []";
|
||||
|
||||
private static final CallerID CALLER_ID =
|
||||
CallerID.newBuilder()
|
||||
.setPrincipal("test_principal")
|
||||
.setComponent("test_component")
|
||||
.setSubcomponent("test_subcomponent")
|
||||
.build();
|
||||
private static final String CALLER_ID_ECHO =
|
||||
"principal:\"test_principal\" component:\"test_component\" subcomponent:\"test_subcomponent\" ";
|
||||
|
||||
private static Map<String, String> getEcho(QueryResult result) {
|
||||
Map<String, String> fields = new HashMap<String, String>();
|
||||
for (int i = 0; i < result.getFieldsCount(); i++) {
|
||||
fields.put(result.getFields(i).getName(), result.getRows(0).getValues(i).toStringUtf8());
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEchoExecute() throws Exception {
|
||||
Map<String, String> echo;
|
||||
|
||||
echo = getEcho(conn.execute(ctx, ECHO_PREFIX + QUERY, BIND_VARS, TABLET_TYPE));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
|
||||
echo = getEcho(
|
||||
conn.executeShards(ctx, ECHO_PREFIX + QUERY, KEYSPACE, SHARDS, BIND_VARS, TABLET_TYPE));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(SHARDS_ECHO, echo.get("shards"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
|
||||
echo = getEcho(conn.executeKeyspaceIds(
|
||||
ctx, ECHO_PREFIX + QUERY, KEYSPACE, KEYSPACE_IDS, BIND_VARS, TABLET_TYPE));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(KEYSPACE_IDS_ECHO, echo.get("keyspaceIds"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
|
||||
echo = getEcho(conn.executeKeyRanges(
|
||||
ctx, ECHO_PREFIX + QUERY, KEYSPACE, KEY_RANGES, BIND_VARS, TABLET_TYPE));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(KEY_RANGES_ECHO, echo.get("keyRanges"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
|
||||
echo = getEcho(conn.executeEntityIds(ctx, ECHO_PREFIX + QUERY, KEYSPACE, "column1",
|
||||
ENTITY_KEYSPACE_IDS, BIND_VARS, TABLET_TYPE));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals("column1", echo.get("entityColumnName"));
|
||||
Assert.assertEquals(ENTITY_KEYSPACE_IDS_ECHO, echo.get("entityIds"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
|
||||
echo = getEcho(conn.executeBatchShards(ctx, Arrays.asList(Proto.bindShardQuery(KEYSPACE, SHARDS,
|
||||
ECHO_PREFIX + QUERY, BIND_VARS)),
|
||||
TABLET_TYPE, true).get(0));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(SHARDS_ECHO, echo.get("shards"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
|
||||
echo = getEcho(
|
||||
conn.executeBatchKeyspaceIds(ctx, Arrays.asList(Proto.bindKeyspaceIdQuery(KEYSPACE,
|
||||
KEYSPACE_IDS, ECHO_PREFIX + QUERY, BIND_VARS)),
|
||||
TABLET_TYPE, true).get(0));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(KEYSPACE_IDS_ECHO_OLD, echo.get("keyspaceIds"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEchoStreamExecute() throws Exception {
|
||||
Map<String, String> echo;
|
||||
|
||||
echo = getEcho(conn.streamExecute(ctx, ECHO_PREFIX + QUERY, BIND_VARS, TABLET_TYPE).next());
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
|
||||
echo = getEcho(
|
||||
conn.streamExecuteShards(ctx, ECHO_PREFIX + QUERY, KEYSPACE, SHARDS, BIND_VARS, TABLET_TYPE)
|
||||
.next());
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(SHARDS_ECHO, echo.get("shards"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
|
||||
echo = getEcho(conn.streamExecuteKeyspaceIds(ctx, ECHO_PREFIX + QUERY, KEYSPACE, KEYSPACE_IDS,
|
||||
BIND_VARS, TABLET_TYPE).next());
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(KEYSPACE_IDS_ECHO, echo.get("keyspaceIds"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
|
||||
echo = getEcho(conn.streamExecuteKeyRanges(ctx, ECHO_PREFIX + QUERY, KEYSPACE, KEY_RANGES,
|
||||
BIND_VARS, TABLET_TYPE).next());
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(KEY_RANGES_ECHO, echo.get("keyRanges"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEchoTransactionExecute() throws Exception {
|
||||
Map<String, String> echo;
|
||||
|
||||
VTGateTx tx = conn.begin(ctx);
|
||||
|
||||
echo = getEcho(tx.execute(ctx, ECHO_PREFIX + QUERY, BIND_VARS, TABLET_TYPE, true));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
Assert.assertEquals(SESSION_ECHO, echo.get("session"));
|
||||
Assert.assertEquals("true", echo.get("notInTransaction"));
|
||||
|
||||
echo = getEcho(
|
||||
tx.executeShards(ctx, ECHO_PREFIX + QUERY, KEYSPACE, SHARDS, BIND_VARS, TABLET_TYPE, true));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(SHARDS_ECHO, echo.get("shards"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
Assert.assertEquals(SESSION_ECHO, echo.get("session"));
|
||||
Assert.assertEquals("true", echo.get("notInTransaction"));
|
||||
|
||||
echo = getEcho(tx.executeKeyspaceIds(
|
||||
ctx, ECHO_PREFIX + QUERY, KEYSPACE, KEYSPACE_IDS, BIND_VARS, TABLET_TYPE, true));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(KEYSPACE_IDS_ECHO, echo.get("keyspaceIds"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
Assert.assertEquals(SESSION_ECHO, echo.get("session"));
|
||||
Assert.assertEquals("true", echo.get("notInTransaction"));
|
||||
|
||||
echo = getEcho(tx.executeKeyRanges(
|
||||
ctx, ECHO_PREFIX + QUERY, KEYSPACE, KEY_RANGES, BIND_VARS, TABLET_TYPE, true));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(KEY_RANGES_ECHO, echo.get("keyRanges"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
Assert.assertEquals(SESSION_ECHO, echo.get("session"));
|
||||
Assert.assertEquals("true", echo.get("notInTransaction"));
|
||||
|
||||
echo = getEcho(tx.executeEntityIds(ctx, ECHO_PREFIX + QUERY, KEYSPACE, "column1",
|
||||
ENTITY_KEYSPACE_IDS, BIND_VARS, TABLET_TYPE, true));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals("column1", echo.get("entityColumnName"));
|
||||
Assert.assertEquals(ENTITY_KEYSPACE_IDS_ECHO, echo.get("entityIds"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
Assert.assertEquals(SESSION_ECHO, echo.get("session"));
|
||||
Assert.assertEquals("true", echo.get("notInTransaction"));
|
||||
|
||||
tx.rollback(ctx);
|
||||
tx = conn.begin(ctx);
|
||||
|
||||
echo = getEcho(tx.executeBatchShards(ctx, Arrays.asList(Proto.bindShardQuery(KEYSPACE, SHARDS,
|
||||
ECHO_PREFIX + QUERY, BIND_VARS)),
|
||||
TABLET_TYPE, true).get(0));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(SHARDS_ECHO, echo.get("shards"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
Assert.assertEquals(SESSION_ECHO, echo.get("session"));
|
||||
|
||||
echo =
|
||||
getEcho(tx.executeBatchKeyspaceIds(ctx, Arrays.asList(Proto.bindKeyspaceIdQuery(KEYSPACE,
|
||||
KEYSPACE_IDS, ECHO_PREFIX + QUERY, BIND_VARS)),
|
||||
TABLET_TYPE, true).get(0));
|
||||
Assert.assertEquals(CALLER_ID_ECHO, echo.get("callerId"));
|
||||
Assert.assertEquals(ECHO_PREFIX + QUERY, echo.get("query"));
|
||||
Assert.assertEquals(KEYSPACE, echo.get("keyspace"));
|
||||
Assert.assertEquals(KEYSPACE_IDS_ECHO_OLD, echo.get("keyspaceIds"));
|
||||
Assert.assertEquals(BIND_VARS_ECHO, echo.get("bindVars"));
|
||||
Assert.assertEquals(TABLET_TYPE_ECHO, echo.get("tabletType"));
|
||||
Assert.assertEquals(SESSION_ECHO, echo.get("session"));
|
||||
|
||||
tx.commit(ctx);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEchoSplitQuery() throws Exception {
|
||||
SplitQueryResponse.Part expected =
|
||||
SplitQueryResponse.Part.newBuilder()
|
||||
.setQuery(Proto.bindQuery(ECHO_PREFIX + QUERY + ":split_column:123", BIND_VARS))
|
||||
.setKeyRangePart(
|
||||
SplitQueryResponse.KeyRangePart.newBuilder().setKeyspace(KEYSPACE).build())
|
||||
.build();
|
||||
SplitQueryResponse.Part actual =
|
||||
conn.splitQuery(ctx, KEYSPACE, ECHO_PREFIX + QUERY, BIND_VARS, "split_column", 123).get(0);
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSrvKeyspace() throws Exception {
|
||||
SrvKeyspace expected =
|
||||
SrvKeyspace.newBuilder()
|
||||
.addPartitions(
|
||||
KeyspacePartition.newBuilder()
|
||||
.setServedType(TabletType.REPLICA)
|
||||
.addShardReferences(
|
||||
ShardReference.newBuilder()
|
||||
.setName("shard0")
|
||||
.setKeyRange(
|
||||
KeyRange.newBuilder()
|
||||
.setStart(
|
||||
ByteString.copyFrom(new byte[] {0x40, 0, 0, 0, 0, 0, 0, 0}))
|
||||
.setEnd(ByteString.copyFrom(
|
||||
new byte[] {(byte) 0x80, 0, 0, 0, 0, 0, 0, 0}))
|
||||
.build())
|
||||
.build())
|
||||
.build())
|
||||
.setShardingColumnName("sharding_column_name")
|
||||
.setShardingColumnType(KeyspaceIdType.UINT64)
|
||||
.addServedFrom(
|
||||
SrvKeyspace.ServedFrom.newBuilder()
|
||||
.setTabletType(TabletType.MASTER)
|
||||
.setKeyspace("other_keyspace")
|
||||
.build())
|
||||
.setSplitShardCount(128)
|
||||
.build();
|
||||
SrvKeyspace actual = conn.getSrvKeyspace(ctx, "big");
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
|
|
7
test.go
7
test.go
|
@ -616,7 +616,12 @@ firstPass:
|
|||
// Update config and print results.
|
||||
for i, tests := range shards {
|
||||
for _, t := range tests {
|
||||
config.Tests[t.name].Shard = i
|
||||
ct, ok := config.Tests[t.name]
|
||||
if !ok {
|
||||
log.Printf("WARNING: skipping unknown test: %v", t.name)
|
||||
continue
|
||||
}
|
||||
ct.Shard = i
|
||||
log.Printf("% 32v:\t%v\n", t.name, t.PassTime)
|
||||
}
|
||||
log.Printf("Shard %v total: %v\n", i, time.Duration(sums[i]))
|
||||
|
|
113
test/config.json
113
test/config.json
|
@ -5,35 +5,40 @@
|
|||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 3
|
||||
"Shard": 4,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"backup": {
|
||||
"File": "backup.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 4
|
||||
"Shard": 4,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"binlog": {
|
||||
"File": "binlog.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 4
|
||||
"Shard": 3,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"client": {
|
||||
"File": "client_test.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 4
|
||||
"Shard": 4,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"custom_sharding": {
|
||||
"File": "custom_sharding.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 4
|
||||
"Shard": 4,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"goveralls": {
|
||||
"File": "",
|
||||
|
@ -42,21 +47,24 @@
|
|||
"travis/goveralls.sh"
|
||||
],
|
||||
"Manual": true,
|
||||
"Shard": 0
|
||||
"Shard": 1,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"initial_sharding": {
|
||||
"File": "initial_sharding.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 1
|
||||
"Shard": 3,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"initial_sharding_bytes": {
|
||||
"File": "initial_sharding_bytes.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 3
|
||||
"Shard": 3,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"java": {
|
||||
"File": "",
|
||||
|
@ -66,28 +74,32 @@
|
|||
"java_test"
|
||||
],
|
||||
"Manual": false,
|
||||
"Shard": 2
|
||||
"Shard": 2,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"keyrange": {
|
||||
"File": "keyrange_test.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 4
|
||||
"Shard": 1,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"keyspace": {
|
||||
"File": "keyspace_test.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 4
|
||||
"Shard": 1,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"mysqlctl": {
|
||||
"File": "mysqlctl.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 4
|
||||
"Shard": 4,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"php": {
|
||||
"File": "",
|
||||
|
@ -97,14 +109,16 @@
|
|||
"php_test"
|
||||
],
|
||||
"Manual": false,
|
||||
"Shard": 1
|
||||
"Shard": 2,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"python_client": {
|
||||
"File": "python_client_test.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 4
|
||||
"Shard": 3,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"queryservice_vtocc": {
|
||||
"File": "queryservice_test.py",
|
||||
|
@ -115,7 +129,8 @@
|
|||
],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 0
|
||||
"Shard": 4,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"queryservice_vttablet": {
|
||||
"File": "queryservice_test.py",
|
||||
|
@ -126,77 +141,88 @@
|
|||
],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 3
|
||||
"Shard": 3,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"reparent": {
|
||||
"File": "reparent.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 2
|
||||
"Shard": 4,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"resharding": {
|
||||
"File": "resharding.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 1
|
||||
"Shard": 0,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"resharding_bytes": {
|
||||
"File": "resharding_bytes.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 2
|
||||
"Shard": 1,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"rowcache_invalidator": {
|
||||
"File": "rowcache_invalidator.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 4
|
||||
"Shard": 4,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"schema": {
|
||||
"File": "schema.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 4
|
||||
"Shard": 4,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"secure": {
|
||||
"File": "secure.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 4
|
||||
"Shard": 0,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"sharded": {
|
||||
"File": "sharded.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 2
|
||||
"Shard": 4,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"sql_builder_test": {
|
||||
"sql_builder": {
|
||||
"File": "sql_builder_test.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 1
|
||||
"Shard": 3,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"tablet": {
|
||||
"File": "tablet_test.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 4
|
||||
"Shard": 1,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"tabletmanager": {
|
||||
"File": "tabletmanager.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 3
|
||||
"Shard": 2,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"unit": {
|
||||
"File": "",
|
||||
|
@ -205,7 +231,7 @@
|
|||
"tools/unit_test_runner.sh"
|
||||
],
|
||||
"Manual": false,
|
||||
"Shard": 0,
|
||||
"Shard": 3,
|
||||
"RetryMax": 1
|
||||
},
|
||||
"unit_race": {
|
||||
|
@ -216,63 +242,72 @@
|
|||
"unit_test_race"
|
||||
],
|
||||
"Manual": false,
|
||||
"Shard": 3
|
||||
"Shard": 2,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"update_stream": {
|
||||
"File": "update_stream.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 4
|
||||
"Shard": 4,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"vertical_split": {
|
||||
"File": "vertical_split.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 4
|
||||
"Shard": 4,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"vtdb": {
|
||||
"File": "vtdb_test.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 3
|
||||
"Shard": 3,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"vtgate_utils": {
|
||||
"File": "vtgate_utils_test.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 4
|
||||
"Shard": 1,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"vtgatev2": {
|
||||
"File": "vtgatev2_test.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 1
|
||||
"Shard": 0,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"vtgatev3": {
|
||||
"File": "vtgatev3_test.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 1
|
||||
"Shard": 4,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"vttest_sample_test": {
|
||||
"vttest_sample": {
|
||||
"File": "vttest_sample_test.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 1
|
||||
"Shard": 2,
|
||||
"RetryMax": 0
|
||||
},
|
||||
"worker": {
|
||||
"File": "worker.py",
|
||||
"Args": [],
|
||||
"Command": [],
|
||||
"Manual": false,
|
||||
"Shard": 4
|
||||
"Shard": 3,
|
||||
"RetryMax": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче