public async Task <BlobDescriptor> CallAsync() { Authorization authorization = await authenticatePushStep.GetFuture().ConfigureAwait(false); using (ProgressEventDispatcher progressEventDispatcher = progressEventDipatcherFactory.Create( "pushing blob " + blobDescriptor.GetDigest(), blobDescriptor.GetSize())) using (TimerEventDispatcher ignored = new TimerEventDispatcher( buildConfiguration.GetEventHandlers(), DESCRIPTION + blobDescriptor)) using (ThrottledAccumulatingConsumer throttledProgressReporter = new ThrottledAccumulatingConsumer(progressEventDispatcher.DispatchProgress)) { RegistryClient registryClient = buildConfiguration .NewTargetImageRegistryClientFactory() .SetAuthorization(authorization) .NewRegistryClient(); // check if the BLOB is available if (await registryClient.CheckBlobAsync(blobDescriptor).ConfigureAwait(false)) { buildConfiguration .GetEventHandlers() .Dispatch(LogEvent.Info("BLOB : " + blobDescriptor + " already exists on registry")); return(blobDescriptor); } // todo: leverage cross-repository mounts await registryClient.PushBlobAsync(blobDescriptor.GetDigest(), blob, null, throttledProgressReporter.Accept).ConfigureAwait(false); return(blobDescriptor); } }
public void TestDelay() { MemoryStream byteArrayOutputStream = new MemoryStream(); IList <long> byteCounts = new List <long>(); Queue <Instant> instantQueue = new Queue <Instant>(); instantQueue.Enqueue(Instant.FromUnixTimeSeconds(0)); using (ThrottledAccumulatingConsumer byteCounter = new ThrottledAccumulatingConsumer( byteCounts.Add, Duration.FromSeconds(3), instantQueue.Dequeue)) using (NotifyingOutputStream notifyingOutputStream = new NotifyingOutputStream(byteArrayOutputStream, byteCounter.Accept)) { instantQueue.Enqueue(Instant.FromUnixTimeSeconds(0)); notifyingOutputStream.WriteByte(100); instantQueue.Enqueue(Instant.FromUnixTimeSeconds(0)); notifyingOutputStream.Write(new byte[] { 101, 102, 103 }); instantQueue.Enqueue(Instant.FromUnixTimeSeconds(0) + Duration.FromSeconds(4)); notifyingOutputStream.Write(new byte[] { 104, 105, 106 }); instantQueue.Enqueue(Instant.FromUnixTimeSeconds(0) + Duration.FromSeconds(10)); notifyingOutputStream.Write(new byte[] { 107, 108 }); instantQueue.Enqueue(Instant.FromUnixTimeSeconds(0) + Duration.FromSeconds(10)); notifyingOutputStream.Write(new byte[] { 109 }); instantQueue.Enqueue(Instant.FromUnixTimeSeconds(0) + Duration.FromSeconds(13)); notifyingOutputStream.Write(new byte[] { 0, 110 }, 1, 1); } Assert.AreEqual(new[] { 7L, 2L, 2L }, byteCounts); CollectionAssert.AreEqual( new byte[] { 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110 }, byteArrayOutputStream.ToArray()); }