Skip to content

Commit

Permalink
One FlowDance.Client now :)
Browse files Browse the repository at this point in the history
  • Loading branch information
olahallvall committed May 13, 2024
1 parent 316c7bc commit 472b9b0
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 139 deletions.
2 changes: 0 additions & 2 deletions FlowDance.AzureFunctions/Sagas/CompensatingSaga.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ public async Task RunOrchestrator([OrchestrationTrigger] TaskOrchestrationContex
var logger = context.CreateReplaySafeLogger(nameof(CompensatingSaga));
var json = context.GetInput<string>();

logger.LogInformation("{json}", json);

var spanList = JsonConvert.DeserializeObject<List<Span>>(json, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Auto });
if (spanList == null || spanList.Count == 0)
{
Expand Down
1 change: 1 addition & 0 deletions FlowDance.Client/CompensationSpan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using RabbitMQ.Client;
using System.Runtime.InteropServices;
using FlowDance.Common.Models;
using System;

namespace FlowDance.Client
{
Expand Down
11 changes: 7 additions & 4 deletions FlowDance.Client/FlowDance.Client.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TargetFrameworks>net6.0;net7.0;net8.0;netstandard2.0</TargetFrameworks>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>FlowDance.Client</Title>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/olahallvall/FlowDance</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Version>1.0.4-alpha</Version>
</PropertyGroup>

<ItemGroup>
Expand All @@ -25,10 +24,14 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="RabbitMQ.Client" Version="6.8.1" />
<PackageReference Include="Teronis.MSBuild.Packaging.ProjectBuildInPackage" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FlowDance.Common\FlowDance.Common.csproj" />
<ProjectReference Include="..\FlowDance.Common\FlowDance.Common.csproj" PrivateAssets="all" />
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions FlowDance.Client/RabbitMq/Storage.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
using FlowDance.Common.Commands;
using FlowDance.Common.Events;
Expand Down
117 changes: 1 addition & 116 deletions FlowDance.Test.Legacy/CompensationSpanTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Threading;
using FlowDance.Client.Legacy;
using FlowDance.Client;
using FlowDance.Common.Models;
using FlowDance.Test.Legacy.RabbitMqHttpApiClient.API;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -35,120 +34,6 @@ public void RootCompensationSpan()

compSpan.Complete();
}

Thread.Sleep(10000);
Assert.AreEqual(2, _rabbitMqApi.GetQueueByVhostAndName("/", traceId.ToString()).Result.MessagesReady);
}

[TestMethod]
public void RootWithInnerCompensationSpan()
{
var traceId = Guid.NewGuid();

// The top-most compensation scope is referred to as the root scope.
// Root span
using (var compSpanRoot = new CompensationSpan(new HttpCompensatingAction("http://localhost/TripBookingService/Compensation"), traceId, _loggerFactory))
{
/* Perform transactional work here */

// Inner scope
using (var compSpanInner = new CompensationSpan(new HttpCompensatingAction("http://localhost/CarService/Compensation"), traceId, _loggerFactory))
{
/* Perform transactional work here */

compSpanInner.Complete();
}

compSpanRoot.Complete();
}

Thread.Sleep(10000);
Assert.AreEqual(4, _rabbitMqApi.GetQueueByVhostAndName("/", traceId.ToString()).Result.MessagesReady);
}

[TestMethod]
[ExpectedException(typeof(Exception))]
public void RootMethodWithTwoInnerMethodCompensationSpan()
{
var guid = Guid.NewGuid();
RootMethod(guid);
}

private void RootMethod(Guid guid)
{
using (var compSpan = new CompensationSpan(new HttpCompensatingAction("http://localhost/CarService/Compensation"), guid, _loggerFactory))
{
/* Perform transactional work here */
InnerMethod(guid);
compSpan.Complete();
}
}

private void InnerMethod(Guid guid)
{
using (var compSpan = new CompensationSpan(new HttpCompensatingAction("http://localhost/HotelService/Compensation"), guid, _loggerFactory))
{
/* Perform transactional work here */
throw new Exception("Something bad has happened!");

compSpan.Complete();
}
}

[TestMethod]
[ExpectedException(typeof(Exception))]
public void MultipleRootCompensationSpanUsingSameTraceId()
{
var traceId = Guid.NewGuid();

// Root
using (var compSpanRoot = new CompensationSpan(new HttpCompensatingAction("http://localhost/HotelService/Compensation"), traceId, _loggerFactory))
{
/* Perform transactional work here */
throw new Exception("Something bad has happened!");

compSpanRoot.Complete();
}

// Root
using (var compSpanRoot = new CompensationSpan(new HttpCompensatingAction("http://localhost/HotelService/Compensation"), traceId, _loggerFactory))
{
/* Perform transactional work here */

compSpanRoot.Complete();
}
}

[TestMethod]
[ExpectedException(typeof(Exception))]
public void RootMethodWithTwoInlineCompensationSpan()
{
var traceId = Guid.NewGuid();

// Root
using (var compSpanRoot = new CompensationSpan(new HttpCompensatingAction("http://localhost/HotelService/Compensation"), traceId, _loggerFactory))
{
/* Perform transactional work here */

// Inner scope 1
using (var compSpanInner = new CompensationSpan(new HttpCompensatingAction("http://localhost/HotelService/Compensation1"), traceId, _loggerFactory))
{
/* Perform transactional work here */

compSpanInner.Complete();
}

// Inner scope 2
using (var compSpanInner = new CompensationSpan(new HttpCompensatingAction("http://localhost/HotelService/Compensation2"), traceId, _loggerFactory))
{
/* Perform transactional work here */
throw new Exception("Something bad has happened!");

compSpanInner.Complete();
}

compSpanRoot.Complete();
}
}
}
}
18 changes: 15 additions & 3 deletions FlowDance.Test.Legacy/FlowDance.Test.Legacy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
<Reference Include="Microsoft.Extensions.Configuration.Binder, Version=8.0.0.1, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.Configuration.Binder.8.0.1\lib\net462\Microsoft.Extensions.Configuration.Binder.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Configuration.FileExtensions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.Configuration.FileExtensions.8.0.0\lib\net462\Microsoft.Extensions.Configuration.FileExtensions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Configuration.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.Configuration.Json.8.0.0\lib\net462\Microsoft.Extensions.Configuration.Json.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.DependencyInjection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.8.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -130,6 +136,9 @@
<Reference Include="NuGet.Frameworks, Version=6.9.1.3, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\NuGet.Frameworks.6.9.1\lib\net472\NuGet.Frameworks.dll</HintPath>
</Reference>
<Reference Include="RabbitMQ.Client, Version=6.0.0.0, Culture=neutral, PublicKeyToken=89e7d7c5feba84ce, processorArchitecture=MSIL">
<HintPath>..\packages\RabbitMQ.Client.6.8.1\lib\net462\RabbitMQ.Client.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
Expand Down Expand Up @@ -258,12 +267,15 @@
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FlowDance.Client.Legacy\FlowDance.Client.Legacy.csproj">
<Project>{2ad48324-72b9-49ed-a2ac-972d762373ce}</Project>
<Name>FlowDance.Client.Legacy</Name>
<ProjectReference Include="..\FlowDance.Client\FlowDance.Client.csproj">
<Project>{d50b54d4-7cb8-438d-92f5-c7c87dd820e7}</Project>
<Name>FlowDance.Client</Name>
</ProjectReference>
<ProjectReference Include="..\FlowDance.Common\FlowDance.Common.csproj">
<Project>{9a05bc35-6b47-4b0e-b6fe-fc0482573ce1}</Project>
Expand Down
8 changes: 0 additions & 8 deletions FlowDance.Test.Legacy/app.config
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>

<appSettings>
<add key="RabbitMqConnection.HostName" value="localhost" />
<add key="RabbitMqConnection.Username" value="guest" />
<add key="RabbitMqConnection.Password" value="guest" />
<add key="RabbitMqConnection.VirtualHost" value="/" />
</appSettings>

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
Expand Down
8 changes: 8 additions & 0 deletions FlowDance.Test.Legacy/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"RabbitMqConnection": {
"HostName": "localhost",
"Username": "guest",
"Password": "guest",
"VirtualHost": "/"
}
}
3 changes: 3 additions & 0 deletions FlowDance.Test.Legacy/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<package id="Microsoft.Extensions.Configuration" version="8.0.0" targetFramework="net472" />
<package id="Microsoft.Extensions.Configuration.Abstractions" version="8.0.0" targetFramework="net472" />
<package id="Microsoft.Extensions.Configuration.Binder" version="8.0.1" targetFramework="net472" />
<package id="Microsoft.Extensions.Configuration.FileExtensions" version="8.0.0" targetFramework="net472" />
<package id="Microsoft.Extensions.Configuration.Json" version="8.0.0" targetFramework="net472" />
<package id="Microsoft.Extensions.DependencyInjection" version="8.0.0" targetFramework="net472" />
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="8.0.1" targetFramework="net472" />
<package id="Microsoft.Extensions.FileProviders.Abstractions" version="8.0.0" targetFramework="net472" />
Expand All @@ -27,6 +29,7 @@
<package id="MSTest.TestFramework" version="3.3.1" targetFramework="net472" />
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net472" />
<package id="NuGet.Frameworks" version="6.9.1" targetFramework="net472" />
<package id="RabbitMQ.Client" version="6.8.1" targetFramework="net472" />
<package id="System.Buffers" version="4.5.1" targetFramework="net472" />
<package id="System.Collections.Immutable" version="8.0.0" targetFramework="net472" />
<package id="System.Diagnostics.DiagnosticSource" version="8.0.1" targetFramework="net472" />
Expand Down
1 change: 1 addition & 0 deletions FlowDance.Tests/FlowDance.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

<ItemGroup>
<ProjectReference Include="..\FlowDance.Client\FlowDance.Client.csproj" />
<ProjectReference Include="..\FlowDance.Common\FlowDance.Common.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 0 additions & 6 deletions FlowDance.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlowDance.AzureFunctions",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlowDance.Tests", "FlowDance.Tests\FlowDance.Tests.csproj", "{1DF738A8-B9EA-4BD3-9704-C30F99C9FC19}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowDance.Client.Legacy", "FlowDance.Client.Legacy\FlowDance.Client.Legacy.csproj", "{2AD48324-72B9-49ED-A2AC-972D762373CE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowDance.Test.Legacy", "FlowDance.Test.Legacy\FlowDance.Test.Legacy.csproj", "{D1E92428-0F99-4FC8-985E-4A6B4AF399AD}"
EndProject
Global
Expand All @@ -43,10 +41,6 @@ Global
{1DF738A8-B9EA-4BD3-9704-C30F99C9FC19}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1DF738A8-B9EA-4BD3-9704-C30F99C9FC19}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1DF738A8-B9EA-4BD3-9704-C30F99C9FC19}.Release|Any CPU.Build.0 = Release|Any CPU
{2AD48324-72B9-49ED-A2AC-972D762373CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2AD48324-72B9-49ED-A2AC-972D762373CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2AD48324-72B9-49ED-A2AC-972D762373CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2AD48324-72B9-49ED-A2AC-972D762373CE}.Release|Any CPU.Build.0 = Release|Any CPU
{D1E92428-0F99-4FC8-985E-4A6B4AF399AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D1E92428-0F99-4FC8-985E-4A6B4AF399AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D1E92428-0F99-4FC8-985E-4A6B4AF399AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down

0 comments on commit 472b9b0

Please sign in to comment.