Skip to content

Commit 5230add

Browse files
committed
Refactor Tables converter & update tests (#1716, #1723, #1727)
1 parent bbeba63 commit 5230add

23 files changed

Lines changed: 320 additions & 432 deletions

File tree

extensions/Worker.Extensions.Kafka/release_notes.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
- My change description (#PR/#issue)
55
-->
66

7-
### Microsoft.Azure.Functions.Worker.Extensions.Kafka <version>
7+
### Microsoft.Azure.Functions.Worker.Extensions.Kafka 3.9.0
88

9-
- <entry>
9+
- Add `BindingCapabilities` attribute to KafkaTrigger to express function-level retry capabilities. (#1457)
10+
- Updated Kafka Extension nuget package to most recent version (3.9.0) (#1713)
11+
- Exposed an important scaling parameter `LagThreshold`` to let a user configure their scaling preferences within Kafka Trigger function. (#1713)

extensions/Worker.Extensions.Shared/Configuration/ConfigurationExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
using System;

extensions/Worker.Extensions.Storage.Blobs/src/Config/BlobStorageBindingOptionsSetup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
using System;
@@ -61,4 +61,4 @@ public void Configure(string name, BlobStorageBindingOptions options)
6161
options.Credential = _componentFactory.CreateTokenCredential(connectionSection);
6262
}
6363
}
64-
}
64+
}

extensions/Worker.Extensions.Tables/src/Config/TablesBindingOptions.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,25 @@ internal class TablesBindingOptions
1717

1818
public TableClientOptions? TableClientOptions { get; set; }
1919

20-
private TableServiceClient? TableServiceClient;
20+
internal TableServiceClient? Client;
2121

2222
internal virtual TableServiceClient CreateClient()
2323
{
24-
if (ConnectionString is null && ServiceUri is null)
24+
if (Client is not null)
2525
{
26-
throw new ArgumentNullException(nameof(ConnectionString) + " " + nameof(ServiceUri));
26+
return Client;
2727
}
2828

29-
if (TableServiceClient is not null)
29+
if (ServiceUri is not null && Credential is not null)
3030
{
31-
return TableServiceClient;
31+
Client = new TableServiceClient(ServiceUri, Credential, TableClientOptions);
32+
}
33+
else
34+
{
35+
Client = new TableServiceClient(ConnectionString, TableClientOptions);
3236
}
3337

34-
TableServiceClient = !string.IsNullOrEmpty(ConnectionString)
35-
? new TableServiceClient(ConnectionString, TableClientOptions) // Connection string based auth;
36-
: new TableServiceClient(ServiceUri, Credential, TableClientOptions); // AAD auth
37-
38-
return TableServiceClient;
38+
return Client;
3939
}
4040
}
4141
}

extensions/Worker.Extensions.Tables/src/Config/TablesBindingOptionsSetup.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ public void Configure(string name, TablesBindingOptions options)
3636
if (!connectionSection.Exists())
3737
{
3838
// Not found
39-
throw new InvalidOperationException($"Tables connection configuration '{name}' does not exist. " +
40-
"Make sure that it is a defined App Setting.");
39+
throw new InvalidOperationException($"Tables connection configuration '{name}' does not exist. Make sure that it is a defined App Setting.");
4140
}
4241

4342
if (!string.IsNullOrWhiteSpace(connectionSection.Value))

extensions/Worker.Extensions.Tables/src/Nuget.config

Lines changed: 0 additions & 7 deletions
This file was deleted.

extensions/Worker.Extensions.Tables/src/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
using System.Runtime.CompilerServices;
55
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
66

7-
[assembly: ExtensionInformation("Microsoft.Azure.WebJobs.Extensions.Tables", "1.2.0-beta.1")]
7+
[assembly: ExtensionInformation("Microsoft.Azure.WebJobs.Extensions.Tables", "1.2.0")]
88
[assembly: InternalsVisibleTo("Microsoft.Azure.Functions.Worker.Extensions.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001005148be37ac1d9f58bd40a2e472c9d380d635b6048278f7d47480b08c928858f0f7fe17a6e4ce98da0e7a7f0b8c308aecd9e9b02d7e9680a5b5b75ac7773cec096fbbc64aebd429e77cb5f89a569a79b28e9c76426783f624b6b70327eb37341eb498a2c3918af97c4860db6cdca4732787150841e395a29cfacb959c1fd971c1")]
99
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]

extensions/Worker.Extensions.Tables/src/TableInputAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ namespace Microsoft.Azure.Functions.Worker
1010
/// <summary>
1111
/// Attribute used to configure a parameter as the input target for the Azure Storage Tables binding.
1212
/// </summary>
13-
[AllowConverterFallback(true)]
1413
[InputConverter(typeof(TableClientConverter))]
1514
[InputConverter(typeof(TableEntityConverter))]
1615
[InputConverter(typeof(TableEntityEnumerableConverter))]
16+
[ConverterFallbackBehavior(ConverterFallbackBehavior.Default)]
1717
public class TableInputAttribute : InputBindingAttribute
1818
{
1919
/// <summary>Initializes a new instance of the <see cref="TableInputAttribute"/> class.</summary>

extensions/Worker.Extensions.Tables/src/TypeConverters/TableClientConverter.cs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
using System;
5-
using System.Collections.Generic;
65
using System.Threading.Tasks;
76
using Azure.Data.Tables;
87
using Microsoft.Azure.Functions.Worker.Converters;
@@ -15,10 +14,10 @@
1514
namespace Microsoft.Azure.Functions.Worker.Extensions.Tables.TypeConverters
1615
{
1716
/// <summary>
18-
/// Converter to bind Table client parameter.
17+
/// Converter to bind <see cref="TableClient" /> type parameters.
1918
/// </summary>
2019
[SupportsDeferredBinding]
21-
[SupportedConverterType(typeof(TableClient))]
20+
[SupportedTargetType(typeof(TableClient))]
2221
internal class TableClientConverter: TableConverterBase<TableClient>
2322
{
2423
public TableClientConverter(IOptionsSnapshot<TablesBindingOptions> tableOptions, ILogger<TableClientConverter> logger)
@@ -28,28 +27,23 @@ public TableClientConverter(IOptionsSnapshot<TablesBindingOptions> tableOptions,
2827

2928
public override ValueTask<ConversionResult> ConvertAsync(ConverterContext context)
3029
{
31-
if (!CanConvert(context))
32-
{
33-
return new(ConversionResult.Unhandled());
34-
}
3530
try
3631
{
32+
if (!CanConvert(context))
33+
{
34+
return new(ConversionResult.Unhandled());
35+
}
36+
3737
var modelBindingData = context?.Source as ModelBindingData;
3838
var tableData = GetBindingDataContent(modelBindingData);
39-
4039
var result = ConvertModelBindingData(tableData);
4140

42-
if (result is not null)
43-
{
44-
return new(ConversionResult.Success(result));
45-
}
41+
return new(ConversionResult.Success(result));
4642
}
4743
catch (Exception ex)
4844
{
4945
return new(ConversionResult.Failed(ex));
5046
}
51-
52-
return new(ConversionResult.Unhandled());
5347
}
5448

5549
private TableClient ConvertModelBindingData(TableData content)

extensions/Worker.Extensions.Tables/src/TypeConverters/TableConverterBase.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
using System;
5-
using System.Collections.Generic;
65
using System.Threading.Tasks;
76
using Azure.Data.Tables;
87
using Microsoft.Azure.Functions.Worker.Converters;
@@ -23,7 +22,7 @@ public TableConverterBase(IOptionsSnapshot<TablesBindingOptions> tableOptions, I
2322
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
2423
_tableOptions = tableOptions ?? throw new ArgumentNullException(nameof(tableOptions));
2524
}
26-
25+
2726
protected bool CanConvert(ConverterContext context)
2827
{
2928
if (context is null)
@@ -36,14 +35,14 @@ protected bool CanConvert(ConverterContext context)
3635
return false;
3736
}
3837

39-
if (!(context.Source is ModelBindingData bindingData))
38+
if (context.Source is not ModelBindingData bindingData)
4039
{
4140
return false;
4241
}
4342

4443
if (bindingData.Source is not Constants.TablesExtensionName)
4544
{
46-
return false;
45+
throw new InvalidBindingSourceException(bindingData.Source, Constants.TablesExtensionName);
4746
}
4847

4948
return true;
@@ -56,7 +55,7 @@ protected TableData GetBindingDataContent(ModelBindingData? bindingData)
5655
return bindingData?.ContentType switch
5756
{
5857
Constants.JsonContentType => bindingData.Content.ToObjectFromJson<TableData>(),
59-
_ => throw new NotSupportedException($"Unexpected content-type. Currently only '{Constants.JsonContentType}' is supported.")
58+
_ => throw new InvalidContentTypeException(bindingData?.ContentType, Constants.JsonContentType)
6059
};
6160
}
6261

0 commit comments

Comments
 (0)