Skip to content

Commit 0fd529d

Browse files
committed
Add support for transport mode validation and update durable mode enforcement
1 parent 8af80f2 commit 0fd529d

File tree

4 files changed

+59
-3
lines changed

4 files changed

+59
-3
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Shouldly;
2+
using Wolverine.Configuration;
3+
using Wolverine.SignalR.Internals;
4+
5+
namespace Wolverine.SignalR.Tests.Internals;
6+
7+
public class SignalRTransportModeTests
8+
{
9+
private readonly SignalRTransport _transport = new();
10+
11+
[Fact]
12+
public void does_not_support_durable_mode()
13+
{
14+
_transport.SupportsMode(EndpointMode.Durable).ShouldBeFalse();
15+
}
16+
17+
[Fact]
18+
public void supports_inline_mode()
19+
{
20+
_transport.SupportsMode(EndpointMode.Inline).ShouldBeTrue();
21+
}
22+
23+
[Fact]
24+
public void supports_buffered_in_memory_mode()
25+
{
26+
_transport.SupportsMode(EndpointMode.BufferedInMemory).ShouldBeTrue();
27+
}
28+
29+
[Fact]
30+
public void setting_durable_mode_throws_exception()
31+
{
32+
Should.Throw<InvalidOperationException>(() => _transport.Mode = EndpointMode.Durable);
33+
}
34+
}

src/Wolverine/Configuration/Endpoint.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,15 @@ protected virtual bool supportsMode(EndpointMode mode)
442442
{
443443
return true;
444444
}
445-
445+
446+
/// <summary>
447+
/// Check if this endpoint supports the specified mode
448+
/// </summary>
449+
public bool SupportsMode(EndpointMode mode)
450+
{
451+
return supportsMode(mode);
452+
}
453+
446454
// Is this endpoint part of a sharded messaging topology?
447455
// If so, this should be "auto-started"
448456
internal bool UsedInShardedTopology { get; set; }

src/Wolverine/Configuration/ISubscriberConfiguration.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ public interface ISubscriberConfiguration<T> : IEndpointConfiguration<T> where T
7070
/// </summary>
7171
/// <returns></returns>
7272
public T GlobalSender();
73+
74+
public Endpoint Endpoint { get; }
7375
}
7476

7577
public interface ISubscriberConfiguration : ISubscriberConfiguration<ISubscriberConfiguration>;

src/Wolverine/WolverineOptions.Policies.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@ void IPolicies.Add(IWolverinePolicy policy)
7272

7373
void IPolicies.UseDurableInboxOnAllListeners()
7474
{
75-
this.As<IPolicies>().AllListeners(x => x.UseDurableInbox());
75+
this.As<IPolicies>().AllListeners(x =>
76+
{
77+
if (x.Endpoint.SupportsMode(EndpointMode.Durable))
78+
{
79+
x.UseDurableInbox();
80+
}
81+
});
7682
}
7783

7884
internal readonly List<IHandledTypeRule> HandledTypeRules = [new AgentCommandHandledTypeRule()];
@@ -94,7 +100,13 @@ void IPolicies.UseDurableLocalQueues()
94100

95101
void IPolicies.UseDurableOutboxOnAllSendingEndpoints()
96102
{
97-
this.As<IPolicies>().AllSenders(x => x.UseDurableOutbox());
103+
this.As<IPolicies>().AllSenders(x =>
104+
{
105+
if (x.Endpoint.SupportsMode(EndpointMode.Durable))
106+
{
107+
x.UseDurableOutbox();
108+
}
109+
});
98110
}
99111

100112
void IPolicies.AllListeners(Action<ListenerConfiguration> configure)

0 commit comments

Comments
 (0)