This repository has been archived by the owner on Jul 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support different throughput options (#60)
* basic changes to handle throughput modes. * Revert breaking change * Update ci.yml * Update publish.yml
- Loading branch information
Showing
15 changed files
with
276 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/Orleans.Clustering.CosmosDB/Extensions/CosmosDBClusteringOptionsExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using Microsoft.Azure.Cosmos; | ||
using Orleans.Clustering.CosmosDB.Models; | ||
|
||
namespace Orleans.Clustering.CosmosDB.Extensions; | ||
|
||
internal static class CosmosDBClusteringOptionsExtensions | ||
{ | ||
internal static ThroughputProperties GetThroughputProperties(this CosmosDBClusteringOptions options) => | ||
options.ThroughputMode switch | ||
{ | ||
ThroughputMode.Manual => ThroughputProperties.CreateManualThroughput(options.CollectionThroughput), | ||
ThroughputMode.Autoscale => ThroughputProperties.CreateAutoscaleThroughput( | ||
options.CollectionThroughput == 400 ? 4000 : options.CollectionThroughput), | ||
ThroughputMode.Serverless => null, | ||
_ => throw new ArgumentOutOfRangeException(nameof(options.ThroughputMode), $"There is no setup for throughput mode {options.ThroughputMode}") | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Orleans.Clustering.CosmosDB.Models; | ||
|
||
public enum ThroughputMode | ||
{ | ||
Manual, | ||
Autoscale, | ||
Serverless | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/Orleans.Persistence.CosmosDB/Extensions/CosmosDBStorageOptionsExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using Microsoft.Azure.Cosmos; | ||
using Orleans.Persistence.CosmosDB.Models; | ||
|
||
namespace Orleans.Persistence.CosmosDB.Extensions; | ||
|
||
internal static class CosmosDBStorageOptionsExtensions | ||
{ | ||
internal static ThroughputProperties GetThroughputProperties(this CosmosDBStorageOptions options) => | ||
options.ThroughputMode switch | ||
{ | ||
ThroughputMode.Manual => ThroughputProperties.CreateManualThroughput(options.CollectionThroughput), | ||
ThroughputMode.Autoscale => ThroughputProperties.CreateAutoscaleThroughput( | ||
options.CollectionThroughput == 400 ? 4000 : options.CollectionThroughput), | ||
ThroughputMode.Serverless => null, | ||
_ => throw new ArgumentOutOfRangeException(nameof(options.ThroughputMode), $"There is no setup for throughput mode {options.ThroughputMode}") | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Orleans.Persistence.CosmosDB.Models; | ||
|
||
public enum ThroughputMode | ||
{ | ||
Manual, | ||
Autoscale, | ||
Serverless | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
test/Orleans.CosmosDB.Tests/Extensions/CosmosDBClusteringOptionsExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using Orleans.Clustering.CosmosDB; | ||
using Orleans.Clustering.CosmosDB.Extensions; | ||
using Orleans.Clustering.CosmosDB.Models; | ||
using Xunit; | ||
|
||
namespace Orleans.CosmosDB.Tests.Extensions; | ||
|
||
public class CosmosDBClusteringOptionsExtensionsTests | ||
{ | ||
[Fact] | ||
public void GetThroughputProperties_ManualMode_SetsThroughputCorrectly() | ||
{ | ||
//Arrange | ||
var options = new CosmosDBClusteringOptions | ||
{ | ||
ThroughputMode = ThroughputMode.Manual | ||
}; | ||
|
||
//Act | ||
var properties = options.GetThroughputProperties(); | ||
|
||
//Assert | ||
Assert.Equal(400, properties.Throughput); | ||
Assert.Null(properties.AutoscaleMaxThroughput); | ||
} | ||
|
||
[Fact] | ||
public void GetThroughputProperties_AutoscaleModeDefaultThroughput_CreatesAutoscaleThroughputWith4000RUs() | ||
{ | ||
//Arrange | ||
var options = new CosmosDBClusteringOptions | ||
{ | ||
ThroughputMode = ThroughputMode.Autoscale | ||
}; | ||
|
||
//Act | ||
var properties = options.GetThroughputProperties(); | ||
|
||
//Assert | ||
Assert.Equal(4000, properties.AutoscaleMaxThroughput); | ||
Assert.Null(properties.Throughput); | ||
} | ||
|
||
[Fact] | ||
public void GetThroughputProperties_AutoscaleModeCustomThroughput_CreatesAutoscaleThroughputWithCustomRUs() | ||
{ | ||
//Arrange | ||
var options = new CosmosDBClusteringOptions | ||
{ | ||
ThroughputMode = ThroughputMode.Autoscale, | ||
CollectionThroughput = 6000 | ||
}; | ||
|
||
//Act | ||
var properties = options.GetThroughputProperties(); | ||
|
||
//Assert | ||
Assert.Equal(6000, properties.AutoscaleMaxThroughput); | ||
Assert.Null(properties.Throughput); | ||
} | ||
|
||
[Fact] | ||
public void GetThroughputProperties_ServerlessMode_ReturnsNullThroughput() | ||
{ | ||
//Arrange | ||
var options = new CosmosDBClusteringOptions | ||
{ | ||
ThroughputMode = ThroughputMode.Serverless | ||
}; | ||
|
||
//Act | ||
var properties = options.GetThroughputProperties(); | ||
|
||
//Assert | ||
Assert.Null(properties); | ||
} | ||
} |
Oops, something went wrong.