public void WeakFingerprintHashToMemoization() { WeakFingerprintHash weak = RandomHelpers.CreateRandomWeakFingerprintHash(); Fingerprint fingerprint = weak.ToMemoization(); Assert.Equal(weak.ToArray(), fingerprint.ToByteArray()); }
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))); } }
/// <inheritdoc /> public IEnumerable <Task <Possible <StrongFingerprint, Failure> > > EnumerateStrongFingerprints( WeakFingerprintHash weak, UrgencyHint urgencyHint, Guid activityId) { // TODO: Extend IAsyncEnumerable up through EnumerateStrongFingerprints var tcs = TaskSourceSlim.Create <IEnumerable <GetSelectorResult> >(); yield return(Task.Run( async() => { try { var results = await ReadOnlyCacheSession.GetSelectors(new Context(Logger), weak.ToMemoization(), CancellationToken.None).ToList(); tcs.SetResult(results); return results.Any() ? results.First().FromMemoization(weak, CacheId) : StrongFingerprintSentinel.Instance; } catch (Exception ex) { tcs.SetException(ex); throw; } })); // For now, callers should always await the first task before enumerating the rest Contract.Assert(tcs.Task.IsCompleted); IEnumerable <GetSelectorResult> otherResults = tcs.Task.GetAwaiter().GetResult(); foreach (var otherResult in otherResults.Skip(1)) { yield return(Task.FromResult(otherResult.FromMemoization(weak, CacheId))); } }