-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3859dd0
commit 6a6b93e
Showing
8 changed files
with
950 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
132 changes: 132 additions & 0 deletions
132
src/NServiceBus.Router.AcceptanceTests/MultipleRouters/When_connecting_to_two_routers.cs
This file contains 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,132 @@ | ||
using System.Threading.Tasks; | ||
using NServiceBus.AcceptanceTesting; | ||
using NUnit.Framework; | ||
|
||
namespace NServiceBus.Router.AcceptanceTests.MultipleRouters | ||
{ | ||
using AcceptanceTesting.Customization; | ||
|
||
[TestFixture] | ||
public class When_connecting_to_two_routers : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public async Task Should_deliver_the_messages_to_destination_endpoints() | ||
{ | ||
var result = await Scenario.Define<Context>() | ||
.WithRouter("RouterA", cfg => | ||
{ | ||
cfg.AddInterface("Left", false).Broker().Charlie(); | ||
cfg.AddInterface("Right", false).Broker().Alpha(); | ||
|
||
cfg.UseStaticRoutingProtocol().AddForwardRoute("Left", "Right"); | ||
}) | ||
.WithRouter("RouterB", cfg => | ||
{ | ||
cfg.AddInterface("Left", false).Broker().Charlie(); | ||
cfg.AddInterface("Right", false).Broker().Bravo(); | ||
|
||
cfg.UseStaticRoutingProtocol().AddForwardRoute("Left", "Right"); | ||
}) | ||
.WithEndpoint<Sender>(c => c.When(async s => | ||
{ | ||
await s.Send(new MyRequestA()); | ||
await s.Send(new MyRequestB()); | ||
})) | ||
.WithEndpoint<ReceiverA>() | ||
.WithEndpoint<ReceiverB>() | ||
.Done(c => c.ReceivedByB && c.ReceivedByA) | ||
.Run(); | ||
|
||
Assert.IsTrue(result.ReceivedByB); | ||
Assert.IsTrue(result.ReceivedByA); | ||
} | ||
|
||
class Context : ScenarioContext | ||
{ | ||
public bool ReceivedByA { get; set; } | ||
public bool ReceivedByB { get; set; } | ||
} | ||
|
||
class Sender : EndpointConfigurationBuilder | ||
{ | ||
public Sender() | ||
{ | ||
EndpointSetup<DefaultServer>(c => | ||
{ | ||
c.ConfigureBroker().Charlie(); | ||
var routing = c.ConfigureRouting(); | ||
|
||
var routerA = routing.ConnectToRouter("RouterA"); | ||
routerA.RouteToEndpoint(typeof(MyRequestA), Conventions.EndpointNamingConvention(typeof(ReceiverA))); | ||
|
||
var routerB = routing.ConnectToRouter("RouterB"); | ||
routerB.RouteToEndpoint(typeof(MyRequestB), Conventions.EndpointNamingConvention(typeof(ReceiverB))); | ||
}); | ||
} | ||
} | ||
|
||
class ReceiverA : EndpointConfigurationBuilder | ||
{ | ||
public ReceiverA() | ||
{ | ||
EndpointSetup<DefaultServer>(c => | ||
{ | ||
//No bridge configuration needed for reply | ||
c.ConfigureBroker().Alpha(); | ||
}); | ||
} | ||
|
||
class MyRequestHandler : IHandleMessages<MyRequestA> | ||
{ | ||
Context scenarioContext; | ||
|
||
public MyRequestHandler(Context scenarioContext) | ||
{ | ||
this.scenarioContext = scenarioContext; | ||
} | ||
|
||
public Task Handle(MyRequestA requestA, IMessageHandlerContext context) | ||
{ | ||
scenarioContext.ReceivedByA = true; | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} | ||
|
||
class ReceiverB : EndpointConfigurationBuilder | ||
{ | ||
public ReceiverB() | ||
{ | ||
EndpointSetup<DefaultServer>(c => | ||
{ | ||
//No bridge configuration needed for reply | ||
c.ConfigureBroker().Bravo(); | ||
}); | ||
} | ||
|
||
class MyRequestHandler : IHandleMessages<MyRequestB> | ||
{ | ||
Context scenarioContext; | ||
|
||
public MyRequestHandler(Context scenarioContext) | ||
{ | ||
this.scenarioContext = scenarioContext; | ||
} | ||
|
||
public Task Handle(MyRequestB requestB, IMessageHandlerContext context) | ||
{ | ||
scenarioContext.ReceivedByB = true; | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} | ||
|
||
class MyRequestA : IMessage | ||
{ | ||
} | ||
|
||
class MyRequestB : IMessage | ||
{ | ||
} | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
...ceBus.Router.AcceptanceTests/MultipleRouters/When_publishing_via_double_unicast_bridge.cs
This file contains 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,98 @@ | ||
using System.Threading.Tasks; | ||
using NServiceBus.AcceptanceTesting; | ||
using NUnit.Framework; | ||
|
||
namespace NServiceBus.Router.AcceptanceTests.MultipleRouters | ||
{ | ||
using AcceptanceTesting.Customization; | ||
|
||
[TestFixture] | ||
public class When_publishing_via_double_unicast_bridge : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public async Task It_should_deliver_the_message() | ||
{ | ||
var result = await Scenario.Define<Context>() | ||
.WithRouter("Green-Blue", cfg => | ||
{ | ||
cfg.AddInterface("Green", false).Broker().Alpha(); | ||
cfg.AddInterface("Blue", false).Broker().Bravo(); | ||
|
||
cfg.UseStaticRoutingProtocol().AddForwardRoute("Blue", "Green"); | ||
}) | ||
.WithRouter("Blue-Red", cfg => | ||
{ | ||
cfg.AddInterface("Blue", false).Broker().Bravo(); | ||
cfg.AddInterface("Red", false).Broker().Charlie(); | ||
|
||
cfg.UseStaticRoutingProtocol().AddForwardRoute("Red", "Blue", "Green-Blue"); | ||
}) | ||
.WithEndpoint<Publisher>(c => c.When(x => x.EventSubscribed, s => s.Publish(new MyEvent()))) | ||
.WithEndpoint<Subscriber>() | ||
.Done(c => c.EventDelivered) | ||
.Run(); | ||
|
||
Assert.IsTrue(result.EventDelivered); | ||
} | ||
|
||
class Context : ScenarioContext | ||
{ | ||
public bool EventDelivered { get; set; } | ||
public bool EventSubscribed { get; set; } | ||
} | ||
|
||
class Publisher : EndpointConfigurationBuilder | ||
{ | ||
public Publisher() | ||
{ | ||
EndpointSetup<DefaultServer>(c => | ||
{ | ||
//No bridge configuration needed for publisher | ||
c.ConfigureBroker().Alpha(); | ||
|
||
c.ConfigureRouting().EnableMessageDrivenPubSubCompatibilityMode(); | ||
|
||
c.OnEndpointSubscribed<Context>((args, context) => | ||
{ | ||
context.EventSubscribed = true; | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
class Subscriber : EndpointConfigurationBuilder | ||
{ | ||
public Subscriber() | ||
{ | ||
EndpointSetup<DefaultServer>(c => | ||
{ | ||
c.ConfigureBroker().Charlie(); | ||
|
||
var routing = c.ConfigureRouting(); | ||
var ramp = routing.ConnectToRouter("Blue-Red"); | ||
ramp.RegisterPublisher(typeof(MyEvent), Conventions.EndpointNamingConvention(typeof(Publisher))); | ||
}); | ||
} | ||
|
||
class MyEventHandler : IHandleMessages<MyEvent> | ||
{ | ||
Context scenarioContext; | ||
|
||
public MyEventHandler(Context scenarioContext) | ||
{ | ||
this.scenarioContext = scenarioContext; | ||
} | ||
|
||
public Task Handle(MyEvent message, IMessageHandlerContext context) | ||
{ | ||
scenarioContext.EventDelivered = true; | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} | ||
|
||
class MyEvent : IEvent | ||
{ | ||
} | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
...er.AcceptanceTests/MultipleRouters/When_publishing_via_double_unicast_multicast_bridge.cs
This file contains 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,98 @@ | ||
using System.Threading.Tasks; | ||
using NServiceBus.AcceptanceTesting; | ||
using NUnit.Framework; | ||
|
||
namespace NServiceBus.Router.AcceptanceTests.MultipleRouters | ||
{ | ||
using AcceptanceTesting.Customization; | ||
|
||
[TestFixture] | ||
public class When_publishing_via_double_unicast_multicast_bridge : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public async Task It_should_deliver_the_message() | ||
{ | ||
var result = await Scenario.Define<Context>() | ||
.WithRouter("Green-Blue", cfg => | ||
{ | ||
cfg.AddInterface("Green", false).Broker().Alpha(); | ||
cfg.AddInterface("Blue", false).Broker().Bravo(); | ||
|
||
cfg.UseStaticRoutingProtocol().AddForwardRoute("Blue", "Green"); | ||
}) | ||
.WithRouter("Blue-Red", cfg => | ||
{ | ||
cfg.AddInterface("Blue", false).Broker().Bravo(); | ||
cfg.AddInterface("Red", false).Broker().Charlie(); | ||
|
||
cfg.UseStaticRoutingProtocol().AddForwardRoute("Red", "Blue", "Green-Blue"); | ||
}) | ||
.WithEndpoint<Publisher>(c => c.When(x => x.EventSubscribed, s => s.Publish(new MyEvent()))) | ||
.WithEndpoint<Subscriber>() | ||
.Done(c => c.EventDelivered) | ||
.Run(); | ||
|
||
Assert.IsTrue(result.EventDelivered); | ||
} | ||
|
||
class Context : ScenarioContext | ||
{ | ||
public bool EventDelivered { get; set; } | ||
public bool EventSubscribed { get; set; } | ||
} | ||
|
||
class Publisher : EndpointConfigurationBuilder | ||
{ | ||
public Publisher() | ||
{ | ||
EndpointSetup<DefaultServer>(c => | ||
{ | ||
//No bridge configuration needed for publisher | ||
c.ConfigureBroker().Alpha(); | ||
|
||
c.ConfigureRouting().EnableMessageDrivenPubSubCompatibilityMode(); | ||
|
||
c.OnEndpointSubscribed<Context>((args, context) => | ||
{ | ||
context.EventSubscribed = true; | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
class Subscriber : EndpointConfigurationBuilder | ||
{ | ||
public Subscriber() | ||
{ | ||
EndpointSetup<DefaultServer>(c => | ||
{ | ||
c.ConfigureBroker().Charlie(); | ||
|
||
var routing = c.ConfigureRouting(); | ||
var bridge = routing.ConnectToRouter("Blue-Red"); | ||
bridge.RegisterPublisher(typeof(MyEvent), Conventions.EndpointNamingConvention(typeof(Publisher))); | ||
}); | ||
} | ||
|
||
class MyEventHandler : IHandleMessages<MyEvent> | ||
{ | ||
Context scenarioContext; | ||
|
||
public MyEventHandler(Context scenarioContext) | ||
{ | ||
this.scenarioContext = scenarioContext; | ||
} | ||
|
||
public Task Handle(MyEvent message, IMessageHandlerContext context) | ||
{ | ||
scenarioContext.EventDelivered = true; | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} | ||
|
||
class MyEvent : IEvent | ||
{ | ||
} | ||
} | ||
} |
Oops, something went wrong.