Skip to content

Commit

Permalink
Add possibility of using local storage emulator
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpetit authored and ReubenBond committed Nov 2, 2024
1 parent 141be0d commit 3186108
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 5 deletions.
3 changes: 3 additions & 0 deletions distributed-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ results:

profiles:
local:
variables:
azureQueueUri: "http://127.0.0.1:10001"
azureTableUri: "http://127.0.0.1:10002"
jobs:
server:
endpoints:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private async Task RunAsync(Parameters parameters)
.UseOrleansClient((ctx, builder) => {
builder
.Configure<ClusterOptions>(options => { options.ClusterId = parameters.ClusterId; options.ServiceId = parameters.ServiceId; })
.UseAzureStorageClustering(options => options.TableServiceClient = new(parameters.AzureTableUri, TokenCredentialHelper.GetTokenCredential()));
.UseAzureStorageClustering(options => options.TableServiceClient = parameters.AzureTableUri.CreateTableServiceClient());
});
using var host = hostBuilder.Build();
await host.StartAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task Run(ClientParameters clientParams, LoadGeneratorParameters loa
var hostBuilder = new HostBuilder().UseOrleansClient((ctx, builder) =>
builder.Configure<ClusterOptions>(options => { options.ClusterId = clientParams.ClusterId; options.ServiceId = clientParams.ServiceId; })
.Configure<ConnectionOptions>(options => clientParams.ConnectionsPerEndpoint = 2)
.UseAzureStorageClustering(options => options.TableServiceClient = new(clientParams.AzureTableUri, TokenCredentialHelper.GetTokenCredential())));
.UseAzureStorageClustering(options => options.TableServiceClient = clientParams.AzureTableUri.CreateTableServiceClient()));
using var host = hostBuilder.Build();

_logger.LogInformation("Connecting to cluster...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
<PackageReference Include="Azure.Storage.Queues" />
<PackageReference Include="Azure.Data.Tables" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Microsoft.Extensions.Configuration" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static class Channels
private static readonly string SILO_TO_CLIENT_QUEUE = "client-{0}";

public static Task<ISendChannel> CreateSendChannel(string clusterId, Uri azureQueueUri)
=> CreateSendChannel(clusterId, new QueueServiceClient(azureQueueUri, TokenCredentialHelper.GetTokenCredential()));
=> CreateSendChannel(clusterId, azureQueueUri.CreateQueueServiceClient());

public static async Task<ISendChannel> CreateSendChannel(string clusterId, QueueServiceClient queueServiceClient)
{
Expand All @@ -86,7 +86,7 @@ public static async Task<ISendChannel> CreateSendChannel(string clusterId, Queue
}

public static Task<IReceiveChannel> CreateReceiveChannel(string serverName, string clusterId, Uri azureQueueUri)
=> CreateReceiveChannel(serverName, clusterId, new QueueServiceClient(azureQueueUri, TokenCredentialHelper.GetTokenCredential()));
=> CreateReceiveChannel(serverName, clusterId, azureQueueUri.CreateQueueServiceClient());

public static async Task<IReceiveChannel> CreateReceiveChannel(string serverName, string clusterId, QueueServiceClient queueServiceClient)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Data.Tables;
using Azure.Identity;
using Azure.Storage.Queues;

namespace DistributedTests.Common;

public static class TokenCredentialHelper
{
private static string EmulatorConnectionString = "UseDevelopmentStorage=true";

public static TableServiceClient CreateTableServiceClient(this Uri azureTableUri)
{
if (azureTableUri.IsLoopback)
{
// Assume it's the emulator/azurite
return new TableServiceClient(EmulatorConnectionString);
}
return new TableServiceClient(azureTableUri, GetTokenCredential());
}

public static QueueServiceClient CreateQueueServiceClient(this Uri azureQueueUri)
{
if (azureQueueUri.IsLoopback)
{
// Assume it's the emulator/azurite
return new QueueServiceClient(EmulatorConnectionString);
}
return new QueueServiceClient(azureQueueUri, GetTokenCredential());
}

public static TokenCredential GetTokenCredential()
{
var tenantId = Environment.GetEnvironmentVariable("TENANT_ID");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private void ConfigureOrleans(ISiloBuilder siloBuilder, CommonParameters commonP
.Configure<SiloOptions>(options => options.SiloName = _siloName)
.Configure<ClusterOptions>(options => { options.ClusterId = commonParameters.ClusterId; options.ServiceId = commonParameters.ServiceId; })
.ConfigureEndpoints(siloPort: commonParameters.SiloPort, gatewayPort: commonParameters.GatewayPort)
.UseAzureStorageClustering(options => options.TableServiceClient = new(commonParameters.AzureTableUri, TokenCredentialHelper.GetTokenCredential()));
.UseAzureStorageClustering(options => options.TableServiceClient = commonParameters.AzureTableUri.CreateTableServiceClient());

if (commonParameters.ActivationRepartitioning)
{
Expand Down

0 comments on commit 3186108

Please sign in to comment.