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.
Signed-off-by: Florent Poinsard <[email protected]>
- Loading branch information
Showing
5 changed files
with
511 additions
and
5 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,93 @@ | ||
/* | ||
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 toto | ||
|
||
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_misc" | ||
cell = "test_misc" | ||
|
||
//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 | ||
} | ||
|
||
clusterInstance.VtTabletExtraArgs = append(clusterInstance.VtTabletExtraArgs, | ||
"--queryserver-config-max-result-size", "1000000") | ||
|
||
// Start keyspace | ||
keyspace := &cluster.Keyspace{ | ||
Name: keyspaceName, | ||
SchemaSQL: schemaSQL, | ||
VSchema: vschema, | ||
} | ||
err = clusterInstance.StartKeyspace(*keyspace, []string{"-10", "11-24", "24-49", "49-6d", "6d-92", "92-b6", "b6-db", "db-df", "e0-e8", "e9-eb", "ec-ef", "f0-f4", "f5-f6", "ff-"}, 0, false) | ||
if err != nil { | ||
return 1 | ||
} | ||
|
||
// 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,128 @@ | ||
/* | ||
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 toto | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
_ "github.com/go-sql-driver/mysql" | ||
"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()) { | ||
mcmp, err := utils.NewMySQLCompare(t, vtParams, mysqlParams) | ||
require.NoError(t, err) | ||
|
||
deleteAll := func() { | ||
tables := []string{"foods"} | ||
for _, table := range tables { | ||
_, _ = mcmp.ExecAndIgnore("delete from " + table) | ||
} | ||
} | ||
|
||
deleteAll() | ||
|
||
return mcmp, func() { | ||
deleteAll() | ||
mcmp.Close() | ||
cluster.PanicHandler(t) | ||
} | ||
} | ||
|
||
const ( | ||
query2 = `select | ||
x2.id, | ||
x3.id | ||
from | ||
foods x2 | ||
left outer join foods x3 on (x2.original_food_id = x3.original_food_id) | ||
and (x3.version > x2.version) | ||
where x2.deleted = true | ||
and x3.id is null | ||
and (x2.updated_at = '2022-09-15T10:57:43Z' and x2.id >= -9223372036854775808 or x2.updated_at > '2022-09-15T10:57:43Z') | ||
and x2.is_public = false | ||
and x2.food_type in (0, 1, 2) | ||
order by | ||
x2.updated_at, | ||
x2.id | ||
limit | ||
1000; | ||
` | ||
|
||
|
||
|
||
|
||
query = `select | ||
x2.id, | ||
x2.user_id, | ||
x2.description, | ||
x2.food_type, | ||
x2.deleted, | ||
x2.created_at, | ||
x2.updated_at, | ||
x2.brand, | ||
x2.is_public, | ||
x2.country_id, | ||
x2.country_code, | ||
x2.brand_as_url, | ||
x2.version, | ||
x2.original_food_id, | ||
x2.brand_name_id, | ||
x2.edit_notes, | ||
x2.verified, | ||
x2.external_id, | ||
x2.external_version, | ||
x2.rank, | ||
x2.delta, | ||
x2.food_provider_id, | ||
x2.promoted_from_user_id, | ||
x2.promoted_from_food_id, | ||
x2.confidence_level | ||
from | ||
foods x2 | ||
left outer join foods x3 on (x2.original_food_id = x3.original_food_id) | ||
and (x3.version > x2.version) | ||
where x2.deleted = true | ||
and x3.id is null | ||
and (x2.updated_at = '2022-09-15T10:57:43Z' and x2.id >= -9223372036854775808 or x2.updated_at > '2022-09-15T10:57:43Z') | ||
and x2.is_public = false | ||
and x2.food_type in (0, 1, 2) | ||
order by | ||
x2.updated_at, | ||
x2.id | ||
limit | ||
1 | ||
` | ||
) | ||
|
||
func TestToto(t *testing.T) { | ||
mcmp, closer := start(t) | ||
defer closer() | ||
|
||
|
||
mcmp.Exec("insert into foods (original_food_id, updated_at, id, is_public, food_type, deleted, version) values (1, '2022-09-15 10:57:43', -1223372036854775808, false, 0, true, 1), (2, '2022-09-19 10:57:43', -2223372036854775808, false, 1, true, 2)") | ||
for i := 1; i < 10000; i++ { | ||
mcmp.Exec(fmt.Sprintf("insert into foods (original_food_id, updated_at, id, is_public, food_type, deleted, version) values (1, '2022-09-15 10:57:43', %d, false, 0, true, 1)", i)) | ||
} | ||
|
||
utils.Exec(t, mcmp.VtConn, "SET workload = olap") | ||
utils.Exec(t, mcmp.VtConn, query) | ||
} |
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 @@ | ||
CREATE TABLE `foods` (`id` bigint NOT NULL,`user_id` int,`description` varchar(255),`food_type` int DEFAULT '0',`rank` int DEFAULT '0',`deleted` tinyint(1) DEFAULT '0',`created_at` datetime,`updated_at` datetime,`brand` varchar(255),`is_public` tinyint(1) DEFAULT '0',`country_code` varchar(2) CHARACTER SET ascii COLLATE ascii_general_ci,`brand_as_url` varchar(255),`version` int DEFAULT '1',`original_food_id` bigint,`brand_name_id` int,`edit_notes` varchar(255),`delta` tinyint(1) DEFAULT '0',`food_provider_id` int,`country_id` int,`promoted_from_user_id` int,`promoted_from_food_id` bigint,`confidence_level` int DEFAULT '0',`verified` tinyint(1) DEFAULT '0',`external_id` varchar(100) CHARACTER SET ascii COLLATE ascii_general_ci,`external_version` varchar(100) CHARACTER SET ascii COLLATE ascii_general_ci,PRIMARY KEY (`id`),UNIQUE KEY `foods_food_id_food_version_idx` (`external_id`, `external_version`),KEY `foods_user_id_index` (`user_id`, `deleted`, `food_type`),KEY `index_foods_on_original_food_id_and_version` (`original_food_id`, `version`),KEY `index_foods_on_updated_at_and_deleted` (`updated_at`, `deleted`),KEY `user_id_and_id_index` (`user_id`, `id`),KEY `food_check_create_index` (`description`(191), `deleted`, `brand`(191), `user_id`)) ENGINE InnoDB, CHARSET utf8mb4, COLLATE utf8mb4_unicode_ci, ROW_FORMAT DYNAMIC; |
Oops, something went wrong.