Skip to content

Commit

Permalink
*: add rawkv register test (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
overvenus authored and siddontang committed Jul 5, 2018
1 parent 61ba42b commit 150e501
Show file tree
Hide file tree
Showing 1,103 changed files with 697,513 additions and 3,691 deletions.
385 changes: 373 additions & 12 deletions Gopkg.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
name = "github.com/urfave/negroni"
version = "0.2.0"

[[constraint]]
name = "github.com/pingcap/tidb"
version = "2.1.0-beta"

[prune]
go-tests = true
unused-packages = true
Expand Down
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
default: build

all: build
all: build

build: chaos verifier

chaos:
chaos: rawkv tidb

tidb:
go build -o bin/chaos-tidb cmd/tidb/main.go

rawkv:
go build -o bin/chaos-rawkv cmd/rawkv/main.go

verifier:
go build -o bin/chaos-verifier cmd/verifier/main.go
48 changes: 48 additions & 0 deletions cmd/rawkv/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

import (
"flag"
"log"
"time"

"github.com/siddontang/chaos/cmd/util"
"github.com/siddontang/chaos/db/rawkv"
"github.com/siddontang/chaos/pkg/control"
"github.com/siddontang/chaos/pkg/core"
)

var (
requestCount = flag.Int("request-count", 500, "client test request count")
runTime = flag.Duration("run-time", 10*time.Minute, "client test run time")
clientCase = flag.String("case", "register", "client test case, like bank,multi_bank")
historyFile = flag.String("history", "./history.log", "history file")
nemesises = flag.String("nemesis", "", "nemesis, seperated by name, like random_kill,all_kill")
verifyNames = flag.String("verifiers", "", "verifier names, seperate by comma, rawkv_register")
)

func main() {
flag.Parse()

cfg := control.Config{
DB: "rawkv",
RequestCount: *requestCount,
RunTime: *runTime,
History: *historyFile,
}

var creator core.ClientCreator
switch *clientCase {
case "register":
creator = rawkv.RegisterClientCreator{}
default:
log.Fatalf("invalid client test case %s", *clientCase)
}

suit := util.Suit{
Config: cfg,
ClientCreator: creator,
VerifyNames: *verifyNames,
Nemesises: *nemesises,
}
suit.Run()
}
56 changes: 9 additions & 47 deletions cmd/tidb/main.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
package main

import (
"context"
"flag"
"log"
"os"
"os/signal"
"strings"
"syscall"
"time"

"github.com/siddontang/chaos/cmd/verifier/verify"
"github.com/siddontang/chaos/cmd/util"
"github.com/siddontang/chaos/db/tidb"
"github.com/siddontang/chaos/pkg/control"
"github.com/siddontang/chaos/pkg/core"
"github.com/siddontang/chaos/pkg/nemesis"
)

var (
Expand All @@ -29,18 +23,14 @@ var (
func main() {
flag.Parse()

cfg := &control.Config{
cfg := control.Config{
DB: "tidb",
RequestCount: *requestCount,
RunTime: *runTime,
History: *historyFile,
}

var (
creator core.ClientCreator
nemesisGens []core.NemesisGenerator
)

var creator core.ClientCreator
switch *clientCase {
case "bank":
creator = tidb.BankClientCreator{}
Expand All @@ -50,39 +40,11 @@ func main() {
log.Fatalf("invalid client test case %s", *clientCase)
}

for _, name := range strings.Split(*nemesises, ",") {
var g core.NemesisGenerator
name := strings.TrimSpace(name)
if len(name) == 0 {
continue
}

switch name {
case "random_kill", "all_kill", "minor_kill", "major_kill":
g = nemesis.NewKillGenerator("tidb", name)
case "random_drop", "all_drop", "minor_drop", "major_drop":
g = nemesis.NewDropGenerator(name)
default:
log.Fatalf("invalid nemesis generator")
}

nemesisGens = append(nemesisGens, g)
suit := util.Suit{
Config: cfg,
ClientCreator: creator,
VerifyNames: *verifyNames,
Nemesises: *nemesises,
}

c := control.NewController(cfg, creator, nemesisGens)

sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

ctx, cancel := context.WithCancel(context.Background())

go func() {
<-sigs
c.Close()
cancel()
}()

c.Run()

verify.Verify(ctx, *historyFile, *verifyNames)
suit.Run()
}
65 changes: 65 additions & 0 deletions cmd/util/suit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package util

import (
"context"
"log"
"os"
"os/signal"
"strings"
"syscall"

"github.com/siddontang/chaos/cmd/verifier/verify"
"github.com/siddontang/chaos/pkg/control"
"github.com/siddontang/chaos/pkg/core"
"github.com/siddontang/chaos/pkg/nemesis"
)

// Suit is a basic chaos testing suit with configurations to run chaos.
type Suit struct {
control.Config
core.ClientCreator
// verifier names, seperate by comma.
VerifyNames string
// nemesis, seperated by comma.
Nemesises string
}

// Run runs the suit.
func (suit *Suit) Run() {
var nemesisGens []core.NemesisGenerator
for _, name := range strings.Split(suit.Nemesises, ",") {
var g core.NemesisGenerator
name := strings.TrimSpace(name)
if len(name) == 0 {
continue
}

switch name {
case "random_kill", "all_kill", "minor_kill", "major_kill":
g = nemesis.NewKillGenerator(suit.Config.DB, name)
case "random_drop", "all_drop", "minor_drop", "major_drop":
g = nemesis.NewDropGenerator(name)
default:
log.Fatalf("invalid nemesis generator %s", name)
}

nemesisGens = append(nemesisGens, g)
}

c := control.NewController(&suit.Config, suit.ClientCreator, nemesisGens)

sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

ctx, cancel := context.WithCancel(context.Background())

go func() {
<-sigs
c.Close()
cancel()
}()

c.Run()

verify.Verify(ctx, suit.Config.History, suit.VerifyNames)
}
3 changes: 3 additions & 0 deletions cmd/verifier/verify/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"strings"

"github.com/siddontang/chaos/db/rawkv"
"github.com/siddontang/chaos/db/tidb"
"github.com/siddontang/chaos/pkg/history"
)
Expand All @@ -20,6 +21,8 @@ func Verify(ctx context.Context, historyFile string, verfier_names string) {
verifier = tidb.BankVerifier{}
case "tidb_bank_tso":
verifier = tidb.BankTsoVerifier{}
case "rawkv_register":
verifier = rawkv.RegisterVerifier{}
case "":
continue
default:
Expand Down
23 changes: 23 additions & 0 deletions db/rawkv/db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package rawkv

import (
"github.com/siddontang/chaos/db/cluster"
"github.com/siddontang/chaos/pkg/core"
)

// db is the TiDB database.
type db struct {
cluster.Cluster
}

// Name returns the unique name for the database
func (db *db) Name() string {
return "rawkv"
}

func init() {
core.RegisterDB(&db{
// RawKV does not use TiDB.
cluster.Cluster{IncludeTidb: false},
})
}
Loading

0 comments on commit 150e501

Please sign in to comment.