public async Task DBFiles_BTree_Test_21_BackwardsEnumeration() { SortedDictionary <Guid, Simple> Objects = await this.CreateObjects(ObjectsToEnumerate); Guid? Prev = null; Simple Obj; ulong Rank = ObjectsToEnumerate; using (ObjectBTreeFileEnumerator <Simple> e = await this.file.GetTypedEnumeratorAsync <Simple>(true)) { while (e.MovePrevious()) { Obj = e.Current; if (Prev.HasValue) { AssertEx.Greater(Prev.Value, Obj.ObjectId); } Prev = Obj.ObjectId; Assert.IsTrue(Objects.Remove(Obj.ObjectId)); AssertEx.Same(--Rank, e.CurrentRank); AssertEx.Same(Obj.ObjectId, e.CurrentObjectId); } } AssertEx.Same(0, Objects.Count); }
public async Task DBFiles_BTree_Test_19_LockedEnumeration() { SortedDictionary <Guid, Simple> Objects = await this.CreateObjects(ObjectsToEnumerate); Guid? Prev = null; Simple Obj; ulong Rank = 0; using (ObjectBTreeFileEnumerator <Simple> e = await this.file.GetTypedEnumeratorAsync <Simple>(true)) { while (await e.MoveNextAsync()) { Obj = e.Current; if (Prev.HasValue) { AssertEx.Less(Prev.Value, Obj.ObjectId); } Prev = Obj.ObjectId; Assert.IsTrue(Objects.Remove(Obj.ObjectId)); AssertEx.Same(Rank++, e.CurrentRank); AssertEx.Same(Obj.ObjectId, e.CurrentObjectId); } } AssertEx.Same(0, Objects.Count); }
public void CopyTo(string[] array, int arrayIndex) { Task <ObjectBTreeFileEnumerator <KeyValuePair <string, object> > > Task = this.dictionary.GetEnumerator(true); FilesProvider.Wait(Task, this.dictionary.DictionaryFile.TimeoutMilliseconds); using (ObjectBTreeFileEnumerator <KeyValuePair <string, object> > e = Task.Result) { while (e.MoveNext()) { array[arrayIndex++] = e.Current.Key; } } }
public async Task DBFiles_BTree_Test_20_UnlockedChangeEnumeration() { await this.CreateObjects(Math.Min(ObjectsToEnumerate, 1000)); Simple Obj; using (ObjectBTreeFileEnumerator <Simple> e = await this.file.GetTypedEnumeratorAsync <Simple>(false)) { while (e.MoveNext()) { Obj = e.Current; Obj = CreateSimple(this.MaxStringLength); await this.file.SaveNewObject(Obj); } } }
public async Task Test_24_Reset() { SortedDictionary <Guid, Simple> Objects = await this.CreateObjects(ObjectsToEnumerate); Guid? Prev = null; Simple Obj; ulong Rank = 0; using (ObjectBTreeFileEnumerator <Simple> e = this.file.GetTypedEnumerator <Simple>(false)) { while (e.MoveNext()) { Obj = e.Current; if (Prev.HasValue) { AssertEx.Less(Prev.Value, Obj.ObjectId); } Prev = Obj.ObjectId; Assert.IsTrue(Objects.ContainsKey(Obj.ObjectId)); AssertEx.Same(Rank++, e.CurrentRank); AssertEx.Same(Obj.ObjectId, e.CurrentObjectId); } e.Reset(); Prev = null; while (e.MovePrevious()) { Obj = e.Current; if (Prev.HasValue) { AssertEx.Greater(Prev.Value, Obj.ObjectId); } Prev = Obj.ObjectId; Assert.IsTrue(Objects.Remove(Obj.ObjectId)); AssertEx.Same(--Rank, e.CurrentRank); AssertEx.Same(Obj.ObjectId, e.CurrentObjectId); } } AssertEx.Same(0, Objects.Count); }
public async Task DBFiles_BTree_Test_22_SelectIthObject() { int c = ObjectsToEnumerate; SortedDictionary <Guid, Simple> Objects = await this.CreateObjects(c); Simple[] Ordered = new Simple[c]; Objects.Values.CopyTo(Ordered, 0); Guid? Prev = null; Simple Obj; Random gen = new Random(); int i, j; for (i = 0; i < c; i++) { j = 0; Prev = null; if (i < 10 || (gen.Next(0, 2) == 0 && i <= c - 10)) { using (ObjectBTreeFileEnumerator <Simple> e = await this.file.GetTypedEnumeratorAsync <Simple>(true)) { Assert.IsTrue(await e.GoToObject((uint)i)); do { Obj = e.Current; if (Prev.HasValue) { AssertEx.Less(Prev.Value, Obj.ObjectId); } Prev = Obj.ObjectId; DBFilesObjectSerializationTests.AssertEqual(Ordered[i + j], Obj); AssertEx.Same(i + j, e.CurrentRank); AssertEx.Same(Obj.ObjectId, e.CurrentObjectId); }while (e.MoveNext() && j++ < 10); } } else { using (ObjectBTreeFileEnumerator <Simple> e = await this.file.GetTypedEnumeratorAsync <Simple>(true)) { Assert.IsTrue(await e.GoToObject((uint)i)); do { Obj = e.Current; if (Prev.HasValue) { AssertEx.Greater(Prev.Value, Obj.ObjectId); } Prev = Obj.ObjectId; DBFilesObjectSerializationTests.AssertEqual(Ordered[i - j], Obj); AssertEx.Same(i - j, e.CurrentRank); AssertEx.Same(Obj.ObjectId, e.CurrentObjectId); }while (e.MovePrevious() && j++ < 10); } } } }