-
Notifications
You must be signed in to change notification settings - Fork 325
Get instance id for desired control-queue(s) #1069
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
base: main
Are you sure you want to change the base?
Changes from 9 commits
409edba
2280605
e98bc4d
e9ee9c0
12719fa
a07015d
f39724d
cb9adbc
7c6811d
be2f775
0284c46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| // ---------------------------------------------------------------------------------- | ||
| // 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 DurableTask.AzureStorage.Tests | ||
| { | ||
| using System.Collections.Generic; | ||
| using System.Threading; | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
|
||
| [TestClass] | ||
| public class TestPartitionIndex | ||
| { | ||
| private AzureStorageOrchestrationService azureStorageOrchestrationService; | ||
| private AzureStorageOrchestrationServiceSettings settings; | ||
| private int partitionCount = 4; | ||
| private CancellationTokenSource cancellationTokenSource; | ||
| private const string TaskHub = "taskHubName"; | ||
|
|
||
| private Dictionary<uint, string> partitionToInstanceId = new Dictionary<uint, string>() | ||
| { | ||
| { 0, "sampleinstanceid!13"}, | ||
| { 1, "sampleinstanceid!3"}, | ||
| { 2, "sampleinstanceid!1!"}, | ||
| { 3, "sampleinstanceid!1"} | ||
| }; | ||
|
|
||
| private Dictionary<uint, string> partitionToInstanceIdWithExplicitPartitionPlacement = new Dictionary<uint, string>() | ||
| { | ||
| { 0, "sampleinstanceid!0"}, | ||
| { 1, "sampleinstanceid!2!1"}, | ||
| { 2, "sampleinstanceid!2"}, | ||
| { 3, "sampleinstanceid!3"} | ||
| }; | ||
|
|
||
| private Dictionary<uint, string> partitionToInstanceIdWithExplicitPartitionPlacementEndingWithExclamation = new Dictionary<uint, string>() | ||
| { | ||
| { 0, "sampleinstanceid!3!"}, | ||
| { 1, "sampleinstanceid!2!"}, | ||
| { 2, "sampleinstanceid!1!"}, | ||
| { 3, "sampleinstanceid!0!"} | ||
| }; | ||
|
|
||
| [TestInitialize] | ||
| public void Initialize() | ||
| { | ||
| cancellationTokenSource = new CancellationTokenSource(); | ||
|
|
||
| settings = new AzureStorageOrchestrationServiceSettings() | ||
| { | ||
| StorageConnectionString = TestHelpers.GetTestStorageAccountConnectionString(), | ||
| TaskHubName = TaskHub, | ||
| PartitionCount = partitionCount | ||
| }; | ||
|
|
||
| azureStorageOrchestrationService = new AzureStorageOrchestrationService(settings); | ||
|
|
||
| string str = "sampleinstanceid!0!"; | ||
| var index = azureStorageOrchestrationService.GetPartitionIndex(str); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void GetPartitionIndexTest_EnableExplicitPartitionPlacement_False() | ||
| { | ||
| settings.EnableExplicitPartitionPlacement = false; | ||
|
|
||
| foreach (var kvp in partitionToInstanceId) | ||
| { | ||
| var instanceId = kvp.Value; | ||
| var expectedPartitionIndex = kvp.Key; | ||
| var partitionIndex = azureStorageOrchestrationService.GetPartitionIndex(instanceId); | ||
|
|
||
| Assert.AreEqual(expectedPartitionIndex, partitionIndex); | ||
| } | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void GetPartitionIndexTest_EnableExplicitPartitionPlacement_True() | ||
| { | ||
| settings.EnableExplicitPartitionPlacement = true; | ||
|
|
||
| foreach (var kvp in partitionToInstanceIdWithExplicitPartitionPlacement) | ||
| { | ||
| var instanceId = kvp.Value; | ||
| var expectedPartitionIndex = kvp.Key; | ||
| var partitionIndex = azureStorageOrchestrationService.GetPartitionIndex(instanceId); | ||
|
|
||
| Assert.AreEqual(expectedPartitionIndex, partitionIndex); | ||
| } | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void GetPartitionIndexTest_EndingWithExclamation_EnableExplicitPartitionPlacement_True() | ||
| { | ||
| settings.EnableExplicitPartitionPlacement = true; | ||
|
|
||
| foreach (var kvp in partitionToInstanceIdWithExplicitPartitionPlacementEndingWithExclamation) | ||
| { | ||
| var instanceId = kvp.Value; | ||
| var expectedPartitionIndex = kvp.Key; | ||
| var partitionIndex = azureStorageOrchestrationService.GetPartitionIndex(instanceId); | ||
|
|
||
| Assert.AreEqual(expectedPartitionIndex, partitionIndex); | ||
| } | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void GetPartitionIndexTest_EndingWithExclamation_EnableExplicitPartitionPlacement_False() | ||
| { | ||
| settings.EnableExplicitPartitionPlacement = false; | ||
|
|
||
| foreach (var kvp in partitionToInstanceIdWithExplicitPartitionPlacementEndingWithExclamation) | ||
| { | ||
| var instanceId = kvp.Value; | ||
| var expectedPartitionIndex = kvp.Key; | ||
| var partitionIndex = azureStorageOrchestrationService.GetPartitionIndex(instanceId); | ||
|
|
||
| Assert.AreEqual(expectedPartitionIndex, partitionIndex); | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -318,5 +318,14 @@ internal LogHelper Logger | |||||||||||||||||||||||||||
| /// Consumers that require separate dispatch (such as the new out-of-proc v2 SDKs) must set this to true. | ||||||||||||||||||||||||||||
| /// </summary> | ||||||||||||||||||||||||||||
| public bool UseSeparateQueueForEntityWorkItems { get; set; } = false; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||
| /// Whether to allow instanceIDs to use special syntax to land on a specific partition. | ||||||||||||||||||||||||||||
| /// If enabled, when an instanceID ends with suffix '!nnn', where 'nnn' is an unsigned number, the instance will land on the partition/queue for to that number. | ||||||||||||||||||||||||||||
| /// </summary> | ||||||||||||||||||||||||||||
|
Comment on lines
+322
to
+325
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit - I believe
Suggested change
|
||||||||||||||||||||||||||||
| /// <remarks> | ||||||||||||||||||||||||||||
| /// It is not generally safe to change to this flag for pre-existing TaskHubs, as it may change the expected target queue for an instanceID. | ||||||||||||||||||||||||||||
| /// </remarks> | ||||||||||||||||||||||||||||
| public bool EnableExplicitPartitionPlacement { get; set; } = false; | ||||||||||||||||||||||||||||
|
Comment on lines
+322
to
+329
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something to consider - it is not safe to change this from Let's call this out in the intellisense |
||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -707,6 +707,7 @@ void CreateAndTrackDependencyTelemetry(TraceContextBase requestTraceContext) | |||
| } | ||||
|
|
||||
| /// <summary> | ||||
| /// Add test for this. | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| /// Raises an event in the specified orchestration instance, which eventually causes the OnEvent() method in the | ||||
| /// orchestration to fire. | ||||
| /// </summary> | ||||
|
|
@@ -755,6 +756,7 @@ public Task TerminateInstanceAsync(OrchestrationInstance orchestrationInstance) | |||
| } | ||||
|
|
||||
| /// <summary> | ||||
| /// Add test for this. | ||||
|
davidmrdavid marked this conversation as resolved.
Outdated
|
||||
| /// Forcefully terminate the specified orchestration instance with a reason | ||||
| /// </summary> | ||||
| /// <param name="orchestrationInstance">Instance to terminate</param> | ||||
|
|
||||
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.
can we add a test that documents the behavior if the customer uses an instanceID with multiple
!in there? Say instanceID "A!1!B!3` should probably map to partition "3", right?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.
Let's also add a test that checks that instanceID
myinstanceID!NotANumberdoes not trigger any errors / that it correctly ignores the explicit placement logic.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.
Thank you for adding the first test, I think we're just missing the very last one: