Exemple #1
0
        public async Task ProcessCatalogIndexEntryAsync(CatalogIndexEntry catalogEntry)
        {
            try
            {
                var rawBlob = _container.GetBlockBlobReference(BuildPackageFileName(catalogEntry));
                var blob    = new AzureCloudBlockBlob(rawBlob);

                for (int i = 0; i < MaximumPackageProcessingAttempts; i++)
                {
                    try
                    {
                        await _handler.ProcessPackageAsync(catalogEntry, blob);

                        return;
                    }
                    catch (Exception e) when(IsRetryableException(e))
                    {
                        _logger.LogWarning(
                            0,
                            e,
                            "Processing package {PackageId} {PackageVersion} failed due to an uncaught exception. " +
                            $"Attempt {{Attempt}} of {MaximumPackageProcessingAttempts}",
                            catalogEntry.Id,
                            catalogEntry.Version,
                            i + 1);
                    }
                }

                _telemetryService.TrackHandlerFailedToProcessPackage(_handler, catalogEntry.Id, catalogEntry.Version);

                _logger.LogError(
                    $"Failed to process package {{PackageId}} {{PackageVersion}} after {MaximumPackageProcessingAttempts} attempts",
                    catalogEntry.Id,
                    catalogEntry.Version);
            }
            catch (StorageException e) when(IsPackageDoesNotExistException(e))
            {
                // This indicates a discrepancy between v2 and v3 APIs that should be caught by
                // the monitoring job. No need to track this handler failure.
                _logger.LogError(
                    "Package {PackageId} {PackageVersion} is missing from the packages container!",
                    catalogEntry.Id,
                    catalogEntry.Version);
            }
            catch (Exception e)
            {
                _telemetryService.TrackHandlerFailedToProcessPackage(_handler, catalogEntry.Id, catalogEntry.Version);

                _logger.LogError(
                    0,
                    e,
                    "Could not process package {PackageId} {PackageVersion}",
                    catalogEntry.Id,
                    catalogEntry.Version);
            }
        }
        public async Task GetMetadataAsync_ReturnsReadOnlyDictionary()
        {
            var blob = new AzureCloudBlockBlob(_underlyingBlob.Object);

            var actualMetadata = await blob.GetMetadataAsync(CancellationToken.None);

            Assert.IsAssignableFrom <IReadOnlyDictionary <string, string> >(actualMetadata);

            _underlyingBlob.VerifyAll();
        }
        public async Task FetchAttributesAsync_CallsUnderlyingMethod()
        {
            _underlyingBlob.Setup(x => x.FetchAttributesAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(0));

            var blob = new AzureCloudBlockBlob(_underlyingBlob.Object);

            await blob.FetchAttributesAsync(CancellationToken.None);

            _underlyingBlob.VerifyAll();
        }
        public async Task ExistsAsync_CallsUnderlyingMethod()
        {
            _underlyingBlob.Setup(x => x.ExistsAsync())
            .ReturnsAsync(true);

            var blob = new AzureCloudBlockBlob(_underlyingBlob.Object);

            Assert.True(await blob.ExistsAsync(CancellationToken.None));

            _underlyingBlob.VerifyAll();
        }
        public async Task GetStreamAsync_CallsUnderlyingMethod()
        {
            var expectedStream = new MemoryStream();

            _underlyingBlob.Setup(x => x.OpenReadAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(expectedStream);

            var blob = new AzureCloudBlockBlob(_underlyingBlob.Object);

            var actualStream = await blob.GetStreamAsync(CancellationToken.None);

            Assert.Same(expectedStream, actualStream);

            _underlyingBlob.VerifyAll();
        }
        public async Task SetPropertiesAsync_CallsUnderlyingMethod()
        {
            // Arrange
            var blob = new AzureCloudBlockBlob(_underlyingBlob.Object);

            var accessCondition  = AccessCondition.GenerateEmptyCondition();
            var options          = new BlobRequestOptions();
            var operationContext = new OperationContext();

            _underlyingBlob
            .Setup(b => b.SetPropertiesAsync(accessCondition, options, operationContext))
            .Returns(Task.CompletedTask);

            // Act
            await blob.SetPropertiesAsync(accessCondition, options, operationContext);

            // Assert
            _underlyingBlob.VerifyAll();
        }