public static async Task ReadWriteApm2(int threshold, bool asyncIO) { using var writer = new FileBufferingWriter(memoryThreshold: threshold, asyncIO: asyncIO); var bytes = new byte[500]; for (byte i = 0; i < byte.MaxValue; i++) { bytes[i] = i; } var checker = new CallbackChecker(); var ar = writer.BeginWrite(bytes, 0, byte.MaxValue, checker.DoCallback, "state1"); Equal("state1", ar.AsyncState); True(await checker.Task); writer.EndWrite(ar); checker = new CallbackChecker(); ar = writer.BeginWrite(bytes, byte.MaxValue, bytes.Length - byte.MaxValue, checker.DoCallback, "state2"); Equal("state2", ar.AsyncState); True(await checker.Task); writer.EndWrite(ar); Equal(bytes.Length, writer.Length); using var manager = await writer.GetWrittenContentAsync(); Equal(bytes, manager.Memory.ToArray()); }
public static void ReadWriteApm(int threshold, bool asyncIO) { using var writer = new FileBufferingWriter(memoryThreshold: threshold, asyncIO: asyncIO); var bytes = new byte[500]; for (byte i = 0; i < byte.MaxValue; i++) { bytes[i] = i; } var ar = writer.BeginWrite(bytes, 0, byte.MaxValue, null, "state1"); Equal("state1", ar.AsyncState); True(ar.AsyncWaitHandle.WaitOne(DefaultTimeout)); writer.EndWrite(ar); ar = writer.BeginWrite(bytes, byte.MaxValue, bytes.Length - byte.MaxValue, null, "state2"); Equal("state2", ar.AsyncState); True(ar.AsyncWaitHandle.WaitOne(DefaultTimeout)); writer.EndWrite(ar); Equal(bytes.Length, writer.Length); using var manager = writer.GetWrittenContent(); Equal(bytes, manager.Memory.ToArray()); }