|
|
|
@ -20,7 +20,8 @@ func TestXa(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func xaLocalError(t *testing.T) { |
|
|
|
_, err := examples.XaClient.XaGlobalTransaction("xaLocalError", func(xa *dtmcli.Xa) (*resty.Response, error) { |
|
|
|
xc := examples.XaClient |
|
|
|
_, err := xc.XaGlobalTransaction("xaLocalError", func(xa *dtmcli.Xa) (*resty.Response, error) { |
|
|
|
return nil, fmt.Errorf("an error") |
|
|
|
}) |
|
|
|
assert.Error(t, err, fmt.Errorf("an error")) |
|
|
|
@ -29,7 +30,7 @@ func xaLocalError(t *testing.T) { |
|
|
|
func xaNormal(t *testing.T) { |
|
|
|
xc := examples.XaClient |
|
|
|
gid := "xaNormal" |
|
|
|
res, err := xc.XaGlobalTransaction(gid, func(xa *dtmcli.Xa) (*resty.Response, error) { |
|
|
|
_, err := xc.XaGlobalTransaction(gid, func(xa *dtmcli.Xa) (*resty.Response, error) { |
|
|
|
req := examples.GenTransReq(30, false, false) |
|
|
|
resp, err := xa.CallBranch(req, examples.Busi+"/TransOutXa") |
|
|
|
if dtmcli.IsFailure(resp, err) { |
|
|
|
@ -37,7 +38,7 @@ func xaNormal(t *testing.T) { |
|
|
|
} |
|
|
|
return xa.CallBranch(req, examples.Busi+"/TransInXa") |
|
|
|
}) |
|
|
|
dtmcli.PanicIfFailure(res, err) |
|
|
|
assert.Equal(t, nil, err) |
|
|
|
WaitTransProcessed(gid) |
|
|
|
assert.Equal(t, []string{"prepared", "succeed", "prepared", "succeed"}, getBranchesStatus(gid)) |
|
|
|
} |
|
|
|
@ -45,7 +46,7 @@ func xaNormal(t *testing.T) { |
|
|
|
func xaRollback(t *testing.T) { |
|
|
|
xc := examples.XaClient |
|
|
|
gid := "xaRollback" |
|
|
|
res, err := xc.XaGlobalTransaction(gid, func(xa *dtmcli.Xa) (*resty.Response, error) { |
|
|
|
_, err := xc.XaGlobalTransaction(gid, func(xa *dtmcli.Xa) (*resty.Response, error) { |
|
|
|
req := &examples.TransReq{Amount: 30, TransInResult: "FAILURE"} |
|
|
|
resp, err := xa.CallBranch(req, examples.Busi+"/TransOutXa") |
|
|
|
if dtmcli.IsFailure(resp, err) { |
|
|
|
@ -53,7 +54,7 @@ func xaRollback(t *testing.T) { |
|
|
|
} |
|
|
|
return xa.CallBranch(req, examples.Busi+"/TransInXa") |
|
|
|
}) |
|
|
|
assert.True(t, dtmcli.IsFailure(res, err)) |
|
|
|
assert.Error(t, err) |
|
|
|
WaitTransProcessed(gid) |
|
|
|
assert.Equal(t, []string{"succeed", "prepared"}, getBranchesStatus(gid)) |
|
|
|
assert.Equal(t, "failed", getTransStatus(gid)) |
|
|
|
|