Skip to content

Commit

Permalink
Addressing #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Austin Hanson committed Sep 21, 2018
1 parent 1945bf9 commit 9f9e025
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 15 deletions.
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

<PropertyGroup>
<AutoBogus_Moq>1.0.0</AutoBogus_Moq>
<Microsoft_Extensions_DependencyInjection>2.1.1</Microsoft_Extensions_DependencyInjection>
<dotnet_xunit>2.3.1</dotnet_xunit>
<FluentAssertions>4.19.4</FluentAssertions>
<Microsoft_NET_Test_Sdk>15.6.0</Microsoft_NET_Test_Sdk>
Expand Down
19 changes: 12 additions & 7 deletions src/Orleans.Redis.Common/CachedConnectionMultiplexerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class CachedConnectionMultiplexerFactory : IConnectionMultiplexerFactory
{
public static IConnectionMultiplexerFactory Default = new CachedConnectionMultiplexerFactory();

private readonly SemaphoreSlim _lock = new SemaphoreSlim(1);
private readonly SemaphoreSlim _lock = new SemaphoreSlim(1, 1);
private readonly Dictionary<string, IConnectionMultiplexer> _connectionMultiplexers = new Dictionary<string, IConnectionMultiplexer>();
internal Dictionary<string, IConnectionMultiplexer> TestHook_ConnectionMultiplexers => _connectionMultiplexers;

Expand All @@ -24,15 +24,20 @@ public async Task<IConnectionMultiplexer> CreateAsync(string configuration)
{
if (!_connectionMultiplexers.TryGetValue(configuration, out var connectionMultiplexer))
{
await _lock.WaitAsync();
try
{
await _lock.WaitAsync();

if (!_connectionMultiplexers.TryGetValue(configuration, out connectionMultiplexer))
if (!_connectionMultiplexers.TryGetValue(configuration, out connectionMultiplexer))
{
connectionMultiplexer = await ConnectionMultiplexer.ConnectAsync(configuration);
_connectionMultiplexers.Add(configuration, connectionMultiplexer);
}
}
finally
{
connectionMultiplexer = await ConnectionMultiplexer.ConnectAsync(configuration);
_connectionMultiplexers.Add(configuration, connectionMultiplexer);
_lock.Release();
}

_lock.Release();
}

return connectionMultiplexer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public RedisQueueAdapter(
Name = providerName;
_streamQueueMapper = streamQueueMapper;
_dataAdapter = dataAdapter;
_logger = logger != null ? logger.ForContext<RedisQueueAdapter>() : SilentLogger.Logger;
_logger = (logger ?? SilentLogger.Logger).ForContext<RedisQueueAdapter>();
}

public IQueueAdapterReceiver CreateReceiver(QueueId queueId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public SiloRedisStreamConfigurator(string name, ISiloHostBuilder builder)
.ConfigureApplicationParts(parts => parts.AddFrameworkPart(typeof(RedisQueueAdapterFactory).Assembly))
.ConfigureServices(services =>
{
services.ConfigureNamedOptionForLogging<RedisStreamOptions>(name);
services.ConfigureNamedOptionForLogging<RedisStreamOptions>(name);
services.TryAddSingleton(CachedConnectionMultiplexerFactory.Default);
services.TryAddSingleton<ISerializationManager, OrleansSerializationManager>();
services.AddSingleton<IRedisDataAdapter, RedisDataAdapter>();
Expand Down
2 changes: 1 addition & 1 deletion test/CoreTests/CoreTests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp2.1</TargetFramework>
<IsPackable>false</IsPackable>
<RuntimeFrameworkVersion>2.0.3</RuntimeFrameworkVersion>
<Configurations>Debug;Release;Test</Configurations>
Expand Down
2 changes: 1 addition & 1 deletion test/Shared/Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(Microsoft_Extensions_DependencyInjection)" />
<PackageReference Include="xunit" Version="$(xunit)" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp2.1</TargetFramework>
<IsPackable>false</IsPackable>
<RuntimeFrameworkVersion>2.0.3</RuntimeFrameworkVersion>
<Configurations>Debug;Release;Test</Configurations>
Expand Down
6 changes: 3 additions & 3 deletions test/StorageTests/StorageTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp2.1</TargetFramework>
<IsPackable>false</IsPackable>
<RuntimeFrameworkVersion>2.0.3</RuntimeFrameworkVersion>
<Configurations>Debug;Release;Test</Configurations>
Expand All @@ -17,8 +17,8 @@
<PackageReference Include="FluentAssertions" Version="$(FluentAssertions)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(Microsoft_NET_Test_Sdk)" />
<PackageReference Include="Microsoft.Orleans.Core" Version="$(Microsoft_Orleans_Core)" />
<PackageReference Include="Microsoft.Orleans.OrleansCodeGenerator" Version="2.0.5" />
<PackageReference Include="Microsoft.Orleans.OrleansCodeGenerator.Build" Version="2.0.5">
<PackageReference Include="Microsoft.Orleans.OrleansCodeGenerator" Version="$(Microsoft_Orleans_Core)" />
<PackageReference Include="Microsoft.Orleans.OrleansCodeGenerator.Build" Version="$(Microsoft_Orleans_Core)">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down

0 comments on commit 9f9e025

Please sign in to comment.