Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,20 @@ internal static TargetScalerResult ThrottleScaleDownIfNecessaryInternal(TargetSc
internal TargetScalerResult GetScaleResultInternal(TargetScalerContext context, long eventCount, int partitionCount)
{
int desiredConcurrency = GetDesiredConcurrencyInternal(context);
int desiredWorkerCount = (int)Math.Ceiling(eventCount / (decimal)desiredConcurrency);

int desiredWorkerCount;
try
{
checked
{
desiredWorkerCount = (int)Math.Ceiling(eventCount / (decimal)desiredConcurrency);
}
}
catch (OverflowException)
{
desiredWorkerCount = int.MaxValue;
}

int[] sortedValidWorkerCounts = GetSortedValidWorkerCountsForPartitionCount(partitionCount);
int validatedTargetWorkerCount = GetValidWorkerCount(desiredWorkerCount, sortedValidWorkerCounts);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,18 @@ public void ThrottleScaleDownIfNecessaryInternal_ReturnsExpected(int currentTarg
}

[Test]
// Using concurrency of 10.
[TestCase(10, 10, 1)]
[TestCase(20, 10, 2)]
[TestCase(30, 10, 3)]
[TestCase(60, 10, 10)]
[TestCase(70, 10, 10)]
[TestCase(150, 10, 10)]
public void GetScaleResultInternal_ReturnsExpected(long eventCount, int partitionCount, int expectedTargetWorkerCount)
// Using default concurrency of 10.
[TestCase(10, 10, 10, 1)]
[TestCase(20, 10, 10, 2)]
[TestCase(30, 10, 10, 3)]
[TestCase(60, 10, 10, 10)]
[TestCase(70, 10, 10, 10)]
[TestCase(150, 10, 10, 10)]
[TestCase(2147483650, 1, 1, 1)] // Testing eventCount > int.MaxInt is 2147483647
[TestCase(21474836500, 1000, 1, 1000)] // Testing eventCount > int.MaxInt is 2147483647, with concurrency 1 to force overflow
public void GetScaleResultInternal_ReturnsExpected(long eventCount, int partitionCount, int? concurrency, int expectedTargetWorkerCount)
{
TargetScalerResult result = _targetScaler.GetScaleResultInternal(new TargetScalerContext { InstanceConcurrency = 10 }, eventCount, partitionCount);
TargetScalerResult result = _targetScaler.GetScaleResultInternal(new TargetScalerContext { InstanceConcurrency = concurrency }, eventCount, partitionCount);
Assert.AreEqual(expectedTargetWorkerCount, result.TargetWorkerCount);
}

Expand Down