public async Task CreateDropAutoscaleAutoUpgradeDatabase() { DatabaseInternal database = (DatabaseInlineCore)await this.cosmosClient.CreateDatabaseAsync( nameof(CreateDropAutoscaleAutoUpgradeDatabase) + Guid.NewGuid(), ThroughputProperties.CreateAutoscaleThroughput( maxAutoscaleThroughput: 5000, autoUpgradeMaxThroughputIncrementPercentage: 10)); // Container is required to validate database throughput upgrade scenarios Container container = await database.CreateContainerAsync("Test", "/id"); ThroughputResponse autoscale = await database.ReadThroughputAsync(requestOptions : null); Assert.IsNotNull(autoscale); Assert.AreEqual(5000, autoscale.Resource.AutoscaleMaxThroughput); Assert.AreEqual(10, autoscale.Resource.AutoUpgradeMaxThroughputIncrementPercentage); ThroughputResponse autoscaleReplaced = await database.ReplaceThroughputAsync( ThroughputProperties.CreateAutoscaleThroughput(6000)); Assert.IsNotNull(autoscaleReplaced); Assert.AreEqual(6000, autoscaleReplaced.Resource.AutoscaleMaxThroughput); Assert.IsNull(autoscaleReplaced.Resource.AutoUpgradeMaxThroughputIncrementPercentage); ThroughputResponse autoUpgradeReplace = await database.ReplaceThroughputAsync( ThroughputProperties.CreateAutoscaleThroughput( maxAutoscaleThroughput: 7000, autoUpgradeMaxThroughputIncrementPercentage: 20)); Assert.IsNotNull(autoUpgradeReplace); Assert.AreEqual(7000, autoUpgradeReplace.Resource.AutoscaleMaxThroughput); Assert.AreEqual(20, autoUpgradeReplace.Resource.AutoUpgradeMaxThroughputIncrementPercentage); await database.DeleteAsync(); }
[TestCategory("Quarantine")] // Not currently working with emulator public async Task CreateDropAutoscaleContainer() { DatabaseInternal database = (DatabaseInlineCore)await this.cosmosClient.CreateDatabaseAsync( Guid.NewGuid().ToString()); ContainerInternal container = (ContainerInlineCore)await database.CreateContainerAsync( new ContainerProperties(Guid.NewGuid().ToString(), "/pk"), ThroughputProperties.CreateAutoscaleThroughput(5000)); Assert.IsNotNull(container); ThroughputResponse throughputResponse = await container.ReadThroughputAsync(requestOptions : null); Assert.IsNotNull(throughputResponse); Assert.AreEqual(5000, throughputResponse.Resource.AutoscaleMaxThroughput); throughputResponse = await container.ReplaceThroughputAsync( ThroughputProperties.CreateAutoscaleThroughput(6000), requestOptions : null, cancellationToken : default(CancellationToken)); Assert.IsNotNull(throughputResponse); Assert.AreEqual(6000, throughputResponse.Resource.AutoscaleMaxThroughput); await database.DeleteAsync(); }
[TestCategory("Quarantine")] // Not currently working with emulator public async Task CreateDropAutoscaleContainerStreamApi() { DatabaseInternal database = (DatabaseInlineCore)await this.cosmosClient.CreateDatabaseAsync( Guid.NewGuid().ToString()); ThroughputResponse databaseThroughput = await database.ReadThroughputIfExistsAsync(requestOptions : null); Assert.IsNotNull(databaseThroughput); Assert.AreEqual(HttpStatusCode.NotFound, databaseThroughput.StatusCode); string streamContainerId = Guid.NewGuid().ToString(); using (ResponseMessage response = await database.CreateContainerStreamAsync( new ContainerProperties(streamContainerId, "/pk"), ThroughputProperties.CreateAutoscaleThroughput(5000))) { Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); ContainerInternal streamContainer = (ContainerInlineCore)database.GetContainer(streamContainerId); ThroughputResponse autoscaleIfExists = await streamContainer.ReadThroughputIfExistsAsync( requestOptions : null, default(CancellationToken)); Assert.IsNotNull(autoscaleIfExists); Assert.AreEqual(5000, autoscaleIfExists.Resource.AutoscaleMaxThroughput); } }
public async Task ReadAutoscaleWithFixedTests() { Database database = await this.cosmosClient.CreateDatabaseAsync( Guid.NewGuid().ToString()); ContainerInternal fixedContainer = (ContainerInlineCore)await database.CreateContainerAsync( new ContainerProperties(Guid.NewGuid().ToString(), "/pk"), throughput : 1000); Assert.IsNotNull(fixedContainer); int?throughput = await fixedContainer.ReadThroughputAsync(); Assert.AreEqual(1000, throughput); // Reading a fixed container with autoscale results in max throughput being null ThroughputResponse autoscale = await fixedContainer.ReadThroughputAsync(requestOptions : null); Assert.IsNotNull(autoscale); Assert.IsNotNull(autoscale.Resource.Throughput); Assert.AreEqual(1000, autoscale.Resource.Throughput); Assert.IsNull(autoscale.Resource.AutoscaleMaxThroughput); await database.DeleteAsync(); }
public async Task CreateDropAutoscaleDatabaseStreamApi() { string databaseId = Guid.NewGuid().ToString(); using (ResponseMessage response = await this.cosmosClient.CreateDatabaseStreamAsync( new DatabaseProperties(databaseId), ThroughputProperties.CreateAutoscaleThroughput(5000))) { Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); } DatabaseInternal database = (DatabaseInlineCore)this.cosmosClient.GetDatabase(databaseId); ThroughputResponse autoscale = await database.ReadThroughputAsync(requestOptions : null); Assert.IsNotNull(autoscale); Assert.AreEqual(5000, autoscale.Resource.AutoscaleMaxThroughput); ThroughputResponse autoscaleReplaced = await database.ReplaceThroughputAsync( ThroughputProperties.CreateAutoscaleThroughput(10000)); Assert.IsNotNull(autoscaleReplaced); Assert.AreEqual(10000, autoscaleReplaced.Resource.AutoscaleMaxThroughput); await database.DeleteAsync(); }
public void OfferReplacePendingHeaderNotSetReturnsNull() { ThroughputResponse throughputResponse = new ThroughputResponse(HttpStatusCode.OK, new Headers(), null, null, null); Assert.IsNull(throughputResponse.IsReplacePending); }
public async Task CreateDropFixedDatabase() { DatabaseInternal database = (DatabaseInlineCore)await this.cosmosClient.CreateDatabaseAsync( nameof(CreateDropAutoscaleDatabase) + Guid.NewGuid().ToString(), ThroughputProperties.CreateManualThroughput(5000)); ThroughputResponse fixedDatabaseThroughput = await database.ReadThroughputAsync(requestOptions : null); Assert.IsNotNull(fixedDatabaseThroughput); Assert.AreEqual(5000, fixedDatabaseThroughput.Resource.Throughput); Assert.IsNull(fixedDatabaseThroughput.Resource.AutoscaleMaxThroughput); Assert.IsNull(fixedDatabaseThroughput.Resource.AutoUpgradeMaxThroughputIncrementPercentage); ThroughputResponse fixedReplaced = await database.ReplaceThroughputAsync( ThroughputProperties.CreateManualThroughput(6000)); Assert.IsNotNull(fixedReplaced); Assert.AreEqual(6000, fixedReplaced.Resource.Throughput); Assert.IsNull(fixedReplaced.Resource.AutoscaleMaxThroughput); Assert.IsNull(fixedReplaced.Resource.AutoUpgradeMaxThroughputIncrementPercentage); ThroughputResponse fixedReplacedIfExists = await database.ReplaceThroughputPropertiesIfExistsAsync( ThroughputProperties.CreateManualThroughput(7000)); Assert.IsNotNull(fixedReplacedIfExists); Assert.AreEqual(7000, fixedReplacedIfExists.Resource.Throughput); Assert.IsNull(fixedReplacedIfExists.Resource.AutoscaleMaxThroughput); Assert.IsNull(fixedReplacedIfExists.Resource.AutoUpgradeMaxThroughputIncrementPercentage); await database.DeleteAsync(); }
[Ignore] // Not currently working with emulator public async Task CreateDropAutoscaleContainer() { DatabaseCore database = (DatabaseInlineCore)await this.cosmosClient.CreateDatabaseAsync( Guid.NewGuid().ToString()); ThroughputResponse databaseThroughput = await database.ReadThroughputIfExistsAsync(requestOptions : null); Assert.IsNotNull(databaseThroughput); Assert.AreEqual(HttpStatusCode.NotFound, databaseThroughput.StatusCode); ContainerCore container = (ContainerInlineCore)await database.CreateContainerAsync( new ContainerProperties(Guid.NewGuid().ToString(), "/pk"), ThroughputProperties.CreateAutoscaleProvionedThroughput(5000)); Assert.IsNotNull(container); ThroughputResponse autoscale = await container.ReadThroughputAsync(requestOptions : null); Assert.IsNotNull(autoscale); Assert.AreEqual(5000, autoscale.Resource.MaxAutoscaleThroughput); ThroughputResponse autoscaleReplaced = await container.ReplaceThroughputPropertiesAsync( ThroughputProperties.CreateAutoscaleProvionedThroughput(10000)); Assert.IsNotNull(autoscaleReplaced); Assert.AreEqual(10000, autoscaleReplaced.Resource.MaxAutoscaleThroughput); await database.DeleteAsync(); }
public async Task CreateDatabaseIfNotExistTest() { string dbName = nameof(CreateDatabaseIfNotExistTest) + Guid.NewGuid(); DatabaseResponse databaseResponse = await this.cosmosClient.CreateDatabaseIfNotExistsAsync( dbName, ThroughputProperties.CreateAutoscaleThroughput(autoscaleMaxThroughput: 5000)); Assert.AreEqual(HttpStatusCode.Created, databaseResponse.StatusCode); // Container is required to validate database throughput upgrade scenarios Container container = await databaseResponse.Database.CreateContainerAsync("Test", "/id"); ThroughputResponse autoscale = await databaseResponse.Database.ReadThroughputAsync(requestOptions : null); Assert.IsNotNull(autoscale); Assert.IsNotNull(autoscale.Resource.Throughput); Assert.AreEqual(5000, autoscale.Resource.AutoscaleMaxThroughput); databaseResponse = await this.cosmosClient.CreateDatabaseIfNotExistsAsync( dbName, ThroughputProperties.CreateAutoscaleThroughput( autoscaleMaxThroughput: 5000)); Assert.AreEqual(HttpStatusCode.OK, databaseResponse.StatusCode); autoscale = await databaseResponse.Database.ReadThroughputAsync(requestOptions : null); Assert.IsNotNull(autoscale); Assert.IsNotNull(autoscale.Resource.Throughput); Assert.AreEqual(5000, autoscale.Resource.AutoscaleMaxThroughput); }
public async Task ThroughputResponseTest() { int expectedThroughput = 2400; string containerName = Guid.NewGuid().ToString(); string partitionKeyPath = "/users"; ContainerResponse containerResponse = await this.database.DefineContainer(containerName, partitionKeyPath) .CreateAsync(expectedThroughput); Assert.AreEqual(HttpStatusCode.Created, containerResponse.StatusCode); Container container = this.database.GetContainer(containerName); ThroughputResponse readThroughput = await container.ReadThroughputAsync(new RequestOptions()); Assert.IsNotNull(readThroughput); Assert.AreEqual(expectedThroughput, readThroughput.Resource.Throughput); // Implicit conversion ThroughputProperties throughputProperties = await container.ReadThroughputAsync(new RequestOptions()); Assert.IsNotNull(throughputProperties); Assert.AreEqual(expectedThroughput, throughputProperties.Throughput); // simple API int?throughput = await container.ReadThroughputAsync(); Assert.IsNotNull(throughput); Assert.AreEqual(expectedThroughput, throughput); containerResponse = await container.DeleteContainerAsync(); Assert.AreEqual(HttpStatusCode.NoContent, containerResponse.StatusCode); }
public async Task ReadReplaceThroughputResponseTests() { string databaseId = Guid.NewGuid().ToString(); int throughput = 10000; DatabaseResponse createResponse = await this.CreateDatabaseHelper(databaseId, databaseExists : false, throughput : throughput); Assert.AreEqual(HttpStatusCode.Created, createResponse.StatusCode); Cosmos.Database cosmosDatabase = createResponse; ThroughputResponse readThroughputResponse = await cosmosDatabase.ReadThroughputAsync(new RequestOptions()); Assert.IsNotNull(readThroughputResponse); Assert.IsNotNull(readThroughputResponse.Resource); Assert.IsNotNull(readThroughputResponse.MinThroughput); Assert.IsNotNull(readThroughputResponse.Resource.Throughput); Assert.AreEqual(throughput, readThroughputResponse.Resource.Throughput.Value); // Implicit ThroughputProperties throughputProperties = await cosmosDatabase.ReadThroughputAsync(new RequestOptions()); Assert.IsNotNull(throughputProperties); Assert.AreEqual(throughput, throughputProperties.Throughput); // Simple API int?readThroughput = await cosmosDatabase.ReadThroughputAsync(); Assert.AreEqual(throughput, readThroughput); string containerId = Guid.NewGuid().ToString(); string partitionPath = "/users"; ContainerResponse containerResponse = await cosmosDatabase.CreateContainerAsync(containerId, partitionPath); Assert.AreEqual(HttpStatusCode.Created, containerResponse.StatusCode); ThroughputResponse replaceThroughputResponse = await cosmosDatabase.ReplaceThroughputAsync(readThroughputResponse.Resource.Throughput.Value + 1000); Assert.IsNotNull(replaceThroughputResponse); Assert.IsNotNull(replaceThroughputResponse.Resource); Assert.AreEqual(readThroughputResponse.Resource.Throughput.Value + 1000, replaceThroughputResponse.Resource.Throughput.Value); Container container = containerResponse; try { readThroughputResponse = await container.ReadThroughputAsync(new RequestOptions()); Assert.Fail("Should through not found exception as throughput is not configured"); } catch (CosmosException exception) { Assert.AreEqual(HttpStatusCode.NotFound, exception.StatusCode); } await container.DeleteContainerAsync(); await cosmosDatabase.DeleteAsync(); }
public void OfferReplacePendingHeaderSetFalseReturnsFalse() { ThroughputResponse throughputResponse = new ThroughputResponse(HttpStatusCode.OK, new Headers { { WFConstants.BackendHeaders.OfferReplacePending, "false" } }, null, null, null); Assert.IsNotNull(throughputResponse.IsReplacePending); Assert.IsFalse(throughputResponse.IsReplacePending.Value); }
private static async Task ThroughputSettings(Container peopleContainer) { ThroughputResponse response = await peopleContainer.ReadThroughputAsync(); int?current = response.Resource.Throughput; await Console.Out.WriteLineAsync($"{current} RU per sec"); await Console.Out.WriteLineAsync($"Minimum allowed: {response.MinThroughput} RU per sec"); await peopleContainer.ReplaceThroughputAsync(1000); }
public static async Task WaitForOfferReplaceAsync(Container container) { bool done = false; while (!done) { ThroughputResponse response = await container.ReadThroughputAsync(new RequestOptions()); done = response.IsReplacePending == null || !response.IsReplacePending.Value; Thread.Sleep(60000); } }
public async Task <int> UpdateDatabaseThroughput(string name, int sharedRu) { try { Database db = client.GetDatabase(name); ThroughputProperties props = ThroughputProperties.CreateAutoscaleThroughput(sharedRu); ThroughputResponse resp = await db.ReplaceThroughputAsync(props); return((int)resp.StatusCode); } catch (Exception e) { Console.WriteLine($"UpdateDatabaseThroughput {name} {sharedRu} -> Exception {e}"); return(-1); } }
public async Task <int> UpdateContainerThroughput(string dbname, string cname, int ru) { try { Database db = await GetDatabase(dbname); Container container = db.GetContainer(cname); ThroughputResponse resp = await container.ReplaceThroughputAsync(ru); return((int)resp.StatusCode); } catch (Exception e) { Console.WriteLine(e); return(-1); } }
// </Main> /// <summary> /// Run basic database meta data operations as a console application. /// </summary> /// <returns></returns> // <RunDatabaseDemo> private static async Task RunDatabaseDemo(CosmosClient client) { // An object containing relevant information about the response DatabaseResponse databaseResponse = await client.CreateDatabaseIfNotExistsAsync(databaseId, 10000); // A client side reference object that allows additional operations like ReadAsync Database database = databaseResponse; // The response from Azure Cosmos DatabaseProperties properties = databaseResponse; Console.WriteLine($"\n1. Create a database resource with id: {properties.Id} and last modified time stamp: {properties.LastModified}"); Console.WriteLine($"\n2. Create a database resource request charge: {databaseResponse.RequestCharge} and Activity Id: {databaseResponse.ActivityId}"); // Read the database from Azure Cosmos DatabaseResponse readResponse = await database.ReadAsync(); Console.WriteLine($"\n3. Read a database: {readResponse.Resource.Id}"); await readResponse.Database.CreateContainerAsync("testContainer", "/pk"); // Get the current throughput for the database ThroughputResponse throughputResponse = await database.ReadThroughputAsync(); if (throughputResponse.Resource.Throughput.HasValue) { Console.WriteLine($"\n4. Read a database throughput: {throughputResponse.Resource.Throughput.HasValue}"); // Update the current throughput for the database await database.ReplaceThroughputAsync(11000); } Console.WriteLine("\n5. Reading all databases resources for an account"); FeedIterator <DatabaseProperties> iterator = client.GetDatabaseIterator(); do { foreach (DatabaseProperties db in await iterator.ReadNextAsync()) { Console.WriteLine(db.Id); } } while (iterator.HasMoreResults); // Delete the database from Azure Cosmos. await database.DeleteAsync(); Console.WriteLine($"\n6. Database {database.Id} deleted."); }
private static async Task SetContainerPerformance(Container container, int desiredThroughput) { ThroughputProperties throughputProperties = await container.ReadThroughputAsync(requestOptions : null); ThroughputResponse throughputResponse = null; if (throughputProperties.AutoscaleMaxThroughput != null) { // Container configured with autoscale throughput if (throughputProperties.AutoscaleMaxThroughput.Value == desiredThroughput) { WriteLineInColor($"\nThe {container.Id} container is already configured with max throughput: {desiredThroughput}. Skipping performance change request...", ConsoleColor.Yellow); } else { WriteLineInColor($"\nThe {container.Id} container is configured with max throughput: {throughputProperties.AutoscaleMaxThroughput}\nChanging max throughput to {desiredThroughput}", ConsoleColor.White); ThroughputProperties newThroughputProperties = ThroughputProperties.CreateAutoscaleThroughput(desiredThroughput); throughputResponse = await container.ReplaceThroughputAsync(newThroughputProperties); WriteLineInColor($"\nChanged {container.Id}'s max throughput to {desiredThroughput}", ConsoleColor.Cyan); } } else { // Container configured with manual throughput if (throughputProperties.Throughput.HasValue && throughputProperties.Throughput.Value == desiredThroughput) { WriteLineInColor($"\nThe {container.Id} container is already configured with throughput: {desiredThroughput}. Skipping performance change request...", ConsoleColor.Yellow); } else { WriteLineInColor($"\nThe {container.Id} container is configured with throughput: {throughputProperties.AutoscaleMaxThroughput}\nChanging throughput to {desiredThroughput}", ConsoleColor.White); ThroughputProperties newThroughputProperties = ThroughputProperties.CreateManualThroughput(desiredThroughput); throughputResponse = await container.ReplaceThroughputAsync(newThroughputProperties); WriteLineInColor($"\nChanged {container.Id}'s throughput to {desiredThroughput}", ConsoleColor.Cyan); } } }
// </CreateContainer> // <CreateAndUpdateAutoscaleContainer> private static async Task CreateAndUpdateAutoscaleContainer() { // Set autoscale throughput to the maximum value of 10000 RU/s ContainerProperties containerProperties = new ContainerProperties(autoscaleContainerId, partitionKeyPath); Container autoscaleContainer = await database.CreateContainerIfNotExistsAsync( containerProperties : containerProperties, throughputProperties : ThroughputProperties.CreateAutoscaleThroughput(autoscaleMaxThroughput: 10000)); Console.WriteLine($"{Environment.NewLine}1.2. Created autoscale container :{autoscaleContainer.Id}"); //********************************************************************************************* // Get configured performance of a CosmosContainer //********************************************************************************************** ThroughputResponse throughputResponse = await autoscaleContainer.ReadThroughputAsync(requestOptions : null); Console.WriteLine($"{Environment.NewLine}1.2.1. Found autoscale throughput {Environment.NewLine}The current throughput: {throughputResponse.Resource.Throughput} Max throughput: {throughputResponse.Resource.AutoscaleMaxThroughput} " + $"using container's id: {autoscaleContainer.Id}"); //********************************************************************************************* // Get the current throughput configured for a Container //********************************************************************************************** int?currentThroughput = await autoscaleContainer.ReadThroughputAsync(); Console.WriteLine($"{Environment.NewLine}1.2.2. Found autoscale throughput {Environment.NewLine}The current throughput: {currentThroughput} using container's id: {autoscaleContainer.Id}"); //****************************************************************************************************************** // Change performance (reserved throughput) of CosmosContainer // Let's change the performance of the autoscale container to a maximum throughput of 15000 RU/s //****************************************************************************************************************** ThroughputResponse throughputUpdateResponse = await autoscaleContainer.ReplaceThroughputAsync(ThroughputProperties.CreateAutoscaleThroughput(15000)); Console.WriteLine($"{Environment.NewLine}1.2.3. Replaced autoscale throughput. {Environment.NewLine}The current throughput: {throughputUpdateResponse.Resource.Throughput} Max throughput: {throughputUpdateResponse.Resource.AutoscaleMaxThroughput} " + $"using container's id: {autoscaleContainer.Id}"); // Get the offer again after replace throughputResponse = await autoscaleContainer.ReadThroughputAsync(requestOptions : null); Console.WriteLine($"{Environment.NewLine}1.2.4. Found autoscale throughput {Environment.NewLine}The current throughput: {throughputResponse.Resource.Throughput} Max throughput: {throughputResponse.Resource.AutoscaleMaxThroughput} " + $"using container's id: {autoscaleContainer.Id}{Environment.NewLine}"); // Delete the container await autoscaleContainer.DeleteContainerAsync(); }
public async Task NegativeContainerThroughputTestAsync() { // Create a database and container to make sure all the caches are warmed up Database db1 = await this.cosmosClient.CreateDatabaseAsync( Guid.NewGuid().ToString(), 400); // Container does not have an offer Container container = await db1.CreateContainerAsync( Guid.NewGuid().ToString(), "/pk"); await container.CreateItemAsync(ToDoActivity.CreateRandomToDoActivity()); try { await container.ReadThroughputAsync(requestOptions : null); Assert.Fail("Should throw exception"); } catch (CosmosException ex) when(ex.StatusCode == HttpStatusCode.NotFound) { Assert.IsTrue(ex.Message.Contains(container.Id)); } try { await container.ReplaceThroughputAsync(400); Assert.Fail("Should throw exception"); } catch (CosmosException ex) when(ex.StatusCode == HttpStatusCode.NotFound) { Assert.IsTrue(ex.Message.Contains(container.Id)); } int?throughput = await container.ReadThroughputAsync(); Assert.IsNull(throughput); { ThroughputResponse offerAfterRecreate = await((ContainerInternal)container).ReadThroughputIfExistsAsync( requestOptions: default,
public async Task CreateDropAutoscaleDatabase() { DatabaseInternal database = (DatabaseInlineCore)await this.cosmosClient.CreateDatabaseAsync( nameof(CreateDropAutoscaleDatabase) + Guid.NewGuid().ToString(), ThroughputProperties.CreateAutoscaleThroughput(5000)); ThroughputResponse autoscale = await database.ReadThroughputAsync(requestOptions : null); Assert.IsNotNull(autoscale); Assert.AreEqual(5000, autoscale.Resource.AutoscaleMaxThroughput); ThroughputResponse autoscaleReplaced = await database.ReplaceThroughputAsync( ThroughputProperties.CreateAutoscaleThroughput(10000)); Assert.IsNotNull(autoscaleReplaced); Assert.AreEqual(10000, autoscaleReplaced.Resource.AutoscaleMaxThroughput); await database.DeleteAsync(); }
[TestCategory("Quarantine")] // Not currently working with emulator public async Task ContainerAutoscaleIfExistsTest() { DatabaseInternal database = (DatabaseInlineCore)await this.cosmosClient.CreateDatabaseAsync( nameof(CreateDropAutoscaleDatabase) + Guid.NewGuid().ToString()); Container container = await database.CreateContainerAsync( containerProperties : new ContainerProperties("Test", "/id"), throughputProperties : ThroughputProperties.CreateAutoscaleThroughput(5000)); ContainerInternal containerCore = (ContainerInlineCore)container; ThroughputResponse throughputResponse = await database.ReadThroughputIfExistsAsync(requestOptions : null); Assert.IsNotNull(throughputResponse); Assert.AreEqual(HttpStatusCode.NotFound, throughputResponse.StatusCode); Assert.IsNull(throughputResponse.Resource); throughputResponse = await database.ReplaceThroughputPropertiesIfExistsAsync( ThroughputProperties.CreateAutoscaleThroughput(6000)); Assert.IsNotNull(throughputResponse); Assert.AreEqual(HttpStatusCode.NotFound, throughputResponse.StatusCode); Assert.IsNull(throughputResponse.Resource); throughputResponse = await containerCore.ReadThroughputIfExistsAsync( requestOptions : null, default(CancellationToken)); Assert.IsNotNull(throughputResponse); Assert.IsTrue(throughputResponse.Resource.Throughput > 400); Assert.AreEqual(5000, throughputResponse.Resource.AutoscaleMaxThroughput); throughputResponse = await containerCore.ReplaceThroughputIfExistsAsync( ThroughputProperties.CreateAutoscaleThroughput(6000), requestOptions : null, default(CancellationToken)); Assert.IsNotNull(throughputResponse); Assert.IsTrue(throughputResponse.Resource.Throughput > 400); Assert.AreEqual(6000, throughputResponse.Resource.AutoscaleMaxThroughput); await database.DeleteAsync(); }
public async Task ReadReplaceThroughputReourceTest() { string containerName = Guid.NewGuid().ToString(); string partitionKeyPath = "/users"; ContainerResponse containerResponse = await this.cosmosDatabase.CreateContainerIfNotExistsAsync(containerName, partitionKeyPath); Assert.AreEqual(HttpStatusCode.Created, containerResponse.StatusCode); Container container = this.cosmosDatabase.GetContainer(containerName); ThroughputResponse readThroughputResponse = await container.ReadThroughputAsync(new RequestOptions()); Assert.IsNotNull(readThroughputResponse); Assert.IsNotNull(readThroughputResponse.Resource); Assert.IsNotNull(readThroughputResponse.MinThroughput); Assert.IsNotNull(readThroughputResponse.Resource.Throughput); ThroughputResponse replaceThroughputResponse = await container.ReplaceThroughputAsync(readThroughputResponse.Resource.Throughput.Value + 1000); Assert.IsNotNull(replaceThroughputResponse); Assert.IsNotNull(replaceThroughputResponse.Resource); Assert.AreEqual(readThroughputResponse.Resource.Throughput.Value + 1000, replaceThroughputResponse.Resource.Throughput.Value); try { ThroughputResponse nonExistingContainerThroughput = await this.cosmosDatabase .GetContainer("nonExistingContainer") .ReadThroughputAsync(new RequestOptions()); Assert.Fail("It should throw Resource Not Found exception"); } catch (CosmosException ex) { Assert.AreEqual(HttpStatusCode.NotFound, ex.StatusCode); } containerResponse = await container.DeleteContainerAsync(); Assert.AreEqual(HttpStatusCode.NoContent, containerResponse.StatusCode); }
public async Task ReadReplaceThroughputResponseTests() { string databaseId = Guid.NewGuid().ToString(); int throughput = 10000; DatabaseResponse createResponse = await this.CreateDatabaseHelper(databaseId, databaseExists : false, throughput : throughput); Assert.AreEqual(HttpStatusCode.Created, createResponse.StatusCode); Cosmos.Database cosmosDatabase = createResponse; ThroughputResponse readThroughputResponse = await cosmosDatabase.ReadThroughputAsync(); Assert.IsNotNull(readThroughputResponse); Assert.IsNotNull(readThroughputResponse.Resource); Assert.IsNotNull(readThroughputResponse.MinThroughput); Assert.IsNotNull(readThroughputResponse.Resource.Throughput); Assert.AreEqual(throughput, readThroughputResponse.Resource.Throughput.Value); string containerId = Guid.NewGuid().ToString(); string partitionPath = "/users"; ContainerResponse containerResponse = await cosmosDatabase.CreateContainerAsync(containerId, partitionPath); Assert.AreEqual(HttpStatusCode.Created, containerResponse.StatusCode); ThroughputResponse replaceThroughputResponse = await cosmosDatabase.ReplaceThroughputAsync(readThroughputResponse.Resource.Throughput.Value + 1000); Assert.IsNotNull(replaceThroughputResponse); Assert.IsNotNull(replaceThroughputResponse.Resource); Assert.AreEqual(readThroughputResponse.Resource.Throughput.Value + 1000, replaceThroughputResponse.Resource.Throughput.Value); Container container = containerResponse; readThroughputResponse = await container.ReadThroughputAsync(); Assert.IsNull(readThroughputResponse.Resource); await container.DeleteContainerAsync(); await cosmosDatabase.DeleteAsync(); }
// </CreateContainerWithTtlExpiration> // <GetAndChangeContainerPerformance> private static async Task GetAndChangeContainerPerformance(Container simpleContainer) { //********************************************************************************************* // Get configured performance (reserved throughput) of a CosmosContainer //********************************************************************************************** ThroughputResponse throughputResponse = await simpleContainer.ReadThroughputAsync(); Console.WriteLine($"\n2. Found throughput \n{throughputResponse.Resource.Throughput.Value}\nusing container's id \n{simpleContainer.Id}"); //****************************************************************************************************************** // Change performance (reserved throughput) of CosmosContainer // Let's change the performance of the container to 500 RU/s //****************************************************************************************************************** await simpleContainer.ReplaceThroughputAsync(500); Console.WriteLine("\n3. Replaced throughput. Throughput is now 500.\n"); // Get the offer again after replace throughputResponse = await simpleContainer.ReadThroughputAsync(); Console.WriteLine($"3. Found throughput \n{throughputResponse.Resource.Throughput.Value}\n using container's ResourceId {simpleContainer.Id}.\n"); }
public async Task DatabaseAutoscaleIfExistsTest() { DatabaseInternal database = (DatabaseInlineCore)await this.cosmosClient.CreateDatabaseAsync( nameof(CreateDropAutoscaleDatabase) + Guid.NewGuid().ToString(), ThroughputProperties.CreateAutoscaleThroughput(5000)); Container container = await database.CreateContainerAsync("Test", "/id"); ContainerInternal containerCore = (ContainerInlineCore)container; ThroughputResponse throughputResponse = await database.ReadThroughputIfExistsAsync(requestOptions : null); Assert.IsNotNull(throughputResponse); Assert.AreEqual(5000, throughputResponse.Resource.AutoscaleMaxThroughput); throughputResponse = await database.ReplaceThroughputAsync( ThroughputProperties.CreateAutoscaleThroughput(6000)); Assert.IsNotNull(throughputResponse); Assert.AreEqual(6000, throughputResponse.Resource.AutoscaleMaxThroughput); throughputResponse = await containerCore.ReadThroughputIfExistsAsync( requestOptions : null,
public async Task DatabaseAutoscaleIfExistsTest() { DatabaseCore database = (DatabaseInlineCore)await this.cosmosClient.CreateDatabaseAsync( nameof(CreateDropAutoscaleDatabase) + Guid.NewGuid().ToString(), ThroughputProperties.CreateAutoscaleProvionedThroughput(5000)); Container container = await database.CreateContainerAsync("Test", "/id"); ContainerCore containerCore = (ContainerInlineCore)container; ThroughputResponse throughputResponse = await database.ReadThroughputIfExistsAsync(requestOptions : null); Assert.IsNotNull(throughputResponse); Assert.AreEqual(5000, throughputResponse.Resource.MaxAutoscaleThroughput); throughputResponse = await database.ReplaceThroughputPropertiesAsync( ThroughputProperties.CreateAutoscaleProvionedThroughput(6000)); Assert.IsNotNull(throughputResponse); Assert.AreEqual(6000, throughputResponse.Resource.MaxAutoscaleThroughput); throughputResponse = await containerCore.ReadThroughputIfExistsAsync(requestOptions : null); Assert.IsNotNull(throughputResponse); Assert.AreEqual(HttpStatusCode.NotFound, throughputResponse.StatusCode); Assert.IsNull(throughputResponse.Resource); throughputResponse = await containerCore.ReplaceThroughputPropertiesIfExistsAsync( ThroughputProperties.CreateAutoscaleProvionedThroughput(6000)); Assert.IsNotNull(throughputResponse); Assert.AreEqual(HttpStatusCode.NotFound, throughputResponse.StatusCode); Assert.IsNull(throughputResponse.Resource); await database.DeleteAsync(); }
public async Task CreateContainerIfNotExistTest() { string dbName = nameof(CreateContainerIfNotExistTest) + Guid.NewGuid(); DatabaseCore database = (DatabaseInlineCore)await this.cosmosClient.CreateDatabaseAsync(dbName); ContainerProperties containerProperties = new ContainerProperties("Test", "/id"); ContainerResponse containerResponse = await database.CreateContainerIfNotExistsAsync( containerProperties, ThroughputProperties.CreateAutoscaleThroughput(5000)); Assert.AreEqual(HttpStatusCode.Created, containerResponse.StatusCode); ThroughputResponse autoscale = await containerResponse.Container.ReadThroughputAsync(requestOptions : null); Assert.IsNotNull(autoscale); Assert.IsNotNull(autoscale.Resource.Throughput); Assert.AreEqual(5000, autoscale.Resource.AutoscaleMaxThroughput); containerResponse = await database.CreateContainerIfNotExistsAsync( containerProperties, ThroughputProperties.CreateAutoscaleThroughput(5000)); Assert.AreEqual(HttpStatusCode.OK, containerResponse.StatusCode); }
public async Task ReadReplaceThroughputResponseTests() { int toStreamCount = 0; int fromStreamCount = 0; CosmosSerializerHelper mockJsonSerializer = new CosmosSerializerHelper( null, (x) => fromStreamCount++, (x) => toStreamCount++); //Create a new cosmos client with the mocked cosmos json serializer CosmosClient client = TestCommon.CreateCosmosClient( (cosmosClientBuilder) => cosmosClientBuilder.WithCustomSerializer(mockJsonSerializer)); int databaseThroughput = 10000; Cosmos.Database databaseNoThroughput = await client.CreateDatabaseAsync(Guid.NewGuid().ToString(), null); Cosmos.Database databaseWithThroughput = await client.CreateDatabaseAsync(Guid.NewGuid().ToString(), databaseThroughput, null); string containerId = Guid.NewGuid().ToString(); string partitionPath = "/users"; Container containerNoThroughput = await databaseWithThroughput.CreateContainerAsync(containerId, partitionPath, throughput : null); try { await containerNoThroughput.ReadThroughputAsync(new RequestOptions()); Assert.Fail("Should through not found exception as throughput is not configured"); } catch (CosmosException exception) { Assert.AreEqual(HttpStatusCode.NotFound, exception.StatusCode); } try { await containerNoThroughput.ReplaceThroughputAsync(2000, new RequestOptions()); Assert.Fail("Should through not found exception as throughput is not configured"); } catch (CosmosException exception) { Assert.AreEqual(HttpStatusCode.NotFound, exception.StatusCode); } int containerThroughput = 1000; Container container = await databaseNoThroughput.CreateContainerAsync(Guid.NewGuid().ToString(), "/id", throughput : containerThroughput); int?containerResponseThroughput = await container.ReadThroughputAsync(); Assert.AreEqual(containerThroughput, containerResponseThroughput); ThroughputResponse containerThroughputResponse = await container.ReadThroughputAsync(new RequestOptions()); Assert.IsNotNull(containerThroughputResponse); Assert.IsNotNull(containerThroughputResponse.Resource); Assert.IsNotNull(containerThroughputResponse.MinThroughput); Assert.IsNotNull(containerThroughputResponse.Resource.Throughput); Assert.AreEqual(containerThroughput, containerThroughputResponse.Resource.Throughput.Value); containerThroughput += 500; containerThroughputResponse = await container.ReplaceThroughputAsync(containerThroughput, new RequestOptions()); Assert.IsNotNull(containerThroughputResponse); Assert.IsNotNull(containerThroughputResponse.Resource); Assert.IsNotNull(containerThroughputResponse.Resource.Throughput); Assert.AreEqual(containerThroughput, containerThroughputResponse.Resource.Throughput.Value); Assert.AreEqual(0, toStreamCount, "Custom serializer to stream should not be used for offer operations"); Assert.AreEqual(0, fromStreamCount, "Custom serializer from stream should not be used for offer operations"); await databaseNoThroughput.DeleteAsync(); }
public async Task ReadReplaceThroughputResponseTests() { int toStreamCount = 0; int fromStreamCount = 0; CosmosSerializerHelper mockJsonSerializer = new CosmosSerializerHelper( null, (x) => fromStreamCount++, (x) => toStreamCount++); //Create a new cosmos client with the mocked cosmos json serializer CosmosClient client = TestCommon.CreateCosmosClient( (cosmosClientBuilder) => cosmosClientBuilder.WithCustomSerializer(mockJsonSerializer)); string databaseId = Guid.NewGuid().ToString(); int throughput = 10000; DatabaseResponse createResponse = await client.CreateDatabaseAsync(databaseId, throughput, null); Assert.AreEqual(HttpStatusCode.Created, createResponse.StatusCode); Cosmos.Database cosmosDatabase = createResponse; ThroughputResponse readThroughputResponse = await cosmosDatabase.ReadThroughputAsync(new RequestOptions()); Assert.IsNotNull(readThroughputResponse); Assert.IsNotNull(readThroughputResponse.Resource); Assert.IsNotNull(readThroughputResponse.MinThroughput); Assert.IsNotNull(readThroughputResponse.Resource.Throughput); Assert.AreEqual(throughput, readThroughputResponse.Resource.Throughput.Value); // Implicit ThroughputProperties throughputProperties = await cosmosDatabase.ReadThroughputAsync(new RequestOptions()); Assert.IsNotNull(throughputProperties); Assert.AreEqual(throughput, throughputProperties.Throughput); // Simple API int?readThroughput = await cosmosDatabase.ReadThroughputAsync(); Assert.AreEqual(throughput, readThroughput); // Database must have a container before it can be scaled string containerId = Guid.NewGuid().ToString(); string partitionPath = "/users"; ContainerResponse containerResponse = await cosmosDatabase.CreateContainerAsync(containerId, partitionPath, throughput : null); Assert.AreEqual(HttpStatusCode.Created, containerResponse.StatusCode); ThroughputResponse replaceThroughputResponse = await cosmosDatabase.ReplaceThroughputAsync(readThroughputResponse.Resource.Throughput.Value + 1000); Assert.IsNotNull(replaceThroughputResponse); Assert.IsNotNull(replaceThroughputResponse.Resource); Assert.AreEqual(readThroughputResponse.Resource.Throughput.Value + 1000, replaceThroughputResponse.Resource.Throughput.Value); await cosmosDatabase.DeleteAsync(); Database databaseNoThroughput = await client.CreateDatabaseAsync(Guid.NewGuid().ToString(), throughput : null); try { ThroughputResponse throughputResponse = await databaseNoThroughput.ReadThroughputAsync(new RequestOptions()); Assert.Fail("Should through not found exception as throughput is not configured"); } catch (CosmosException exception) { Assert.AreEqual(HttpStatusCode.NotFound, exception.StatusCode); } try { ThroughputResponse throughputResponse = await databaseNoThroughput.ReplaceThroughputAsync(2000, new RequestOptions()); Assert.Fail("Should through not found exception as throughput is not configured"); } catch (CosmosException exception) { Assert.AreEqual(HttpStatusCode.NotFound, exception.StatusCode); } int?dbThroughput = await databaseNoThroughput.ReadThroughputAsync(); Assert.IsNull(dbThroughput); Assert.AreEqual(0, toStreamCount, "Custom serializer to stream should not be used for offer operations"); Assert.AreEqual(0, fromStreamCount, "Custom serializer from stream should not be used for offer operations"); await databaseNoThroughput.DeleteAsync(); }