diff --git a/sdk/eventhub/Microsoft.Azure.WebJobs.Extensions.EventHubs/src/Listeners/EventHubsTargetScaler.cs b/sdk/eventhub/Microsoft.Azure.WebJobs.Extensions.EventHubs/src/Listeners/EventHubsTargetScaler.cs index 008a09f5c46c1..8bccdf773591a 100644 --- a/sdk/eventhub/Microsoft.Azure.WebJobs.Extensions.EventHubs/src/Listeners/EventHubsTargetScaler.cs +++ b/sdk/eventhub/Microsoft.Azure.WebJobs.Extensions.EventHubs/src/Listeners/EventHubsTargetScaler.cs @@ -86,7 +86,7 @@ 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); + long desiredWorkerCount = (long)Math.Ceiling(eventCount / (decimal)desiredConcurrency); int[] sortedValidWorkerCounts = GetSortedValidWorkerCountsForPartitionCount(partitionCount); int validatedTargetWorkerCount = GetValidWorkerCount(desiredWorkerCount, sortedValidWorkerCounts); @@ -163,9 +163,15 @@ internal static int[] GetSortedValidWorkerCountsForPartitionCount(int partitionC /// The value that we want to find in the sortedValues list (if it exists), or the next largest element. /// The list of valid worker counts. This must be sorted. /// - internal static int GetValidWorkerCount(int workerCount, int[] sortedValidWorkerCountList) + internal static int GetValidWorkerCount(long workerCount, int[] sortedValidWorkerCountList) { - int i = Array.BinarySearch(sortedValidWorkerCountList, workerCount); + // Handling cases where workerCount exceeds int.MaxInt + if (workerCount > int.MaxValue) + { + return sortedValidWorkerCountList.Last(); + } + + int i = Array.BinarySearch(sortedValidWorkerCountList, (int)workerCount); if (i >= 0) { return sortedValidWorkerCountList[i]; diff --git a/sdk/eventhub/Microsoft.Azure.WebJobs.Extensions.EventHubs/tests/EventHubsTargetScalerTests.cs b/sdk/eventhub/Microsoft.Azure.WebJobs.Extensions.EventHubs/tests/EventHubsTargetScalerTests.cs index fa7bc86e0fc0a..a8a3c82c6eada 100644 --- a/sdk/eventhub/Microsoft.Azure.WebJobs.Extensions.EventHubs/tests/EventHubsTargetScalerTests.cs +++ b/sdk/eventhub/Microsoft.Azure.WebJobs.Extensions.EventHubs/tests/EventHubsTargetScalerTests.cs @@ -127,7 +127,9 @@ public void TestGetSortedValidWorkerCountsForPartitionCount(int partitionCount, [TestCase(21, new[] { 1, 4, 10, 20 }, 20)] [TestCase(0, new[] { 1, 4, 10, 20 }, 1)] [TestCase(10, new[] { 1, 4, 10, 20 }, 10)] - public void GetSortedValidWorkerCountsForPartitionCount_ReturnsExpected(int workerCount, int[] sortedWorkerCountList, int expectedValidWorkerCount) + [TestCase(2147483650, new[] { 1, 4, 10, 20 }, 20)] // workerCount exceeds MaxInt + [TestCase(2147483650, new[] { 1 }, 1)] + public void GetSortedValidWorkerCountsForPartitionCount_ReturnsExpected(long workerCount, int[] sortedWorkerCountList, int expectedValidWorkerCount) { int actualValidWorkerCount = EventHubsTargetScaler.GetValidWorkerCount(workerCount, sortedWorkerCountList); Assert.AreEqual(expectedValidWorkerCount, actualValidWorkerCount);