public Task <StreamWithLength> OpenStreamAsync(ContentHash hash, uint bufferSize, CancellationToken token) { return(WithOperationContext(new Context(_logger), token, context => { return context.PerformOperationAsync( Tracer, async() => { var openStreamResult = await _placer.OpenStreamAsync( context, hash, context.Token).ThrowIfFailure(); var streamWithLength = openStreamResult.StreamWithLength.Value; if (streamWithLength.Length >= 0) { Counters[VfsCounters.PlaceHydratedFileBytes].Add(streamWithLength.Length); } return Result.Success(streamWithLength); }, extraEndMessage: r => $"Hash={hash}").ThrowIfFailureAsync(); })); }
public Task <OpenStreamResult> OpenStreamAsync( Context context, ContentHash contentHash, CancellationToken cts, UrgencyHint urgencyHint = UrgencyHint.Nominal) { return(PreferredContentSession.OpenStreamAsync(context, contentHash, cts, urgencyHint)); }
private async Task OpenStreamAsync( IReadOnlyContentSession session, IReadOnlyCollection <ContentHash> hashes, List <OpenStreamResult> results) { var tasks = hashes.Select(contentHash => Task.Run(async() => await session.OpenStreamAsync(_context, contentHash, Token))); foreach (var task in tasks.ToList()) { var result = await task; results.Add(result); } }
protected async Task OpenStreamReturnsExpectedFile( IReadOnlyContentSession session, Context context, ContentHash hash, byte[] expected) { OpenStreamResult openResult = await session.OpenStreamAsync(context, hash, Token); context.Debug($"Validating stream for content hash {hash} returned result {openResult.Code} with diagnostics {openResult} with ErrorMessage {openResult.ErrorMessage} diagnostics {openResult.Diagnostics}"); Assert.Equal <OpenStreamResult.ResultCode>(OpenStreamResult.ResultCode.Success, openResult.Code); Assert.True(openResult.Succeeded, $"OpenStream did not succeed for content hash {hash}"); Assert.NotNull(openResult.Stream); using (openResult.Stream) { var actualBytes = await openResult.Stream.GetBytes(false); actualBytes.Should().Equal(expected); } }
/// <inheritdoc /> public Task <OpenStreamResult> OpenStreamAsync( Context context, ContentHash contentHash, CancellationToken cts, UrgencyHint urgencyHint) { return(_contentReadOnlySession.OpenStreamAsync(context, contentHash, cts, urgencyHint)); }