Exemplo n.º 1
0
        public void DeltaHashProviderConstructor_Should_Apply_Capacity()
        {
            const int deltaCount = 9;

            BuildDeltasAndSetCacheExpectations(deltaCount);

            const int cacheCapacity     = 3;
            var       deltaHashProvider = new DeltaHashProvider(_deltaCache, Substitute.For <IDeltaIndexService>(), _logger, cacheCapacity);

            Enumerable.Range(1, deltaCount - 1).ToList().ForEach(i =>
            {
                var updated = deltaHashProvider.TryUpdateLatestHash(GetHash(i - 1), GetHash(i));
                updated.Should().BeTrue();
            });

            deltaHashProvider.GetLatestDeltaHash().Should().Be(GetHash(deltaCount - 1));

            var evictedCount    = deltaCount - cacheCapacity;
            var nonEvictedRange = Enumerable.Range(evictedCount, deltaCount - evictedCount);

            nonEvictedRange.ToList().ForEach(i =>
            {
                deltaHashProvider.GetLatestDeltaHash(GetDateTimeForIndex(i))
                .Should().Be(GetHash(i));
            });

            var evictedRange = Enumerable.Range(0, evictedCount);

            evictedRange.ToList().ForEach(i =>
            {
                deltaHashProvider.GetLatestDeltaHash(GetDateTimeForIndex(i))
                .Should().Be(default);
Exemplo n.º 2
0
        public void TryUpdateLatestHash_Should_Put_New_Hash_At_The_Top_Of_The_List()
        {
            const int deltaCount = 3;

            BuildDeltasAndSetCacheExpectations(deltaCount);

            var hashProvider = new DeltaHashProvider(_deltaCache, Substitute.For <IDeltaIndexService>(), _logger, 4);
            var updated      = hashProvider.TryUpdateLatestHash(GetHash(0), GetHash(1));

            updated.Should().BeTrue();
            updated = hashProvider.TryUpdateLatestHash(GetHash(1), GetHash(2));
            updated.Should().BeTrue();

            hashProvider.GetLatestDeltaHash()
            .Should().Be(GetHash(2));
        }
Exemplo n.º 3
0
        public void TryUpdateLatestHash_Should_Update_If_Hashes_Are_Valid()
        {
            const int deltaCount = 2;

            BuildDeltasAndSetCacheExpectations(deltaCount);

            var hashProvider = new DeltaHashProvider(_deltaCache, Substitute.For <IDeltaIndexService>(), _logger, 3);
            var updated      = hashProvider.TryUpdateLatestHash(GetHash(0), GetHash(1));

            updated.Should().BeTrue();

            hashProvider.GetLatestDeltaHash()
            .Should().Be(GetHash(1));
        }
Exemplo n.º 4
0
        public void TryUpdateLatestHash_Should_Push_New_Hash_On_Stream_When_Updating_Latest()
        {
            const int deltaCount = 2;

            BuildDeltasAndSetCacheExpectations(deltaCount);
            var observer = Substitute.For <IObserver <Cid> >();

            var hashProvider = new DeltaHashProvider(_deltaCache, Substitute.For <IDeltaIndexService>(), _logger, 3);

            using (hashProvider.DeltaHashUpdates.Subscribe(observer))
            {
                hashProvider.TryUpdateLatestHash(GetHash(0), GetHash(1));

                observer.Received(1).OnNext(Arg.Is(GetHash(1)));
            }
        }