Exemplo n.º 1
0
        public RunspacesStatsMonitor(
            int maxNumberOfRunspaces,
            int maxRunspaceIdleTimeMinutes,
            int maxRunspaceActiveTimeMinutes,
            IRunspaceStatsFactory runspaceStatsFactory,
            IRemoveExpiredIdleRunspaceRuleFactory removeExpiredIdleRuleFactory,
            IRemoveExpiredActiveRunspaceRuleFactory removeExpiredActiveRuleFactory,
            RunspaceRetentionPolicy runspaceRetentionPolicy)
        {
            if (removeExpiredIdleRuleFactory == null)
            {
                throw new ArgumentNullException(nameof(removeExpiredIdleRuleFactory));
            }
            if (removeExpiredActiveRuleFactory == null)
            {
                throw new ArgumentNullException(nameof(removeExpiredActiveRuleFactory));
            }

            _maxNumberOfRunspaces = maxNumberOfRunspaces;

            _removeExpiredIdleRuleFactory   = removeExpiredIdleRuleFactory;
            _removeExpiredActiveRuleFactory = removeExpiredActiveRuleFactory;

            if (runspaceRetentionPolicy == null)
            {
                // Create retention policy with rules

                _lastConfiguredMaxRunspaceIdleTimeMinutes   = maxRunspaceIdleTimeMinutes;
                _lastConfiguredMaxRunspaceActiveTimeMinutes = maxRunspaceActiveTimeMinutes;

                _retentionPolicy = new RunspaceRetentionPolicy(
                    new IRunspaceRetentionRule[] {
                    new KeepActiveRunspaceOnInactiveSessionRule(),
                    _removeExpiredIdleRuleFactory.Create(maxRunspaceIdleTimeMinutes),
                    _removeExpiredActiveRuleFactory.Create(maxRunspaceActiveTimeMinutes),
                });
            }
            else
            {
                _retentionPolicy = runspaceRetentionPolicy;
            }

            _runspaceStatsFactory = runspaceStatsFactory;
        }
Exemplo n.º 2
0
        public void PolicyKeepsWhenAllRulesKeep()
        {
            // Arrange
            var rule1Mock = new Mock <IRunspaceRetentionRule>();

            rule1Mock.Setup(r => r.ShouldRemove(It.IsAny <IRunspaceStats>())).Returns(false);

            var rule2Mock = new Mock <IRunspaceRetentionRule>();

            rule2Mock.Setup(r => r.ShouldRemove(It.IsAny <IRunspaceStats>())).Returns(false);

            var policy = new RunspaceRetentionPolicy(new[] { rule1Mock.Object, rule2Mock.Object });

            // Act
            var actual = policy.ShouldRemove(null);

            // Assert
            Assert.IsFalse(actual);
        }
Exemplo n.º 3
0
        public void UpdateConfiguration(
            int maxNumberOfRunspaces,
            int maxRunspaceIdleTimeMinutes,
            int maxRunspaceActiveTimeMinutes)
        {
            _maxNumberOfRunspaces = maxNumberOfRunspaces;

            if (ShouldUpdateRetentionPolicy(maxRunspaceIdleTimeMinutes, maxRunspaceActiveTimeMinutes))
            {
                // Create new retention policy with updated settings
                _lastConfiguredMaxRunspaceIdleTimeMinutes   = maxRunspaceIdleTimeMinutes;
                _lastConfiguredMaxRunspaceActiveTimeMinutes = maxRunspaceActiveTimeMinutes;

                _retentionPolicy = new RunspaceRetentionPolicy(
                    new IRunspaceRetentionRule[] {
                    new KeepActiveRunspaceOnInactiveSessionRule(),
                    _removeExpiredIdleRuleFactory.Create(maxRunspaceIdleTimeMinutes),
                    _removeExpiredActiveRuleFactory.Create(maxRunspaceActiveTimeMinutes),
                });
            }
        }