Skip to content

Commit 7db9f60

Browse files
authored
Throw exception for scaling configuration invalid value (#450)
* Throw exception for scaling configuration invalid value * Change Exception type
1 parent 58659a6 commit 7db9f60

File tree

2 files changed

+9
-24
lines changed

2 files changed

+9
-24
lines changed

src/TriggerBinding/SqlTriggerListener.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,17 @@ public SqlTriggerListener(string connectionString, string tableName, string user
7070
this._executor = executor ?? throw new ArgumentNullException(nameof(executor));
7171
this._logger = logger ?? throw new ArgumentNullException(nameof(logger));
7272
this._configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
73-
int configuredMaxChangesPerWorker;
73+
int? configuredMaxChangesPerWorker;
7474
// Do not convert the scale-monitor ID to lower-case string since SQL table names can be case-sensitive
7575
// depending on the collation of the current database.
7676
this._scaleMonitorDescriptor = new ScaleMonitorDescriptor($"{userFunctionId}-SqlTrigger-{tableName}");
7777

78-
// In case converting from string to int is not possible from the user input.
79-
try
78+
configuredMaxChangesPerWorker = configuration.GetValue<int?>(ConfigKey_SqlTrigger_MaxChangesPerWorker);
79+
this._maxChangesPerWorker = configuredMaxChangesPerWorker ?? DefaultMaxChangesPerWorker;
80+
if (this._maxChangesPerWorker <= 0)
8081
{
81-
configuredMaxChangesPerWorker = configuration.GetValue<int>(ConfigKey_SqlTrigger_MaxChangesPerWorker);
82-
}
83-
catch (Exception ex)
84-
{
85-
this._logger.LogError($"Failed to resolve integer value from user configured setting '{ConfigKey_SqlTrigger_MaxChangesPerWorker}' due to exception: {ex.GetType()}. Exception message: {ex.Message}");
86-
TelemetryInstance.TrackException(TelemetryErrorName.InvalidConfigurationValue, ex, this._telemetryProps);
87-
88-
configuredMaxChangesPerWorker = DefaultMaxChangesPerWorker;
82+
throw new InvalidOperationException($"Invalid value for configuration setting '{ConfigKey_SqlTrigger_MaxChangesPerWorker}'. Ensure that the value is a positive integer.");
8983
}
90-
this._maxChangesPerWorker = configuredMaxChangesPerWorker > 0 ? configuredMaxChangesPerWorker : DefaultMaxChangesPerWorker;
9184
}
9285

9386
public void Cancel()

test/Unit/TriggerBinding/SqlTriggerListenerTests.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -232,20 +232,12 @@ public void ScaleMonitorGetScaleStatus_UserConfiguredMaxChangesPerWorker_Respect
232232
[InlineData("-1")]
233233
[InlineData("0")]
234234
[InlineData("10000000000")]
235-
public void ScaleMonitorGetScaleStatus_InvalidUserConfiguredMaxChangesPerWorker_UsesDefaultValue(string maxChangesPerWorker)
235+
public void InvalidUserConfiguredMaxChangesPerWorker(string maxChangesPerWorker)
236236
{
237-
(IScaleMonitor<SqlTriggerMetrics> monitor, _) = GetScaleMonitor(maxChangesPerWorker);
238-
239-
ScaleStatusContext context;
240-
ScaleStatus scaleStatus;
241-
242-
context = GetScaleStatusContext(new int[] { 0, 0, 0, 0, 10000 }, 10);
243-
scaleStatus = monitor.GetScaleStatus(context);
244-
Assert.Equal(ScaleVote.None, scaleStatus.Vote);
237+
(Mock<ILogger> mockLogger, List<string> logMessages) = CreateMockLogger();
238+
Mock<IConfiguration> mockConfiguration = CreateMockConfiguration(maxChangesPerWorker);
245239

246-
context = GetScaleStatusContext(new int[] { 0, 0, 0, 0, 10001 }, 10);
247-
scaleStatus = monitor.GetScaleStatus(context);
248-
Assert.Equal(ScaleVote.ScaleOut, scaleStatus.Vote);
240+
Assert.Throws<InvalidOperationException>(() => new SqlTriggerListener<object>("testConnectionString", "testTableName", "testUserFunctionId", Mock.Of<ITriggeredFunctionExecutor>(), mockLogger.Object, mockConfiguration.Object));
249241
}
250242

251243
private static IScaleMonitor<SqlTriggerMetrics> GetScaleMonitor(string tableName, string userFunctionId)

0 commit comments

Comments
 (0)