public void NotificationsSubscriber_WhenProcessingIsNotEnabled_AddsListenerToCollection(
            INotificationListener listener,
            EventStoreConnectionConfiguration connectionConfiguration)
        {
            connectionConfiguration.Notifications.Subscribe(listener);

            Assert.DoesNotContain(listener, connectionConfiguration.NotificationListeners);
        }
        public void OutgoingEventsWith_AddsItToOutgoingMutatorsList(
            IEventMutator mutator,
            EventStoreConnectionConfiguration connectionConfiguration)
        {
            connectionConfiguration.Mutate.OutgoingEventsWith(mutator);

            Assert.Contains(mutator, connectionConfiguration.OutgoingMessageMutators);
        }
Ejemplo n.º 3
0
        public void ReadEventStoreConnectionConfig(string name, int queueSize, int batchSize, string stream, string uri)
        {
            var config = new EventStoreConnectionConfiguration
            {
                ConnectionName   = name,
                MaxLiveQueueSize = queueSize,
                ReadBatchSize    = batchSize,
                Stream           = stream,
                Uri = uri
            };

            Assert.Equal(name, config.ConnectionName);
            Assert.Equal(queueSize, config.MaxLiveQueueSize);
            Assert.Equal(batchSize, config.ReadBatchSize);
            Assert.Equal(stream, config.Stream);
            Assert.Equal(uri, config.Uri);
        }
Ejemplo n.º 4
0
        public IEventStoreConnection Build()
        {
            if (m_configuration == null)
            {
                m_configuration = new EventStoreConnectionConfiguration();
                m_configure(m_configuration);

                m_configuration.AssertConfigurationCompleted();
                m_factory = new StorageFactory();
            }

            var connectivityState = new EventStoreConnectionState();

            var journalTable = new EventJournalTable(m_factory.CreateTable(
                                                         m_configuration.StorageConnectionString,
                                                         m_configuration.JournalTableName));

            var deploymentTable = m_factory.CreateTable(
                m_configuration.StorageConnectionString,
                m_configuration.EventStoreDeploymentTableName);

            var sessionFactory = new EventStreamConsumingSessionFactory(
                m_factory.CreateBlobContainer(
                    m_configuration.StorageConnectionString,
                    m_configuration.StreamConsumerSessionsBlobContainerName));

            var pipelineFactory = new EventMutationPipelineFactory(
                m_configuration.IncomingMessageMutators,
                m_configuration.OutgoingMessageMutators);

            var queues = Enumerable
                         .Range(0, m_configuration.NotificationQueuePartitionCount)
                         .Select(index => m_factory.CreateQueue(
                                     m_configuration.StorageConnectionString,
                                     m_configuration.NotificationQueueName + "-" + index.ToString("D3")))
                         .ToArray();

            var eventJournal = new EventJournal(journalTable);

            var consumersRegistry = new EventStreamConsumers(deploymentTable);
            var consumersService  = new ConsumersService(consumersRegistry, eventJournal);

            var notificationHub = new NotificationHub(
                new PollingJob("NotificationHubPollingJob", new PollingTimeout()),
                new NotificationsChannel(queues, new NotificationFormatter()),
                new ReceivedNotificationProcessor());

            var pendingNotificationTable          = m_factory.CreateTable(m_configuration.StorageConnectionString, m_configuration.PendingNotificationsTableName);
            var pendingNotifications              = new PendingNotifications(pendingNotificationTable);
            var pendingNotificationsChaserTimeout = new PollingTimeout(
                TimeSpan.FromMinutes(Constants.Settings.PENDING_NOTIFICATIONS_CHASER_INITIAL_TIMEOUT_IN_MINUTES),
                Constants.Settings.PENDING_NOTIFICATIONS_CHASER_TIMEOUT_MULTIPLIER,
                Constants.Settings.PENDING_NOTIFICATIONS_CHASER_TIMEOUT_INCREASING_THRESHOLD,
                TimeSpan.FromMinutes(Constants.Settings.PENDING_NOTIFICATIONS_CHASER_MAX_TIMEOUT_IN_MINUTES));

            var pendingNotificationsChaser = new PendingNotificationsChaser(
                pendingNotifications,
                notificationHub,
                new PollingJob("PendingNotificationsChaserPollingJob", pendingNotificationsChaserTimeout),
                m_factory.CreateBlobContainer(
                    m_configuration.StorageConnectionString,
                    m_configuration.PendingNotificationsChaserExclusiveAccessLockBlobContainerName).CreateBlockBlob(
                    m_configuration.PendingNotificationsChaserExclusiveAccessLockBlobName));

            connectivityState.ConnectionCreated += (sender, args) =>
            {
                if (m_configuration.BackgroundProcessingEnabled)
                {
                    foreach (var notificationListener in m_configuration.NotificationListeners)
                    {
                        notificationHub.Subscribe(notificationListener);
                    }

                    notificationHub.StartNotificationProcessing(args.Connection);
                    pendingNotificationsChaser.Start();
                }
            };

            connectivityState.ConnectionClosing += (sender, args) =>
            {
                if (m_configuration.BackgroundProcessingEnabled)
                {
                    notificationHub.StopNotificationProcessing();
                    pendingNotificationsChaser.Stop();
                }
            };

            connectivityState.ConnectionClosed += (sender, args) =>
            {
                if (m_configuration.BackgroundProcessingEnabled)
                {
                    foreach (var notificationListener in m_configuration.NotificationListeners)
                    {
                        notificationHub.Unsubscribe(notificationListener);
                    }
                }
            };

            return(new EventStoreConnection(
                       connectivityState,
                       eventJournal,
                       notificationHub,
                       pendingNotifications,
                       consumersRegistry,
                       sessionFactory,
                       pipelineFactory,
                       consumersService));
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     subscribe to a stream and count the events in it
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="configuration"></param>
        /// <returns></returns>
        private async Task <TestResult> CountEvents(IEventStoreConnection connection, EventStoreConnectionConfiguration configuration)
        {
            _output.WriteLine($"Counting all Events in Stream '{configuration.Stream}'", 1);

            var startTime = DateTime.Now;
            var stopTime  = DateTime.Now;

            // subscribe to the stream to count the number of events contained in it
            connection.SubscribeToStreamFrom(configuration.Stream,
                                             StreamCheckpoint.StreamStart,
                                             new CatchUpSubscriptionSettings(128, 256, false, true, "ConfigService.CLI.ConnectionTest"),
                                             (subscription, @event) => { _countedEvents += 1; },
                                             subscription =>
            {
                _output.WriteLine($"Subscription to '{subscription.SubscriptionName}' opened", 1);
                stopTime = DateTime.Now;
                _liveProcessingEvents = true;
            },
                                             (subscription, reason, exception) =>
            {
                _output.WriteLine(
                    $"Subscription to '{subscription.SubscriptionName}' dropped: " +
                    $"{reason}; {exception.GetType().Name} {exception.Message}", 1);
                stopTime             = DateTime.Now;
                _subscriptionDropped = true;
            });

            do
            {
                await Task.Delay(TimeSpan.FromSeconds(1));
            } while (!_liveProcessingEvents && !_subscriptionDropped);

            if (_subscriptionDropped)
            {
                _output.WriteLine($"Counted '{_countedEvents}' events in {FormatTime(stopTime - startTime)} before Subscription was dropped", 1);
                return(new TestResult
                {
                    Result = false,
                    Message = "Subscription was dropped"
                });
            }

            _output.WriteLine($"Counted '{_countedEvents}' events in {FormatTime(stopTime - startTime)}", 1);

            return(new TestResult
            {
                Result = true,
                Message = string.Empty
            });
        }
Ejemplo n.º 6
0
 /// <summary>
 ///     open a connection to an EventStore as configured in <paramref name="configuration"/>
 /// </summary>
 /// <param name="configuration"></param>
 /// <returns></returns>
 private IEventStoreConnection MakeConnection(EventStoreConnectionConfiguration configuration)
 => EventStoreConnection.Create(ConnectionSettings.Create()
                                .KeepReconnecting()
                                .KeepRetrying(),
                                new Uri(configuration.Uri),
                                configuration.ConnectionName);
 public void NotificationsSubscriber_ReturnsInstanceOfConnectionConfiguration(
     INotificationListener listener,
     EventStoreConnectionConfiguration connectionConfiguration)
 {
     Assert.Same(connectionConfiguration, connectionConfiguration.Notifications.Subscribe(listener));
 }
 public void OutgoingEventsWith_ReturnsInstanceOfConnectionConfiguration(
     IEventMutator mutator,
     EventStoreConnectionConfiguration connectionConfiguration)
 {
     Assert.Same(connectionConfiguration, connectionConfiguration.Mutate.OutgoingEventsWith(mutator));
 }