示例#1
0
        private async Task ScaleCollection(CosmosCollectionType cosmosRepositoryType, int requestUnits)
        {
            ICosmosDbScalingRepository cosmosDbScalingRepository = _cosmosDbScalingRepositoryProvider.GetRepository(cosmosRepositoryType);

            try
            {
                await _scalingRepositoryPolicy.ExecuteAsync(() => cosmosDbScalingRepository.SetThroughput(requestUnits));
            }
            catch (Exception ex)
            {
                _logger.Error(ex, $"Failed to set throughput on repository type '{cosmosRepositoryType}' with '{requestUnits}' request units");

                throw;
            }
        }
示例#2
0
        public async Task <int> ScaleCollection(CosmosCollectionType cosmosRepositoryType, int requestUnits, int maxRequestUnits)
        {
            ICosmosDbScalingRepository cosmosDbScalingRepository = _cosmosDbScalingRepositoryProvider.GetRepository(cosmosRepositoryType);

            int throughPutRequestUnits = Math.Min(requestUnits, maxRequestUnits);

            try
            {
                await _scalingRepositoryPolicy.ExecuteAsync(async() => await cosmosDbScalingRepository.SetThroughput(throughPutRequestUnits));

                return(throughPutRequestUnits);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, $"Failed to set throughput on repository type '{cosmosRepositoryType}' with '{requestUnits}' request units");

                throw;
            }
        }
        public void GetRepository_GivenRepositoryType_ReturnsInstanceOfCorrectRepository(CosmosCollectionType cosmosRepositoryType, string repositoryTypeName)
        {
            //Arrange
            CosmosCollectionType repositoryType = cosmosRepositoryType;

            IServiceProvider serviceProvider = CreateServiceProvider();

            CosmosDbScalingRepositoryProvider scalingRepositoryProvider = new CosmosDbScalingRepositoryProvider(serviceProvider);

            //Act
            ICosmosDbScalingRepository scalingRepository = scalingRepositoryProvider.GetRepository(repositoryType);

            //Assert
            //AB: using gettype and name rather than assignable tp because ncrunch throws a wobbly
            scalingRepository
            .GetType()
            .Name
            .Should()
            .Be(repositoryTypeName);
        }
示例#4
0
        private async Task <int?> GetMinimumThroughput(CosmosCollectionType collectionType)
        {
            ICosmosDbScalingRepository cosmosDbScalingRepository = _cosmosDbScalingRepositoryProvider.GetRepository(collectionType);

            return(await _scalingRepositoryPolicy.ExecuteAsync(async() => await cosmosDbScalingRepository.GetMinimumThroughput()));
        }