Skip to content

Commit

Permalink
Autoscale: Add to official release and do renames (#1428)
Browse files Browse the repository at this point in the history
* Change autoscale property names.

* Updating names

* Removed commented code

* Making autoscale public
  • Loading branch information
j82w authored May 4, 2020
1 parent 2bca8a6 commit 0a1f95e
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 92 deletions.
14 changes: 2 additions & 12 deletions Microsoft.Azure.Cosmos/src/CosmosClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,7 @@ public virtual Task<DatabaseResponse> CreateDatabaseAsync(
/// <param name="cancellationToken">(Optional) <see cref="CancellationToken"/> representing request cancellation.</param>
/// <returns>A <see cref="Task"/> containing a <see cref="DatabaseResponse"/> which wraps a <see cref="DatabaseProperties"/> containing the resource record.</returns>
/// <seealso href="https://docs.microsoft.com/azure/cosmos-db/request-units">Request Units</seealso>
#if PREVIEW
public
#else
internal
#endif
virtual Task<DatabaseResponse> CreateDatabaseAsync(
public virtual Task<DatabaseResponse> CreateDatabaseAsync(
string id,
ThroughputProperties throughputProperties,
RequestOptions requestOptions = null,
Expand Down Expand Up @@ -462,12 +457,7 @@ virtual Task<DatabaseResponse> CreateDatabaseAsync(
/// </list>
/// </returns>
/// <seealso href="https://docs.microsoft.com/azure/cosmos-db/request-units">Request Units</seealso>
#if PREVIEW
public
#else
internal
#endif
virtual Task<DatabaseResponse> CreateDatabaseIfNotExistsAsync(
public virtual Task<DatabaseResponse> CreateDatabaseIfNotExistsAsync(
string id,
ThroughputProperties throughputProperties,
RequestOptions requestOptions = null,
Expand Down
2 changes: 1 addition & 1 deletion Microsoft.Azure.Cosmos/src/Handler/RequestMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ internal void AddThroughputPropertiesHeader(ThroughputProperties throughputPrope
}

if (throughputProperties.Throughput.HasValue &&
(throughputProperties.MaxAutoscaleThroughput.HasValue || throughputProperties.AutoUpgradeMaxThroughputIncrementPercentage.HasValue))
(throughputProperties.AutoscaleMaxThroughput.HasValue || throughputProperties.AutoUpgradeMaxThroughputIncrementPercentage.HasValue))
{
throw new InvalidOperationException("Autoscale provisioned throughput can not be configured with fixed offer");
}
Expand Down
2 changes: 0 additions & 2 deletions Microsoft.Azure.Cosmos/src/Resource/Container/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ public abstract Task<ThroughputResponse> ReplaceThroughputAsync(
RequestOptions requestOptions = null,
CancellationToken cancellationToken = default(CancellationToken));

#if PREVIEW
/// <summary>
/// Sets throughput provisioned for a container in measurement of request units per second in the Azure Cosmos service.
/// </summary>
Expand Down Expand Up @@ -331,7 +330,6 @@ public abstract Task<ThroughputResponse> ReplaceThroughputAsync(
ThroughputProperties throughputProperties,
RequestOptions requestOptions = null,
CancellationToken cancellationToken = default(CancellationToken));
#endif

/// <summary>
/// Creates a Item as an asynchronous operation in the Azure Cosmos service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ internal static void ValidatePartitionKey(object partitionKey, RequestOptions re
}

#if !PREVIEW
public abstract Task<ThroughputResponse> ReplaceThroughputAsync(
ThroughputProperties throughputProperties,
RequestOptions requestOptions = null,
CancellationToken cancellationToken = default(CancellationToken));

public abstract Task<IReadOnlyList<FeedRange>> GetFeedRangesAsync(CancellationToken cancellationToken = default(CancellationToken));

Expand Down
3 changes: 1 addition & 2 deletions Microsoft.Azure.Cosmos/src/Resource/Database/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public abstract Task<DatabaseResponse> DeleteAsync(
public abstract Task<ThroughputResponse> ReadThroughputAsync(
RequestOptions requestOptions,
CancellationToken cancellationToken = default(CancellationToken));
#if PREVIEW

/// <summary>
/// Sets throughput provisioned for a database in measurement of request units per second in the Azure Cosmos service.
/// </summary>
Expand Down Expand Up @@ -353,7 +353,6 @@ public abstract Task<ResponseMessage> CreateContainerStreamAsync(
ThroughputProperties throughputProperties,
RequestOptions requestOptions = null,
CancellationToken cancellationToken = default(CancellationToken));
#endif

/// <summary>
/// Sets throughput provisioned for a database in measurement of request units per second in the Azure Cosmos service.
Expand Down
25 changes: 0 additions & 25 deletions Microsoft.Azure.Cosmos/src/Resource/Database/DatabaseInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,5 @@ public abstract FeedIterator GetUserQueryStreamIterator(
string queryText = null,
string continuationToken = null,
QueryRequestOptions requestOptions = null);

#if !PREVIEW
public abstract Task<ThroughputResponse> ReplaceThroughputAsync(
ThroughputProperties throughputProperties,
RequestOptions requestOptions = null,
CancellationToken cancellationToken = default(CancellationToken));

public abstract Task<ContainerResponse> CreateContainerAsync(
ContainerProperties containerProperties,
ThroughputProperties throughputProperties,
RequestOptions requestOptions = null,
CancellationToken cancellationToken = default(CancellationToken));

public abstract Task<ContainerResponse> CreateContainerIfNotExistsAsync(
ContainerProperties containerProperties,
ThroughputProperties throughputProperties,
RequestOptions requestOptions = null,
CancellationToken cancellationToken = default(CancellationToken));

public abstract Task<ResponseMessage> CreateContainerStreamAsync(
ContainerProperties containerProperties,
ThroughputProperties throughputProperties,
RequestOptions requestOptions = null,
CancellationToken cancellationToken = default(CancellationToken));
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,7 @@ public int? Throughput
/// The maximum throughput the autoscale will scale to.
/// </summary>
[JsonIgnore]
#if PREVIEW
public
#else
internal
#endif
int? MaxAutoscaleThroughput => this.Content?.OfferAutoscaleSettings?.MaxThroughput;
public int? AutoscaleMaxThroughput => this.Content?.OfferAutoscaleSettings?.MaxThroughput;

/// <summary>
/// The amount to increment if the maximum RUs is getting throttled.
Expand All @@ -95,31 +90,31 @@ public int? Throughput
/// </summary>
/// <param name="throughput">The current provisioned throughput for the resource.</param>
/// <returns>Returns a ThroughputProperties for manual throughput</returns>
#if PREVIEW
public
#else
internal
#endif
static ThroughputProperties CreateManualThroughput(int throughput)
public static ThroughputProperties CreateManualThroughput(int throughput)
{
if (throughput <= 0)
{
throw new ArgumentOutOfRangeException($"{nameof(throughput)} must be greater than 0");
}

return new ThroughputProperties(OfferContentProperties.CreateManualOfferConent(throughput));
}

/// <summary>
/// The Throughput properties for autoscale provisioned throughput offering
/// </summary>
/// <param name="maxAutoscaleThroughput">The maximum throughput the resource can scale to.</param>
/// <param name="autoscaleMaxThroughput">The maximum throughput the resource can scale to.</param>
/// <returns>Returns a ThroughputProperties for autoscale provisioned throughput</returns>
#if PREVIEW
public
#else
internal
#endif
static ThroughputProperties CreateAutoscaleThroughput(
int maxAutoscaleThroughput)
public static ThroughputProperties CreateAutoscaleThroughput(
int autoscaleMaxThroughput)
{
if (autoscaleMaxThroughput <= 0)
{
throw new ArgumentOutOfRangeException($"{nameof(autoscaleMaxThroughput)} must be greater than 0");
}

return new ThroughputProperties(OfferContentProperties.CreateAutoscaleOfferConent(
startingMaxThroughput: maxAutoscaleThroughput,
startingMaxThroughput: autoscaleMaxThroughput,
autoUpgradeMaxThroughputIncrementPercentage: null));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public async Task CreateDropAutoscaleDatabaseStreamApi()
DatabaseInternal database = (DatabaseInlineCore)this.cosmosClient.GetDatabase(databaseId);
ThroughputResponse autoscale = await database.ReadThroughputAsync(requestOptions: null);
Assert.IsNotNull(autoscale);
Assert.AreEqual(5000, autoscale.Resource.MaxAutoscaleThroughput);
Assert.AreEqual(5000, autoscale.Resource.AutoscaleMaxThroughput);

ThroughputResponse autoscaleReplaced = await database.ReplaceThroughputAsync(
ThroughputProperties.CreateAutoscaleThroughput(10000));
Assert.IsNotNull(autoscaleReplaced);
Assert.AreEqual(10000, autoscaleReplaced.Resource.MaxAutoscaleThroughput);
Assert.AreEqual(10000, autoscaleReplaced.Resource.AutoscaleMaxThroughput);

await database.DeleteAsync();
}
Expand All @@ -66,12 +66,12 @@ public async Task CreateDropAutoscaleDatabase()

ThroughputResponse autoscale = await database.ReadThroughputAsync(requestOptions: null);
Assert.IsNotNull(autoscale);
Assert.AreEqual(5000, autoscale.Resource.MaxAutoscaleThroughput);
Assert.AreEqual(5000, autoscale.Resource.AutoscaleMaxThroughput);

ThroughputResponse autoscaleReplaced = await database.ReplaceThroughputAsync(
ThroughputProperties.CreateAutoscaleThroughput(10000));
Assert.IsNotNull(autoscaleReplaced);
Assert.AreEqual(10000, autoscaleReplaced.Resource.MaxAutoscaleThroughput);
Assert.AreEqual(10000, autoscaleReplaced.Resource.AutoscaleMaxThroughput);

await database.DeleteAsync();
}
Expand All @@ -86,21 +86,21 @@ public async Task CreateDropFixedDatabase()
ThroughputResponse fixedDatabaseThroughput = await database.ReadThroughputAsync(requestOptions: null);
Assert.IsNotNull(fixedDatabaseThroughput);
Assert.AreEqual(5000, fixedDatabaseThroughput.Resource.Throughput);
Assert.IsNull(fixedDatabaseThroughput.Resource.MaxAutoscaleThroughput);
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.MaxAutoscaleThroughput);
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.MaxAutoscaleThroughput);
Assert.IsNull(fixedReplacedIfExists.Resource.AutoscaleMaxThroughput);
Assert.IsNull(fixedReplacedIfExists.Resource.AutoUpgradeMaxThroughputIncrementPercentage);

await database.DeleteAsync();
Expand All @@ -118,12 +118,12 @@ public async Task DatabaseAutoscaleIfExistsTest()

ThroughputResponse throughputResponse = await database.ReadThroughputIfExistsAsync(requestOptions: null);
Assert.IsNotNull(throughputResponse);
Assert.AreEqual(5000, throughputResponse.Resource.MaxAutoscaleThroughput);
Assert.AreEqual(5000, throughputResponse.Resource.AutoscaleMaxThroughput);

throughputResponse = await database.ReplaceThroughputAsync(
ThroughputProperties.CreateAutoscaleThroughput(6000));
Assert.IsNotNull(throughputResponse);
Assert.AreEqual(6000, throughputResponse.Resource.MaxAutoscaleThroughput);
Assert.AreEqual(6000, throughputResponse.Resource.AutoscaleMaxThroughput);

throughputResponse = await containerCore.ReadThroughputIfExistsAsync(
requestOptions: null,
Expand Down Expand Up @@ -171,15 +171,15 @@ public async Task ContainerAutoscaleIfExistsTest()
default(CancellationToken));
Assert.IsNotNull(throughputResponse);
Assert.IsTrue(throughputResponse.Resource.Throughput > 400);
Assert.AreEqual(5000, throughputResponse.Resource.MaxAutoscaleThroughput);
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.MaxAutoscaleThroughput);
Assert.AreEqual(6000, throughputResponse.Resource.AutoscaleMaxThroughput);

await database.DeleteAsync();
}
Expand All @@ -190,7 +190,7 @@ public async Task CreateDatabaseIfNotExistTest()
string dbName = nameof(CreateDatabaseIfNotExistTest) + Guid.NewGuid();
DatabaseResponse databaseResponse = await this.cosmosClient.CreateDatabaseIfNotExistsAsync(
dbName,
ThroughputProperties.CreateAutoscaleThroughput(maxAutoscaleThroughput: 5000));
ThroughputProperties.CreateAutoscaleThroughput(autoscaleMaxThroughput: 5000));
Assert.AreEqual(HttpStatusCode.Created, databaseResponse.StatusCode);

// Container is required to validate database throughput upgrade scenarios
Expand All @@ -199,18 +199,18 @@ public async Task CreateDatabaseIfNotExistTest()
ThroughputResponse autoscale = await databaseResponse.Database.ReadThroughputAsync(requestOptions: null);
Assert.IsNotNull(autoscale);
Assert.IsNotNull(autoscale.Resource.Throughput);
Assert.AreEqual(5000, autoscale.Resource.MaxAutoscaleThroughput);
Assert.AreEqual(5000, autoscale.Resource.AutoscaleMaxThroughput);

databaseResponse = await this.cosmosClient.CreateDatabaseIfNotExistsAsync(
dbName,
ThroughputProperties.CreateAutoscaleThroughput(
maxAutoscaleThroughput: 5000));
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.MaxAutoscaleThroughput);
Assert.AreEqual(5000, autoscale.Resource.AutoscaleMaxThroughput);
}

[TestMethod]
Expand All @@ -228,7 +228,7 @@ public async Task CreateContainerIfNotExistTest()
ThroughputResponse autoscale = await containerResponse.Container.ReadThroughputAsync(requestOptions: null);
Assert.IsNotNull(autoscale);
Assert.IsNotNull(autoscale.Resource.Throughput);
Assert.AreEqual(5000, autoscale.Resource.MaxAutoscaleThroughput);
Assert.AreEqual(5000, autoscale.Resource.AutoscaleMaxThroughput);

containerResponse = await database.CreateContainerIfNotExistsAsync(
containerProperties,
Expand All @@ -250,21 +250,21 @@ public async Task CreateDropAutoscaleAutoUpgradeDatabase()

ThroughputResponse autoscale = await database.ReadThroughputAsync(requestOptions: null);
Assert.IsNotNull(autoscale);
Assert.AreEqual(5000, autoscale.Resource.MaxAutoscaleThroughput);
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.MaxAutoscaleThroughput);
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.MaxAutoscaleThroughput);
Assert.AreEqual(7000, autoUpgradeReplace.Resource.AutoscaleMaxThroughput);
Assert.AreEqual(20, autoUpgradeReplace.Resource.AutoUpgradeMaxThroughputIncrementPercentage);

await database.DeleteAsync();
Expand Down Expand Up @@ -294,7 +294,7 @@ public async Task CreateDropAutoscaleContainerStreamApi()
requestOptions: null,
default(CancellationToken));
Assert.IsNotNull(autoscaleIfExists);
Assert.AreEqual(5000, autoscaleIfExists.Resource.MaxAutoscaleThroughput);
Assert.AreEqual(5000, autoscaleIfExists.Resource.AutoscaleMaxThroughput);
}
}

Expand All @@ -312,15 +312,15 @@ public async Task CreateDropAutoscaleContainer()

ThroughputResponse throughputResponse = await container.ReadThroughputAsync(requestOptions: null);
Assert.IsNotNull(throughputResponse);
Assert.AreEqual(5000, throughputResponse.Resource.MaxAutoscaleThroughput);
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.MaxAutoscaleThroughput);
Assert.AreEqual(6000, throughputResponse.Resource.AutoscaleMaxThroughput);

await database.DeleteAsync();
}
Expand Down Expand Up @@ -363,7 +363,7 @@ public async Task ReadAutoscaleWithFixedTests()
Assert.IsNotNull(autoscale);
Assert.IsNotNull(autoscale.Resource.Throughput);
Assert.AreEqual(1000, autoscale.Resource.Throughput);
Assert.IsNull(autoscale.Resource.MaxAutoscaleThroughput);
Assert.IsNull(autoscale.Resource.AutoscaleMaxThroughput);

await database.DeleteAsync();
}
Expand Down
Loading

0 comments on commit 0a1f95e

Please sign in to comment.