-
-
Notifications
You must be signed in to change notification settings - Fork 337
[1/N] dynamic listeners — foundation only (GH-2685) #2699
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
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
55 changes: 55 additions & 0 deletions
55
src/Testing/CoreTests/Persistence/Durability/DynamicListenersDefaultsTests.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,55 @@ | ||
| using Shouldly; | ||
| using Wolverine.Persistence.Durability; | ||
| using Xunit; | ||
|
|
||
| namespace CoreTests.Persistence.Durability; | ||
|
|
||
| /// <summary> | ||
| /// Lock down the upgrade-safety contract for the new dynamic-listener registry: | ||
| /// the opt-in flag defaults to <c>false</c>, the default | ||
| /// <c>IMessageStore.Listeners</c> is the no-op store, and existing apps that | ||
| /// bump Wolverine without touching options pay nothing — no schema migration, | ||
| /// no behavioural change, no agent family registration. | ||
| /// </summary> | ||
| public class DynamicListenersDefaultsTests | ||
| { | ||
| [Fact] | ||
| public void enable_dynamic_listeners_defaults_to_false_on_a_fresh_durability_settings() | ||
| { | ||
| // Direct construction (no host bootstrap) — guards against a future | ||
| // ctor or property-initializer regression flipping the default. | ||
| new DurabilitySettings().EnableDynamicListeners.ShouldBeFalse(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void enable_dynamic_listeners_defaults_to_false_on_wolverine_options() | ||
| { | ||
| // Whole-options walk — covers any indirect mutation that | ||
| // WolverineOptions' constructor could introduce on Durability. | ||
| new WolverineOptions().Durability.EnableDynamicListeners.ShouldBeFalse(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void null_listener_store_register_is_a_no_op() | ||
| { | ||
| // The default store every IMessageStore.Listeners points at when the | ||
| // flag is off. Locks down the no-op contract: no exception, no state. | ||
| var store = NullListenerStore.Instance; | ||
|
|
||
| store.RegisterListenerAsync(new Uri("mqtt://topic/devices/abc")) | ||
| .GetAwaiter().GetResult(); // sync drain — no-op should be sync-completed | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task null_listener_store_returns_empty_listing() | ||
| { | ||
| var listeners = await NullListenerStore.Instance.AllListenersAsync(); | ||
| listeners.ShouldBeEmpty(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task null_listener_store_remove_is_a_no_op() | ||
| { | ||
| await NullListenerStore.Instance.RemoveListenerAsync(new Uri("mqtt://topic/whatever")); | ||
| } | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| namespace Wolverine.Persistence.Durability; | ||
|
|
||
| /// <summary> | ||
| /// Persistence contract for the dynamic-listener registry. Stores the set of | ||
| /// listener URIs Wolverine should activate at runtime in addition to the | ||
| /// listeners declared statically through <c>WolverineOptions</c>. The registry | ||
| /// is opt-in via <see cref="DurabilitySettings.EnableDynamicListeners"/> — when | ||
| /// disabled, providers must NOT create the backing storage so that users | ||
| /// upgrading Wolverine see no schema migration churn. | ||
| /// | ||
| /// The store is transport-agnostic: each entry is a single <see cref="Uri"/>. | ||
| /// The pluggable <c>DynamicListenerAgentFamily</c> turns each persisted URI | ||
| /// into a runtime listener via the appropriate transport. | ||
| /// </summary> | ||
| public interface IListenerStore | ||
| { | ||
| /// <summary> | ||
| /// Persist <paramref name="uri"/> as a registered listener. Idempotent — a | ||
| /// repeat registration of the same URI is a no-op rather than an error. | ||
| /// </summary> | ||
| Task RegisterListenerAsync(Uri uri, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Remove <paramref name="uri"/> from the registry. Idempotent — removing a | ||
| /// URI that isn't registered is a no-op rather than an error. | ||
| /// </summary> | ||
| Task RemoveListenerAsync(Uri uri, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Snapshot of every currently-registered listener URI. The order is | ||
| /// implementation-defined; callers that need a deterministic ordering should | ||
| /// sort the result themselves. | ||
| /// </summary> | ||
| Task<IReadOnlyList<Uri>> AllListenersAsync(CancellationToken cancellationToken = default); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Default no-op listener store. Returned by <see cref="IMessageStore.Listeners"/> | ||
| /// when dynamic listeners are disabled (<see cref="DurabilitySettings.EnableDynamicListeners"/> | ||
| /// is <c>false</c>) or when the message store has no durable backing (e.g. <c>NullMessageStore</c> | ||
| /// in solo-mode-without-DB scenarios). All operations are no-ops or return empty. | ||
| /// </summary> | ||
| public sealed class NullListenerStore : IListenerStore | ||
| { | ||
| public static NullListenerStore Instance { get; } = new(); | ||
|
|
||
| public Task RegisterListenerAsync(Uri uri, CancellationToken cancellationToken = default) | ||
| => Task.CompletedTask; | ||
|
|
||
| public Task RemoveListenerAsync(Uri uri, CancellationToken cancellationToken = default) | ||
| => Task.CompletedTask; | ||
|
|
||
| public Task<IReadOnlyList<Uri>> AllListenersAsync(CancellationToken cancellationToken = default) | ||
| => Task.FromResult<IReadOnlyList<Uri>>(Array.Empty<Uri>()); | ||
| } |
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.
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.
Understood, that is OK for our situation.
We would then associate the listener data with a tenant as the device will belong to a tenant, but that can happen outside of this process.