-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
8 changed files
with
216 additions
and
0 deletions.
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
19 changes: 19 additions & 0 deletions
19
...eBuses/Wolverine/Cleipnir.Flows.Wolverine.Console/Cleipnir.Flows.Wolverine.Console.csproj
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,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" /> | ||
<PackageReference Include="WolverineFx" Version="2.17.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\Cleipnir.Flows\Cleipnir.Flows.csproj" /> | ||
</ItemGroup> | ||
</Project> |
3 changes: 3 additions & 0 deletions
3
ServiceBuses/Wolverine/Cleipnir.Flows.Wolverine.Console/MyMessage.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,3 @@ | ||
namespace Cleipnir.Flows.MassTransit.Console; | ||
|
||
public record MyMessage(string Value); |
49 changes: 49 additions & 0 deletions
49
ServiceBuses/Wolverine/Cleipnir.Flows.Wolverine.Console/Program.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,49 @@ | ||
using Cleipnir.Flows.AspNet; | ||
using Cleipnir.Flows.MassTransit.Console; | ||
using Cleipnir.ResilientFunctions.Helpers; | ||
using Cleipnir.ResilientFunctions.Storage; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Wolverine; | ||
|
||
namespace Cleipnir.Flows.Wolverine.Console; | ||
|
||
internal static class Program | ||
{ | ||
public static async Task Main(string[] args) | ||
{ | ||
var host = await CreateHostBuilder([]).StartAsync(); | ||
var bus = host.Services.GetRequiredService<IMessageBus>(); | ||
var store = host.Services.GetRequiredService<IFunctionStore>(); | ||
|
||
var testSize = 1_000; | ||
for (var i = 0; i < testSize; i++) | ||
await bus.PublishAsync(new MyMessage(i.ToString())); | ||
|
||
while (true) | ||
{ | ||
var succeeded = await store.GetSucceededFunctions( | ||
nameof(SimpleFlow), | ||
DateTime.UtcNow.Ticks + 1_000_000 | ||
).SelectAsync(f => f.Count); | ||
if (succeeded == testSize) | ||
break; | ||
|
||
await Task.Delay(250); | ||
} | ||
|
||
System.Console.WriteLine("All completed"); | ||
} | ||
|
||
private static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.ConfigureServices((_, services) => | ||
{ | ||
services.AddFlows(c => c | ||
.UseInMemoryStore() | ||
.RegisterFlow<SimpleFlow, SimpleFlows>() | ||
//.RegisterFlowsAutomatically() | ||
); | ||
}) | ||
.UseWolverine(); | ||
} |
25 changes: 25 additions & 0 deletions
25
ServiceBuses/Wolverine/Cleipnir.Flows.Wolverine.Console/SimpleFlow.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,25 @@ | ||
using Cleipnir.Flows.MassTransit.Console; | ||
using Cleipnir.ResilientFunctions.Reactive.Extensions; | ||
|
||
namespace Cleipnir.Flows.Wolverine.Console; | ||
|
||
public class SimpleFlow : Flow | ||
{ | ||
public override async Task Run() | ||
{ | ||
var msg = await Messages.FirstOfType<MyMessage>(); | ||
System.Console.WriteLine($"SimpleFlow({msg}) executed"); | ||
} | ||
} | ||
|
||
public class SimpleFlows : Flows<SimpleFlow> | ||
{ | ||
public SimpleFlows(FlowsContainer flowsContainer) | ||
: base("SimpleFlow", flowsContainer, options: null) { } | ||
} | ||
|
||
public class SimpleFlowsHandler(SimpleFlows flows) | ||
{ | ||
public Task Handle(MyMessage myMessage) | ||
=> flows.SendMessage(myMessage.Value, myMessage); | ||
} |
31 changes: 31 additions & 0 deletions
31
ServiceBuses/Wolverine/Cleipnir.Flows.Wolverine.Tests/Cleipnir.Flows.Wolverine.Tests.csproj
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,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.2"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="3.5.2" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="3.5.2" /> | ||
<PackageReference Include="Shouldly" Version="4.2.1" /> | ||
<PackageReference Include="WolverineFx" Version="2.17.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\Cleipnir.Flows\Cleipnir.Flows.csproj" /> | ||
</ItemGroup> | ||
</Project> |
66 changes: 66 additions & 0 deletions
66
ServiceBuses/Wolverine/Cleipnir.Flows.Wolverine.Tests/IntegrationTests.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,66 @@ | ||
using Cleipnir.Flows.AspNet; | ||
using Cleipnir.ResilientFunctions.Helpers; | ||
using Cleipnir.ResilientFunctions.Reactive.Extensions; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Shouldly; | ||
using Wolverine; | ||
|
||
namespace Cleipnir.Flows.Wolverine.Tests; | ||
|
||
[TestClass] | ||
public class IntegrationTests | ||
{ | ||
public record MyMessage(string Value); | ||
|
||
public class TestFlow : Flow | ||
{ | ||
public static volatile MyMessage? ReceivedMyMessage; | ||
|
||
public override async Task Run() | ||
{ | ||
ReceivedMyMessage = await Messages.FirstOfType<MyMessage>(); | ||
} | ||
} | ||
|
||
public class TestFlows : Flows<TestFlow> | ||
{ | ||
public TestFlows(FlowsContainer flowsContainer) : base(flowName: "RebusTestFlow", flowsContainer) { } | ||
} | ||
|
||
private class TestHostedService : IHostedService | ||
{ | ||
public static IServiceProvider? ServiceProvider { get; set; } | ||
|
||
public TestHostedService(IServiceProvider serviceProvider) => ServiceProvider = serviceProvider; | ||
|
||
public async Task StartAsync(CancellationToken cancellationToken) | ||
{ | ||
await ServiceProvider!.GetRequiredService<IMessageBus>().SendAsync(new MyMessage("SomeMessage")); | ||
} | ||
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; | ||
} | ||
|
||
[TestMethod] | ||
public async Task SunshineScenario() | ||
{ | ||
var host = await Host | ||
.CreateDefaultBuilder([]) | ||
.UseWolverine() | ||
.ConfigureServices((_, services) => | ||
{ | ||
services.AddHostedService<TestHostedService>(); | ||
|
||
services.AddFlows(c => c | ||
.UseInMemoryStore() | ||
.RegisterFlow<TestFlow, TestFlows>() | ||
); | ||
}) | ||
.StartAsync(); | ||
|
||
await BusyWait.Until(() => TestFlow.ReceivedMyMessage is not null, maxWait: TimeSpan.FromSeconds(5)); | ||
TestFlow.ReceivedMyMessage!.Value.ShouldBe("SomeMessage"); | ||
|
||
host.Dispose(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
ServiceBuses/Wolverine/Cleipnir.Flows.Wolverine.Tests/TestFlowHandler.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,6 @@ | ||
namespace Cleipnir.Flows.Wolverine.Tests; | ||
|
||
public class TestFlowHandler(IntegrationTests.TestFlows flows) | ||
{ | ||
public Task Handle(IntegrationTests.MyMessage message) => flows.SendMessage(message.Value, message); | ||
} |