コード例 #1
0
        /// <inheritdoc />
        public Task <ISubscriptionTrackingService> CreateSubscriptionTrackingService(IConfiguration configuration)
        {
            var connectionName = configuration["connectionName"];

            if (string.IsNullOrWhiteSpace(connectionName))
            {
                throw new ConfigurationErrorsException(
                          "Attribute 'connectionName' is required for SQL subscription tracking service");
            }

            var connectionStringSettings = ConfigurationManager.ConnectionStrings[connectionName];

            if (connectionStringSettings == null)
            {
                throw new ConfigurationErrorsException($"Connection string settings \"{connectionName}\" not found");
            }
            var sqlSubscriptionTrackingService = new SQLSubscriptionTrackingService(connectionStringSettings);

            sqlSubscriptionTrackingService.Init();

            var multicastSection = configuration.GetSection("multicast");
            var multicastFactory = new MulticastSubscriptionTrackingServiceFactory();

            return(multicastFactory.InitSubscriptionTrackingService(multicastSection, sqlSubscriptionTrackingService));
        }
コード例 #2
0
        public async Task Handles_Many_Concurrent_Calls_Correctly_Without_Errors()
        {
            var connectionStringSettings = GetConnectionStringSettings();
            var sqlSubscriptionService = new SQLSubscriptionTrackingService(connectionStringSettings);
            await sqlSubscriptionService.Init();

            var topicNames = Enumerable.Range(0, 10)
                .Select(i => new TopicName("Topic-" + i));

            var subscriptions = topicNames
                .SelectMany(t =>
                    Enumerable.Range(0, 100)
                        .Select(j => new Uri("http://localhost/subscriber-" + j))
                        .Select(s => new
                        {
                            Topic = t,
                            Subscriber = s
                        }))
                .ToList();

            await Task.WhenAll(subscriptions.Select(s => sqlSubscriptionService.AddSubscription(s.Topic, s.Subscriber)));

            var subscriptionsByTopic = subscriptions.GroupBy(s => s.Topic);
            foreach (var grouping in subscriptionsByTopic)
            {
                var expectedSubscribers = grouping.Select(g => g.Subscriber).ToList();
                var actualSubscribers = await sqlSubscriptionService.GetSubscribers(grouping.Key);
                Assert.That(actualSubscribers, Is.EquivalentTo(expectedSubscribers));
            }
        }
コード例 #3
0
        public async Task Subscriber_Should_Not_Be_Returned_After_It_Is_Removed()
        {
            var connectionStringSettings = GetConnectionStringSettings();
            var sqlSubscriptionService = new SQLSubscriptionTrackingService(connectionStringSettings);
            await sqlSubscriptionService.Init();

            var topic = "topic-0";
            var subscriber = new Uri("http://localhost/platibus");
            await sqlSubscriptionService.AddSubscription(topic, subscriber);

            var subscribers = await sqlSubscriptionService.GetSubscribers(topic);
            Assert.That(subscribers, Has.Member(subscriber));

            await sqlSubscriptionService.RemoveSubscription(topic, subscriber);

            var subscribersAfterRemoval = await sqlSubscriptionService.GetSubscribers(topic);
            Assert.That(subscribersAfterRemoval, Has.No.Member(subscriber));
        }
コード例 #4
0
        public async Task<ISubscriptionTrackingService> CreateSubscriptionTrackingService(
            SubscriptionTrackingElement configuration)
        {
            var connectionName = configuration.GetString("connectionName");
            if (string.IsNullOrWhiteSpace(connectionName))
            {
                throw new ConfigurationErrorsException(
                    "Attribute 'connectionName' is required for SQL subscription tracking service");
            }

            var connectionStringSettings = ConfigurationManager.ConnectionStrings[connectionName];
            if (connectionStringSettings == null)
            {
                throw new ConfigurationErrorsException("Connection string settings \"" + connectionName + "\" not found");
            }
            var sqlSubscriptionTrackingService = new SQLSubscriptionTrackingService(connectionStringSettings);
            await sqlSubscriptionTrackingService.Init();
            return sqlSubscriptionTrackingService;
        }
コード例 #5
0
        public async Task Expired_Subscription_Should_Not_Be_Returned()
        {
            var connectionStringSettings = GetConnectionStringSettings();
            Log.DebugFormat("Temp directory: {0}", connectionStringSettings);

            var sqlSubscriptionService = new SQLSubscriptionTrackingService(connectionStringSettings);
            await sqlSubscriptionService.Init();

            var topic = "topic-0";
            var subscriber = new Uri("http://localhost/platibus");
            await sqlSubscriptionService.AddSubscription(topic, subscriber, TimeSpan.FromMilliseconds(1));

            await Task.Delay(TimeSpan.FromMilliseconds(100));

            var subscribers = await sqlSubscriptionService.GetSubscribers(topic);
            Assert.That(subscribers, Has.No.Member(subscriber));
        }
コード例 #6
0
        public async Task Existing_Subscriptions_Should_Be_Loaded_When_Initializing()
        {
            var connectionStringSettings = GetConnectionStringSettings();
            var sqlSubscriptionService = new SQLSubscriptionTrackingService(connectionStringSettings);
            await sqlSubscriptionService.Init();

            var topicNames = Enumerable.Range(0, 10)
                .Select(i => new TopicName("Topic-" + i));

            var subscriptions = topicNames
                .SelectMany(t =>
                    Enumerable.Range(0, 100)
                        .Select(j => new Uri("http://localhost/subscriber-" + j))
                        .Select(s => new
                        {
                            Topic = t,
                            Subscriber = s
                        }))
                .ToList();

            await Task.WhenAll(subscriptions.Select(s => sqlSubscriptionService.AddSubscription(s.Topic, s.Subscriber)));

            // Next, initialize a new SQLSubscriptionService instance
            // with the same directory and observe that the subscriptions
            // are returned as expected.

            var sqlSubscriptionService2 = new SQLSubscriptionTrackingService(connectionStringSettings);
            await sqlSubscriptionService2.Init();

            var subscriptionsByTopic = subscriptions.GroupBy(s => s.Topic);
            foreach (var grouping in subscriptionsByTopic)
            {
                var expectedSubscribers = grouping.Select(g => g.Subscriber).ToList();
                var actualSubscribers = await sqlSubscriptionService2.GetSubscribers(grouping.Key);
                Assert.That(actualSubscribers, Is.EquivalentTo(expectedSubscribers));
            }
        }