-
Notifications
You must be signed in to change notification settings - Fork 16
Adding rewind client API #253
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
Open
bachuv
wants to merge
7
commits into
main
Choose a base branch
from
vabachu/rewind
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+436
−10
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a1e2098
initial commit
bachuv cab7522
added api
bachuv 5a804bc
updated EndToEndTests.java
bachuv 132532d
updated CHANGELOG
bachuv f73c058
updated build-validation.yml
bachuv 959da6a
Merge branch 'main' into vabachu/rewind
bachuv 46cc864
reverted build-validation.yml changes
bachuv 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| package com.functions; | ||
|
|
||
| import com.microsoft.azure.functions.ExecutionContext; | ||
| import com.microsoft.azure.functions.HttpMethod; | ||
| import com.microsoft.azure.functions.HttpRequestMessage; | ||
| import com.microsoft.azure.functions.HttpResponseMessage; | ||
| import com.microsoft.azure.functions.annotation.AuthorizationLevel; | ||
| import com.microsoft.azure.functions.annotation.FunctionName; | ||
| import com.microsoft.azure.functions.annotation.HttpTrigger; | ||
| import com.microsoft.durabletask.DurableTaskClient; | ||
| import com.microsoft.durabletask.TaskOrchestrationContext; | ||
| import com.microsoft.durabletask.azurefunctions.DurableActivityTrigger; | ||
| import com.microsoft.durabletask.azurefunctions.DurableClientContext; | ||
| import com.microsoft.durabletask.azurefunctions.DurableClientInput; | ||
| import com.microsoft.durabletask.azurefunctions.DurableOrchestrationTrigger; | ||
|
|
||
| import java.util.Optional; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
|
|
||
| /** | ||
| * Sample functions to test the rewind functionality. | ||
| * Rewind allows a failed orchestration to be replayed from its last known good state. | ||
| */ | ||
| public class RewindTest { | ||
|
|
||
| // Flag to control whether the activity should fail (first call fails, subsequent calls succeed) | ||
| private static final AtomicBoolean shouldFail = new AtomicBoolean(true); | ||
|
|
||
| /** | ||
| * HTTP trigger to start the rewindable orchestration. | ||
| */ | ||
| @FunctionName("StartRewindableOrchestration") | ||
| public HttpResponseMessage startRewindableOrchestration( | ||
| @HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request, | ||
| @DurableClientInput(name = "durableContext") DurableClientContext durableContext, | ||
| final ExecutionContext context) { | ||
| context.getLogger().info("Starting rewindable orchestration."); | ||
|
|
||
| // Reset the failure flag so the first activity call will fail | ||
| shouldFail.set(true); | ||
|
|
||
| DurableTaskClient client = durableContext.getClient(); | ||
| String instanceId = client.scheduleNewOrchestrationInstance("RewindableOrchestration"); | ||
| context.getLogger().info("Created new Java orchestration with instance ID = " + instanceId); | ||
| return durableContext.createCheckStatusResponse(request, instanceId); | ||
| } | ||
|
|
||
| /** | ||
| * Orchestration that calls an activity which will fail on the first attempt. | ||
| * After rewinding, the orchestration will replay and the activity will succeed. | ||
| */ | ||
| @FunctionName("RewindableOrchestration") | ||
| public String rewindableOrchestration( | ||
| @DurableOrchestrationTrigger(name = "ctx") TaskOrchestrationContext ctx) { | ||
| // Call the activity that may fail | ||
| String result = ctx.callActivity("FailOnceActivity", "RewindTest", String.class).await(); | ||
| return result; | ||
| } | ||
|
|
||
| /** | ||
| * Activity that fails on the first call but succeeds on subsequent calls. | ||
| * This simulates a transient failure that can be recovered by rewinding. | ||
| */ | ||
| @FunctionName("FailOnceActivity") | ||
| public String failOnceActivity( | ||
| @DurableActivityTrigger(name = "input") String input, | ||
| final ExecutionContext context) { | ||
| if (shouldFail.compareAndSet(true, false)) { | ||
| context.getLogger().warning("FailOnceActivity: Simulating failure for input: " + input); | ||
| throw new RuntimeException("Simulated transient failure - rewind to retry"); | ||
| } | ||
| context.getLogger().info("FailOnceActivity: Success for input: " + input); | ||
| return input + "-rewound-success"; | ||
| } | ||
|
|
||
| /** | ||
| * HTTP trigger to reset the failure flag (useful for testing). | ||
| */ | ||
| @FunctionName("ResetRewindFailureFlag") | ||
| public HttpResponseMessage resetRewindFailureFlag( | ||
| @HttpTrigger(name = "req", methods = {HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request, | ||
| final ExecutionContext context) { | ||
| shouldFail.set(true); | ||
| context.getLogger().info("Reset failure flag to true."); | ||
| return request.createResponseBuilder(com.microsoft.azure.functions.HttpStatus.OK) | ||
| .body("Failure flag reset to true") | ||
| .build(); | ||
| } | ||
| } |
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 | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |||||||||||||||||||||
| import io.restassured.http.ContentType; | ||||||||||||||||||||||
| import io.restassured.path.json.JsonPath; | ||||||||||||||||||||||
| import io.restassured.response.Response; | ||||||||||||||||||||||
| import org.junit.jupiter.api.BeforeAll; | ||||||||||||||||||||||
| import org.junit.jupiter.api.Order; | ||||||||||||||||||||||
| import org.junit.jupiter.api.Tag; | ||||||||||||||||||||||
| import org.junit.jupiter.api.Test; | ||||||||||||||||||||||
|
|
@@ -26,6 +27,14 @@ | |||||||||||||||||||||
| @Tag("e2e") | ||||||||||||||||||||||
| public class EndToEndTests { | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| @BeforeAll | ||||||||||||||||||||||
| public static void setup() { | ||||||||||||||||||||||
| RestAssured.baseURI = "http://localhost"; | ||||||||||||||||||||||
| // Use port 8080 for Docker, 7071 for local func start | ||||||||||||||||||||||
| String port = System.getenv("FUNCTIONS_PORT"); | ||||||||||||||||||||||
| RestAssured.port = port != null ? Integer.parseInt(port) : 8080; | ||||||||||||||||||||||
|
||||||||||||||||||||||
| RestAssured.port = port != null ? Integer.parseInt(port) : 8080; | |
| int resolvedPort = 8080; | |
| if (port != null && !port.isEmpty()) { | |
| try { | |
| resolvedPort = Integer.parseInt(port); | |
| } catch (NumberFormatException e) { | |
| System.err.println("Invalid FUNCTIONS_PORT value '" + port + "'. Falling back to default port " + resolvedPort + "."); | |
| } | |
| } | |
| RestAssured.port = resolvedPort; |
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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| fbe5bb20835678099fc51a44993ed9b045dee5a6 | ||
| 026329c53fe6363985655857b9ca848ec7238bd2 |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing null check for instanceId parameter. Similar methods in this class like terminate() at line 249 use Helpers.throwIfArgumentNull(instanceId, "instanceId") to validate the parameter. This validation should be added for consistency and to provide a clear error message when null is passed.