-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add end to end test for UNION collation handling
Signed-off-by: Andres Taylor <[email protected]>
- Loading branch information
Showing
5 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
go/test/endtoend/vtgate/queries/collations/collations_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
Copyright 2021 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 collations | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"vitess.io/vitess/go/test/endtoend/cluster" | ||
"vitess.io/vitess/go/test/endtoend/utils" | ||
) | ||
|
||
func start(t *testing.T) (utils.MySQLCompare, func()) { | ||
// ensure that the vschema and the tables have been created before running any tests | ||
_ = utils.WaitForAuthoritative(t, keyspaceName, "t1", clusterInstance.VtgateProcess.ReadVSchema) | ||
_ = utils.WaitForAuthoritative(t, keyspaceName, "t2", clusterInstance.VtgateProcess.ReadVSchema) | ||
|
||
mcmp, err := utils.NewMySQLCompare(t, vtParams, mysqlParams) | ||
require.NoError(t, err) | ||
|
||
deleteAll := func() { | ||
_, _ = utils.ExecAllowError(t, mcmp.VtConn, "set workload = oltp") | ||
|
||
tables := []string{"t1", "t2"} | ||
for _, table := range tables { | ||
_, _ = mcmp.ExecAndIgnore("delete from " + table) | ||
} | ||
} | ||
|
||
deleteAll() | ||
|
||
return mcmp, func() { | ||
deleteAll() | ||
mcmp.Close() | ||
cluster.PanicHandler(t) | ||
} | ||
} | ||
|
||
func TestCollationTyping(t *testing.T) { | ||
utils.SkipIfBinaryIsBelowVersion(t, 19, "vtgate") | ||
|
||
mcmp, closer := start(t) | ||
defer closer() | ||
mcmp.Exec("insert into t1(id, name) values(1,'ß'), (2,'s'), (3,'ss')") | ||
mcmp.Exec("insert into t2(id, name) values(1,'ß'), (2,'s'), (3,'ss')") | ||
|
||
res := utils.Exec(t, mcmp.VtConn, `vexplain plan SELECT name from t1 union select name from t2`) | ||
fmt.Printf("%v", res.Rows) | ||
mcmp.Exec(`SELECT name from t1 union select name from t2`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
Copyright 2021 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 collations | ||
|
||
import ( | ||
_ "embed" | ||
"flag" | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"vitess.io/vitess/go/test/endtoend/utils" | ||
|
||
"vitess.io/vitess/go/mysql" | ||
"vitess.io/vitess/go/test/endtoend/cluster" | ||
) | ||
|
||
var ( | ||
clusterInstance *cluster.LocalProcessCluster | ||
vtParams mysql.ConnParams | ||
mysqlParams mysql.ConnParams | ||
keyspaceName = "ks_aggr" | ||
cell = "test_aggr" | ||
|
||
//go:embed schema.sql | ||
schemaSQL string | ||
|
||
//go:embed vschema.json | ||
vschema string | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
defer cluster.PanicHandler(nil) | ||
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, | ||
} | ||
clusterInstance.VtGateExtraArgs = []string{"--schema_change_signal"} | ||
clusterInstance.VtTabletExtraArgs = []string{"--queryserver-config-schema-change-signal"} | ||
err = clusterInstance.StartKeyspace(*keyspace, []string{"-80", "80-"}, 0, false) | ||
if err != nil { | ||
return 1 | ||
} | ||
|
||
clusterInstance.VtGateExtraArgs = append(clusterInstance.VtGateExtraArgs, "--enable_system_settings=true") | ||
// Start vtgate | ||
err = clusterInstance.StartVtgate() | ||
if err != nil { | ||
return 1 | ||
} | ||
|
||
vtParams = clusterInstance.GetVTParams(keyspaceName) | ||
|
||
// create mysql instance and connection parameters | ||
conn, closer, err := utils.NewMySQL(clusterInstance, keyspaceName, schemaSQL) | ||
if err != nil { | ||
fmt.Println(err) | ||
return 1 | ||
} | ||
defer closer() | ||
mysqlParams = conn | ||
|
||
return m.Run() | ||
}() | ||
os.Exit(exitCode) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
create table t1 | ||
( | ||
id bigint, | ||
name varchar(255) collate utf8_general_mysql500_ci, | ||
primary key (id) | ||
) Engine = InnoDB; | ||
|
||
create table t2 | ||
( | ||
id bigint, | ||
name varchar(255) collate utf8_general_mysql500_ci, | ||
primary key (id) | ||
) ENGINE = InnoDB; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"sharded": true, | ||
"vindexes": { | ||
"hash": { | ||
"type": "hash" | ||
}, | ||
"unicode_loose_xxhash": { | ||
"type": "unicode_loose_xxhash" | ||
} | ||
}, | ||
"tables": { | ||
"t1": { | ||
"column_vindexes": [ | ||
{ | ||
"column": "id", | ||
"name": "hash" | ||
} | ||
] | ||
}, | ||
"t2": { | ||
"column_vindexes": [ | ||
{ | ||
"column": "id", | ||
"name": "hash" | ||
} | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters