From aa435a343edcebb72c360f6def3a321df81d479b Mon Sep 17 00:00:00 2001 From: yedf2 <120050102@qq.com> Date: Fri, 3 Dec 2021 10:29:58 +0800 Subject: [PATCH] test passed --- bench/http.go | 2 +- common/types.go | 6 ++++++ conf.sample.yml | 1 - dtmsvr/dtmsvr.go | 14 +++++--------- examples/base_types.go | 6 +++--- examples/http_gorm_xa.go | 2 +- examples/http_msg.go | 2 +- examples/http_saga.go | 6 +++--- examples/http_saga_barrier.go | 2 +- examples/http_saga_gorm_barrier.go | 2 +- examples/http_tcc.go | 8 ++++---- examples/http_tcc_barrier.go | 4 ++-- examples/http_xa.go | 4 ++-- examples/quick_start.go | 2 +- go.sum | 4 ++++ test/api_test.go | 12 ++++++------ test/dtmsvr_test.go | 2 +- test/msg_test.go | 2 +- test/saga_compatible_test.go | 2 +- test/saga_test.go | 4 ++-- test/tcc_test.go | 8 ++++---- 21 files changed, 50 insertions(+), 45 deletions(-) diff --git a/bench/http.go b/bench/http.go index e1cb91f..a60cf02 100644 --- a/bench/http.go +++ b/bench/http.go @@ -152,7 +152,7 @@ func benchAddRoute(app *gin.Engine) { params2 := fmt.Sprintf("?uid=%s", suid2) dtmimp.Logf("mode: %s contains dtm: %t", mode, strings.Contains(mode, "dtm")) if strings.Contains(mode, "dtm") { - saga := dtmcli.NewSaga(examples.DtmServer, fmt.Sprintf("bench-%d", uid)). + saga := dtmcli.NewSaga(examples.DtmHttpServer, fmt.Sprintf("bench-%d", uid)). Add(benchBusi+"/TransOut"+params, benchBusi+"/TransOutCompensate"+params, req). Add(benchBusi+"/TransIn"+params2, benchBusi+"/TransInCompensate"+params2, req) saga.WaitResult = true diff --git a/common/types.go b/common/types.go index 1606523..c68f8ba 100644 --- a/common/types.go +++ b/common/types.go @@ -17,6 +17,12 @@ import ( "github.com/yedf/dtm/dtmcli/dtmimp" ) +const ( + DtmHttpPort = 36789 + DtmGrpcPort = 36790 + DtmMetricsPort = 8889 +) + // MicroService config type for micro service type MicroService struct { Driver string `yaml:"Driver"` diff --git a/conf.sample.yml b/conf.sample.yml index 78f174d..f306ef2 100644 --- a/conf.sample.yml +++ b/conf.sample.yml @@ -18,7 +18,6 @@ DB: # Driver: 'dtm-driver-gozero' # name of the driver to handle register/discover # URL: 'etcd://localhost:2379/dtmservice' # register dtm server to this url # EndPoint: 'localhost:36790' - # the unit of following configurations is second # TransCronInterval: 3 # the interval to poll unfinished global transaction for every dtm process diff --git a/dtmsvr/dtmsvr.go b/dtmsvr/dtmsvr.go index 3a00ed6..f744dce 100644 --- a/dtmsvr/dtmsvr.go +++ b/dtmsvr/dtmsvr.go @@ -25,20 +25,16 @@ import ( "github.com/yedf/dtm/examples" ) -var dtmsvrPort = 36789 -var dtmsvrGrpcPort = 36790 -var metricsPort = 8889 - // StartSvr StartSvr func StartSvr() { dtmimp.Logf("start dtmsvr") app := common.GetGinApp() app = httpMetrics(app) addRoute(app) - dtmimp.Logf("dtmsvr listen at: %d", dtmsvrPort) - go app.Run(fmt.Sprintf(":%d", dtmsvrPort)) + dtmimp.Logf("dtmsvr listen at: %d", common.DtmHttpPort) + go app.Run(fmt.Sprintf(":%d", common.DtmHttpPort)) - lis, err := net.Listen("tcp", fmt.Sprintf(":%d", dtmsvrGrpcPort)) + lis, err := net.Listen("tcp", fmt.Sprintf(":%d", common.DtmGrpcPort)) dtmimp.FatalIfError(err) s := grpc.NewServer( grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer( @@ -53,8 +49,8 @@ func StartSvr() { go updateBranchAsync() // prometheus exporter - dtmimp.Logf("prometheus exporter listen at: %d", metricsPort) - prometheusHTTPRun(fmt.Sprintf("%d", metricsPort)) + dtmimp.Logf("prometheus exporter listen at: %d", common.DtmMetricsPort) + prometheusHTTPRun(fmt.Sprintf("%d", common.DtmMetricsPort)) time.Sleep(100 * time.Millisecond) err = dtmdriver.Use(config.MicroService.Driver) dtmimp.FatalIfError(err) diff --git a/examples/base_types.go b/examples/base_types.go index ee9514a..400be7f 100644 --- a/examples/base_types.go +++ b/examples/base_types.go @@ -18,11 +18,11 @@ import ( "github.com/yedf/dtm/dtmgrpc" ) -// DtmServer dtm service address -const DtmServer = "http://localhost:8080/api/dtmsvr" +// DtmHttpServer dtm service address +var DtmHttpServer = fmt.Sprintf("http://localhost:%d/api/dtmsvr", common.DtmHttpPort) // DtmGrpcServer dtm grpc service address -const DtmGrpcServer = "localhost:58080" +var DtmGrpcServer = fmt.Sprintf("localhost:%d", common.DtmGrpcPort) // TransReq transaction request payload type TransReq struct { diff --git a/examples/http_gorm_xa.go b/examples/http_gorm_xa.go index fbe6298..6034469 100644 --- a/examples/http_gorm_xa.go +++ b/examples/http_gorm_xa.go @@ -14,7 +14,7 @@ import ( func init() { addSample("xa_gorm", func() string { - gid := dtmcli.MustGenGid(DtmServer) + gid := dtmcli.MustGenGid(DtmHttpServer) err := XaClient.XaGlobalTransaction(gid, func(xa *dtmcli.Xa) (*resty.Response, error) { resp, err := xa.CallBranch(&TransReq{Amount: 30}, Busi+"/TransOutXaGorm") if err != nil { diff --git a/examples/http_msg.go b/examples/http_msg.go index 589bf72..be0e9ac 100644 --- a/examples/http_msg.go +++ b/examples/http_msg.go @@ -15,7 +15,7 @@ func init() { addSample("msg", func() string { dtmimp.Logf("a busi transaction begin") req := &TransReq{Amount: 30} - msg := dtmcli.NewMsg(DtmServer, dtmcli.MustGenGid(DtmServer)). + msg := dtmcli.NewMsg(DtmHttpServer, dtmcli.MustGenGid(DtmHttpServer)). Add(Busi+"/TransOut", req). Add(Busi+"/TransIn", req) err := msg.Prepare(Busi + "/query") diff --git a/examples/http_saga.go b/examples/http_saga.go index 64071cb..54e2885 100644 --- a/examples/http_saga.go +++ b/examples/http_saga.go @@ -15,7 +15,7 @@ func init() { addSample("saga", func() string { dtmimp.Logf("a saga busi transaction begin") req := &TransReq{Amount: 30} - saga := dtmcli.NewSaga(DtmServer, dtmcli.MustGenGid(DtmServer)). + saga := dtmcli.NewSaga(DtmHttpServer, dtmcli.MustGenGid(DtmHttpServer)). Add(Busi+"/TransOut", Busi+"/TransOutRevert", req). Add(Busi+"/TransIn", Busi+"/TransInRevert", req) dtmimp.Logf("saga busi trans submit") @@ -27,7 +27,7 @@ func init() { addSample("saga_wait", func() string { dtmimp.Logf("a saga busi transaction begin") req := &TransReq{Amount: 30} - saga := dtmcli.NewSaga(DtmServer, dtmcli.MustGenGid(DtmServer)). + saga := dtmcli.NewSaga(DtmHttpServer, dtmcli.MustGenGid(DtmHttpServer)). Add(Busi+"/TransOut", Busi+"/TransOutRevert", req). Add(Busi+"/TransIn", Busi+"/TransInRevert", req) saga.SetOptions(&dtmcli.TransOptions{WaitResult: true}) @@ -39,7 +39,7 @@ func init() { addSample("concurrent_saga", func() string { dtmimp.Logf("a concurrent saga busi transaction begin") req := &TransReq{Amount: 30} - csaga := dtmcli.NewSaga(DtmServer, dtmcli.MustGenGid(DtmServer)). + csaga := dtmcli.NewSaga(DtmHttpServer, dtmcli.MustGenGid(DtmHttpServer)). Add(Busi+"/TransOut", Busi+"/TransOutRevert", req). Add(Busi+"/TransOut", Busi+"/TransOutRevert", req). Add(Busi+"/TransIn", Busi+"/TransInRevert", req). diff --git a/examples/http_saga_barrier.go b/examples/http_saga_barrier.go index 578cfba..7c9e916 100644 --- a/examples/http_saga_barrier.go +++ b/examples/http_saga_barrier.go @@ -23,7 +23,7 @@ func init() { addSample("saga_barrier", func() string { dtmimp.Logf("a busi transaction begin") req := &TransReq{Amount: 30} - saga := dtmcli.NewSaga(DtmServer, dtmcli.MustGenGid(DtmServer)). + saga := dtmcli.NewSaga(DtmHttpServer, dtmcli.MustGenGid(DtmHttpServer)). Add(Busi+"/SagaBTransOut", Busi+"/SagaBTransOutCompensate", req). Add(Busi+"/SagaBTransIn", Busi+"/SagaBTransInCompensate", req) dtmimp.Logf("busi trans submit") diff --git a/examples/http_saga_gorm_barrier.go b/examples/http_saga_gorm_barrier.go index 22268c9..8652a74 100644 --- a/examples/http_saga_gorm_barrier.go +++ b/examples/http_saga_gorm_barrier.go @@ -22,7 +22,7 @@ func init() { addSample("saga_gorm_barrier", func() string { dtmimp.Logf("a busi transaction begin") req := &TransReq{Amount: 30} - saga := dtmcli.NewSaga(DtmServer, dtmcli.MustGenGid(DtmServer)). + saga := dtmcli.NewSaga(DtmHttpServer, dtmcli.MustGenGid(DtmHttpServer)). Add(Busi+"/SagaBTransOutGorm", Busi+"/SagaBTransOutCompensate", req). Add(Busi+"/SagaBTransIn", Busi+"/SagaBTransInCompensate", req) dtmimp.Logf("busi trans submit") diff --git a/examples/http_tcc.go b/examples/http_tcc.go index e9d23cb..49c949f 100644 --- a/examples/http_tcc.go +++ b/examples/http_tcc.go @@ -24,8 +24,8 @@ func init() { })) } addSample("tcc_nested", func() string { - gid := dtmcli.MustGenGid(DtmServer) - err := dtmcli.TccGlobalTransaction(DtmServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) { + gid := dtmcli.MustGenGid(DtmHttpServer) + err := dtmcli.TccGlobalTransaction(DtmHttpServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) { resp, err := tcc.CallBranch(&TransReq{Amount: 30}, Busi+"/TransOut", Busi+"/TransOutConfirm", Busi+"/TransOutRevert") if err != nil { return resp, err @@ -37,8 +37,8 @@ func init() { }) addSample("tcc", func() string { dtmimp.Logf("tcc simple transaction begin") - gid := dtmcli.MustGenGid(DtmServer) - err := dtmcli.TccGlobalTransaction(DtmServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) { + gid := dtmcli.MustGenGid(DtmHttpServer) + err := dtmcli.TccGlobalTransaction(DtmHttpServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) { resp, err := tcc.CallBranch(&TransReq{Amount: 30}, Busi+"/TransOut", Busi+"/TransOutConfirm", Busi+"/TransOutRevert") if err != nil { return resp, err diff --git a/examples/http_tcc_barrier.go b/examples/http_tcc_barrier.go index dff36a1..089a4f6 100644 --- a/examples/http_tcc_barrier.go +++ b/examples/http_tcc_barrier.go @@ -27,8 +27,8 @@ func init() { } addSample("tcc_barrier", func() string { dtmimp.Logf("tcc transaction begin") - gid := dtmcli.MustGenGid(DtmServer) - err := dtmcli.TccGlobalTransaction(DtmServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) { + gid := dtmcli.MustGenGid(DtmHttpServer) + err := dtmcli.TccGlobalTransaction(DtmHttpServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) { resp, err := tcc.CallBranch(&TransReq{Amount: 30}, Busi+"/TccBTransOutTry", Busi+"/TccBTransOutConfirm", Busi+"/TccBTransOutCancel") if err != nil { diff --git a/examples/http_xa.go b/examples/http_xa.go index 9ae4e8e..b4d0ca3 100644 --- a/examples/http_xa.go +++ b/examples/http_xa.go @@ -20,7 +20,7 @@ var XaClient *dtmcli.XaClient = nil func init() { setupFuncs["XaSetup"] = func(app *gin.Engine) { var err error - XaClient, err = dtmcli.NewXaClient(DtmServer, config.DB, Busi+"/xa", func(path string, xa *dtmcli.XaClient) { + XaClient, err = dtmcli.NewXaClient(DtmHttpServer, config.DB, Busi+"/xa", func(path string, xa *dtmcli.XaClient) { app.POST(path, common.WrapHandler(func(c *gin.Context) (interface{}, error) { return xa.HandleCallback(c.Query("gid"), c.Query("branch_id"), c.Query("op")) })) @@ -28,7 +28,7 @@ func init() { dtmimp.FatalIfError(err) } addSample("xa", func() string { - gid := dtmcli.MustGenGid(DtmServer) + gid := dtmcli.MustGenGid(DtmHttpServer) err := XaClient.XaGlobalTransaction(gid, func(xa *dtmcli.Xa) (*resty.Response, error) { resp, err := xa.CallBranch(&TransReq{Amount: 30}, Busi+"/TransOutXa") if err != nil { diff --git a/examples/quick_start.go b/examples/quick_start.go index fbf0c88..e71d816 100644 --- a/examples/quick_start.go +++ b/examples/quick_start.go @@ -37,7 +37,7 @@ func QsStartSvr() { func QsFireRequest() string { req := &gin.H{"amount": 30} // 微服务的载荷 // DtmServer为DTM服务的地址 - saga := dtmcli.NewSaga(DtmServer, dtmcli.MustGenGid(DtmServer)). + saga := dtmcli.NewSaga(DtmHttpServer, dtmcli.MustGenGid(DtmHttpServer)). // 添加一个TransOut的子事务,正向操作为url: qsBusi+"/TransOut", 逆向操作为url: qsBusi+"/TransOutCompensate" Add(qsBusi+"/TransOut", qsBusi+"/TransOutCompensate", req). // 添加一个TransIn的子事务,正向操作为url: qsBusi+"/TransOut", 逆向操作为url: qsBusi+"/TransInCompensate" diff --git a/go.sum b/go.sum index e4742e3..5536c05 100644 --- a/go.sum +++ b/go.sum @@ -145,6 +145,7 @@ github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL9 github.com/go-openapi/spec v0.19.3/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo= github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= @@ -391,6 +392,7 @@ github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= @@ -445,6 +447,7 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/tal-tech/go-zero v1.2.4 h1:S0Cj69rHfIbZBVgQHnblR2dGkhz5Ij3bm1lM19kkig4= github.com/tal-tech/go-zero v1.2.4/go.mod h1:EHOQsRClBD4svg5mJl8iqkQn5bTMZx+AeHwkQpSjJXg= @@ -817,6 +820,7 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gorm.io/driver/mysql v1.0.3 h1:+JKBYPfn1tygR1/of/Fh2T8iwuVwzt+PEJmKaXzMQXg= gorm.io/driver/mysql v1.0.3/go.mod h1:twGxftLBlFgNVNakL7F+P/x9oYqoymG3YYT8cAfI9oI= diff --git a/test/api_test.go b/test/api_test.go index 5fdf063..eefe35a 100644 --- a/test/api_test.go +++ b/test/api_test.go @@ -20,7 +20,7 @@ func TestAPIQuery(t *testing.T) { err := genMsg(gidTestAPI).Submit() assert.Nil(t, err) waitTransProcessed(gidTestAPI) - resp, err := dtmimp.RestyClient.R().SetQueryParam("gid", gidTestAPI).Get(examples.DtmServer + "/query") + resp, err := dtmimp.RestyClient.R().SetQueryParam("gid", gidTestAPI).Get(examples.DtmHttpServer + "/query") e2p(err) m := map[string]interface{}{} assert.Equal(t, resp.StatusCode(), 200) @@ -28,11 +28,11 @@ func TestAPIQuery(t *testing.T) { assert.NotEqual(t, nil, m["transaction"]) assert.Equal(t, 2, len(m["branches"].([]interface{}))) - resp, err = dtmimp.RestyClient.R().SetQueryParam("gid", "").Get(examples.DtmServer + "/query") + resp, err = dtmimp.RestyClient.R().SetQueryParam("gid", "").Get(examples.DtmHttpServer + "/query") e2p(err) assert.Equal(t, resp.StatusCode(), 500) - resp, err = dtmimp.RestyClient.R().SetQueryParam("gid", "1").Get(examples.DtmServer + "/query") + resp, err = dtmimp.RestyClient.R().SetQueryParam("gid", "1").Get(examples.DtmHttpServer + "/query") e2p(err) assert.Equal(t, resp.StatusCode(), 200) dtmimp.MustUnmarshalString(resp.String(), &m) @@ -41,10 +41,10 @@ func TestAPIQuery(t *testing.T) { } func TestAPIAll(t *testing.T) { - _, err := dtmimp.RestyClient.R().Get(examples.DtmServer + "/all") + _, err := dtmimp.RestyClient.R().Get(examples.DtmHttpServer + "/all") assert.Nil(t, err) - _, err = dtmimp.RestyClient.R().SetQueryParam("last_id", "10").Get(examples.DtmServer + "/all") + _, err = dtmimp.RestyClient.R().SetQueryParam("last_id", "10").Get(examples.DtmHttpServer + "/all") assert.Nil(t, err) - resp, err := dtmimp.RestyClient.R().SetQueryParam("last_id", "abc").Get(examples.DtmServer + "/all") + resp, err := dtmimp.RestyClient.R().SetQueryParam("last_id", "abc").Get(examples.DtmHttpServer + "/all") assert.Equal(t, resp.StatusCode(), 500) } diff --git a/test/dtmsvr_test.go b/test/dtmsvr_test.go index 6bc9e80..05930c1 100644 --- a/test/dtmsvr_test.go +++ b/test/dtmsvr_test.go @@ -19,7 +19,7 @@ import ( "github.com/yedf/dtm/examples" ) -var DtmServer = examples.DtmServer +var DtmServer = examples.DtmHttpServer var Busi = examples.Busi var app *gin.Engine diff --git a/test/msg_test.go b/test/msg_test.go index 493839f..40979c8 100644 --- a/test/msg_test.go +++ b/test/msg_test.go @@ -68,7 +68,7 @@ func TestMsgAbnormal(t *testing.T) { func genMsg(gid string) *dtmcli.Msg { req := examples.GenTransReq(30, false, false) - msg := dtmcli.NewMsg(examples.DtmServer, gid). + msg := dtmcli.NewMsg(examples.DtmHttpServer, gid). Add(examples.Busi+"/TransOut", &req). Add(examples.Busi+"/TransIn", &req) msg.QueryPrepared = examples.Busi + "/CanSubmit" diff --git a/test/saga_compatible_test.go b/test/saga_compatible_test.go index 925ab90..c7e29f9 100644 --- a/test/saga_compatible_test.go +++ b/test/saga_compatible_test.go @@ -19,7 +19,7 @@ func TestSagaCompatibleNormal(t *testing.T) { // compatible with old http, which gid := dtmimp.GetFuncName() body := fmt.Sprintf(`{"gid":"%s","trans_type":"saga","steps":[{"action":"%s/TransOut","compensate":"%s/TransOutRevert","data":"{\"amount\":30,\"transInResult\":\"SUCCESS\",\"transOutResult\":\"SUCCESS\"}"},{"action":"%s/TransIn","compensate":"%s/TransInRevert","data":"{\"amount\":30,\"transInResult\":\"SUCCESS\",\"transOutResult\":\"SUCCESS\"}"}]}`, gid, examples.Busi, examples.Busi, examples.Busi, examples.Busi) - dtmimp.RestyClient.R().SetBody(body).Post(fmt.Sprintf("%s/submit", examples.DtmServer)) + dtmimp.RestyClient.R().SetBody(body).Post(fmt.Sprintf("%s/submit", examples.DtmHttpServer)) waitTransProcessed(gid) assert.Equal(t, []string{StatusPrepared, StatusSucceed, StatusPrepared, StatusSucceed}, getBranchesStatus(gid)) assert.Equal(t, StatusSucceed, getTransStatus(gid)) diff --git a/test/saga_test.go b/test/saga_test.go index 0e459ed..0e42b05 100644 --- a/test/saga_test.go +++ b/test/saga_test.go @@ -59,7 +59,7 @@ func TestSagaAbnormal(t *testing.T) { } func genSaga(gid string, outFailed bool, inFailed bool) *dtmcli.Saga { - saga := dtmcli.NewSaga(examples.DtmServer, gid) + saga := dtmcli.NewSaga(examples.DtmHttpServer, gid) req := examples.GenTransReq(30, outFailed, inFailed) saga.Add(examples.Busi+"/TransOut", examples.Busi+"/TransOutRevert", &req) saga.Add(examples.Busi+"/TransIn", examples.Busi+"/TransInRevert", &req) @@ -67,7 +67,7 @@ func genSaga(gid string, outFailed bool, inFailed bool) *dtmcli.Saga { } func genSaga1(gid string, outFailed bool, inFailed bool) *dtmcli.Saga { - saga := dtmcli.NewSaga(examples.DtmServer, gid) + saga := dtmcli.NewSaga(examples.DtmHttpServer, gid) req := examples.GenTransReq(30, outFailed, inFailed) saga.Add(examples.Busi+"/TransOut", examples.Busi+"/TransOutRevert", &req) return saga diff --git a/test/tcc_test.go b/test/tcc_test.go index 76d0bc8..0697f4e 100644 --- a/test/tcc_test.go +++ b/test/tcc_test.go @@ -19,7 +19,7 @@ import ( func TestTccNormal(t *testing.T) { req := examples.GenTransReq(30, false, false) gid := dtmimp.GetFuncName() - err := dtmcli.TccGlobalTransaction(examples.DtmServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) { + err := dtmcli.TccGlobalTransaction(examples.DtmHttpServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) { _, err := tcc.CallBranch(req, Busi+"/TransOut", Busi+"/TransOutConfirm", Busi+"/TransOutRevert") assert.Nil(t, err) return tcc.CallBranch(req, Busi+"/TransIn", Busi+"/TransInConfirm", Busi+"/TransInRevert") @@ -33,7 +33,7 @@ func TestTccNormal(t *testing.T) { func TestTccRollback(t *testing.T) { gid := dtmimp.GetFuncName() req := examples.GenTransReq(30, false, true) - err := dtmcli.TccGlobalTransaction(examples.DtmServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) { + err := dtmcli.TccGlobalTransaction(examples.DtmHttpServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) { _, rerr := tcc.CallBranch(req, Busi+"/TransOut", Busi+"/TransOutConfirm", Busi+"/TransOutRevert") assert.Nil(t, rerr) examples.MainSwitch.TransOutRevertResult.SetOnce(dtmcli.ResultOngoing) @@ -52,7 +52,7 @@ func TestTccTimeout(t *testing.T) { gid := dtmimp.GetFuncName() timeoutChan := make(chan int, 1) - err := dtmcli.TccGlobalTransaction(examples.DtmServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) { + err := dtmcli.TccGlobalTransaction(examples.DtmHttpServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) { _, err := tcc.CallBranch(req, Busi+"/TransOut", Busi+"/TransOutConfirm", Busi+"/TransOutRevert") assert.Nil(t, err) go func() { @@ -72,7 +72,7 @@ func TestTccTimeout(t *testing.T) { func TestTccCompatible(t *testing.T) { req := examples.GenTransReq(30, false, false) gid := dtmimp.GetFuncName() - err := dtmcli.TccGlobalTransaction(examples.DtmServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) { + err := dtmcli.TccGlobalTransaction(examples.DtmHttpServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) { _, err := tcc.CallBranch(req, Busi+"/TransOut", Busi+"/TransOutConfirm", Busi+"/TransOutRevert") assert.Nil(t, err) return tcc.CallBranch(req, Busi+"/TransIn", Busi+"/TransInConfirm", Busi+"/TransInRevert")