vitess.io/vitess@v0.16.2/go/test/endtoend/mysqlserver/main_test.go (about) 1 /* 2 Copyright 2019 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package mysqlserver 18 19 import ( 20 "flag" 21 "fmt" 22 "os" 23 "strconv" 24 "testing" 25 26 "vitess.io/vitess/go/mysql" 27 "vitess.io/vitess/go/test/endtoend/cluster" 28 ) 29 30 var ( 31 clusterInstance *cluster.LocalProcessCluster 32 vtParams mysql.ConnParams 33 hostname = "localhost" 34 keyspaceName = "test_keyspace" 35 tableACLConfig = "/table_acl_config.json" 36 mysqlAuthServerStatic = "/mysql_auth_server_static.json" 37 cell = "zone1" 38 sqlSchema = `create table vt_insert_test ( 39 id bigint auto_increment, 40 msg varchar(64), 41 keyspace_id bigint(20) unsigned NOT NULL, 42 data longblob, 43 primary key (id) 44 ) Engine=InnoDB; 45 create table vt_partition_test ( 46 c1 int NOT NULL, 47 logdata BLOB NOT NULL, 48 created DATETIME NOT NULL, 49 PRIMARY KEY(c1, created) 50 ) 51 PARTITION BY HASH( TO_DAYS(created) ) 52 PARTITIONS 10; 53 ` 54 createProcSQL = `use vt_test_keyspace; 55 CREATE PROCEDURE testing() 56 BEGIN 57 delete from vt_insert_test; 58 delete from vt_partition_test; 59 END; 60 ` 61 ) 62 63 func TestMain(m *testing.M) { 64 defer cluster.PanicHandler(nil) 65 flag.Parse() 66 67 // setting grpc max size 68 if os.Getenv("grpc_max_massage_size") == "" { 69 os.Setenv("grpc_max_message_size", strconv.FormatInt(16*1024*1024, 10)) 70 } 71 72 exitcode, err := func() (int, error) { 73 clusterInstance = cluster.NewCluster(cell, hostname) 74 defer clusterInstance.Teardown() 75 76 // Start topo server 77 if err := clusterInstance.StartTopo(); err != nil { 78 return 1, err 79 } 80 81 // create acl config 82 ACLConfig := `{ 83 "table_groups": [ 84 { 85 "table_names_or_prefixes": ["vt_insert_test", "vt_partition_test", "dual"], 86 "readers": ["vtgate client 1"], 87 "writers": ["vtgate client 1"], 88 "admins": ["vtgate client 1"] 89 } 90 ] 91 }` 92 if err := createConfig(tableACLConfig, ACLConfig); err != nil { 93 return 1, err 94 } 95 96 // create auth server config 97 SQLConfig := `{ 98 "testuser1": { 99 "Password": "testpassword1", 100 "UserData": "vtgate client 1" 101 }, 102 "testuser2": { 103 "Password": "testpassword2", 104 "UserData": "vtgate client 2" 105 } 106 }` 107 if err := createConfig(mysqlAuthServerStatic, SQLConfig); err != nil { 108 return 1, err 109 } 110 111 clusterInstance.VtGateExtraArgs = []string{ 112 "--vschema_ddl_authorized_users=%", 113 "--mysql_server_query_timeout", "1s", 114 "--mysql_auth_server_impl", "static", 115 "--mysql_auth_server_static_file", clusterInstance.TmpDirectory + mysqlAuthServerStatic, 116 "--mysql_server_version", "8.0.16-7", 117 "--warn_sharded_only=true", 118 } 119 120 clusterInstance.VtTabletExtraArgs = []string{ 121 "--table-acl-config", clusterInstance.TmpDirectory + tableACLConfig, 122 "--queryserver-config-strict-table-acl", 123 } 124 125 // Start keyspace 126 keyspace := &cluster.Keyspace{ 127 Name: keyspaceName, 128 SchemaSQL: sqlSchema, 129 } 130 if err := clusterInstance.StartUnshardedKeyspace(*keyspace, 1, false); err != nil { 131 return 1, err 132 } 133 134 // Start vtgate 135 if err := clusterInstance.StartVtgate(); err != nil { 136 return 1, err 137 } 138 139 vtParams = mysql.ConnParams{ 140 Host: clusterInstance.Hostname, 141 Port: clusterInstance.VtgateMySQLPort, 142 Uname: "testuser1", 143 Pass: "testpassword1", 144 } 145 146 primaryTabletProcess := clusterInstance.Keyspaces[0].Shards[0].PrimaryTablet().VttabletProcess 147 if _, err := primaryTabletProcess.QueryTablet(createProcSQL, keyspaceName, false); err != nil { 148 return 1, err 149 } 150 151 return m.Run(), nil 152 }() 153 if err != nil { 154 fmt.Printf("%v\n", err) 155 os.Exit(1) 156 } else { 157 os.Exit(exitcode) 158 } 159 160 }