-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AzureServiceFabric provider] Implement ContinueAsNew functionality. (#…
…362) * [AzureServiceFabric] Implement ContinueAsNew functionality. * Fixes for ContinueAsNew functionality. * Add test for RecurringOrchestration. * Convert RetryPolicy to interface. Remove confusing assert.
- Loading branch information
Showing
20 changed files
with
327 additions
and
62 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
42 changes: 42 additions & 0 deletions
42
...stFabricApplication/TestApplication.Common/Orchestrations/GenerationBasicOrchestration.cs
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,42 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
namespace TestApplication.Common.Orchestrations | ||
{ | ||
using System.Threading.Tasks; | ||
|
||
using DurableTask.Core; | ||
|
||
using TestApplication.Common.OrchestrationTasks; | ||
|
||
public class GenerationBasicOrchestration : TaskOrchestration<int, int> | ||
{ | ||
// HACK: This is just a hack to communicate result of orchestration back to test | ||
public static int Result; | ||
|
||
public override async Task<int> RunTask(OrchestrationContext context, int numberOfGenerations) | ||
{ | ||
var testTasks = context.CreateClient<ITestTasks>(); | ||
int count = await testTasks.IncrementGenerationCount(); | ||
numberOfGenerations--; | ||
if (numberOfGenerations > 0) | ||
{ | ||
context.ContinueAsNew(numberOfGenerations); | ||
} | ||
|
||
// This is a HACK to get unit test up and running. Should never be done in actual code. | ||
Result = count; | ||
return count; | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
Test/TestFabricApplication/TestApplication.Common/Orchestrations/RecurringOrchestration.cs
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,75 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
namespace TestApplication.Common.Orchestrations | ||
{ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
using DurableTask.Core; | ||
|
||
using TestApplication.Common.OrchestrationTasks; | ||
|
||
public class RecurringOrchestration : TaskOrchestration<int, RecurringOrchestrationInput> | ||
{ | ||
// HACK: This is just a hack to communicate result of orchestration back to test | ||
private static int targetOchestrationInvocationsCount = 0; | ||
|
||
public override async Task<int> RunTask(OrchestrationContext context, RecurringOrchestrationInput input) | ||
{ | ||
var testTasks = context.CreateClient<ITestTasks>(); | ||
|
||
if (targetOchestrationInvocationsCount == 0) | ||
{ | ||
// First time, Reset Generation Count variable. | ||
await testTasks.ResetGenerationCounter(); | ||
} | ||
|
||
int result = await context.CreateSubOrchestrationInstance<int>(input.TargetOrchestrationType, | ||
GetTargetOrchestrationVersion(), | ||
input.TargetOrchestrationInstanceId, | ||
input.TargetOrchestrationInput); | ||
|
||
await context.CreateTimer(GetNextExecutionTime(context), true, CancellationToken.None); | ||
if (ShouldRepeatTargetOrchestration()) | ||
{ | ||
context.ContinueAsNew(input); | ||
} | ||
else | ||
{ | ||
// Finally, Reset Generation Count variable. | ||
await testTasks.ResetGenerationCounter(); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public virtual DateTime GetNextExecutionTime(OrchestrationContext context) | ||
{ | ||
return context.CurrentUtcDateTime.AddSeconds(Math.Pow(2, targetOchestrationInvocationsCount)); | ||
} | ||
|
||
public virtual string GetTargetOrchestrationVersion() | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
public virtual bool ShouldRepeatTargetOrchestration() | ||
{ | ||
targetOchestrationInvocationsCount++; | ||
|
||
return targetOchestrationInvocationsCount < 4; | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...estFabricApplication/TestApplication.Common/Orchestrations/RecurringOrchestrationInput.cs
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,24 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
namespace TestApplication.Common.Orchestrations | ||
{ | ||
public class RecurringOrchestrationInput | ||
{ | ||
public string TargetOrchestrationType { get; set; } | ||
|
||
public string TargetOrchestrationInput { get; set; } | ||
|
||
public string TargetOrchestrationInstanceId { get; set; } | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...stFabricApplication/TestApplication.Common/Orchestrations/RecurringTargetOrchestration.cs
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,31 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
namespace TestApplication.Common.Orchestrations | ||
{ | ||
using System.Threading.Tasks; | ||
|
||
using DurableTask.Core; | ||
|
||
using TestApplication.Common.OrchestrationTasks; | ||
|
||
public class RecurringTargetOrchestration : TaskOrchestration<int, string> | ||
{ | ||
public override async Task<int> RunTask(OrchestrationContext context, string input) | ||
{ | ||
var testTasks = context.CreateClient<ITestTasks>(); | ||
int count = await testTasks.IncrementGenerationCount(); | ||
return count; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.