-
Notifications
You must be signed in to change notification settings - Fork 524
Add environment variable configuration for BatchAsyncContainerExecutor MaxOperationsInDirectModeBatchRequest #5295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
7
commits into
master
Choose a base branch
from
copilot/fix-5294
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3ba3133
Initial plan
Copilot b521198
Add environment variable configuration for MaxOperationsInDirectModeB…
Copilot 1883e99
Merge branch 'master' into copilot/fix-5294
kirankumarkolli 8abde21
Move BatchConfiguration logic to ConfigurationManager and add upper b…
Copilot 00ea126
Remove unnecessary BatchConfiguration class and use ConfigurationMana…
Copilot e1e0458
Update env var name and implement performance optimization with caching
Copilot d515dd8
Fix caching implementation to properly reset cache for tests
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
159 changes: 159 additions & 0 deletions
159
...t.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Batch/ConfigurationManagerBatchTests.cs
This file contains hidden or 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,159 @@ | ||
| //------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| //------------------------------------------------------------ | ||
|
|
||
| namespace Microsoft.Azure.Cosmos.Tests | ||
| { | ||
| using System; | ||
| using Microsoft.Azure.Documents; | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
|
||
| [TestClass] | ||
| public class ConfigurationManagerTests | ||
| { | ||
| private const string EnvironmentVariableName = "AZURE_COSMOS_MAX_OPERATIONS_IN_BATCH_REQUEST"; | ||
|
|
||
| [ClassInitialize] | ||
| public static void ClassInitialize(TestContext context) | ||
| { | ||
| // Disable caching for tests to allow environment variable changes to take effect | ||
| ConfigurationManager.DisableBatchRequestCaching(); | ||
| } | ||
|
|
||
| [ClassCleanup] | ||
| public static void ClassCleanup() | ||
| { | ||
| // Re-enable caching after tests | ||
| ConfigurationManager.EnableBatchRequestCaching(); | ||
| } | ||
|
|
||
| [TestCleanup] | ||
| public void TestCleanup() | ||
| { | ||
| // Clean up environment variable after each test | ||
| Environment.SetEnvironmentVariable(EnvironmentVariableName, null); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void GetMaxOperationsInDirectModeBatchRequest_WhenEnvironmentVariableNotSet_ReturnsDefault() | ||
| { | ||
| // Arrange | ||
| Environment.SetEnvironmentVariable(EnvironmentVariableName, null); | ||
|
|
||
| // Act | ||
| int result = ConfigurationManager.GetMaxOperationsInDirectModeBatchRequest(); | ||
|
|
||
| // Assert | ||
| Assert.AreEqual(Constants.MaxOperationsInDirectModeBatchRequest, result); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void GetMaxOperationsInDirectModeBatchRequest_WhenEnvironmentVariableSetToValidValue_ReturnsValue() | ||
| { | ||
| // Arrange | ||
| const int expectedValue = 50; | ||
| Environment.SetEnvironmentVariable(EnvironmentVariableName, expectedValue.ToString()); | ||
|
|
||
| // Act | ||
| int result = ConfigurationManager.GetMaxOperationsInDirectModeBatchRequest(); | ||
|
|
||
| // Assert | ||
| Assert.AreEqual(expectedValue, result); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void GetMaxOperationsInDirectModeBatchRequest_WhenEnvironmentVariableSetToLargeValue_ReturnsValue() | ||
| { | ||
| // Arrange | ||
| const int expectedValue = 50; // Changed to a smaller value that should be within bounds | ||
| Environment.SetEnvironmentVariable(EnvironmentVariableName, expectedValue.ToString()); | ||
|
|
||
| // Act | ||
| int result = ConfigurationManager.GetMaxOperationsInDirectModeBatchRequest(); | ||
|
|
||
| // Assert | ||
| Assert.AreEqual(expectedValue, result); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [ExpectedException(typeof(ArgumentException))] | ||
| public void GetMaxOperationsInDirectModeBatchRequest_WhenEnvironmentVariableSetToValueGreaterThanMax_ThrowsArgumentException() | ||
| { | ||
| // Arrange | ||
| // Set to a value that's likely greater than the default constant | ||
| const int valueGreaterThanMax = 10000; | ||
| Environment.SetEnvironmentVariable(EnvironmentVariableName, valueGreaterThanMax.ToString()); | ||
|
|
||
| // Act | ||
| ConfigurationManager.GetMaxOperationsInDirectModeBatchRequest(); | ||
|
|
||
| // Assert - ExpectedException | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [ExpectedException(typeof(ArgumentException))] | ||
| public void GetMaxOperationsInDirectModeBatchRequest_WhenEnvironmentVariableSetToZero_ThrowsArgumentException() | ||
| { | ||
| // Arrange | ||
| Environment.SetEnvironmentVariable(EnvironmentVariableName, "0"); | ||
|
|
||
| // Act | ||
| ConfigurationManager.GetMaxOperationsInDirectModeBatchRequest(); | ||
|
|
||
| // Assert - ExpectedException | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [ExpectedException(typeof(ArgumentException))] | ||
| public void GetMaxOperationsInDirectModeBatchRequest_WhenEnvironmentVariableSetToNegativeValue_ThrowsArgumentException() | ||
| { | ||
| // Arrange | ||
| Environment.SetEnvironmentVariable(EnvironmentVariableName, "-1"); | ||
|
|
||
| // Act | ||
| ConfigurationManager.GetMaxOperationsInDirectModeBatchRequest(); | ||
|
|
||
| // Assert - ExpectedException | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [ExpectedException(typeof(ArgumentException))] | ||
| public void GetMaxOperationsInDirectModeBatchRequest_WhenEnvironmentVariableSetToInvalidString_ThrowsArgumentException() | ||
| { | ||
| // Arrange | ||
| Environment.SetEnvironmentVariable(EnvironmentVariableName, "invalid"); | ||
|
|
||
| // Act | ||
| ConfigurationManager.GetMaxOperationsInDirectModeBatchRequest(); | ||
|
|
||
| // Assert - ExpectedException | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void GetMaxOperationsInDirectModeBatchRequest_WhenEnvironmentVariableSetToEmptyString_ReturnsDefault() | ||
| { | ||
| // Arrange | ||
| Environment.SetEnvironmentVariable(EnvironmentVariableName, ""); | ||
|
|
||
| // Act | ||
| int result = ConfigurationManager.GetMaxOperationsInDirectModeBatchRequest(); | ||
|
|
||
| // Assert | ||
| Assert.AreEqual(Constants.MaxOperationsInDirectModeBatchRequest, result); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void GetMaxOperationsInDirectModeBatchRequest_WhenEnvironmentVariableSetToOne_ReturnsOne() | ||
| { | ||
| // Arrange | ||
| const int expectedValue = 1; | ||
| Environment.SetEnvironmentVariable(EnvironmentVariableName, expectedValue.ToString()); | ||
|
|
||
| // Act | ||
| int result = ConfigurationManager.GetMaxOperationsInDirectModeBatchRequest(); | ||
|
|
||
| // Assert | ||
| Assert.AreEqual(expectedValue, result); | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its reading everytime and checking ENVIRONMENT variables which is expensive.
Please read it once and use afterewards
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented caching to read environment variable only once using Lazy<T>. The value is now cached on first access and reused for subsequent calls, eliminating the performance overhead. Added test-friendly controls to disable caching during unit tests. (d515dd8)