vitess-gh/go/test/endtoend/vtgate/main_test.go

204 строки
3.7 KiB
Go

/*
Copyright 2019 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package vtgate
import (
"flag"
"os"
"testing"
"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/test/endtoend/cluster"
)
var (
clusterInstance *cluster.LocalProcessCluster
vtParams mysql.ConnParams
KeyspaceName = "ks"
Cell = "test"
SchemaSQL = `create table t1(
id1 bigint,
id2 bigint,
primary key(id1)
) Engine=InnoDB;
create table t1_id2_idx(
id2 bigint,
keyspace_id varbinary(10),
primary key(id2)
) Engine=InnoDB;
create table vstream_test(
id bigint,
val bigint,
primary key(id)
) Engine=InnoDB;
create table aggr_test(
id bigint,
val1 varchar(16),
val2 bigint,
primary key(id)
) Engine=InnoDB;
create table t2(
id3 bigint,
id4 bigint,
primary key(id3)
) Engine=InnoDB;
create table t2_id4_idx(
id bigint not null auto_increment,
id4 bigint,
id3 bigint,
primary key(id),
key idx_id4(id4)
) Engine=InnoDB;
`
VSchema = `
{
"sharded": true,
"vindexes": {
"hash": {
"type": "hash"
},
"t1_id2_vdx": {
"type": "consistent_lookup_unique",
"params": {
"table": "t1_id2_idx",
"from": "id2",
"to": "keyspace_id"
},
"owner": "t1"
},
"t2_id4_idx": {
"type": "lookup_hash",
"params": {
"table": "t2_id4_idx",
"from": "id4",
"to": "id3",
"autocommit": "true"
},
"owner": "t2"
}
},
"tables": {
"t1": {
"column_vindexes": [
{
"column": "id1",
"name": "hash"
},
{
"column": "id2",
"name": "t1_id2_vdx"
}
]
},
"t1_id2_idx": {
"column_vindexes": [
{
"column": "id2",
"name": "hash"
}
]
},
"t2": {
"column_vindexes": [
{
"column": "id3",
"name": "hash"
},
{
"column": "id4",
"name": "t2_id4_idx"
}
]
},
"t2_id4_idx": {
"column_vindexes": [
{
"column": "id4",
"name": "hash"
}
]
},
"vstream_test": {
"column_vindexes": [
{
"column": "id",
"name": "hash"
}
]
},
"aggr_test": {
"column_vindexes": [
{
"column": "id",
"name": "hash"
}
],
"columns": [
{
"name": "val1",
"type": "VARCHAR"
}
]
}
}
}`
)
func TestMain(m *testing.M) {
flag.Parse()
exitCode := func() int {
clusterInstance = cluster.NewCluster(Cell, "localhost")
defer clusterInstance.Teardown()
// Start topo server
err := clusterInstance.StartTopo()
if err != nil {
return 1
}
// Start keyspace
keyspace := &cluster.Keyspace{
Name: KeyspaceName,
SchemaSQL: SchemaSQL,
VSchema: VSchema,
}
err = clusterInstance.StartKeyspace(*keyspace, []string{"-80", "80-"}, 1, true)
if err != nil {
return 1
}
// Start vtgate
err = clusterInstance.StartVtgate()
if err != nil {
return 1
}
vtParams = mysql.ConnParams{
Host: clusterInstance.Hostname,
Port: clusterInstance.VtgateMySQLPort,
}
return m.Run()
}()
os.Exit(exitCode)
}