public void ExecuteEvictionCallsCacheMethodForEachBeacon() { // given var configuration = MockBeaconCacheConfig(1000L, 1000L, 2000L); var target = CreateSpaceEvictionStrategyWith(configuration); mockBeaconCache.NumBytesInCache.Returns(configuration.CacheSizeUpperBound + 1, configuration.CacheSizeUpperBound + 1, configuration.CacheSizeUpperBound + 1, configuration.CacheSizeUpperBound + 1, 0L); var keyOne = new BeaconKey(42, 0); var keyTwo = new BeaconKey(1, 0); mockBeaconCache.BeaconKeys.Returns(new HashSet <BeaconKey> { keyOne, keyTwo }); // when executing the first time target.Execute(); // then _ = mockBeaconCache.Received(5).NumBytesInCache; mockBeaconCache.Received(1).EvictRecordsByNumber(keyTwo, 1); mockBeaconCache.Received(1).EvictRecordsByNumber(keyOne, 1); }
public void ExecuteEvictionCallsCacheMethodForEachBeacon() { // given var configuration = new BeaconCacheConfiguration(1000L, 1000L, 2000L); var target = new SpaceEvictionStrategy(mockLogger, mockBeaconCache, configuration, isShutdownFunc); mockBeaconCache.NumBytesInCache.Returns(configuration.CacheSizeUpperBound + 1, configuration.CacheSizeUpperBound + 1, configuration.CacheSizeUpperBound + 1, configuration.CacheSizeUpperBound + 1, 0L); mockBeaconCache.BeaconIDs.Returns(new HashSet <int> { 42, 1 }); // when executing the first time target.Execute(); // then var tmp = mockBeaconCache.Received(5).NumBytesInCache; mockBeaconCache.Received(1).EvictRecordsByNumber(1, 1); mockBeaconCache.Received(1).EvictRecordsByNumber(42, 1); }
public void ExecuteEvictionStopsIfNoBeaconIdsAreAvailableInCache() { // given var configuration = new BeaconCacheConfiguration(1000L, 1000L, 2000L); var target = new TimeEvictionStrategy(mockLogger, mockBeaconCache, configuration, mockTimingProvider, isShutdownFunc); mockTimingProvider.ProvideTimestampInMilliseconds().Returns(1000L, 2000L); mockBeaconCache.BeaconIDs.Returns(new HashSet <int>()); // when target.Execute(); // then verify interactions var tmp = mockBeaconCache.Received(1).BeaconIDs; mockTimingProvider.Received(3).ProvideTimestampInMilliseconds(); mockBeaconCache.DidNotReceiveWithAnyArgs().EvictRecordsByAge(0, 0L); // also ensure that the last run timestamp was updated Assert.That(target.LastRunTimestamp, Is.EqualTo(2000L)); }
public void ExecuteEvictionStopsIfNoBeaconIdsAreAvailableInCache() { // given var configuration = MockBeaconCacheConfig(1000L, 1000L, 2000L); var target = CreateTimeEvictionStrategyWith(configuration); var key = new BeaconKey(0, 0); mockTimingProvider.ProvideTimestampInMilliseconds().Returns(1000L, 2000L); mockBeaconCache.BeaconKeys.Returns(new HashSet <BeaconKey>()); // when target.Execute(); // then verify interactions _ = mockBeaconCache.Received(1).BeaconKeys; mockTimingProvider.Received(3).ProvideTimestampInMilliseconds(); mockBeaconCache.DidNotReceiveWithAnyArgs().EvictRecordsByAge(key, 0L); // also ensure that the last run timestamp was updated Assert.That(target.LastRunTimestamp, Is.EqualTo(2000L)); }