public void CacheMap_IsCached() { var cm = new CacheMap(); cm.SetCached(0, 10); Assert.IsTrue(cm.IsCached(0, 10)); Assert.IsTrue(cm.IsCached(2, 5)); }
public void CacheMap_GetMisingChunks() { var cm = new CacheMap(); cm.SetCached(5, 4); // overlaps with the second one cm.SetCached(1, 9); // overlaps with previous one cm.SetCached(20, 10); // has a gap before cm.SetCached(15, 1); // is adjascent to the next one cm.SetCached(16, 1); // is adjascent to the next one var missing = cm.GetMissingChunks(0, 31); Assert.AreEqual(4, missing.Count); Assert.AreEqual(new CachedFileChunk(new Range <int>(0, 0)), missing[0]); Assert.AreEqual(new CachedFileChunk(new Range <int>(10, 14)), missing[1]); Assert.AreEqual(new CachedFileChunk(new Range <int>(17, 19)), missing[2]); Assert.AreEqual(new CachedFileChunk(new Range <int>(30, 30)), missing[3]); }
public void CacheMap_GetOneMisingChunk() { var cm = new CacheMap(); cm.SetCached(0, 32); var missing = cm.GetMissingChunks(33, 10); Assert.AreEqual(1, missing.Count); Assert.AreEqual(new CachedFileChunk(33, 10), missing[0]); }
public override void Write(byte[] buffer, int offset, int count) { lock (_innerStream) { _cacheMap.SetCached(offset, count); _innerStream.Position = _writePosition; _innerStream.Seek(offset, SeekOrigin.Begin); _innerStream.Write(buffer, 0, count); _writePosition = _innerStream.Position; } }