-
Notifications
You must be signed in to change notification settings - Fork 494
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
Subpartitioning: Add tests for Transactional Batch #3930
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests | |
using System.Reflection; | ||
using System.Text.RegularExpressions; | ||
using Microsoft.Azure.Cosmos.Diagnostics; | ||
using global::Azure; | ||
|
||
[TestClass] | ||
public class CosmosItemTests : BaseCosmosClientHelper | ||
|
@@ -841,6 +842,73 @@ public async Task PartitionKeyDeleteTestForSubpartitionedContainer() | |
} | ||
} | ||
|
||
[TestMethod] | ||
public async Task TransactionalBatchTestForSubpartitionedContainer() | ||
{ | ||
string currentVersion = HttpConstants.Versions.CurrentVersion; | ||
HttpConstants.Versions.CurrentVersion = "2020-07-15"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this? |
||
using CosmosClient client = TestCommon.CreateCosmosClient(true); | ||
Cosmos.Database database = null; | ||
try | ||
{ | ||
database = await client.CreateDatabaseIfNotExistsAsync("mydb"); | ||
|
||
ContainerProperties containerProperties = new ContainerProperties("subpartitionedcontainer", new List<string> { "/Country", "/City" }); | ||
Container container = await database.CreateContainerAsync(containerProperties); | ||
ContainerInternal containerInternal = (ContainerInternal)container; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these casts needed? Aren't all the APIs being accessed in the non-internal interface? |
||
|
||
TransactionalBatchInternal transactionalBatchInternal = (TransactionalBatchInternal)containerInternal.CreateTransactionalBatch( | ||
new PartitionKeyBuilder().Add("USA").Add("Redmond").Build()) ; | ||
|
||
//Document create. | ||
ItemResponse<Document>[] documents = new ItemResponse<Document>[5]; | ||
Document doc1 = new Document { Id = "document1" }; | ||
doc1.SetValue("Country", "USA"); | ||
doc1.SetValue("City", "Redmond"); | ||
|
||
Document doc2 = new Document { Id = "document2" }; | ||
doc2.SetValue("Country", "USA"); | ||
doc2.SetValue("City", "Redmond"); | ||
await transactionalBatchInternal | ||
.CreateItem<Document>(doc1) | ||
.CreateItem<Document>(doc2) | ||
.ExecuteAsync(); | ||
|
||
//Specifying a partial partition key should fail | ||
Cosmos.PartitionKey partialPartitionKey = new PartitionKeyBuilder().Add("USA").Build(); | ||
TransactionalBatch transactionalBatchInternalPartialKey = containerInternal.CreateTransactionalBatch(partialPartitionKey); | ||
try | ||
{ | ||
TransactionalBatchResponse response = await transactionalBatchInternalPartialKey.CreateItem<Document>(doc1).ExecuteAsync(); | ||
Assert.Fail("Should have thrown"); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Assert.AreEqual(typeof(ArgumentException), ex.GetType()); | ||
Assert.IsTrue(ex.Message.Contains(ClientResources.TooFewPartitionKeyComponents)); | ||
} | ||
|
||
//OverSpecifying a partition key should fail | ||
Cosmos.PartitionKey overSpecifiedPartitionKey = new PartitionKeyBuilder().Add("USA").Add("Redmond").Add("someValue").Build(); | ||
TransactionalBatch transactionalBatchOverSpecifiedPartitionKey = containerInternal.CreateTransactionalBatch(overSpecifiedPartitionKey); | ||
try | ||
{ | ||
TransactionalBatchResponse response = await transactionalBatchOverSpecifiedPartitionKey.CreateItem<Document>(doc1).ExecuteAsync(); | ||
Assert.Fail("Should have thrown"); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Assert.AreEqual(typeof(ArgumentException), ex.GetType()); | ||
Assert.IsTrue(ex.Message.Contains(ClientResources.TooManyPartitionKeyComponents)); | ||
} | ||
} | ||
finally | ||
{ | ||
HttpConstants.Versions.CurrentVersion = currentVersion; | ||
if (database != null) await database.DeleteAsync(); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public async Task ItemCustomSerialzierTest() | ||
{ | ||
|
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.
"than defined for the container." instead of "than defined the collection resource."