public async Task Handles_Many_Concurrent_Calls_Correctly_Without_Errors()
        {
            var tempDir = GetTempDirectory();
            Log.DebugFormat("Temp directory: {0}", tempDir);

            var sqliteSubscriptionService = new SQLiteSubscriptionTrackingService(tempDir);
            await sqliteSubscriptionService.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 => sqliteSubscriptionService.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 sqliteSubscriptionService.GetSubscribers(grouping.Key);
                Assert.That(actualSubscribers, Is.EquivalentTo(expectedSubscribers));
            }
        }
예제 #2
0
 public async Task<ISubscriptionTrackingService> CreateSubscriptionTrackingService(
     SubscriptionTrackingElement configuration)
 {
     var path = configuration.GetString("path");
     var sqliteBaseDir = new DirectoryInfo(GetRootedPath(path));
     var sqliteSubscriptionTrackingService = new SQLiteSubscriptionTrackingService(sqliteBaseDir);
     await sqliteSubscriptionTrackingService.Init();
     return sqliteSubscriptionTrackingService;
 }
예제 #3
0
        /// <inheritdoc />
        public Task <ISubscriptionTrackingService> CreateSubscriptionTrackingService(IConfiguration configuration)
        {
            var path          = configuration?["path"];
            var sqliteBaseDir = GetRootedDirectory(path);
            var sqliteSubscriptionTrackingService = new SQLiteSubscriptionTrackingService(sqliteBaseDir);

            sqliteSubscriptionTrackingService.Init();

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

            return(multicastFactory.InitSubscriptionTrackingService(multicastSection, sqliteSubscriptionTrackingService));
        }
예제 #4
0
        /// <inheritdoc />
        public Task <ISubscriptionTrackingService> CreateSubscriptionTrackingService(
            SubscriptionTrackingElement configuration)
        {
            var path          = configuration.GetString("path");
            var sqliteBaseDir = GetRootedDirectory(path);
            var sqliteSubscriptionTrackingService = new SQLiteSubscriptionTrackingService(sqliteBaseDir);

            sqliteSubscriptionTrackingService.Init();

            var multicast        = configuration.Multicast;
            var multicastFactory = new MulticastSubscriptionTrackingServiceFactory();

            return(multicastFactory.InitSubscriptionTrackingService(multicast, sqliteSubscriptionTrackingService));
        }
        public async Task Subscriber_Should_Not_Be_Returned_After_It_Is_Removed()
        {
            var tempDir = GetTempDirectory();
            Log.DebugFormat("Temp directory: {0}", tempDir);

            var sqliteSubscriptionService = new SQLiteSubscriptionTrackingService(tempDir);
            await sqliteSubscriptionService.Init();

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

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

            await sqliteSubscriptionService.RemoveSubscription(topic, subscriber);

            var subscribersAfterRemoval = await sqliteSubscriptionService.GetSubscribers(topic);
            Assert.That(subscribersAfterRemoval, Has.No.Member(subscriber));
        }
        public async Task Expired_Subscription_Should_Not_Be_Returned()
        {
            var tempDir = GetTempDirectory();
            Log.DebugFormat("Temp directory: {0}", tempDir);

            var sqliteSubscriptionService = new SQLiteSubscriptionTrackingService(tempDir);
            await sqliteSubscriptionService.Init();

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

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

            var subscribers = await sqliteSubscriptionService.GetSubscribers(topic);
            Assert.That(subscribers, Has.No.Member(subscriber));
        }
        public async Task Existing_Subscriptions_Should_Be_Loaded_When_Initializing()
        {
            var tempDir = GetTempDirectory();
            Log.DebugFormat("Temp directory: {0}", tempDir);

            var sqliteSubscriptionService = new SQLiteSubscriptionTrackingService(tempDir);
            await sqliteSubscriptionService.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 => sqliteSubscriptionService.AddSubscription(s.Topic, s.Subscriber)));

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

            var sqliteSubscriptionService2 = new SQLiteSubscriptionTrackingService(tempDir);
            await sqliteSubscriptionService2.Init();

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