public void GetItem_OfCacheableClassWhenInitialisationTimesOut_ReturnsInitialValueOfNull() { // Arrange AutoRefreshingItemCache <CacheableClass> cache = new AutoRefreshingItemCache <CacheableClass>( new FakeLogger(), async(ct) => { await TimeDelay.WaitForAsync(500); return(new CacheableClass(100)); }, null, TimeSpan.FromMinutes(2) ); CacheableClass actualResult; cache.StartInitialisation(); cache.TryCompleteInitialisation(TimeSpan.FromMilliseconds(50)); // Act actualResult = cache.GetItem(); // Assert Assert.IsNull(actualResult); }
public void TryCompleteInitialisation_VerySlowCacheLoad_TimesOut() { // Arrange AutoRefreshingItemCache <int> cache = new AutoRefreshingItemCache <int>( new FakeLogger(), new NonCloningClonerFactory <int>(), async(ct) => { await TimeDelay.WaitForAsync(30000); return(125); }, 0, TimeSpan.FromMinutes(30) ); bool actualResult; bool expectedResult = false; cache.StartInitialisation(); // Act actualResult = cache.TryCompleteInitialisation(TimeSpan.FromMilliseconds(50)); // Assert Assert.AreEqual(expectedResult, actualResult); }
public void TryCompleteInitialisation_ImmediateCacheLoad_DoesNotTimeOut() { // Arrange AutoRefreshingItemCache <int> cache = new AutoRefreshingItemCache <int>( new FakeLogger(), new NonCloningClonerFactory <int>(), (ct) => { return(Task.FromResult(125)); }, 0, TimeSpan.FromMinutes(30) ); bool actualResult; bool expectedResult = true; cache.StartInitialisation(); // Act actualResult = cache.TryCompleteInitialisation(TimeSpan.FromMilliseconds(50)); // Assert Assert.AreEqual(expectedResult, actualResult); }
public void Initialise_CacheLoadThrowsException_TimesOut() { // Arrange AutoRefreshingItemCache <int> cache = new AutoRefreshingItemCache <int>( new FakeLogger(), new NonCloningClonerFactory <int>(), (ct) => { throw new Exception("Test exception raised during cache load tests"); }, 0, TimeSpan.FromMinutes(30) ); bool actualResult; bool expectedResult = false; cache.StartInitialisation(); // Act actualResult = cache.TryCompleteInitialisation(TimeSpan.FromMilliseconds(50)); // Assert Assert.AreEqual(expectedResult, actualResult); }
public void GetItem_OfIntWhenInitialialisationTimesOut_ReturnsInitialValueOfZero() { // Arrange AutoRefreshingItemCache <int> cache = new AutoRefreshingItemCache <int>( new FakeLogger(), new NonCloningClonerFactory <int>(), async(ct) => { await TimeDelay.WaitForAsync(500); return(125); }, 0, TimeSpan.FromMinutes(2) ); int actualResult; int expectedResult = 0; cache.StartInitialisation(); cache.TryCompleteInitialisation(TimeSpan.FromMilliseconds(50)); // Act actualResult = cache.GetItem(); // Assert Assert.AreEqual(expectedResult, actualResult); }
/// <summary> /// Start background initialisation of the underlying cache and then return. /// </summary> /// <remarks> /// This method returns before initialisation is complete, allowing other processing to /// continue in the meantime. Call TryCompleteInitialisation at the last possible moment to /// try to ensure that initialisation has been completed</remarks> void IDisallowedFragmentListCacheInitialiser.StartInitialisation() { _cache.StartInitialisation(); }
/// <summary> /// Start background initialisation of the underlying cache and then return. /// </summary> /// <remarks> /// This method returns before initialisation is complete, allowing other processing to /// continue in the meantime. Call TryCompleteInitialisation at the last possible moment to /// try to ensure that initialisation has been completed</remarks> void ICharacterSetListCacheInitialiser.StartInitialisation() { _cache.StartInitialisation(); }