-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix swallowed exception - Improve output exception message (#185)
* fix issue 184 - improve output exception message update changelog fix same issue for handleTaskCompleted, handleSubOrchestrationCompleted improve the example and e2e tests * add deserialize erro test - add POJO input sample * quick test * improve test method name * improve samples
- Loading branch information
Showing
10 changed files
with
361 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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 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 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
103 changes: 103 additions & 0 deletions
103
endtoendtests/src/main/java/com/functions/DeserializeErrorTest.java
This file contains 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,103 @@ | ||
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.Task; | ||
import com.microsoft.durabletask.TaskOrchestrationContext; | ||
import com.microsoft.durabletask.azurefunctions.DurableClientContext; | ||
import com.microsoft.durabletask.azurefunctions.DurableClientInput; | ||
import com.microsoft.durabletask.azurefunctions.DurableOrchestrationTrigger; | ||
|
||
import java.util.Optional; | ||
|
||
public class DeserializeErrorTest { | ||
@FunctionName("DeserializeErrorHttp") | ||
public HttpResponseMessage deserializeErrorHttp( | ||
@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("Java HTTP trigger processed a request."); | ||
|
||
DurableTaskClient client = durableContext.getClient(); | ||
String instanceId = client.scheduleNewOrchestrationInstance("DeserializeErrorOrchestrator"); | ||
context.getLogger().info("Created new Java orchestration with instance ID = " + instanceId); | ||
return durableContext.createCheckStatusResponse(request, instanceId); | ||
} | ||
|
||
@FunctionName("DeserializeErrorOrchestrator") | ||
public String deserializeErrorOrchestrator( | ||
@DurableOrchestrationTrigger(name = "ctx") TaskOrchestrationContext ctx) { | ||
// cause deserialize error | ||
Person result = ctx.callActivity("Capitalize", "Austin", Person.class).await(); | ||
return result.getName(); | ||
} | ||
|
||
@FunctionName("SubCompletedErrorHttp") | ||
public HttpResponseMessage subCompletedErrorHttp( | ||
@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("Java HTTP trigger processed a request."); | ||
|
||
DurableTaskClient client = durableContext.getClient(); | ||
String instanceId = client.scheduleNewOrchestrationInstance("CompletedErrorOrchestrator"); | ||
context.getLogger().info("Created new Java orchestration with instance ID = " + instanceId); | ||
return durableContext.createCheckStatusResponse(request, instanceId); | ||
} | ||
|
||
@FunctionName("CompletedErrorOrchestrator") | ||
public String completedErrorOrchestrator( | ||
@DurableOrchestrationTrigger(name = "ctx") TaskOrchestrationContext ctx) { | ||
// cause deserialize issue | ||
Person result = ctx.callSubOrchestrator("CompletedErrorSubOrchestrator", "Austin", Person.class).await(); | ||
return result.getName(); | ||
} | ||
|
||
@FunctionName("CompletedErrorSubOrchestrator") | ||
public String completedErrorSubOrchestrator( | ||
@DurableOrchestrationTrigger(name = "ctx") TaskOrchestrationContext ctx) { | ||
return "test"; | ||
} | ||
|
||
@FunctionName("ExternalEventHttp") | ||
public HttpResponseMessage externalEventHttp( | ||
@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("Java HTTP trigger processed a request."); | ||
|
||
DurableTaskClient client = durableContext.getClient(); | ||
String instanceId = client.scheduleNewOrchestrationInstance("ExternalEventActivity"); | ||
context.getLogger().info("Created new Java orchestration with instance ID = " + instanceId); | ||
return durableContext.createCheckStatusResponse(request, instanceId); | ||
} | ||
|
||
@FunctionName("ExternalEventActivity") | ||
public void externalEventActivity(@DurableOrchestrationTrigger(name = "runtimeState") TaskOrchestrationContext ctx) | ||
{ | ||
System.out.println("Waiting external event..."); | ||
Task<String> event = ctx.waitForExternalEvent("event", String.class); | ||
Task<?> result = ctx.anyOf(event).await(); | ||
Object input = result.await(); | ||
System.out.println(input); | ||
} | ||
|
||
static class Person { | ||
String name; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} | ||
} |
This file contains 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 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
46 changes: 46 additions & 0 deletions
46
samples-azure-functions/src/main/java/com/functions/SubOrchestrator.java
This file contains 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,46 @@ | ||
package com.functions; | ||
|
||
import com.functions.model.Person; | ||
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.DurableClientContext; | ||
import com.microsoft.durabletask.azurefunctions.DurableClientInput; | ||
import com.microsoft.durabletask.azurefunctions.DurableOrchestrationTrigger; | ||
|
||
import java.util.Optional; | ||
|
||
public class SubOrchestrator { | ||
|
||
@FunctionName("SubOrchestratorHttp") | ||
public HttpResponseMessage subOrchestratorHttp( | ||
@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("Java HTTP trigger processed a request."); | ||
|
||
DurableTaskClient client = durableContext.getClient(); | ||
String instanceId = client.scheduleNewOrchestrationInstance("RootOrchestrator"); | ||
context.getLogger().info("Created new Java orchestration with instance ID = " + instanceId); | ||
return durableContext.createCheckStatusResponse(request, instanceId); | ||
} | ||
|
||
@FunctionName("RootOrchestrator") | ||
public String rootOrchestrator( | ||
@DurableOrchestrationTrigger(name = "ctx") TaskOrchestrationContext ctx) { | ||
return ctx.callSubOrchestrator("SubOrchestrator", "Austin", String.class).await(); | ||
} | ||
|
||
@FunctionName("SubOrchestrator") | ||
public String subOrchestrator( | ||
@DurableOrchestrationTrigger(name = "ctx") TaskOrchestrationContext ctx) { | ||
String input = ctx.getInput(String.class); | ||
return ctx.callSubOrchestrator("Capitalize", input, String.class).await(); | ||
} | ||
} |
Oops, something went wrong.