-
Notifications
You must be signed in to change notification settings - Fork 18
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 #333 from scylladb/dk/fix-gen_stmt-add_tests
feat(generators): add tests for genCheckStmt and GenDDLStmt functions
- Loading branch information
Showing
15 changed files
with
1,264 additions
and
181 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,194 @@ | ||
// Copyright 2019 ScyllaDB | ||
// | ||
// 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 generators | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/scylladb/gemini/pkg/utils" | ||
) | ||
|
||
var checkDataPath = "./test_expected_data/check/" | ||
|
||
// GenCheck functions tests | ||
func TestGenSinglePartitionQuery(t *testing.T) { | ||
utils.SetUnderTest() | ||
t.Parallel() | ||
expected := initExpected(t, checkDataPath, "single_partition.json", genSinglePartitionQueryCases, *updateExpected) | ||
if *updateExpected { | ||
defer expected.updateExpected(t) | ||
} | ||
for idx := range genSinglePartitionQueryCases { | ||
caseName := genSinglePartitionQueryCases[idx] | ||
t.Run(caseName, | ||
func(subT *testing.T) { | ||
schema, prc, gen, rnd, opts := getAllForTestStmt(subT, caseName) | ||
stmt := genSinglePartitionQuery(schema, schema.Tables[0], gen, rnd, prc, opts.mvNum) | ||
validateStmt(subT, stmt, nil) | ||
expected.CompareOrStore(subT, caseName, stmt) | ||
}) | ||
} | ||
} | ||
|
||
func TestGenMultiplePartitionQuery(t *testing.T) { | ||
utils.SetUnderTest() | ||
t.Parallel() | ||
expected := initExpected(t, checkDataPath, "multiple_partition.json", genMultiplePartitionQueryCases, *updateExpected) | ||
if *updateExpected { | ||
defer expected.updateExpected(t) | ||
} | ||
for idx := range genMultiplePartitionQueryCases { | ||
caseName := genMultiplePartitionQueryCases[idx] | ||
t.Run(caseName, | ||
func(subT *testing.T) { | ||
schema, prc, gen, rnd, opts := getAllForTestStmt(subT, caseName) | ||
stmt := genMultiplePartitionQuery(schema, schema.Tables[0], gen, rnd, prc, opts.mvNum, opts.pkCount) | ||
validateStmt(subT, stmt, nil) | ||
expected.CompareOrStore(subT, caseName, stmt) | ||
}) | ||
} | ||
} | ||
|
||
func TestGenClusteringRangeQuery(t *testing.T) { | ||
utils.SetUnderTest() | ||
t.Parallel() | ||
expected := initExpected(t, checkDataPath, "clustering_range.json", genClusteringRangeQueryCases, *updateExpected) | ||
if *updateExpected { | ||
defer expected.updateExpected(t) | ||
} | ||
for idx := range genClusteringRangeQueryCases { | ||
caseName := genClusteringRangeQueryCases[idx] | ||
t.Run(caseName, | ||
func(subT *testing.T) { | ||
schema, prc, gen, rnd, opts := getAllForTestStmt(subT, caseName) | ||
stmt := genClusteringRangeQuery(schema, schema.Tables[0], gen, rnd, prc, opts.mvNum, opts.ckCount) | ||
validateStmt(subT, stmt, nil) | ||
expected.CompareOrStore(subT, caseName, stmt) | ||
}) | ||
} | ||
} | ||
|
||
func TestGenMultiplePartitionClusteringRangeQuery(t *testing.T) { | ||
utils.SetUnderTest() | ||
t.Parallel() | ||
expected := initExpected(t, checkDataPath, "multiple_partition_clustering_range.json", genMultiplePartitionClusteringRangeQueryCases, *updateExpected) | ||
if *updateExpected { | ||
defer expected.updateExpected(t) | ||
} | ||
for idx := range genMultiplePartitionClusteringRangeQueryCases { | ||
caseName := genMultiplePartitionClusteringRangeQueryCases[idx] | ||
t.Run(caseName, | ||
func(subT *testing.T) { | ||
schema, prc, gen, rnd, opts := getAllForTestStmt(subT, caseName) | ||
stmt := genMultiplePartitionClusteringRangeQuery(schema, schema.Tables[0], gen, rnd, prc, opts.mvNum, opts.pkCount, opts.ckCount) | ||
validateStmt(subT, stmt, nil) | ||
expected.CompareOrStore(subT, caseName, stmt) | ||
}) | ||
} | ||
} | ||
|
||
func TestGenSingleIndexQuery(t *testing.T) { | ||
utils.SetUnderTest() | ||
t.Parallel() | ||
expected := initExpected(t, checkDataPath, "single_index.json", genSingleIndexQueryCases, *updateExpected) | ||
if *updateExpected { | ||
defer expected.updateExpected(t) | ||
} | ||
for idx := range genSingleIndexQueryCases { | ||
caseName := genSingleIndexQueryCases[idx] | ||
t.Run(caseName, | ||
func(subT *testing.T) { | ||
schema, prc, gen, rnd, opts := getAllForTestStmt(subT, caseName) | ||
stmt := genSingleIndexQuery(schema, schema.Tables[0], gen, rnd, prc, opts.idxCount) | ||
validateStmt(subT, stmt, nil) | ||
expected.CompareOrStore(subT, caseName, stmt) | ||
}) | ||
} | ||
} | ||
|
||
func BenchmarkGenSinglePartitionQuery(t *testing.B) { | ||
utils.SetUnderTest() | ||
for idx := range genSinglePartitionQueryCases { | ||
caseName := genSinglePartitionQueryCases[idx] | ||
t.Run(caseName, | ||
func(subT *testing.B) { | ||
schema, prc, gen, rnd, opts := getAllForTestStmt(subT, caseName) | ||
subT.ResetTimer() | ||
for x := 0; x < subT.N; x++ { | ||
_ = genSinglePartitionQuery(schema, schema.Tables[0], gen, rnd, prc, opts.mvNum) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func BenchmarkGenMultiplePartitionQuery(t *testing.B) { | ||
utils.SetUnderTest() | ||
for idx := range genMultiplePartitionQueryCases { | ||
caseName := genMultiplePartitionQueryCases[idx] | ||
t.Run(caseName, | ||
func(subT *testing.B) { | ||
schema, prc, gen, rnd, opts := getAllForTestStmt(subT, caseName) | ||
subT.ResetTimer() | ||
for x := 0; x < subT.N; x++ { | ||
_ = genMultiplePartitionQuery(schema, schema.Tables[0], gen, rnd, prc, opts.mvNum, opts.pkCount) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func BenchmarkGenClusteringRangeQuery(t *testing.B) { | ||
utils.SetUnderTest() | ||
for idx := range genClusteringRangeQueryCases { | ||
caseName := genClusteringRangeQueryCases[idx] | ||
t.Run(caseName, | ||
func(subT *testing.B) { | ||
schema, prc, gen, rnd, opts := getAllForTestStmt(subT, caseName) | ||
subT.ResetTimer() | ||
for x := 0; x < subT.N; x++ { | ||
_ = genClusteringRangeQuery(schema, schema.Tables[0], gen, rnd, prc, opts.mvNum, opts.ckCount) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func BenchmarkGenMultiplePartitionClusteringRangeQuery(t *testing.B) { | ||
utils.SetUnderTest() | ||
for idx := range genMultiplePartitionClusteringRangeQueryCases { | ||
caseName := genMultiplePartitionClusteringRangeQueryCases[idx] | ||
t.Run(caseName, | ||
func(subT *testing.B) { | ||
schema, prc, gen, rnd, opts := getAllForTestStmt(subT, caseName) | ||
subT.ResetTimer() | ||
for x := 0; x < subT.N; x++ { | ||
_ = genMultiplePartitionClusteringRangeQuery(schema, schema.Tables[0], gen, rnd, prc, opts.mvNum, opts.pkCount, opts.ckCount) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func BenchmarkGenSingleIndexQuery(t *testing.B) { | ||
utils.SetUnderTest() | ||
for idx := range genSingleIndexQueryCases { | ||
caseName := genSingleIndexQueryCases[idx] | ||
t.Run(caseName, | ||
func(subT *testing.B) { | ||
schema, prc, gen, rnd, opts := getAllForTestStmt(subT, caseName) | ||
subT.ResetTimer() | ||
for x := 0; x < subT.N; x++ { | ||
_ = genSingleIndexQuery(schema, schema.Tables[0], gen, rnd, prc, opts.idxCount) | ||
} | ||
}) | ||
} | ||
} |
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,114 @@ | ||
// Copyright 2019 ScyllaDB | ||
// | ||
// 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 generators | ||
|
||
import ( | ||
"strconv" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/scylladb/gemini/pkg/coltypes" | ||
"github.com/scylladb/gemini/pkg/utils" | ||
) | ||
|
||
var ddlDataPath = "./test_expected_data/ddl/" | ||
|
||
func TestGenDropColumnStmt(t *testing.T) { | ||
utils.SetUnderTest() | ||
t.Parallel() | ||
|
||
expected := initExpected(t, ddlDataPath, "drop_column.json", genDropColumnStmtCases, *updateExpected) | ||
if *updateExpected { | ||
defer expected.updateExpected(t) | ||
} | ||
for idx := range genDropColumnStmtCases { | ||
caseName := genDropColumnStmtCases[idx] | ||
t.Run(caseName, | ||
func(subT *testing.T) { | ||
schema, _, _, _, opts := getAllForTestStmt(subT, caseName) | ||
stmt, err := genDropColumnStmt(schema.Tables[0], schema.Keyspace.Name, opts.delNum) | ||
validateStmt(subT, stmt, err) | ||
expected.CompareOrStore(subT, caseName, stmt) | ||
}) | ||
} | ||
} | ||
|
||
func TestGenAddColumnStmt(t *testing.T) { | ||
utils.SetUnderTest() | ||
t.Parallel() | ||
checkOnAllTypesInAddColumnCases(t, genAddColumnStmtCases) | ||
expected := initExpected(t, ddlDataPath, "add_column.json", genAddColumnStmtCases, *updateExpected) | ||
if *updateExpected { | ||
defer expected.updateExpected(t) | ||
} | ||
for idx := range genAddColumnStmtCases { | ||
caseName := genAddColumnStmtCases[idx] | ||
t.Run(caseName, | ||
func(subT *testing.T) { | ||
schema, _, _, _, opts := getAllForTestStmt(subT, caseName) | ||
stmt, err := genAddColumnStmt(schema.Tables[0], schema.Keyspace.Name, &opts.addType) | ||
validateStmt(subT, stmt, err) | ||
expected.CompareOrStore(subT, caseName, stmt) | ||
}) | ||
} | ||
} | ||
|
||
func BenchmarkGenDropColumnStmt(t *testing.B) { | ||
utils.SetUnderTest() | ||
for idx := range genDropColumnStmtCases { | ||
caseName := genDropColumnStmtCases[idx] | ||
t.Run(caseName, | ||
func(subT *testing.B) { | ||
schema, _, _, _, opts := getAllForTestStmt(subT, caseName) | ||
subT.ResetTimer() | ||
for x := 0; x < subT.N; x++ { | ||
_, _ = genDropColumnStmt(schema.Tables[0], schema.Keyspace.Name, opts.delNum) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func BenchmarkGenAddColumnStmt(t *testing.B) { | ||
utils.SetUnderTest() | ||
for idx := range genAddColumnStmtCases { | ||
caseName := genAddColumnStmtCases[idx] | ||
t.Run(caseName, | ||
func(subT *testing.B) { | ||
schema, _, _, _, opts := getAllForTestStmt(subT, caseName) | ||
subT.ResetTimer() | ||
for x := 0; x < subT.N; x++ { | ||
_, _ = genAddColumnStmt(schema.Tables[0], schema.Keyspace.Name, &opts.addType) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func checkOnAllTypesInAddColumnCases(t *testing.T, cases []string) { | ||
founded := 0 | ||
for j := 0; j < len(coltypes.AllTypes); j++ { | ||
for i := range cases { | ||
caseName := cases[i] | ||
_, caseNum, _ := strings.Cut(caseName, ".") | ||
caseN, _ := strconv.ParseInt(caseNum, 0, 8) | ||
num := int(caseN) | ||
if num == j { | ||
founded++ | ||
} | ||
} | ||
} | ||
if founded != len(coltypes.AllTypes) || founded != len(cases) { | ||
t.Error("not all column types in genAddColumnStmtCases") | ||
} | ||
} |
Oops, something went wrong.