diff --git a/build.sh b/build.sh index b04b285..4d4c7c2 100755 --- a/build.sh +++ b/build.sh @@ -51,6 +51,7 @@ done # copy scripts cp scripts/start.sh ${output}/ cp scripts/stop.sh ${output}/ +cp scripts/run_direct.py ${output}/ cp -r tools ${output}/ cp -r test ${output}/ diff --git a/scripts/run_direct.py b/scripts/run_direct.py new file mode 100644 index 0000000..468d66f --- /dev/null +++ b/scripts/run_direct.py @@ -0,0 +1,52 @@ +import os +import getopt +import sys + +def usage(): + print('|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|') + print('| Usage: ./run_direct.py --src=source_redis_address --srcPasswd=source_password --srcType=source_type(default is \'standalone\') --dst=target_redis_address --dstPasswd=target_redis_address --dstType=target_redis_address(default is \'standalone\') |') + print('|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|') + print('| Like : ./run_direct.py --src=10.1.1.1:3456 --srcPasswd=Test123456 --srcType=standalone --dst=20.1.1.2:15678 --dstPasswd=Test123456 --dstType=standalone |') + print('| Like : ./run_direct.py --src=10.1.1.1:3456;10.1.1.2:5678;10.1.1.3:7890 --srcPasswd=Test123456 --srcType=standalone --dst=20.1.1.1:13456;20.1.1.2:15678 --dstPasswd=Test123456 --dstType=proxy |') + print('|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|') + exit(0) + +if __name__ == "__main__": + opts, args = getopt.getopt(sys.argv[1:], "hs:a:t:d:p:e:", ["help", "src=", "srcPasswd=", "srcType=", "dst=", "dstPasswd=", "dstType="]) + if len(opts) == 0: + usage() + + mp = {} + for key, value in opts: + if key in ("-h", "--help"): + usage() + sys.exit() + + if key in ("-s", "--src"): + mp['source.address'] = value + if key in ("-a", "--srcPasswd"): + mp['source.password_raw'] = value + if key in ("-t", "--srcType"): + mp['source.type'] = value + if key in ("-d", "--dst"): + mp['target.address'] = value + if key in ("-p", "--dstPasswd"): + mp['target.password_raw'] = value + if key in ("-e", "--dstType"): + mp['target.type'] = value + + mp['id'] = 'redis-shake' + mp['source.type'] = 'standalone' if 'source.type' not in mp else mp['source.type'] + mp['target.type'] = 'standalone' if 'target.type' not in mp else mp['source.type'] + mp['source.auth_type'] = 'auth' + mp['target.auth_type'] = 'auth' + mp['rewrite'] = 'true' + + name = "run_direct.conf" + f = open(name, "w+") + for key, val in mp.items(): + f.writelines('%s = %s\n' % (key, val)) + f.close() + + os.system("./redis-shake.linux -type=sync -conf=%s" % name) + #os.system("./redis-shake.darwin -type=sync -conf=%s" % name) diff --git a/src/integration-test/deploy/deploy.go b/src/integration-test/deploy/deploy.go index 0577dcb..0420667 100644 --- a/src/integration-test/deploy/deploy.go +++ b/src/integration-test/deploy/deploy.go @@ -11,10 +11,13 @@ import ( const ( StandaloneScript = "deploy_standalone.sh" - ClusterScript = "deploy_cluster.sh" + ClusterScript = "deploy_cluster.sh" - RedisShake = "redis-shake" + RedisShake = "redis-shake" RedisShakeConf = "redis-shake.conf" + + CmdStart = "start" + CmdStop = "stop" ) func run(cmd *exec.Cmd) error { @@ -103,4 +106,4 @@ func StartShake(shakeDir, runDir string, conf map[string]interface{}, mode strin // start redis-shake execCmd := exec.Command(to, fmt.Sprintf("-type=%s", mode), fmt.Sprintf("-conf=%s", RedisShakeConf), "&") return run(execCmd) -} \ No newline at end of file +} diff --git a/src/integration-test/main/main.go b/src/integration-test/main/main.go index ee8a161..0092e6e 100644 --- a/src/integration-test/main/main.go +++ b/src/integration-test/main/main.go @@ -1,5 +1,40 @@ package main +import ( + "pkg/libs/log" + "flag" + + "integration-test/tcase" +) + func main() { + sourcePort := flag.Int("sourcePort", 20001, "source redis port") + targetPort := flag.Int("targetPort", 30001, "target redis port") + + log.SetLevel(log.LEVEL_INFO) + + log.Infof("run test starts") + + source, target := *sourcePort, *targetPort + for _, tc := range tcase.CaseList { + tc.SetInfo(source, target) + + if err := tc.Before(); err != nil { + log.Panicf("run case %v before stage failed: %v", tc.Info(), err) + } + + if err := tc.Run(); err != nil { + log.Panicf("run case %v run stage failed: %v", tc.Info(), err) + } + + if err := tc.Before(); err != nil { + log.Panicf("run case %v after stage failed: %v", tc.Info(), err) + } + + // +50 in different case + source += 50 + target += 50 + } + log.Infof("finish all test case") } \ No newline at end of file diff --git a/src/integration-test/tcase/base.go b/src/integration-test/tcase/base.go new file mode 100644 index 0000000..9689413 --- /dev/null +++ b/src/integration-test/tcase/base.go @@ -0,0 +1,13 @@ +package tcase + +var ( + CaseList = []Base{new(Standalone2StandaloneCase),} +) + +type Base interface { + SetInfo(sourcePort, targetPort int) // set + Info() string // name + Before() error // prepare + Run() error // run + After() error // finish +} diff --git a/src/integration-test/tcase/standalone2standalone.go b/src/integration-test/tcase/standalone2standalone.go new file mode 100644 index 0000000..ace1b00 --- /dev/null +++ b/src/integration-test/tcase/standalone2standalone.go @@ -0,0 +1,57 @@ +package tcase + +import ( + "integration-test/deploy" + "fmt" + shakeUtils "redis-shake/common" +) + +type Standalone2StandaloneCase struct { + SourcePort int + TargetPort int +} + +func (s2s *Standalone2StandaloneCase) SetInfo(sourcePort, targetPort int) { + s2s.SourcePort = sourcePort + s2s.TargetPort = targetPort +} + +func (s2s *Standalone2StandaloneCase) Info() string { + return fmt.Sprintf("standalone->standalone") +} + +func (s2s *Standalone2StandaloneCase) Before() error { + // deploy source redis with given port + if err := deploy.Deploy(deploy.StandaloneScript, s2s.SourcePort, deploy.CmdStart, -1); err != nil { + return fmt.Errorf("deploy source redis failed: %v", err) + } + + // deploy target redis with given port + if err := deploy.Deploy(deploy.StandaloneScript, s2s.TargetPort, deploy.CmdStart, -1); err != nil { + return fmt.Errorf("deploy source redis failed: %v", err) + } + + return nil +} + +func (s2s *Standalone2StandaloneCase) Run() error { + // build client + sourceConn := shakeUtils.OpenRedisConn([]string{fmt.Sprintf(":%d", s2s.SourcePort)}, "auth", "", false, false) + targeteConn := shakeUtils.OpenRedisConn([]string{fmt.Sprintf(":%d", s2s.TargetPort)}, "auth", "", false, false) + + +} + +func (s2s *Standalone2StandaloneCase) After() error { + // close source redis + if err := deploy.Deploy(deploy.StandaloneScript, s2s.SourcePort, deploy.CmdStop, -1); err != nil { + return fmt.Errorf("close source redis failed: %v", err) + } + + // close target redis + if err := deploy.Deploy(deploy.StandaloneScript, s2s.TargetPort, deploy.CmdStop, -1); err != nil { + return fmt.Errorf("close source redis failed: %v", err) + } + + return nil +} \ No newline at end of file