Skip to content

Commit

Permalink
Updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pasaini-microsoft committed Jul 10, 2024
1 parent e98bc4d commit e9ee9c0
Showing 1 changed file with 35 additions and 27 deletions.
62 changes: 35 additions & 27 deletions Test/DurableTask.AzureStorage.Tests/TestPartitionIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ public class TestPartitionIndex
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!11"},
{ 3, "sampleinstanceid!1"}
};

private Dictionary<uint, string> partitionToInstanceIdWithExplicitPartitionPlacement = new Dictionary<uint, string>()
{
{ 0, "sampleinstanceid!0"},
{ 1, "sampleinstanceid!1"},
{ 2, "sampleinstanceid!2"},
{ 3, "sampleinstanceid!3"}
};

[TestInitialize]
public void Initialize()
{
Expand All @@ -53,40 +69,32 @@ public void Initialize()
}

[TestMethod]
[DataRow(20, false)]
[DataRow(20, true)]
public void GetPartitionIndexTest(int maxInstanceIdCount, bool enableExplicitPartitionPlacement)
public void GetPartitionIndexTest_EnableExplicitPartitionPlacement_False()
{
settings.EnableExplicitPartitionPlacement = enableExplicitPartitionPlacement;
settings.EnableExplicitPartitionPlacement = false;

for (uint instanceIdSuffix = 0; instanceIdSuffix < settings.PartitionCount * 4; instanceIdSuffix++)
foreach (var kvp in partitionToInstanceId)
{
Dictionary<uint, int> indexNumberToCount = new Dictionary<uint, int>();

for (uint indexCount = 0; indexCount < settings.PartitionCount; indexCount++)
{
indexNumberToCount[indexCount] = 0;
}

for (int instanceCount = 0; instanceCount < maxInstanceIdCount; instanceCount++)
{
var instanceIdPrefix = Guid.NewGuid().ToString();
var instanceId = kvp.Value;
var expectedPartitionIndex = kvp.Key;
var partitionIndex = azureStorageOrchestrationService.GetPartitionIndex(instanceId);

var instanceId = $"{instanceIdPrefix}!{instanceIdSuffix}";
Assert.AreEqual(expectedPartitionIndex, partitionIndex);
}
}

var partitionIndex = azureStorageOrchestrationService.GetPartitionIndex(instanceId);
[TestMethod]
public void GetPartitionIndexTest_EnableExplicitPartitionPlacement_True()
{
settings.EnableExplicitPartitionPlacement = true;

indexNumberToCount[partitionIndex]++;
}
foreach (var kvp in partitionToInstanceIdWithExplicitPartitionPlacement)
{
var instanceId = kvp.Value;
var expectedPartitionIndex = kvp.Key;
var partitionIndex = azureStorageOrchestrationService.GetPartitionIndex(instanceId);

if (enableExplicitPartitionPlacement)
{
Assert.AreEqual(indexNumberToCount[(uint)(instanceIdSuffix % settings.PartitionCount)], maxInstanceIdCount);
}
else
{
Assert.AreNotEqual(indexNumberToCount[(uint)(instanceIdSuffix % settings.PartitionCount)], maxInstanceIdCount);
}
Assert.AreEqual(expectedPartitionIndex, partitionIndex);
}
}
}
Expand Down

0 comments on commit e9ee9c0

Please sign in to comment.