Last active
August 29, 2015 14:09
-
-
Save plentysmart/ffa7e45cbf8f5489d552 to your computer and use it in GitHub Desktop.
Azure service bus maximum message size test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Runtime.Remoting; | |
using System.Text; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using Microsoft.ServiceBus; | |
using Microsoft.ServiceBus.Messaging; | |
using Xunit; | |
namespace MaxMessageSent | |
{ | |
public class TestClass | |
{ | |
private const string ConnectionString = | |
@"paste your connection string here"; | |
private NamespaceManager namespaceManager = | |
NamespaceManager.CreateFromConnectionString(ConnectionString); | |
private const string QueueName = "test-queue-with-large-messages"; | |
private Random random = new Random(); | |
public TestClass() | |
{ | |
if (namespaceManager.QueueExists(QueueName)) | |
{ | |
namespaceManager.DeleteQueue(QueueName); | |
} | |
namespaceManager.CreateQueue(new QueueDescription(QueueName) | |
{ | |
MaxSizeInMegabytes = 5120, | |
DefaultMessageTimeToLive = new TimeSpan(1, 1, 0) | |
}); | |
} | |
[Fact] | |
public void MaxMessageSize() | |
{ | |
var sender = CreateClient(); | |
var reciver = CreateClient(); | |
for (int i = 100; i < 255; i++) | |
{ | |
var size = i*1024; | |
var buffer = new byte[size]; | |
random.NextBytes(buffer); | |
BrokeredMessage msg = | |
new BrokeredMessage(buffer); | |
msg.Properties["size"] = size; | |
sender.Send(msg); | |
var message = reciver.Receive(); | |
Assert.NotNull(message); | |
Assert.Equal(message.Properties["size"], size); | |
var bufferReceived = message.GetBody<byte[]>(); | |
Assert.Equal(buffer, bufferReceived); | |
message.Complete(); | |
} | |
} | |
[Fact] | |
public void MaxMessageSizeExceeded() | |
{ | |
var sender = CreateClient(); | |
var size = 256*1024; | |
var buffer = new byte[size]; | |
random.NextBytes(buffer); | |
BrokeredMessage msg = | |
new BrokeredMessage(buffer); | |
msg.Properties["size"] = size; | |
Assert.Throws<MessageSizeExceededException>(() => sender.Send(msg)); | |
} | |
private QueueClient CreateClient() | |
{ | |
return QueueClient.CreateFromConnectionString(ConnectionString, QueueName); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment