Inheritance: IChunkCache, IDisposable
Ejemplo n.º 1
0
 public void GetFromEmptyCacheReturnsEmptyByteBuffer()
 {
     using (var fileCollection = new InMemoryFileCollection())
     using (var cache = new DiskChunkCache(fileCollection, 20, 1000))
     {
         Assert.AreEqual(0, cache.Get(CalcHash(new byte[] { 0 })).Result.Length);
     }
 }
Ejemplo n.º 2
0
 public void GettingContentMakesItStayLongerDecreasingRate()
 {
     using (var fileCollection = new InMemoryFileCollection())
     {
         const int cacheCapacity = 50000;
         using (var cache = new DiskChunkCache(fileCollection, 20, cacheCapacity))
         {
             for (var i = 0; i < 80; i++)
             {
                 Put(cache, i);
                 for (var j = 0; j < 79 - i; j++)
                     Get(cache, i);
                 Assert.LessOrEqual(fileCollection.Enumerate().Sum(f => (long)f.GetSize()), cacheCapacity);
             }
             Console.WriteLine(cache.CalcStats());
             Assert.True(Get(cache, 0));
             Assert.False(Get(cache, 60));
         }
     }
 }
Ejemplo n.º 3
0
 public void AccessEveryTenthTenTimesMoreMakesItStay()
 {
     using (var fileCollection = new InMemoryFileCollection())
     {
         const int cacheCapacity = 50000;
         using (var cache = new DiskChunkCache(fileCollection, 20, cacheCapacity))
         {
             for (var i = 0; i < 46; i++)
             {
                 Put(cache, i);
                 for (var j = 0; j < (i % 5 == 0 ? 10 + i : 1); j++)
                     Get(cache, i);
                 if (i==42) Thread.Sleep(500);
                 Assert.LessOrEqual(fileCollection.Enumerate().Sum(f => (long)f.GetSize()), cacheCapacity);
             }
             Console.WriteLine(cache.CalcStats());
             Assert.True(Get(cache, 0));
             Assert.False(Get(cache, 1));
         }
     }
 }
Ejemplo n.º 4
0
 public void WhatIPutICanGet()
 {
     using (var fileCollection = new InMemoryFileCollection())
     using (var cache = new DiskChunkCache(fileCollection, 20, 1000))
     {
         cache.Put(CalcHash(new byte[] { 0 }), ByteBuffer.NewAsync(new byte[] { 1 }));
         Assert.AreEqual(new byte[] { 1 }, cache.Get(CalcHash(new byte[] { 0 })).Result.ToByteArray());
     }
 }
Ejemplo n.º 5
0
 public void SizeDoesNotGrowOverLimit()
 {
     using (var fileCollection = new InMemoryFileCollection())
     {
         const int cacheCapacity = 50000;
         using (var cache = new DiskChunkCache(fileCollection, 20, cacheCapacity))
         {
             for (var i = 0; i < 80; i++)
             {
                 Put(cache, i);
                 Assert.LessOrEqual(fileCollection.Enumerate().Sum(f => (long)f.GetSize()), cacheCapacity);
             }
         }
     }
 }
Ejemplo n.º 6
0
 public void ItRemebersContentAfterReopen()
 {
     using (var fileCollection = new InMemoryFileCollection())
     {
         using (var cache = new DiskChunkCache(fileCollection, 20, 1000))
         {
             cache.Put(CalcHash(new byte[] { 0 }), ByteBuffer.NewAsync(new byte[] { 1 }));
         }
         using (var cache = new DiskChunkCache(fileCollection, 20, 1000))
         {
             Assert.AreEqual(new byte[] { 1 }, cache.Get(CalcHash(new byte[] { 0 })).Result.ToByteArray());
         }
     }
 }