Skip to content

Commit b9f7ab7

Browse files
committed
tests are fine now
1 parent 2d9fb7b commit b9f7ab7

File tree

73 files changed

+2023
-891
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2023
-891
lines changed

.editorconfig

Lines changed: 464 additions & 0 deletions
Large diffs are not rendered by default.

ManagedCode.Orleans.SignalR.Client/Extensions/OrleansDependencyInjectionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ public static ISignalRServerBuilder AddOrleans(this ISignalRServerBuilder signal
2323
signalrBuilder.Services.AddSingleton(typeof(HubLifetimeManager<>), typeof(OrleansHubLifetimeManager<>));
2424
return signalrBuilder;
2525
}
26-
}
26+
}

ManagedCode.Orleans.SignalR.Core/Config/OrleansSignalROptions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,28 @@ public class OrleansSignalROptions
1919
/// Set to false only if you don't want to send messages to the specific connectionId.
2020
/// </summary>
2121
public bool KeepEachConnectionAlive { get; set; } = true;
22-
22+
2323
/// <summary>
2424
/// This property determines the duration for which messages are stored when a client is disconnected.
2525
/// The default timeout is 1.1 minute.
2626
/// </summary>
2727
public TimeSpan KeepMessageInterval { get; set; } = TimeSpan.FromMinutes(1.1);
28-
28+
2929
/// <summary>
3030
/// Number of partitions to use for connection distribution.
3131
/// Set to 1 to disable partitioning.
3232
/// Increase this value for better scalability with millions of connections.
3333
/// The default value is 4.
3434
/// </summary>
3535
public uint ConnectionPartitionCount { get; set; } = 4;
36-
36+
3737
/// <summary>
3838
/// Target number of concurrent connections per partition.
3939
/// Used as a hint when determining how many partitions to allocate dynamically.
4040
/// Lower values result in more partitions.
4141
/// </summary>
4242
public int ConnectionsPerPartitionHint { get; set; } = 10_000;
43-
43+
4444
/// <summary>
4545
/// Number of partitions to use for group distribution.
4646
/// Set to 1 to disable partitioning.

ManagedCode.Orleans.SignalR.Core/Helpers/Logs.cs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,78 +7,76 @@ public static partial class Logs
77
[LoggerMessage(
88
Level = LogLevel.Trace,
99
Message = "{grainType}:{grainId} OnDeactivateAsync")]
10-
public static partial void OnDeactivateAsync(ILogger logger, string grainType, string grainId);
11-
10+
public static partial void OnDeactivateAsync(ILogger logger, string grainType, string grainId);
11+
1212
[LoggerMessage(
1313
Level = LogLevel.Trace,
1414
Message = "{grainType}:{grainId} Ping")]
1515
public static partial void Ping(ILogger logger, string grainType, string grainId);
16-
16+
1717
[LoggerMessage(
1818
Level = LogLevel.Debug,
1919
Message = "{grainType}:{grainId} AddConnection `{connectionId}`")]
2020
public static partial void AddConnection(ILogger logger, string grainType, string grainId, string connectionId);
21-
21+
2222
[LoggerMessage(
2323
Level = LogLevel.Debug,
2424
Message = "{grainType}:{grainId} RemoveConnection `{connectionId}`")]
2525
public static partial void RemoveConnection(ILogger logger, string grainType, string grainId, string connectionId);
26-
26+
2727
[LoggerMessage(
2828
Level = LogLevel.Debug,
2929
Message = "{grainType}:{grainId} SendToAll")]
30-
public static partial void SendToAll(ILogger logger, string grainType, string grainId);
31-
30+
public static partial void SendToAll(ILogger logger, string grainType, string grainId);
31+
3232
[LoggerMessage(
3333
Level = LogLevel.Debug,
3434
Message = "{grainType}:{grainId} SendToAllExcept")]
3535
public static partial void SendToAllExcept(ILogger logger, string grainType, string grainId, string[] expectedConnectionIds);
36-
36+
3737
[LoggerMessage(
3838
Level = LogLevel.Debug,
3939
Message = "{grainType}:{grainId} SendToConnection")]
4040
public static partial void SendToConnection(ILogger logger, string grainType, string grainId, string connectionId);
41-
41+
4242
[LoggerMessage(
4343
Level = LogLevel.Debug,
4444
Message = "{grainType}:{grainId} SendToConnections")]
4545
public static partial void SendToConnections(ILogger logger, string grainType, string grainId, string[] expectedConnectionIds);
46-
47-
46+
4847
[LoggerMessage(
4948
Level = LogLevel.Debug,
5049
Message = "{grainType}:{grainId} SendToGroup")]
5150
public static partial void SendToGroup(ILogger logger, string grainType, string grainId);
52-
51+
5352
[LoggerMessage(
5453
Level = LogLevel.Debug,
5554
Message = "{grainType}:{grainId} SendToGroupExcept")]
5655
public static partial void SendToGroupExcept(ILogger logger, string grainType, string grainId, string[] expectedConnectionIds);
57-
56+
5857
[LoggerMessage(
5958
Level = LogLevel.Debug,
6059
Message = "{grainType}:{grainId} TryCompleteResult")]
6160
public static partial void TryCompleteResult(ILogger logger, string grainType, string grainId, string connectionId);
62-
61+
6362
[LoggerMessage(
6463
Level = LogLevel.Debug,
6564
Message = "{grainType}:{grainId} TryGetReturnType")]
6665
public static partial void TryGetReturnType(ILogger logger, string grainType, string grainId);
67-
66+
6867
[LoggerMessage(
6968
Level = LogLevel.Debug,
7069
Message = "{grainType}:{grainId} AddInvocation")]
7170
public static partial void AddInvocation(ILogger logger, string grainType, string grainId, string invocationId, string connectionId);
72-
71+
7372
[LoggerMessage(
7473
Level = LogLevel.Trace,
7574
Message = "{grainType}:{grainId} RemoveInvocation")]
76-
public static partial void RemoveInvocation(ILogger logger, string grainType, string grainId);
77-
75+
public static partial void RemoveInvocation(ILogger logger, string grainType, string grainId);
76+
7877
[LoggerMessage(
7978
Level = LogLevel.Debug,
8079
Message = "{grainType}:{grainId} SendToUser")]
81-
public static partial void SendToUser(ILogger logger, string grainType, string grainId);
82-
83-
80+
public static partial void SendToUser(ILogger logger, string grainType, string grainId);
81+
8482
}

ManagedCode.Orleans.SignalR.Core/Helpers/PartitionHelper.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
2+
using System.Collections.Concurrent;
23
using System.Collections.Generic;
34
using System.Linq;
4-
using System.Collections.Concurrent;
55
using System.Security.Cryptography;
66
using System.Text;
77

@@ -11,14 +11,18 @@ public static class PartitionHelper
1111
{
1212
private const int VirtualNodesPerPartition = 150; // Number of virtual nodes per physical partition
1313
private static readonly ConcurrentDictionary<RingCacheKey, ConsistentHashRing> RingCache = new();
14-
14+
1515
public static int GetPartitionId(string connectionId, uint partitionCount)
1616
{
1717
if (string.IsNullOrEmpty(connectionId))
18+
{
1819
throw new ArgumentException("Connection ID cannot be null or empty", nameof(connectionId));
20+
}
1921

2022
if (partitionCount <= 0)
23+
{
2124
throw new ArgumentException("Partition count must be greater than 0", nameof(partitionCount));
25+
}
2226

2327
var ring = RingCache.GetOrAdd(new RingCacheKey((int)partitionCount, VirtualNodesPerPartition),
2428
key => new ConsistentHashRing(key.PartitionCount, key.VirtualNodes));
@@ -30,14 +34,14 @@ public static int GetOptimalPartitionCount(int expectedConnections)
3034
{
3135
return GetOptimalPartitionCount(expectedConnections, 10_000);
3236
}
33-
37+
3438
public static int GetOptimalPartitionCount(int expectedConnections, int connectionsPerPartition)
3539
{
3640
var perPartition = Math.Max(1, connectionsPerPartition);
3741
var partitions = Math.Max(1, (expectedConnections + perPartition - 1) / perPartition);
3842
return ToPowerOfTwo(partitions);
3943
}
40-
44+
4145
public static int GetOptimalGroupPartitionCount(int expectedGroups)
4246
{
4347
return GetOptimalGroupPartitionCount(expectedGroups, 1_000);
@@ -104,16 +108,22 @@ private static SortedList<uint, int> InitializeRing(int partitionCount, int virt
104108
public int GetPartition(string key)
105109
{
106110
if (_keys.Length == 0)
111+
{
107112
return 0;
113+
}
108114

109115
var hash = GetHash(key);
110116

111117
var index = Array.BinarySearch(_keys, hash);
112118
if (index < 0)
119+
{
113120
index = ~index;
121+
}
114122

115123
if (index >= _keys.Length)
124+
{
116125
index = 0;
126+
}
117127

118128
return _partitions[index];
119129
}

ManagedCode.Orleans.SignalR.Core/Helpers/TimeIntervalHelper.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ public static TimeSpan GetClientTimeoutInterval(IOptions<OrleansSignalROptions>
1313
var timeSpan = orleansSignalOptions.Value.ClientTimeoutInterval;
1414

1515
if (hubOptions.Value.ClientTimeoutInterval.HasValue && timeSpan > hubOptions.Value.ClientTimeoutInterval)
16+
{
1617
timeSpan = hubOptions.Value.ClientTimeoutInterval.Value;
18+
}
1719

1820
return timeSpan;
1921
}
@@ -25,26 +27,33 @@ public static TimeSpan GetClientTimeoutInterval(IOptions<OrleansSignalROptions>
2527

2628
if (globalHubOptions.Value.ClientTimeoutInterval.HasValue &&
2729
timeSpan > globalHubOptions.Value.ClientTimeoutInterval)
30+
{
2831
timeSpan = globalHubOptions.Value.ClientTimeoutInterval.Value;
32+
}
2933

3034
if (hubOptions.Value.ClientTimeoutInterval.HasValue && timeSpan > hubOptions.Value.ClientTimeoutInterval)
35+
{
3136
timeSpan = hubOptions.Value.ClientTimeoutInterval.Value;
37+
}
3238

3339
return timeSpan;
3440
}
3541

36-
3742
public static TimeSpan GetClientTimeoutInterval(IOptions<HubOptions> globalHubOptions,
3843
IOptions<HubOptions> hubOptions)
3944
{
4045
var timeSpan = TimeSpan.FromSeconds(15);
4146

4247
if (globalHubOptions.Value.ClientTimeoutInterval.HasValue &&
4348
timeSpan > globalHubOptions.Value.ClientTimeoutInterval)
49+
{
4450
timeSpan = globalHubOptions.Value.ClientTimeoutInterval.Value;
51+
}
4552

4653
if (hubOptions.Value.ClientTimeoutInterval.HasValue && timeSpan > hubOptions.Value.ClientTimeoutInterval)
54+
{
4755
timeSpan = hubOptions.Value.ClientTimeoutInterval.Value;
56+
}
4857

4958
return timeSpan;
5059
}
@@ -54,16 +63,20 @@ public static TimeSpan GetKeepAliveInterval(IOptions<HubOptions> globalHubOption
5463
var timeSpan = TimeSpan.FromSeconds(15);
5564

5665
if (globalHubOptions.Value.ClientTimeoutInterval.HasValue)
66+
{
5767
timeSpan = globalHubOptions.Value.ClientTimeoutInterval.Value;
68+
}
5869

5970
if (hubOptions.Value.ClientTimeoutInterval.HasValue)
71+
{
6072
timeSpan = hubOptions.Value.ClientTimeoutInterval.Value;
73+
}
6174

6275
return timeSpan;
6376
}
64-
77+
6578
public static TimeSpan AddExpirationIntervalBuffer(TimeSpan timeSpan)
6679
{
6780
return timeSpan * 1.2;
6881
}
69-
}
82+
}

ManagedCode.Orleans.SignalR.Core/HubContext/IOrleansHubContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ public interface IOrleansHubContext<THub, TClient> where THub : Hub
1616
/// Gets a <see cref="IGroupManager" /> that can be used to add and remove connections to named groups.
1717
/// </summary>
1818
IGroupManager Groups { get; }
19-
}
19+
}

ManagedCode.Orleans.SignalR.Core/HubContext/OrleansHubClients.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ public T Users(IReadOnlyList<string> userIds)
4646
{
4747
return TypedClientBuilder<T>.Build(hubClients.Users(userIds));
4848
}
49-
}
49+
}

ManagedCode.Orleans.SignalR.Core/HubContext/OrleansHubContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ public class OrleansHubContext<THub, TClient>(IHubContext<THub> context) : IOrle
1616
/// Gets a <see cref="IGroupManager" /> that can be used to add and remove connections to named groups.
1717
/// </summary>
1818
public IGroupManager Groups { get; } = context.Groups;
19-
}
19+
}

0 commit comments

Comments
 (0)