public File(OnDiskMemoryMappedFileCollection owner, uint index, string fileName) { _owner = owner; _index = index; _fileName = fileName; _stream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read, 1, FileOptions.None); _trueLength = _stream.Length; _cachedLength = _trueLength; _writer = new Writer(this); }
public void Reader() { IEnumerable <KeyValuePair <long, Tick> > flow = TicksGenerator.GetFlow(1000000, KeysType.Random); //passed //using (var fileCollection = new OnDiskFileCollection("data")) //failed using (var fileCollection = new OnDiskMemoryMappedFileCollection("data")) //passed //using (var fileCollection = new InMemoryFileCollection()) { using (IKeyValueDB db = new KeyValueDB(fileCollection, new SnappyCompressionStrategy(), (uint)Int16.MaxValue * 10)) { using (var tr = db.StartTransaction()) { foreach (KeyValuePair <long, Tick> item in flow) { byte[] key = Direct(item.Key); byte[] value = FromTick(item.Value); tr.CreateOrUpdateKeyValue(key, value); } tr.Commit(); } flow = TicksGenerator.GetFlow(1000000, KeysType.Random); foreach (KeyValuePair <long, Tick> item in flow) { using (var tr = db.StartTransaction()) { byte[] key = Direct(item.Key); bool find = tr.FindExactKey(key); if (find) { var id = Reverse(tr.GetKeyToArray()); var tick = ToTick(tr.GetValue().ToArray()); Assert.Equal(item.Key, id); } } } } } }