ptyin commented on code in PR #650: URL: https://github.com/apache/incubator-seata-go/pull/650#discussion_r1462869840
########## pkg/saga/statemachine/statelang/parser/compensation_trigger_state_parser.go: ########## @@ -0,0 +1,31 @@ +package parser + +import ( + "github.com/seata/seata-go/pkg/saga/statemachine/constant" + "github.com/seata/seata-go/pkg/saga/statemachine/statelang" + "github.com/seata/seata-go/pkg/saga/statemachine/statelang/state" +) + +type CompensationTriggerStateParser struct { + BaseStateParser Review Comment: I found `BaseStateParser` are sometimes used as pointer embedding, and sometimes value embedding. Is there any special consideration? ########## pkg/saga/statemachine/statelang/state/sub_state_machine.go: ########## @@ -0,0 +1,70 @@ +package state + +import ( + "github.com/google/uuid" + "github.com/seata/seata-go/pkg/saga/statemachine/constant" + "strconv" +) + +type SubStateMachine interface { + TaskState + + StateMachineName() string + + CompensateStateImpl() TaskState +} + +type SubStateMachineImpl struct { + *ServiceTaskStateImpl + stateMachineName string + compensateState TaskState +} + +func NewSubStateMachineImpl() *SubStateMachineImpl { + return &SubStateMachineImpl{ + ServiceTaskStateImpl: NewServiceTaskStateImpl(), + } +} + +func (s *SubStateMachineImpl) StateMachineName() string { + return s.stateMachineName +} + +func (s *SubStateMachineImpl) SetStateMachineName(stateMachineName string) { + s.stateMachineName = stateMachineName +} + +func (s *SubStateMachineImpl) CompensateStateImpl() TaskState { + return s.compensateState +} + +func (s *SubStateMachineImpl) SetCompensateStateImpl(compensateState TaskState) { + s.compensateState = compensateState +} + +type CompensateSubStateMachineState interface { + ServiceTaskState +} + +type CompensateSubStateMachineStateImpl struct { + *ServiceTaskStateImpl + hashcode string +} + +func NewCompensateSubStateMachineStateImpl() *CompensateSubStateMachineStateImpl { + uuid := uuid.New() + c := &CompensateSubStateMachineStateImpl{ + ServiceTaskStateImpl: NewServiceTaskStateImpl(), + hashcode: strconv.Itoa(int(uuid.ID())), Review Comment: `uuid.String()` is more appropriate ########## pkg/saga/statemachine/statelang/parser/statemachine_json_parser_test.go: ########## @@ -11,3 +11,11 @@ func TestParseChoice(t *testing.T) { t.Error("parse fail: " + err.Error()) } } + +func TestParseServiceTask(t *testing.T) { + content := "{\n \"Name\": \"StateMachineNewDesigner\",\n \"Comment\": \"This state machine is modeled by designer tools.\",\n \"Version\": \"0.0.1\",\n \"style\": {\n \"bounds\": {\n \"x\": 200,\n \"y\": 200,\n \"width\": 36,\n \"height\": 36\n }\n },\n \"States\": {\n \"ServiceTask-a9h2o51\": {\n \"style\": {\n \"bounds\": {\n \"x\": 300,\n \"y\": 178,\n \"width\": 100,\n \"height\": 80\n }\n },\n \"Name\": \"ServiceTask-a9h2o51\",\n \"IsForCompensation\": false,\n \"Input\": [\n {}\n ],\n \"Output\": {},\n \"Status\": {},\n \"Retry\": [],\n \"ServiceName\": \"\",\n \"ServiceMethod\": \"\",\n \"Type\": \"ServiceTask\",\n \"Next\": \"Choice- 4ajl8nt\",\n \"edge\": {\n \"Choice-4ajl8nt\": {\n \"style\": {\n \"waypoints\": [\n {\n \"original\": {\n \"x\": 400,\n \"y\": 218\n },\n \"x\": 400,\n \"y\": 218\n },\n {\n \"x\": 435,\n \"y\": 218\n },\n {\n \"original\": {\n \"x\": 455,\n \"y\": 218\n },\n \"x\": 455,\n \"y\": 218\n }\n ], \n \"source\": \"ServiceTask-a9h2o51\",\n \"target\": \"Choice-4ajl8nt\"\n },\n \"Type\": \"Transition\"\n }\n },\n \"CompensateState\": \"CompensateFirstState\"\n },\n \"Choice-4ajl8nt\": {\n \"style\": {\n \"bounds\": {\n \"x\": 455,\n \"y\": 193,\n \"width\": 50,\n \"height\": 50\n }\n },\n \"Name\": \"Choice-4ajl8nt\",\n \"Type\": \"Choice\",\n \"Choices\": [\n {\n \"Expression\": \"\",\n \"Next\": \"SubStateMachine-cauj9uy\"\n },\n {\n \"Expression\": \"\",\n \"Next\": \"ServiceTask-vdij28l\"\n }\n ],\n \"Default\": \"SubStateMachin e-cauj9uy\",\n \"edge\": {\n \"SubStateMachine-cauj9uy\": {\n \"style\": {\n \"waypoints\": [\n {\n \"original\": {\n \"x\": 505,\n \"y\": 218\n },\n \"x\": 505,\n \"y\": 218\n },\n {\n \"x\": 530,\n \"y\": 218\n },\n {\n \"original\": {\n \"x\": 550,\n \"y\": 218\n },\n \"x\": 550,\n \"y\": 218\n }\n ],\n \"source\": \"Choice-4ajl8nt\",\n \"target\": \"SubStateMachine-cauj9uy\"\n },\n \"Type\": \"ChoiceEntry\"\n },\n \"ServiceTask-vdij28l\": {\n \"style\": {\n \"waypoints\": [\n {\n \"original\": {\n \"x\": 480,\n \"y\": 243\n },\n \"x\": 480,\n \"y\": 243\n },\n {\n \"x\": 600,\n \"y\": 290\n },\n {\n \"original\": {\n \"x\": 600,\n \"y\": 310\n },\n \"x\": 600,\n \"y\": 310\n }\n ],\n \"source\": \"Choice-4ajl8nt\",\n \"target\": \"ServiceTask-vdij28l\"\n },\n \"Type\": \"ChoiceEntry\"\n }\n }\n },\n \"CompensateFirstState\": {\n \"style\": {\n \"bounds\": {\n \"x\": 300,\n \"y\": 310,\n \"width\": 100,\n \"height\": 80\n }\n },\n \"Name\": \"CompensateFirstState\",\n \"IsForCompensation\": true,\n \"Input\": [\n {}\n ],\n \"Output\": {},\n \"Status\": {},\n \"Retry\": [],\n \"ServiceName\": \"\",\n \"ServiceMe thod\": \"\",\n \"Type\": \"ServiceTask\"\n },\n \"SubStateMachine-cauj9uy\": {\n \"style\": {\n \"bounds\": {\n \"x\": 550,\n \"y\": 178,\n \"width\": 100,\n \"height\": 80\n }\n },\n \"Name\": \"SubStateMachine-cauj9uy\",\n \"IsForCompensation\": false,\n \"Input\": [\n {}\n ],\n \"Output\": {},\n \"Status\": {},\n \"Retry\": [],\n \"StateMachineName\": \"\",\n \"Type\": \"SubStateMachine\",\n \"Next\": \"Succeed-5x3z98u\",\n \"edge\": {\n \"Succeed-5x3z98u\": {\n \"style\": {\n \"waypoints\": [\n {\n \"original\": {\n \"x\": 650,\n \"y\": 218\n },\n \"x\": 650,\n \"y\": 218\n },\n {\n \"x\": 702,\n \"y\": 218\n },\n {\n \"original\": {\n \"x\": 722,\n \"y\": 218\n },\n \"x\": 722,\n \"y\": 218\n }\n ],\n \"source\": \"SubStateMachine-cauj9uy\",\n \"target\": \"Succeed-5x3z98u\"\n },\n \"Type\": \"Transition\"\n }\n }\n },\n \"ServiceTask-vdij28l\": {\n \"style\": {\n \"bounds\": {\n \"x\": 550,\n \"y\": 310,\n \"width\": 100,\n \"height\": 80\n }\n },\n \"Name\": \"ServiceTask-vdij28l\",\n \"IsForCompensation\": false,\n \"Input\": [\n {}\n ],\n \"Output\": {},\n \"Status\": {},\n \"Retry\": [],\n \"ServiceName\": \"\",\n \"ServiceMethod\": \"\",\n \"Catch\": [\n {\n \"Exceptions\": [],\n \"Next\": \"CompensationTrigger-uldp2ou\"\n }\n ],\n \"Type\": \"ServiceTask\",\n \"catch\": {\n \"style\": {\n \"bounds\": {\n \"x\": 632,\n \"y\": 372,\n \"width\": 36,\n \"height\": 36\n }\n },\n \"edge\": {\n \"CompensationTrigger-uldp2ou\": {\n \"style\": {\n \"waypoints\": [\n {\n \"original\": {\n \"x\": 668,\n \"y\": 390\n },\n \"x\": 668,\n \"y\": 390\n },\n {\n \"x\": 702,\n \"y\": 390\n },\n {\n \"original\": {\n \"x\": 722,\n \"y\": 390\n },\n \"x\": 722,\n \"y\": 390\n }\n ],\n \"source\": \"ServiceTask-vdij28l\",\n \"target\": \"CompensationTrigger-uldp2ou\"\n },\n \"Type\": \"ExceptionMatch\"\n }\n }\n },\n \"Next\": \"Succeed-5x3z98u\",\n \"edge\": {\n \"Succeed-5x3z98u\": {\n \"style\": {\n \"waypoints\": [\n {\n \"original\": {\n \"x\": 600,\n \"y\": 310\n },\n \"x\": 600,\n \"y\": 310\n },\n {\n \"x\": 740,\n \"y\": 256\n },\n {\n \"original\": {\n \"x\": 740,\n \"y\": 236\n },\n \"x\": 740,\n \"y\": 236\n }\n ],\n \"source\": \"ServiceTask-vdij28l\",\n \"target\": \"Succeed-5x3z98u\"\n },\n \"Type\": \"Transition\"\n }\n }\n },\n \"Succeed-5x3z98u\": {\n \"style\": {\n \"bounds\": {\n \"x\": 722,\n \"y\": 200,\n \"width\": 36,\n \"height\": 36\n }\n },\n \"Name\": \"Succeed-5x3z98u\",\n \"Type\": \"Succeed\"\n },\n \"CompensationTrigger-uldp2ou\": {\n \"style\": {\n \"bounds\": {\n \"x\": 722,\n \"y\": 372,\n \"width\": 36,\n \"height\": 36\n }\n },\n \"Name\": \"CompensationTrigger-uldp2ou\",\n \"Type\": \"CompensationTrigger\",\n \"Next\": \"Fail-9roxcv5\",\n \"edge\": {\n \"Fail-9roxcv5\": {\n \"style\": {\n \"waypoints\": [\n {\n \"original\": {\n \"x\": 758,\n \"y\": 390\n },\n \"x\": 758,\n \"y\": 390\n },\n {\n \"x\": 792,\n \"y\": 390\n },\n {\n \"original\": {\n \"x\": 812,\n \"y\": 390\n },\n \"x\": 812,\n \"y\": 390\n }\n ],\n \"source\": \"CompensationTrigger-uldp2ou\",\n \"target\": \"Fail-9roxcv5\"\n },\n \"Type\": \"Transition\"\n }\n }\n },\n \"Fail-9roxcv5\": {\n \"style\": {\n \"bounds\": {\n \"x\": 812,\n \"y\": 372,\n \"width\": 36,\n \"height\": 36\n }\n },\n \"Name\": \"Fail-9roxcv5\",\n \"ErrorCode\": \"\",\n \"Message\": \"\",\n \"Type\": \"Fail\"\n }\n },\n \"StartState\": \"ServiceTask-a9h2o51\",\n \"edge\": {\n \"style\": {\n \"waypoints\": [\n {\n \"original\": {\n \"x\": 236,\n \"y\": 218\n },\n \"x\": 236,\n \"y\": 218\n },\n {\n \"x\": 280,\n \"y\": 218\n },\n {\n \"original\": {\n \"x\": 300,\n \"y\": 218\n },\n \"x\": 300,\n \"y\": 218\n }\n ],\n \"target\": \"ServiceTask-a9h2o51\"\n },\n \"Type\": \"Transition\"\n }\n}" Review Comment: I think we should add another UT, using the following file as the test source, which is better aligned with Java. https://github.com/apache/incubator-seata/blob/2.x/saga/seata-saga-statelang/src/test/resources/statelang/simple_statemachine.json -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@seata.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@seata.apache.org For additional commands, e-mail: dev-h...@seata.apache.org