예제 #1
0
        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();
            }));
        }
예제 #2
0
 public Task <OpenStreamResult> OpenStreamAsync(
     Context context,
     ContentHash contentHash,
     CancellationToken cts,
     UrgencyHint urgencyHint = UrgencyHint.Nominal)
 {
     return(PreferredContentSession.OpenStreamAsync(context, contentHash, cts, urgencyHint));
 }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
 /// <inheritdoc />
 public Task <OpenStreamResult> OpenStreamAsync(
     Context context, ContentHash contentHash, CancellationToken cts, UrgencyHint urgencyHint)
 {
     return(_contentReadOnlySession.OpenStreamAsync(context, contentHash, cts, urgencyHint));
 }