forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix V3: only use the special NoRoute handling mode when needed (vites…
…sio#10422) Signed-off-by: Andres Taylor <andres@planetscale.com>
- Loading branch information
1 parent
926e9ad
commit 1232ac4
Showing
6 changed files
with
177 additions
and
3 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,113 @@ | ||
/* | ||
Copyright 2022 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 ( | ||
"context" | ||
_ "embed" | ||
"flag" | ||
"os" | ||
"testing" | ||
|
||
"vitess.io/vitess/go/test/endtoend/utils" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"vitess.io/vitess/go/mysql" | ||
"vitess.io/vitess/go/test/endtoend/cluster" | ||
) | ||
|
||
var ( | ||
clusterInstance *cluster.LocalProcessCluster | ||
vtParams mysql.ConnParams | ||
KeyspaceName = "ks" | ||
Cell = "test" | ||
//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, | ||
} | ||
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) | ||
} | ||
|
||
func start(t *testing.T) (*mysql.Conn, func()) { | ||
ctx := context.Background() | ||
conn, err := mysql.Connect(ctx, &vtParams) | ||
require.Nil(t, err) | ||
|
||
deleteAll := func() { | ||
_, _ = utils.ExecAllowError(t, conn, "set workload = oltp") | ||
|
||
tables := []string{"t1", "lookup_t1"} | ||
for _, table := range tables { | ||
_, _ = utils.ExecAllowError(t, conn, "delete from "+table) | ||
} | ||
} | ||
|
||
deleteAll() | ||
|
||
return conn, func() { | ||
deleteAll() | ||
conn.Close() | ||
cluster.PanicHandler(t) | ||
} | ||
} | ||
|
||
func TestInAgainstSecondaryVindex(t *testing.T) { | ||
conn, closer := start(t) | ||
defer closer() | ||
|
||
utils.AssertMatches(t, conn, `select 1 from t1 where c2 in ("abc")`, "[]") | ||
} |
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,11 @@ | ||
CREATE TABLE t1 ( | ||
c1 bigint unsigned NOT NULL, | ||
c2 varchar(16) NOT NULL, | ||
PRIMARY KEY (c1) | ||
) ENGINE InnoDB; | ||
|
||
CREATE TABLE lookup_t1 ( | ||
c2 varchar(16) NOT NULL, | ||
keyspace_id varbinary(16) NOT NULL, | ||
PRIMARY KEY (c2) | ||
) 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,39 @@ | ||
{ | ||
"sharded": true, | ||
"vindexes": { | ||
"lookup_idx": { | ||
"type": "lookup", | ||
"params": { | ||
"from": "c2", | ||
"to": "keyspace_id", | ||
"table": "lookup_t1" | ||
}, | ||
"owner": "t1" | ||
}, | ||
"xxhash": { | ||
"type": "xxhash" | ||
} | ||
}, | ||
"tables": { | ||
"t1": { | ||
"columnVindexes": [ | ||
{ | ||
"column": "c1", | ||
"name": "xxhash" | ||
}, | ||
{ | ||
"column": "c2", | ||
"name": "lookup_idx" | ||
} | ||
] | ||
}, | ||
"lookup_t1": { | ||
"columnVindexes": [ | ||
{ | ||
"column": "c2", | ||
"name": "xxhash" | ||
} | ||
] | ||
} | ||
} | ||
} |
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
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