vitess.io/vitess@v0.16.2/go/test/endtoend/vtgate/queries/informationschema/main_test.go (about)

     1  /*
     2  Copyright 2021 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 informationschema
    18  
    19  import (
    20  	_ "embed"
    21  	"flag"
    22  	"fmt"
    23  	"os"
    24  	"testing"
    25  
    26  	"vitess.io/vitess/go/test/endtoend/utils"
    27  
    28  	"vitess.io/vitess/go/mysql"
    29  	"vitess.io/vitess/go/test/endtoend/cluster"
    30  )
    31  
    32  var (
    33  	clusterInstance *cluster.LocalProcessCluster
    34  	vtParams        mysql.ConnParams
    35  	mysqlParams     mysql.ConnParams
    36  	keyspaceName    = "ks"
    37  	cell            = "test"
    38  
    39  	//go:embed schema.sql
    40  	schemaSQL string
    41  
    42  	//go:embed vschema.json
    43  	vschema      string
    44  	routingRules = `
    45  {"rules": [
    46    {
    47      "from_table": "ks.t1000",
    48  	"to_tables": ["ks.t1"]
    49    }
    50  ]}
    51  `
    52  )
    53  
    54  func TestMain(m *testing.M) {
    55  	defer cluster.PanicHandler(nil)
    56  	flag.Parse()
    57  
    58  	exitCode := func() int {
    59  		clusterInstance = cluster.NewCluster(cell, "localhost")
    60  		defer clusterInstance.Teardown()
    61  
    62  		// Start topo server
    63  		err := clusterInstance.StartTopo()
    64  		if err != nil {
    65  			return 1
    66  		}
    67  
    68  		// Start keyspace
    69  		keyspace := &cluster.Keyspace{
    70  			Name:      keyspaceName,
    71  			SchemaSQL: schemaSQL,
    72  			VSchema:   vschema,
    73  		}
    74  		clusterInstance.VtGateExtraArgs = []string{"--schema_change_signal"}
    75  		clusterInstance.VtTabletExtraArgs = []string{"--queryserver-config-schema-change-signal", "--queryserver-config-schema-change-signal-interval", "0.1"}
    76  		err = clusterInstance.StartKeyspace(*keyspace, []string{"-80", "80-"}, 0, false)
    77  		if err != nil {
    78  			return 1
    79  		}
    80  
    81  		err = clusterInstance.VtctlclientProcess.ApplyRoutingRules(routingRules)
    82  		if err != nil {
    83  			return 1
    84  		}
    85  
    86  		err = clusterInstance.VtctlclientProcess.ExecuteCommand("RebuildVSchemaGraph")
    87  		if err != nil {
    88  			return 1
    89  		}
    90  
    91  		clusterInstance.VtGateExtraArgs = append(clusterInstance.VtGateExtraArgs, "--enable_system_settings=true")
    92  		// Start vtgate
    93  		err = clusterInstance.StartVtgate()
    94  		if err != nil {
    95  			return 1
    96  		}
    97  
    98  		vtParams = clusterInstance.GetVTParams(keyspaceName)
    99  
   100  		// create mysql instance and connection parameters
   101  		conn, closer, err := utils.NewMySQL(clusterInstance, keyspaceName, schemaSQL)
   102  		if err != nil {
   103  			fmt.Println(err)
   104  			return 1
   105  		}
   106  		defer closer()
   107  		mysqlParams = conn
   108  		return m.Run()
   109  	}()
   110  	os.Exit(exitCode)
   111  }