github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/workload/bank/bank_test.go (about) 1 // Copyright 2017 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package bank 12 13 import ( 14 "context" 15 "fmt" 16 "testing" 17 18 "github.com/cockroachdb/cockroach/pkg/base" 19 "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" 20 "github.com/cockroachdb/cockroach/pkg/testutils/sqlutils" 21 "github.com/cockroachdb/cockroach/pkg/util/leaktest" 22 "github.com/cockroachdb/cockroach/pkg/workload/workloadsql" 23 ) 24 25 func TestBank(t *testing.T) { 26 defer leaktest.AfterTest(t)() 27 28 tests := []struct { 29 rows int 30 ranges int 31 expectedRanges int 32 }{ 33 {10, 0, 1}, // we always have at least one range 34 {10, 1, 1}, 35 {10, 9, 9}, 36 {10, 10, 10}, 37 {10, 100, 10}, // don't make more ranges than rows 38 } 39 40 ctx := context.Background() 41 s, db, _ := serverutils.StartServer(t, base.TestServerArgs{UseDatabase: `test`}) 42 defer s.Stopper().Stop(ctx) 43 sqlutils.MakeSQLRunner(db).Exec(t, `CREATE DATABASE test`) 44 45 for _, test := range tests { 46 t.Run(fmt.Sprintf("rows=%d/ranges=%d", test.rows, test.ranges), func(t *testing.T) { 47 sqlDB := sqlutils.MakeSQLRunner(db) 48 sqlDB.Exec(t, `DROP TABLE IF EXISTS bank`) 49 50 bank := FromConfig(test.rows, test.rows, defaultPayloadBytes, test.ranges) 51 bankTable := bank.Tables()[0] 52 sqlDB.Exec(t, fmt.Sprintf(`CREATE TABLE %s %s`, bankTable.Name, bankTable.Schema)) 53 54 if err := workloadsql.Split(ctx, db, bankTable, 1 /* concurrency */); err != nil { 55 t.Fatalf("%+v", err) 56 } 57 58 var rangeCount int 59 sqlDB.QueryRow(t, 60 fmt.Sprintf(`SELECT count(*) FROM [SHOW RANGES FROM TABLE %s]`, bankTable.Name), 61 ).Scan(&rangeCount) 62 if rangeCount != test.expectedRanges { 63 t.Errorf("got %d ranges expected %d", rangeCount, test.expectedRanges) 64 } 65 }) 66 } 67 }