Skip to content

Commit

Permalink
fix(generators): remove extra file
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Kropachev committed May 30, 2023
1 parent 321ee62 commit d690122
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 170 deletions.
170 changes: 0 additions & 170 deletions pkg/generators/schema_stmt_gen_test.go

This file was deleted.

148 changes: 148 additions & 0 deletions pkg/generators/suite_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ import (
"path"
"strings"
"testing"
"time"

"golang.org/x/exp/rand"

"github.com/scylladb/gemini/pkg/builders"
"github.com/scylladb/gemini/pkg/replication"
"github.com/scylladb/gemini/pkg/routingkey"
"github.com/scylladb/gemini/pkg/tableopts"
"github.com/scylladb/gemini/pkg/testschema"
"github.com/scylladb/gemini/pkg/utils"

"github.com/pkg/errors"

Expand Down Expand Up @@ -228,3 +238,141 @@ func (e *ExpectedList) loadExpectedFromFile(filePath string) error {
}
return nil
}

type nonRandSource uint64

func (s nonRandSource) Uint64() uint64 {
return uint64(s)
}

func (s nonRandSource) Seed(uint64) {
}

func getAllForTestStmt(t *testing.T, caseName string) (*testschema.Schema, *typedef.PartitionRangeConfig, *MockGenerator, *rand.Rand, bool, bool) {
utils.SetTestUUIDFromTime()
rnd := rand.New(nonRandSource(1))
table, useLWT, useMV := getTableAndOptionsFromName(t, caseName)

testSchema, testSchemaCfg, err := getTestSchema(table)
if err != nil {
t.Errorf("getTestSchema error:%v", err)
}

testPRC := &typedef.PartitionRangeConfig{
MaxBlobLength: testSchemaCfg.MaxBlobLength,
MinBlobLength: testSchemaCfg.MinBlobLength,
MaxStringLength: testSchemaCfg.MaxStringLength,
MinStringLength: testSchemaCfg.MinStringLength,
UseLWT: testSchemaCfg.UseLWT,
}

testGenerator := NewTestGenerator(testSchema.Tables[0], rnd, testPRC, &routingkey.RoutingKeyCreator{})

return testSchema, testPRC, testGenerator, rnd, useLWT, useMV
}

func getTestSchema(table *testschema.Table) (*testschema.Schema, *typedef.SchemaConfig, error) {
tableOpt := createTableOptions("compaction = {'class':'LeveledCompactionStrategy','enabled':true,'tombstone_threshold':0.2," +
"'tombstone_compaction_interval':86400,'sstable_size_in_mb':160}")
testSchemaConfig := typedef.SchemaConfig{
ReplicationStrategy: replication.NewSimpleStrategy(),
OracleReplicationStrategy: replication.NewSimpleStrategy(),
TableOptions: tableOpt,
MaxTables: 1,
MaxPartitionKeys: 40,
MinPartitionKeys: 1,
MaxClusteringKeys: 40,
MinClusteringKeys: 0,
MaxColumns: 40,
MinColumns: 0,
MaxUDTParts: 2,
MaxTupleParts: 2,
MaxBlobLength: 20,
MinBlobLength: 1,
MaxStringLength: 20,
MinStringLength: 1,
UseCounters: false,
UseLWT: false,
CQLFeature: 2,
AsyncObjectStabilizationAttempts: 10,
AsyncObjectStabilizationDelay: 10 * time.Millisecond,
}

testSchema := genTestSchema(testSchemaConfig, table)
return testSchema, &testSchemaConfig, nil
}

func createTableOptions(cql string) []tableopts.Option {
opt, _ := tableopts.FromCQL(cql)
opts := []string{opt.ToCQL()}
var tableOptions []tableopts.Option

for _, optionString := range opts {
o, err := tableopts.FromCQL(optionString)
if err != nil {
continue
}
tableOptions = append(tableOptions, o)
}
return tableOptions
}

func genTestSchema(sc typedef.SchemaConfig, table *testschema.Table) *testschema.Schema {
builder := builders.NewSchemaBuilder()
keyspace := typedef.Keyspace{
Name: "ks1",
Replication: sc.ReplicationStrategy,
OracleReplication: sc.OracleReplicationStrategy,
}
builder.Keyspace(keyspace)
builder.Table(table)
return builder.Build()
}

func getTableAndOptionsFromName(t *testing.T, tableName string) (*testschema.Table, bool, bool) {
nameParts := strings.Split(tableName, "_")
var table testschema.Table
var useLWT, useMV bool
for idx := range nameParts {
switch idx {
case 0:
table.PartitionKeys = genColumnsFromCase(t, partitionKeysCases, nameParts[0], "pk")
case 1:
table.ClusteringKeys = genColumnsFromCase(t, clusteringKeysCases, nameParts[1], "ck")
case 2:
table.Columns = genColumnsFromCase(t, columnsCases, nameParts[2], "col")
case 3:
opt, haveOpt := optionsCases[nameParts[3]]
if !haveOpt {
t.Fatalf("Error in getTableAndOptionsFromName OptCaseName:%s, not found", nameParts[3])
}
for i := range opt {
switch opt[i] {
case "lwt":
useLWT = true
case "mv":
useMV = true
}
}
}
}
table.Name = tableName

return &table, useLWT, useMV
}

func genColumnsFromCase(t *testing.T, typeCases map[string][]typedef.Type, caseName, prefix string) testschema.Columns {
typeCase, ok := typeCases[caseName]
if !ok {
t.Fatalf("Error caseName:%s, not found", caseName)
}
columns := make(testschema.Columns, 0, len(typeCase))
for idx := range typeCase {
columns = append(columns,
&testschema.ColumnDef{
Type: typeCase[idx],
Name: fmt.Sprintf("%s%d", prefix, idx),
})
}
return columns
}

0 comments on commit d690122

Please sign in to comment.