Seata 分布式事务功能测试(三)

前置内容:Seata 分布式事务功能测试(一)

当前数据库隔离级别为 read_commit,测试调用服务后,再通过服务查询时获取的数据是否正确。

//查询当前账户余额
Double amount = accountService.getAmount(orderVO.getUserId());
logger.info("扣款前余额: " + amount);
accountService.decreaseAccount(accountVO);
//查询当前账户余额
amount = accountService.getAmount(orderVO.getUserId());
logger.info("扣款后余额: " + amount);

1. 测试用例 1

属性
库存500
余额2000
商品编号C201901140001
用户1

结果:操作成功,库存变成500,余额变成2000,增加一个新订单

1.1 business 日志:

2019-10-11 10:09:07,960 [DubboServerHandler-10.10.10.130:20883-thread-27] INFO  i.s.t.a.DefaultGlobalTransaction - Begin new global transaction [10.42.1.30:8091:2024332412]
开始全局事务,XID = 10.42.1.30:8091:2024332412
2019-10-11 10:09:10,599 [DubboServerHandler-10.10.10.130:20883-thread-27] INFO  i.s.t.a.DefaultGlobalTransaction - [10.42.1.30:8091:2024332412] commit status:Committed

1.2 storage 日志:

2019-10-11 10:09:07,975 [DubboServerHandler-10.10.10.130:20882-thread-13] DEBUG c.n.s.d.T.decreaseStorage - ==>  Preparing: update t_storage set count = count-500 where commodity_code = ? and count >= ?
2019-10-11 10:09:07,977 [DubboServerHandler-10.10.10.130:20882-thread-13] DEBUG c.n.s.d.T.decreaseStorage - ==> Parameters: C201901140001(String), 500(Integer)
2019-10-11 10:09:08,430 [DubboServerHandler-10.10.10.130:20882-thread-13] DEBUG c.n.s.d.T.decreaseStorage - <==    Updates: 1
2019-10-11 10:09:11,397 [rpcDispatch_RMROLE_3_8] INFO  i.s.c.r.n.RmMessageListener - onMessage:xid=10.42.1.30:8091:2024332412,branchId=2024332415,branchType=AT,resourceId=jdbc:mysql://10.10.10.233:3306/seata_demo_storage,applicationData=null
2019-10-11 10:09:11,397 [rpcDispatch_RMROLE_3_8] INFO  i.s.r.AbstractRMHandler - Branch committing: 10.42.1.30:8091:2024332412 2024332415 jdbc:mysql://10.10.10.233:3306/seata_demo_storage null
2019-10-11 10:09:11,397 [rpcDispatch_RMROLE_3_8] INFO  i.s.r.AbstractRMHandler - Branch commit result: PhaseTwo_Committed

1.3 account 日志:

2019-10-11 10:09:08,570 [DubboServerHandler-10.10.10.130:20880-thread-2] INFO  i.s.c.l.EnhancedServiceLoader - load ContextCore[null] extension by class[io.seata.core.context.ThreadLocalContextCore]
2019-10-11 10:09:08,632 [DubboServerHandler-10.10.10.130:20880-thread-2] DEBUG c.n.a.d.T.selectOne - ==>  Preparing: SELECT id,user_id,amount FROM t_account WHERE user_id = ?
2019-10-11 10:09:08,649 [DubboServerHandler-10.10.10.130:20880-thread-2] DEBUG c.n.a.d.T.selectOne - ==> Parameters: 1(String)
2019-10-11 10:09:08,748 [DubboServerHandler-10.10.10.130:20880-thread-2] DEBUG c.n.a.d.T.selectOne - <==      Total: 1
2019-10-11 10:09:08,807 [DubboServerHandler-10.10.10.130:20880-thread-3] DEBUG c.n.a.d.T.decreaseAccount - ==>  Preparing: update t_account set amount = amount-3000.0 where user_id = ? and amount > ?
2019-10-11 10:09:08,808 [DubboServerHandler-10.10.10.130:20880-thread-3] DEBUG c.n.a.d.T.decreaseAccount - ==> Parameters: 1(String), 3000.0(Double)
2019-10-11 10:09:09,268 [DubboServerHandler-10.10.10.130:20880-thread-3] DEBUG c.n.a.d.T.decreaseAccount - <==    Updates: 1
2019-10-11 10:09:09,272 [DubboServerHandler-10.10.10.130:20880-thread-3] INFO  i.s.c.l.EnhancedServiceLoader - load LoadBalance[null] extension by class[io.seata.discovery.loadbalance.RandomLoadBalance]
2019-10-11 10:09:09,415 [DubboServerHandler-10.10.10.130:20880-thread-3] INFO  i.s.c.l.EnhancedServiceLoader - load UndoLogParser[jackson] extension by class[io.seata.rm.datasource.undo.parser.JacksonUndoLogParser]
2019-10-11 10:09:09,545 [DubboServerHandler-10.10.10.130:20880-thread-4] DEBUG c.n.a.d.T.selectOne - ==>  Preparing: SELECT id,user_id,amount FROM t_account WHERE user_id = ?
2019-10-11 10:09:09,546 [DubboServerHandler-10.10.10.130:20880-thread-4] DEBUG c.n.a.d.T.selectOne - ==> Parameters: 1(String)
2019-10-11 10:09:09,550 [DubboServerHandler-10.10.10.130:20880-thread-4] DEBUG c.n.a.d.T.selectOne - <==      Total: 1
2019-10-11 10:09:11,459 [rpcDispatch_RMROLE_1_8] INFO  i.s.c.r.n.RmMessageListener - onMessage:xid=10.42.1.30:8091:2024332412,branchId=2024332418,branchType=AT,resourceId=jdbc:mysql://10.10.10.233:3306/seata_demo_account,applicationData=null
2019-10-11 10:09:11,460 [rpcDispatch_RMROLE_1_8] INFO  i.s.r.AbstractRMHandler - Branch committing: 10.42.1.30:8091:2024332412 2024332418 jdbc:mysql://10.10.10.233:3306/seata_demo_account null
2019-10-11 10:09:11,461 [rpcDispatch_RMROLE_1_8] INFO  i.s.r.AbstractRMHandler - Branch commit result: PhaseTwo_Committed

1.4 order 日志:

2019-10-11 10:09:08,523 [DubboServerHandler-10.10.10.130:20881-thread-2] INFO  i.s.c.l.EnhancedServiceLoader - load ContextCore[null] extension by class[io.seata.core.context.ThreadLocalContextCore]
2019-10-11 10:09:08,795 [DubboServerHandler-10.10.10.130:20881-thread-2] INFO  c.n.o.s.i.TOrderServiceImpl - 扣款前余额: 4000.0
2019-10-11 10:09:09,583 [DubboServerHandler-10.10.10.130:20881-thread-2] INFO  c.n.o.s.i.TOrderServiceImpl - 扣款后余额: 1000.0
2019-10-11 10:09:09,871 [DubboServerHandler-10.10.10.130:20881-thread-2] DEBUG c.n.o.d.T.insert - ==>  Preparing: INSERT INTO t_order ( id,order_no,user_id,commodity_code,count,amount ) VALUES( ?,?,?,?,?,? )
2019-10-11 10:09:09,890 [DubboServerHandler-10.10.10.130:20881-thread-2] DEBUG c.n.o.d.T.insert - ==> Parameters: 1314754168291853302(Long), 2d247c43418545b4812a4a8cc9efd718(String), 1(String), C201901140001(String), 500(Integer), 3000.0(Double)
2019-10-11 10:09:10,178 [DubboServerHandler-10.10.10.130:20881-thread-2] DEBUG c.n.o.d.T.insert - <==    Updates: 1
2019-10-11 10:09:10,185 [DubboServerHandler-10.10.10.130:20881-thread-2] INFO  i.s.c.l.EnhancedServiceLoader - load LoadBalance[null] extension by class[io.seata.discovery.loadbalance.RandomLoadBalance]
2019-10-11 10:09:10,371 [DubboServerHandler-10.10.10.130:20881-thread-2] INFO  i.s.c.l.EnhancedServiceLoader - load UndoLogParser[jackson] extension by class[io.seata.rm.datasource.undo.parser.JacksonUndoLogParser]
2019-10-11 10:09:11,531 [rpcDispatch_RMROLE_1_8] INFO  i.s.c.r.n.RmMessageListener - onMessage:xid=10.42.1.30:8091:2024332412,branchId=2024332422,branchType=AT,resourceId=jdbc:mysql://10.10.10.233:3306/seata_demo_order,applicationData=null
2019-10-11 10:09:11,533 [rpcDispatch_RMROLE_1_8] INFO  i.s.r.AbstractRMHandler - Branch committing: 10.42.1.30:8091:2024332412 2024332422 jdbc:mysql://10.10.10.233:3306/seata_demo_order null
2019-10-11 10:09:11,534 [rpcDispatch_RMROLE_1_8] INFO  i.s.r.AbstractRMHandler - Branch commit result: PhaseTwo_Committed

1.5 合并日志看整体执行顺序

服务时间日志
business2019-10-11 10:09:07,960[DubboServerHandler-10.10.10.130:20883-thread-27] INFO i.s.t.a.DefaultGlobalTransaction - Begin new global transaction [10.42.1.30:8091:2024332412]
business2019-10-11 10:09:07,960开始全局事务,XID = 10.42.1.30:8091:2024332412
storage2019-10-11 10:09:07,975[DubboServerHandler-10.10.10.130:20882-thread-13] DEBUG c.n.s.d.T.decreaseStorage - ==> Preparing: update t_storage set count = count-500 where commodity_code = ? and count >= ?
storage2019-10-11 10:09:07,977[DubboServerHandler-10.10.10.130:20882-thread-13] DEBUG c.n.s.d.T.decreaseStorage - ==> Parameters: C201901140001(String), 500(Integer)
storage2019-10-11 10:09:08,430[DubboServerHandler-10.10.10.130:20882-thread-13] DEBUG c.n.s.d.T.decreaseStorage - <== Updates: 1
order2019-10-11 10:09:08,523[DubboServerHandler-10.10.10.130:20881-thread-2] INFO i.s.c.l.EnhancedServiceLoader - load ContextCore[null] extension by class[io.seata.core.context.ThreadLocalContextCore]
account2019-10-11 10:09:08,570[DubboServerHandler-10.10.10.130:20880-thread-2] INFO i.s.c.l.EnhancedServiceLoader - load ContextCore[null] extension by class[io.seata.core.context.ThreadLocalContextCore]
account2019-10-11 10:09:08,632[DubboServerHandler-10.10.10.130:20880-thread-2] DEBUG c.n.a.d.T.selectOne - ==> Preparing: SELECT id,user_id,amount FROM t_account WHERE user_id = ?
account2019-10-11 10:09:08,649[DubboServerHandler-10.10.10.130:20880-thread-2] DEBUG c.n.a.d.T.selectOne - ==> Parameters: 1(String)
account2019-10-11 10:09:08,748[DubboServerHandler-10.10.10.130:20880-thread-2] DEBUG c.n.a.d.T.selectOne - <== Total: 1
order2019-10-11 10:09:08,795[DubboServerHandler-10.10.10.130:20881-thread-2] INFO c.n.o.s.i.TOrderServiceImpl - 扣款前余额: 4000
account2019-10-11 10:09:08,807[DubboServerHandler-10.10.10.130:20880-thread-3] DEBUG c.n.a.d.T.decreaseAccount - ==> Preparing: update t_account set amount = amount-3000.0 where user_id = ? and amount > ?
account2019-10-11 10:09:08,808[DubboServerHandler-10.10.10.130:20880-thread-3] DEBUG c.n.a.d.T.decreaseAccount - ==> Parameters: 1(String), 3000.0(Double)
account2019-10-11 10:09:09,268[DubboServerHandler-10.10.10.130:20880-thread-3] DEBUG c.n.a.d.T.decreaseAccount - <== Updates: 1
account2019-10-11 10:09:09,272[DubboServerHandler-10.10.10.130:20880-thread-3] INFO i.s.c.l.EnhancedServiceLoader - load LoadBalance[null] extension by class[io.seata.discovery.loadbalance.RandomLoadBalance]
account2019-10-11 10:09:09,415[DubboServerHandler-10.10.10.130:20880-thread-3] INFO i.s.c.l.EnhancedServiceLoader - load UndoLogParser[jackson] extension by class[io.seata.rm.datasource.undo.parser.JacksonUndoLogParser]
account2019-10-11 10:09:09,545[DubboServerHandler-10.10.10.130:20880-thread-4] DEBUG c.n.a.d.T.selectOne - ==> Preparing: SELECT id,user_id,amount FROM t_account WHERE user_id = ?
account2019-10-11 10:09:09,546[DubboServerHandler-10.10.10.130:20880-thread-4] DEBUG c.n.a.d.T.selectOne - ==> Parameters: 1(String)
account2019-10-11 10:09:09,550[DubboServerHandler-10.10.10.130:20880-thread-4] DEBUG c.n.a.d.T.selectOne - <== Total: 1
order2019-10-11 10:09:09,583[DubboServerHandler-10.10.10.130:20881-thread-2] INFO c.n.o.s.i.TOrderServiceImpl - 扣款后余额: 1000
order2019-10-11 10:09:09,871[DubboServerHandler-10.10.10.130:20881-thread-2] DEBUG c.n.o.d.T.insert - ==> Preparing: INSERT INTO t_order ( id,order_no,user_id,commodity_code,count,amount ) VALUES( ?,?,?,?,?,? )
order2019-10-11 10:09:09,890[DubboServerHandler-10.10.10.130:20881-thread-2] DEBUG c.n.o.d.T.insert - ==> Parameters: 1314754168291853302(Long), 2d247c43418545b4812a4a8cc9efd718(String), 1(String), C201901140001(String), 500(Integer), 3000.0(Double)
order2019-10-11 10:09:10,178[DubboServerHandler-10.10.10.130:20881-thread-2] DEBUG c.n.o.d.T.insert - <== Updates: 1
order2019-10-11 10:09:10,185[DubboServerHandler-10.10.10.130:20881-thread-2] INFO i.s.c.l.EnhancedServiceLoader - load LoadBalance[null] extension by class[io.seata.discovery.loadbalance.RandomLoadBalance]
order2019-10-11 10:09:10,371[DubboServerHandler-10.10.10.130:20881-thread-2] INFO i.s.c.l.EnhancedServiceLoader - load UndoLogParser[jackson] extension by class[io.seata.rm.datasource.undo.parser.JacksonUndoLogParser]
business2019-10-11 10:09:10,599[DubboServerHandler-10.10.10.130:20883-thread-27] INFO i.s.t.a.DefaultGlobalTransaction - [10.42.1.30:8091:2024332412] commit status:Committed
storage2019-10-11 10:09:11,397[rpcDispatch_RMROLE_3_8] INFO i.s.c.r.n.RmMessageListener - onMessage:xid=10.42.1.30:8091:2024332412,branchId=2024332415,branchType=AT,resourceId=jdbc:mysql://10.10.10.233:3306/seata_demo_storage,applicationData=null
storage2019-10-11 10:09:11,397[rpcDispatch_RMROLE_3_8] INFO i.s.r.AbstractRMHandler - Branch committing: 10.42.1.30:8091:2024332412 2024332415 jdbc:mysql://10.10.10.233:3306/seata_demo_storage null
storage2019-10-11 10:09:11,397[rpcDispatch_RMROLE_3_8] INFO i.s.r.AbstractRMHandler - Branch commit result: PhaseTwo_Committed
account2019-10-11 10:09:11,459[rpcDispatch_RMROLE_1_8] INFO i.s.c.r.n.RmMessageListener - onMessage:xid=10.42.1.30:8091:2024332412,branchId=2024332418,branchType=AT,resourceId=jdbc:mysql://10.10.10.233:3306/seata_demo_account,applicationData=null
account2019-10-11 10:09:11,460[rpcDispatch_RMROLE_1_8] INFO i.s.r.AbstractRMHandler - Branch committing: 10.42.1.30:8091:2024332412 2024332418 jdbc:mysql://10.10.10.233:3306/seata_demo_account null
account2019-10-11 10:09:11,461[rpcDispatch_RMROLE_1_8] INFO i.s.r.AbstractRMHandler - Branch commit result: PhaseTwo_Committed
order2019-10-11 10:09:11,531[rpcDispatch_RMROLE_1_8] INFO i.s.c.r.n.RmMessageListener - onMessage:xid=10.42.1.30:8091:2024332412,branchId=2024332422,branchType=AT,resourceId=jdbc:mysql://10.10.10.233:3306/seata_demo_order,applicationData=null
order2019-10-11 10:09:11,533[rpcDispatch_RMROLE_1_8] INFO i.s.r.AbstractRMHandler - Branch committing: 10.42.1.30:8091:2024332412 2024332422 jdbc:mysql://10.10.10.233:3306/seata_demo_order null
order2019-10-11 10:09:11,534[rpcDispatch_RMROLE_1_8] INFO i.s.r.AbstractRMHandler - Branch commit result: PhaseTwo_Committed
isea533 CSDN认证博客专家 运维开发 系统架构
《MyBatis从入门到精通》作者,MyBatis分页插件PageHelper作者,通用Mapper作者,个人网站:https://mybatis.io
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 酷酷鲨 设计师:CSDN官方博客 返回首页