This repository was archived by the owner on Dec 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 447
AllExcept for Groups - GroupExcept #1204
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,25 @@ public Task InvokeAsync(string method, params object[] args) | |
| } | ||
| } | ||
|
|
||
| public class GroupExceptProxy<THub> : IClientProxy | ||
| { | ||
| private readonly string _groupName; | ||
| private readonly HubLifetimeManager<THub> _lifetimeManager; | ||
| private IReadOnlyList<string> _excludedIds; | ||
|
||
|
|
||
| public GroupExceptProxy(HubLifetimeManager<THub> lifetimeManager, string groupName, IReadOnlyList<string> excludedIds) | ||
| { | ||
| _lifetimeManager = lifetimeManager; | ||
| _groupName = groupName; | ||
| _excludedIds = excludedIds; | ||
| } | ||
|
|
||
| public Task InvokeAsync(string method, params object[] args) | ||
| { | ||
| return _lifetimeManager.InvokeGroupExceptAsync(_groupName, method, args, _excludedIds); | ||
| } | ||
| } | ||
|
|
||
| public class AllClientProxy<THub> : IClientProxy | ||
| { | ||
| private readonly HubLifetimeManager<THub> _lifetimeManager; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -190,7 +190,19 @@ public override Task InvokeGroupAsync(string groupName, string methodName, objec | |
| throw new ArgumentNullException(nameof(groupName)); | ||
| } | ||
|
|
||
| var message = new InvocationMessage(GetInvocationId(), nonBlocking: true, target: methodName, argumentBindingException: null, arguments: args); | ||
| var message = new RedisExcludeClientsMessage(GetInvocationId(), nonBlocking: true, target: methodName, excludedIds: null, arguments: args); | ||
|
|
||
| return PublishAsync(_channelNamePrefix + ".group." + groupName, message); | ||
| } | ||
|
|
||
| public override Task InvokeGroupExceptAsync(string groupName, string methodName, object[] args, IReadOnlyList<string> excludedIds) | ||
| { | ||
| if (groupName == null) | ||
| { | ||
| throw new ArgumentNullException(nameof(groupName)); | ||
| } | ||
|
|
||
| var message = new RedisExcludeClientsMessage(GetInvocationId(), nonBlocking: true, target: methodName, excludedIds: excludedIds, arguments: args); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this. It uses an existing message and we just publish it to a different Redis key. 👍 |
||
|
|
||
| return PublishAsync(_channelNamePrefix + ".group." + groupName, message); | ||
| } | ||
|
|
@@ -547,11 +559,16 @@ private Task SubscribeToGroup(string groupChannel, GroupData group) | |
| { | ||
| try | ||
| { | ||
| var message = DeserializeMessage<HubInvocationMessage>(data); | ||
| var message = DeserializeMessage<RedisExcludeClientsMessage>(data); | ||
|
|
||
| var tasks = new List<Task>(group.Connections.Count); | ||
| var tasks = new List<Task>(); | ||
| foreach (var groupConnection in group.Connections) | ||
| { | ||
| if (message.ExcludedIds?.Contains(groupConnection.ConnectionId) == true) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| tasks.Add(groupConnection.WriteAsync(message)); | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Threading; | ||
| using System.Threading.Channels; | ||
| using System.Threading.Tasks; | ||
|
|
@@ -102,6 +103,37 @@ public async Task InvokeGroupAsyncWritesToAllConnectionsInGroupOutput() | |
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task InvokeGroupExceptAsyncWritesToAllValidConnectionsInGroupOutput() | ||
| { | ||
| using (var client1 = new TestClient()) | ||
| using (var client2 = new TestClient()) | ||
| { | ||
| var manager = new RedisHubLifetimeManager<MyHub>(new LoggerFactory().CreateLogger<RedisHubLifetimeManager<MyHub>>(), | ||
| Options.Create(new RedisOptions() | ||
| { | ||
| Factory = t => new TestConnectionMultiplexer() | ||
| })); | ||
| var connection1 = HubConnectionContextUtils.Create(client1.Connection); | ||
| var connection2 = HubConnectionContextUtils.Create(client2.Connection); | ||
|
|
||
| await manager.OnConnectedAsync(connection1).OrTimeout(); | ||
| await manager.OnConnectedAsync(connection2).OrTimeout(); | ||
|
|
||
| await manager.AddGroupAsync(connection1.ConnectionId, "gunit").OrTimeout(); | ||
| await manager.AddGroupAsync(connection2.ConnectionId, "gunit").OrTimeout(); | ||
|
|
||
| var excludedIds = new List<string>{client2.Connection.ConnectionId }; | ||
|
||
| await manager.InvokeGroupExceptAsync("gunit", "Hello", new object[] { "World" }, excludedIds).OrTimeout(); | ||
|
|
||
| await AssertMessageAsync(client1); | ||
|
|
||
| await connection1.DisposeAsync().OrTimeout(); | ||
| await connection2.DisposeAsync().OrTimeout(); | ||
| Assert.Null(client2.TryRead()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do this before disposing |
||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task InvokeConnectionAsyncWritesToConnectionOutput() | ||
| { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a reasonable place to add logging or should we first finalize our logging strategy? @BrennanConroy @anurse