Skip to content

Commit 22a08d0

Browse files
committed
682 Add support for asynchronous workflow test execution and SSE streaming
1 parent e1a0b6f commit 22a08d0

File tree

9 files changed

+1190
-140
lines changed

9 files changed

+1190
-140
lines changed

server/libs/platform/platform-coordinator/src/main/java/com/bytechef/platform/coordinator/job/JobSyncExecutor.java

Lines changed: 432 additions & 86 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2025 ByteChef
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.bytechef.platform.workflow.test.dto;
18+
19+
/**
20+
* @author Ivica Cardic
21+
*/
22+
public record ExecutionErrorEventDTO(long jobId, String message) {
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2025 ByteChef
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.bytechef.platform.workflow.test.dto;
18+
19+
import java.time.Instant;
20+
21+
/**
22+
* @author Ivica Cardic
23+
*/
24+
public record JobStatusEventDTO(long jobId, String status, Instant timestamp) {
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2025 ByteChef
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.bytechef.platform.workflow.test.dto;
18+
19+
import java.time.Instant;
20+
21+
/**
22+
* Unified task status event covering both task started and completed events.
23+
*
24+
* @author Ivica Cardic
25+
*/
26+
public record TaskStatusEventDTO(
27+
long jobId, long taskExecutionId, Status status, String name, String type, Instant startedAt, Instant endedAt) {
28+
29+
public enum Status {
30+
STARTED, COMPLETED
31+
}
32+
}

server/libs/platform/platform-workflow/platform-workflow-test/platform-workflow-test-api/src/main/java/com/bytechef/platform/workflow/test/facade/WorkflowTestFacade.java

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,101 @@
1616

1717
package com.bytechef.platform.workflow.test.facade;
1818

19+
import com.bytechef.platform.workflow.test.dto.ExecutionErrorEventDTO;
20+
import com.bytechef.platform.workflow.test.dto.JobStatusEventDTO;
21+
import com.bytechef.platform.workflow.test.dto.TaskStatusEventDTO;
1922
import com.bytechef.platform.workflow.test.dto.WorkflowTestExecutionDTO;
2023
import java.util.Map;
24+
import java.util.function.Consumer;
2125

2226
/**
2327
* @author Ivica Cardic
2428
*/
2529
public interface WorkflowTestFacade {
2630

31+
/**
32+
* Tests the execution of a workflow given its identifier, input parameters, and execution environment.
33+
*
34+
* @param workflowId The unique identifier of the workflow to be tested.
35+
* @param inputs A map of input parameters to be supplied to the workflow during execution.
36+
* @param environmentId The unique identifier of the environment in which the workflow will be executed.
37+
* @return A {@code WorkflowTestExecutionDTO} object that encapsulates the details of the test execution, including
38+
* the executed job and any associated trigger execution details.
39+
*/
2740
WorkflowTestExecutionDTO testWorkflow(String workflowId, Map<String, Object> inputs, long environmentId);
41+
42+
/**
43+
* Initiates the test workflow execution for the specified workflow ID and environment.
44+
*
45+
* @param workflowId The unique identifier of the workflow to be tested.
46+
* @param inputs A map of input parameters required to execute the workflow.
47+
* @param environmentId The identifier of the environment in which the workflow is to be tested.
48+
* @return The unique job ID assigned to the test workflow execution.
49+
*/
50+
long startTestWorkflow(String workflowId, Map<String, Object> inputs, long environmentId);
51+
52+
/**
53+
* Waits for the result of a test workflow execution associated with a specific job ID.
54+
*
55+
* @param jobId The unique identifier of the job whose test result is being awaited.
56+
* @return A {@link WorkflowTestExecutionDTO} object containing details about the test execution, including job and
57+
* trigger execution information.
58+
*/
59+
WorkflowTestExecutionDTO awaitTestResult(long jobId);
60+
61+
/**
62+
* Attempts to stop the running test job with the given job id.
63+
*
64+
* @param jobId The job identifier
65+
*/
66+
void stopTest(long jobId);
67+
68+
/**
69+
* Registers a listener to monitor job status updates for a specific job. The listener will be triggered with
70+
* {@link JobStatusEventDTO} objects whenever the job status changes.
71+
*
72+
* @param jobId The unique identifier of the job whose status updates should be monitored.
73+
* @param listener The consumer that will process {@link JobStatusEventDTO} instances representing job status
74+
* changes.
75+
* @return An {@link AutoCloseable} instance that can be used to unregister the listener and stop receiving job
76+
* status updates.
77+
*/
78+
AutoCloseable addJobStatusListener(long jobId, Consumer<JobStatusEventDTO> listener);
79+
80+
/**
81+
* Registers a listener to monitor task start events for a specific job. The listener will be triggered with
82+
* {@link TaskStatusEventDTO} objects whenever a task in the given job transitions to the "STARTED" state.
83+
*
84+
* @param jobId The unique identifier of the job for which task start events should be monitored.
85+
* @param listener The consumer that will process {@link TaskStatusEventDTO} instances representing task start
86+
* events.
87+
* @return An {@link AutoCloseable} instance that can be used to unregister the listener and stop receiving task
88+
* start notifications.
89+
*/
90+
AutoCloseable addTaskStartedListener(long jobId, Consumer<TaskStatusEventDTO> listener);
91+
92+
/**
93+
* Registers a listener to monitor task execution completion events for a specific job. The listener will be
94+
* triggered with {@link TaskStatusEventDTO} objects whenever a task in the given job transitions to the "COMPLETED"
95+
* state.
96+
*
97+
* @param jobId The unique identifier of the job for which task completion events should be monitored.
98+
* @param listener The consumer that will process {@link TaskStatusEventDTO} instances representing task completion
99+
* events.
100+
* @return An {@link AutoCloseable} instance that can be used to unregister the listener and stop receiving task
101+
* completion notifications.
102+
*/
103+
AutoCloseable addTaskExecutionCompleteListener(long jobId, Consumer<TaskStatusEventDTO> listener);
104+
105+
/**
106+
* Registers a listener to monitor error events for a specific job. The listener will be triggered with
107+
* {@link ExecutionErrorEventDTO} objects whenever an error occurs during the execution of the specified job.
108+
*
109+
* @param jobId The unique identifier of the job for which error events should be monitored.
110+
* @param listener The consumer that will process {@link ExecutionErrorEventDTO} instances representing execution
111+
* error events.
112+
* @return An {@link AutoCloseable} instance that can be used to unregister the listener and stop receiving
113+
* execution error notifications.
114+
*/
115+
AutoCloseable addErrorListener(long jobId, Consumer<ExecutionErrorEventDTO> listener);
28116
}

0 commit comments

Comments
 (0)