From 935506a388fdef22670b5d3a628b0d92a066f2cc Mon Sep 17 00:00:00 2001 From: bryan31 Date: Mon, 16 May 2022 11:58:18 +0800 Subject: [PATCH] =?UTF-8?q?feature=20#I54VBS=20=E4=BB=8E=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E4=B8=8A=E6=94=B9=E5=96=84NodeComponent=EF=BC=8C=E4=BD=BF?= =?UTF-8?q?=E4=B9=8B=E5=8F=98=E6=88=90=E5=A3=B0=E6=98=8E=E5=BC=8F=E7=9A=84?= =?UTF-8?q?=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteflow-core/pom.xml | 4 + .../annotation/LiteflowCmpDefine.java | 10 + .../annotation/LiteflowCondCmpDefine.java | 10 + .../liteflow/annotation/LiteflowMethod.java | 14 ++ .../liteflow/annotation/util/AnnoUtil.java | 1 + .../liteflow/builder/LiteFlowNodeBuilder.java | 6 + .../yomahub/liteflow/core/NodeComponent.java | 2 +- .../liteflow/core/proxy/ComponentProxy.java | 129 +++++++++++ .../core/proxy/LiteFlowMethodBean.java | 31 +++ .../liteflow/enums/LiteFlowMethodEnum.java | 26 +++ .../ComponentMethodDefineErrorException.java | 22 ++ .../ComponentProxyErrorException.java | 22 ++ .../com/yomahub/liteflow/flow/FlowBus.java | 48 +++- .../yomahub/liteflow/spi/ContextAware.java | 2 + .../liteflow/spi/local/LocalContextAware.java | 5 + .../liteflow/util/LiteFlowProxyUtil.java | 102 ++++++++ .../yomahub/liteflow/util/SerialsUtil.java | 192 ++++++++++++++++ .../liteflow/spi/spring/SpringAware.java | 10 + .../liteflow/spring/ComponentScanner.java | 13 ++ liteflow-testcase-declare-component/pom.xml | 69 ++++++ .../com/yomahub/liteflow/test/BaseTest.java | 20 ++ .../AbsoluteConfigPathSpringbootTest.java | 42 ++++ .../test/absoluteConfigPath/cmp/ACmp.java | 24 ++ .../test/absoluteConfigPath/cmp/BCmp.java | 25 ++ .../test/absoluteConfigPath/cmp/CCmp.java | 25 ++ .../test/aop/CustomAOPSpringbootTest.java | 56 +++++ .../test/aop/GlobalAOPSpringbootTest.java | 76 ++++++ .../liteflow/test/aop/aspect/CmpAspect.java | 17 ++ .../test/aop/aspect/CustomAspect.java | 27 +++ .../yomahub/liteflow/test/aop/cmp1/ACmp.java | 25 ++ .../yomahub/liteflow/test/aop/cmp1/BCmp.java | 25 ++ .../yomahub/liteflow/test/aop/cmp1/CCmp.java | 25 ++ .../yomahub/liteflow/test/aop/cmp2/DCmp.java | 25 ++ .../yomahub/liteflow/test/aop/cmp2/ECmp.java | 25 ++ .../yomahub/liteflow/test/aop/cmp2/FCmp.java | 25 ++ .../asyncNode/AsyncNodeSpringbootTest.java | 134 +++++++++++ .../liteflow/test/asyncNode/cmp/ACmp.java | 28 +++ .../liteflow/test/asyncNode/cmp/BCmp.java | 28 +++ .../liteflow/test/asyncNode/cmp/CCmp.java | 28 +++ .../liteflow/test/asyncNode/cmp/DCmp.java | 29 +++ .../liteflow/test/asyncNode/cmp/ECmp.java | 20 ++ .../liteflow/test/asyncNode/cmp/FCmp.java | 18 ++ .../liteflow/test/asyncNode/cmp/GCmp.java | 30 +++ .../liteflow/test/asyncNode/cmp/HCmp.java | 30 +++ .../liteflow/test/asyncNode/cmp/ICmp.java | 28 +++ .../liteflow/test/asyncNode/cmp/JCmp.java | 21 ++ .../asyncNode/exception/TestException.java | 4 + .../test/base/BaseSpringbootTest.java | 39 ++++ .../yomahub/liteflow/test/base/cmp/ACmp.java | 24 ++ .../yomahub/liteflow/test/base/cmp/BCmp.java | 25 ++ .../yomahub/liteflow/test/base/cmp/CCmp.java | 25 ++ .../yomahub/liteflow/test/base/cmp/DCmp.java | 31 +++ .../liteflow/test/base/cmp/TestDomain.java | 10 + .../test/builder/BuilderSpringbootTest1.java | 217 ++++++++++++++++++ .../test/builder/BuilderSpringbootTest2.java | 41 ++++ .../liteflow/test/builder/cmp1/ACmp.java | 22 ++ .../liteflow/test/builder/cmp1/BCmp.java | 23 ++ .../liteflow/test/builder/cmp1/CCmp.java | 23 ++ .../liteflow/test/builder/cmp1/DCmp.java | 23 ++ .../liteflow/test/builder/cmp1/ECmp.java | 24 ++ .../liteflow/test/builder/cmp1/FCmp.java | 23 ++ .../liteflow/test/builder/cmp1/GCmp.java | 23 ++ .../liteflow/test/builder/cmp2/HCmp.java | 25 ++ .../liteflow/test/builder/cmp2/ICmp.java | 25 ++ .../liteflow/test/builder/cmp2/JCmp.java | 25 ++ .../cmpRetry/LiteflowRetrySpringbootTest.java | 64 ++++++ .../liteflow/test/cmpRetry/cmp/ACmp.java | 24 ++ .../liteflow/test/cmpRetry/cmp/BCmp.java | 31 +++ .../liteflow/test/cmpRetry/cmp/CCmp.java | 28 +++ .../liteflow/test/cmpRetry/cmp/DCmp.java | 28 +++ .../liteflow/test/cmpRetry/cmp/ECmp.java | 28 +++ .../component/FlowExecutorSpringbootTest.java | 94 ++++++++ .../liteflow/test/component/cmp1/ACmp.java | 30 +++ .../liteflow/test/component/cmp1/BCmp.java | 33 +++ .../liteflow/test/component/cmp1/CCmp.java | 33 +++ .../liteflow/test/component/cmp1/DCmp.java | 30 +++ .../liteflow/test/component/cmp1/ECmp.java | 28 +++ .../liteflow/test/component/cmp1/GCmp.java | 30 +++ .../liteflow/test/component/cmp1/HCmp.java | 24 ++ .../test/component/cmp2/FCondCmp.java | 27 +++ .../CustomNodesSpringbootTest.java | 45 ++++ .../liteflow/test/customNodes/cmp/ACmp.java | 22 ++ .../liteflow/test/customNodes/cmp/BCmp.java | 29 +++ .../liteflow/test/customNodes/cmp/CCmp.java | 23 ++ .../liteflow/test/customNodes/cmp/DCmp.java | 23 ++ .../liteflow/test/customNodes/cmp/ECmp.java | 30 +++ .../liteflow/test/customNodes/cmp/FCmp.java | 23 ++ .../test/customNodes/domain/DemoDomain.java | 11 + .../CustomThreadExecutor1.java | 25 ++ .../CustomThreadExecutor2.java | 24 ++ .../CustomThreadExecutor3.java | 24 ++ .../CustomWhenThreadPoolSpringbootTest.java | 72 ++++++ .../test/customWhenThreadPool/cmp/ACmp.java | 24 ++ .../test/customWhenThreadPool/cmp/BCmp.java | 26 +++ .../test/customWhenThreadPool/cmp/CCmp.java | 26 +++ .../test/customWhenThreadPool/cmp/DCmp.java | 26 +++ .../test/customWhenThreadPool/cmp/ECmp.java | 26 +++ .../test/customWhenThreadPool/cmp/FCmp.java | 26 +++ .../exception/ExceptionSpringBootTest.java | 83 +++++++ .../liteflow/test/exception/cmp/ACmp.java | 34 +++ .../liteflow/test/exception/cmp/BCmp.java | 39 ++++ .../liteflow/test/exception/cmp/CCmp.java | 28 +++ .../liteflow/test/exception/cmp/DCmp.java | 31 +++ .../Executor2FutureSpringbootTest.java | 41 ++++ .../test/execute2Future/cmp/ACmp.java | 24 ++ .../test/execute2Future/cmp/BCmp.java | 25 ++ .../test/execute2Future/cmp/CCmp.java | 25 ++ .../test/execute2Future/cmp/DCmp.java | 25 ++ .../test/flowmeta/FlowMetaSpringbootTest.java | 38 +++ .../liteflow/test/flowmeta/cmp1/ACmp.java | 24 ++ .../liteflow/test/flowmeta/cmp1/BCmp.java | 25 ++ .../liteflow/test/flowmeta/cmp1/CCmp.java | 25 ++ .../liteflow/test/flowmeta/cmp2/DCmp.java | 23 ++ .../test/lazy/LazySpringbootTest.java | 33 +++ .../yomahub/liteflow/test/lazy/cmp/ACmp.java | 26 +++ .../yomahub/liteflow/test/lazy/cmp/BCmp.java | 25 ++ .../yomahub/liteflow/test/lazy/cmp/CCmp.java | 25 ++ .../LiteflowComponentSpringbootTest.java | 39 ++++ .../test/liteflowcomponent/cmp/ACmp.java | 24 ++ .../test/liteflowcomponent/cmp/BCmp.java | 25 ++ .../test/liteflowcomponent/cmp/CCmp.java | 25 ++ .../test/liteflowcomponent/cmp/DCmp.java | 25 ++ .../test/monitor/MonitorSpringbootTest.java | 50 ++++ .../liteflow/test/monitor/cmp/ACmp.java | 32 +++ .../liteflow/test/monitor/cmp/BCmp.java | 32 +++ .../liteflow/test/monitor/cmp/CCmp.java | 32 +++ .../LiteflowMultipleTypeSpringbootTest.java | 42 ++++ .../liteflow/test/multipleType/cmp/ACmp.java | 24 ++ .../liteflow/test/multipleType/cmp/BCmp.java | 25 ++ .../liteflow/test/multipleType/cmp/CCmp.java | 25 ++ .../CustomerDefaultNodeExecutor.java | 19 ++ .../nodeExecutor/CustomerNodeExecutor.java | 20 ++ .../CustomerNodeExecutorAndCustomRetry.java | 29 +++ .../LiteflowNodeExecutorSpringbootTest.java | 69 ++++++ .../liteflow/test/nodeExecutor/cmp/ACmp.java | 26 +++ .../liteflow/test/nodeExecutor/cmp/BCmp.java | 31 +++ .../liteflow/test/nodeExecutor/cmp/CCmp.java | 33 +++ .../liteflow/test/nodeExecutor/cmp/DCmp.java | 35 +++ .../CustomParserJsonSpringbootTest.java | 39 ++++ .../CustomParserXmlSpringbootTest.java | 40 ++++ .../test/parsecustom/bean/TestBean.java | 11 + .../liteflow/test/parsecustom/cmp/ACmp.java | 30 +++ .../liteflow/test/parsecustom/cmp/BCmp.java | 25 ++ .../liteflow/test/parsecustom/cmp/CCmp.java | 25 ++ .../liteflow/test/parsecustom/cmp/DCmp.java | 25 ++ .../liteflow/test/parsecustom/cmp/ECmp.java | 25 ++ .../liteflow/test/parsecustom/cmp/FCmp.java | 25 ++ .../liteflow/test/parsecustom/cmp/GCmp.java | 25 ++ .../parser/CustomJsonFlowParser.java | 17 ++ .../parser/CustomXmlFlowParser.java | 23 ++ .../test/parser/JsonParserSpringbootTest.java | 37 +++ .../parser/SpringELSupportSpringbootTest.java | 32 +++ .../test/parser/XmlParserSpringbootTest.java | 37 +++ .../test/parser/YmlParserSpringbootTest.java | 37 +++ .../liteflow/test/parser/cmp/ACmp.java | 24 ++ .../liteflow/test/parser/cmp/BCmp.java | 25 ++ .../liteflow/test/parser/cmp/CCmp.java | 25 ++ .../liteflow/test/parser/cmp/DCmp.java | 25 ++ .../liteflow/test/parser/cmp/ECmp.java | 25 ++ .../liteflow/test/parser/cmp/FCmp.java | 25 ++ .../liteflow/test/parser/cmp/GCmp.java | 25 ++ .../PreAndFinallySpringbootTest.java | 64 ++++++ .../liteflow/test/preAndFinally/cmp/ACmp.java | 24 ++ .../liteflow/test/preAndFinally/cmp/BCmp.java | 25 ++ .../liteflow/test/preAndFinally/cmp/CCmp.java | 25 ++ .../liteflow/test/preAndFinally/cmp/DCmp.java | 26 +++ .../test/preAndFinally/cmp/Finally1Cmp.java | 24 ++ .../test/preAndFinally/cmp/Finally2Cmp.java | 24 ++ .../test/preAndFinally/cmp/Finally3Cmp.java | 32 +++ .../test/preAndFinally/cmp/Pre1Cmp.java | 24 ++ .../test/preAndFinally/cmp/Pre2Cmp.java | 24 ++ .../PrivateDeliverySpringbootTest.java | 41 ++++ .../test/privateDelivery/cmp/ACmp.java | 34 +++ .../test/privateDelivery/cmp/BCmp.java | 30 +++ .../test/privateDelivery/cmp/CCmp.java | 25 ++ .../test/privateDelivery/cmp/DCmp.java | 25 ++ .../RefreshRuleSpringbootTest.java | 70 ++++++ .../liteflow/test/refreshRule/cmp/ACmp.java | 24 ++ .../liteflow/test/refreshRule/cmp/BCmp.java | 25 ++ .../liteflow/test/refreshRule/cmp/CCmp.java | 25 ++ .../test/reload/ReloadSpringbootTest.java | 41 ++++ .../liteflow/test/reload/cmp/ACmp.java | 24 ++ .../liteflow/test/reload/cmp/BCmp.java | 25 ++ .../liteflow/test/reload/cmp/CCmp.java | 25 ++ .../resizeSlot/ResizeSlotSpringbootTest.java | 65 ++++++ .../liteflow/test/resizeSlot/cmp/ACmp.java | 24 ++ .../liteflow/test/resizeSlot/cmp/BCmp.java | 25 ++ .../liteflow/test/resizeSlot/cmp/CCmp.java | 25 ++ .../ImplicitSubFlowSpringbootTest.java | 49 ++++ ...ubflowInDifferentConfigSpringbootTest.java | 54 +++++ .../subflow/SubflowJsonSpringBootTest.java | 40 ++++ .../subflow/SubflowXMLSpringBootTest.java | 40 ++++ .../subflow/SubflowYmlSpringBootTest.java | 40 ++++ .../liteflow/test/subflow/cmp1/ACmp.java | 17 ++ .../liteflow/test/subflow/cmp1/BCmp.java | 17 ++ .../liteflow/test/subflow/cmp1/CCmp.java | 17 ++ .../liteflow/test/subflow/cmp1/DCmp.java | 17 ++ .../liteflow/test/subflow/cmp1/ECmp.java | 18 ++ .../liteflow/test/subflow/cmp2/FCmp.java | 22 ++ .../liteflow/test/subflow/cmp2/GCmp.java | 31 +++ .../liteflow/test/subflow/cmp2/HCmp.java | 22 ++ .../liteflow/test/subflow/cmp2/MCmp.java | 22 ++ .../test/tag/NodeTagSpringbootJsonTest.java | 67 ++++++ .../test/tag/NodeTagSpringbootXmlTest.java | 67 ++++++ .../yomahub/liteflow/test/tag/cmp/ACmp.java | 34 +++ .../yomahub/liteflow/test/tag/cmp/B1Cmp.java | 27 +++ .../yomahub/liteflow/test/tag/cmp/BCmp.java | 28 +++ .../yomahub/liteflow/test/tag/cmp/CCmp.java | 30 +++ .../yomahub/liteflow/test/tag/cmp/DCmp.java | 25 ++ .../yomahub/liteflow/test/tag/cmp/ECmp.java | 25 ++ .../yomahub/liteflow/test/tag/cmp/FCmp.java | 29 +++ .../yomahub/liteflow/test/tag/cmp/GCmp.java | 24 ++ .../liteflow/test/useTTLInWhen/TestTL.java | 16 ++ .../UseTTLInWhenSpringbootTest.java | 42 ++++ .../liteflow/test/useTTLInWhen/cmp/ACmp.java | 26 +++ .../liteflow/test/useTTLInWhen/cmp/BCmp.java | 28 +++ .../liteflow/test/useTTLInWhen/cmp/CCmp.java | 28 +++ .../liteflow/test/useTTLInWhen/cmp/DCmp.java | 28 +++ .../liteflow/test/useTTLInWhen/cmp/ECmp.java | 28 +++ .../liteflow/test/useTTLInWhen/cmp/FCmp.java | 28 +++ .../WhenTimeOutSpringbootTest1.java | 45 ++++ .../WhenTimeOutSpringbootTest2.java | 43 ++++ .../liteflow/test/whenTimeOut/cmp/ACmp.java | 24 ++ .../liteflow/test/whenTimeOut/cmp/BCmp.java | 30 +++ .../liteflow/test/whenTimeOut/cmp/CCmp.java | 30 +++ .../liteflow/test/whenTimeOut/cmp/DCmp.java | 30 +++ .../liteflow/test/whenTimeOut/cmp/ECmp.java | 30 +++ .../liteflow/test/whenTimeOut/cmp/FCmp.java | 30 +++ .../ZkNodeWithJsonSpringbootTest.java | 83 +++++++ .../ZkNodeWithXmlSpringbootTest.java | 83 +++++++ .../ZkNodeWithYmlSpringbootTest.java | 83 +++++++ .../liteflow/test/zookeeper/cmp/ACmp.java | 24 ++ .../liteflow/test/zookeeper/cmp/BCmp.java | 25 ++ .../liteflow/test/zookeeper/cmp/CCmp.java | 25 ++ .../absoluteConfigPath/application.properties | 1 + .../resources/absoluteConfigPath/flow.xml | 7 + .../test/resources/aop/application.properties | 1 + .../src/test/resources/aop/flow.xml | 15 ++ .../asyncNode/application.properties | 1 + .../src/test/resources/asyncNode/flow.xml | 56 +++++ .../resources/base/application.properties | 1 + .../src/test/resources/base/flow.xml | 7 + .../resources/cmpRetry/application.properties | 3 + .../src/test/resources/cmpRetry/flow.xml | 18 ++ .../component/application.properties | 1 + .../src/test/resources/component/flow.xml | 30 +++ .../test/resources/config/aaa/bbb/flow1.xml | 7 + .../src/test/resources/config/aaa/flow0.xml | 6 + .../resources/config/application1.properties | 1 + .../resources/config/application2.properties | 1 + .../src/test/resources/config/flow.yml | 6 + .../customNodes/application.properties | 1 + .../src/test/resources/customNodes/flow.xml | 19 ++ .../application.properties | 1 + .../resources/customWhenThreadPool/flow.xml | 12 + .../deadLoopChain/application.properties | 2 + .../src/test/resources/deadLoopChain/flow.xml | 11 + .../emptyFlow/application.properties | 1 + .../src/test/resources/emptyFlow/flow.xml | 0 .../resources/enable/application.properties | 2 + .../src/test/resources/enable/flow.xml | 6 + .../exception/application.properties | 2 + .../src/test/resources/exception/flow.xml | 17 ++ .../execute2Future/application.properties | 1 + .../test/resources/execute2Future/flow.xml | 8 + .../resources/flowmeta/application.properties | 2 + .../src/test/resources/flowmeta/flow.xml | 6 + .../resources/lazy/application.properties | 1 + .../src/test/resources/lazy/flow.xml | 6 + .../liteflowComponent/application.properties | 1 + .../test/resources/liteflowComponent/flow.xml | 10 + .../resources/monitor/application.properties | 5 + .../src/test/resources/monitor/flow.xml | 8 + .../multipleType/application.properties | 2 + .../src/test/resources/multipleType/flow.xml | 10 + .../src/test/resources/multipleType/flow.yml | 6 + .../nodeExecutor/application.properties | 4 + .../src/test/resources/nodeExecutor/flow.xml | 18 ++ .../nullParam/application.properties | 1 + .../src/test/resources/nullParam/flow.xml | 7 + .../application-custom-json.properties | 1 + .../application-custom-xml.properties | 1 + .../parser/application-json.properties | 1 + .../parser/application-springEL.properties | 1 + .../parser/application-xml.properties | 1 + .../parser/application-yml.properties | 1 + .../src/test/resources/parser/flow.json | 52 +++++ .../src/test/resources/parser/flow.xml | 22 ++ .../src/test/resources/parser/flow.yml | 30 +++ .../parser/subFoder1/subFoder2/flow1.xml | 22 ++ .../parser/subFoder1/subFoder2/flow2.xml | 9 + .../parser/subFoder1/subFoder2/flow3.xml | 6 + .../preAndFinally/application.properties | 1 + .../src/test/resources/preAndFinally/flow.xml | 26 +++ .../privateDelivery/application.properties | 1 + .../test/resources/privateDelivery/flow.xml | 18 ++ .../refreshRule/application.properties | 1 + .../src/test/resources/refreshRule/flow.xml | 6 + .../resources/refreshRule/flow_update.xml | 6 + .../resources/reload/application.properties | 1 + .../src/test/resources/reload/flow.xml | 6 + .../removeChain/application.properties | 1 + .../src/test/resources/removeChain/flow.xml | 11 + .../resizeSlot/application.properties | 2 + .../src/test/resources/resizeSlot/flow.xml | 6 + .../subflow/application-implicit.properties | 1 + .../subflow/application-json.properties | 1 + ...plication-subInDifferentConfig1.properties | 1 + ...plication-subInDifferentConfig2.properties | 1 + .../subflow/application-xml.properties | 1 + .../subflow/application-yml.properties | 1 + .../test/resources/subflow/flow-implicit.xml | 11 + .../src/test/resources/subflow/flow-main.xml | 7 + .../src/test/resources/subflow/flow-sub1.xml | 7 + .../src/test/resources/subflow/flow-sub2.xml | 6 + .../src/test/resources/subflow/flow-sub2.yml | 6 + .../src/test/resources/subflow/flow.json | 33 +++ .../src/test/resources/subflow/flow.xml | 22 ++ .../src/test/resources/subflow/flow.yml | 24 ++ .../resources/tag/application-json.properties | 1 + .../resources/tag/application-xml.properties | 1 + .../src/test/resources/tag/flow.json | 31 +++ .../src/test/resources/tag/flow.xml | 19 ++ .../useTTLInWhen/application.properties | 2 + .../src/test/resources/useTTLInWhen/flow.xml | 7 + .../whenTimeOut/application1.properties | 2 + .../whenTimeOut/application2.properties | 2 + .../src/test/resources/whenTimeOut/flow1.xml | 6 + .../src/test/resources/whenTimeOut/flow2.xml | 8 + .../zookeeper/application-json.properties | 1 + .../zookeeper/application-xml.properties | 1 + .../zookeeper/application-yml.properties | 1 + .../src/test/resources/zookeeper/flow.json | 12 + .../src/test/resources/zookeeper/flow.xml | 6 + .../src/test/resources/zookeeper/flow.yml | 6 + .../LiteflowMultipleTypeTest.java | 2 +- .../LiteflowMultipleTypeSpringbootTest.java | 2 +- .../LiteflowMultipleTypeSpringTest.java | 2 +- pom.xml | 9 +- 339 files changed, 8359 insertions(+), 16 deletions(-) create mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowCmpDefine.java create mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowCondCmpDefine.java create mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowMethod.java create mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java create mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/LiteFlowMethodBean.java create mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/enums/LiteFlowMethodEnum.java create mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentMethodDefineErrorException.java create mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentProxyErrorException.java create mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteFlowProxyUtil.java create mode 100644 liteflow-core/src/main/java/com/yomahub/liteflow/util/SerialsUtil.java create mode 100644 liteflow-testcase-declare-component/pom.xml create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/BaseTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/CustomAOPSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpAspect.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/DCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/ECmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/FCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/BaseSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/DCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/TestDomain.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/BuilderSpringbootTest1.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/BuilderSpringbootTest2.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/DCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ECmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/FCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/GCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/HCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/ICmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/JCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetrySpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp2/FCondCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/DCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ECmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/FCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/DCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ECmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/FCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/ExceptionSpringBootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/DCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/FlowMetaSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp2/DCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/LazySpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/LiteflowComponentSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/DCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/MonitorSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/DCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/FCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/GCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/JsonParserSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/XmlParserSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/YmlParserSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/DCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/FCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/GCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallySpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliverySpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/DCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/ReloadSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/ResizeSlotSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonSpringBootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLSpringBootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlSpringBootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/NodeTagSpringbootJsonTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/NodeTagSpringbootXmlTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest1.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest2.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithJsonSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithYmlSpringbootTest.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/ACmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/BCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/CCmp.java create mode 100644 liteflow-testcase-declare-component/src/test/resources/absoluteConfigPath/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/absoluteConfigPath/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/aop/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/aop/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/asyncNode/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/asyncNode/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/base/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/base/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/cmpRetry/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/cmpRetry/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/component/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/component/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/config/aaa/bbb/flow1.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/config/aaa/flow0.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/config/application1.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/config/application2.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/config/flow.yml create mode 100644 liteflow-testcase-declare-component/src/test/resources/customNodes/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/customNodes/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/customWhenThreadPool/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/customWhenThreadPool/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/deadLoopChain/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/deadLoopChain/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/emptyFlow/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/emptyFlow/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/enable/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/enable/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/exception/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/exception/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/execute2Future/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/execute2Future/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/flowmeta/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/flowmeta/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/lazy/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/lazy/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/liteflowComponent/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/liteflowComponent/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/monitor/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/monitor/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/multipleType/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/multipleType/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/multipleType/flow.yml create mode 100644 liteflow-testcase-declare-component/src/test/resources/nodeExecutor/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/nodeExecutor/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/nullParam/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/nullParam/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/parsecustom/application-custom-json.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/parsecustom/application-custom-xml.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/parser/application-json.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/parser/application-springEL.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/parser/application-xml.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/parser/application-yml.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/parser/flow.json create mode 100644 liteflow-testcase-declare-component/src/test/resources/parser/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/parser/flow.yml create mode 100644 liteflow-testcase-declare-component/src/test/resources/parser/subFoder1/subFoder2/flow1.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/parser/subFoder1/subFoder2/flow2.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/parser/subFoder1/subFoder2/flow3.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/preAndFinally/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/preAndFinally/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/privateDelivery/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/privateDelivery/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/refreshRule/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/refreshRule/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/refreshRule/flow_update.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/reload/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/reload/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/removeChain/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/removeChain/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/resizeSlot/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/resizeSlot/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/subflow/application-implicit.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/subflow/application-json.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/subflow/application-subInDifferentConfig1.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/subflow/application-subInDifferentConfig2.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/subflow/application-xml.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/subflow/application-yml.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/subflow/flow-implicit.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/subflow/flow-main.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/subflow/flow-sub1.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/subflow/flow-sub2.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/subflow/flow-sub2.yml create mode 100644 liteflow-testcase-declare-component/src/test/resources/subflow/flow.json create mode 100644 liteflow-testcase-declare-component/src/test/resources/subflow/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/subflow/flow.yml create mode 100644 liteflow-testcase-declare-component/src/test/resources/tag/application-json.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/tag/application-xml.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/tag/flow.json create mode 100644 liteflow-testcase-declare-component/src/test/resources/tag/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/useTTLInWhen/application.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/useTTLInWhen/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/whenTimeOut/application1.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/whenTimeOut/application2.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/whenTimeOut/flow1.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/whenTimeOut/flow2.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/zookeeper/application-json.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/zookeeper/application-xml.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/zookeeper/application-yml.properties create mode 100644 liteflow-testcase-declare-component/src/test/resources/zookeeper/flow.json create mode 100644 liteflow-testcase-declare-component/src/test/resources/zookeeper/flow.xml create mode 100644 liteflow-testcase-declare-component/src/test/resources/zookeeper/flow.yml diff --git a/liteflow-core/pom.xml b/liteflow-core/pom.xml index fb2664fdc..0c9c917ed 100644 --- a/liteflow-core/pom.xml +++ b/liteflow-core/pom.xml @@ -61,5 +61,9 @@ com.alibaba transmittable-thread-local + + net.bytebuddy + byte-buddy + diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowCmpDefine.java b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowCmpDefine.java new file mode 100644 index 000000000..bbddb6cbe --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowCmpDefine.java @@ -0,0 +1,10 @@ +package com.yomahub.liteflow.annotation; + +import java.lang.annotation.*; + +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface LiteflowCmpDefine { +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowCondCmpDefine.java b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowCondCmpDefine.java new file mode 100644 index 000000000..7700ee387 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowCondCmpDefine.java @@ -0,0 +1,10 @@ +package com.yomahub.liteflow.annotation; + +import java.lang.annotation.*; + +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface LiteflowCondCmpDefine { +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowMethod.java b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowMethod.java new file mode 100644 index 000000000..c43b60df8 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/LiteflowMethod.java @@ -0,0 +1,14 @@ +package com.yomahub.liteflow.annotation; + +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +import java.lang.annotation.*; + +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface LiteflowMethod { + + LiteFlowMethodEnum value(); +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/util/AnnoUtil.java b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/util/AnnoUtil.java index a7af0f06d..47460d351 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/util/AnnoUtil.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/annotation/util/AnnoUtil.java @@ -4,6 +4,7 @@ import cn.hutool.core.annotation.AnnotationUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ReflectUtil; import com.yomahub.liteflow.annotation.AliasFor; +import com.yomahub.liteflow.util.LiteFlowProxyUtil; import java.lang.annotation.Annotation; import java.lang.reflect.AnnotatedElement; diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/LiteFlowNodeBuilder.java b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/LiteFlowNodeBuilder.java index b580d9950..4deb8a6c2 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/builder/LiteFlowNodeBuilder.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/builder/LiteFlowNodeBuilder.java @@ -64,6 +64,12 @@ public class LiteFlowNodeBuilder { return this; } + public LiteFlowNodeBuilder setClazz(Class clazz){ + assert clazz != null; + setClazz(clazz.getName()); + return this; + } + // 设置节点组件的class public LiteFlowNodeBuilder setNodeComponentClazz(Class nodeComponentClass) { assert nodeComponentClass != null; diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java index 11138a0e1..da45ee8a5 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java @@ -35,7 +35,7 @@ import java.util.Map; */ public abstract class NodeComponent{ - private static final Logger LOG = LoggerFactory.getLogger(NodeComponent.class); + private final Logger LOG = LoggerFactory.getLogger(this.getClass()); private final TransmittableThreadLocal slotIndexTL = new TransmittableThreadLocal<>(); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java new file mode 100644 index 000000000..515b222e0 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java @@ -0,0 +1,129 @@ +package com.yomahub.liteflow.core.proxy; + +import cn.hutool.core.util.*; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.exception.ComponentMethodDefineErrorException; +import com.yomahub.liteflow.util.LiteFlowProxyUtil; +import com.yomahub.liteflow.util.SerialsUtil; +import net.bytebuddy.ByteBuddy; +import net.bytebuddy.implementation.InvocationHandlerAdapter; +import net.bytebuddy.matcher.ElementMatchers; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * 声明式组件的代理核心生成类 + * @author Bryan.Zhang + * @since 2.6.14 + */ +public class ComponentProxy { + + private final Logger LOG = LoggerFactory.getLogger(this.getClass()); + + private final String nodeId; + + private final Object bean; + + private final Class clazz; + + public ComponentProxy(String nodeId, Object bean, Class clazz) { + this.nodeId = nodeId; + this.bean = bean; + this.clazz = clazz; + } + + public Object getProxy() throws Exception{ + //这里要判断bean是否是spring代理过的bean,如果是代理过的bean需要取到原class对象 + Class beanClazz; + if (LiteFlowProxyUtil.isCglibProxyClass(bean.getClass())){ + beanClazz = LiteFlowProxyUtil.getUserClass(bean.getClass()); + }else{ + beanClazz = bean.getClass(); + } + + //得到当前bean里所覆盖的组件方法(一定是被@LiteFlowMethod修饰的),自己定义的不算 + List methodStrList = Arrays.stream(beanClazz.getDeclaredMethods()).filter( + m -> m.getAnnotation(LiteflowMethod.class) != null + ).map(m -> { + LiteflowMethod liteflowMethod = m.getAnnotation(LiteflowMethod.class); + return liteflowMethod.value().getMethodName(); + }).collect(Collectors.toList()); + + //创建对象 + //这里package进行了重设,放到了被代理对象的所在目录 + //生成的对象也加了上被代理对象拥有的注解 + //被拦截的对象也根据被代理对象根据@LiteFlowMethod所标注的进行了动态判断 + return new ByteBuddy().subclass(clazz) + .name(StrUtil.format("{}.ByteBuddy${}${}", + ClassUtil.getPackage(bean.getClass()), + nodeId, + SerialsUtil.generateShortUUID())) + .method(ElementMatchers.namedOneOf(methodStrList.toArray(new String[]{}))) + .intercept(InvocationHandlerAdapter.of(new AopInvocationHandler(bean))) + .annotateType(bean.getClass().getAnnotations()) + .make() + .load(ComponentProxy.class.getClassLoader()) + .getLoaded() + .newInstance(); + } + + public class AopInvocationHandler implements InvocationHandler { + + private final Object bean; + + public AopInvocationHandler(Object bean) { + this.bean = bean; + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + //这里做了2件事情 + //先是从普通的bean里过滤出含有@LiteFlowMethod这个标注的方法 + //然后进行转换成LiteFlowMethodBean对象List,形成键值对的对象 + List liteFlowMethodBeanList = Arrays.stream(ReflectUtil.getMethods(bean.getClass())).filter(m -> { + LiteflowMethod liteFlowMethod = m.getAnnotation(LiteflowMethod.class); + return ObjectUtil.isNotNull(liteFlowMethod); + }).map(m -> { + LiteflowMethod liteFlowMethod = m.getAnnotation(LiteflowMethod.class); + return new LiteFlowMethodBean(liteFlowMethod.value().getMethodName(), m); + }).collect(Collectors.toList()); + + //获取当前调用方法,是否在被代理的对象方法里面(根据@LiteFlowMethod这个标注去判断) + //如果在里面,则返回那个LiteFlowMethodBean,不在则返回null + LiteFlowMethodBean liteFlowMethodBean = liteFlowMethodBeanList.stream().filter( + liteFlowMethodBean1 -> liteFlowMethodBean1.getMethod().getName().equals(method.getName()) + ).findFirst().orElse(null); + + //如果被代理的对象里有此标注标的方法,则调用此被代理的对象里的方法,如果没有,则调用父类里的方法 + if (liteFlowMethodBean != null){ + //进行检查,检查被代理的bean里是否有且仅有NodeComponent这个类型的参数 + boolean checkFlag = liteFlowMethodBean.getMethod().getParameterTypes().length == 1 + && Arrays.asList(liteFlowMethodBean.getMethod().getParameterTypes()).contains(NodeComponent.class); + if (!checkFlag){ + String errMsg = StrUtil.format("Method[{}.{}] must have NodeComponent parameter(and only one parameter)", bean.getClass().getName(), liteFlowMethodBean.getMethod().getName()); + LOG.error(errMsg); + throw new ComponentMethodDefineErrorException(errMsg); + } + + try{ + return liteFlowMethodBean.getMethod().invoke(bean, proxy); + }catch (Exception e){ + InvocationTargetException targetEx = (InvocationTargetException)e; + throw targetEx.getTargetException(); + } + }else{ + //理论上来说这句应该执行不到,因为前面在设置拦截对象类型的时候,已经根据当前bean所覆盖的方法进行了动态判断 + return method.invoke(proxy, args); + } + } + } +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/LiteFlowMethodBean.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/LiteFlowMethodBean.java new file mode 100644 index 000000000..3da3caf44 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/LiteFlowMethodBean.java @@ -0,0 +1,31 @@ +package com.yomahub.liteflow.core.proxy; + +import java.lang.reflect.Method; + +public class LiteFlowMethodBean { + + private String methodName; + + private Method method; + + public LiteFlowMethodBean(String methodName, Method method) { + this.methodName = methodName; + this.method = method; + } + + public String getMethodName() { + return methodName; + } + + public void setMethodName(String methodName) { + this.methodName = methodName; + } + + public Method getMethod() { + return method; + } + + public void setMethod(Method method) { + this.method = method; + } +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/enums/LiteFlowMethodEnum.java b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/LiteFlowMethodEnum.java new file mode 100644 index 000000000..ec4c6ef21 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/enums/LiteFlowMethodEnum.java @@ -0,0 +1,26 @@ +package com.yomahub.liteflow.enums; + +public enum LiteFlowMethodEnum { + PROCESS("process"), + PROCESS_COND("processCond"), + IS_ACCESS("isAccess"), + + IS_END("isEnd"), + IS_CONTINUE_ON_ERROR("isContinueOnError"), + + GET_NODE_EXECUTOR_CLASS("getNodeExecutorClass"); + + private String methodName; + + LiteFlowMethodEnum(String methodName){ + this.methodName = methodName; + } + + public String getMethodName() { + return methodName; + } + + public void setMethodName(String methodName) { + this.methodName = methodName; + } +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentMethodDefineErrorException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentMethodDefineErrorException.java new file mode 100644 index 000000000..9e8beb8ac --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentMethodDefineErrorException.java @@ -0,0 +1,22 @@ + +package com.yomahub.liteflow.exception; + +public class ComponentMethodDefineErrorException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + /** 异常信息 */ + private String message; + + public ComponentMethodDefineErrorException(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentProxyErrorException.java b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentProxyErrorException.java new file mode 100644 index 000000000..4b04c29b3 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/exception/ComponentProxyErrorException.java @@ -0,0 +1,22 @@ + +package com.yomahub.liteflow.exception; + +public class ComponentProxyErrorException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + /** 异常信息 */ + private String message; + + public ComponentProxyErrorException(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java index 99b1a4d99..7caac00b2 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/flow/FlowBus.java @@ -28,8 +28,11 @@ import com.yomahub.liteflow.parser.LocalYmlFlowParser; import com.yomahub.liteflow.script.ScriptExecutor; import com.yomahub.liteflow.script.ScriptExecutorFactory; import com.yomahub.liteflow.script.exception.ScriptSpiException; +import com.yomahub.liteflow.spi.ContextAware; import com.yomahub.liteflow.spi.holder.ContextAwareHolder; +import com.yomahub.liteflow.spi.local.LocalContextAware; import com.yomahub.liteflow.util.CopyOnWriteHashMap; +import com.yomahub.liteflow.util.LiteFlowProxyUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -82,8 +85,13 @@ public class FlowBus { nodeMap.put(nodeId, new Node(ComponentInitializer.loadInstance().initComponent(nodeComponent, NodeTypeEnum.COMMON, null, nodeId))); } - public static void addCommonNode(String nodeId, String name, String cmpClazzStr) throws Exception { - Class cmpClazz = (Class) Class.forName(cmpClazzStr); + public static void addCommonNode(String nodeId, String name, String cmpClazzStr){ + Class cmpClazz; + try{ + cmpClazz = Class.forName(cmpClazzStr); + }catch (Exception e){ + throw new ComponentCannotRegisterException(e.getMessage()); + } addNode(nodeId, name, NodeTypeEnum.COMMON, cmpClazz, null); } @@ -99,18 +107,36 @@ public class FlowBus { addNode(nodeId, name, NodeTypeEnum.COND_SCRIPT, ScriptCondComponent.class, script); } - private static void addNode(String nodeId, String name, NodeTypeEnum type, Class cmpClazz, String script) { + private static void addNode(String nodeId, String name, NodeTypeEnum type, Class cmpClazz, String script) { try { - //以node方式配置,本质上是为了适配无spring的环境,如果有spring环境,其实不用这么配置 - //这里的逻辑是判断是否能从spring上下文中取到,如果没有spring,则就是new instance了 - //如果是script类型的节点,因为class只有一个,所以也不能注册进spring上下文,注册的时候需要new Instance + //判断此类是否是声明式的组件,如果是声明式的组件,就用动态代理生成实例 + //如果不是声明式的,就用传统的方式进行判断 NodeComponent cmpInstance = null; - if (!CollectionUtil.newArrayList(NodeTypeEnum.SCRIPT, NodeTypeEnum.COND_SCRIPT).contains(type)){ - cmpInstance = ContextAwareHolder.loadContextAware().registerOrGet(nodeId, cmpClazz); - } + if (LiteFlowProxyUtil.isMarkedCmp(cmpClazz)){ + //这里的逻辑要仔细看下 + //如果是spring体系,把原始的类往spring上下文中进行注册,那么会走到ComponentScanner中 + //由于ComponentScanner中已经对原始类进行了动态代理,出来的对象已经变成了动态代理类,所以这时候的bean已经是NodeComponent的子类了 + //所以spring体系下,无需再对这个bean做二次代理 + //但是在非spring体系下,这个bean依旧是原来那个bean,所以需要对这个bean做一次代理 + //这里用ContextAware的spi机制来判断是否spring体系 + ContextAware contextAware = ContextAwareHolder.loadContextAware(); + Object bean = ContextAwareHolder.loadContextAware().registerBean(nodeId, cmpClazz); + if (LocalContextAware.class.isAssignableFrom(contextAware.getClass())){ + cmpInstance = LiteFlowProxyUtil.proxy2NodeComponent(bean, nodeId); + }else { + cmpInstance = (NodeComponent) bean; + } + }else{ + //以node方式配置,本质上是为了适配无spring的环境,如果有spring环境,其实不用这么配置 + //这里的逻辑是判断是否能从spring上下文中取到,如果没有spring,则就是new instance了 + //如果是script类型的节点,因为class只有一个,所以也不能注册进spring上下文,注册的时候需要new Instance + if (!CollectionUtil.newArrayList(NodeTypeEnum.SCRIPT, NodeTypeEnum.COND_SCRIPT).contains(type)){ + cmpInstance = (NodeComponent) ContextAwareHolder.loadContextAware().registerOrGet(nodeId, cmpClazz); + } - if (ObjectUtil.isNull(cmpInstance)) { - cmpInstance = cmpClazz.newInstance(); + if (ObjectUtil.isNull(cmpInstance)) { + cmpInstance = (NodeComponent) cmpClazz.newInstance(); + } } //进行初始化 diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/ContextAware.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/ContextAware.java index d313f8575..b6b60aaf9 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/ContextAware.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/ContextAware.java @@ -16,5 +16,7 @@ public interface ContextAware extends SpiPriority { T registerBean(Class clazz); + T registerBean(String beanName, Object bean); + T registerOrGet(String beanName, Class clazz); } diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalContextAware.java b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalContextAware.java index 8734b270c..54cf12f81 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalContextAware.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/spi/local/LocalContextAware.java @@ -30,6 +30,11 @@ public class LocalContextAware implements ContextAware { return registerBean(null, clazz); } + @Override + public T registerBean(String beanName, Object bean) { + return (T)bean; + } + @Override public T registerOrGet(String beanName, Class clazz) { return registerBean(beanName, clazz); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteFlowProxyUtil.java b/liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteFlowProxyUtil.java new file mode 100644 index 000000000..4478a6913 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/util/LiteFlowProxyUtil.java @@ -0,0 +1,102 @@ +package com.yomahub.liteflow.util; + +import cn.hutool.core.collection.ListUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowCondCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.core.NodeCondComponent; +import com.yomahub.liteflow.core.proxy.ComponentProxy; +import com.yomahub.liteflow.exception.ComponentProxyErrorException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Arrays; + +/** + * 组件代理类通用方法 + * 主要用于声明式组件 + * @author Bryan.Zhang + * @since 2.6.14 + */ +public class LiteFlowProxyUtil { + + private static final Logger LOG = LoggerFactory.getLogger(LiteFlowProxyUtil.class); + + //判断一个bean是否是解耦式组件 + public static boolean isMarkedCmp(Class clazz){ + //判断bean是否标记了@LiteflowCmpDefine或者@LiteflowCondCmpDefine这2个标注之一 + boolean flag1 = clazz.getAnnotation(LiteflowCmpDefine.class) != null + || clazz.getAnnotation(LiteflowCondCmpDefine.class) != null; + + if (!flag1){ + return false; + } + + //看超类是否是NodeComponent和NodeCondComponent中的一个,如果不是,则说明满足条件。是的话,也不满足 + boolean flag2 = !ListUtil.toList(NodeComponent.class, NodeCondComponent.class).contains(clazz.getSuperclass()); + + if (!flag2){ + return false; + } + + //查看bean里的method是否有方法标记了@LiteflowMethod标注 + //这里的bean有可能是cglib加强过的class,所以要先进行个判断 + Class targetClass; + if (isCglibProxyClass(clazz)){ + targetClass = getUserClass(clazz); + }else{ + targetClass = clazz; + } + boolean flag3 = Arrays.stream(targetClass.getMethods()).anyMatch( + method -> method.getAnnotation(LiteflowMethod.class) != null + ); + + return flag3; + } + + //对一个满足声明式的bean进行代理 + public static NodeComponent proxy2NodeComponent(Object bean, String nodeId){ + try{ + LiteflowCmpDefine liteflowCmpDefine = bean.getClass().getAnnotation(LiteflowCmpDefine.class); + LiteflowCondCmpDefine liteflowCondCmpDefine = bean.getClass().getAnnotation(LiteflowCondCmpDefine.class); + + ComponentProxy proxy; + if (ObjectUtil.isNotNull(liteflowCmpDefine)){ + proxy = new ComponentProxy(nodeId, bean, NodeComponent.class); + return (NodeComponent) proxy.getProxy(); + } + + if (ObjectUtil.isNotNull(liteflowCondCmpDefine)){ + proxy = new ComponentProxy(nodeId, bean, NodeCondComponent.class); + return (NodeCondComponent) proxy.getProxy(); + } + + throw new RuntimeException(); + }catch (Exception e){ + String errMsg = StrUtil.format("Error while proxying bean[{}]",bean.getClass().getName()); + LOG.error(errMsg, e); + throw new ComponentProxyErrorException(errMsg); + } + } + + public static boolean isCglibProxyClass(Class clazz) { + return (clazz != null && isCglibProxyClassName(clazz.getName())); + } + + public static Class getUserClass(Class clazz) { + if (clazz.getName().contains("$$")) { + Class superclass = clazz.getSuperclass(); + if (superclass != null && superclass != Object.class) { + return superclass; + } + } + return clazz; + } + + private static boolean isCglibProxyClassName(String className) { + return (className != null && className.contains("$$")); + } +} diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/util/SerialsUtil.java b/liteflow-core/src/main/java/com/yomahub/liteflow/util/SerialsUtil.java new file mode 100644 index 000000000..ac7abb6a1 --- /dev/null +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/util/SerialsUtil.java @@ -0,0 +1,192 @@ +package com.yomahub.liteflow.util; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.*; + +public class SerialsUtil { + + public static int serialInt = 1; + + private static final DecimalFormat format8 = new DecimalFormat("00000000"); + private static final DecimalFormat format12 = new DecimalFormat("000000000000"); + private static final BigInteger divisor; + private static final BigInteger divisor12; + + static { + divisor = BigInteger.valueOf(19999999L).multiply(BigInteger.valueOf(5)); + divisor12 = BigInteger.valueOf(190000000097L).multiply(BigInteger.valueOf(5)); + } + + public static String genSerialNo(){ + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); + String strNow = sdf.format(new Date()); + + // 生成3位随机数 + Random random = new Random(); + int intRandom = random.nextInt(999); + + String strRandom = String.valueOf(intRandom); + int len = strRandom.length(); + for (int i = 0; i < (3-len); i++) { + strRandom = "0" + strRandom; + } + String serialStr = SerialsUtil.nextSerial(); + return (strNow + strRandom + serialStr) ; + } + + public static synchronized String nextSerial(){ + int serial = serialInt++; + if (serial > 999){ + serialInt = 1; + serial=1; + } + String serialStr = serial + ""; + int len = serialStr.length(); + for (int i = 0; i < (3-len); i++) { + serialStr = "0" + serialStr; + } + + return serialStr; + } + + + /** + * 生成一个12位随机数 + * + * @param seed 种子 + * @return + */ + public static String randomNum12(long seed) { + // 被除数 + BigInteger dividend = BigDecimal.valueOf(seed).pow(5).toBigInteger(); + return format12.format(dividend.remainder(divisor12)); + } + + /** + * 生成一个8位随机数 + * + * @param seed 种子 + * @return + */ + public static String randomNum8(long seed) { + // 被除数 + BigInteger dividend = BigDecimal.valueOf(seed).pow(5).toBigInteger(); + return format8.format(dividend.remainder(divisor)); + } + + /* + * 10进制转32进制(去除0,O,1,I) + */ + public static String from10To32(String numStr, int size){ + long to=32; + long num = Long.parseLong(numStr); + String jg=""; + while(num!=0){ + switch (new Long(num%to).intValue()) { + case 0:jg="B"+jg;break; case 1:jg="R"+jg;break; case 2:jg="6"+jg;break; case 3:jg="U"+jg;break; + case 4:jg="M"+jg;break; case 5:jg="E"+jg;break; case 6:jg="H"+jg;break; case 7:jg="C"+jg;break; + case 8:jg="G"+jg;break; case 9:jg="Q"+jg;break; case 10:jg="A"+jg;break; case 11:jg="8"+jg;break; + case 12:jg="3"+jg;break; case 13:jg="S"+jg;break; case 14:jg="J"+jg;break; case 15:jg="Y"+jg;break; + case 16:jg="7"+jg;break; case 17:jg="5"+jg;break; case 18:jg="W"+jg;break; case 19:jg="9"+jg;break; + case 20:jg="F"+jg;break; case 21:jg="T"+jg;break; case 22:jg="D"+jg;break; case 23:jg="2"+jg;break; + case 24:jg="P"+jg;break; case 25:jg="Z"+jg;break; case 26:jg="N"+jg;break; case 27:jg="K"+jg;break; + case 28:jg="V"+jg;break; case 29:jg="X"+jg;break; case 30:jg="L"+jg;break; case 31:jg="4"+jg;break; + default: jg=String.valueOf(num%to)+jg;break; + } + num=num/to; + } + if (jg.length() < size){ + int loop = size - jg.length(); + for (int i = 0; i < loop; i++){ + jg = "2" + jg; + } + } + return jg; + } + + /* + * 10进制转32进制(去除0,O,1,I) + */ + public static String from10To24(String numStr, int size){ + long to=24; + long num = Long.parseLong(numStr); + String jg=""; + while(num!=0){ + switch (new Long(num%to).intValue()) { + case 0:jg="B"+jg;break; + case 1:jg="R"+jg;break; + case 2:jg="U"+jg;break; + case 3:jg="M"+jg;break; + case 4:jg="E"+jg;break; + case 5:jg="H"+jg;break; + case 6:jg="C"+jg;break; + case 7:jg="G"+jg;break; + case 8:jg="Q"+jg;break; + case 9:jg="A"+jg;break; + case 10:jg="S"+jg;break; + case 11:jg="J"+jg;break; + case 12:jg="Y"+jg;break; + case 13:jg="W"+jg;break; + case 14:jg="F"+jg;break; + case 15:jg="T"+jg;break; + case 16:jg="D"+jg;break; + case 17:jg="P"+jg;break; + case 18:jg="Z"+jg;break; + case 19:jg="N"+jg;break; + case 20:jg="K"+jg;break; + case 21:jg="V"+jg;break; + case 22:jg="X"+jg;break; + case 23:jg="L"+jg;break; + default: jg=String.valueOf(num%to)+jg;break; + } + num=num/to; + } + if (jg.length() < size){ + int loop = size - jg.length(); + for (int i = 0; i < loop; i++){ + jg = "B" + jg; + } + } + return jg; + } + + /** + * 32位 + * @return + */ + public static String getUUID() { + UUID uuid = UUID.randomUUID(); + String str = uuid.toString(); + // 去掉"-"符号 + String temp = str.substring(0, 8) + str.substring(9, 13) + str.substring(14, 18) + str.substring(19, 23) + str.substring(24); + return temp; + } + + public static String generateShortUUID() { + String str = randomNum8(System.nanoTime()); + return from10To24(str, 6); + } + + public static String generateFileUUID() { + String str = randomNum12(System.nanoTime()); + return from10To32(str, 8); + } + + public static String genToken(){ + return from10To32(randomNum12(System.currentTimeMillis()),8) + from10To32(randomNum12(System.nanoTime()),8); + } + + public static void main(String[] args) { + Set set = new HashSet(); + String str; + for (int i = 0; i < 300; i++) { + str = generateShortUUID(); + System.out.println(str); + set.add(str); + } + System.out.println(set.size()); + } +} \ No newline at end of file diff --git a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringAware.java b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringAware.java index e3f5e9043..0634c1135 100644 --- a/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringAware.java +++ b/liteflow-spring/src/main/java/com/yomahub/liteflow/spi/spring/SpringAware.java @@ -4,11 +4,13 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ReflectUtil; import com.yomahub.liteflow.spi.ContextAware; import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.GenericBeanDefinition; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; +import org.springframework.context.ConfigurableApplicationContext; /** * 基于代码形式的spring上下文工具类 @@ -64,6 +66,14 @@ public class SpringAware implements ApplicationContextAware, ContextAware { return registerBean(c.getName(), c); } + @Override + public T registerBean(String beanName, Object bean) { + ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) applicationContext; + DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) configurableApplicationContext.getAutowireCapableBeanFactory(); + defaultListableBeanFactory.registerSingleton(beanName,bean); + return (T) configurableApplicationContext.getBean(beanName); + } + public T registerOrGet(String beanName, Class clazz) { if (ObjectUtil.isNull(applicationContext)){ return null; diff --git a/liteflow-spring/src/main/java/com/yomahub/liteflow/spring/ComponentScanner.java b/liteflow-spring/src/main/java/com/yomahub/liteflow/spring/ComponentScanner.java index c932bcd80..25439090c 100644 --- a/liteflow-spring/src/main/java/com/yomahub/liteflow/spring/ComponentScanner.java +++ b/liteflow-spring/src/main/java/com/yomahub/liteflow/spring/ComponentScanner.java @@ -12,6 +12,7 @@ import com.yomahub.liteflow.aop.ICmpAroundAspect; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.property.LiteflowConfig; import com.yomahub.liteflow.util.LOGOPrinter; +import com.yomahub.liteflow.util.LiteFlowProxyUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeansException; @@ -55,17 +56,29 @@ public class ComponentScanner implements BeanPostProcessor { @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { Class clazz = bean.getClass(); + + //判断是不是声明式组件 + //如果是,就缓存到类属性的map中 + if (LiteFlowProxyUtil.isMarkedCmp(bean.getClass())){ + LOG.info("proxy component[{}] has been found", beanName); + NodeComponent nodeComponent = LiteFlowProxyUtil.proxy2NodeComponent(bean, beanName); + nodeComponentMap.put(beanName, nodeComponent); + return nodeComponent; + } + // 组件的扫描发现,扫到之后缓存到类属性map中 if (NodeComponent.class.isAssignableFrom(clazz)) { LOG.info("component[{}] has been found", beanName); NodeComponent nodeComponent = (NodeComponent) bean; nodeComponentMap.put(beanName, nodeComponent); + return nodeComponent; } // 组件Aop的实现类加载 if (ICmpAroundAspect.class.isAssignableFrom(clazz)) { LOG.info("component aspect implement[{}] has been found", beanName); cmpAroundAspect = (ICmpAroundAspect) bean; + return cmpAroundAspect; } return bean; diff --git a/liteflow-testcase-declare-component/pom.xml b/liteflow-testcase-declare-component/pom.xml new file mode 100644 index 000000000..e0f7c22cf --- /dev/null +++ b/liteflow-testcase-declare-component/pom.xml @@ -0,0 +1,69 @@ + + + + liteflow + com.yomahub + 2.6.14 + + 4.0.0 + + liteflow-testcase-declare-component + + + + com.yomahub + liteflow-spring-boot-starter + ${project.version} + + + + org.springframework.boot + spring-boot-starter-test + ${springboot.version} + test + + + org.aspectj + aspectjweaver + 1.8.13 + test + + + org.apache.curator + curator-test + test + + + com.101tec + zkclient + test + + + com.yomahub + liteflow-script-qlexpress + ${project.version} + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${springboot.version} + + + org.apache.maven.plugins + maven-deploy-plugin + 2.8.2 + + true + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/BaseTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/BaseTest.java new file mode 100644 index 000000000..64886670f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/BaseTest.java @@ -0,0 +1,20 @@ +package com.yomahub.liteflow.test; + +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.spi.holder.SpiFactoryCleaner; +import com.yomahub.liteflow.spring.ComponentScanner; +import com.yomahub.liteflow.thread.ExecutorHelper; +import org.junit.AfterClass; + +public class BaseTest { + + @AfterClass + public static void cleanScanCache(){ + ComponentScanner.cleanCache(); + FlowBus.cleanCache(); + ExecutorHelper.loadInstance().clearExecutorServiceMap(); + SpiFactoryCleaner.clean(); + LiteflowConfigGetter.clean(); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathSpringbootTest.java new file mode 100644 index 000000000..09b6de2a0 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/AbsoluteConfigPathSpringbootTest.java @@ -0,0 +1,42 @@ +package com.yomahub.liteflow.test.absoluteConfigPath; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境下异步线程超时日志打印测试 + * @author Bryan.Zhang + * @since 2.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/absoluteConfigPath/application.properties") +@SpringBootTest(classes = AbsoluteConfigPathSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.absoluteConfigPath.cmp"}) +public class AbsoluteConfigPathSpringbootTest extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testAbsoluteConfig() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java new file mode 100644 index 000000000..f2370fa61 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.absoluteConfigPath.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/BCmp.java new file mode 100644 index 000000000..e83723bdb --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.absoluteConfigPath.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/CCmp.java new file mode 100644 index 000000000..17a096598 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/absoluteConfigPath/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.absoluteConfigPath.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/CustomAOPSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/CustomAOPSpringbootTest.java new file mode 100644 index 000000000..41c08bcee --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/CustomAOPSpringbootTest.java @@ -0,0 +1,56 @@ +package com.yomahub.liteflow.test.aop; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import com.yomahub.liteflow.test.aop.aspect.CustomAspect; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * 切面场景单元测试 + * 在声明式组件场景中,自定义aspect的aop不生效的,因为生成的代理类并不是原类,也不是原类的子类,而是NodeComponent的子类 + * 所以切不到,暂且没有想出办法来解决,这个测试类暂时不用 + * @author Bryan.Zhang + */ +/*@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/aop/application.properties") +@SpringBootTest(classes = CustomAOPSpringbootTest.class) +@EnableAutoConfiguration +@Import(CustomAspect.class) +@ComponentScan({"com.yomahub.liteflow.test.aop.cmp1","com.yomahub.liteflow.test.aop.cmp2"})*/ +public class CustomAOPSpringbootTest extends BaseTest { + + /*@Resource + private FlowExecutor flowExecutor; + + //测试自定义AOP,串行场景 + @Test + public void testCustomAopS() { + LiteflowResponse response= flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("before_after", response.getSlot().getData("a")); + Assert.assertEquals("before_after", response.getSlot().getData("b")); + Assert.assertEquals("before_after", response.getSlot().getData("c")); + } + + //测试自定义AOP,并行场景 + @Test + public void testCustomAopP() { + LiteflowResponse response= flowExecutor.execute2Resp("chain2", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("before_after", response.getSlot().getData("a")); + Assert.assertEquals("before_after", response.getSlot().getData("b")); + Assert.assertEquals("before_after", response.getSlot().getData("c")); + }*/ +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPSpringbootTest.java new file mode 100644 index 000000000..43f0f5bd1 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/GlobalAOPSpringbootTest.java @@ -0,0 +1,76 @@ +package com.yomahub.liteflow.test.aop; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.spring.ComponentScanner; +import com.yomahub.liteflow.test.BaseTest; +import com.yomahub.liteflow.test.aop.aspect.CmpAspect; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * 切面场景单元测试 + * @author Bryan.Zhang + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/aop/application.properties") +@SpringBootTest(classes = GlobalAOPSpringbootTest.class) +@EnableAutoConfiguration +@Import(CmpAspect.class) +@ComponentScan({"com.yomahub.liteflow.test.aop.cmp1","com.yomahub.liteflow.test.aop.cmp2"}) +public class GlobalAOPSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试全局AOP,串行场景 + @Test + public void testGlobalAopS() { + LiteflowResponse response= flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("before_after", response.getSlot().getData("a")); + Assert.assertEquals("before_after", response.getSlot().getData("b")); + Assert.assertEquals("before_after", response.getSlot().getData("c")); + Assert.assertEquals("before_after", response.getSlot().getData("d")); + Assert.assertEquals("before_after", response.getSlot().getData("e")); + } + + //测试全局AOP,并行场景 + @Test + public void testGlobalAopP() { + LiteflowResponse response= flowExecutor.execute2Resp("chain2", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("before_after", response.getSlot().getData("a")); + Assert.assertEquals("before_after", response.getSlot().getData("b")); + Assert.assertEquals("before_after", response.getSlot().getData("c")); + Assert.assertEquals("before_after", response.getSlot().getData("d")); + Assert.assertEquals("before_after", response.getSlot().getData("e")); + } + + @Test + public void testGlobalAopException() { + LiteflowResponse response= flowExecutor.execute2Resp("chain3", "it's a request"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("before_after", response.getSlot().getData("a")); + Assert.assertEquals("before_after", response.getSlot().getData("b")); + Assert.assertEquals("before_after", response.getSlot().getData("c")); + Assert.assertEquals("before_after", response.getSlot().getData("f")); + } + + @AfterClass + public static void cleanScanCache(){ + BaseTest.cleanScanCache(); + ComponentScanner.cmpAroundAspect = null; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpAspect.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpAspect.java new file mode 100644 index 000000000..22a94daa7 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/aspect/CmpAspect.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.aop.aspect; + +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.aop.ICmpAroundAspect; +import com.yomahub.liteflow.entity.data.Slot; + +public class CmpAspect implements ICmpAroundAspect { + @Override + public void beforeProcess(String nodeId, Slot slot) { + slot.setData(nodeId, "before"); + } + + @Override + public void afterProcess(String nodeId, Slot slot) { + slot.setData(nodeId, StrUtil.format("{}_{}", slot.getData(nodeId), "after")); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java new file mode 100644 index 000000000..50de54cad --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/aspect/CustomAspect.java @@ -0,0 +1,27 @@ +package com.yomahub.liteflow.test.aop.aspect; + +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; + +@Aspect +public class CustomAspect { + + @Pointcut("execution(* com.yomahub.liteflow.test.aop.cmp1.*.process(*))") + public void cut() { + } + + @Around("cut()") + public Object around(ProceedingJoinPoint jp) throws Throwable { + NodeComponent cmp = (NodeComponent) jp.getThis(); + Slot slot = cmp.getSlot(); + slot.setData(cmp.getNodeId(), "before"); + Object returnObj = jp.proceed(); + slot.setData(cmp.getNodeId(), StrUtil.format("{}_{}", slot.getData(cmp.getNodeId()), "after")); + return returnObj; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/ACmp.java new file mode 100644 index 000000000..8802336f1 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/ACmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.aop.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Acomp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/BCmp.java new file mode 100644 index 000000000..8b688aef5 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/BCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.aop.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Bcomp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/CCmp.java new file mode 100644 index 000000000..b8c52b500 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp1/CCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.aop.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Ccomp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/DCmp.java new file mode 100644 index 000000000..ff4680e1f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/DCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.aop.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Dcomp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/ECmp.java new file mode 100644 index 000000000..99db4df8a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/ECmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.aop.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("e") +@LiteflowCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Ecomp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/FCmp.java new file mode 100644 index 000000000..38b8971c7 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/aop/cmp2/FCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.aop.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("f") +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + throw new RuntimeException("test error"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeSpringbootTest.java new file mode 100644 index 000000000..b6cc97ca4 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/AsyncNodeSpringbootTest.java @@ -0,0 +1,134 @@ +package com.yomahub.liteflow.test.asyncNode; + +import cn.hutool.core.collection.ListUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import com.yomahub.liteflow.test.asyncNode.exception.TestException; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * 测试隐式调用子流程 + * 单元测试 + * + * @author ssss + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/asyncNode/application.properties") +@SpringBootTest(classes = AsyncNodeSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.asyncNode.cmp"}) +public class AsyncNodeSpringbootTest extends BaseTest { + @Resource + private FlowExecutor flowExecutor; + + /***** + * 标准chain 嵌套选择 嵌套子chain进行执行 + * 验证了when情况下 多个node是并行执行 + * 验证了默认参数情况下 when可以加载执行 + * **/ + @Test + public void testAsyncFlow1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a base request"); + Assert.assertTrue(response.isSuccess()); + System.out.println(response.getSlot().getExecuteStepStr()); + } + + //这个和test1有点类似,只不过进一步验证了步骤 + @Test + public void testAsyncFlow2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "it's a base request"); + Assert.assertTrue(ListUtil.toList("b==>j==>g==>f==>h","b==>j==>g==>h==>f", + "b==>j==>h==>g==>f","b==>j==>h==>f==>g", + "b==>j==>f==>h==>g","b==>j==>f==>g==>h" + ).contains(response.getSlot().getExecuteStepStr())); + } + + //测试errorResume,默认的errorResume为false,这里测试默认的 + @Test + public void testAsyncFlow3_1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3-1", "it's a base request"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(response.getSlot().getException().getClass(), TestException.class); + } + + //测试errorResume,默认的errorResume为false,这里设置为true + @Test + public void testAsyncFlow3_2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3-2", "it's a base request"); + Assert.assertTrue(response.isSuccess()); + } + + //相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了不抛错 + @Test + public void testAsyncFlow4() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "it's a base request"); + //因为不记录错误,所以最终结果是true + Assert.assertTrue(response.isSuccess()); + //因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 + Integer count = response.getSlot().getData("count"); + Assert.assertEquals(new Integer(2), count); + //因为配置了不抛错,所以response里的cause应该为null + Assert.assertNull(response.getCause()); + } + + //相同group的并行组,会合并,并且errorResume根据第一个when来,这里第一个when配置了会抛错 + @Test + public void testAsyncFlow5() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", "it's a base request"); + //整个并行组是报错的,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + //因为是并行组,所以即便抛错了,其他组件也会执行,i在流程里配置了2遍,i抛错,但是也执行了2遍,这里验证下 + Integer count = response.getSlot().getData("count"); + Assert.assertEquals(new Integer(2), count); + //因为第一个when配置了会报错,所以response里的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } + + //不同group的并行组,不会合并,第一个when的errorResume是false,会抛错,那第二个when就不会执行 + @Test + public void testAsyncFlow6() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", "it's a base request"); + //第一个when会抛错,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + //因为是不同组并行组,第一组的when里的i就抛错了,所以i就执行了1遍 + Integer count = response.getSlot().getData("count"); + Assert.assertEquals(new Integer(1), count); + //第一个when会报错,所以最终response的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } + + //不同group的并行组,不会合并,第一个when的errorResume是true,不会报错,那第二个when还会继续执行,但是第二个when的errorResume是false,所以第二个when会报错 + @Test + public void testAsyncFlow7() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", "it's a base request"); + //第二个when会抛错,所以最终结果是false + Assert.assertFalse(response.isSuccess()); + // 传递了slotIndex,则set的size==2 + Integer count = response.getSlot().getData("count"); + Assert.assertEquals(new Integer(2), count); + //第一个when会报错,所以最终response的cause里应该会有TestException + Assert.assertEquals(TestException.class, response.getCause().getClass()); + } + + //测试任意异步一个执行完即继续的场景 + //d g h并行,配置了any=true,其中d耗时1秒,g耗时0.5秒,其他都不设耗时 + //最终执行效果应该是h先返回,然后执行abc,最后gd + //这里要注意的是,由于step是先加入,所以step的打印顺序并不是这样的。但是实际执行是正确的 + @Test + public void testAsyncFlow8() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain8", "it's a base request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertTrue(response.getSlot().getData("check").toString().startsWith("habc")); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java new file mode 100644 index 000000000..21eac78bf --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ACmp.java @@ -0,0 +1,28 @@ +package com.yomahub.liteflow.test.asyncNode.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + Slot slot = bindCmp.getSlot(); + synchronized (NodeComponent.class){ + if (slot.hasData("check")){ + String str = slot.getData("check"); + str += bindCmp.getNodeId(); + slot.setData("check", str); + }else{ + slot.setData("check", bindCmp.getNodeId()); + } + } + System.out.println("Acomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java new file mode 100644 index 000000000..2d3a1f211 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/BCmp.java @@ -0,0 +1,28 @@ +package com.yomahub.liteflow.test.asyncNode.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + Slot slot = bindCmp.getSlot(); + synchronized (NodeComponent.class){ + if (slot.hasData("check")){ + String str = slot.getData("check"); + str += bindCmp.getNodeId(); + slot.setData("check", str); + }else{ + slot.setData("check", bindCmp.getNodeId()); + } + } + System.out.println("Bcomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java new file mode 100644 index 000000000..3c79fe629 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/CCmp.java @@ -0,0 +1,28 @@ +package com.yomahub.liteflow.test.asyncNode.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + Slot slot = bindCmp.getSlot(); + synchronized (NodeComponent.class){ + if (slot.hasData("check")){ + String str = slot.getData("check"); + str += bindCmp.getNodeId(); + slot.setData("check", str); + }else{ + slot.setData("check", bindCmp.getNodeId()); + } + } + System.out.println("Ccomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java new file mode 100644 index 000000000..e96d0b9f0 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/DCmp.java @@ -0,0 +1,29 @@ +package com.yomahub.liteflow.test.asyncNode.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + Thread.sleep(1000); + Slot slot = bindCmp.getSlot(); + synchronized (NodeComponent.class){ + if (slot.hasData("check")){ + String str = slot.getData("check"); + str += bindCmp.getNodeId(); + slot.setData("check", str); + }else{ + slot.setData("check", bindCmp.getNodeId()); + } + } + System.out.println("Dcomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java new file mode 100644 index 000000000..56869f5cf --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ECmp.java @@ -0,0 +1,20 @@ +package com.yomahub.liteflow.test.asyncNode.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCondCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.core.NodeCondComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("e") +@LiteflowCondCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS_COND) + public String processCond(NodeComponent bindCmp) throws Exception { + System.out.println("Ecomp executed!"); + return "g"; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java new file mode 100644 index 000000000..83eac4042 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/FCmp.java @@ -0,0 +1,18 @@ +package com.yomahub.liteflow.test.asyncNode.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("f") +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + System.out.println("Fcomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java new file mode 100644 index 000000000..1a719d525 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/GCmp.java @@ -0,0 +1,30 @@ +package com.yomahub.liteflow.test.asyncNode.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("g") +@LiteflowCmpDefine +public class GCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + Thread.sleep(500); + Slot slot = bindCmp.getSlot(); + synchronized (NodeComponent.class){ + if (slot.hasData("check")){ + String str = slot.getData("check"); + str += bindCmp.getNodeId(); + slot.setData("check", str); + }else{ + slot.setData("check", bindCmp.getNodeId()); + } + } + System.out.println("Gcomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java new file mode 100644 index 000000000..b8ae6ce8a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/HCmp.java @@ -0,0 +1,30 @@ +package com.yomahub.liteflow.test.asyncNode.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("h") +@LiteflowCmpDefine +public class HCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + Slot slot = bindCmp.getSlot(); + synchronized (NodeComponent.class){ + if (slot.hasData("check")){ + String str = slot.getData("check"); + str += bindCmp.getNodeId(); + slot.setData("check", str); + }else{ + slot.setData("check", bindCmp.getNodeId()); + } + } + + System.out.println("Hcomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java new file mode 100644 index 000000000..37937c23a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/ICmp.java @@ -0,0 +1,28 @@ +package com.yomahub.liteflow.test.asyncNode.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.asyncNode.exception.TestException; +import org.springframework.stereotype.Component; + + +@Component("i") +@LiteflowCmpDefine +public class ICmp { + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + Slot slot = bindCmp.getSlot(); + if (slot.hasData("count")){ + Integer count = slot.getData("count"); + slot.setData("count", ++count); + } else{ + slot.setData("count", 1); + } + System.out.println("Icomp executed! throw Exception!"); + throw new TestException(); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java new file mode 100644 index 000000000..48e19487e --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/cmp/JCmp.java @@ -0,0 +1,21 @@ +package com.yomahub.liteflow.test.asyncNode.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowCondCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.core.NodeCondComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("j") +@LiteflowCondCmpDefine +public class JCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS_COND) + public String processCond(NodeComponent bindCmp) throws Exception { + System.out.println("Jcomp executed!"); + return "chain3"; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java new file mode 100644 index 000000000..e786e9f86 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/asyncNode/exception/TestException.java @@ -0,0 +1,4 @@ +package com.yomahub.liteflow.test.asyncNode.exception; + +public class TestException extends Exception{ +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/BaseSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/BaseSpringbootTest.java new file mode 100644 index 000000000..029d3a5cc --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/BaseSpringbootTest.java @@ -0,0 +1,39 @@ +package com.yomahub.liteflow.test.base; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境最普通的例子测试 + * @author Bryan.Zhang + * @since 2.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/base/application.properties") +@SpringBootTest(classes = BaseSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.base.cmp"}) +public class BaseSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testBase() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java new file mode 100644 index 000000000..d192c24aa --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.base.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/BCmp.java new file mode 100644 index 000000000..0f29823cc --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.base.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/CCmp.java new file mode 100644 index 000000000..d147a02c1 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.base.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/DCmp.java new file mode 100644 index 000000000..937c79b9b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/DCmp.java @@ -0,0 +1,31 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.base.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @Resource + private TestDomain testDomain; + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + testDomain.sayHi(); + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/TestDomain.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/TestDomain.java new file mode 100644 index 000000000..16f159324 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/base/cmp/TestDomain.java @@ -0,0 +1,10 @@ +package com.yomahub.liteflow.test.base.cmp; + +import org.springframework.stereotype.Component; + +@Component +public class TestDomain { + public void sayHi(){ + System.out.println("hello"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/BuilderSpringbootTest1.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/BuilderSpringbootTest1.java new file mode 100644 index 000000000..55f4011c2 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/BuilderSpringbootTest1.java @@ -0,0 +1,217 @@ +package com.yomahub.liteflow.test.builder; + +import com.yomahub.liteflow.builder.LiteFlowChainBuilder; +import com.yomahub.liteflow.builder.LiteFlowConditionBuilder; +import com.yomahub.liteflow.builder.LiteFlowNodeBuilder; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.ExecutableEntity; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.enums.NodeTypeEnum; +import com.yomahub.liteflow.test.BaseTest; +import com.yomahub.liteflow.test.builder.cmp1.*; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +//基于builder模式的单元测试 +//这里只是最基本的builder模式的测试,只是为了验证在springboot模式下的正常性 +//更详细的builder模式测试用例会单独拉testcase去做 +@RunWith(SpringRunner.class) +@SpringBootTest(classes = BuilderSpringbootTest1.class) +@EnableAutoConfiguration +public class BuilderSpringbootTest1 extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //基于普通组件的builder模式测试 + @Test + public void testBuilder() throws Exception { + LiteFlowNodeBuilder.createNode().setId("a") + .setName("组件A") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.ACmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("b") + .setName("组件B") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.BCmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("c") + .setName("组件C") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.CCmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("d") + .setName("组件D") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.DCmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("e") + .setName("组件E") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.ECmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("f") + .setName("组件F") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.FCmp") + .build(); + LiteFlowNodeBuilder.createNode().setId("g") + .setName("组件G") + .setType(NodeTypeEnum.COMMON) + .setClazz("com.yomahub.liteflow.test.builder.cmp1.GCmp") + .build(); + + + LiteFlowChainBuilder.createChain().setChainName("chain2").setCondition( + LiteFlowConditionBuilder.createThenCondition().setValue("c,d").build() + ).build(); + + LiteFlowChainBuilder.createChain().setChainName("chain1").setCondition( + LiteFlowConditionBuilder + .createThenCondition() + .setValue("a,b").build() + ).setCondition( + LiteFlowConditionBuilder.createWhenCondition() + .setValue("e(f|g|chain2)").build() + ).build(); + + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getSlot().getExecuteStepStr()); + } + + //基于普通组件的builder模式测试 + @Test + public void testBuilderForClassAndCode() throws Exception { + LiteFlowNodeBuilder.createNode().setId("a") + .setName("组件A") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(ACmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("b") + .setName("组件B") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(BCmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("c") + .setName("组件C") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(CCmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("d") + .setName("组件D") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(DCmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("e") + .setName("组件E") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(ECmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("f") + .setName("组件F") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(FCmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("g") + .setName("组件G") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(GCmp.class) + .build(); + + + LiteFlowChainBuilder.createChain().setChainName("chain2").setCondition( + LiteFlowConditionBuilder.createThenCondition().setValue("c,d").build() + ).build(); + + LiteFlowChainBuilder.createChain().setChainName("chain1").setCondition( + LiteFlowConditionBuilder + .createThenCondition() + .setValue("a,b").build() + ).setCondition( + LiteFlowConditionBuilder.createWhenCondition() + .setValue("e(f|g|chain2)").build() + ).build(); + + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getSlot().getExecuteStepStr()); + } + + + //基于普通组件的builder模式测试 + @Test + public void testBuilderForConditionNode() throws Exception { + LiteFlowNodeBuilder.createNode().setId("a") + .setName("组件A") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(ACmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("b") + .setName("组件B") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(BCmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("c") + .setName("组件C") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(CCmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("d") + .setName("组件D") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(DCmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("e") + .setName("组件E") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(ECmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("f") + .setName("组件F") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(FCmp.class) + .build(); + LiteFlowNodeBuilder.createNode().setId("g") + .setName("组件G") + .setTypeCode(NodeTypeEnum.COMMON.getCode()) + .setClazz(GCmp.class) + .build(); + + + LiteFlowChainBuilder.createChain().setChainName("chain2").setCondition( + LiteFlowConditionBuilder.createThenCondition() + .setExecutable(new ExecutableEntity().setId("c")) + .setExecutable(new ExecutableEntity().setId("d")) + .build() + ).build(); + + LiteFlowChainBuilder.createChain().setChainName("chain1").setCondition( + LiteFlowConditionBuilder + .createThenCondition() + .setExecutable(new ExecutableEntity().setId("a").setTag("hello")) + .setExecutable(new ExecutableEntity().setId("b")) + .build() + ).setCondition( + LiteFlowConditionBuilder.createWhenCondition() + .setExecutable( + new ExecutableEntity().setId("e") + .addNodeCondComponent(new ExecutableEntity().setId("f").setTag("FHello")) + .addNodeCondComponent(new ExecutableEntity().setId("g")) + .addNodeCondComponent(new ExecutableEntity().setId("chain2") + )).build() + ).build(); + + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[组件A]==>b[组件B]==>e[组件E]==>c[组件C]==>d[组件D]", response.getSlot().getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/BuilderSpringbootTest2.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/BuilderSpringbootTest2.java new file mode 100644 index 000000000..d412674c3 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/BuilderSpringbootTest2.java @@ -0,0 +1,41 @@ +package com.yomahub.liteflow.test.builder; + +import com.yomahub.liteflow.builder.LiteFlowChainBuilder; +import com.yomahub.liteflow.builder.LiteFlowConditionBuilder; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +//基于builder模式的单元测试 +//这里测试的是通过spring去扫描,但是通过代码去构建chain的用例 +@RunWith(SpringRunner.class) +@SpringBootTest(classes = BuilderSpringbootTest2.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.builder.cmp2"}) +public class BuilderSpringbootTest2 extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //通过spring去扫描组件,通过代码去构建chain + @Test + public void testBuilder() throws Exception { + LiteFlowChainBuilder.createChain().setChainName("chain1").setCondition( + LiteFlowConditionBuilder.createThenCondition().setValue("h,i,j").build() + ).build(); + + LiteflowResponse response = flowExecutor.execute2Resp("chain1"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("h==>i==>j", response.getSlot().getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java new file mode 100644 index 000000000..a9ffd1f01 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ACmp.java @@ -0,0 +1,22 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/BCmp.java new file mode 100644 index 000000000..e13b0434f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/BCmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/CCmp.java new file mode 100644 index 000000000..6fbbc10e6 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/CCmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/DCmp.java new file mode 100644 index 000000000..27fb0fd46 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/DCmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ECmp.java new file mode 100644 index 000000000..3fbb2daca --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/ECmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCondCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCondCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS_COND) + public String processCond(NodeComponent bindCmp) throws Exception { + System.out.println("ECmp executed!"); + return "chain2"; + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/FCmp.java new file mode 100644 index 000000000..a300c50fd --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/FCmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/GCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/GCmp.java new file mode 100644 index 000000000..4035e89ca --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp1/GCmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class GCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("GCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/HCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/HCmp.java new file mode 100644 index 000000000..a3bd495ac --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/HCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("h") +@LiteflowCmpDefine +public class HCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("HCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/ICmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/ICmp.java new file mode 100644 index 000000000..a7546b330 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/ICmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("i") +@LiteflowCmpDefine +public class ICmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ICmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/JCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/JCmp.java new file mode 100644 index 000000000..a270fc3c9 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/builder/cmp2/JCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.builder.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("j") +@LiteflowCmpDefine +public class JCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("JCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetrySpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetrySpringbootTest.java new file mode 100644 index 000000000..d744c69be --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/LiteflowRetrySpringbootTest.java @@ -0,0 +1,64 @@ +package com.yomahub.liteflow.test.cmpRetry; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + + +/** + * 测试springboot下的节点执行器 + * @author Bryan.Zhang + * @since 2.5.10 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/cmpRetry/application.properties") +@SpringBootTest(classes = LiteflowRetrySpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.cmpRetry.cmp"}) +public class LiteflowRetrySpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //全局重试配置测试 + @Test + public void testRetry1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>b==>b", response.getSlot().getExecuteStepStr()); + } + + //单个组件重试配置测试 + @Test + public void testRetry2() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("c==>c==>c==>c==>c==>c", response.getSlot().getExecuteStepStr()); + } + + //单个组件指定异常,但抛出的并不是指定异常的场景测试 + @Test + public void testRetry3() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertFalse(response.isSuccess()); + } + + //单个组件指定异常重试,抛出的是指定异常或者 + @Test + public void testRetry4() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("e==>e==>e==>e==>e==>e", response.getSlot().getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java new file mode 100644 index 000000000..2bd626295 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.cmpRetry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java new file mode 100644 index 000000000..9107e2381 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/BCmp.java @@ -0,0 +1,31 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.cmpRetry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("b") +@LiteflowCmpDefine +public class BCmp { + + private int flag = 0; + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + if (flag < 2){ + flag++; + throw new RuntimeException("demo exception"); + } + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/CCmp.java new file mode 100644 index 000000000..05ea10fd8 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/CCmp.java @@ -0,0 +1,28 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.cmpRetry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.annotation.LiteflowRetry; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("c") +@LiteflowRetry(5) +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + throw new RuntimeException("demo exception"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java new file mode 100644 index 000000000..c3d21e729 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/DCmp.java @@ -0,0 +1,28 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.cmpRetry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.annotation.LiteflowRetry; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("d") +@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + throw new RuntimeException("demo exception"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java new file mode 100644 index 000000000..f33b4ca64 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/cmpRetry/cmp/ECmp.java @@ -0,0 +1,28 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.cmpRetry.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.annotation.LiteflowRetry; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("e") +@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) +@LiteflowCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ECmp executed!"); + throw new NullPointerException("demo null exception"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorSpringbootTest.java new file mode 100644 index 000000000..140cffe60 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/FlowExecutorSpringbootTest.java @@ -0,0 +1,94 @@ +package com.yomahub.liteflow.test.component; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.util.ReflectionUtils; + +import javax.annotation.Resource; + +/** + * 组件功能点测试 + * 单元测试 + * + * @author donguo.tao + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/component/application.properties") +@SpringBootTest(classes = FlowExecutorSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.component.cmp1","com.yomahub.liteflow.test.component.cmp2"}) +public class FlowExecutorSpringbootTest extends BaseTest { + private static final Logger LOG = LoggerFactory.getLogger(FlowExecutorSpringbootTest.class); + + @Resource + private FlowExecutor flowExecutor; + + //isAccess方法的功能测试 + @Test + public void testIsAccess() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", 101); + Assert.assertTrue(response.isSuccess()); + Assert.assertNotNull(response.getSlot().getResponseData()); + } + + //组件抛错的功能点测试 + @Test(expected = ArithmeticException.class) + public void testComponentException() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", 0); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("/ by zero", response.getMessage()); + ReflectionUtils.rethrowException(response.getCause()); + } + + //isContinueOnError方法的功能点测试 + @Test + public void testIsContinueOnError() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", 0); + Assert.assertTrue(response.isSuccess()); + Assert.assertNull(response.getCause()); + } + + //isEnd方法的功能点测试 + @Test + public void testIsEnd() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("d",response.getSlot().getExecuteStepStr()); + } + + //setIsEnd方法的功能点测试 + @Test + public void testSetIsEnd1() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain5", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("e",response.getSlot().getExecuteStepStr()); + } + + //条件组件的功能点测试 + @Test + public void testNodeCondComponent() { + LiteflowResponse response = flowExecutor.execute2Resp("chain6", 0); + Assert.assertTrue(response.isSuccess()); + } + + //测试setIsEnd如果为true,continueError也为true,那不应该continue了 + @Test + public void testSetIsEnd2() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain7", 10); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g",response.getSlot().getExecuteStepStr()); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java new file mode 100644 index 000000000..25012ae40 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/ACmp.java @@ -0,0 +1,30 @@ +package com.yomahub.liteflow.test.component.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Objects; + + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("AComp executed!"); + bindCmp.getSlot().setResponseData("AComp executed!"); + } + + @LiteflowMethod(LiteFlowMethodEnum.IS_ACCESS) + public boolean isAccess(NodeComponent bindCmp) { + Integer requestData = bindCmp.getSlot().getRequestData(); + if (Objects.nonNull(requestData) && requestData > 100){ + return true; + } + System.out.println("AComp isAccess false."); + return false; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java new file mode 100644 index 000000000..832060c05 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/BCmp.java @@ -0,0 +1,33 @@ +package com.yomahub.liteflow.test.component.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Objects; + + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BComp executed!"); + Integer requestData = bindCmp.getSlot().getRequestData(); + Integer divisor = 130; + Integer result = divisor / requestData; + bindCmp.getSlot().setResponseData(result); + } + + @LiteflowMethod(LiteFlowMethodEnum.IS_ACCESS) + public boolean isAccess(NodeComponent bindCmp) { + Integer requestData = bindCmp.getSlot().getRequestData(); + if (Objects.nonNull(requestData)){ + return true; + } + return false; + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java new file mode 100644 index 000000000..c741a1ec8 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/CCmp.java @@ -0,0 +1,33 @@ +package com.yomahub.liteflow.test.component.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Objects; + + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CComp executed!"); + Integer requestData = bindCmp.getSlot().getRequestData(); + Integer divisor = 130; + Integer result = divisor / requestData; + bindCmp.getSlot().setResponseData(result); + System.out.println("responseData="+Integer.parseInt(bindCmp.getSlot().getResponseData())); + } + + @LiteflowMethod(LiteFlowMethodEnum.IS_CONTINUE_ON_ERROR) + public boolean isContinueOnError(NodeComponent bindCmp) { + Integer requestData = bindCmp.getSlot().getRequestData(); + if (Objects.nonNull(requestData)){ + return true; + } + return false; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java new file mode 100644 index 000000000..96253f090 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/DCmp.java @@ -0,0 +1,30 @@ +package com.yomahub.liteflow.test.component.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Objects; + + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + System.out.println("DComp executed!"); + } + + @LiteflowMethod(LiteFlowMethodEnum.IS_END) + public boolean isEnd(NodeComponent bindCmp) { + //组件的process执行完之后才会执行isEnd + Object requestData = bindCmp.getSlot().getResponseData(); + if (Objects.isNull(requestData)){ + System.out.println("DComp flow isEnd, because of responseData is null."); + return true; + } + return false; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java new file mode 100644 index 000000000..7a5099242 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/ECmp.java @@ -0,0 +1,28 @@ +package com.yomahub.liteflow.test.component.cmp1; + +import com.alibaba.fastjson.JSON; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Objects; + + +@Component("e") +@LiteflowCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + System.out.println("EComp executed!"); + Object responseData = bindCmp.getSlot().getResponseData(); + if (Objects.isNull(responseData)){ + System.out.println("EComp responseData flow must be set end ."); + //执行到某个条件时,手动结束流程。 + bindCmp.setIsEnd(true); + } + System.out.println("EComp responseData responseData=" + JSON.toJSONString(responseData)); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java new file mode 100644 index 000000000..ebfd97d28 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/GCmp.java @@ -0,0 +1,30 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.component.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("g") +@LiteflowCmpDefine +public class GCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("GCmp executed!"); + bindCmp.setIsEnd(true); + } + + @LiteflowMethod(LiteFlowMethodEnum.IS_CONTINUE_ON_ERROR) + public boolean isContinueOnError(NodeComponent bindCmp) { + return true; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java new file mode 100644 index 000000000..c2a30d0a5 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp1/HCmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.component.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("h") +@LiteflowCmpDefine +public class HCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("HCmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp2/FCondCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp2/FCondCmp.java new file mode 100644 index 000000000..360e02cb8 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/component/cmp2/FCondCmp.java @@ -0,0 +1,27 @@ +package com.yomahub.liteflow.test.component.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCondCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.core.NodeCondComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Objects; + + +@Component("f") +@LiteflowCondCmpDefine +public class FCondCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS_COND) + public String processCond(NodeComponent bindCmp) { + Integer requestData = bindCmp.getSlot().getRequestData(); + if (Objects.isNull(requestData)){ + return "d"; + } else if(requestData == 0){ + return "c"; + } else { + return "b"; + } + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesSpringbootTest.java new file mode 100644 index 000000000..ec49601af --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/CustomNodesSpringbootTest.java @@ -0,0 +1,45 @@ +package com.yomahub.liteflow.test.customNodes; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境下自定义声明节点的测试 + * 不通过spring扫描的方式,通过在配置文件里定义nodes的方式 + * @author Bryan.Zhang + * @since 2.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/customNodes/application.properties") +@SpringBootTest(classes = CustomNodesSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.customNodes.domain"}) +public class CustomNodesSpringbootTest extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testCustomNodes() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java new file mode 100644 index 000000000..fb8982c22 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ACmp.java @@ -0,0 +1,22 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customNodes.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/BCmp.java new file mode 100644 index 000000000..67ed16bcf --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/BCmp.java @@ -0,0 +1,29 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customNodes.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.customNodes.domain.DemoDomain; + +import javax.annotation.Resource; + +@LiteflowCmpDefine +public class BCmp{ + + @Resource + private DemoDomain demoDomain; + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + demoDomain.sayHi(); + System.out.println("BCmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/CCmp.java new file mode 100644 index 000000000..d4ee3cf17 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/CCmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customNodes.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/DCmp.java new file mode 100644 index 000000000..619905b1e --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/DCmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customNodes.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ECmp.java new file mode 100644 index 000000000..27b3243ce --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/ECmp.java @@ -0,0 +1,30 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customNodes.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.customNodes.domain.DemoDomain; + +import javax.annotation.Resource; + +@LiteflowCmpDefine +public class ECmp{ + + @Resource + private DemoDomain demoDomain; + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + demoDomain.sayHi(); + System.out.println("ECmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/FCmp.java new file mode 100644 index 000000000..a7f22de97 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/cmp/FCmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customNodes.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java new file mode 100644 index 000000000..d0b10dc0b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customNodes/domain/DemoDomain.java @@ -0,0 +1,11 @@ +package com.yomahub.liteflow.test.customNodes.domain; + +import org.springframework.stereotype.Component; + +@Component +public class DemoDomain { + + public void sayHi(){ + System.out.println("hi"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java new file mode 100644 index 000000000..6f88c4cdd --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor1.java @@ -0,0 +1,25 @@ +package com.yomahub.liteflow.test.customWhenThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomThreadExecutor1 implements ExecutorBuilder { + + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + //只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor( + liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), + "customer-when-1-thead-"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java new file mode 100644 index 000000000..7d45e4ad5 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor2.java @@ -0,0 +1,24 @@ +package com.yomahub.liteflow.test.customWhenThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomThreadExecutor2 implements ExecutorBuilder { + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + //只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor( + liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), + "customer-when-2-thead-"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java new file mode 100644 index 000000000..875dc3d1d --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomThreadExecutor3.java @@ -0,0 +1,24 @@ +package com.yomahub.liteflow.test.customWhenThreadPool; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.thread.ExecutorBuilder; + +import java.util.concurrent.ExecutorService; + +public class CustomThreadExecutor3 implements ExecutorBuilder { + @Override + public ExecutorService buildExecutor() { + LiteflowConfig liteflowConfig = LiteflowConfigGetter.get(); + //只有在非spring的场景下liteflowConfig才会为null + if (ObjectUtil.isNull(liteflowConfig)) { + liteflowConfig = new LiteflowConfig(); + } + return buildDefaultExecutor( + liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenMaxWorkers(), + liteflowConfig.getWhenQueueLimit(), + "customer-when-3-thead-"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolSpringbootTest.java new file mode 100644 index 000000000..b21eed76f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/CustomWhenThreadPoolSpringbootTest.java @@ -0,0 +1,72 @@ +package com.yomahub.liteflow.test.customWhenThreadPool; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境下异步线程超时日志打印测试 + * + * @author Bryan.Zhang + * @since 2.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/customWhenThreadPool/application.properties") +@SpringBootTest(classes = CustomWhenThreadPoolSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.customWhenThreadPool.cmp"}) +public class CustomWhenThreadPoolSpringbootTest extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + /** + * 测试全局线程池配置 + */ + @Test + public void testGlobalThreadPool() { + LiteflowResponse response = flowExecutor.execute2Resp("chain", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertTrue(response.getSlot().getData("threadName").toString().startsWith("lf-when-thead")); + } + + /** + * 测试全局和when上自定义线程池-优先以when上为准 + */ + @Test + public void testGlobalAndCustomWhenThreadPool() { + LiteflowResponse response1 = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response1.isSuccess()); + Assert.assertTrue(response1.getSlot().getData("threadName").toString().startsWith("customer-when-1-thead")); + } + + + /** + * when配置的线程池可以共用 + */ + @Test + public void testCustomWhenThreadPool() { + // 使用when - thread1 + testGlobalAndCustomWhenThreadPool(); + // chain配置同一个thead1 + LiteflowResponse response2 = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response2.isSuccess()); + Assert.assertTrue(response2.getSlot().getData("threadName").toString().startsWith("customer-when-1-thead")); + + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java new file mode 100644 index 000000000..ebe0cbf58 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customWhenThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/BCmp.java new file mode 100644 index 000000000..2a00fb1a5 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/BCmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customWhenThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + bindCmp.getSlot().setData("threadName", Thread.currentThread().getName()); + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/CCmp.java new file mode 100644 index 000000000..1a85ad0cb --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/CCmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customWhenThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + bindCmp.getSlot().setData("threadName", Thread.currentThread().getName()); + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/DCmp.java new file mode 100644 index 000000000..d5b9f6ce1 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/DCmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customWhenThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + bindCmp.getSlot().setData("threadName", Thread.currentThread().getName()); + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ECmp.java new file mode 100644 index 000000000..c9bac33b7 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/ECmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customWhenThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("e") +@LiteflowCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + bindCmp.getSlot().setData("threadName", Thread.currentThread().getName()); + System.out.println("ECmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/FCmp.java new file mode 100644 index 000000000..552ea97a0 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/customWhenThreadPool/cmp/FCmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.customWhenThreadPool.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("f") +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + bindCmp.getSlot().setData("threadName", Thread.currentThread().getName()); + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/ExceptionSpringBootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/ExceptionSpringBootTest.java new file mode 100644 index 000000000..de1c3a285 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/ExceptionSpringBootTest.java @@ -0,0 +1,83 @@ +package com.yomahub.liteflow.test.exception; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.exception.ChainNotFoundException; +import com.yomahub.liteflow.exception.ConfigErrorException; +import com.yomahub.liteflow.exception.FlowExecutorNotInitException; +import com.yomahub.liteflow.exception.FlowSystemException; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.util.ReflectionUtils; + +import javax.annotation.Resource; + +/** + * 流程执行异常 + * 单元测试 + * + * @author zendwang + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/exception/application.properties") +@SpringBootTest(classes = ExceptionSpringBootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.exception.cmp"}) +public class ExceptionSpringBootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Autowired + private ApplicationContext context; + + @Test(expected = ConfigErrorException.class) + public void testConfigErrorException() { + flowExecutor.setLiteflowConfig(null); + flowExecutor.init(); + } + + @Test(expected = FlowExecutorNotInitException.class) + public void testFlowExecutorNotInitException() { + LiteflowConfig config = context.getBean(LiteflowConfig.class); + config.setRuleSource("error/flow.txt"); + flowExecutor.init(); + } + + @Test(expected = ChainNotFoundException.class) + public void testChainNotFoundException() throws Exception { + flowExecutor.execute("chain0", "it's a request"); + } + + @Test(expected = RuntimeException.class) + public void testComponentCustomException() throws Exception { + flowExecutor.execute("chain1", "exception"); + } + + @Test(expected = FlowSystemException.class) + public void testNoConditionInChainException() throws Exception { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "test"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("no conditionList in this chain[chain2]", response.getMessage()); + ReflectionUtils.rethrowException(response.getCause()); + } + + @Test + public void testGetSlotFromResponseWhenException() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "test"); + Assert.assertFalse(response.isSuccess()); + Assert.assertNotNull(response.getCause()); + Assert.assertNotNull(response.getSlot()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java new file mode 100644 index 000000000..21523bf92 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/ACmp.java @@ -0,0 +1,34 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.exception.cmp; + +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + private static final Logger LOG = LoggerFactory.getLogger(ACmp.class); + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + String str = bindCmp.getSlot().getRequestData(); + if(StrUtil.isNotBlank(str) && str.equals("exception")) { + throw new RuntimeException("chain execute execption"); + } + LOG.info("Acomp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java new file mode 100644 index 000000000..5ec0f8b04 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/BCmp.java @@ -0,0 +1,39 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.exception.cmp; + +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + private static final Logger LOG = LoggerFactory.getLogger(BCmp.class); + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws InterruptedException { + String str = bindCmp.getSlot().getRequestData(); + if(StrUtil.isNotBlank(str) && str.equals("when")) { + try { + LOG.info("Bcomp sleep begin"); + Thread.sleep(3000); + LOG.info("Bcomp sleep end"); + } catch (InterruptedException e) { + throw e; + } + } + LOG.info("Bcomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java new file mode 100644 index 000000000..4e4b4e25c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/CCmp.java @@ -0,0 +1,28 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.exception.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + private static final Logger LOG = LoggerFactory.getLogger(CCmp.class); + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + LOG.info("Ccomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java new file mode 100644 index 000000000..6da4fe9a1 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/exception/cmp/DCmp.java @@ -0,0 +1,31 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.exception.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + private static final Logger LOG = LoggerFactory.getLogger(DCmp.class); + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + if(1==1){ + int a = 1/0; + } + LOG.info("Dcomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureSpringbootTest.java new file mode 100644 index 000000000..d2460105b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/Executor2FutureSpringbootTest.java @@ -0,0 +1,41 @@ +package com.yomahub.liteflow.test.execute2Future; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.util.concurrent.Future; + +/** + * springboot环境执行返回future的例子 + * @author Bryan.Zhang + * @since 2.6.13 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/execute2Future/application.properties") +@SpringBootTest(classes = Executor2FutureSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.execute2Future.cmp"}) +public class Executor2FutureSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testFuture() throws Exception{ + Future> future = flowExecutor.execute2Future("chain1", "arg", DefaultSlot.class); + LiteflowResponse response = future.get(); + Assert.assertTrue(response.isSuccess()); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java new file mode 100644 index 000000000..a46e144e0 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.execute2Future.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/BCmp.java new file mode 100644 index 000000000..2678f2557 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.execute2Future.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/CCmp.java new file mode 100644 index 000000000..a3ca40a89 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.execute2Future.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/DCmp.java new file mode 100644 index 000000000..121619827 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/execute2Future/cmp/DCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.execute2Future.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/FlowMetaSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/FlowMetaSpringbootTest.java new file mode 100644 index 000000000..5e7ed5727 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/FlowMetaSpringbootTest.java @@ -0,0 +1,38 @@ +package com.yomahub.liteflow.test.flowmeta; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.test.BaseTest; +import com.yomahub.liteflow.test.flowmeta.cmp2.DCmp; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/flowmeta/application.properties") +@SpringBootTest(classes = FlowMetaSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.flowmeta.cmp1"}) +public class FlowMetaSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试动态添加元信息节点 + @Test + public void testFlowMeta() { + FlowBus.addCommonNode("d", "d组件", DCmp.class.getName()); + LiteflowResponse response= flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>d[d组件]", response.getSlot().getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/ACmp.java new file mode 100644 index 000000000..4c315157b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/ACmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.flowmeta.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/BCmp.java new file mode 100644 index 000000000..134185aef --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/BCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.flowmeta.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/CCmp.java new file mode 100644 index 000000000..30c3f8bfb --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp1/CCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.flowmeta.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp2/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp2/DCmp.java new file mode 100644 index 000000000..260ad8091 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/flowmeta/cmp2/DCmp.java @@ -0,0 +1,23 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.flowmeta.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Dcomp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/LazySpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/LazySpringbootTest.java new file mode 100644 index 000000000..6e3500217 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/LazySpringbootTest.java @@ -0,0 +1,33 @@ +package com.yomahub.liteflow.test.lazy; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/lazy/application.properties") +@SpringBootTest(classes = LazySpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.lazy.cmp"}) +public class LazySpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testLazy() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java new file mode 100644 index 000000000..01a43e2a2 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/ACmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.lazy.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + +@Lazy +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java new file mode 100644 index 000000000..628760c66 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.lazy.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java new file mode 100644 index 000000000..781d1a209 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/lazy/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.lazy.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/LiteflowComponentSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/LiteflowComponentSpringbootTest.java new file mode 100644 index 000000000..954bee888 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/LiteflowComponentSpringbootTest.java @@ -0,0 +1,39 @@ +package com.yomahub.liteflow.test.liteflowcomponent; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + + +/** + * 测试@LiteflowComponent标注 + * @author Bryan.Zhang + * @since 2.5.10 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/liteflowComponent/application.properties") +@SpringBootTest(classes = LiteflowComponentSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.liteflowComponent.cmp"}) +public class LiteflowComponentSpringbootTest extends BaseTest { + + @Autowired + private FlowExecutor flowExecutor; + + @Test + public void testConfig() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a[A组件]==>b[B组件]==>c[C组件]==>b[B组件]==>a[A组件]==>d", response.getSlot().getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/ACmp.java new file mode 100644 index 000000000..cbb4d4381 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.liteflowcomponent.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent(id = "a", name = "A组件") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/BCmp.java new file mode 100644 index 000000000..dfab6f34b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.liteflowcomponent.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent(id = "b", name = "B组件") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/CCmp.java new file mode 100644 index 000000000..1f4fdd22f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.liteflowcomponent.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent(id = "c", name = "C组件") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/DCmp.java new file mode 100644 index 000000000..9f338fa01 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/liteflowcomponent/cmp/DCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.liteflowcomponent.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/MonitorSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/MonitorSpringbootTest.java new file mode 100644 index 000000000..11147d10c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/MonitorSpringbootTest.java @@ -0,0 +1,50 @@ +package com.yomahub.liteflow.test.monitor; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.monitor.MonitorBus; +import com.yomahub.liteflow.spi.holder.ContextAwareHolder; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境最普通的例子测试 + * @author Bryan.Zhang + * @since 2.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/monitor/application.properties") +@SpringBootTest(classes = MonitorSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.monitor.cmp"}) +public class MonitorSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testMonitor() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + + Thread.sleep(10000); + } + + @AfterClass + public static void clean(){ + MonitorBus monitorBus = ContextAwareHolder.loadContextAware().getBean(MonitorBus.class); + monitorBus.closeScheduler(); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/ACmp.java new file mode 100644 index 000000000..314ca078f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/ACmp.java @@ -0,0 +1,32 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.monitor.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Random; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(new Random().nextInt(2000)); + }catch (Exception e){ + e.printStackTrace(); + } + + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java new file mode 100644 index 000000000..51d239b72 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/BCmp.java @@ -0,0 +1,32 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.monitor.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Random; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(new Random().nextInt(2000)); + }catch (Exception e){ + e.printStackTrace(); + } + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java new file mode 100644 index 000000000..3d802e5ea --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/monitor/cmp/CCmp.java @@ -0,0 +1,32 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.monitor.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import java.util.Random; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(new Random().nextInt(2000)); + }catch (Exception e){ + e.printStackTrace(); + } + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringbootTest.java new file mode 100644 index 000000000..91ef144e4 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringbootTest.java @@ -0,0 +1,42 @@ +package com.yomahub.liteflow.test.multipleType; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + + +/** + * 测试springboot下混合格式规则的场景 + * @author Bryan.Zhang + * @since 2.5.10 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/multipleType/application.properties") +@SpringBootTest(classes = LiteflowMultipleTypeSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.multipleType.cmp"}) +public class LiteflowMultipleTypeSpringbootTest extends BaseTest { + + @Autowired + private FlowExecutor flowExecutor; + + @Test + public void testMultipleType() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a", response.getSlot().getExecuteStepStr()); + response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c", response.getSlot().getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java new file mode 100644 index 000000000..31fb6b256 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.multipleType.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/BCmp.java new file mode 100644 index 000000000..4f6b64dfc --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.multipleType.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/CCmp.java new file mode 100644 index 000000000..66dadb7ea --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/multipleType/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.multipleType.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java new file mode 100644 index 000000000..84b60247a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerDefaultNodeExecutor.java @@ -0,0 +1,19 @@ +package com.yomahub.liteflow.test.nodeExecutor; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.DataBus; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.entity.executor.NodeExecutor; + +/** + * 自定义默认的节点执行器 + */ +public class CustomerDefaultNodeExecutor extends NodeExecutor { + @Override + public void execute(NodeComponent instance) throws Exception { + Slot slot = DataBus.getSlot(instance.getSlotIndex()); + LOG.info("使用customerDefaultNodeExecutor进行执行"); + slot.setData("customerDefaultNodeExecutor", this.getClass()); + super.execute(instance); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java new file mode 100644 index 000000000..247bc3d47 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutor.java @@ -0,0 +1,20 @@ +package com.yomahub.liteflow.test.nodeExecutor; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.DataBus; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.entity.executor.NodeExecutor; + +/** + * 自定义节点执行器 + */ +public class CustomerNodeExecutor extends NodeExecutor { + @Override + public void execute(NodeComponent instance) throws Exception { + Slot slot = DataBus.getSlot(instance.getSlotIndex()); + LOG.info("使用customerNodeExecutor进行执行"); + slot.setData("customerNodeExecutor", this.getClass()); + super.execute(instance); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java new file mode 100644 index 000000000..46792852a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/CustomerNodeExecutorAndCustomRetry.java @@ -0,0 +1,29 @@ +package com.yomahub.liteflow.test.nodeExecutor; + +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.DataBus; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.entity.executor.NodeExecutor; + +import java.util.concurrent.TimeUnit; + +/** + * 自定义节点执行器 + */ +public class CustomerNodeExecutorAndCustomRetry extends NodeExecutor { + @Override + public void execute(NodeComponent instance) throws Exception { + Slot slot = DataBus.getSlot(instance.getSlotIndex()); + LOG.info("使用customerNodeExecutorAndCustomRetry进行执行"); + slot.setData("customerNodeExecutorAndCustomRetry", this.getClass()); + super.execute(instance); + } + + @Override + protected void retry(NodeComponent instance, int currentRetryCount) throws Exception { + TimeUnit.MICROSECONDS.sleep(20L); + Slot slot = DataBus.getSlot(instance.getSlotIndex()); + slot.setData("retryLogic", this.getClass()); + super.retry(instance, currentRetryCount); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorSpringbootTest.java new file mode 100644 index 000000000..0c13bdadb --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/LiteflowNodeExecutorSpringbootTest.java @@ -0,0 +1,69 @@ +package com.yomahub.liteflow.test.nodeExecutor; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + + +/** + * 测试springboot下的组件重试 + * + * @author Bryan.Zhang + * @since 2.5.10 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/nodeExecutor/application.properties") +@SpringBootTest(classes = LiteflowNodeExecutorSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.nodeExecutor.cmp"}) +public class LiteflowNodeExecutorSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + // 默认执行器测试 + @Test + public void testCustomerDefaultNodeExecutor() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(CustomerDefaultNodeExecutor.class, response.getSlot().getData("customerDefaultNodeExecutor")); + Assert.assertEquals("a", response.getSlot().getExecuteStepStr()); + } + + //默认执行器测试+全局重试配置测试 + @Test + public void testDefaultExecutorForRetry() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(CustomerDefaultNodeExecutor.class, response.getSlot().getData("customerDefaultNodeExecutor")); + Assert.assertEquals("b==>b==>b", response.getSlot().getExecuteStepStr()); + } + + //自定义执行器测试 + @Test + public void testCustomerExecutor() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("c", response.getSlot().getExecuteStepStr()); + } + + //自定义执行器测试+全局重试配置测试 + @Test + public void testCustomExecutorForRetry() { + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(CustomerNodeExecutorAndCustomRetry.class, response.getSlot().getData("retryLogic")); + Assert.assertEquals("d==>d==>d==>d==>d==>d", response.getSlot().getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java new file mode 100644 index 000000000..e576f564b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/ACmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.nodeExecutor.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java new file mode 100644 index 000000000..9581a0655 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/BCmp.java @@ -0,0 +1,31 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.nodeExecutor.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("b") +@LiteflowCmpDefine +public class BCmp{ + + private int flag = 0; + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + if (flag < 2){ + flag++; + throw new RuntimeException("demo exception"); + } + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java new file mode 100644 index 000000000..3cf2a06fa --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/CCmp.java @@ -0,0 +1,33 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.nodeExecutor.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.annotation.LiteflowRetry; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.executor.NodeExecutor; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.nodeExecutor.CustomerNodeExecutor; + +@LiteflowComponent("c") +@LiteflowRetry(5) +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + + @LiteflowMethod(LiteFlowMethodEnum.GET_NODE_EXECUTOR_CLASS) + public Class getNodeExecutorClass(NodeComponent bindCmp) { + return CustomerNodeExecutor.class; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java new file mode 100644 index 000000000..61c8b4c14 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/nodeExecutor/cmp/DCmp.java @@ -0,0 +1,35 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * + * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.nodeExecutor.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.annotation.LiteflowRetry; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.executor.NodeExecutor; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.nodeExecutor.CustomerNodeExecutorAndCustomRetry; + +@LiteflowComponent("d") +@LiteflowRetry(retry = 5, forExceptions = {NullPointerException.class}) +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + throw new NullPointerException("demo exception"); + } + + @LiteflowMethod(LiteFlowMethodEnum.GET_NODE_EXECUTOR_CLASS) + public Class getNodeExecutorClass(NodeComponent bindCmp) { + return CustomerNodeExecutorAndCustomRetry.class; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonSpringbootTest.java new file mode 100644 index 000000000..5f61dc208 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserJsonSpringbootTest.java @@ -0,0 +1,39 @@ +package com.yomahub.liteflow.test.parsecustom; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境的自定义json parser单元测试 + * @author dongguo.tao + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/parsecustom/application-custom-json.properties") +@SpringBootTest(classes = CustomParserJsonSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.parsecustom.cmp"}) +public class CustomParserJsonSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试springboot场景的自定义json parser + @Test + public void testJsonCustomParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlSpringbootTest.java new file mode 100644 index 000000000..b534a745e --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/CustomParserXmlSpringbootTest.java @@ -0,0 +1,40 @@ +package com.yomahub.liteflow.test.parsecustom; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境的自定义xml parser单元测试 + * 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * @author bryan.zhang + * @since 2.5.7 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/parsecustom/application-custom-xml.properties") +@SpringBootTest(classes = CustomParserXmlSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.parsecustom.cmp","com.yomahub.liteflow.test.parsecustom.bean"}) +public class CustomParserXmlSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试springboot场景的自定义json parser + @Test + public void testXmlCustomParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "args"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java new file mode 100644 index 000000000..3d4eece3b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/bean/TestBean.java @@ -0,0 +1,11 @@ +package com.yomahub.liteflow.test.parsecustom.bean; + +import org.springframework.stereotype.Component; + +@Component +public class TestBean { + + public String returnXmlContent(){ + return ""; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java new file mode 100644 index 000000000..ed877bf98 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ACmp.java @@ -0,0 +1,30 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import cn.hutool.core.util.StrUtil; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.exception.FlowSystemException; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + String str = bindCmp.getSlot().getRequestData(); + if(StrUtil.isNotBlank(str) && str.equals("exception")) { + throw new FlowSystemException("chain execute execption"); + } + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/BCmp.java new file mode 100644 index 000000000..440ea579a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/CCmp.java new file mode 100644 index 000000000..75ca94417 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/DCmp.java new file mode 100644 index 000000000..12789ff2e --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/DCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java new file mode 100644 index 000000000..7b15119d0 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/ECmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCondCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.core.NodeCondComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("e") +@LiteflowCondCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS_COND) + public String processCond(NodeComponent bindCmp) throws Exception { + return "g"; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/FCmp.java new file mode 100644 index 000000000..4bb6d0311 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/FCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("f") +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/GCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/GCmp.java new file mode 100644 index 000000000..62242e698 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/cmp/GCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parsecustom.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("g") +@LiteflowCmpDefine +public class GCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("GCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java new file mode 100644 index 000000000..dd3a41929 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomJsonFlowParser.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.parsecustom.parser; + +import com.yomahub.liteflow.parser.ClassJsonFlowParser; + +/** + * 模拟用户自定义源解析 + * @author dongguo.tao + * @since 2.5.0 + */ +public class CustomJsonFlowParser extends ClassJsonFlowParser { + @Override + public String parseCustom() { + //模拟自定义解析结果 + String content = "{\"flow\":{\"nodes\":{\"node\":[{\"id\":\"a\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ACmp\"},{\"id\":\"b\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.BCmp\"},{\"id\":\"c\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.CCmp\"},{\"id\":\"d\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.DCmp\"},{\"id\":\"e\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.ECmp\"},{\"id\":\"f\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.FCmp\"},{\"id\":\"g\",\"class\":\"com.yomahub.liteflow.test.parsecustom.cmp.GCmp\"}]},\"chain\":[{\"name\":\"chain2\",\"condition\":[{\"type\":\"then\",\"value\":\"c,g,f\"}]},{\"name\":\"chain1\",\"condition\":[{\"type\":\"then\",\"value\":\"a,c\"},{\"type\":\"when\",\"value\":\"b,d,e(f|g)\"},{\"type\":\"then\",\"value\":\"chain2\"}]}]}}"; + return content; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java new file mode 100644 index 000000000..064323b89 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parsecustom/parser/CustomXmlFlowParser.java @@ -0,0 +1,23 @@ +package com.yomahub.liteflow.test.parsecustom.parser; + +import com.yomahub.liteflow.parser.ClassXmlFlowParser; +import com.yomahub.liteflow.test.parsecustom.bean.TestBean; + +import javax.annotation.Resource; + +/** + * springboot环境的自定义xml parser单元测试 + * 主要测试自定义配置源类是否能引入springboot中的其他依赖 + * @author bryan.zhang + * @since 2.5.7 + */ +public class CustomXmlFlowParser extends ClassXmlFlowParser { + + @Resource + private TestBean testBean; + + @Override + public String parseCustom() { + return testBean.returnXmlContent(); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/JsonParserSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/JsonParserSpringbootTest.java new file mode 100644 index 000000000..6b4ee17f6 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/JsonParserSpringbootTest.java @@ -0,0 +1,37 @@ +package com.yomahub.liteflow.test.parser; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * spring环境的json parser单元测试 + * @author Bryan.Zhang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/parser/application-json.properties") +@SpringBootTest(classes = JsonParserSpringbootTest.class) +@EnableAutoConfiguration +public class JsonParserSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试spring场景的json parser + @Test + public void testJsonParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportSpringbootTest.java new file mode 100644 index 000000000..ec0e2acc7 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/SpringELSupportSpringbootTest.java @@ -0,0 +1,32 @@ +package com.yomahub.liteflow.test.parser; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/parser/application-springEL.properties") +@SpringBootTest(classes = SpringELSupportSpringbootTest.class) +@EnableAutoConfiguration +public class SpringELSupportSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试springEL的解析情况 + @Test + public void testSpringELParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/XmlParserSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/XmlParserSpringbootTest.java new file mode 100644 index 000000000..562e7456e --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/XmlParserSpringbootTest.java @@ -0,0 +1,37 @@ +package com.yomahub.liteflow.test.parser; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境的xml parser单元测试 + * @author Bryan.Zhang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/parser/application-xml.properties") +@SpringBootTest(classes = XmlParserSpringbootTest.class) +@EnableAutoConfiguration +public class XmlParserSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试无springboot场景的xml parser + @Test + public void testXmlParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/YmlParserSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/YmlParserSpringbootTest.java new file mode 100644 index 000000000..ad2050c00 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/YmlParserSpringbootTest.java @@ -0,0 +1,37 @@ +package com.yomahub.liteflow.test.parser; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot下的yml parser测试用例 + * @author Bryan.Zhang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/parser/application-yml.properties") +@SpringBootTest(classes = YmlParserSpringbootTest.class) +@EnableAutoConfiguration +public class YmlParserSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试无springboot场景的yml parser + @Test + public void testYmlParser() { + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java new file mode 100644 index 000000000..33d611a3f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parser.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/BCmp.java new file mode 100644 index 000000000..d40b13d2f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parser.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/CCmp.java new file mode 100644 index 000000000..e9d3dceb8 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parser.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/DCmp.java new file mode 100644 index 000000000..9f86ac0f7 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/DCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parser.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java new file mode 100644 index 000000000..620495a5f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/ECmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parser.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCondCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.core.NodeCondComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("e") +@LiteflowCondCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS_COND) + public String processCond(NodeComponent bindCmp) throws Exception { + return "g"; + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/FCmp.java new file mode 100644 index 000000000..84e178b5b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/FCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parser.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("f") +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/GCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/GCmp.java new file mode 100644 index 000000000..8b50f2452 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/parser/cmp/GCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.parser.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("g") +@LiteflowCmpDefine +public class GCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("GCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallySpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallySpringbootTest.java new file mode 100644 index 000000000..0becd8269 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/PreAndFinallySpringbootTest.java @@ -0,0 +1,64 @@ +package com.yomahub.liteflow.test.preAndFinally; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境下pre节点和finally节点的测试 + * @author Bryan.Zhang + * @since 2.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/preAndFinally/application.properties") +@SpringBootTest(classes = PreAndFinallySpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.preAndFinally.cmp"}) +public class PreAndFinallySpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试普通的pre和finally节点 + @Test + public void testPreAndFinally1() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2",response.getSlot().getExecuteStepStr()); + } + + //测试pre和finally节点不放在开头和结尾的情况 + @Test + public void testPreAndFinally2() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>b==>c==>f1==>f2",response.getSlot().getExecuteStepStr()); + } + + //测试有节点报错是否还执行finally节点的情况,其中d节点会报错,但依旧执行f1,f2节点 + @Test + public void testPreAndFinally3() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals("p1==>p2==>a==>d==>f1==>f2", response.getSlot().getExecuteStepStr()); + } + + //测试在finally节点里是否能获取exception + @Test + public void testPreAndFinally4() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertTrue(response.getSlot().getData("hasEx")); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java new file mode 100644 index 000000000..c5b4afe65 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/BCmp.java new file mode 100644 index 000000000..92644fcab --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/CCmp.java new file mode 100644 index 000000000..23813b76a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java new file mode 100644 index 000000000..f6f948273 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/DCmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + int i = 1/0; + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java new file mode 100644 index 000000000..fd5fed96c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally1Cmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("f1") +@LiteflowCmpDefine +public class Finally1Cmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Finally1Cmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java new file mode 100644 index 000000000..e1c809727 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally2Cmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("f2") +@LiteflowCmpDefine +public class Finally2Cmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Finally2Cmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java new file mode 100644 index 000000000..a775a42ab --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Finally3Cmp.java @@ -0,0 +1,32 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import cn.hutool.core.util.ObjectUtil; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("f3") +@LiteflowCmpDefine +public class Finally3Cmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception{ + Slot slot = bindCmp.getSlot(); + if (ObjectUtil.isNull(slot.getException())){ + slot.setData("hasEx", false); + }else{ + slot.setData("hasEx", true); + } + System.out.println("Finally3Cmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java new file mode 100644 index 000000000..ffe0556c3 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre1Cmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("p1") +@LiteflowCmpDefine +public class Pre1Cmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Pre1Cmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java new file mode 100644 index 000000000..f00a75263 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/preAndFinally/cmp/Pre2Cmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.preAndFinally.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("p2") +@LiteflowCmpDefine +public class Pre2Cmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Pre2Cmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliverySpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliverySpringbootTest.java new file mode 100644 index 000000000..9f2831197 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/PrivateDeliverySpringbootTest.java @@ -0,0 +1,41 @@ +package com.yomahub.liteflow.test.privateDelivery; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.util.Set; + +/** + * springboot环境下隐私投递的测试 + * @author Bryan.Zhang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/privateDelivery/application.properties") +@SpringBootTest(classes = PrivateDeliverySpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.privateDelivery.cmp"}) +public class PrivateDeliverySpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testPrivateDelivery() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Set set = response.getSlot().getData("testSet"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals(100, set.size()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java new file mode 100644 index 000000000..d2c8a3218 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/ACmp.java @@ -0,0 +1,34 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.privateDelivery.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +import java.util.HashSet; + +@LiteflowComponent("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + Slot slot = bindCmp.getSlot(); + slot.setData("testSet", new HashSet<>()); + + for (int i = 0; i < 100; i++) { + bindCmp.sendPrivateDeliveryData("b",i+1); + } + } +} + diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java new file mode 100644 index 000000000..3290d9ca2 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/BCmp.java @@ -0,0 +1,30 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.privateDelivery.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +import java.util.Set; + +@LiteflowComponent("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + Integer value = bindCmp.getPrivateDeliveryData(); + Set testSet = bindCmp.getSlot().getData("testSet"); + testSet.add(value); + } +} + diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/CCmp.java new file mode 100644 index 000000000..c73d66402 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.privateDelivery.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/DCmp.java new file mode 100644 index 000000000..354abbb9e --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/privateDelivery/cmp/DCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.privateDelivery.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleSpringbootTest.java new file mode 100644 index 000000000..d4504ce59 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/RefreshRuleSpringbootTest.java @@ -0,0 +1,70 @@ +package com.yomahub.liteflow.test.refreshRule; + +import cn.hutool.core.io.resource.ResourceUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.enums.FlowParserTypeEnum; +import com.yomahub.liteflow.flow.FlowBus; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境下重新加载规则测试 + * @author Bryan.Zhang + * @since 2.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/refreshRule/application.properties") +@SpringBootTest(classes = RefreshRuleSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.refreshRule.cmp"}) +public class RefreshRuleSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //测试普通刷新流程的场景 + @Test + public void testRefresh1() throws Exception{ + String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.xml"); + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_XML, content); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + //测试优雅刷新的场景 + @Test + public void testRefresh2() throws Exception{ + new Thread(() -> { + try { + Thread.sleep(3000L); + String content = ResourceUtil.readUtf8Str("classpath: /refreshRule/flow_update.xml"); + FlowBus.refreshFlowMetaData(FlowParserTypeEnum.TYPE_XML, content); + } catch (Exception e) { + e.printStackTrace(); + } + + }).start(); + + for (int i = 0; i < 500; i++) { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + try { + Thread.sleep(10L); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java new file mode 100644 index 000000000..6912aaf8a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.refreshRule.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/BCmp.java new file mode 100644 index 000000000..aaef859a6 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.refreshRule.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CCmp.java new file mode 100644 index 000000000..7e935c272 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/refreshRule/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.refreshRule.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/ReloadSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/ReloadSpringbootTest.java new file mode 100644 index 000000000..e09edbdd1 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/ReloadSpringbootTest.java @@ -0,0 +1,41 @@ +package com.yomahub.liteflow.test.reload; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境下重新加载规则测试 + * @author Bryan.Zhang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/reload/application.properties") +@SpringBootTest(classes = ReloadSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.reload.cmp"}) +public class ReloadSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + //用reloadRule去重新加载,这里如果配置是放在本地。如果想修改,则要去修改target下面的flow.xml + //这里的测试,手动打断点然后去修改,是ok的。但是整个测试,暂且只是为了测试这个功能是否能正常运行 + @Test + public void testReload() throws Exception{ + flowExecutor.reloadRule(); + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java new file mode 100644 index 000000000..57cc3a6df --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.reload.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/BCmp.java new file mode 100644 index 000000000..5ca7ff6d1 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.reload.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/CCmp.java new file mode 100644 index 000000000..af6e8b52c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/reload/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.reload.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/ResizeSlotSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/ResizeSlotSpringbootTest.java new file mode 100644 index 000000000..7af320ed3 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/ResizeSlotSpringbootTest.java @@ -0,0 +1,65 @@ +package com.yomahub.liteflow.test.resizeSlot; + +import cn.hutool.core.util.ReflectUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DataBus; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +/** + * springboot环境下slot扩容测试 + * @author Bryan.Zhang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/resizeSlot/application.properties") +@SpringBootTest(classes = ResizeSlotSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.resizeSlot.cmp"}) +public class ResizeSlotSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testResize() throws Exception{ + ExecutorService pool = Executors.newCachedThreadPool(); + + List>> futureList = new ArrayList<>(); + for (int i = 0; i < 100; i++) { + Future> future = pool.submit(() -> flowExecutor.execute2Resp("chain1", "arg")); + futureList.add(future); + } + + for(Future> future : futureList){ + Assert.assertTrue(future.get().isSuccess()); + } + + //取到static的对象QUEUE + Field field = ReflectUtil.getField(DataBus.class, "QUEUE"); + ConcurrentLinkedQueue queue = (ConcurrentLinkedQueue) ReflectUtil.getStaticFieldValue(field); + + //因为初始slotSize是4,按照0.75的扩容比,要满足100个线程,应该扩容5~6次,5次=65,6次=114 + //为什么不是直接114呢? + //因为在单测中根据机器的性能,在多线程情况下,有些机器跑的慢一点,也就是说65个就足够了。有些机器跑的快一点,是能真正扩容到114个的 + Assert.assertTrue(queue.size() > 4); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/ACmp.java new file mode 100644 index 000000000..c05adbf38 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.resizeSlot.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/BCmp.java new file mode 100644 index 000000000..4a5e5ea8d --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.resizeSlot.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/CCmp.java new file mode 100644 index 000000000..a0156105c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/resizeSlot/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.resizeSlot.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringbootTest.java new file mode 100644 index 000000000..82540c127 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/ImplicitSubFlowSpringbootTest.java @@ -0,0 +1,49 @@ +package com.yomahub.liteflow.test.subflow; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.util.HashSet; +import java.util.Set; + +/** + * 测试隐式调用子流程 + * 单元测试 + * + * @author justin.xu + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/subflow/application-implicit.properties") +@SpringBootTest(classes = ImplicitSubFlowSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp2"}) +public class ImplicitSubFlowSpringbootTest extends BaseTest { + @Resource + private FlowExecutor flowExecutor; + + public static final Set RUN_TIME_SLOT = new HashSet<>(); + + //这里GCmp中隐式的调用chain4,从而执行了h,m + @Test + public void testImplicitSubFlow() { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("f==>g==>h==>m", response.getSlot().getExecuteStepStr()); + + // 传递了slotIndex,则set的size==1 + Assert.assertEquals(1, RUN_TIME_SLOT.size()); + // set中第一次设置的requestId和response中的requestId一致 + Assert.assertTrue(RUN_TIME_SLOT.contains(response.getSlot().getRequestId())); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigSpringbootTest.java new file mode 100644 index 000000000..a3179eca9 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowInDifferentConfigSpringbootTest.java @@ -0,0 +1,54 @@ +package com.yomahub.liteflow.test.subflow; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.exception.MultipleParsersException; +import com.yomahub.liteflow.property.LiteflowConfig; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * 测试主流程与子流程在不同的配置文件的场景 + * + * @author Bryan.Zhang + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/subflow/application-subInDifferentConfig1.properties") +@SpringBootTest(classes = SubflowInDifferentConfigSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1","com.yomahub.liteflow.test.subflow.cmp2"}) +public class SubflowInDifferentConfigSpringbootTest extends BaseTest { + @Resource + private FlowExecutor flowExecutor; + + //是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow1() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>b==>a==>e==>d", response.getSlot().getExecuteStepStr()); + } + + @Autowired + private ApplicationContext context; + + //主要测试有不同的配置类型后会不会报出既定的错误 + @Test(expected = MultipleParsersException.class) + public void testExplicitSubFlow2() { + LiteflowConfig config = context.getBean(LiteflowConfig.class); + config.setRuleSource("subflow/flow-main.xml,subflow/flow-sub1.xml,subflow/flow-sub2.yml"); + flowExecutor.init(); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonSpringBootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonSpringBootTest.java new file mode 100644 index 000000000..f112252ed --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowJsonSpringBootTest.java @@ -0,0 +1,40 @@ +package com.yomahub.liteflow.test.subflow; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * 测试显示调用子流程(json) + * 单元测试 + * + * @author justin.xu + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/subflow/application-json.properties") +@SpringBootTest(classes = SubflowJsonSpringBootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"}) +public class SubflowJsonSpringBootTest extends BaseTest { + @Resource + private FlowExecutor flowExecutor; + + //是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getSlot().getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLSpringBootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLSpringBootTest.java new file mode 100644 index 000000000..96d0d7015 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowXMLSpringBootTest.java @@ -0,0 +1,40 @@ +package com.yomahub.liteflow.test.subflow; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * 测试显示调用子流程(xml) + * 单元测试 + * + * @author justin.xu + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/subflow/application-xml.properties") +@SpringBootTest(classes = SubflowXMLSpringBootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"}) +public class SubflowXMLSpringBootTest extends BaseTest { + @Resource + private FlowExecutor flowExecutor; + + //是否按照流程定义配置执行 + @Test + public void testExplicitSubFlow() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getSlot().getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlSpringBootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlSpringBootTest.java new file mode 100644 index 000000000..5b2501322 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/SubflowYmlSpringBootTest.java @@ -0,0 +1,40 @@ +package com.yomahub.liteflow.test.subflow; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * 测试显示调用子流程(yml) + * 单元测试 + * + * @author justin.xu + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/subflow/application-yml.properties") +@SpringBootTest(classes = SubflowYmlSpringBootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.subflow.cmp1"}) +public class SubflowYmlSpringBootTest extends BaseTest { + @Resource + private FlowExecutor flowExecutor; + + //是否按照流程定义配置执行 + @Test + public void testExplicitSubFlowYml() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "it's a request"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>b==>c==>b==>a==>e==>d", response.getSlot().getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java new file mode 100644 index 000000000..f20ef02ae --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ACmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.subflow.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Acomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java new file mode 100644 index 000000000..4801ac868 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/BCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.subflow.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("Bcomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java new file mode 100644 index 000000000..2ae551ea7 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/CCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.subflow.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + System.out.println("Ccomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java new file mode 100644 index 000000000..e734549c8 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/DCmp.java @@ -0,0 +1,17 @@ +package com.yomahub.liteflow.test.subflow.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + System.out.println("Dcomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java new file mode 100644 index 000000000..d8ae800cc --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp1/ECmp.java @@ -0,0 +1,18 @@ +package com.yomahub.liteflow.test.subflow.cmp1; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + + +@Component("e") +@LiteflowCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + System.out.println("Ecomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java new file mode 100644 index 000000000..f260b44a0 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/FCmp.java @@ -0,0 +1,22 @@ +package com.yomahub.liteflow.test.subflow.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringbootTest.RUN_TIME_SLOT; + + +@Component("f") +@LiteflowCmpDefine +public class FCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + + RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); + + System.out.println("Fcomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java new file mode 100644 index 000000000..ef110aea2 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/GCmp.java @@ -0,0 +1,31 @@ +package com.yomahub.liteflow.test.subflow.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringbootTest.RUN_TIME_SLOT; + + +@Component("g") +@LiteflowCmpDefine +public class GCmp{ + + @Autowired + private FlowExecutor flowExecutor; + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + + RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); + + System.out.println("Gcmp executed!"); + + flowExecutor.invoke("chain4", "it's implicit subflow.", DefaultSlot.class, bindCmp.getSlotIndex()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java new file mode 100644 index 000000000..d8c5eebf6 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/HCmp.java @@ -0,0 +1,22 @@ +package com.yomahub.liteflow.test.subflow.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringbootTest.RUN_TIME_SLOT; + + +@Component("h") +@LiteflowCmpDefine +public class HCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + + RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); + + System.out.println("Hcomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java new file mode 100644 index 000000000..199abff79 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/subflow/cmp2/MCmp.java @@ -0,0 +1,22 @@ +package com.yomahub.liteflow.test.subflow.cmp2; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +import static com.yomahub.liteflow.test.subflow.ImplicitSubFlowSpringbootTest.RUN_TIME_SLOT; + + +@Component("m") +@LiteflowCmpDefine +public class MCmp{ + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) throws Exception { + + RUN_TIME_SLOT.add(bindCmp.getSlot().getRequestId()); + + System.out.println("Mcomp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/NodeTagSpringbootJsonTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/NodeTagSpringbootJsonTest.java new file mode 100644 index 000000000..b44541270 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/NodeTagSpringbootJsonTest.java @@ -0,0 +1,67 @@ +package com.yomahub.liteflow.test.tag; + +import cn.hutool.core.collection.ConcurrentHashSet; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境下隐私投递的测试 + * @author Bryan.Zhang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/tag/application-json.properties") +@SpringBootTest(classes = NodeTagSpringbootJsonTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.tag.cmp"}) +public class NodeTagSpringbootJsonTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testTag1() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("123",response.getSlot().getData("test")); + } + + @Test + public void testTag2() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>a==>a==>c==>e", response.getSlot().getExecuteStepStr()); + } + + //测试多线程when情况下的tag取值是否正确 + //这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 + @Test + public void testTag3() throws Exception{ + for (int i = 0; i < 50; i++) { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + ConcurrentHashSet testSet = response.getSlot().getData("test"); + Assert.assertEquals(3, testSet.size()); + } + } + + //测试tag是否能在isAccess中起效 + @Test + public void testTag4() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g", response.getSlot().getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/NodeTagSpringbootXmlTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/NodeTagSpringbootXmlTest.java new file mode 100644 index 000000000..7ed257553 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/NodeTagSpringbootXmlTest.java @@ -0,0 +1,67 @@ +package com.yomahub.liteflow.test.tag; + +import cn.hutool.core.collection.ConcurrentHashSet; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境下隐私投递的测试 + * @author Bryan.Zhang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/tag/application-xml.properties") +@SpringBootTest(classes = NodeTagSpringbootXmlTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.tag.cmp"}) +public class NodeTagSpringbootXmlTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testTag1() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("123",response.getSlot().getData("test")); + } + + @Test + public void testTag2() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain2", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("a==>a==>a==>c==>e", response.getSlot().getExecuteStepStr()); + } + + //测试多线程when情况下的tag取值是否正确 + //这里循环多次的原因是,因为when多线程,有时候因为凑巧,可能正确。所以多次情况下在2.6.4版本肯定出错 + @Test + public void testTag3() throws Exception{ + for (int i = 0; i < 50; i++) { + LiteflowResponse response = flowExecutor.execute2Resp("chain3", "arg"); + Assert.assertTrue(response.isSuccess()); + ConcurrentHashSet testSet = response.getSlot().getData("test"); + Assert.assertEquals(3, testSet.size()); + } + } + + //测试tag是否能在isAccess中起效 + @Test + public void testTag4() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain4", "arg"); + Assert.assertTrue(response.isSuccess()); + Assert.assertEquals("g", response.getSlot().getExecuteStepStr()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java new file mode 100644 index 000000000..08ddb9edd --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/ACmp.java @@ -0,0 +1,34 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.tag.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + String testKey = "test"; + + Slot slot = bindCmp.getSlot(); + if (slot.getData(testKey) == null){ + slot.setData(testKey,bindCmp.getTag()); + }else{ + String s = slot.getData(testKey); + s += bindCmp.getTag(); + slot.setData(testKey, s); + } + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java new file mode 100644 index 000000000..5fb5e35e6 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/B1Cmp.java @@ -0,0 +1,27 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.tag.cmp; + +import cn.hutool.core.collection.ConcurrentHashSet; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("b1") +@LiteflowCmpDefine +public class B1Cmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + Slot slot = bindCmp.getSlot(); + slot.setData("test",new ConcurrentHashSet()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java new file mode 100644 index 000000000..06da76a82 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/BCmp.java @@ -0,0 +1,28 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.tag.cmp; + +import cn.hutool.core.collection.ConcurrentHashSet; +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.entity.data.Slot; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + Slot slot = bindCmp.getSlot(); + ConcurrentHashSet testSet = slot.getData("test"); + testSet.add(bindCmp.getTag()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java new file mode 100644 index 000000000..7639fc6ba --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/CCmp.java @@ -0,0 +1,30 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.tag.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowCondCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.core.NodeCondComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("c") +@LiteflowCondCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS_COND) + public String processCond(NodeComponent bindCmp) throws Exception { + if(bindCmp.getTag().equals("2")){ + return "e"; + }else{ + return "d"; + } + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java new file mode 100644 index 000000000..8ee32b746 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/DCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.tag.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println(bindCmp.getTag()); + System.out.println("DCmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java new file mode 100644 index 000000000..84423ee71 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/ECmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.tag.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("e") +@LiteflowCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println(bindCmp.getTag()); + System.out.println("ECmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java new file mode 100644 index 000000000..e3ea2023d --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/FCmp.java @@ -0,0 +1,29 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.tag.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("f") +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process() { + System.out.println("FCmp executed!"); + } + + @LiteflowMethod(LiteFlowMethodEnum.IS_ACCESS) + public boolean isAccess(NodeComponent bindCmp) { + return Boolean.parseBoolean(bindCmp.getTag()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java new file mode 100644 index 000000000..f8aae453c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/tag/cmp/GCmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.tag.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowComponent; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; + +@LiteflowComponent("g") +@LiteflowCmpDefine +public class GCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("GCmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java new file mode 100644 index 000000000..fee0055e5 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/TestTL.java @@ -0,0 +1,16 @@ +package com.yomahub.liteflow.test.useTTLInWhen; + +import com.alibaba.ttl.TransmittableThreadLocal; + +public class TestTL { + + public static ThreadLocal tl = new TransmittableThreadLocal<>(); + + public static String get(){ + return tl.get(); + } + + public static void set(String value){ + tl.set(value); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenSpringbootTest.java new file mode 100644 index 000000000..5d74a18a8 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/UseTTLInWhenSpringbootTest.java @@ -0,0 +1,42 @@ +package com.yomahub.liteflow.test.useTTLInWhen; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * 在when异步节点的情况下去拿ThreadLocal里的测试场景 + * @author Bryan.Zhang + * @since 2.6.3 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/useTTLInWhen/application.properties") +@SpringBootTest(classes = UseTTLInWhenSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.useTTLInWhen.cmp"}) +public class UseTTLInWhenSpringbootTest extends BaseTest { + + @Resource + private FlowExecutor flowExecutor; + + @Test + public void testUseTTLInWhen() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertEquals("hello,b", response.getSlot().getData("b")); + Assert.assertEquals("hello,c", response.getSlot().getData("c")); + Assert.assertEquals("hello,d", response.getSlot().getData("d")); + Assert.assertEquals("hello,e", response.getSlot().getData("e")); + Assert.assertEquals("hello,f", response.getSlot().getData("f")); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java new file mode 100644 index 000000000..18687b6ea --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ACmp.java @@ -0,0 +1,26 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.useTTLInWhen.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.useTTLInWhen.TestTL; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + TestTL.set("hello"); + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java new file mode 100644 index 000000000..b2e30c9b0 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/BCmp.java @@ -0,0 +1,28 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.useTTLInWhen.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.useTTLInWhen.TestTL; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + String value = TestTL.get(); + bindCmp.getSlot().setData(bindCmp.getNodeId(),value+",b"); + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java new file mode 100644 index 000000000..429eca6d4 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/CCmp.java @@ -0,0 +1,28 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.useTTLInWhen.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.useTTLInWhen.TestTL; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + String value = TestTL.get(); + bindCmp.getSlot().setData(bindCmp.getNodeId(),value+",c"); + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java new file mode 100644 index 000000000..a9e657f99 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/DCmp.java @@ -0,0 +1,28 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.useTTLInWhen.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.useTTLInWhen.TestTL; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + String value = TestTL.get(); + bindCmp.getSlot().setData(bindCmp.getNodeId(),value+",d"); + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java new file mode 100644 index 000000000..f039dbcc4 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/ECmp.java @@ -0,0 +1,28 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.useTTLInWhen.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.useTTLInWhen.TestTL; +import org.springframework.stereotype.Component; + +@Component("e") +@LiteflowCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + String value = TestTL.get(); + bindCmp.getSlot().setData(bindCmp.getNodeId(),value+",e"); + System.out.println("ECmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java new file mode 100644 index 000000000..2cb04f0ab --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/useTTLInWhen/cmp/FCmp.java @@ -0,0 +1,28 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.useTTLInWhen.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import com.yomahub.liteflow.test.useTTLInWhen.TestTL; +import org.springframework.stereotype.Component; + +@Component("f") +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + String value = TestTL.get(); + bindCmp.getSlot().setData(bindCmp.getNodeId(),value+",f"); + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest1.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest1.java new file mode 100644 index 000000000..78e6a33cf --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest1.java @@ -0,0 +1,45 @@ +package com.yomahub.liteflow.test.whenTimeOut; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.exception.WhenTimeoutException; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境下异步线程超时日志打印测试 + * @author Bryan.Zhang + * @since 2.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/whenTimeOut/application1.properties") +@SpringBootTest(classes = WhenTimeOutSpringbootTest1.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.whenTimeOut.cmp"}) +public class WhenTimeOutSpringbootTest1 extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + //其中b和c在when情况下超时,所以抛出了WhenTimeoutException这个错 + @Test + public void testWhenTimeOut() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertFalse(response.isSuccess()); + Assert.assertEquals(WhenTimeoutException.class, response.getCause().getClass()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest2.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest2.java new file mode 100644 index 000000000..74c8223f9 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/WhenTimeOutSpringbootTest2.java @@ -0,0 +1,43 @@ +package com.yomahub.liteflow.test.whenTimeOut; + +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * springboot环境下异步线程超时日志打印测试 + * @author Bryan.Zhang + * @since 2.6.4 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/whenTimeOut/application2.properties") +@SpringBootTest(classes = WhenTimeOutSpringbootTest2.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.whenTimeOut.cmp"}) +public class WhenTimeOutSpringbootTest2 extends BaseTest { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Resource + private FlowExecutor flowExecutor; + + //其中d,e,f都sleep 4秒,其中def是不同的组,超时设置5秒 + @Test + public void testWhenTimeOut() throws Exception{ + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java new file mode 100644 index 000000000..236b7093f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.whenTimeOut.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java new file mode 100644 index 000000000..6628e838e --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/BCmp.java @@ -0,0 +1,30 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.whenTimeOut.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(4000); + }catch (Exception ignored){ + + } + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java new file mode 100644 index 000000000..e26c064f6 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/CCmp.java @@ -0,0 +1,30 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.whenTimeOut.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(3500); + }catch (Exception ignored){ + + } + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java new file mode 100644 index 000000000..720a4a8b8 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/DCmp.java @@ -0,0 +1,30 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.whenTimeOut.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("d") +@LiteflowCmpDefine +public class DCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(4000); + }catch (Exception ignored){ + + } + System.out.println("DCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java new file mode 100644 index 000000000..6485ae74b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/ECmp.java @@ -0,0 +1,30 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.whenTimeOut.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("e") +@LiteflowCmpDefine +public class ECmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(4000); + }catch (Exception ignored){ + + } + System.out.println("ECmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java new file mode 100644 index 000000000..f16bda6ad --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/whenTimeOut/cmp/FCmp.java @@ -0,0 +1,30 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.whenTimeOut.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("f") +@LiteflowCmpDefine +public class FCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + try { + Thread.sleep(4000); + }catch (Exception ignored){ + + } + System.out.println("FCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithJsonSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithJsonSpringbootTest.java new file mode 100644 index 000000000..474c3fd9f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithJsonSpringbootTest.java @@ -0,0 +1,83 @@ +package com.yomahub.liteflow.test.zookeeper; + +import cn.hutool.core.io.resource.ResourceUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.I0Itec.zkclient.ZkClient; +import org.I0Itec.zkclient.exception.ZkMarshallingError; +import org.I0Itec.zkclient.serialize.ZkSerializer; +import org.apache.curator.test.TestingServer; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.nio.charset.Charset; +import java.util.concurrent.CountDownLatch; + +/** + * springboot环境下的zk配置源功能测试 + * ZK节点存储数据的格式为json文件 + * @author zendwang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/zookeeper/application-json.properties") +@SpringBootTest(classes = ZkNodeWithJsonSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.zookeeper.cmp"}) +public class ZkNodeWithJsonSpringbootTest extends BaseTest { + + private static final String ZK_NODE_PATH = "/lite-flow/flow"; + + private static TestingServer zkServer; + + @Resource + private FlowExecutor flowExecutor; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + zkServer = new TestingServer(21810); + CountDownLatch latch = new CountDownLatch(1); + new Thread(() -> { + String data = ResourceUtil.readUtf8Str("zookeeper/flow.json"); + ZkClient zkClient = new ZkClient("127.0.0.1:21810"); + zkClient.setZkSerializer(new ZkSerializer() { + @Override + public byte[] serialize(final Object o) throws ZkMarshallingError { + return o.toString().getBytes(Charset.forName("UTF-8")); + } + + @Override + public Object deserialize(final byte[] bytes) throws ZkMarshallingError { + return new String(bytes, Charset.forName("UTF-8")); + } + }); + zkClient.createPersistent(ZK_NODE_PATH, true); + zkClient.writeData(ZK_NODE_PATH, data); + zkClient.close(); + latch.countDown(); + }).start(); + latch.await(); + } + + @Test + public void testZkNodeWithJson() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + @AfterClass + public static void tearDown() throws Exception { + zkServer.stop(); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlSpringbootTest.java new file mode 100644 index 000000000..c80a72fc3 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithXmlSpringbootTest.java @@ -0,0 +1,83 @@ +package com.yomahub.liteflow.test.zookeeper; + +import cn.hutool.core.io.resource.ResourceUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.I0Itec.zkclient.ZkClient; +import org.I0Itec.zkclient.exception.ZkMarshallingError; +import org.I0Itec.zkclient.serialize.ZkSerializer; +import org.apache.curator.test.TestingServer; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.nio.charset.Charset; +import java.util.concurrent.CountDownLatch; + +/** + * springboot环境下的zk配置源功能测试 + * ZK节点存储数据的格式为xml文件 + * @author zendwang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/zookeeper/application-xml.properties") +@SpringBootTest(classes = ZkNodeWithXmlSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.zookeeper.cmp"}) +public class ZkNodeWithXmlSpringbootTest extends BaseTest { + + private static final String ZK_NODE_PATH = "/lite-flow/flow"; + + private static TestingServer zkServer; + + @Resource + private FlowExecutor flowExecutor; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + zkServer = new TestingServer(21810); + CountDownLatch latch = new CountDownLatch(1); + new Thread(() -> { + String data = ResourceUtil.readUtf8Str("zookeeper/flow.xml"); + ZkClient zkClient = new ZkClient("127.0.0.1:21810"); + zkClient.setZkSerializer(new ZkSerializer() { + @Override + public byte[] serialize(final Object o) throws ZkMarshallingError { + return o.toString().getBytes(Charset.forName("UTF-8")); + } + + @Override + public Object deserialize(final byte[] bytes) throws ZkMarshallingError { + return new String(bytes, Charset.forName("UTF-8")); + } + }); + zkClient.createPersistent(ZK_NODE_PATH, true); + zkClient.writeData(ZK_NODE_PATH, data); + zkClient.close(); + latch.countDown(); + }).start(); + latch.await(); + } + + @Test + public void testZkNodeWithXml() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + @AfterClass + public static void tearDown() throws Exception { + zkServer.stop(); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithYmlSpringbootTest.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithYmlSpringbootTest.java new file mode 100644 index 000000000..5cc62daae --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/ZkNodeWithYmlSpringbootTest.java @@ -0,0 +1,83 @@ +package com.yomahub.liteflow.test.zookeeper; + +import cn.hutool.core.io.resource.ResourceUtil; +import com.yomahub.liteflow.core.FlowExecutor; +import com.yomahub.liteflow.entity.data.DefaultSlot; +import com.yomahub.liteflow.entity.data.LiteflowResponse; +import com.yomahub.liteflow.test.BaseTest; +import org.I0Itec.zkclient.ZkClient; +import org.I0Itec.zkclient.exception.ZkMarshallingError; +import org.I0Itec.zkclient.serialize.ZkSerializer; +import org.apache.curator.test.TestingServer; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; +import java.nio.charset.Charset; +import java.util.concurrent.CountDownLatch; + +/** + * springboot环境下的zk配置源功能测试 + * ZK节点存储数据的格式为yml文件 + * @author zendwang + * @since 2.5.0 + */ +@RunWith(SpringRunner.class) +@TestPropertySource(value = "classpath:/zookeeper/application-yml.properties") +@SpringBootTest(classes = ZkNodeWithYmlSpringbootTest.class) +@EnableAutoConfiguration +@ComponentScan({"com.yomahub.liteflow.test.zookeeper.cmp"}) +public class ZkNodeWithYmlSpringbootTest extends BaseTest { + + private static final String ZK_NODE_PATH = "/lite-flow/flow"; + + private static TestingServer zkServer; + + @Resource + private FlowExecutor flowExecutor; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + zkServer = new TestingServer(21810); + CountDownLatch latch = new CountDownLatch(1); + new Thread(() -> { + String data = ResourceUtil.readUtf8Str("zookeeper/flow.yml"); + ZkClient zkClient = new ZkClient("127.0.0.1:21810"); + zkClient.setZkSerializer(new ZkSerializer() { + @Override + public byte[] serialize(final Object o) throws ZkMarshallingError { + return o.toString().getBytes(Charset.forName("UTF-8")); + } + + @Override + public Object deserialize(final byte[] bytes) throws ZkMarshallingError { + return new String(bytes, Charset.forName("UTF-8")); + } + }); + zkClient.createPersistent(ZK_NODE_PATH, true); + zkClient.writeData(ZK_NODE_PATH, data); + zkClient.close(); + latch.countDown(); + }).start(); + latch.await(); + } + + @Test + public void testZkNodeWithYml() { + LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg"); + Assert.assertTrue(response.isSuccess()); + } + + @AfterClass + public static void tearDown() throws Exception { + zkServer.stop(); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/ACmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/ACmp.java new file mode 100644 index 000000000..31ae50e37 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/ACmp.java @@ -0,0 +1,24 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.zookeeper.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("a") +@LiteflowCmpDefine +public class ACmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("ACmp executed!"); + } +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/BCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/BCmp.java new file mode 100644 index 000000000..0599bc17f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/BCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.zookeeper.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("b") +@LiteflowCmpDefine +public class BCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("BCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/CCmp.java b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/CCmp.java new file mode 100644 index 000000000..cddcc3365 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/java/com/yomahub/liteflow/test/zookeeper/cmp/CCmp.java @@ -0,0 +1,25 @@ +/** + *

Title: liteflow

+ *

Description: 轻量级的组件式流程框架

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2020/4/1 + */ +package com.yomahub.liteflow.test.zookeeper.cmp; + +import com.yomahub.liteflow.annotation.LiteflowCmpDefine; +import com.yomahub.liteflow.annotation.LiteflowMethod; +import com.yomahub.liteflow.core.NodeComponent; +import com.yomahub.liteflow.enums.LiteFlowMethodEnum; +import org.springframework.stereotype.Component; + +@Component("c") +@LiteflowCmpDefine +public class CCmp{ + + @LiteflowMethod(LiteFlowMethodEnum.PROCESS) + public void process(NodeComponent bindCmp) { + System.out.println("CCmp executed!"); + } + +} diff --git a/liteflow-testcase-declare-component/src/test/resources/absoluteConfigPath/application.properties b/liteflow-testcase-declare-component/src/test/resources/absoluteConfigPath/application.properties new file mode 100644 index 000000000..55fe91fd8 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/absoluteConfigPath/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=/usr/local/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/absoluteConfigPath/flow.xml b/liteflow-testcase-declare-component/src/test/resources/absoluteConfigPath/flow.xml new file mode 100644 index 000000000..a6fda5aa0 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/absoluteConfigPath/flow.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/aop/application.properties b/liteflow-testcase-declare-component/src/test/resources/aop/application.properties new file mode 100644 index 000000000..f9075d1c6 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/aop/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=aop/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/aop/flow.xml b/liteflow-testcase-declare-component/src/test/resources/aop/flow.xml new file mode 100644 index 000000000..84e8d4588 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/aop/flow.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/asyncNode/application.properties b/liteflow-testcase-declare-component/src/test/resources/asyncNode/application.properties new file mode 100644 index 000000000..db0c76e72 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/asyncNode/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=asyncNode/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/asyncNode/flow.xml b/liteflow-testcase-declare-component/src/test/resources/asyncNode/flow.xml new file mode 100644 index 000000000..e81546bb6 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/asyncNode/flow.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/base/application.properties b/liteflow-testcase-declare-component/src/test/resources/base/application.properties new file mode 100644 index 000000000..cf3ccb24b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/base/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=base/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/base/flow.xml b/liteflow-testcase-declare-component/src/test/resources/base/flow.xml new file mode 100644 index 000000000..7068d6cee --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/base/flow.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/cmpRetry/application.properties b/liteflow-testcase-declare-component/src/test/resources/cmpRetry/application.properties new file mode 100644 index 000000000..bd5d04cdb --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/cmpRetry/application.properties @@ -0,0 +1,3 @@ +liteflow.rule-source=cmpRetry/flow.xml +liteflow.retry-count=3 +liteflow.slot-size=512 \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/cmpRetry/flow.xml b/liteflow-testcase-declare-component/src/test/resources/cmpRetry/flow.xml new file mode 100644 index 000000000..d44e3ee05 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/cmpRetry/flow.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/component/application.properties b/liteflow-testcase-declare-component/src/test/resources/component/application.properties new file mode 100644 index 000000000..d5b0e66d5 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/component/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=component/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/component/flow.xml b/liteflow-testcase-declare-component/src/test/resources/component/flow.xml new file mode 100644 index 000000000..2a504fd01 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/component/flow.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/config/aaa/bbb/flow1.xml b/liteflow-testcase-declare-component/src/test/resources/config/aaa/bbb/flow1.xml new file mode 100644 index 000000000..ced398c9b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/config/aaa/bbb/flow1.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/config/aaa/flow0.xml b/liteflow-testcase-declare-component/src/test/resources/config/aaa/flow0.xml new file mode 100644 index 000000000..22870d94f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/config/aaa/flow0.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/config/application1.properties b/liteflow-testcase-declare-component/src/test/resources/config/application1.properties new file mode 100644 index 000000000..4ac6c4d63 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/config/application1.properties @@ -0,0 +1 @@ +liteflow.rule-source=config/flow.yml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/config/application2.properties b/liteflow-testcase-declare-component/src/test/resources/config/application2.properties new file mode 100644 index 000000000..5079ac3d2 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/config/application2.properties @@ -0,0 +1 @@ +liteflow.rule-source=config/**/flow*.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/config/flow.yml b/liteflow-testcase-declare-component/src/test/resources/config/flow.yml new file mode 100644 index 000000000..3cdaced3e --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/config/flow.yml @@ -0,0 +1,6 @@ +flow: + chain: + - name: chain1 + condition: + - type: then + value: 'a,b,c' diff --git a/liteflow-testcase-declare-component/src/test/resources/customNodes/application.properties b/liteflow-testcase-declare-component/src/test/resources/customNodes/application.properties new file mode 100644 index 000000000..ab7716a61 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/customNodes/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=customNodes/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/customNodes/flow.xml b/liteflow-testcase-declare-component/src/test/resources/customNodes/flow.xml new file mode 100644 index 000000000..ecc1abcd6 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/customNodes/flow.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/customWhenThreadPool/application.properties b/liteflow-testcase-declare-component/src/test/resources/customWhenThreadPool/application.properties new file mode 100644 index 000000000..3447aaa3f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/customWhenThreadPool/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=customWhenThreadPool/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/customWhenThreadPool/flow.xml b/liteflow-testcase-declare-component/src/test/resources/customWhenThreadPool/flow.xml new file mode 100644 index 000000000..c6f199ddb --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/customWhenThreadPool/flow.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/deadLoopChain/application.properties b/liteflow-testcase-declare-component/src/test/resources/deadLoopChain/application.properties new file mode 100644 index 000000000..8e35187c2 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/deadLoopChain/application.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=deadLoopChain/flow.xml +liteflow.parse-on-start=false \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/deadLoopChain/flow.xml b/liteflow-testcase-declare-component/src/test/resources/deadLoopChain/flow.xml new file mode 100644 index 000000000..ca6e1c3f7 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/deadLoopChain/flow.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/emptyFlow/application.properties b/liteflow-testcase-declare-component/src/test/resources/emptyFlow/application.properties new file mode 100644 index 000000000..953c02066 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/emptyFlow/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=emptyFlow/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/emptyFlow/flow.xml b/liteflow-testcase-declare-component/src/test/resources/emptyFlow/flow.xml new file mode 100644 index 000000000..e69de29bb diff --git a/liteflow-testcase-declare-component/src/test/resources/enable/application.properties b/liteflow-testcase-declare-component/src/test/resources/enable/application.properties new file mode 100644 index 000000000..64bcf0011 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/enable/application.properties @@ -0,0 +1,2 @@ +liteflow.enable=false +liteflow.rule-source=enable/flow.xml diff --git a/liteflow-testcase-declare-component/src/test/resources/enable/flow.xml b/liteflow-testcase-declare-component/src/test/resources/enable/flow.xml new file mode 100644 index 000000000..22870d94f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/enable/flow.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/exception/application.properties b/liteflow-testcase-declare-component/src/test/resources/exception/application.properties new file mode 100644 index 000000000..79b39156f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/exception/application.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=exception/flow.xml +liteflow.when-max-wait-seconds=1 \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/exception/flow.xml b/liteflow-testcase-declare-component/src/test/resources/exception/flow.xml new file mode 100644 index 000000000..e975ef328 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/exception/flow.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/execute2Future/application.properties b/liteflow-testcase-declare-component/src/test/resources/execute2Future/application.properties new file mode 100644 index 000000000..1545d0a13 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/execute2Future/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=execute2Future/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/execute2Future/flow.xml b/liteflow-testcase-declare-component/src/test/resources/execute2Future/flow.xml new file mode 100644 index 000000000..a7517a2cf --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/execute2Future/flow.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/flowmeta/application.properties b/liteflow-testcase-declare-component/src/test/resources/flowmeta/application.properties new file mode 100644 index 000000000..83834c85b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/flowmeta/application.properties @@ -0,0 +1,2 @@ +liteflow.rule-source=flowmeta/flow.xml +liteflow.parse-on-start=false \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/flowmeta/flow.xml b/liteflow-testcase-declare-component/src/test/resources/flowmeta/flow.xml new file mode 100644 index 000000000..7153add87 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/flowmeta/flow.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/lazy/application.properties b/liteflow-testcase-declare-component/src/test/resources/lazy/application.properties new file mode 100644 index 000000000..372a320c8 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/lazy/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=lazy/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/lazy/flow.xml b/liteflow-testcase-declare-component/src/test/resources/lazy/flow.xml new file mode 100644 index 000000000..22870d94f --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/lazy/flow.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/liteflowComponent/application.properties b/liteflow-testcase-declare-component/src/test/resources/liteflowComponent/application.properties new file mode 100644 index 000000000..62a916d4a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/liteflowComponent/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=liteflowComponent/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/liteflowComponent/flow.xml b/liteflow-testcase-declare-component/src/test/resources/liteflowComponent/flow.xml new file mode 100644 index 000000000..62def0c37 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/liteflowComponent/flow.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/monitor/application.properties b/liteflow-testcase-declare-component/src/test/resources/monitor/application.properties new file mode 100644 index 000000000..ee78cdf43 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/monitor/application.properties @@ -0,0 +1,5 @@ +liteflow.rule-source=monitor/flow.xml +liteflow.monitor.enable-log=true +liteflow.monitor.queue-limit=200 +liteflow.monitor.delay=5000 +liteflow.monitor.period=5000 \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/monitor/flow.xml b/liteflow-testcase-declare-component/src/test/resources/monitor/flow.xml new file mode 100644 index 000000000..e8ea83f95 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/monitor/flow.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/multipleType/application.properties b/liteflow-testcase-declare-component/src/test/resources/multipleType/application.properties new file mode 100644 index 000000000..a6da8abe5 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/multipleType/application.properties @@ -0,0 +1,2 @@ +liteflow.support-multiple-type=true +liteflow.rule-source=multipleType/flow.xml,multipleType/flow.yml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/multipleType/flow.xml b/liteflow-testcase-declare-component/src/test/resources/multipleType/flow.xml new file mode 100644 index 000000000..38b703214 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/multipleType/flow.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/multipleType/flow.yml b/liteflow-testcase-declare-component/src/test/resources/multipleType/flow.yml new file mode 100644 index 000000000..4c1d8375a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/multipleType/flow.yml @@ -0,0 +1,6 @@ +flow: + chain: + - name: chain3 + condition: + - type: then + value: 'a,b,c' diff --git a/liteflow-testcase-declare-component/src/test/resources/nodeExecutor/application.properties b/liteflow-testcase-declare-component/src/test/resources/nodeExecutor/application.properties new file mode 100644 index 000000000..b2ca1d088 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/nodeExecutor/application.properties @@ -0,0 +1,4 @@ +liteflow.rule-source=nodeExecutor/flow.xml +liteflow.retry-count=3 +liteflow.slot-size=512 +liteflow.node-executor-class=com.yomahub.liteflow.test.nodeExecutor.CustomerDefaultNodeExecutor \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/nodeExecutor/flow.xml b/liteflow-testcase-declare-component/src/test/resources/nodeExecutor/flow.xml new file mode 100644 index 000000000..6b867c5bc --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/nodeExecutor/flow.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/nullParam/application.properties b/liteflow-testcase-declare-component/src/test/resources/nullParam/application.properties new file mode 100644 index 000000000..7f320b595 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/nullParam/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=nullParam/flow.xml diff --git a/liteflow-testcase-declare-component/src/test/resources/nullParam/flow.xml b/liteflow-testcase-declare-component/src/test/resources/nullParam/flow.xml new file mode 100644 index 000000000..eb30c8e40 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/nullParam/flow.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/liteflow-testcase-declare-component/src/test/resources/parsecustom/application-custom-json.properties b/liteflow-testcase-declare-component/src/test/resources/parsecustom/application-custom-json.properties new file mode 100644 index 000000000..989a199c9 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/parsecustom/application-custom-json.properties @@ -0,0 +1 @@ +liteflow.rule-source=com.yomahub.liteflow.test.parsecustom.parser.CustomJsonFlowParser \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/parsecustom/application-custom-xml.properties b/liteflow-testcase-declare-component/src/test/resources/parsecustom/application-custom-xml.properties new file mode 100644 index 000000000..c1763fe16 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/parsecustom/application-custom-xml.properties @@ -0,0 +1 @@ +liteflow.rule-source=com.yomahub.liteflow.test.parsecustom.parser.CustomXmlFlowParser \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/parser/application-json.properties b/liteflow-testcase-declare-component/src/test/resources/parser/application-json.properties new file mode 100644 index 000000000..e8b247226 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/parser/application-json.properties @@ -0,0 +1 @@ +liteflow.rule-source=parser/flow.json \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/parser/application-springEL.properties b/liteflow-testcase-declare-component/src/test/resources/parser/application-springEL.properties new file mode 100644 index 000000000..7db93206b --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/parser/application-springEL.properties @@ -0,0 +1 @@ +liteflow.rule-source=parser/**/*.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/parser/application-xml.properties b/liteflow-testcase-declare-component/src/test/resources/parser/application-xml.properties new file mode 100644 index 000000000..d8aacc36c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/parser/application-xml.properties @@ -0,0 +1 @@ +liteflow.rule-source=parser/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/parser/application-yml.properties b/liteflow-testcase-declare-component/src/test/resources/parser/application-yml.properties new file mode 100644 index 000000000..e0680a12c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/parser/application-yml.properties @@ -0,0 +1 @@ +liteflow.rule-source=parser/flow.yml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/parser/flow.json b/liteflow-testcase-declare-component/src/test/resources/parser/flow.json new file mode 100644 index 000000000..52d0d05c0 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/parser/flow.json @@ -0,0 +1,52 @@ +{ + "flow": { + "nodes": { + "node": [ + { + "id": "a", + "class": "com.yomahub.liteflow.test.parser.cmp.ACmp" + }, + { + "id": "b", + "class": "com.yomahub.liteflow.test.parser.cmp.BCmp" + }, + { + "id": "c", + "class": "com.yomahub.liteflow.test.parser.cmp.CCmp" + }, + { + "id": "d", + "class": "com.yomahub.liteflow.test.parser.cmp.DCmp" + }, + { + "id": "e", + "class": "com.yomahub.liteflow.test.parser.cmp.ECmp" + }, + { + "id": "f", + "class": "com.yomahub.liteflow.test.parser.cmp.FCmp" + }, + { + "id": "g", + "class": "com.yomahub.liteflow.test.parser.cmp.GCmp" + } + ] + }, + "chain": [ + { + "name": "chain2", + "condition": [ + {"type": "then", "value": "c,g,f"} + ] + }, + { + "name": "chain1", + "condition": [ + {"type": "then", "value": "a,c"}, + {"type": "when", "value": "b,d,e(f|g)"}, + {"type": "then", "value": "chain2"} + ] + } + ] + } +} \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/parser/flow.xml b/liteflow-testcase-declare-component/src/test/resources/parser/flow.xml new file mode 100644 index 000000000..0775c5ec1 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/parser/flow.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/parser/flow.yml b/liteflow-testcase-declare-component/src/test/resources/parser/flow.yml new file mode 100644 index 000000000..814f59d54 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/parser/flow.yml @@ -0,0 +1,30 @@ +flow: + nodes: + node: + - id: a + class: com.yomahub.liteflow.test.parser.cmp.ACmp + - id: b + class: com.yomahub.liteflow.test.parser.cmp.BCmp + - id: c + class: com.yomahub.liteflow.test.parser.cmp.CCmp + - id: d + class: com.yomahub.liteflow.test.parser.cmp.DCmp + - id: e + class: com.yomahub.liteflow.test.parser.cmp.ECmp + - id: f + class: com.yomahub.liteflow.test.parser.cmp.FCmp + - id: g + class: com.yomahub.liteflow.test.parser.cmp.GCmp + chain: + - name: chain1 + condition: + - type: then + value: 'a,c' + - type: when + value: 'b,d,e(f|g)' + - type: then + value: 'chain2' + - name: chain2 + condition: + - type: then + value: 'c,g,f' diff --git a/liteflow-testcase-declare-component/src/test/resources/parser/subFoder1/subFoder2/flow1.xml b/liteflow-testcase-declare-component/src/test/resources/parser/subFoder1/subFoder2/flow1.xml new file mode 100644 index 000000000..0775c5ec1 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/parser/subFoder1/subFoder2/flow1.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/parser/subFoder1/subFoder2/flow2.xml b/liteflow-testcase-declare-component/src/test/resources/parser/subFoder1/subFoder2/flow2.xml new file mode 100644 index 000000000..d739f6b53 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/parser/subFoder1/subFoder2/flow2.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/parser/subFoder1/subFoder2/flow3.xml b/liteflow-testcase-declare-component/src/test/resources/parser/subFoder1/subFoder2/flow3.xml new file mode 100644 index 000000000..0a898126c --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/parser/subFoder1/subFoder2/flow3.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/preAndFinally/application.properties b/liteflow-testcase-declare-component/src/test/resources/preAndFinally/application.properties new file mode 100644 index 000000000..9ea8432e6 --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/preAndFinally/application.properties @@ -0,0 +1 @@ +liteflow.rule-source=preAndFinally/flow.xml \ No newline at end of file diff --git a/liteflow-testcase-declare-component/src/test/resources/preAndFinally/flow.xml b/liteflow-testcase-declare-component/src/test/resources/preAndFinally/flow.xml new file mode 100644 index 000000000..5dac9fb0a --- /dev/null +++ b/liteflow-testcase-declare-component/src/test/resources/preAndFinally/flow.xml @@ -0,0 +1,26 @@ + + + +
+        
+        
+    
+
+    
+        
+        
+        
+        
+    
+
+    
+        
+        
+        
+    
+
+    
+        
+        
+    
+
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/privateDelivery/application.properties b/liteflow-testcase-declare-component/src/test/resources/privateDelivery/application.properties
new file mode 100644
index 000000000..c515ad389
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/privateDelivery/application.properties
@@ -0,0 +1 @@
+liteflow.rule-source=privateDelivery/flow.xml
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/privateDelivery/flow.xml b/liteflow-testcase-declare-component/src/test/resources/privateDelivery/flow.xml
new file mode 100644
index 000000000..bf7146217
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/privateDelivery/flow.xml
@@ -0,0 +1,18 @@
+
+
+    
+        
+        
+        
+        
+        
+        
+        
+        
+        
+        
+        
+        
+        
+    
+
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/refreshRule/application.properties b/liteflow-testcase-declare-component/src/test/resources/refreshRule/application.properties
new file mode 100644
index 000000000..174501a6c
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/refreshRule/application.properties
@@ -0,0 +1 @@
+liteflow.rule-source=refreshRule/flow.xml
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/refreshRule/flow.xml b/liteflow-testcase-declare-component/src/test/resources/refreshRule/flow.xml
new file mode 100644
index 000000000..22870d94f
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/refreshRule/flow.xml
@@ -0,0 +1,6 @@
+
+
+    
+        
+    
+
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/refreshRule/flow_update.xml b/liteflow-testcase-declare-component/src/test/resources/refreshRule/flow_update.xml
new file mode 100644
index 000000000..29090f04a
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/refreshRule/flow_update.xml
@@ -0,0 +1,6 @@
+
+
+    
+        
+    
+
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/reload/application.properties b/liteflow-testcase-declare-component/src/test/resources/reload/application.properties
new file mode 100644
index 000000000..5150bc23e
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/reload/application.properties
@@ -0,0 +1 @@
+liteflow.rule-source=reload/flow.xml
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/reload/flow.xml b/liteflow-testcase-declare-component/src/test/resources/reload/flow.xml
new file mode 100644
index 000000000..22870d94f
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/reload/flow.xml
@@ -0,0 +1,6 @@
+
+
+    
+        
+    
+
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/removeChain/application.properties b/liteflow-testcase-declare-component/src/test/resources/removeChain/application.properties
new file mode 100644
index 000000000..729879505
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/removeChain/application.properties
@@ -0,0 +1 @@
+liteflow.rule-source=removeChain/flow.xml
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/removeChain/flow.xml b/liteflow-testcase-declare-component/src/test/resources/removeChain/flow.xml
new file mode 100644
index 000000000..c89c44473
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/removeChain/flow.xml
@@ -0,0 +1,11 @@
+
+
+    
+        
+        
+    
+
+    
+        
+    
+
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/resizeSlot/application.properties b/liteflow-testcase-declare-component/src/test/resources/resizeSlot/application.properties
new file mode 100644
index 000000000..6bea4bd1c
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/resizeSlot/application.properties
@@ -0,0 +1,2 @@
+liteflow.rule-source=resizeSlot/flow.xml
+liteflow.slot-size=4
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/resizeSlot/flow.xml b/liteflow-testcase-declare-component/src/test/resources/resizeSlot/flow.xml
new file mode 100644
index 000000000..22870d94f
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/resizeSlot/flow.xml
@@ -0,0 +1,6 @@
+
+
+    
+        
+    
+
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/application-implicit.properties b/liteflow-testcase-declare-component/src/test/resources/subflow/application-implicit.properties
new file mode 100644
index 000000000..3fc4f024e
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/subflow/application-implicit.properties
@@ -0,0 +1 @@
+liteflow.rule-source=subflow/flow-implicit.xml
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/application-json.properties b/liteflow-testcase-declare-component/src/test/resources/subflow/application-json.properties
new file mode 100644
index 000000000..7ca7b7bec
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/subflow/application-json.properties
@@ -0,0 +1 @@
+liteflow.rule-source=subflow/flow.json
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/application-subInDifferentConfig1.properties b/liteflow-testcase-declare-component/src/test/resources/subflow/application-subInDifferentConfig1.properties
new file mode 100644
index 000000000..8c77ba82c
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/subflow/application-subInDifferentConfig1.properties
@@ -0,0 +1 @@
+liteflow.rule-source=subflow/flow-main.xml,subflow/flow-sub1.xml,subflow/flow-sub2.xml
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/application-subInDifferentConfig2.properties b/liteflow-testcase-declare-component/src/test/resources/subflow/application-subInDifferentConfig2.properties
new file mode 100644
index 000000000..e02c3b6a9
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/subflow/application-subInDifferentConfig2.properties
@@ -0,0 +1 @@
+liteflow.rule-source=subflow/flow-main.xml,subflow/flow-sub1.xml,subflow/flow-sub2.yml
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/application-xml.properties b/liteflow-testcase-declare-component/src/test/resources/subflow/application-xml.properties
new file mode 100644
index 000000000..1abd50496
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/subflow/application-xml.properties
@@ -0,0 +1 @@
+liteflow.rule-source=subflow/flow.xml
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/application-yml.properties b/liteflow-testcase-declare-component/src/test/resources/subflow/application-yml.properties
new file mode 100644
index 000000000..72074ec82
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/subflow/application-yml.properties
@@ -0,0 +1 @@
+liteflow.rule-source=subflow/flow.yml
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/flow-implicit.xml b/liteflow-testcase-declare-component/src/test/resources/subflow/flow-implicit.xml
new file mode 100644
index 000000000..5baca7072
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/subflow/flow-implicit.xml
@@ -0,0 +1,11 @@
+
+
+    
+         
+    
+
+    
+        
+    
+    
+
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/flow-main.xml b/liteflow-testcase-declare-component/src/test/resources/subflow/flow-main.xml
new file mode 100644
index 000000000..0adf54fc4
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/subflow/flow-main.xml
@@ -0,0 +1,7 @@
+
+
+    
+        
+         
+    
+
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/flow-sub1.xml b/liteflow-testcase-declare-component/src/test/resources/subflow/flow-sub1.xml
new file mode 100644
index 000000000..471dee3fe
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/subflow/flow-sub1.xml
@@ -0,0 +1,7 @@
+
+
+    
+        
+        
+    
+
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/flow-sub2.xml b/liteflow-testcase-declare-component/src/test/resources/subflow/flow-sub2.xml
new file mode 100644
index 000000000..63dd964bf
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/subflow/flow-sub2.xml
@@ -0,0 +1,6 @@
+
+
+    
+        
+    
+
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/flow-sub2.yml b/liteflow-testcase-declare-component/src/test/resources/subflow/flow-sub2.yml
new file mode 100644
index 000000000..8ba43c102
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/subflow/flow-sub2.yml
@@ -0,0 +1,6 @@
+flow:
+  chain:
+    - name: chain3
+      condition:
+        - type: then
+          value: 'e,d'
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/flow.json b/liteflow-testcase-declare-component/src/test/resources/subflow/flow.json
new file mode 100644
index 000000000..143589315
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/subflow/flow.json
@@ -0,0 +1,33 @@
+{
+  "flow": {
+    "chain": [
+      {
+        "name": "chain3",
+        "condition": [
+          {"type": "then", "value": "e,d"}
+        ]
+      },
+      {
+        "name": "chain2",
+        "condition": [
+          {"type": "then", "value": "b,a"},
+          {"type": "then", "value": "chain3"}
+        ]
+      },
+      {
+        "name": "chain1",
+        "condition": [
+          {"type": "then", "value": "a,b"},
+          {"type": "then", "value": "c"},
+          {"type": "then", "value": "chain2"}
+        ]
+      },
+      {
+        "name": "c",
+        "condition": [
+          {"type": "then", "value": "d,e"}
+        ]
+      }
+    ]
+  }
+}
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/flow.xml b/liteflow-testcase-declare-component/src/test/resources/subflow/flow.xml
new file mode 100644
index 000000000..03cf81299
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/subflow/flow.xml
@@ -0,0 +1,22 @@
+
+
+    
+        
+           
+         
+    
+
+    
+        
+    
+
+    
+        
+        
+    
+
+    
+        
+    
+    
+
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/subflow/flow.yml b/liteflow-testcase-declare-component/src/test/resources/subflow/flow.yml
new file mode 100644
index 000000000..cdd8de74b
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/subflow/flow.yml
@@ -0,0 +1,24 @@
+flow:
+  chain:
+    - name: chain3
+      condition:
+        - type: then
+          value: 'e,d'
+    - name: chain1
+      condition:
+        - type: then
+          value: 'a,b'
+        - type: then
+          value: 'c'
+        - type: then
+          value: 'chain2'
+    - name: c
+      condition:
+        - type: then
+          value: 'd,e'
+    - name: chain2
+      condition:
+        - type: then
+          value: 'b,a'
+        - type: then
+          value: 'chain3'
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/tag/application-json.properties b/liteflow-testcase-declare-component/src/test/resources/tag/application-json.properties
new file mode 100644
index 000000000..2f9c09d4e
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/tag/application-json.properties
@@ -0,0 +1 @@
+liteflow.rule-source=tag/flow.json
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/tag/application-xml.properties b/liteflow-testcase-declare-component/src/test/resources/tag/application-xml.properties
new file mode 100644
index 000000000..cc52d7cbc
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/tag/application-xml.properties
@@ -0,0 +1 @@
+liteflow.rule-source=tag/flow.xml
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/tag/flow.json b/liteflow-testcase-declare-component/src/test/resources/tag/flow.json
new file mode 100644
index 000000000..49c902e4a
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/tag/flow.json
@@ -0,0 +1,31 @@
+{
+  "flow": {
+    "chain": [
+      {
+        "name": "chain1",
+        "condition": [
+          {"type": "then", "value": "a[1],a[2],a[3]"}
+        ]
+      },
+      {
+        "name": "chain2",
+        "condition": [
+          {"type": "then", "value": "a[1],a[2],a[3],c[2](d[5]|e[6])"}
+        ]
+      },
+      {
+        "name": "chain3",
+        "condition": [
+          {"type": "then", "value": "b1"},
+          {"type": "when", "value": "b[1],b[2],b[3]"}
+        ]
+      },
+      {
+        "name": "chain4",
+        "condition": [
+          {"type": "then", "value": "f[false],g"}
+        ]
+      }
+    ]
+  }
+}
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/tag/flow.xml b/liteflow-testcase-declare-component/src/test/resources/tag/flow.xml
new file mode 100644
index 000000000..b7ceb903d
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/tag/flow.xml
@@ -0,0 +1,19 @@
+
+
+    
+        
+    
+
+    
+        
+    
+
+    
+        
+        
+    
+
+    
+        
+    
+
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/useTTLInWhen/application.properties b/liteflow-testcase-declare-component/src/test/resources/useTTLInWhen/application.properties
new file mode 100644
index 000000000..58d40f9ab
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/useTTLInWhen/application.properties
@@ -0,0 +1,2 @@
+liteflow.rule-source=useTTLInWhen/flow.xml
+liteflow.when-max-workers=2
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/useTTLInWhen/flow.xml b/liteflow-testcase-declare-component/src/test/resources/useTTLInWhen/flow.xml
new file mode 100644
index 000000000..af6d2ef54
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/useTTLInWhen/flow.xml
@@ -0,0 +1,7 @@
+
+
+    
+        
+        
+    
+
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/whenTimeOut/application1.properties b/liteflow-testcase-declare-component/src/test/resources/whenTimeOut/application1.properties
new file mode 100644
index 000000000..05eb9ab0e
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/whenTimeOut/application1.properties
@@ -0,0 +1,2 @@
+liteflow.rule-source=whenTimeOut/flow1.xml
+liteflow.when-max-wait-seconds=3
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/whenTimeOut/application2.properties b/liteflow-testcase-declare-component/src/test/resources/whenTimeOut/application2.properties
new file mode 100644
index 000000000..b90ff9c36
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/whenTimeOut/application2.properties
@@ -0,0 +1,2 @@
+liteflow.rule-source=whenTimeOut/flow2.xml
+liteflow.when-max-wait-seconds=5
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/whenTimeOut/flow1.xml b/liteflow-testcase-declare-component/src/test/resources/whenTimeOut/flow1.xml
new file mode 100644
index 000000000..657f64cc3
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/whenTimeOut/flow1.xml
@@ -0,0 +1,6 @@
+
+
+    
+        
+    
+
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/whenTimeOut/flow2.xml b/liteflow-testcase-declare-component/src/test/resources/whenTimeOut/flow2.xml
new file mode 100644
index 000000000..6586ab0b8
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/whenTimeOut/flow2.xml
@@ -0,0 +1,8 @@
+
+
+    
+        
+        
+        
+    
+
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/zookeeper/application-json.properties b/liteflow-testcase-declare-component/src/test/resources/zookeeper/application-json.properties
new file mode 100644
index 000000000..50d6ddca7
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/zookeeper/application-json.properties
@@ -0,0 +1 @@
+liteflow.rule-source=json:127.0.0.1:21810
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/zookeeper/application-xml.properties b/liteflow-testcase-declare-component/src/test/resources/zookeeper/application-xml.properties
new file mode 100644
index 000000000..e56e99757
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/zookeeper/application-xml.properties
@@ -0,0 +1 @@
+liteflow.rule-source=xml:127.0.0.1:21810
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/zookeeper/application-yml.properties b/liteflow-testcase-declare-component/src/test/resources/zookeeper/application-yml.properties
new file mode 100644
index 000000000..9c88b3fd3
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/zookeeper/application-yml.properties
@@ -0,0 +1 @@
+liteflow.rule-source=yml:127.0.0.1:21810
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/zookeeper/flow.json b/liteflow-testcase-declare-component/src/test/resources/zookeeper/flow.json
new file mode 100644
index 000000000..24615d628
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/zookeeper/flow.json
@@ -0,0 +1,12 @@
+{
+  "flow": {
+    "chain": [
+      {
+        "name": "chain1",
+        "condition": [
+          {"type": "then", "value": "a,b,c"}
+        ]
+      }
+    ]
+  }
+}
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/zookeeper/flow.xml b/liteflow-testcase-declare-component/src/test/resources/zookeeper/flow.xml
new file mode 100644
index 000000000..22870d94f
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/zookeeper/flow.xml
@@ -0,0 +1,6 @@
+
+
+    
+        
+    
+
\ No newline at end of file
diff --git a/liteflow-testcase-declare-component/src/test/resources/zookeeper/flow.yml b/liteflow-testcase-declare-component/src/test/resources/zookeeper/flow.yml
new file mode 100644
index 000000000..3cdaced3e
--- /dev/null
+++ b/liteflow-testcase-declare-component/src/test/resources/zookeeper/flow.yml
@@ -0,0 +1,6 @@
+flow:
+  chain:
+    - name: chain1
+      condition:
+        - type: then
+          value: 'a,b,c'
diff --git a/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeTest.java b/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeTest.java
index acc563cfe..0988be134 100644
--- a/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeTest.java
+++ b/liteflow-testcase-nospring/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeTest.java
@@ -28,7 +28,7 @@ public class LiteflowMultipleTypeTest extends BaseTest {
     }
 
     @Test
-    public void testConfig() {
+    public void testMultipleType() {
         LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
         Assert.assertTrue(response.isSuccess());
         Assert.assertEquals("a==>b==>c==>b==>a", response.getSlot().getExecuteStepStr());
diff --git a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringbootTest.java b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringbootTest.java
index 20d2c85df..91ef144e4 100644
--- a/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringbootTest.java
+++ b/liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringbootTest.java
@@ -31,7 +31,7 @@ public class LiteflowMultipleTypeSpringbootTest extends BaseTest {
     private FlowExecutor flowExecutor;
 
     @Test
-    public void testConfig() {
+    public void testMultipleType() {
         LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
         Assert.assertTrue(response.isSuccess());
         Assert.assertEquals("a==>b==>c==>b==>a", response.getSlot().getExecuteStepStr());
diff --git a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringTest.java b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringTest.java
index 7a9f95d97..8207ff5c0 100644
--- a/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringTest.java
+++ b/liteflow-testcase-springnative/src/test/java/com/yomahub/liteflow/test/multipleType/LiteflowMultipleTypeSpringTest.java
@@ -25,7 +25,7 @@ public class LiteflowMultipleTypeSpringTest extends BaseTest {
     private FlowExecutor flowExecutor;
 
     @Test
-    public void testConfig() {
+    public void testMultipleType() {
         LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
         Assert.assertTrue(response.isSuccess());
         Assert.assertEquals("a==>b==>c==>b==>a", response.getSlot().getExecuteStepStr());
diff --git a/pom.xml b/pom.xml
index dcf985314..8714790cf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -55,6 +55,7 @@
 		0.10
 		3.2.7
 		3.0.8
+		1.11.13
     
 
     
@@ -177,6 +178,11 @@
 				groovy-jsr223
 				${groovy.version}
 			
+			
+				net.bytebuddy
+				byte-buddy
+				${bytebuddy.version}
+			
 		
 	
 
@@ -255,7 +261,8 @@
 		liteflow-testcase-script-groovy
 		liteflow-testcase-nospring
 		liteflow-spring
-	
+        liteflow-testcase-declare-component
+