Skip to content

Commit 6a6b93e

Browse files
committed
Added multi-router tests
1 parent 3859dd0 commit 6a6b93e

8 files changed

+950
-1
lines changed

src/NServiceBus.Router.AcceptanceTests/Infrastructure/BrokerSettings.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ public void Charlie()
3131
{
3232
SetStoragePath("Charlie");
3333
}
34-
34+
35+
public void Delta()
36+
{
37+
SetStoragePath("Delta");
38+
}
39+
3540
public void Yankee()
3641
{
3742
SetStoragePath("Yankee");
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
using System.Threading.Tasks;
2+
using NServiceBus.AcceptanceTesting;
3+
using NUnit.Framework;
4+
5+
namespace NServiceBus.Router.AcceptanceTests.MultipleRouters
6+
{
7+
using AcceptanceTesting.Customization;
8+
9+
[TestFixture]
10+
public class When_connecting_to_two_routers : NServiceBusAcceptanceTest
11+
{
12+
[Test]
13+
public async Task Should_deliver_the_messages_to_destination_endpoints()
14+
{
15+
var result = await Scenario.Define<Context>()
16+
.WithRouter("RouterA", cfg =>
17+
{
18+
cfg.AddInterface("Left", false).Broker().Charlie();
19+
cfg.AddInterface("Right", false).Broker().Alpha();
20+
21+
cfg.UseStaticRoutingProtocol().AddForwardRoute("Left", "Right");
22+
})
23+
.WithRouter("RouterB", cfg =>
24+
{
25+
cfg.AddInterface("Left", false).Broker().Charlie();
26+
cfg.AddInterface("Right", false).Broker().Bravo();
27+
28+
cfg.UseStaticRoutingProtocol().AddForwardRoute("Left", "Right");
29+
})
30+
.WithEndpoint<Sender>(c => c.When(async s =>
31+
{
32+
await s.Send(new MyRequestA());
33+
await s.Send(new MyRequestB());
34+
}))
35+
.WithEndpoint<ReceiverA>()
36+
.WithEndpoint<ReceiverB>()
37+
.Done(c => c.ReceivedByB && c.ReceivedByA)
38+
.Run();
39+
40+
Assert.IsTrue(result.ReceivedByB);
41+
Assert.IsTrue(result.ReceivedByA);
42+
}
43+
44+
class Context : ScenarioContext
45+
{
46+
public bool ReceivedByA { get; set; }
47+
public bool ReceivedByB { get; set; }
48+
}
49+
50+
class Sender : EndpointConfigurationBuilder
51+
{
52+
public Sender()
53+
{
54+
EndpointSetup<DefaultServer>(c =>
55+
{
56+
c.ConfigureBroker().Charlie();
57+
var routing = c.ConfigureRouting();
58+
59+
var routerA = routing.ConnectToRouter("RouterA");
60+
routerA.RouteToEndpoint(typeof(MyRequestA), Conventions.EndpointNamingConvention(typeof(ReceiverA)));
61+
62+
var routerB = routing.ConnectToRouter("RouterB");
63+
routerB.RouteToEndpoint(typeof(MyRequestB), Conventions.EndpointNamingConvention(typeof(ReceiverB)));
64+
});
65+
}
66+
}
67+
68+
class ReceiverA : EndpointConfigurationBuilder
69+
{
70+
public ReceiverA()
71+
{
72+
EndpointSetup<DefaultServer>(c =>
73+
{
74+
//No bridge configuration needed for reply
75+
c.ConfigureBroker().Alpha();
76+
});
77+
}
78+
79+
class MyRequestHandler : IHandleMessages<MyRequestA>
80+
{
81+
Context scenarioContext;
82+
83+
public MyRequestHandler(Context scenarioContext)
84+
{
85+
this.scenarioContext = scenarioContext;
86+
}
87+
88+
public Task Handle(MyRequestA requestA, IMessageHandlerContext context)
89+
{
90+
scenarioContext.ReceivedByA = true;
91+
return Task.CompletedTask;
92+
}
93+
}
94+
}
95+
96+
class ReceiverB : EndpointConfigurationBuilder
97+
{
98+
public ReceiverB()
99+
{
100+
EndpointSetup<DefaultServer>(c =>
101+
{
102+
//No bridge configuration needed for reply
103+
c.ConfigureBroker().Bravo();
104+
});
105+
}
106+
107+
class MyRequestHandler : IHandleMessages<MyRequestB>
108+
{
109+
Context scenarioContext;
110+
111+
public MyRequestHandler(Context scenarioContext)
112+
{
113+
this.scenarioContext = scenarioContext;
114+
}
115+
116+
public Task Handle(MyRequestB requestB, IMessageHandlerContext context)
117+
{
118+
scenarioContext.ReceivedByB = true;
119+
return Task.CompletedTask;
120+
}
121+
}
122+
}
123+
124+
class MyRequestA : IMessage
125+
{
126+
}
127+
128+
class MyRequestB : IMessage
129+
{
130+
}
131+
}
132+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using System.Threading.Tasks;
2+
using NServiceBus.AcceptanceTesting;
3+
using NUnit.Framework;
4+
5+
namespace NServiceBus.Router.AcceptanceTests.MultipleRouters
6+
{
7+
using AcceptanceTesting.Customization;
8+
9+
[TestFixture]
10+
public class When_publishing_via_double_unicast_bridge : NServiceBusAcceptanceTest
11+
{
12+
[Test]
13+
public async Task It_should_deliver_the_message()
14+
{
15+
var result = await Scenario.Define<Context>()
16+
.WithRouter("Green-Blue", cfg =>
17+
{
18+
cfg.AddInterface("Green", false).Broker().Alpha();
19+
cfg.AddInterface("Blue", false).Broker().Bravo();
20+
21+
cfg.UseStaticRoutingProtocol().AddForwardRoute("Blue", "Green");
22+
})
23+
.WithRouter("Blue-Red", cfg =>
24+
{
25+
cfg.AddInterface("Blue", false).Broker().Bravo();
26+
cfg.AddInterface("Red", false).Broker().Charlie();
27+
28+
cfg.UseStaticRoutingProtocol().AddForwardRoute("Red", "Blue", "Green-Blue");
29+
})
30+
.WithEndpoint<Publisher>(c => c.When(x => x.EventSubscribed, s => s.Publish(new MyEvent())))
31+
.WithEndpoint<Subscriber>()
32+
.Done(c => c.EventDelivered)
33+
.Run();
34+
35+
Assert.IsTrue(result.EventDelivered);
36+
}
37+
38+
class Context : ScenarioContext
39+
{
40+
public bool EventDelivered { get; set; }
41+
public bool EventSubscribed { get; set; }
42+
}
43+
44+
class Publisher : EndpointConfigurationBuilder
45+
{
46+
public Publisher()
47+
{
48+
EndpointSetup<DefaultServer>(c =>
49+
{
50+
//No bridge configuration needed for publisher
51+
c.ConfigureBroker().Alpha();
52+
53+
c.ConfigureRouting().EnableMessageDrivenPubSubCompatibilityMode();
54+
55+
c.OnEndpointSubscribed<Context>((args, context) =>
56+
{
57+
context.EventSubscribed = true;
58+
});
59+
});
60+
}
61+
}
62+
63+
class Subscriber : EndpointConfigurationBuilder
64+
{
65+
public Subscriber()
66+
{
67+
EndpointSetup<DefaultServer>(c =>
68+
{
69+
c.ConfigureBroker().Charlie();
70+
71+
var routing = c.ConfigureRouting();
72+
var ramp = routing.ConnectToRouter("Blue-Red");
73+
ramp.RegisterPublisher(typeof(MyEvent), Conventions.EndpointNamingConvention(typeof(Publisher)));
74+
});
75+
}
76+
77+
class MyEventHandler : IHandleMessages<MyEvent>
78+
{
79+
Context scenarioContext;
80+
81+
public MyEventHandler(Context scenarioContext)
82+
{
83+
this.scenarioContext = scenarioContext;
84+
}
85+
86+
public Task Handle(MyEvent message, IMessageHandlerContext context)
87+
{
88+
scenarioContext.EventDelivered = true;
89+
return Task.CompletedTask;
90+
}
91+
}
92+
}
93+
94+
class MyEvent : IEvent
95+
{
96+
}
97+
}
98+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using System.Threading.Tasks;
2+
using NServiceBus.AcceptanceTesting;
3+
using NUnit.Framework;
4+
5+
namespace NServiceBus.Router.AcceptanceTests.MultipleRouters
6+
{
7+
using AcceptanceTesting.Customization;
8+
9+
[TestFixture]
10+
public class When_publishing_via_double_unicast_multicast_bridge : NServiceBusAcceptanceTest
11+
{
12+
[Test]
13+
public async Task It_should_deliver_the_message()
14+
{
15+
var result = await Scenario.Define<Context>()
16+
.WithRouter("Green-Blue", cfg =>
17+
{
18+
cfg.AddInterface("Green", false).Broker().Alpha();
19+
cfg.AddInterface("Blue", false).Broker().Bravo();
20+
21+
cfg.UseStaticRoutingProtocol().AddForwardRoute("Blue", "Green");
22+
})
23+
.WithRouter("Blue-Red", cfg =>
24+
{
25+
cfg.AddInterface("Blue", false).Broker().Bravo();
26+
cfg.AddInterface("Red", false).Broker().Charlie();
27+
28+
cfg.UseStaticRoutingProtocol().AddForwardRoute("Red", "Blue", "Green-Blue");
29+
})
30+
.WithEndpoint<Publisher>(c => c.When(x => x.EventSubscribed, s => s.Publish(new MyEvent())))
31+
.WithEndpoint<Subscriber>()
32+
.Done(c => c.EventDelivered)
33+
.Run();
34+
35+
Assert.IsTrue(result.EventDelivered);
36+
}
37+
38+
class Context : ScenarioContext
39+
{
40+
public bool EventDelivered { get; set; }
41+
public bool EventSubscribed { get; set; }
42+
}
43+
44+
class Publisher : EndpointConfigurationBuilder
45+
{
46+
public Publisher()
47+
{
48+
EndpointSetup<DefaultServer>(c =>
49+
{
50+
//No bridge configuration needed for publisher
51+
c.ConfigureBroker().Alpha();
52+
53+
c.ConfigureRouting().EnableMessageDrivenPubSubCompatibilityMode();
54+
55+
c.OnEndpointSubscribed<Context>((args, context) =>
56+
{
57+
context.EventSubscribed = true;
58+
});
59+
});
60+
}
61+
}
62+
63+
class Subscriber : EndpointConfigurationBuilder
64+
{
65+
public Subscriber()
66+
{
67+
EndpointSetup<DefaultServer>(c =>
68+
{
69+
c.ConfigureBroker().Charlie();
70+
71+
var routing = c.ConfigureRouting();
72+
var bridge = routing.ConnectToRouter("Blue-Red");
73+
bridge.RegisterPublisher(typeof(MyEvent), Conventions.EndpointNamingConvention(typeof(Publisher)));
74+
});
75+
}
76+
77+
class MyEventHandler : IHandleMessages<MyEvent>
78+
{
79+
Context scenarioContext;
80+
81+
public MyEventHandler(Context scenarioContext)
82+
{
83+
this.scenarioContext = scenarioContext;
84+
}
85+
86+
public Task Handle(MyEvent message, IMessageHandlerContext context)
87+
{
88+
scenarioContext.EventDelivered = true;
89+
return Task.CompletedTask;
90+
}
91+
}
92+
}
93+
94+
class MyEvent : IEvent
95+
{
96+
}
97+
}
98+
}

0 commit comments

Comments
 (0)