Skip to content

Commit 38d4ef0

Browse files
Make MaxMessageSizeInKilobytes nullable (Azure#25073)
* Make MaxMessageSizeInKilobytes nullable * Add another assertion * re-record * re-record * re-record * PR FB
1 parent 18db221 commit 38d4ef0

File tree

8 files changed

+154
-182
lines changed

8 files changed

+154
-182
lines changed

sdk/servicebus/Azure.Messaging.ServiceBus/api/Azure.Messaging.ServiceBus.netstandard2.0.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ internal QueueProperties() { }
680680
public string ForwardTo { get { throw null; } set { } }
681681
public System.TimeSpan LockDuration { get { throw null; } set { } }
682682
public int MaxDeliveryCount { get { throw null; } set { } }
683-
public long MaxMessageSizeInKilobytes { get { throw null; } set { } }
683+
public long? MaxMessageSizeInKilobytes { get { throw null; } set { } }
684684
public long MaxSizeInMegabytes { get { throw null; } set { } }
685685
public string Name { get { throw null; } }
686686
public bool RequiresDuplicateDetection { get { throw null; } }
@@ -882,7 +882,7 @@ internal TopicProperties() { }
882882
public System.TimeSpan DuplicateDetectionHistoryTimeWindow { get { throw null; } set { } }
883883
public bool EnableBatchedOperations { get { throw null; } set { } }
884884
public bool EnablePartitioning { get { throw null; } set { } }
885-
public long MaxMessageSizeInKilobytes { get { throw null; } set { } }
885+
public long? MaxMessageSizeInKilobytes { get { throw null; } set { } }
886886
public long MaxSizeInMegabytes { get { throw null; } set { } }
887887
public string Name { get { throw null; } set { } }
888888
public bool RequiresDuplicateDetection { get { throw null; } set { } }

sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/QueueProperties.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ internal bool SupportOrdering
316316
/// This feature is only available when using a Premium namespace and service version "2021-05" or higher.
317317
/// <seealso href="https://docs.microsoft.com/azure/service-bus-messaging/service-bus-premium-messaging"/>
318318
/// </summary>
319-
public long MaxMessageSizeInKilobytes { get; set; }
319+
public long? MaxMessageSizeInKilobytes { get; set; }
320320

321321
/// <summary>
322322
/// List of properties that were retrieved using GetQueue but are not understood by this version of client is stored here.

sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/QueuePropertiesExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static XDocument Serialize(this QueueProperties description)
3838
new XElement(XName.Get("EnablePartitioning", AdministrationClientConstants.ServiceBusNamespace), XmlConvert.ToString(description.EnablePartitioning)),
3939
description.ForwardDeadLetteredMessagesTo != null ? new XElement(XName.Get("ForwardDeadLetteredMessagesTo", AdministrationClientConstants.ServiceBusNamespace), description.ForwardDeadLetteredMessagesTo) : null,
4040
new XElement(XName.Get("EnableExpress", AdministrationClientConstants.ServiceBusNamespace), XmlConvert.ToString(description.EnableExpress)),
41-
description.MaxMessageSizeInKilobytes != 0 ? new XElement(XName.Get("MaxMessageSizeInKilobytes", AdministrationClientConstants.ServiceBusNamespace), XmlConvert.ToString(description.MaxMessageSizeInKilobytes)) : null,
41+
description.MaxMessageSizeInKilobytes.HasValue ? new XElement(XName.Get("MaxMessageSizeInKilobytes", AdministrationClientConstants.ServiceBusNamespace), XmlConvert.ToString(description.MaxMessageSizeInKilobytes.Value)) : null,
4242
};
4343

4444
// Insert unknown properties in the exact order they were in the received xml.

sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/TopicProperties.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public string UserMetadata
202202
/// This feature is only available when using a Premium namespace and service version "2021-05" or higher.
203203
/// <seealso href="https://docs.microsoft.com/azure/service-bus-messaging/service-bus-premium-messaging"/>
204204
/// </summary>
205-
public long MaxMessageSizeInKilobytes { get; set; }
205+
public long? MaxMessageSizeInKilobytes { get; set; }
206206

207207
internal bool IsAnonymousAccessible { get; set; }
208208

sdk/servicebus/Azure.Messaging.ServiceBus/src/Administration/TopicPropertiesExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public static XDocument Serialize(this TopicProperties description)
193193
new XElement(XName.Get("EnablePartitioning", AdministrationClientConstants.ServiceBusNamespace), XmlConvert.ToString(description.EnablePartitioning)),
194194
new XElement(XName.Get("EnableSubscriptionPartitioning", AdministrationClientConstants.ServiceBusNamespace), XmlConvert.ToString(description.EnableSubscriptionPartitioning)),
195195
new XElement(XName.Get("EnableExpress", AdministrationClientConstants.ServiceBusNamespace), XmlConvert.ToString(description.EnableExpress)),
196-
description.MaxMessageSizeInKilobytes != 0 ? new XElement(XName.Get("MaxMessageSizeInKilobytes", AdministrationClientConstants.ServiceBusNamespace), XmlConvert.ToString(description.MaxMessageSizeInKilobytes)) : null,
196+
description.MaxMessageSizeInKilobytes.HasValue ? new XElement(XName.Get("MaxMessageSizeInKilobytes", AdministrationClientConstants.ServiceBusNamespace), XmlConvert.ToString(description.MaxMessageSizeInKilobytes.Value)) : null,
197197
};
198198

199199
// Insert unknown properties in the exact order they were in the received xml.

sdk/servicebus/Azure.Messaging.ServiceBus/tests/Administration/ServiceBusManagementClientLiveTests.cs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ private ServiceBusAdministrationClient CreateSasTokenClient()
7676
[Test]
7777
[TestCase(false)]
7878
[TestCase(true)]
79-
[ServiceVersion(Min = ServiceBusAdministrationClientOptions.ServiceVersion.V2021_05)]
8079
public async Task BasicQueueCrudOperations(bool premium)
8180
{
8281
var queueName = nameof(BasicQueueCrudOperations).ToLower() + Recording.Random.NewGuid().ToString("D").Substring(0, 8);
@@ -101,7 +100,7 @@ public async Task BasicQueueCrudOperations(bool premium)
101100
Status = EntityStatus.Disabled
102101
};
103102

104-
if (premium)
103+
if (CanSetMaxMessageSize(premium))
105104
{
106105
queueOptions.MaxMessageSizeInKilobytes = 100000;
107106
}
@@ -118,15 +117,19 @@ public async Task BasicQueueCrudOperations(bool premium)
118117

119118
QueueProperties createdQueue = createdQueueResponse.Value;
120119

121-
if (premium)
120+
if (CanSetMaxMessageSize(premium))
122121
{
123122
Assert.AreEqual(100000, createdQueue.MaxMessageSizeInKilobytes);
124123
}
125-
else
124+
else if (_serviceVersion == ServiceBusAdministrationClientOptions.ServiceVersion.V2021_05)
126125
{
127126
// standard namespaces either use 256KB or 1024KB when in Canary
128127
Assert.LessOrEqual(createdQueue.MaxMessageSizeInKilobytes, 1024);
129128
}
129+
else
130+
{
131+
Assert.IsNull(createdQueue.MaxMessageSizeInKilobytes);
132+
}
130133

131134
AssertQueueOptions(queueOptions, createdQueue);
132135

@@ -149,6 +152,11 @@ public async Task BasicQueueCrudOperations(bool premium)
149152
getQueue.Status = EntityStatus.Disabled;
150153
getQueue.AutoDeleteOnIdle = TimeSpan.FromMinutes(6);
151154
getQueue.MaxSizeInMegabytes = 1024;
155+
if (CanSetMaxMessageSize(premium))
156+
{
157+
getQueue.MaxMessageSizeInKilobytes = 10000;
158+
}
159+
152160
QueueProperties updatedQueue = await client.UpdateQueueAsync(getQueue);
153161

154162
if (Mode == RecordedTestMode.Playback)
@@ -197,7 +205,6 @@ await client.GetQueueAsync(queueOptions.Name),
197205
[Test]
198206
[TestCase(false)]
199207
[TestCase(true)]
200-
[ServiceVersion(Min = ServiceBusAdministrationClientOptions.ServiceVersion.V2021_05)]
201208
public async Task BasicTopicCrudOperations(bool premium)
202209
{
203210
var topicName = nameof(BasicTopicCrudOperations).ToLower() + Recording.Random.NewGuid().ToString("D").Substring(0, 8);
@@ -215,7 +222,7 @@ public async Task BasicTopicCrudOperations(bool premium)
215222
UserMetadata = nameof(BasicTopicCrudOperations),
216223
};
217224

218-
if (premium)
225+
if (CanSetMaxMessageSize(premium))
219226
{
220227
options.MaxMessageSizeInKilobytes = 100000;
221228
}
@@ -232,15 +239,19 @@ public async Task BasicTopicCrudOperations(bool premium)
232239

233240
TopicProperties createdTopic = createdTopicResponse.Value;
234241

235-
if (premium)
242+
if (CanSetMaxMessageSize(premium))
236243
{
237244
Assert.AreEqual(100000, createdTopic.MaxMessageSizeInKilobytes);
238245
}
239-
else
246+
else if (_serviceVersion == ServiceBusAdministrationClientOptions.ServiceVersion.V2021_05)
240247
{
241248
// standard namespaces either use 256KB or 1024KB when in Canary
242249
Assert.LessOrEqual(createdTopic.MaxMessageSizeInKilobytes, 1024);
243250
}
251+
else
252+
{
253+
Assert.IsNull(createdTopic.MaxMessageSizeInKilobytes);
254+
}
244255

245256
AssertTopicOptions(options, createdTopic);
246257

@@ -260,6 +271,10 @@ public async Task BasicTopicCrudOperations(bool premium)
260271
getTopic.DuplicateDetectionHistoryTimeWindow = TimeSpan.FromMinutes(2);
261272
getTopic.EnableBatchedOperations = false;
262273
getTopic.MaxSizeInMegabytes = 1024;
274+
if (CanSetMaxMessageSize(premium))
275+
{
276+
getTopic.MaxMessageSizeInKilobytes = 10000;
277+
}
263278

264279
Response<TopicProperties> updatedTopicResponse = await client.UpdateTopicAsync(getTopic);
265280
rawResponse = updatedTopicResponse.GetRawResponse();
@@ -296,6 +311,11 @@ await client.GetTopicAsync(options.Name),
296311
Assert.False(exists);
297312
}
298313

314+
private bool CanSetMaxMessageSize(bool premium)
315+
{
316+
return premium && _serviceVersion >= ServiceBusAdministrationClientOptions.ServiceVersion.V2021_05;
317+
}
318+
299319
[Test]
300320
public async Task BasicSubscriptionCrudOperations()
301321
{

0 commit comments

Comments
 (0)