public async Task CorrectlyAddSinglePageIndex() { var path = Path.Combine(MockFilesDirectory, "singlepage-write"); var fileInfo = new FileInfo(Path.Combine(path, "data-record-index-pointers.index")); if (fileInfo.Exists) { fileInfo.Delete(); await Task.Delay(100); } var dataRecordIndexPointer = new DataRecordIndexPointer(1, 10, 0, 132); DataRecordIndexPointer foundPointer; bool isFound; using (var dataRecordIndexStore = new Core.DataRecordIndexStorage(path, new DataRecordIndexStoreConfig(TimeSpan.FromMilliseconds(200)))) { dataRecordIndexStore.AddToIndex(dataRecordIndexPointer); isFound = dataRecordIndexStore.TryGetIndex(dataRecordIndexPointer.DataRecordId, out foundPointer); } Assert.Multiple(() => { Assert.IsTrue(isFound, "Данные по индексу должны найтись."); Assert.AreEqual(dataRecordIndexPointer, foundPointer, "То что положили, то и должны вернуть."); Assert.AreEqual(File.ReadAllBytes(Path.Combine(path, "expected.index")), File.ReadAllBytes(fileInfo.FullName)); }); }
public async Task CorrectlyAddMultiPageIndex() { var path = Path.Combine(MockFilesDirectory, "multipage-write"); var fileInfo = new FileInfo(Path.Combine(path, "data-record-index-pointers.index")); if (fileInfo.Exists) { fileInfo.Delete(); await Task.Delay(100); } DataRecordIndexPointer multipageIndex; DataRecordIndexPointer foundPointer; bool isFound; using (var dataRecordIndexStore = new Core.DataRecordIndexStorage(path, new DataRecordIndexStoreConfig(TimeSpan.FromMilliseconds(200)))) { var dataRecordIndexPointer1 = new DataRecordIndexPointer(1, 1, 0, 512); var dataRecordIndexPointer2 = new DataRecordIndexPointer(1, 2, 0, 512); var dataRecordIndexPointer3 = new DataRecordIndexPointer(1, 3, 0, 256); multipageIndex = new DataRecordIndexPointer( dataRecordIndexPointer1.DataRecordId, dataRecordIndexPointer1.DataPageNumber, dataRecordIndexPointer1.Offset, dataRecordIndexPointer1.Length, dataRecordIndexPointer2, dataRecordIndexPointer3 ); dataRecordIndexStore.AddToIndex(multipageIndex); isFound = dataRecordIndexStore.TryGetIndex(multipageIndex.DataRecordId, out foundPointer); } Assert.Multiple(() => { Assert.IsTrue(isFound, "Данные по индексу должны найтись."); Assert.AreEqual(multipageIndex, foundPointer, "То что положили, то и должны вернуть."); Assert.AreEqual(multipageIndex.AdditionalDataRecordIndexPointers.Length, foundPointer.AdditionalDataRecordIndexPointers.Length, "То что положили, то и должны вернуть."); Assert.AreEqual(File.ReadAllBytes(Path.Combine(path, "expected.index")), File.ReadAllBytes(fileInfo.FullName)); }); }