-
Notifications
You must be signed in to change notification settings - Fork 3
feat(cqrs): 补齐流式管道行为接缝 #339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 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
13 changes: 13 additions & 0 deletions
13
GFramework.Core.Tests/Architectures/ModuleStreamBehaviorRequest.cs
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 |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // Copyright (c) 2025-2026 GeWuYou | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| using GFramework.Cqrs.Abstractions.Cqrs; | ||
|
|
||
| namespace GFramework.Core.Tests.Architectures; | ||
|
|
||
| /// <summary> | ||
| /// 用于验证架构公开 stream pipeline 行为注册入口的最小流式请求。 | ||
| /// </summary> | ||
| public sealed class ModuleStreamBehaviorRequest : IStreamRequest<int> | ||
| { | ||
| } |
28 changes: 28 additions & 0 deletions
28
GFramework.Core.Tests/Architectures/ModuleStreamBehaviorRequestHandler.cs
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 |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // Copyright (c) 2025-2026 GeWuYou | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Runtime.CompilerServices; | ||
| using GFramework.Cqrs.Abstractions.Cqrs; | ||
|
|
||
| namespace GFramework.Core.Tests.Architectures; | ||
|
|
||
| /// <summary> | ||
| /// 处理 <see cref="ModuleStreamBehaviorRequest" /> 并返回一个固定元素。 | ||
| /// </summary> | ||
| public sealed class ModuleStreamBehaviorRequestHandler : IStreamRequestHandler<ModuleStreamBehaviorRequest, int> | ||
| { | ||
| /// <summary> | ||
| /// 返回一个固定元素,供架构 stream pipeline 行为回归断言使用。 | ||
| /// </summary> | ||
| /// <param name="request">当前流式请求。</param> | ||
| /// <param name="cancellationToken">取消令牌。</param> | ||
| /// <returns>包含一个固定元素的异步流。</returns> | ||
| public async IAsyncEnumerable<int> Handle( | ||
| ModuleStreamBehaviorRequest request, | ||
| [EnumeratorCancellation] CancellationToken cancellationToken) | ||
| { | ||
| yield return 7; | ||
| await ValueTask.CompletedTask.ConfigureAwait(false); | ||
| } | ||
| } |
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
44 changes: 44 additions & 0 deletions
44
GFramework.Core.Tests/Architectures/TrackingStreamPipelineBehavior.cs
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 |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Copyright (c) 2025-2026 GeWuYou | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| using System.Threading; | ||
| using GFramework.Cqrs.Abstractions.Cqrs; | ||
|
|
||
| namespace GFramework.Core.Tests.Architectures; | ||
|
|
||
| /// <summary> | ||
| /// 记录流式请求通过管道次数的测试行为。 | ||
| /// </summary> | ||
| /// <typeparam name="TRequest">流式请求类型。</typeparam> | ||
| /// <typeparam name="TResponse">流式响应元素类型。</typeparam> | ||
| public sealed class TrackingStreamPipelineBehavior<TRequest, TResponse> : IStreamPipelineBehavior<TRequest, TResponse> | ||
| where TRequest : IStreamRequest<TResponse> | ||
| { | ||
| private static int _invocationCount; | ||
|
|
||
| /// <summary> | ||
| /// 获取当前测试进程中该流式请求类型对应的行为触发次数。 | ||
| /// 该计数器是按泛型闭包共享的静态状态,测试需要在每次运行前显式重置。 | ||
| /// </summary> | ||
| public static int InvocationCount | ||
| { | ||
| get => Volatile.Read(ref _invocationCount); | ||
| set => Volatile.Write(ref _invocationCount, value); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// 以线程安全方式记录一次行为执行,然后继续执行下一个处理阶段。 | ||
| /// </summary> | ||
| /// <param name="message">当前流式请求消息。</param> | ||
| /// <param name="next">下一个处理阶段。</param> | ||
| /// <param name="cancellationToken">取消令牌。</param> | ||
| /// <returns>下游处理阶段返回的异步流。</returns> | ||
| public IAsyncEnumerable<TResponse> Handle( | ||
| TRequest message, | ||
| StreamMessageHandlerDelegate<TRequest, TResponse> next, | ||
| CancellationToken cancellationToken) | ||
| { | ||
| Interlocked.Increment(ref _invocationCount); | ||
| return next(message, cancellationToken); | ||
| } | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.