Ejemplo n.º 1
0
        public async Task Should_only_count_topics_following_bundle_pattern()
        {
            var bundlePrefix = $"bundle{DateTime.Now.Ticks}-";

            nonBundledTopic = $"{bundlePrefix}x";

            namespaceManager = new NamespaceManagerAdapterInternal(NamespaceManager.CreateFromConnectionString(AzureServiceBusConnectionString.Value), AzureServiceBusConnectionString.Value);

            try
            {
                await namespaceManager.CreateTopic(new TopicDescription(nonBundledTopic));
            }
            catch (MessagingEntityAlreadyExistsException)
            {
                // ignore if topic already exists
            }

            var settings = new SettingsHolder();
            var namespaceConfigurations = new NamespaceConfigurations();
            var namespaceAlias          = "namespace1";

            namespaceConfigurations.Add(namespaceAlias, AzureServiceBusConnectionString.Value, NamespacePurpose.Routing);
            settings.Set(WellKnownConfigurationKeys.Topology.Addressing.Namespaces, namespaceConfigurations);

            var result = await NumberOfTopicsInBundleCheck.Run(new NamespaceManagerLifeCycleManagerInternal(new NamespaceManagerCreator(settings)), namespaceConfigurations, bundlePrefix);

            Assert.AreEqual(0, result.GetNumberOfTopicInBundle(namespaceAlias));
        }
        public async Task Should_not_throw_if_user_provided_a_custom_namespace_manager()
        {
            var settings = new SettingsHolder();

            var namespaces = new NamespaceConfigurations
            {
                { "name1", ConnectionStringValue.Build("namespace1"), NamespacePurpose.Partitioning },
                { "name2", ConnectionStringValue.Build("namespace2"), NamespacePurpose.Partitioning }
            };

            settings.Set(WellKnownConfigurationKeys.Topology.Addressing.Namespaces, namespaces);

#pragma warning disable 618
            var namespaceManager = A.Fake <INamespaceManager>();
#pragma warning restore 618
            A.CallTo(() => namespaceManager.CanManageEntities()).Returns(Task.FromResult(true));
#pragma warning disable 618
            var manageNamespaceLifeCycle = A.Fake <IManageNamespaceManagerLifeCycle>();
#pragma warning restore 618
            A.CallTo(() => manageNamespaceLifeCycle.Get(A <string> .Ignored)).Returns(namespaceManager);

            var namespaceBundleConfigurations = await NumberOfTopicsInBundleCheck.Run(manageNamespaceLifeCycle, namespaces, "bundle");

            Assert.That(namespaceBundleConfigurations.Count(), Is.Zero);
        }
        protected override ITopologySectionManagerInternal CreateTopologySectionManager(string defaultAlias, NamespaceConfigurations namespaces, INamespacePartitioningStrategy partitioning, AddressingLogic addressing)
        {
            var endpointName             = Settings.EndpointName();
            var numberOfEntitiesInBundle = Settings.Get <int>(WellKnownConfigurationKeys.Topology.Bundling.NumberOfEntitiesInBundle);

            bundlePrefix = Settings.Get <string>(WellKnownConfigurationKeys.Topology.Bundling.BundlePrefix);

            topologySectionManager = new ForwardingTopologySectionManager(defaultAlias, namespaces, endpointName, numberOfEntitiesInBundle, bundlePrefix, partitioning, addressing);
            // By design the topology section manager should determine the resources to create without needing information
            // from ASB. When we realized one bundle was enough we had to call out for backward compatibility reasons to query
            // how many bundles there are. This is async but should happen outside the actual section manager. Thus
            // the callback was introduced.
            topologySectionManager.Initialize = async() =>
            {
                if (Interlocked.Exchange(ref initializeSignaled, 1) != 0)
                {
                    return;
                }

                var bundleConfigurations = await NumberOfTopicsInBundleCheck.Run(namespaceManager, namespaceConfigurations, bundlePrefix)
                                           .ConfigureAwait(false);

                topologySectionManager.BundleConfigurations = bundleConfigurations;
            };
            return(topologySectionManager);
        }