public async Task TestReadFromStream() { var options = new FileBufferOptions(100, 10); await using var buffers = new FileBuffers(options); using var memStream = new MemoryStream(); var data = new byte[150]; for (byte i = 0; i < data.Length; i++) { data[i] = i; } memStream.Write(data, 0, data.Length); var id = new BufferId(Guid.NewGuid(), "*"); await using var buffer = await buffers.AddForMememoryStream(id, memStream).NoSync(); var page = UseAndReturn.That(await buffer.GetPageAsync(0).ConfigureAwait(false)); AssertEqual(1, page.Data[1]); AssertEqual(100, page.Data.Length); await page.DisposeAsync().NoSync(); AssertEqual(1, buffers.Pool.Count); page = UseAndReturn.That(await buffer.GetPageAsync(0).ConfigureAwait(false)); AssertEqual(0L, page.Data.Number); AssertEqual(1, buffer.NumberOfBufferedPages); await page.DisposeAsync().NoSync(); }
public async Task TestUseAndReturn() { await using var demoObject = new CountObject(); AssertEqual(false, demoObject.IsPinned); demoObject.Pin(); AssertEqual(true, demoObject.IsPinned); await using (var x = UseAndReturn.That(demoObject)) { AssertEqual(true, demoObject.IsPinned); } AssertEqual(false, demoObject.IsPinned); }
public static async Task Main() { await using var buffers = new FileBuffers(new FileBufferOptions()); var id = new BufferId(Guid.NewGuid(), "*"); var buffer = await buffers.AddForFile(id, "d:\\temp\\2.abc").NoSync(); for (var i = 0; i < buffer.PageCount; i++) { await using var p1 = UseAndReturn.That(await buffer.GetPageAsync(i).NoSync()); Console.WriteLine("Data: " + p1.Data[0].ToString(CultureInfo.CurrentCulture)); } }