public async Task Should_create_a_subscription_based_on_event_type_full_name_for_an_event_name_reused_across_multiple_namespaces() { var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value)); await namespaceManager.CreateSubscription(new SubscriptionDescription(topicPath, nameof(Ns1.ReusedEvent)), new SqlSubscriptionFilter(typeof(Ns1.ReusedEvent)).Serialize()); var creator = new AzureServiceBusSubscriptionCreatorV6(new TopologySubscriptionSettings()); var metadata1 = new SubscriptionMetadataInternal { SubscriptionNameBasedOnEventWithNamespace = typeof(Ns1.ReusedEvent).FullName, Description = Guid.NewGuid().ToString() }; var metadata2 = new SubscriptionMetadataInternal { SubscriptionNameBasedOnEventWithNamespace = typeof(Ns2.ReusedEvent).FullName, Description = Guid.NewGuid().ToString() }; var shortedSubscriptionName = typeof(Ns2.ReusedEvent).FullName; await creator.Create(topicPath, nameof(Ns1.ReusedEvent), metadata1, new SqlSubscriptionFilter(typeof(Ns1.ReusedEvent)).Serialize(), namespaceManager); await creator.Create(topicPath, nameof(Ns2.ReusedEvent), metadata2, new SqlSubscriptionFilter(typeof(Ns2.ReusedEvent)).Serialize(), namespaceManager); var subscriptionDescription = await namespaceManager.GetSubscription(topicPath, shortedSubscriptionName); Assert.AreEqual(metadata2.Description, subscriptionDescription.UserMetadata); Assert.AreEqual(metadata2.SubscriptionNameBasedOnEventWithNamespace, subscriptionDescription.Name); await namespaceManager.DeleteSubscription(new SubscriptionDescription(topicPath, nameof(Ns1.ReusedEvent))); await namespaceManager.DeleteSubscription(new SubscriptionDescription(topicPath, nameof(Ns2.ReusedEvent))); }
public async Task Should_properly_set_ForwardTo_on_the_created_entity() { var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value)); await namespaceManager.CreateSubscription(new SubscriptionDescription(topicPath, nameof(Ns1.ReusedEvent)), new SqlSubscriptionFilter(typeof(Ns1.ReusedEvent)).Serialize()); var topicCreator = new AzureServiceBusTopicCreator(new TopologyTopicSettings()); var topicToForwardTo = await topicCreator.Create("topic2forward2", namespaceManager); var creator = new AzureServiceBusSubscriptionCreatorV6(new TopologySubscriptionSettings()); var metadata1 = new SubscriptionMetadataInternal { SubscriptionNameBasedOnEventWithNamespace = typeof(Ns1.ReusedEvent).FullName, Description = Guid.NewGuid().ToString() }; var subscriptionName = nameof(Ns1.ReusedEvent); await creator.Create(topicPath, subscriptionName, metadata1, new SqlSubscriptionFilter(typeof(Ns1.ReusedEvent)).Serialize(), namespaceManager, topicToForwardTo.Path); // create again without forward to await creator.Create(topicPath, subscriptionName, metadata1, new SqlSubscriptionFilter(typeof(Ns1.ReusedEvent)).Serialize(), namespaceManager); var subscriptionDescription = await namespaceManager.GetSubscription(topicPath, subscriptionName); Assert.IsNull(subscriptionDescription.ForwardTo); await namespaceManager.DeleteSubscription(new SubscriptionDescription(topicPath, subscriptionName)); await namespaceManager.DeleteTopic(topicToForwardTo.Path); }
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 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 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 async Task Should_store_event_original_name_as_usermetadata() { const string subscriptionName = "sub16"; var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value), AzureServiceBusConnectionString.Value); var creator = new AzureServiceBusSubscriptionCreator(new TopologySubscriptionSettings()); var subscriptionDescription = await creator.Create(topicPath, subscriptionName, new SubscriptionMetadataInternal { Description = "very.long.name.of.an.event.that.would.exceed.subscription.length" }, sqlFilter, namespaceManager); Assert.IsTrue(await namespaceManager.SubscriptionExists(topicPath, subscriptionName)); Assert.AreEqual("very.long.name.of.an.event.that.would.exceed.subscription.length", subscriptionDescription.UserMetadata); await namespaceManager.DeleteSubscription(new SubscriptionDescription(topicPath, subscriptionName)); }
public async Task Should_properly_set_EnableDeadLetteringOnMessageExpiration_on_the_created_entity() { var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value)); var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); extensions.UseForwardingTopology().Subscriptions().EnableDeadLetteringOnMessageExpiration(true); var creator = new AzureServiceBusForwardingSubscriptionCreator(settings.Get <TopologySettings>().SubscriptionSettings); const string subscriptionName = "endpoint7"; await creator.Create(topicPath, subscriptionName, metadata, sqlFilter, namespaceManager, forwardToQueue); var foundDescription = await namespaceManager.GetSubscription(topicPath, subscriptionName); Assert.IsTrue(foundDescription.EnableDeadLetteringOnMessageExpiration); await namespaceManager.DeleteSubscription(new SubscriptionDescription(topicPath, subscriptionName)); }
public async Task Should_set_forwarding_to_an_explicitly_provided_forwardto() { var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value), AzureServiceBusConnectionString.Value); var queueCreator = new AzureServiceBusQueueCreator(new TopologyQueueSettings(), DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer())); var queueToForwardTo = await queueCreator.Create("forwardto", namespaceManager); var creator = new AzureServiceBusSubscriptionCreator(new TopologySubscriptionSettings()); const string subscriptionName = "sub15"; await creator.Create(topicPath, subscriptionName, metadata, sqlFilter, namespaceManager, queueToForwardTo.Path); var foundDescription = await namespaceManager.GetSubscription(topicPath, subscriptionName); Assert.That(foundDescription.ForwardTo.EndsWith(queueToForwardTo.Path)); await namespaceManager.DeleteSubscription(new SubscriptionDescription(topicPath, subscriptionName)); await namespaceManager.DeleteQueue(queueToForwardTo.Path); }
public async Task Should_properly_set_EnableBatchedOperations_on_the_created_entity() { var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value), AzureServiceBusConnectionString.Value); var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); extensions.Subscriptions().EnableBatchedOperations(false); var creator = new AzureServiceBusSubscriptionCreator(settings.Get <TopologySettings>().SubscriptionSettings); const string subscriptionName = "sub5"; await creator.Create(topicPath, subscriptionName, metadata, sqlFilter, namespaceManager); var foundDescription = await namespaceManager.GetSubscription(topicPath, subscriptionName); Assert.IsFalse(foundDescription.EnableBatchedOperations); await namespaceManager.DeleteSubscription(new SubscriptionDescription(topicPath, subscriptionName)); }
public async Task Should_properly_set_use_subscription_description_defaults_if_user_does_not_provide_topic_description_values() { var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value)); var creator = new AzureServiceBusForwardingSubscriptionCreator(new TopologySubscriptionSettings()); const string subscriptionName = "endpoint1"; var subscriptionDescription = await creator.Create(topicPath, subscriptionName, metadata, sqlFilter, namespaceManager, forwardToQueue); Assert.IsTrue(await namespaceManager.SubscriptionExists(topicPath, subscriptionName)); Assert.AreEqual(TimeSpan.MaxValue, subscriptionDescription.AutoDeleteOnIdle); Assert.AreEqual(TimeSpan.MaxValue, subscriptionDescription.DefaultMessageTimeToLive); Assert.AreEqual(TimeSpan.FromMilliseconds(30000), subscriptionDescription.LockDuration); Assert.True(subscriptionDescription.EnableBatchedOperations); Assert.IsFalse(subscriptionDescription.EnableDeadLetteringOnFilterEvaluationExceptions); Assert.IsFalse(subscriptionDescription.EnableDeadLetteringOnMessageExpiration); Assert.IsFalse(subscriptionDescription.RequiresSession); Assert.AreEqual(AzureServiceBusForwardingSubscriptionCreator.DefaultMaxDeliveryCountForNoImmediateRetries, subscriptionDescription.MaxDeliveryCount); Assert.IsNull(subscriptionDescription.ForwardDeadLetteredMessagesTo); Assert.That(subscriptionDescription.ForwardTo, Does.EndWith(forwardToQueue)); await namespaceManager.DeleteSubscription(new SubscriptionDescription(topicPath, subscriptionName)); }
public async Task Should_properly_set_DefaultMessageTimeToLive_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 timeToLive = TimeSpan.FromDays(10); extensions.Subscriptions().DefaultMessageTimeToLive(timeToLive); var creator = new AzureServiceBusSubscriptionCreator(settings.Get <TopologySettings>().SubscriptionSettings); const string subscriptionName = "sub4"; await creator.Create(topicPath, subscriptionName, metadata, sqlFilter, namespaceManager); var foundDescription = await namespaceManager.GetSubscription(topicPath, subscriptionName); Assert.AreEqual(timeToLive, foundDescription.DefaultMessageTimeToLive); await namespaceManager.DeleteSubscription(new SubscriptionDescription(topicPath, subscriptionName)); }
public async Task Should_properly_set_ForwardTo_on_the_created_entity_with_hierarchy() { var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value), AzureServiceBusConnectionString.Value); var queueCreator = new AzureServiceBusQueueCreator(new TopologyQueueSettings(), DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer())); var queueToForwardTo = await queueCreator.Create("forwardto", namespaceManager); var creator = new AzureServiceBusSubscriptionCreator(new TopologySubscriptionSettings()); const string subscriptionName = "sub17"; await creator.Create(hierarchyTopicPath, subscriptionName, metadata, sqlFilter, namespaceManager, queueToForwardTo.Path); // create again without forward to await creator.Create(hierarchyTopicPath, subscriptionName, metadata, sqlFilter, namespaceManager); var foundDescription = await namespaceManager.GetSubscription(hierarchyTopicPath, subscriptionName); Assert.IsNull(foundDescription.ForwardTo); await namespaceManager.DeleteSubscription(new SubscriptionDescription(hierarchyTopicPath, subscriptionName)); await namespaceManager.DeleteQueue(queueToForwardTo.Path); }
public async Task Should_properly_set_use_subscription_description_provided_by_user() { var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value)); const string subscriptionName = "endpoint2"; var userCustomizationsWhereInvoked = false; extensions.Subscriptions().DescriptionCustomizer(_ => { userCustomizationsWhereInvoked = true; }); var creator = new AzureServiceBusForwardingSubscriptionCreator(settings.Get <TopologySettings>().SubscriptionSettings); await creator.Create(topicPath, subscriptionName, metadata, sqlFilter, namespaceManager, forwardToQueue); Assert.IsTrue(await namespaceManager.SubscriptionExists(topicPath, subscriptionName)); Assert.IsTrue(userCustomizationsWhereInvoked); await namespaceManager.DeleteSubscription(new SubscriptionDescription(topicPath, subscriptionName)); }
public async Task Should_create_subscription_with_sql_filter() { const string subscriber = "subscriber"; const string filter = @"[NServiceBus.EnclosedMessageTypes] LIKE 'Test.SomeEvent%'" + " OR [NServiceBus.EnclosedMessageTypes] LIKE '%Test.SomeEvent%'" + " OR [NServiceBus.EnclosedMessageTypes] LIKE '%Test.SomeEvent'" + " OR [NServiceBus.EnclosedMessageTypes] = 'Test.SomeEvent'"; var namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value)); var creator = new AzureServiceBusForwardingSubscriptionCreator(new TopologySubscriptionSettings()); var subscriptionDescription = await creator.Create(topicPath, subscriber, metadata, filter, namespaceManager, forwardToQueue); var rules = await namespaceManager.GetRules(subscriptionDescription); var foundFilter = rules.First().Filter as SqlFilter; Assert.IsTrue(rules.Count() == 1, "Subscription should only have 1 rule"); Assert.AreEqual(filter, foundFilter.SqlExpression, "Rule was expected to have a specific SQL filter, but it didn't"); await namespaceManager.DeleteSubscription(new SubscriptionDescription(topicPath, subscriber)); }