public async Task UpdateOfferAsync_WhenUsingDbOffer_ThenDbOfferIsUpdated() { // Arrange var expectedThroughput = 20000; await _cosmonautClient.CreateDatabaseAsync(new Database { Id = _scaleableDbId }, new RequestOptions { OfferThroughput = 10000 }); await _cosmonautClient.CreateCollectionAsync(_scaleableDbId, new DocumentCollection { Id = _collectionName, PartitionKey = new PartitionKeyDefinition() { Paths = new Collection <string>(new List <string> { "/id" }) } }); var offer = await _cosmonautClient.GetOfferV2ForDatabaseAsync(_scaleableDbId); // Act var newOffer = new OfferV2(offer, expectedThroughput); var updatedOffer = await _cosmonautClient.UpdateOfferAsync(newOffer); // Assert updatedOffer.StatusCode.Should().Be(HttpStatusCode.OK); var dbOffer = await _cosmonautClient.GetOfferV2ForDatabaseAsync(_scaleableDbId); dbOffer.Content.OfferThroughput.Should().Be(expectedThroughput); }
public async Task <bool> EnsureCreatedAsync <TEntity>( string databaseId, string collectionId, int collectionThroughput, IndexingPolicy indexingPolicy = null) where TEntity : class { var collectionResource = await _cosmonautClient.GetCollectionAsync(databaseId, collectionId); if (collectionResource != null) { return(true); } var newCollection = new DocumentCollection { Id = collectionId, IndexingPolicy = indexingPolicy ?? CosmosConstants.DefaultIndexingPolicy }; SetPartitionKeyDefinitionForCollection(typeof(TEntity), newCollection); newCollection = await _cosmonautClient.CreateCollectionAsync(databaseId, newCollection, new RequestOptions { OfferThroughput = collectionThroughput }); return(newCollection != null); }
public async Task <bool> EnsureCreatedAsync <TEntity>( string databaseId, string collectionId, int collectionThroughput, IndexingPolicy indexingPolicy = null, ThroughputBehaviour onDatabaseBehaviour = ThroughputBehaviour.UseDatabaseThroughput, UniqueKeyPolicy uniqueKeyPolicy = null) where TEntity : class { var collectionResource = await _cosmonautClient.GetCollectionAsync(databaseId, collectionId); var databaseHasOffer = (await _cosmonautClient.GetOfferV2ForDatabaseAsync(databaseId)) != null; if (collectionResource != null) { return(true); } var newCollection = new DocumentCollection { Id = collectionId, IndexingPolicy = indexingPolicy ?? CosmosConstants.DefaultIndexingPolicy, UniqueKeyPolicy = uniqueKeyPolicy ?? CosmosConstants.DefaultUniqueKeyPolicy }; SetPartitionKeyDefinitionForCollection(typeof(TEntity), newCollection); var finalCollectionThroughput = databaseHasOffer ? onDatabaseBehaviour == ThroughputBehaviour.DedicateCollectionThroughput ? (int?)collectionThroughput : null : collectionThroughput; newCollection = await _cosmonautClient.CreateCollectionAsync(databaseId, newCollection, new RequestOptions { OfferThroughput = finalCollectionThroughput }); return(newCollection != null); }
public async Task <bool> EnsureCreatedAsync <TEntity>( string databaseId, string collectionId, int collectionThroughput, IndexingPolicy indexingPolicy = null) where TEntity : class { var isSharedCollection = typeof(TEntity).UsesSharedCollection(); var collectionResource = await _cosmonautClient.GetCollectionAsync(databaseId, collectionId); if (collectionResource != null) { return(true); } var newCollection = new DocumentCollection { Id = collectionId }; SetPartitionKeyIfCollectionIsNotShared(typeof(TEntity), isSharedCollection, newCollection); SetPartitionKeyAsIdIfCollectionIsShared(isSharedCollection, newCollection); if (indexingPolicy != null) { newCollection.IndexingPolicy = indexingPolicy; } newCollection = await _cosmonautClient.CreateCollectionAsync(databaseId, newCollection, new RequestOptions { OfferThroughput = collectionThroughput }); return(newCollection != null); }
public CosmonautClientTests() { _cosmonautClient = new CosmonautClient(_emulatorUri, _emulatorKey, new ConnectionPolicy { ConnectionProtocol = Protocol.Tcp, ConnectionMode = ConnectionMode.Direct }); _cosmonautClient.CreateDatabaseAsync(new Database { Id = _databaseId }).GetAwaiter().GetResult(); _cosmonautClient.CreateCollectionAsync(_databaseId, new DocumentCollection { Id = _collectionName }).GetAwaiter().GetResult(); }
public CosmonautClientTests() { _cosmonautClient = new CosmonautClient(_emulatorUri, _emulatorKey, new ConnectionPolicy { ConnectionProtocol = Protocol.Tcp, ConnectionMode = ConnectionMode.Direct }); _cosmonautClient.CreateDatabaseAsync(new Database { Id = _databaseId }).GetAwaiter().GetResult(); _cosmonautClient.CreateCollectionAsync(_databaseId, new DocumentCollection { Id = _collectionName, IndexingPolicy = new IndexingPolicy(new RangeIndex(DataType.Number, -1), new RangeIndex(DataType.String, -1)) }).GetAwaiter().GetResult(); }
public async Task GetOfferV2ForCollectionAsync_WhenDatabaseIsDbLevelScaleable_ThenCollectionOfferShouldNotExist() { // Arrange await _cosmonautClient.CreateDatabaseAsync(new Database { Id = _scaleableDbId }, new RequestOptions { OfferThroughput = 10000 }); await _cosmonautClient.CreateCollectionAsync(_scaleableDbId, new DocumentCollection { Id = _collectionName, PartitionKey = new PartitionKeyDefinition() { Paths = new Collection <string>(new List <string> { "/id" }) } }); // Act var collectionOffer = await _cosmonautClient.GetOfferV2ForCollectionAsync(_scaleableDbId, _collectionName); // Assert collectionOffer.Should().BeNull(); }