-
Notifications
You must be signed in to change notification settings - Fork 19
Re-stamp workflow executor_id when successfully checkpointing a step #462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
transact/src/test/java/dev/dbos/transact/execution/ExecutorIdRestampTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| package dev.dbos.transact.execution; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| import dev.dbos.transact.DBOS; | ||
| import dev.dbos.transact.StartWorkflowOptions; | ||
| import dev.dbos.transact.config.DBOSConfig; | ||
| import dev.dbos.transact.utils.PgContainer; | ||
| import dev.dbos.transact.workflow.Step; | ||
| import dev.dbos.transact.workflow.Workflow; | ||
|
|
||
| import java.sql.Connection; | ||
| import java.sql.PreparedStatement; | ||
| import java.sql.SQLException; | ||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import javax.sql.DataSource; | ||
|
|
||
| import com.zaxxer.hikari.HikariDataSource; | ||
| import org.junit.jupiter.api.AutoClose; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class ExecutorIdRestampTest { | ||
|
|
||
| static final String EXECUTOR_ID = "restamp-test-executor"; | ||
|
|
||
| @AutoClose final PgContainer pgContainer = new PgContainer(); | ||
|
|
||
| DBOSConfig dbosConfig; | ||
| @AutoClose HikariDataSource dataSource; | ||
|
|
||
| interface RestampService { | ||
| String twoStepWorkflow(); | ||
|
|
||
| String stepOne(); | ||
|
|
||
| String stepTwo(); | ||
| } | ||
|
|
||
| static class RestampServiceImpl implements RestampService { | ||
| static CountDownLatch midpoint = new CountDownLatch(1); | ||
| static CountDownLatch proceed = new CountDownLatch(1); | ||
|
|
||
| private RestampService self; | ||
|
|
||
| void setSelf(RestampService self) { | ||
| this.self = self; | ||
| } | ||
|
|
||
| @Override | ||
| @Workflow(name = "twoStepWorkflow") | ||
| public String twoStepWorkflow() { | ||
| var one = self.stepOne(); | ||
| midpoint.countDown(); | ||
| try { | ||
| proceed.await(30, TimeUnit.SECONDS); | ||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| throw new RuntimeException(e); | ||
| } | ||
| return one + self.stepTwo(); | ||
| } | ||
|
|
||
| @Override | ||
| @Step(name = "stepOne") | ||
| public String stepOne() { | ||
| return "one"; | ||
| } | ||
|
|
||
| @Override | ||
| @Step(name = "stepTwo") | ||
| public String stepTwo() { | ||
| return "two"; | ||
| } | ||
| } | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| dbosConfig = pgContainer.dbosConfig().withExecutorId(EXECUTOR_ID); | ||
| dataSource = pgContainer.dataSource(); | ||
| RestampServiceImpl.midpoint = new CountDownLatch(1); | ||
| RestampServiceImpl.proceed = new CountDownLatch(1); | ||
| } | ||
|
|
||
| @Test | ||
| void restampExecutorIdOnStepCheckpoint() throws Exception { | ||
| try (var dbos = new DBOS(dbosConfig)) { | ||
| var impl = new RestampServiceImpl(); | ||
| var service = dbos.registerProxy(RestampService.class, impl); | ||
| impl.setSelf(service); | ||
| dbos.launch(); | ||
|
|
||
| String wfid = "restamp-wf-1"; | ||
| var handle = dbos.startWorkflow(service::twoStepWorkflow, new StartWorkflowOptions(wfid)); | ||
|
|
||
| assertTrue(RestampServiceImpl.midpoint.await(30, TimeUnit.SECONDS)); | ||
| setExecutorId(dataSource, wfid, "stale-executor"); | ||
| assertEquals("stale-executor", getExecutorId(dataSource, wfid)); | ||
| RestampServiceImpl.proceed.countDown(); | ||
|
|
||
| assertEquals("onetwo", handle.getResult()); | ||
| assertEquals(EXECUTOR_ID, getExecutorId(dataSource, wfid)); | ||
| } | ||
| } | ||
|
|
||
| private static void setExecutorId(DataSource ds, String workflowId, String executorId) | ||
| throws SQLException { | ||
| String sql = "UPDATE dbos.workflow_status SET executor_id = ? WHERE workflow_uuid = ?"; | ||
| try (Connection conn = ds.getConnection(); | ||
| PreparedStatement pstmt = conn.prepareStatement(sql)) { | ||
| pstmt.setString(1, executorId); | ||
| pstmt.setString(2, workflowId); | ||
| assertEquals(1, pstmt.executeUpdate()); | ||
| } | ||
| } | ||
|
|
||
| private static String getExecutorId(DataSource ds, String workflowId) throws SQLException { | ||
| String sql = "SELECT executor_id FROM dbos.workflow_status WHERE workflow_uuid = ?"; | ||
| try (Connection conn = ds.getConnection(); | ||
| PreparedStatement pstmt = conn.prepareStatement(sql)) { | ||
| pstmt.setString(1, workflowId); | ||
| try (var rs = pstmt.executeQuery()) { | ||
| assertTrue(rs.next()); | ||
| return rs.getString("executor_id"); | ||
| } | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.