edit
This commit is contained in:
parent
72c31c5517
commit
7d6891851d
@ -0,0 +1,14 @@
|
||||
package com.ybw.constant;
|
||||
|
||||
/**
|
||||
* redis前缀常量
|
||||
*
|
||||
* @author weixiansheng
|
||||
* @version V1.0
|
||||
* @className RedisPreConstant
|
||||
* @date 2023/12/27
|
||||
**/
|
||||
public interface RedisPreConstant {
|
||||
|
||||
String STATE_MACHINE = "STATE:MACHINE";
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.ybw.state;
|
||||
|
||||
import com.ybw.constant.RedisPreConstant;
|
||||
import com.ybw.constant.RegEventEnum;
|
||||
import com.ybw.constant.RegStatusEnum;
|
||||
import com.ybw.entity.Order;
|
||||
@ -38,20 +39,37 @@ public class StateTest {
|
||||
@Test
|
||||
public void testState() {
|
||||
try {
|
||||
//1、订单数据
|
||||
Order order = Order.builder()
|
||||
.id(1L)
|
||||
.name("张三")
|
||||
.status(RegStatusEnum.CONNECTED)
|
||||
.build();
|
||||
//2、获取redis key
|
||||
String redisKey = getRedisKey(order);
|
||||
//3、启动状态机
|
||||
stateMachine.start();
|
||||
//尝试恢复状态机状态(read)
|
||||
persister.restore(stateMachine, order.getId().toString());
|
||||
//4、尝试恢复状态机状态(read)
|
||||
persister.restore(stateMachine, redisKey);
|
||||
Message<RegEventEnum> message = MessageBuilder.withPayload(RegEventEnum.REGISTER).setHeader("order", order).build();
|
||||
stateMachine.sendEvent(message);
|
||||
//持久化状态机状态(write)
|
||||
persister.persist(stateMachine, order.getId().toString());
|
||||
//5、持久化状态机状态(write)
|
||||
persister.persist(stateMachine, redisKey);
|
||||
} catch (Exception e) {
|
||||
log.error("testState error:", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取redis key
|
||||
*
|
||||
* @param order
|
||||
* @methodName: getRedisKey
|
||||
* @return: java.lang.String
|
||||
* @author: weixiansheng
|
||||
* @date: 2023/12/27
|
||||
**/
|
||||
private static String getRedisKey(Order order) {
|
||||
return RedisPreConstant.STATE_MACHINE + order.getId();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user