public void TestUpdateBlockToBiggerSize () { 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 * 2 + 19); // Use 3 block, so this record should be extended 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 TestUpdateEqualSizeBlock () { 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 (9177); // Use 2 blocks, still 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 }