Ejemplo n.º 1
0
 internal CosmosStore(ICosmonautClient cosmonautClient,
                      string databaseName,
                      string overriddenCollectionName,
                      IDatabaseCreator databaseCreator     = null,
                      ICollectionCreator collectionCreator = null,
                      bool scaleable = false)
 {
     CollectionName  = overriddenCollectionName;
     DatabaseName    = databaseName;
     CosmonautClient = cosmonautClient ?? throw new ArgumentNullException(nameof(cosmonautClient));
     Settings        = new CosmosStoreSettings(databaseName, cosmonautClient.DocumentClient.ServiceEndpoint.ToString(), string.Empty, cosmonautClient.DocumentClient.ConnectionPolicy,
                                               scaleCollectionRUsAutomatically: scaleable);
     if (Settings.InfiniteRetries)
     {
         CosmonautClient.DocumentClient.SetupInfiniteRetries();
     }
     if (string.IsNullOrEmpty(Settings.DatabaseName))
     {
         throw new ArgumentNullException(nameof(Settings.DatabaseName));
     }
     _collectionCreator = collectionCreator ?? new CosmosCollectionCreator(CosmonautClient);
     _databaseCreator   = databaseCreator ?? new CosmosDatabaseCreator(CosmonautClient);
     _cosmosScaler      = new CosmosScaler <TEntity>(this);
     InitialiseCosmosStore();
 }
Ejemplo n.º 2
0
        internal CosmosStore(IDocumentClient documentClient,
                             string databaseName,
                             string authKey,
                             string endpoint,
                             string overriddenCollectionName,
                             IDatabaseCreator databaseCreator     = null,
                             ICollectionCreator collectionCreator = null,
                             bool scaleable = false)
        {
            CollectionName = overriddenCollectionName;
            DatabaseName   = databaseName;
            if (documentClient == null)
            {
                throw new ArgumentNullException(nameof(documentClient));
            }
            var cosmonautClient = new CosmonautClient(documentClient);

            Settings = new CosmosStoreSettings(databaseName, endpoint, authKey, documentClient.ConnectionPolicy,
                                               scaleCollectionRUsAutomatically: scaleable);
            if (string.IsNullOrEmpty(Settings.DatabaseName))
            {
                throw new ArgumentNullException(nameof(Settings.DatabaseName));
            }
            _collectionCreator = collectionCreator ?? new CosmosCollectionCreator(cosmonautClient);
            _databaseCreator   = databaseCreator ?? new CosmosDatabaseCreator(cosmonautClient);
            _cosmosScaler      = new CosmosScaler <TEntity>(this);
            InitialiseCosmosStore();
        }
Ejemplo n.º 3
0
        public async Task WhenCollectionIsUpScaled_AndAutomaticScalingIsTurnedOff_ThenOfferDoesNotChange()
        {
            var catStore     = new CosmosStore <Cat>(new CosmosStoreSettings(_databaseId, _emulatorUri, _emulatorKey), _collectionName);
            var cosmosScaler = new CosmosScaler <Cat>(catStore);

            await cosmosScaler.UpscaleCollectionRequestUnitsForRequest(_databaseId, _collectionName, 100, 5);

            var offer = await catStore.CosmonautClient.GetOfferV2ForCollectionAsync(_databaseId, _collectionName);

            offer.Content.OfferThroughput.Should().Be(400);
        }
Ejemplo n.º 4
0
        public async Task WhenCollectionIsUpScaled_AndAutomaticScalingIsTurnedOn_ThenOfferIsUpscaled()
        {
            var catStore = new CosmosStore <Cat>(new CosmosStoreSettings(_databaseId, _emulatorUri, _emulatorKey,
                                                                         settings =>
            {
                settings.DefaultCollectionThroughput     = 500;
                settings.ScaleCollectionRUsAutomatically = true;
            }), _collectionName);
            var cosmosScaler = new CosmosScaler <Cat>(catStore);

            await cosmosScaler.UpscaleCollectionRequestUnitsForRequest(_databaseId, _collectionName, 100, 5);

            var offer = await catStore.CosmonautClient.GetOfferV2ForCollectionAsync(_databaseId, _collectionName);

            offer.Content.OfferThroughput.Should().Be(500);
        }
Ejemplo n.º 5
0
        public CosmosStore(CosmosStoreSettings settings, string overriddenCollectionName)
        {
            CollectionName = overriddenCollectionName;
            Settings       = settings ?? throw new ArgumentNullException(nameof(settings));
            DatabaseName   = settings.DatabaseName;
            var documentClient = DocumentClientFactory.CreateDocumentClient(settings);

            CosmonautClient = new CosmonautClient(documentClient, Settings.InfiniteRetries);
            if (string.IsNullOrEmpty(Settings.DatabaseName))
            {
                throw new ArgumentNullException(nameof(Settings.DatabaseName));
            }
            _collectionCreator = new CosmosCollectionCreator(CosmonautClient);
            _databaseCreator   = new CosmosDatabaseCreator(CosmonautClient);
            _cosmosScaler      = new CosmosScaler <TEntity>(this);
            InitialiseCosmosStore();
        }
Ejemplo n.º 6
0
        public async Task WhenCollectionIsDownScaled_AndAutomaticScalingIsTurnedOff_ThenOfferDoesNotChange()
        {
            var catStore = new CosmosStore <Cat>(new CosmosStoreSettings(_databaseId, _emulatorUri, _emulatorKey,
                                                                         settings =>
            {
                settings.DefaultCollectionThroughput = 500;
            }), _collectionName);
            var cosmosScaler = new CosmosScaler <Cat>(catStore);

            var preScaleOffer = await catStore.CosmonautClient.GetOfferV2ForCollectionAsync(_databaseId, _collectionName);

            await cosmosScaler.DownscaleCollectionRequestUnitsToDefault(_databaseId, _collectionName);

            var postScaleOffer = await catStore.CosmonautClient.GetOfferV2ForCollectionAsync(_databaseId, _collectionName);

            preScaleOffer.Content.OfferThroughput.Should().Be(500);
            postScaleOffer.Content.OfferThroughput.Should().Be(500);
        }