Esempio n. 1
0
        public void Show(LibraryViewNode node)
        {
            try
            {
                if (node is LibraryFileNode)
                {
                    using (var guard = new MultiGuard(1))
                    {
                        IClaim newBinary;
                        guard.Accept(newBinary = _binariesCache.GetBinary(node.Id));
                        if (newBinary != null)
                        {
                            ChangeClaim(newBinary);
                            guard.Commit();

                            LoadImage(newBinary.Binary);
                        }
                    }
                }
                else
                {
                    Image = null;
                }
            }
// ReSharper disable once EmptyGeneralCatchClause
            catch
            {
            }
        }
Esempio n. 2
0
 public void ExcessItemsAreRemovedFromCacheWhenClaimsAreReleased()
 {
     using (var mg = new MultiGuard())
     {
         _items.Take(10).Select(i => mg.Accept(_cache.GetBinary(i.Id))).ToList();
     }
     Assert.That(_cache.NumItems, Is.EqualTo(CacheCapacity));
 }
Esempio n. 3
0
 public void CacheBecomesOversizedIfClaimsExceedCapacity()
 {
     using (var mg = new MultiGuard())
     {
         var claims = _items.Take(10).Select(i => mg.Accept(_cache.GetBinary(i.Id))).ToList();
         Assert.That(_cache.NumItems, Is.EqualTo(claims.Count));
     }
 }
Esempio n. 4
0
        public void UnclaimedItemsAreDiscardedToMakeRoomForNewClaims()
        {
            using (var mg = new MultiGuard())
            {
                _items.Take(CacheCapacity).Select(i => mg.Accept(_cache.GetBinary(i.Id))).ToList();
            }

            //cache is now full of unclaimed items. In order to load the last one, an old one needs to be discarded.
            using (_cache.GetBinary(_items.Last().Id))
                Assert.That(_cache.NumItems, Is.EqualTo(CacheCapacity));
        }
Esempio n. 5
0
 public void TwoClaimsCreateAClaimCountOfTwo()
 {
     using (var mg = new MultiGuard())
     {
         _items.Take(CacheCapacity).Select(i => mg.Accept(_cache.GetBinary(i.Id))).ToList();
         var guid = _items.Last().Id;
         using (_cache.GetBinary(guid))
         {
             //cache is now oversize - claim and release the same item again. the cache should stay oversized
             using (_cache.GetBinary(guid))
             {
             }
             Assert.That(_cache.NumItems, Is.EqualTo(CacheCapacity + 1));
         }
     }
 }
Esempio n. 6
0
        public void ItemsAreReleasedWhenAllClaimsAreDisposed()
        {
            using (var mg = new MultiGuard())
            {
                _items.Take(CacheCapacity).Select(i => mg.Accept(_cache.GetBinary(i.Id))).ToList();
                var guid = _items.Last().Id;
                using (_cache.GetBinary(guid))
                {
                    //cache is now oversize - claim and release the same item again. the cache should stay oversized
                    using (_cache.GetBinary(guid))
                    {
                    }
                }

                //cache should now be full (there are still enough claims to keep it full, so the only one released will be the double claimed one)
                Assert.That(_cache.NumItems, Is.EqualTo(CacheCapacity));
            }
        }