public async Task CreateGetDestroyBlobs() { byte[] data1 = new byte[] { 0, 1, 2, 3, 4, 5 }; byte[] data2 = new byte[] { 10, 11, 12, 13, 14, 15 }; byte[] data3 = new byte[] { 20, 21, 22, 23, 24, 25 }; var dataSet = new byte[][] { data1, data2, data3 }; using (DataTransferSession dts = new DataTransferSession(_session, null)) { var blob1 = await dts.SendBytesAsync(data1, true, null, CancellationToken.None); var blob2 = await dts.SendBytesAsync(data2, true, null, CancellationToken.None); var blob3 = await dts.SendBytesAsync(data3, true, null, CancellationToken.None); blob1.Id.Should().BeGreaterThan(0); blob2.Id.Should().BeGreaterThan(0); blob3.Id.Should().BeGreaterThan(0); blob1.Id.Should().NotBe(blob2.Id); blob2.Id.Should().NotBe(blob3.Id); blob3.Id.Should().NotBe(blob1.Id); var blobIds = new IRBlobInfo[] { blob1, blob2, blob3 }; for (int i = 0; i < blobIds.Length; ++i) { var blob = await dts.FetchBytesAsync(blobIds[i], false, null, CancellationToken.None); blob.Should().Equal(dataSet[i]); } } }
public async Task CreateGetDestroyBlobs() { byte[] data1 = new byte[] { 0, 1, 2, 3, 4, 5 }; byte[] data2 = new byte[] { 10, 11, 12, 13, 14, 15 }; byte[] data3 = new byte[] { 20, 21, 22, 23, 24, 25 }; var dataSet = new byte[][] { data1, data2, data3 }; using (DataTransferSession dts = new DataTransferSession(_session, null)) { var blob1 = await dts.SendBytesAsync(data1, true, null, CancellationToken.None); var blob2 = await dts.SendBytesAsync(data2, true, null, CancellationToken.None); var blob3 = await dts.SendBytesAsync(data3, true, null, CancellationToken.None); blob1.Id.Should().BeGreaterThan(0); blob2.Id.Should().BeGreaterThan(0); blob3.Id.Should().BeGreaterThan(0); blob1.Id.Should().NotBe(blob2.Id); blob2.Id.Should().NotBe(blob3.Id); blob3.Id.Should().NotBe(blob1.Id); var blobIds = new IRBlobInfo[] { blob1, blob2, blob3 }; for (int i = 0; i < blobIds.Length; ++i) { var blob = await dts.FetchBytesAsync(blobIds[i], false, null, CancellationToken.None); blob.Should().Equal(dataSet[i]); } } }
public async Task CreateBlob_DisconnectedFromTheStart() { using (var session = new RSession(0, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { })) { var data = new byte[] { 1, 2, 3, 4, 5 }; using (DataTransferSession dts = new DataTransferSession(session, null)) { Func<Task> f = () => dts.SendBytesAsync(data, false, null, CancellationToken.None); await f.ShouldThrowAsync<RHostDisconnectedException>(); } } }
public async Task CreateBlob_DisconnectedFromTheStart() { using (var session = new RSession(0, _testMethod.FileSystemSafeName, _fileSystem, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { })) { var data = new byte[] { 1, 2, 3, 4, 5 }; using (DataTransferSession dts = new DataTransferSession(session, null)) { Func <Task> f = () => dts.SendBytesAsync(data, false, null, CancellationToken.None); await f.ShouldThrowAsync <RHostDisconnectedException>(); } } }
public async Task CreateBlob_DisconnectedFromTheStart() { using (var session = new RSession(0, _brokerClient, () => { })) { var data = new byte[] { 1, 2, 3, 4, 5 }; using (DataTransferSession dts = new DataTransferSession(session, null)) { Func <Task> f = () => dts.SendBytesAsync(data, false); await f.ShouldThrowAsync <RHostDisconnectedException>(); } } }
public async Task CreateBlob_DisconnectedDuringCreate() { var data = new byte[25 * 1024 * 1024]; // try to send a massive blob ManualResetEvent testStarted = new ManualResetEvent(false); using (DataTransferSession dts = new DataTransferSession(_session, null)) { Func<Task> f = () => dts.SendBytesAsync(data, false, null, CancellationToken.None); var assertion = f.ShouldThrowAsync<RHostDisconnectedException>(); await Task.Delay(100); await _session.StopHostAsync(); await assertion; } }
public async Task CreateBlob_DisconnectedDuringCreate() { var data = new byte[25 * 1024 * 1024]; // try to send a massive blob using (DataTransferSession dts = new DataTransferSession(_session, null)) { Func <Task> f = () => dts.SendBytesAsync(data, false, null, CancellationToken.None); var assertion = f.ShouldThrowAsync <RHostDisconnectedException>(); await Task.Delay(100); await _session.StopHostAsync(); await assertion; } }
public async Task GetBlob_CanceledDuringGet() { var cts = new CancellationTokenSource(); var data = new byte[1024 * 1024]; IRBlobInfo blob = null; using (DataTransferSession dts = new DataTransferSession(_session, null)) { blob = await dts.SendBytesAsync(data, false, null, CancellationToken.None); } Func <Task> f = async() => { while (true) { await _session.BlobReadAllAsync(blob.Id, ct : cts.Token); } }; var assertion = f.ShouldThrowAsync <OperationCanceledException>(); cts.CancelAfter(1); await assertion; }
public async Task GetBlob_DisconnectedDuringGet() { var data = new byte[1024 * 1024]; IRBlobInfo blob = null; using (DataTransferSession dts = new DataTransferSession(_session, null)) { blob = await dts.SendBytesAsync(data, false, null, CancellationToken.None); } using (RBlobStream blobStream = await RBlobStream.OpenAsync(blob, _session)) { Func <Task> f = async() => { using (MemoryStream ms = new MemoryStream()) { await blobStream.CopyToAsync(ms, 1024); } }; await Task.Delay(100); await _session.StopHostAsync(); await f.ShouldThrowAsync <RHostDisconnectedException>(); } }
public async Task GetBlob_DisconnectedDuringGet() { var data = new byte[1024 * 1024]; IRBlobInfo blob = null; using (DataTransferSession dts = new DataTransferSession(_session, null)) { blob = await dts.SendBytesAsync(data, false, null, CancellationToken.None); } using (RBlobStream blobStream = await RBlobStream.OpenAsync(blob, _session)) { Func<Task> f = async () => { using (MemoryStream ms = new MemoryStream()) { await blobStream.CopyToAsync(ms, 1024); } }; await Task.Delay(100); await _session.StopHostAsync(); await f.ShouldThrowAsync<RHostDisconnectedException>(); } }
public async Task GetBlob_CanceledDuringGet() { var cts = new CancellationTokenSource(); var data = new byte[1024 * 1024]; IRBlobInfo blob = null; using (DataTransferSession dts = new DataTransferSession(_session, null)) { blob = await dts.SendBytesAsync(data, false, null, CancellationToken.None); } Func<Task> f = async () => { while (true) { await _session.BlobReadAllAsync(blob.Id, ct: cts.Token); } }; var assertion = f.ShouldThrowAsync<OperationCanceledException>(); cts.CancelAfter(1); await assertion; }