文档首页 > > SDK参考> 工作流Java SDK> 工作流测试示例

工作流测试示例

分享
更新时间: 2019/07/11 20:20

测试启动运行实例

首先创建工作流client客户端,前提需要创建对应的grpah,创建测试工作流启动实例请求,调用testStartExecution方法测试启动运行实例。TestStartExecutionRequest和TestStartExecutionResponse属性的详细信息,参考启动工作流测试实例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.fgs.sdk.demo;

import com.hwc.fgs.client.FunctionGraphClient; 
import com.hwc.fgs.config.FunctionGraphConfig; 
import com.hwc.fgs.exception.FgsClientException; 
import com.hwc.fgs.exception.FgsServerException;
import com.hwc.fgs.model.StartAndTestExecutionMetadata;
import com.hwc.fgs.request.graphtest.StartTestExecutionRequest;
import com.hwc.fgs.response.graphtest.StartTestExecutionResponse;

public class Main {
    public static void main(String[] args) {
        String ak = "your ak";
        String sk = "your sk";
        String region = "FGS_region";
        String projectId = "your project_id";

        // 创建工作流 client
        FunctionGraphConfig config = new FunctionGraphConfig(region, ak, sk, projectId);
        FunctionGraphClient client = new FunctionGraphClient(config);

        try {

             // 构造请求对象
            StartAndTestExecutionMetadata startAndTestExecutionMetadata = new StartAndTestExecutionMetadata();
            startAndTestExecutionMetadata.setExecutionName("workRequest");
            startAndTestExecutionMetadata.setInput("{}");
            StartTestExecutionRequest startTestExecutionRequest = new StartTestExecutionRequest.Builder()
                    .executions(startAndTestExecutionMetadata)
                    .graphUrn("graphUrn")
                    .build();
 
            // 发送请求
            StartTestExecutionResponse startTestExecutionResponse = client.startTestExecution(startTestExecutionRequest);
        } catch (FgsServerException e) {
            System.out.println(e.getErrorMessage());
        } catch (FgsClientException e) {
            System.out.println(e.getErrorMessage());
        }
    }
}

模拟触发器消息触发

首先创建工作流client客户端,创建模拟触发器消息触发的请求,调用eventTest方法模拟触发器消息触发。TestTriggerRequest属性的详细信息,参考模拟事件消息触发event state

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.fgs.sdk.demo;

import com.hwc.fgs.client.FunctionGraphClient; 
import com.hwc.fgs.config.FunctionGraphConfig; 
import com.hwc.fgs.exception.FgsClientException; 
import com.hwc.fgs.exception.FgsServerException;
import com.hwc.fgs.request.graphtest.TestTriggerRequest;


public class Main {
    public static void main(String[] args) {
        String ak = "your ak";
        String sk = "your sk";
        String region = "FGS_region";
        String projectId = "your project_id";

        // 创建工作流 client
        FunctionGraphConfig config = new FunctionGraphConfig(region, ak, sk, projectId);
        FunctionGraphClient client = new FunctionGraphClient(config);

        try {

            TestTriggerRequest testTriggerRequest = new TestTriggerRequest.Builder()
                    .executionUrn("execution")
                    .graphUrn("graphUrn")
                    .input("input")
                    .triggerUrn("triggerUrn")
                    .invocationMode("sync")
                    .build();

            client.testTrigger(testTriggerRequest );
        } catch (FgsServerException e) {
            System.out.println(e.getErrorMessage());
        } catch (FgsClientException e) {
            System.out.println(e.getErrorMessage());
        }
    }
}
分享:

    相关文档

    相关产品

文档是否有解决您的问题?

提交成功!

非常感谢您的反馈,我们会继续努力做到更好!

反馈提交失败,请稍后再试!

*必选

请至少选择或填写一项反馈信息

字符长度不能超过200

提交反馈 取消

如您有其它疑问,您也可以通过华为云社区问答频道来与我们联系探讨

跳转到云社区