File tree Expand file tree Collapse file tree 4 files changed +25
-2
lines changed
src/Microsoft.Azure.ServiceBus/Core
test/Microsoft.Azure.ServiceBus.UnitTests Expand file tree Collapse file tree 4 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -63,10 +63,16 @@ public bool TryAdd(Message message)
6363
6464 }
6565
66+ /// <summary>
67+ /// Number of messages in batch.
68+ /// </summary>
69+ public int Length => datas . Count ;
70+
6671 private long Size => result . SerializedMessageSize ;
6772
73+
6874 /// <summary>
69- /// Convert batch to AMQP message
75+ /// Convert batch to AMQP message.
7076 /// </summary>
7177 /// <returns></returns>
7278 public AmqpMessage ToAmqpMessage ( )
Original file line number Diff line number Diff line change @@ -277,7 +277,7 @@ public async Task SendAsync(Batch batch)
277277 {
278278 this . ThrowIfClosed ( ) ;
279279
280- // MessagingEventSource.Log.MessageSendStart(this.ClientId, count );
280+ MessagingEventSource . Log . MessageSendStart ( this . ClientId , batch . Length ) ;
281281
282282// var isDiagnosticSourceEnabled = ServiceBusDiagnosticSource.IsEnabled();
283283// var activity = isDiagnosticSourceEnabled ? this.diagnosticSource.SendStart(messageList) : null;
Original file line number Diff line number Diff line change @@ -483,6 +483,7 @@ namespace Microsoft.Azure.ServiceBus.Core
483483 public class Batch : System.IDisposable
484484 {
485485 public Batch(long maximumBatchSize) { }
486+ public int Length { get; }
486487 public void Dispose() { }
487488 public Microsoft.Azure.Amqp.AmqpMessage ToAmqpMessage() { }
488489 public bool TryAdd(Microsoft.Azure.ServiceBus.Message message) { }
Original file line number Diff line number Diff line change @@ -41,5 +41,21 @@ public void Should_throw_when_trying_to_add_an_already_received_message_to_batch
4141 Assert . Throws < ArgumentException > ( ( ) => batch . TryAdd ( message ) ) ;
4242 }
4343 }
44+
45+ [ Theory ]
46+ [ InlineData ( 1 ) ]
47+ [ InlineData ( 3 ) ]
48+ public void Should_report_how_many_messages_are_in_batch ( int numberOfMessages )
49+ {
50+ using ( var batch = new Batch ( 100 ) )
51+ {
52+ for ( var i = 0 ; i < numberOfMessages ; i ++ )
53+ {
54+ batch . TryAdd ( new Message ( ) ) ;
55+ }
56+
57+ Assert . Equal ( numberOfMessages , batch . Length ) ;
58+ }
59+ }
4460 }
4561}
You can’t perform that action at this time.
0 commit comments