Skip to content

Commit 4105caa

Browse files
committed
Update performance tests and include bulk, batch and query.
1 parent 6317547 commit 4105caa

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Performance.Tests/Benchmarks/ThinClientIntegrationBenchmark.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,70 @@ public async Task DeleteItemStreamAsync()
269269
this.deleteStreamItems.RemoveAt(index);
270270
}
271271

272+
[Benchmark]
273+
public async Task BulkCreateItemsAsync()
274+
{
275+
string pk = "pk_bulk";
276+
List<CosmosIntegrationTestObject> bulkItems = this.GenerateItems(pk).Take(100).ToList();
277+
List<Task> tasks = new();
278+
279+
foreach (CosmosIntegrationTestObject item in bulkItems)
280+
{
281+
tasks.Add(this.container.CreateItemAsync(item, new PartitionKey(item.Pk)));
282+
}
283+
284+
await Task.WhenAll(tasks);
285+
}
286+
287+
[Benchmark]
288+
public async Task TransactionalBatchCreateAsync()
289+
{
290+
string pk = "pk_batch";
291+
List<CosmosIntegrationTestObject> batchItems = this.GenerateItems(pk).Take(10).ToList();
292+
293+
TransactionalBatch batch = this.container.CreateTransactionalBatch(new PartitionKey(pk));
294+
foreach (CosmosIntegrationTestObject item in batchItems)
295+
{
296+
batch.CreateItem(item);
297+
}
298+
TransactionalBatchResponse response = await batch.ExecuteAsync();
299+
if (!response.IsSuccessStatusCode)
300+
{
301+
throw new Exception("Transactional batch failed.");
302+
}
303+
}
304+
305+
[Benchmark]
306+
public async Task QueryItemsAsync()
307+
{
308+
FeedIterator<CosmosIntegrationTestObject> query = this.container.GetItemQueryIterator<CosmosIntegrationTestObject>(
309+
$"SELECT * FROM c WHERE c.pk = 'pk_benchmark'");
310+
List<CosmosIntegrationTestObject> results = new();
311+
while (query.HasMoreResults)
312+
{
313+
FeedResponse<CosmosIntegrationTestObject> response = await query.ReadNextAsync();
314+
results.AddRange(response);
315+
}
316+
if (results.Count == 0)
317+
{
318+
throw new Exception("Query returned no results.");
319+
}
320+
}
321+
322+
[Benchmark]
323+
public async Task QueryItemsStreamAsync()
324+
{
325+
FeedIterator query = this.container.GetItemQueryStreamIterator(
326+
$"SELECT * FROM c WHERE c.pk = 'pk_benchmark'");
327+
while (query.HasMoreResults)
328+
{
329+
using ResponseMessage response = await query.ReadNextAsync();
330+
if (!response.IsSuccessStatusCode)
331+
{
332+
throw new Exception("QueryStream failed.");
333+
}
334+
}
335+
}
272336
private class CustomBenchmarkConfig : ManualConfig
273337
{
274338
public CustomBenchmarkConfig()

0 commit comments

Comments
 (0)