Esempio n. 1
0
        public void CasEntriesRoundTrip(int casEntryCount, int determinism)
        {
            CasEntries casEntries = RandomHelpers.CreateRandomCasEntries(casEntryCount, m_buildXLDeterminism[determinism]);
            CasEntries roundTrip  = casEntries.ToMemoization().FromMemoization();

            Assert.Equal(casEntries, roundTrip);
        }
Esempio n. 2
0
        public void CasEntriesToMemoization(int casEntryCount, int determinism)
        {
            CasEntries casEntries = RandomHelpers.CreateRandomCasEntries(casEntryCount, m_buildXLDeterminism[determinism]);
            ContentHashListWithDeterminism contentHashListWithDeterminism = casEntries.ToMemoization();

            Assert.Equal(casEntries.Count, contentHashListWithDeterminism.ContentHashList.Hashes.Count);
            for (int i = 0; i < casEntries.Count; i++)
            {
                Assert.Equal(casEntries[i].ToMemoization(), contentHashListWithDeterminism.ContentHashList.Hashes[i]);
            }

            AssertDeterminismEqualEnough(casEntries.Determinism, contentHashListWithDeterminism.Determinism);
        }
        public async Task <Possible <FullCacheRecordWithDeterminism, Failure> > AddOrGetAsync(WeakFingerprintHash weak, CasHash casElement, Hash hashElement, CasEntries hashes, UrgencyHint urgencyHint, Guid activityId)
        {
            var addResult = await CacheSession.AddOrGetContentHashListAsync(
                new Context(Logger),
                new BuildXL.Cache.MemoizationStore.Interfaces.Sessions.StrongFingerprint(
                    weak.ToMemoization(),
                    new Selector(casElement.ToMemoization(), hashElement.RawHash.ToByteArray())),
                hashes.ToMemoization(),
                CancellationToken.None,
                urgencyHint.ToMemoization());

            var strong = new StrongFingerprint(weak, casElement, hashElement, CacheId);

            switch (addResult.Code)
            {
            case AddOrGetContentHashListResult.ResultCode.Success:
                SessionEntries?.TryAdd(strong, 1);

                return(addResult.ContentHashListWithDeterminism.ContentHashList == null
                        ? new FullCacheRecordWithDeterminism(addResult.ContentHashListWithDeterminism.Determinism.FromMemoization())
                        : new FullCacheRecordWithDeterminism(new FullCacheRecord(strong, addResult.ContentHashListWithDeterminism.FromMemoization())));

            case AddOrGetContentHashListResult.ResultCode.SinglePhaseMixingError:
                return(new SinglePhaseMixingFailure(CacheId));

            case AddOrGetContentHashListResult.ResultCode.InvalidToolDeterminismError:
                return(new NotDeterministicFailure(
                           CacheId,
                           new FullCacheRecord(strong, addResult.ContentHashListWithDeterminism.FromMemoization()),
                           new FullCacheRecord(strong, hashes)));

            case AddOrGetContentHashListResult.ResultCode.Error:
                return(new CacheFailure(addResult.ErrorMessage));

            default:
                return(new CacheFailure("Unrecognized AddOrGetContentHashListAsync result code: " + addResult.Code + ", error message: " + (addResult.ErrorMessage ?? string.Empty)));
            }
        }