forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request vitessio#6069 from planetscale/set-plan-sysvar
Planning Set Statement for System Variable with Ignore and CheckAndIgnore
- Loading branch information
Showing
17 changed files
with
737 additions
and
173 deletions.
There are no files selected for viewing
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,101 @@ | ||
/* | ||
Copyright 2020 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 setstatement | ||
|
||
import ( | ||
"flag" | ||
"os" | ||
"testing" | ||
|
||
"vitess.io/vitess/go/mysql" | ||
"vitess.io/vitess/go/sqltypes" | ||
"vitess.io/vitess/go/test/endtoend/cluster" | ||
) | ||
|
||
var ( | ||
clusterInstance *cluster.LocalProcessCluster | ||
keyspaceName = "ks" | ||
cell = "zone1" | ||
hostname = "localhost" | ||
sqlSchema = ` | ||
create table test( | ||
id bigint, | ||
val1 varchar(16), | ||
val2 int, | ||
val3 float, | ||
primary key(id) | ||
)Engine=InnoDB;` | ||
|
||
vSchema = ` | ||
{ | ||
"sharded":true, | ||
"vindexes": { | ||
"hash_index": { | ||
"type": "hash" | ||
} | ||
}, | ||
"tables": { | ||
"test":{ | ||
"column_vindexes": [ | ||
{ | ||
"column": "id", | ||
"name": "hash_index" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
` | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
defer cluster.PanicHandler(nil) | ||
flag.Parse() | ||
|
||
exitCode := func() int { | ||
clusterInstance = cluster.NewCluster(cell, hostname) | ||
defer clusterInstance.Teardown() | ||
|
||
// Start topo server | ||
if err := clusterInstance.StartTopo(); err != nil { | ||
return 1 | ||
} | ||
|
||
// Start keyspace | ||
keyspace := &cluster.Keyspace{ | ||
Name: keyspaceName, | ||
SchemaSQL: sqlSchema, | ||
VSchema: vSchema, | ||
} | ||
if err := clusterInstance.StartKeyspace(*keyspace, []string{"-80", "80-"}, 1, false); err != nil { | ||
return 1 | ||
} | ||
|
||
// Start vtgate | ||
if err := clusterInstance.StartVtgate(); err != nil { | ||
return 1 | ||
} | ||
|
||
return m.Run() | ||
}() | ||
os.Exit(exitCode) | ||
} | ||
|
||
func exec(t *testing.T, conn *mysql.Conn, query string) (*sqltypes.Result, error) { | ||
t.Helper() | ||
return conn.ExecuteFetch(query, 1000, true) | ||
} |
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,89 @@ | ||
/* | ||
Copyright 2020 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 setstatement | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/stretchr/testify/require" | ||
|
||
"vitess.io/vitess/go/mysql" | ||
"vitess.io/vitess/go/test/endtoend/cluster" | ||
) | ||
|
||
func TestSetSysVar(t *testing.T) { | ||
defer cluster.PanicHandler(t) | ||
ctx := context.Background() | ||
vtParams := mysql.ConnParams{ | ||
Host: "localhost", | ||
Port: clusterInstance.VtgateMySQLPort, | ||
} | ||
type queriesWithExpectations struct { | ||
query string | ||
expectedRows string | ||
rowsAffected int | ||
errMsg string | ||
expectedWarning string | ||
} | ||
|
||
queries := []queriesWithExpectations{{ | ||
query: `set @@default_storage_engine = INNODB`, | ||
expectedRows: ``, rowsAffected: 0, | ||
expectedWarning: "[[VARCHAR(\"Warning\") UINT16(1235) VARCHAR(\"Ignored inapplicable SET default_storage_engine = INNODB\")]]", | ||
}, { | ||
query: `set @@sql_mode = @@sql_mode`, | ||
expectedRows: ``, rowsAffected: 0, | ||
}, { | ||
query: `set @@sql_mode = concat(@@sql_mode,"")`, | ||
expectedRows: ``, rowsAffected: 0, | ||
}, { | ||
query: `set @@sql_mode = concat(@@sql_mode,"ALLOW_INVALID_DATES")`, | ||
errMsg: "Modification not allowed using set construct for: sql_mode", | ||
}} | ||
|
||
conn, err := mysql.Connect(ctx, &vtParams) | ||
require.NoError(t, err) | ||
defer conn.Close() | ||
|
||
for i, q := range queries { | ||
t.Run(fmt.Sprintf("%d-%s", i, q.query), func(t *testing.T) { | ||
qr, err := exec(t, conn, q.query) | ||
if q.errMsg != "" { | ||
require.Contains(t, err.Error(), q.errMsg) | ||
} else { | ||
require.NoError(t, err) | ||
require.Equal(t, uint64(q.rowsAffected), qr.RowsAffected, "rows affected wrong for query: %s", q.query) | ||
if q.expectedRows != "" { | ||
result := fmt.Sprintf("%v", qr.Rows) | ||
if diff := cmp.Diff(q.expectedRows, result); diff != "" { | ||
t.Errorf("%s\nfor query: %s", diff, q.query) | ||
} | ||
} | ||
if q.expectedWarning != "" { | ||
qr, err := exec(t, conn, "show warnings") | ||
require.NoError(t, err) | ||
if got, want := fmt.Sprintf("%v", qr.Rows), q.expectedWarning; got != want { | ||
t.Errorf("select:\n%v want\n%v", got, want) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
} |
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
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
Oops, something went wrong.