public async Task Update(DocumentModel model) { if (Disposed) { throw new ObjectDisposedException(nameof(model)); } var entry = await _index.Get(model.Id); var oldModel = _documentSerializer.Deserialize(_records.Find(entry.Item2)); _records.Update(entry.Item2, _documentSerializer.Serialize(model)); var oldDict = _indexingOperations.CreateIndexes(oldModel.Value, oldModel).Result; foreach (var(k, v) in oldDict) { await _secondaryIndex.Delete(k, v); } var dict = await _indexingOperations.CreateIndexes(model.Value, model); foreach (var(k, v) in dict) { await _secondaryIndex.Insert(k, v); } }
public void TestUpdateBlockToMuchBiggerSize() { var recordStorage = new RecordStorage(new BlockStorage(new MemoryStream(), 8192, 48)); var x1 = UnitTestHelper.RandomData(2491); var x2 = UnitTestHelper.RandomData(9182); var x3 = UnitTestHelper.RandomData(5182); recordStorage.Create(x1); // Use 1 block recordStorage.Create(x2); // Use 2 blocks recordStorage.Create(x3); // Use 1 block var x2u = UnitTestHelper.RandomData(8192 * 11 + 19); // Use 12 blocks recordStorage.Update(2, x2u); Assert.IsTrue(recordStorage.Find(1).SequenceEqual(x1)); Assert.IsTrue(recordStorage.Find(2).SequenceEqual(x2u)); Assert.IsTrue(recordStorage.Find(4).SequenceEqual(x3)); }
public void TestUpdateBlockToSmallerSize() { var recordStorage = new RecordStorage(new BlockStorage(new MemoryStream(), 8192, 48)); var x1 = UnitTestHelper.RandomData(2491); var x2 = UnitTestHelper.RandomData(9182); var x3 = UnitTestHelper.RandomData(5182); recordStorage.Create(x1); // Use 1 block recordStorage.Create(x2); // Use 2 blocks recordStorage.Create(x3); // Use 1 block var x2u = UnitTestHelper.RandomData(1177); // Use 1 block, so this record should be truncated recordStorage.Update(2, x2u); Assert.IsTrue(recordStorage.Find(1).SequenceEqual(x1)); Assert.IsTrue(recordStorage.Find(2).SequenceEqual(x2u)); Assert.IsTrue(recordStorage.Find(4).SequenceEqual(x3)); Assert.IsTrue(recordStorage.Create(UnitTestHelper.RandomData(10)) == 3); // Check if block #3 being reused }