public void Round_robins_across_instances_in_pool() { var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var creator = new InterceptedFactoryCreator(); var lifecycleManager = new MessagingFactoryLifeCycleManager(creator, settings); var poolSize = settings.Get <int>(WellKnownConfigurationKeys.Connectivity.MessagingFactories.NumberOfMessagingFactoriesPerNamespace); var first = lifecycleManager.Get(AzureServiceBusConnectionString.Value); var next = first; var reuseInPool = false; for (var i = 0; i < poolSize - 1; i++) { var n = lifecycleManager.Get(AzureServiceBusConnectionString.Value); reuseInPool &= next == n; next = n; } var second = lifecycleManager.Get(AzureServiceBusConnectionString.Value); Assert.IsFalse(reuseInPool); Assert.AreEqual(first, second); }
public async Task Should_be_able_to_update_an_existing_subscription_with_new_property_values() { var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value), AzureServiceBusConnectionString.Value); //cleanup await namespaceManager.DeleteTopic("sometopic1"); await namespaceManager.CreateTopic(new TopicDescription("sometopic1")); await namespaceManager.CreateSubscription(new SubscriptionDescription("sometopic1", "existingsubscription1"), sqlFilter); var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); extensions.Subscriptions().DescriptionCustomizer(description => { description.LockDuration = TimeSpan.FromSeconds(100); description.EnableDeadLetteringOnMessageExpiration = true; }); var creator = new AzureServiceBusSubscriptionCreator(settings.Get <TopologySettings>().SubscriptionSettings); await creator.Create("sometopic1", "existingsubscription1", metadata, sqlFilter, namespaceManager); var subscriptionDescription = await namespaceManager.GetSubscription("sometopic1", "existingsubscription1"); Assert.AreEqual(TimeSpan.FromSeconds(100), subscriptionDescription.LockDuration); }
public async Task Should_be_able_to_update_an_existing_subscription_with_new_property_values_without_failing_on_readonly_properties() { var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value), AzureServiceBusConnectionString.Value); await namespaceManager.CreateTopic(new TopicDescription("sometopic2")); await namespaceManager.CreateSubscription(new SubscriptionDescription("sometopic2", "existingsubscription2") { EnableDeadLetteringOnFilterEvaluationExceptions = true, RequiresSession = true, }, "1=1"); var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); extensions.Subscriptions().DescriptionCustomizer(description => { description.EnableDeadLetteringOnFilterEvaluationExceptions = false; description.RequiresSession = false; }); var creator = new AzureServiceBusSubscriptionCreator(settings.Get <TopologySettings>().SubscriptionSettings); var subscriptionDescription = await creator.Create("sometopic2", "existingsubscription2", metadata, sqlFilter, namespaceManager); Assert.IsTrue(subscriptionDescription.RequiresSession); //cleanup await namespaceManager.DeleteTopic("sometopic2"); }
public async Task Should_properly_set_AutoDeleteOnIdle_on_the_created_entity() { var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value)); var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); var autoDeleteTime = TimeSpan.FromDays(1); extensions.UseForwardingTopology().Subscriptions().AutoDeleteOnIdle(autoDeleteTime); var creator = new AzureServiceBusForwardingSubscriptionCreator(settings.Get <TopologySettings>().SubscriptionSettings); const string subscriptionName = "endpoint3"; await creator.Create(topicPath, subscriptionName, metadata, sqlFilter, namespaceManager, forwardToQueue); var foundDescription = await namespaceManager.GetSubscription(topicPath, subscriptionName); // TODO: remove when ASB bug is fixed if (foundDescription.AutoDeleteOnIdle == TimeSpan.MaxValue) { Assert.Inconclusive("Microsoft ASB bug. Pending response from ASB group: https://www.yammer.com/azureadvisors/#/Threads/show?threadId=654972562"); } Assert.AreEqual(autoDeleteTime, foundDescription.AutoDeleteOnIdle); await namespaceManager.DeleteSubscription(new SubscriptionDescription(topicPath, subscriptionName)); }
public void SendVia_should_be_enabled() { // default settings var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); Assert.IsTrue(settings.Get <bool>(WellKnownConfigurationKeys.Connectivity.SendViaReceiveQueue)); }
public async Task Can_send_a_brokered_message() { // default settings var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); settings.Set <TopologySettings>(new TopologySettings()); var namespacesDefinition = settings.Get <NamespaceConfigurations>(WellKnownConfigurationKeys.Topology.Addressing.Namespaces); namespacesDefinition.Add("namespace", AzureServiceBusConnectionString.Value, NamespacePurpose.Partitioning); // setup the infrastructure var namespaceManagerCreator = new NamespaceManagerCreator(settings); var namespaceLifecycleManager = new NamespaceManagerLifeCycleManagerInternal(namespaceManagerCreator); var messagingFactoryCreator = new MessagingFactoryCreator(namespaceLifecycleManager, settings); var messagingFactoryLifeCycleManager = new MessagingFactoryLifeCycleManager(messagingFactoryCreator, settings); var messageSenderCreator = new MessageSenderCreator(messagingFactoryLifeCycleManager, settings); var creator = new AzureServiceBusQueueCreator(settings.Get <TopologySettings>().QueueSettings, settings); // create the queue var namespaceManager = namespaceLifecycleManager.Get("namespace"); await creator.Create("myqueue", namespaceManager); // perform the test var sender = await messageSenderCreator.Create("myqueue", null, "namespace"); await sender.Send(new BrokeredMessage()); //validate var queue = await namespaceManager.GetQueue("myqueue"); Assert.IsTrue(queue.MessageCount > 0); //cleanup await namespaceManager.DeleteQueue("myqueue"); }
public async Task Should_be_able_to_create_partitioned_topic_with_multiple_rules() { const string subscriber = "subscriber"; const string filter1 = @"[x] LIKE 'x%'"; const string filter2 = @"[y] LIKE 'y%'"; var metadata2 = new ForwardingTopologySubscriptionMetadata { Description = "endpoint blah", NamespaceInfo = new RuntimeNamespaceInfo("name", AzureServiceBusConnectionString.Value), SubscribedEventFullName = "event2.full.name", SubscriptionNameBasedOnEventWithNamespace = "sha1.of.event2.full.name" }; var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); extensions.UseForwardingTopology().Topics().EnablePartitioning(true); var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value)); var creator = new AzureServiceBusForwardingSubscriptionCreator(new TopologySubscriptionSettings()); // add subscription with one rule await creator.Create(topicPath, subscriber, metadata, filter1, namespaceManager, forwardToQueue); // add additional rule to the same subscription var subscriptionDescription = await creator.Create(topicPath, subscriber, metadata2, filter2, namespaceManager, forwardToQueue); var rules = await namespaceManager.GetRules(subscriptionDescription); Assert.That(rules.Count(), Is.EqualTo(2), "Subscription didn't have correct number of rules"); await namespaceManager.DeleteSubscription(new SubscriptionDescription(topicPath, subscriber)); }
public void Should_extract_body_as_stream_when_configured() { // default settings var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); extensions.BrokeredMessageBodyType(SupportedBrokeredMessageBodyTypes.Stream); var converter = new BatchedOperationsToBrokeredMessagesConverter(settings); var bytes = Encoding.UTF8.GetBytes("Whatever"); var batchedOperation = new BatchedOperationInternal { Message = new OutgoingMessage("SomeId", new Dictionary <string, string>(), bytes), DeliveryConstraints = new List <DeliveryConstraint>() }; var brokeredMessage = converter.Convert(batchedOperation, new RoutingOptionsInternal()); var sr = new StreamReader(brokeredMessage.GetBody <Stream>()); var body = sr.ReadToEnd(); Assert.AreEqual("Whatever", body); }
public void Should_extract_body_as_stream_when_configured(string transportEncoding) { // default settings var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); extensions.BrokeredMessageBodyType(SupportedBrokeredMessageBodyTypes.Stream); var converter = new BrokeredMessagesToIncomingMessagesConverter(settings, new FakeMapper(settings, "MyQueue", "MyQueue")); var stream = new MemoryStream(); var writer = new StreamWriter(stream); writer.Write("Whatever"); writer.Flush(); stream.Position = 0; var brokeredMessage = new BrokeredMessage(stream); brokeredMessage.Properties[BrokeredMessageHeaders.TransportEncoding] = transportEncoding; var incomingMessage = converter.Convert(brokeredMessage); var body = Encoding.UTF8.GetString(incomingMessage.Body); Assert.AreEqual("Whatever", body); }
public void Should_apply_time_to_live() { var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var converter = new BatchedOperationsToBrokeredMessagesConverter(settings); var ttl = TimeSpan.FromMinutes(1); var headers = new Dictionary <string, string> { { Headers.TimeToBeReceived, ttl.ToString() } }; var batchedOperation = new BatchedOperationInternal { Message = new OutgoingMessage("SomeId", headers, new byte[0]), DeliveryConstraints = new List <DeliveryConstraint> { new DiscardIfNotReceivedBefore(ttl) } }; var brokeredMessage = converter.Convert(batchedOperation, new RoutingOptionsInternal()); Assert.IsTrue(brokeredMessage.TimeToLive == ttl); }
public void Should_set_replyto_address_to_destination_if_multiple_available_with_respect_to_secured_connection_strings_setting(bool shouldSecureConnectionString, string expectedReplyToAddress) { var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); settings.Set(WellKnownConfigurationKeys.Topology.Addressing.UseNamespaceAliasesInsteadOfConnectionStrings, shouldSecureConnectionString); var namespaces = new NamespaceConfigurations(new List <NamespaceInfo> { new NamespaceInfo("alias1", "Endpoint=sb://name-x.servicebus.windows.net;SharedAccessKeyName=keyname;SharedAccessKey=key"), new NamespaceInfo("alias2", "Endpoint=sb://name-y.servicebus.windows.net;SharedAccessKeyName=keyname;SharedAccessKey=key") }); settings.Set(WellKnownConfigurationKeys.Topology.Addressing.Namespaces, namespaces); var headers = new Dictionary <string, string> { { Headers.ReplyToAddress, "MyQueue" } }; var batchedOperation = new BatchedOperationInternal { Message = new OutgoingMessage("SomeId", headers, new byte[0]), DeliveryConstraints = new List <DeliveryConstraint>() }; var converter = new BatchedOperationsToBrokeredMessagesConverter(settings); var brokeredMessage = converter.Convert(batchedOperation, new RoutingOptionsInternal { DestinationNamespace = new RuntimeNamespaceInfo("alias2", "Endpoint=sb://name-y.servicebus.windows.net;SharedAccessKeyName=keyname;SharedAccessKey=key") }); Assert.That(brokeredMessage.ReplyTo, Is.EqualTo(expectedReplyToAddress)); }
public void Should_apply_delivery_at_specific_date() { // default settings var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var converter = new BatchedOperationsToBrokeredMessagesConverter(settings); var now = DateTime.UtcNow; Time.UtcNow = () => now; var delay = new DoNotDeliverBefore(now.AddDays(2)); var batchedOperation = new BatchedOperationInternal { Message = new OutgoingMessage("SomeId", new Dictionary <string, string>(), new byte[0]), DeliveryConstraints = new List <DeliveryConstraint> { delay } }; var brokeredMessage = converter.Convert(batchedOperation, new RoutingOptionsInternal()); Assert.IsTrue(brokeredMessage.ScheduledEnqueueTimeUtc == now.AddDays(2)); Time.UtcNow = () => DateTime.UtcNow; }
public async Task Should_throw_if_at_least_one_batch_fails() { // cleanup await TestUtility.Delete("myqueue", "myqueue2"); // default settings var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); settings.Set(new TopologySettings()); var namespacesDefinition = settings.Get <NamespaceConfigurations>(WellKnownConfigurationKeys.Topology.Addressing.Namespaces); namespacesDefinition.Add("namespace", AzureServiceBusConnectionString.Value, NamespacePurpose.Partitioning); // setup the infrastructure var namespaceManagerCreator = new NamespaceManagerCreator(settings); var namespaceLifecycleManager = new NamespaceManagerLifeCycleManagerInternal(namespaceManagerCreator); var messagingFactoryCreator = new MessagingFactoryCreator(namespaceLifecycleManager, settings); var messagingFactoryLifeCycleManager = new MessagingFactoryLifeCycleManager(messagingFactoryCreator, settings); var messageSenderCreator = new MessageSenderCreator(messagingFactoryLifeCycleManager, settings); var clientLifecycleManager = new MessageSenderLifeCycleManager(messageSenderCreator, settings); var router = new OutgoingBatchRouter(new BatchedOperationsToBrokeredMessagesConverter(settings), clientLifecycleManager, settings, new ThrowOnOversizedBrokeredMessages()); // create the queue var creator = new AzureServiceBusQueueCreator(settings.Get <TopologySettings>().QueueSettings, settings); var namespaceManager = namespaceLifecycleManager.Get("namespace"); await creator.Create("myqueue", namespaceManager); // perform the test var dispatcher = new Dispatcher(router, new FakeBatcher()); // validate Assert.ThrowsAsync <MessagingEntityNotFoundException>(async() => await dispatcher.Dispatch(new TransportOperations(), new TransportTransaction(), new ContextBag())); }
public void Should_throw_on_invalid_length(string entityPathOrName, EntityType entityType) { var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var sanitization = new ThrowOnFailedValidation(settings); Assert.Throws <Exception>(() => sanitization.Sanitize(entityPathOrName, entityType)); }
public async Task Should_properly_set_ForwardDeadLetteredMessagesTo_on_the_created_entity_that_qualifies_the_condition() { var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value)); var topicCreator = new AzureServiceBusTopicCreator(new TopologyTopicSettings()); var notUsedEntity = await topicCreator.Create("topic2forward2", namespaceManager); var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); extensions.UseForwardingTopology().Subscriptions().ForwardDeadLetteredMessagesTo(subPath => subPath.EndsWith("endpoint14"), notUsedEntity.Path); var creator = new AzureServiceBusForwardingSubscriptionCreator(settings.Get <TopologySettings>().SubscriptionSettings); const string subscriptionName = "endpoint14"; await creator.Create(topicPath, subscriptionName, metadata, sqlFilter, namespaceManager, forwardToQueue); var foundDescription = await namespaceManager.GetSubscription(topicPath, subscriptionName); Assert.That(foundDescription.ForwardDeadLetteredMessagesTo.EndsWith(notUsedEntity.Path)); await namespaceManager.DeleteSubscription(new SubscriptionDescription(topicPath, subscriptionName)); await namespaceManager.DeleteTopic(notUsedEntity.Path); }
public async Task Round_robins_across_instances_in_pool() { var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var creator = new InterceptedMessageReceiverCreator(); var lifecycleManager = new MessageReceiverLifeCycleManager(creator, settings); var poolSize = settings.Get <int>(WellKnownConfigurationKeys.Connectivity.NumberOfClientsPerEntity); var first = await lifecycleManager.Get("myqueue", AzureServiceBusConnectionString.Value); var next = first; var reuseInPool = false; for (var i = 0; i < poolSize - 1; i++) { var n = await lifecycleManager.Get("myqueue", AzureServiceBusConnectionString.Value); reuseInPool &= next == n; next = n; } var second = await lifecycleManager.Get("myqueue", AzureServiceBusConnectionString.Value); Assert.IsFalse(reuseInPool); Assert.AreEqual(first, second); }
public async Task Properly_sets_ForwardDeadLetteredMessagesTo_on_the_created_entity_that_qualifies_condition() { var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value)); var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); var creator = new AzureServiceBusQueueCreator(settings.Get <TopologySettings>().QueueSettings, settings); await creator.Create("myotherqueue", namespaceManager); extensions.Queues().ForwardDeadLetteredMessagesTo(name => name == "myqueue", "myotherqueue"); await creator.Create("myqueue", namespaceManager); var real = await namespaceManager.GetQueue("myqueue"); var forwardReal = await namespaceManager.GetQueue("myotherqueue"); Assert.IsTrue(real.ForwardDeadLetteredMessagesTo.EndsWith("myotherqueue")); Assert.IsTrue(string.IsNullOrEmpty(forwardReal.ForwardDeadLetteredMessagesTo)); //cleanup await namespaceManager.DeleteQueue("myqueue"); await namespaceManager.DeleteQueue("myotherqueue"); }
public async Task Should_throw_exception_for_a_message_that_exceeds_maximum_size() { // default settings var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); settings.Set(new TopologySettings()); var namespacesDefinition = settings.Get <NamespaceConfigurations>(WellKnownConfigurationKeys.Topology.Addressing.Namespaces); namespacesDefinition.Add("namespace", AzureServiceBusConnectionString.Value, NamespacePurpose.Partitioning); // setup the infrastructure var namespaceManagerCreator = new NamespaceManagerCreator(settings); var namespaceLifecycleManager = new NamespaceManagerLifeCycleManagerInternal(namespaceManagerCreator); var messagingFactoryCreator = new MessagingFactoryCreator(namespaceLifecycleManager, settings); var messagingFactoryLifeCycleManager = new MessagingFactoryLifeCycleManager(messagingFactoryCreator, settings); var messageSenderCreator = new MessageSenderCreator(messagingFactoryLifeCycleManager, settings); var clientLifecycleManager = new MessageSenderLifeCycleManager(messageSenderCreator, settings); var router = new OutgoingBatchRouter(new BatchedOperationsToBrokeredMessagesConverter(settings), clientLifecycleManager, settings, new ThrowOnOversizedBrokeredMessages()); // create the queue var creator = new AzureServiceBusQueueCreator(settings.Get <TopologySettings>().QueueSettings, settings); var namespaceManager = namespaceLifecycleManager.Get("namespace"); await creator.Create("myqueue", namespaceManager); // setup the batch var @namespace = new RuntimeNamespaceInfo("namespace", AzureServiceBusConnectionString.Value); var bytes = Enumerable.Range(0, settings.Get <int>(WellKnownConfigurationKeys.Connectivity.MessageSenders.MaximumMessageSizeInKilobytes) * 1024).Select(x => (byte)(x % 256)).ToArray(); var batch = new BatchInternal { Destinations = new TopologySectionInternal { Entities = new List <EntityInfoInternal> { new EntityInfoInternal { Namespace = @namespace, Path = "MyQueue", Type = EntityType.Queue } }, Namespaces = new List <RuntimeNamespaceInfo> { @namespace } }, RequiredDispatchConsistency = DispatchConsistency.Default, Operations = new List <BatchedOperationInternal> { new BatchedOperationInternal { Message = new OutgoingMessage("Id-1", new Dictionary <string, string>(), bytes), DeliveryConstraints = new List <DeliveryConstraint>() } } }; // perform the test Assert.That(async() => await router.RouteBatch(batch, null, DispatchConsistency.Default), Throws.Exception.TypeOf <MessageTooLargeException>()); }
public async Task Should_not_update_properties_of_an_existing_system_queue() { var queuePath = "errorQ"; var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value)); await namespaceManager.DeleteQueue(queuePath).ConfigureAwait(false); if (!await namespaceManager.QueueExists(queuePath).ConfigureAwait(false)) { await namespaceManager.CreateQueue(new QueueDescription(queuePath)).ConfigureAwait(false); } var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); settings.Set(WellKnownConfigurationKeys.Core.RecoverabilityNumberOfImmediateRetries, 2); var queueBindings = new QueueBindings(); queueBindings.BindSending(queuePath); settings.Set <QueueBindings>(queueBindings); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); extensions.Queues().LockDuration(TimeSpan.FromMinutes(4)); var creator = new AzureServiceBusQueueCreator(settings.Get <TopologySettings>().QueueSettings, settings); await creator.Create(queuePath, namespaceManager); var real = await namespaceManager.GetQueue(queuePath); Assert.That(real.LockDuration, Is.EqualTo(TimeSpan.FromSeconds(60))); //cleanup await namespaceManager.DeleteQueue(queuePath); }
public async Task Should_be_able_to_update_an_existing_queue_with_new_property_values() { var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value)); await namespaceManager.DeleteQueue("existingqueue").ConfigureAwait(false); await namespaceManager.CreateQueue(new QueueDescription("existingqueue")); var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); extensions.Queues().DescriptionCustomizer(qd => { qd.AutoDeleteOnIdle = TimeSpan.FromMinutes(100); qd.EnableExpress = true; }); var creator = new AzureServiceBusQueueCreator(settings.Get <TopologySettings>().QueueSettings, settings); await creator.Create("existingqueue", namespaceManager); var queueDescription = await namespaceManager.GetQueue("existingqueue"); Assert.AreEqual(TimeSpan.FromMinutes(100), queueDescription.AutoDeleteOnIdle); //cleanup await namespaceManager.DeleteQueue("existingqueue"); }
public async Task Properly_sets_ForwardDeadLetteredMessagesTo_on_the_created_entity() { var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value)); // forwarding queue needs to exist before you can use it as a forwarding target // needs to be created with different settings as it cannot forward to itself obviously var originalsettings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var originalcreator = new AzureServiceBusQueueCreator(new TopologyQueueSettings(), originalsettings); await originalcreator.Create("myotherqueue", namespaceManager); // actual test var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); extensions.Queues().ForwardDeadLetteredMessagesTo("myotherqueue"); var creator = new AzureServiceBusQueueCreator(settings.Get <TopologySettings>().QueueSettings, settings); await creator.Create("myqueue", namespaceManager); var real = await namespaceManager.GetQueue("myqueue"); Assert.IsTrue(real.ForwardDeadLetteredMessagesTo.EndsWith("myotherqueue")); //cleanup await namespaceManager.DeleteQueue("myqueue"); await namespaceManager.DeleteQueue("myotherqueue"); }
public void Should_remove_leading_and_trailing_slashes(string entityPathOrName, EntityType entityType, string expectedPathOrName) { var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var sanitization = new ValidateAndHashIfNeeded(settings); var sanitizedResult = sanitization.Sanitize(entityPathOrName, entityType); Assert.That(sanitizedResult, Is.EqualTo(expectedPathOrName)); }
public void Should_not_sanitize_characters_passing_default_validation_for_registered_sanitizer(string entityPathOrName, EntityType entityType, string expectedPathOrName) { var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var sanitization = new ValidateAndHashIfNeeded(settings); var sanitizedResult = sanitization.Sanitize(entityPathOrName, entityType); Assert.That(sanitizedResult, Is.EqualTo(expectedPathOrName)); }
public void Should_not_change_valid_paths_or_names(string entityPathOrName, EntityType entityType) { var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var sanitization = new ThrowOnFailedValidation(settings); var sanitizedResult = sanitization.Sanitize(entityPathOrName, entityType); Assert.That(sanitizedResult, Is.EqualTo(entityPathOrName)); }
public async Task Triggers_critical_error_when_receiver_cannot_be_started() { var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60)); // default settings var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); settings.Set <TopologySettings>(new TopologySettings()); var namespacesDefinition = settings.Get <NamespaceConfigurations>(WellKnownConfigurationKeys.Topology.Addressing.Namespaces); namespacesDefinition.Add("namespace", AzureServiceBusConnectionString.Value, NamespacePurpose.Partitioning); // setup the infrastructure var namespaceManagerCreator = new NamespaceManagerCreator(settings); var namespaceLifecycleManager = new NamespaceManagerLifeCycleManagerInternal(namespaceManagerCreator); var messagingFactoryCreator = new MessagingFactoryCreator(namespaceLifecycleManager, settings); var messagingFactoryLifeCycleManager = new MessagingFactoryLifeCycleManager(messagingFactoryCreator, settings); var messageReceiverCreator = new MessageReceiverCreator(messagingFactoryLifeCycleManager, settings); var clientEntityLifeCycleManager = new MessageReceiverLifeCycleManager(messageReceiverCreator, settings); var brokeredMessageConverter = new BrokeredMessagesToIncomingMessagesConverter(settings, new PassThroughMapper(settings)); // perform the test var notifier = new MessageReceiverNotifier(clientEntityLifeCycleManager, brokeredMessageConverter, BuildMessageReceiverNotifierSettings(settings)); var completed = new AsyncManualResetEvent(false); var error = new AsyncManualResetEvent(false); Exception ex = null; var received = false; notifier.Initialize(new EntityInfoInternal { Path = "myqueue", Namespace = new RuntimeNamespaceInfo("namespace", AzureServiceBusConnectionString.Value) }, (message, context) => { received = true; completed.Set(); return(TaskEx.Completed); }, null, exception => { ex = exception; error.Set(); }, null, 1); notifier.Start(); await Task.WhenAny(completed.WaitAsync(cts.Token).IgnoreCancellation(), error.WaitAsync(cts.Token).IgnoreCancellation()); // validate Assert.IsFalse(received); Assert.IsNotNull(ex); }
/// <inheritdoc cref="Initialize"/> public override TransportInfrastructure Initialize(SettingsHolder settings, string connectionString) { Guard.AgainstNull(nameof(settings), settings); Guard.AgainstNullAndEmpty(nameof(connectionString), connectionString); Guard.AgainstUnsetSerializerSetting(settings); DefaultConfigurationValues.Apply(settings); return(new AzureStorageQueueInfrastructure(settings, connectionString)); }
public void Should_throw_for_a_message_without_transport_encoding_header_supplied_and_actual_body_type_other_than_default() { // default settings var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var converter = new BrokeredMessagesToIncomingMessagesConverter(settings, new FakeMapper(settings, "MyQueue", "MyQueue")); var brokeredMessage = new BrokeredMessage("non-default-type"); Assert.Throws <UnsupportedBrokeredMessageBodyTypeException>(() => converter.Convert(brokeredMessage)); }
public void Should_sanitize_longer_than_maximum_path_or_name(string entityPathOrName, EntityType entityType) { var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var sanitization = new ValidateAndHashIfNeeded(settings); var sanitizedResult = sanitization.Sanitize(entityPathOrName, entityType); var expectedPathOrName = MD5DeterministicNameBuilder.Build(entityPathOrName); Assert.That(sanitizedResult, Is.EqualTo(expectedPathOrName)); }
public async Task Delegates_creation_to_messaging_factory() { var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var factory = new InterceptedMessagingFactory(); var creator = new MessageSenderCreator(new InterceptedMessagingFactoryFactory(factory), settings); var sender = await creator.Create("myqueue", null, AzureServiceBusConnectionString.Value); Assert.IsTrue(factory.IsInvoked); Assert.IsInstanceOf <IMessageSenderInternal>(sender); }
public async Task Creates_a_pool_of_clients_per_entity() { var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var poolSize = settings.Get <int>(WellKnownConfigurationKeys.Connectivity.NumberOfClientsPerEntity); var creator = new InterceptedMessageReceiverCreator(); var lifecycleManager = new MessageReceiverLifeCycleManager(creator, settings); await lifecycleManager.Get("myqueue", AzureServiceBusConnectionString.Value); Assert.AreEqual(poolSize, creator.InvocationCount); }