Esempio n. 1
0
        public void Increase_WhenCallsThresholdWasNotHappend_Tests()
        {
            var timeout = new PollingTimeout();

            timeout.Increase();
            Assert.Equal(TimeSpan.FromSeconds(1), timeout.Value);
        }
Esempio n. 2
0
        public void Increase_WhenCallsThresholdWasHappend_Tests()
        {
            var timeout = new PollingTimeout();

            Assert.Equal(TimeSpan.FromSeconds(1), timeout.Value);

            Increase(timeout, PollingTimeout.INCREASING_THRESHOLD);
            Assert.Equal(TimeSpan.FromSeconds(5), timeout.Value);

            Increase(timeout, PollingTimeout.INCREASING_THRESHOLD);
            Assert.Equal(TimeSpan.FromSeconds(10), timeout.Value);

            Increase(timeout, PollingTimeout.INCREASING_THRESHOLD);
            Assert.Equal(TimeSpan.FromSeconds(15), timeout.Value);

            Increase(timeout, PollingTimeout.INCREASING_THRESHOLD);
            Assert.Equal(TimeSpan.FromSeconds(20), timeout.Value);

            Increase(timeout, PollingTimeout.INCREASING_THRESHOLD);
            Assert.Equal(TimeSpan.FromSeconds(25), timeout.Value);

            Increase(timeout, PollingTimeout.INCREASING_THRESHOLD);
            Assert.Equal(TimeSpan.FromSeconds(30), timeout.Value);

            Increase(timeout, PollingTimeout.INCREASING_THRESHOLD);
            Assert.Equal(TimeSpan.FromSeconds(30), timeout.Value);
        }
Esempio n. 3
0
        public void WaitAsync_WhenCancellationTokenWasCancelled_DoesNotThrow()
        {
            var timeout = new PollingTimeout(TimeSpan.FromSeconds(10), 1, 1, TimeSpan.FromSeconds(10));
            var cts     = new CancellationTokenSource();

            var waitTask = timeout.WaitAsync(cts.Token);

            cts.Cancel();
            waitTask.Wait();
        }
Esempio n. 4
0
        public void Reset_Tests()
        {
            var timeout = new PollingTimeout();

            Increase(timeout, PollingTimeout.INCREASING_THRESHOLD);
            Assert.Equal(TimeSpan.FromSeconds(5), timeout.Value);

            timeout.Reset();
            Assert.Equal(TimeSpan.FromSeconds(1), timeout.Value);
        }
Esempio n. 5
0
        public override int GetHashCode()
        {
            var hashCode = 1183322437;

            hashCode = hashCode * -1521134295 + base.GetHashCode();
            hashCode = hashCode * -1521134295 + PollingTimeout.GetHashCode();
            hashCode = hashCode * -1521134295 + UnitId.GetHashCode();
            hashCode = hashCode * -1521134295 + EqualityComparer <List <ModbusVariableParams> > .Default.GetHashCode(Variables);

            return(hashCode);
        }
Esempio n. 6
0
 public override string ToString()
 {
     return(String.Format("PolleableBean({0}, PollingTimeout: {1}, PollingInterval: {2})", base.ToString(),
                          PollingTimeout.ToString(), PollingInterval.ToString()));
 }
Esempio n. 7
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));
        }
 public Task Timeout(PollingTimeout state, IMessageHandlerContext context)
 => CheckTransactionStatusAsync(context);