コード例 #1
0
        public async Task <Possible <Stream, Failure> > GetStreamAsync(CasHash hash, UrgencyHint urgencyHint, Guid activityId)
        {
            Contract.Requires(!IsClosed);

            using (var counter = m_counters.GetStreamCounter())
            {
                using (var eventing = new GetStreamActivity(BasicFilesystemCache.EventSource, activityId, this))
                {
                    eventing.Start(hash, urgencyHint);

                    if (!m_pinnedToCas.ContainsKey(hash))
                    {
                        counter.Miss();
                        return(eventing.StopFailure(new UnpinnedCasEntryFailure(CacheId, hash)));
                    }

                    try
                    {
                        Stream result =
                            CasHash.NoItem.Equals(hash) ?
                            Stream.Null :
                            await m_cache.ContendedOpenStreamAsync(m_cache.ToPath(hash), FileMode.Open, FileAccess.Read, FileShare.Read, useAsync : true, handlePendingDelete : true);

                        counter.FileSize(result.Length);
                        return(eventing.Returns(result));
                    }
                    catch (Exception e)
                    {
                        counter.Fail();
                        return(eventing.StopFailure(new ProduceStreamFailure(CacheId, hash, e)));
                    }
                }
            }
        }
コード例 #2
0
        protected override Task CorruptCasEntry(ICache cache, CasHash hash)
        {
            // We use this as a Task.Run() just to help prove the test structure
            // Other caches are likely to need async behavior so we needed to support
            // that.  No return result.  This must fail if it can not work.
            return(Task.Run(() =>
            {
                BasicFilesystemCache myCache = cache as BasicFilesystemCache;
                XAssert.IsNotNull(myCache, "Invalid cache passed to TestBasicFilesyste CorruptCasEntry test method");

                using (var f = File.AppendText(myCache.ToPath(hash)))
                {
                    f.Write("!Corrupted!");
                }
            }));
        }