public WebHooksRepository(IStreamStore streamStore, string name, GetUtcNow getUtcNow, int maxWebHookCount)
 {
     _streamStore     = streamStore;
     _name            = name;
     _getUtcNow       = getUtcNow;
     _maxWebHookCount = maxWebHookCount;
 }
Beispiel #2
0
        public void ShouldThrottle_WhenCalledWithCumulativeNGreaterThanMaxSleepCumulativeNGreaterThanMax()
        {
            _getUtcNow = () => new DateTime(2014, 2, 27, 0, 0, 0, DateTimeKind.Utc);
            var virtualNow = _getUtcNow();

            for (var i = 0; i < 3 * Cumulative; i++)
            {
                _bucket.ShouldThrottle(NLessThanMax);
            }

            var before       = _bucket.ShouldThrottle(NLessThanMax);
            var tokensBefore = _bucket.CurrentTokenCount;

            before.Should().BeTrue();
            tokensBefore.Should().BeLessThan(NLessThanMax);

            _getUtcNow = () => virtualNow.AddSeconds(RefillInterval);

            for (var i = 0; i < 3 * Cumulative; i++)
            {
                _bucket.ShouldThrottle(NLessThanMax);
            }
            var after       = _bucket.ShouldThrottle(NLessThanMax);
            var tokensAfter = _bucket.CurrentTokenCount;

            after.Should().BeTrue();
            tokensAfter.Should().BeLessThan(NLessThanMax);
        }
 public InMemoryStreamStore(GetUtcNow getUtcNow = null, string logName = null)
     : base(TimeSpan.FromMinutes(1), 10000, getUtcNow, logName ?? nameof(InMemoryStreamStore))
 {
     _getUtcNow = getUtcNow ?? SystemClock.GetUtcNow;
     _allStream.AddFirst(new InMemoryStreamMessage(
                             "<in-memory-root-message>",
                             Guid.NewGuid(),
                             -1,
                             -1,
                             _getUtcNow(),
                             null,
                             null,
                             null));
     _onStreamAppended = () =>
     {
         if (_signallingToSubscribers.CompareExchange(true, false) == false)
         {
             Task.Run(() =>
             {
                 _subscriptions.OnNext(Unit.Default);
                 _signallingToSubscribers.Set(false);
             });
         }
     };
 }
        public void ShouldThrottle_WhenCalledWithCumulativeNGreaterThanMaxSleepCumulativeNGreaterThanMax()
        {
            _getUtcNow = () => new DateTime(2014, 2, 27, 0, 0, 0, DateTimeKind.Utc);
            var virtualNow = _getUtcNow();

            for (int i = 0; i < 3 * CUMULATIVE; i++)
            {
                _bucket.ShouldThrottle(N_LESS_THAN_MAX);
            }

            bool before       = _bucket.ShouldThrottle(N_LESS_THAN_MAX);
            long tokensBefore = _bucket.CurrentTokenCount;

            before.ShouldBeTrue();
            tokensBefore.ShouldBeLessThan(N_LESS_THAN_MAX);

            _getUtcNow = () => virtualNow.AddSeconds(REFILL_INTERVAL);

            for (int i = 0; i < 3 * CUMULATIVE; i++)
            {
                _bucket.ShouldThrottle(N_LESS_THAN_MAX);
            }
            bool after       = _bucket.ShouldThrottle(N_LESS_THAN_MAX);
            long tokensAfter = _bucket.CurrentTokenCount;

            after.ShouldBeTrue();
            tokensAfter.ShouldBeLessThan(N_LESS_THAN_MAX);
        }
        public void ShouldThrottle_WhenCalledWithNLessThanMaxSleepCumulativeNLessThanMax()
        {
            _getUtcNow = () => new DateTime(2014, 2, 27, 0, 0, 0, DateTimeKind.Utc);
            var virtualNow = _getUtcNow();

            long sum = 0;

            for (int i = 0; i < CUMULATIVE; i++)
            {
                _bucket.ShouldThrottle(N_LESS_THAN_MAX).ShouldBeFalse();
                sum += N_LESS_THAN_MAX;
            }
            long tokensBefore = _bucket.CurrentTokenCount;

            tokensBefore.ShouldBe(MAX_TOKENS - sum);

            _getUtcNow = () => virtualNow.AddSeconds(REFILL_INTERVAL);

            for (int i = 0; i < CUMULATIVE; i++)
            {
                _bucket.ShouldThrottle(N_LESS_THAN_MAX).ShouldBeFalse();
            }
            long tokensAfter = _bucket.CurrentTokenCount;

            tokensAfter.ShouldBe(MAX_TOKENS - sum);
        }
Beispiel #6
0
        public void ShouldThrottle_WhenCalledWithNLessThanMaxSleepCumulativeNLessThanMax()
        {
            _getUtcNow = () => new DateTime(2014, 2, 27, 0, 0, 0, DateTimeKind.Utc);
            var virtualNow = _getUtcNow();

            long sum = 0;

            for (var i = 0; i < Cumulative; i++)
            {
                _bucket.ShouldThrottle(NLessThanMax).Should().BeFalse();
                sum += NLessThanMax;
            }
            var tokensBefore = _bucket.CurrentTokenCount;

            tokensBefore.Should().Be(MaxTokens - sum);

            _getUtcNow = () => virtualNow.AddSeconds(RefillInterval);

            for (var i = 0; i < Cumulative; i++)
            {
                _bucket.ShouldThrottle(NLessThanMax).Should().BeFalse();
            }
            var tokensAfter = _bucket.CurrentTokenCount;

            tokensAfter.Should().Be(MaxTokens - sum);
        }
 public FixedTokenBucket(Func <int> getBucketTokenCapacty, GetUtcNow getUtcNow = null)
 {
     _getBucketTokenCapacty = getBucketTokenCapacty;
     _refillInterval        = TimeSpan.FromSeconds(1);
     _refillIntervalTicks   = TimeSpan.FromSeconds(1).Ticks;
     _getUtcNow             = getUtcNow ?? SystemClock.GetUtcNow;
 }
 protected StreamStoreBase(
     TimeSpan metadataMaxAgeCacheExpiry,
     int metadataMaxAgeCacheMaxSize,
     GetUtcNow getUtcNow,
     string logName)
     : base(metadataMaxAgeCacheExpiry, metadataMaxAgeCacheMaxSize, getUtcNow, logName)
 {
 }
Beispiel #9
0
 public WebHooks(WebHooksMemento webHooksMemento, GetUtcNow getUtcNow, int maxCount)
     : this(getUtcNow, maxCount)
 {
     _webHooks = webHooksMemento
                 .Items
                 .Select(w => new WebHook(w))
                 .ToDictionary(w => w.Id, w => w);
 }
        public MetadataMaxAgeCacheTests()
        {
            _currentUtc = new DateTime(2016, 1, 1, 0, 0, 0);
            GetUtcNow getUtcNow = () => _currentUtc;

            _store = new InMemoryStreamStore(getUtcNow);
            _cache = new MetadataMaxAgeCache(_store, _expiry, _maxSize, getUtcNow);
        }
 public FixedTokenBucket(
     Func<int> getBucketTokenCapacty,
     GetUtcNow getUtcNow = null)
 {
     _getBucketTokenCapacty = getBucketTokenCapacty;
     _refillInterval = TimeSpan.FromSeconds(1);
     _refillIntervalTicks = TimeSpan.FromSeconds(1).Ticks;
     _getUtcNow = getUtcNow ?? SystemClock.GetUtcNow;
 }
Beispiel #12
0
 public ScreeningAppService(IAggregateStore aggregateStore,
                            GetUtcNow getUtcNow,
                            GetMovieDuration getMovieDuration,
                            GetTheaterCapacity getTheaterCapacity) : base(aggregateStore)
 {
     _getUtcNow          = getUtcNow;
     _getMovieDuration   = getMovieDuration;
     _getTheaterCapacity = getTheaterCapacity;
 }
Beispiel #13
0
 //MonthlyAmount information or maybe with different API
 public static EmployeeSummary Load(IReadOnlyEmployee employee, GetUtcNow nowUtc)
 {
     return(new EmployeeSummary()
     {
         Id = employee.Id,
         DateOfBirth = employee.DateOfBirth,
         Height = employee.Height,
         Age = employee.DateOfBirth.GetAge(nowUtc()) //Another way might be that we calculate this from the data storage. But put some restriction on how we sore data
     });
 }
        public SqliteEventStore(ISQLitePlatform sqLitePlatform, string databasePath, GetUtcNow getUtcNow = null)
        {
            Ensure.That(sqLitePlatform, "sqLitePlatform").IsNotNull();
            Ensure.That(databasePath, "databasePath").IsNotNull();

            _getUtcNow = getUtcNow ?? SystemClock.GetUtcNow;
            _connectionPool = new SQLiteConnectionPool(sqLitePlatform);
            var connectionString = new SQLiteConnectionString(databasePath, false);
            _getConnection = () => _connectionPool.GetConnection(connectionString);
        }
Beispiel #15
0
        public SqliteEventStore(ISQLitePlatform sqLitePlatform, string databasePath, GetUtcNow getUtcNow = null)
        {
            Ensure.That(sqLitePlatform, "sqLitePlatform").IsNotNull();
            Ensure.That(databasePath, "databasePath").IsNotNull();

            _getUtcNow      = getUtcNow ?? SystemClock.GetUtcNow;
            _connectionPool = new SQLiteConnectionPool(sqLitePlatform);
            var connectionString = new SQLiteConnectionString(databasePath, false);

            _getConnection = () => _connectionPool.GetConnection(connectionString);
        }
 internal InMemoryStream(
     string streamId,
     InMemoryAllStream inMemoryAllStream,
     GetUtcNow getUtcNow,
     Action onStreamAppended)
 {
     _streamId          = streamId;
     _inMemoryAllStream = inMemoryAllStream;
     _getUtcNow         = getUtcNow;
     _onStreamAppended  = onStreamAppended;
 }
        public MetadataMaxAgeCache(IReadonlyStreamStore store, TimeSpan expiration, int maxSize, GetUtcNow getUtcNow)
        {
            Ensure.That(store, nameof(store)).IsNotNull();
            Ensure.That(maxSize).IsGte(0);
            Ensure.That(getUtcNow).IsNotNull();

            _store      = store;
            _expiration = expiration;
            _maxSize    = maxSize;
            _getUtcNow  = getUtcNow;
        }
Beispiel #18
0
        protected ReadonlyStreamStoreBase(
            TimeSpan metadataMaxAgeCacheExpiry,
            int metadataMaxAgeCacheMaxSize,
            GetUtcNow getUtcNow,
            string logName)
        {
            GetUtcNow = getUtcNow ?? SystemClock.GetUtcNow;
            Logger    = LogProvider.GetLogger(logName);

            _metadataMaxAgeCache = new MetadataMaxAgeCache(this, metadataMaxAgeCacheExpiry,
                                                           metadataMaxAgeCacheMaxSize, GetUtcNow);
        }
Beispiel #19
0
 internal InMemoryStream(
     string streamId,
     InMemoryAllStream inMemoryAllStream,
     GetUtcNow getUtcNow,
     Action onStreamAppended,
     Func <int> getNextPosition)
 {
     _streamId          = streamId;
     _inMemoryAllStream = inMemoryAllStream;
     _getUtcNow         = getUtcNow;
     _onStreamAppended  = onStreamAppended;
     _getNextPosition   = getNextPosition;
 }
 public SubscriptionsRepository(
     IStreamStore streamStore,
     JsonSerializerSettings jsonSerializerSettings,
     string name,
     GetUtcNow getUtcNow,
     int maxSubscriptionCount)
 {
     _streamStore            = streamStore;
     _jsonSerializerSettings = jsonSerializerSettings;
     _name                 = name;
     _getUtcNow            = getUtcNow;
     _maxSubscriptionCount = maxSubscriptionCount;
 }
        public InMemoryEventStore(GetUtcNow getUtcNow = null, string logName = null)
            : base(logName ?? nameof(InMemoryEventStore))
        {
            _getUtcNow = getUtcNow ?? SystemClock.GetUtcNow;
            _allStream.AddFirst(new InMemoryStreamEvent(
                                    "<in-memory-root-event>",
                                    Guid.NewGuid(),
                                    -1,
                                    -1,
                                    _getUtcNow(),
                                    null,
                                    null,
                                    null));

            _onStreamAppended = () => _subscriptions.OnNext(Unit.Default);
        }
        public InMemoryStreamStore(GetUtcNow getUtcNow = null, string logName = null)
            : base(TimeSpan.FromMinutes(1), 10000, getUtcNow, logName ?? nameof(InMemoryStreamStore))
        {
            _getUtcNow = getUtcNow ?? SystemClock.GetUtcNow;
            _allStream.AddFirst(new InMemoryStreamMessage(
                                    "<in-memory-root-message>",
                                    Guid.NewGuid(),
                                    -1,
                                    -1,
                                    _getUtcNow(),
                                    null,
                                    null,
                                    null));

            _onStreamAppended = () => _subscriptions.OnNext(Unit.Default);
        }
        public void ShouldThrottle_WhenCalledWithNGreaterThanMaxSleepNGreaterThanMax_ReturnsTrue()
        {
            _getUtcNow = () => new DateTime(2014, 2, 27, 0, 0, 0, DateTimeKind.Utc);
            var virtualNow = _getUtcNow();

            var before = _bucket.ShouldThrottle(NGreaterThanMax);
            var tokensBefore = _bucket.CurrentTokenCount;

            before.Should().BeTrue();
            tokensBefore.Should().Be(MaxTokens);

            _getUtcNow = () => virtualNow.AddSeconds(RefillInterval);

            var after = _bucket.ShouldThrottle(NGreaterThanMax);
            var tokensAfter = _bucket.CurrentTokenCount;
            after.Should().BeTrue();
            tokensAfter.Should().Be(MaxTokens);
        }
        public void ShouldThrottle_WhenCalledWithNGreaterThanMaxSleepNGreaterThanMax_ReturnsTrue()
        {
            _getUtcNow = () => new DateTime(2014, 2, 27, 0, 0, 0, DateTimeKind.Utc);
            var virtualNow = _getUtcNow();

            bool before       = _bucket.ShouldThrottle(N_GREATER_THAN_MAX);
            long tokensBefore = _bucket.CurrentTokenCount;

            before.ShouldBeTrue();
            tokensBefore.ShouldBe(MAX_TOKENS);

            _getUtcNow = () => virtualNow.AddSeconds(REFILL_INTERVAL);

            bool after       = _bucket.ShouldThrottle(N_GREATER_THAN_MAX);
            long tokensAfter = _bucket.CurrentTokenCount;

            after.ShouldBeTrue();
            tokensAfter.ShouldBe(MAX_TOKENS);
        }
Beispiel #25
0
        public void ShouldThrottle_WhenCalledWithNGreaterThanMaxSleepNGreaterThanMax_ReturnsTrue()
        {
            _getUtcNow = () => new DateTime(2014, 2, 27, 0, 0, 0, DateTimeKind.Utc);
            var virtualNow = _getUtcNow();

            var before       = _bucket.ShouldThrottle(NGreaterThanMax);
            var tokensBefore = _bucket.CurrentTokenCount;

            before.Should().BeTrue();
            tokensBefore.Should().Be(MaxTokens);

            _getUtcNow = () => virtualNow.AddSeconds(RefillInterval);

            var after       = _bucket.ShouldThrottle(NGreaterThanMax);
            var tokensAfter = _bucket.CurrentTokenCount;

            after.Should().BeTrue();
            tokensAfter.Should().Be(MaxTokens);
        }
 public Subscriptions(SubscriptionsMemento memento, GetUtcNow getUtcNow, int maxSubscriptionCount)
     : this(getUtcNow, maxSubscriptionCount)
 {
     _items = memento.Items.ToDictionary(i => i.Id, i => new Subscription(i));
 }
Beispiel #27
0
 public ImportEmployeeHandler(ILogger <ImportEmployeeHandler> logger, EmployeesRepository employeesRepository, GetUtcNow getUtcNow)
 {
     _logger = logger;
     _employeesRepository = employeesRepository;
     _getUtcNow           = getUtcNow;
 }
        public void ShouldThrottle_WhenCalledWithCumulativeNGreaterThanMaxSleepCumulativeNGreaterThanMax()
        {
            _getUtcNow = () => new DateTime(2014, 2, 27, 0, 0, 0, DateTimeKind.Utc);
            var virtualNow = _getUtcNow();

            for (var i = 0; i < 3*Cumulative; i++)
            {
                _bucket.ShouldThrottle(NLessThanMax);
            }

            var before = _bucket.ShouldThrottle(NLessThanMax);
            var tokensBefore = _bucket.CurrentTokenCount;

            before.Should().BeTrue();
            tokensBefore.Should().BeLessThan(NLessThanMax);

            _getUtcNow = () => virtualNow.AddSeconds(RefillInterval);

            for (var i = 0; i < 3*Cumulative; i++)
            {
                _bucket.ShouldThrottle(NLessThanMax);
            }
            var after = _bucket.ShouldThrottle(NLessThanMax);
            var tokensAfter = _bucket.CurrentTokenCount;

            after.Should().BeTrue();
            tokensAfter.Should().BeLessThan(NLessThanMax);
        }
Beispiel #29
0
 protected ReadonlyStreamStoreBase(GetUtcNow getUtcNow, string logName)
 {
     GetUtcNow             = getUtcNow ?? SystemClock.GetUtcNow;
     Logger                = LogProvider.GetLogger(logName);
     _disableMetadataCache = true;
 }
Beispiel #30
0
 /// <summary>
 ///     Initialized an new instance of a <see cref="StreamStoreBase"/>
 /// </summary>
 /// <param name="getUtcNow"></param>
 /// <param name="logName"></param>
 protected StreamStoreBase(GetUtcNow getUtcNow, string logName)
     : base(getUtcNow, logName)
 {
 }
Beispiel #31
0
 public WebHooks(GetUtcNow getUtcNow, int maxCount)
 {
     _getUtcNow = getUtcNow;
     _maxCount  = maxCount;
 }
 public Subscriptions(GetUtcNow getUtcNow, int maxSubscriptionCount)
 {
     _getUtcNow            = getUtcNow;
     _maxSubscriptionCount = maxSubscriptionCount;
 }
        public void ShouldThrottle_WhenCalledWithNLessThanMaxSleepCumulativeNLessThanMax()
        {
            _getUtcNow = () => new DateTime(2014, 2, 27, 0, 0, 0, DateTimeKind.Utc);
            var virtualNow = _getUtcNow();

            long sum = 0;
            for (var i = 0; i < Cumulative; i++)
            {
                _bucket.ShouldThrottle(NLessThanMax).Should().BeFalse();
                sum += NLessThanMax;
            }
            var tokensBefore = _bucket.CurrentTokenCount;
            tokensBefore.Should().Be(MaxTokens - sum);

            _getUtcNow = () => virtualNow.AddSeconds(RefillInterval);

            for (var i = 0; i < Cumulative; i++)
            {
                _bucket.ShouldThrottle(NLessThanMax).Should().BeFalse();
            }
            var tokensAfter = _bucket.CurrentTokenCount;
            tokensAfter.Should().Be(MaxTokens - sum);
        }
Beispiel #34
0
 public EmployeeController(EmployeesRepository employeesRepository, GetUtcNow getUtcNow, CreateEmployeeRequestValidator createEmployeeRequestValidator)
 {
     _employeesRepository            = employeesRepository;
     _getUtcNow                      = getUtcNow;
     _createEmployeeRequestValidator = createEmployeeRequestValidator;
 }