Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Aspire.Hosting.Azure.CosmosDB/AzureCosmosDBExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ public static IResourceBuilder<AzureCosmosDBResource> RunAsEmulator(this IResour
Tag = "latest"
});

if (configureContainer != null)
{
var surrogate = new AzureCosmosDBEmulatorResource(builder.Resource);
var surrogateBuilder = builder.ApplicationBuilder.CreateResourceBuilder(surrogate);
configureContainer(surrogateBuilder);
}
var surrogate = new AzureCosmosDBEmulatorResource(builder.Resource);
var surrogateBuilder = builder.ApplicationBuilder.CreateResourceBuilder(surrogate);
// Set a low default number of partitions to improve container startup time
surrogateBuilder.WithEnvironment("AZURE_COSMOS_EMULATOR_PARTITION_COUNT", "1");

configureContainer?.Invoke(surrogateBuilder);

return builder;
}
Expand Down
27 changes: 27 additions & 0 deletions tests/Aspire.Hosting.Azure.Tests/AzureResourceExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Tests.Utils;
using Aspire.Hosting.Utils;
using Xunit;

Expand Down Expand Up @@ -173,4 +174,30 @@ public void AddAzureCosmosDBWithEmulatorGetsExpectedImageTag(string imageTag)
var actualTag = containerImageAnnotation.Tag;
Assert.Equal(imageTag ?? "latest", actualTag);
}

[Fact]
public async Task AddAzureCosmosDBWithEmulatorGetDefaultNumberOfPartitions()
{
using var builder = TestDistributedApplicationBuilder.Create();

var cosmos = builder.AddAzureCosmosDB("cosmos");

cosmos.RunAsEmulator();
var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(cosmos.Resource, DistributedApplicationOperation.Run, TestServiceProvider.Instance);

Assert.Equal("1", config["AZURE_COSMOS_EMULATOR_PARTITION_COUNT"]);
}

[Fact]
public async Task AddAzureCosmosDBWithEmulatorCanOverrideNumberOfPartitions()
{
using var builder = TestDistributedApplicationBuilder.Create();

var cosmos = builder.AddAzureCosmosDB("cosmos");

cosmos.RunAsEmulator(r => r.WithEnvironment("AZURE_COSMOS_EMULATOR_PARTITION_COUNT", "30"));
var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(cosmos.Resource, DistributedApplicationOperation.Run, TestServiceProvider.Instance);

Assert.Equal("30", config["AZURE_COSMOS_EMULATOR_PARTITION_COUNT"]);
}
}