Release() публичный Метод

public Release ( ) : void
Результат void
Пример #1
0
        public async Task CopyToTest_RequiresFlushingOfWrites(bool copyAsynchronously)
        {
            byte[] data = Enumerable.Range(0, 1000).Select(i => (byte)(i % 256)).ToArray();

            var manualReleaseStream = new ManuallyReleaseAsyncOperationsStream();
            var src = new BufferedStream(manualReleaseStream);

            src.Write(data, 0, data.Length);
            src.Position = 0;

            var dst = new MemoryStream();

            data[0] = 42;
            src.WriteByte(42);
            dst.WriteByte(42);

            if (copyAsynchronously)
            {
                Task copyTask = src.CopyToAsync(dst);
                manualReleaseStream.Release();
                await copyTask;
            }
            else
            {
                manualReleaseStream.Release();
                src.CopyTo(dst);
            }

            Assert.Equal(data, dst.ToArray());
        }
Пример #2
0
        public async Task CopyToTest_ReadBeforeCopy_CopiesAllData(bool copyAsynchronously, bool wrappedStreamCanSeek)
        {
            byte[] data = Enumerable.Range(0, 1000).Select(i => (byte)(i % 256)).ToArray();

            var wrapped = new ManuallyReleaseAsyncOperationsStream();

            wrapped.Release();
            wrapped.Write(data, 0, data.Length);
            wrapped.Position = 0;
            wrapped.SetCanSeek(wrappedStreamCanSeek);
            var src = new BufferedStream(wrapped, 100);

            src.ReadByte();

            var dst = new MemoryStream();

            if (copyAsynchronously)
            {
                await src.CopyToAsync(dst);
            }
            else
            {
                src.CopyTo(dst);
            }

            var expected = new byte[data.Length - 1];

            Array.Copy(data, 1, expected, 0, expected.Length);
            Assert.Equal(expected, dst.ToArray());
        }
Пример #3
0
        public async Task ConcurrentOperationsAreSerialized(bool apm)
        {
            byte[] data   = Enumerable.Range(0, 1000).Select(i => (byte)i).ToArray();
            var    mcaos  = new ManuallyReleaseAsyncOperationsStream();
            var    stream = new BufferedStream(mcaos, 1);

            var tasks = new Task[4];

            for (int i = 0; i < 4; i++)
            {
                tasks[i] = apm ?
                           Task.Factory.FromAsync(stream.BeginWrite, stream.EndWrite, data, 250 * i, 250, null) :
                           stream.WriteAsync(data, 250 * i, 250);
            }
            Assert.False(tasks.All(t => t.IsCompleted));

            mcaos.Release();
            await Task.WhenAll(tasks);

            stream.Position = 0;
            for (int i = 0; i < tasks.Length; i++)
            {
                Assert.Equal(i, stream.ReadByte());
            }
        }
Пример #4
0
        public async Task CopyToAsyncTest_RequiresAsyncFlushingOfWrites()
        {
            byte[] data = Enumerable.Range(0, 1000).Select(i => (byte)(i % 256)).ToArray();

            var manualReleaseStream = new ManuallyReleaseAsyncOperationsStream();
            var src = new BufferedStream(manualReleaseStream);
            src.Write(data, 0, data.Length);
            src.Position = 0;

            var dst = new MemoryStream();

            data[0] = 42;
            src.WriteByte(42);
            dst.WriteByte(42);

            Task copyTask = src.CopyToAsync(dst);
            manualReleaseStream.Release();
            await copyTask;

            Assert.Equal(data, dst.ToArray());
        }
Пример #5
0
        public async Task ConcurrentOperationsAreSerialized()
        {
            byte[] data = Enumerable.Range(0, 1000).Select(i => (byte)i).ToArray();
            var mcaos = new ManuallyReleaseAsyncOperationsStream();
            var stream = new BufferedStream(mcaos, 1);

            var tasks = new Task[4];
            for (int i = 0; i < 4; i++)
            {
                tasks[i] = stream.WriteAsync(data, 250 * i, 250);
            }
            Assert.False(tasks.All(t => t.IsCompleted));

            mcaos.Release();
            await Task.WhenAll(tasks);

            stream.Position = 0;
            for (int i = 0; i < tasks.Length; i++)
            {
                Assert.Equal(i, stream.ReadByte());
            }
        }
        public async Task ConcurrentOperationsAreSerialized()
        {
            byte[] data = Enumerable.Range(0, 1000).Select(i => unchecked((byte)i)).ToArray();
            var mcaos = new ManuallyReleaseAsyncOperationsStream();
            var stream = new BufferedStream(mcaos, 1);

            var tasks = new Task[4];
            for (int i = 0; i < 4; i++)
            {
                tasks[i] = stream.WriteAsync(data, 250 * i, 250);
            }
            Assert.All(tasks, t => Assert.Equal(TaskStatus.WaitingForActivation, t.Status));

            mcaos.Release();
            await Task.WhenAll(tasks);

            stream.Position = 0;
            for (int i = 0; i < tasks.Length; i++)
            {
                Assert.Equal(i, stream.ReadByte());
            }
        }
Пример #7
0
        public async Task CopyToAsyncTest_ReadBeforeCopy_CopiesAllData(bool wrappedStreamCanSeek)
        {
            byte[] data = Enumerable.Range(0, 1000).Select(i => (byte)(i % 256)).ToArray();

            var wrapped = new ManuallyReleaseAsyncOperationsStream();
            wrapped.Release();
            wrapped.Write(data, 0, data.Length);
            wrapped.Position = 0;
            wrapped.SetCanSeek(wrappedStreamCanSeek);
            var src = new BufferedStream(wrapped, 100);

            src.ReadByte();

            var dst = new MemoryStream();
            await src.CopyToAsync(dst);

            var expected = new byte[data.Length - 1];
            Array.Copy(data, 1, expected, 0, expected.Length);
            Assert.Equal(expected, dst.ToArray());
        }