Skip to content

Commit 0ac2eed

Browse files
authored
Amazon DynamoDB persistence provider (danielgerlag#227)
1 parent 6b7ac54 commit 0ac2eed

33 files changed

+1186
-39
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ There are several persistence providers available as separate Nuget packages.
114114

115115
* MemoryPersistenceProvider *(Default provider, for demo and testing purposes)*
116116
* [MongoDB](src/providers/WorkflowCore.Persistence.MongoDB)
117+
* [Amazon DynamoDB](src/providers/WorkflowCore.Providers.AWS)
117118
* [SQL Server](src/providers/WorkflowCore.Persistence.SqlServer)
118119
* [PostgreSQL](src/providers/WorkflowCore.Persistence.PostgreSQL)
119120
* [Sqlite](src/providers/WorkflowCore.Persistence.Sqlite)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using Docker.DotNet;
2+
using Docker.DotNet.Models;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Net;
6+
using System.Runtime.InteropServices;
7+
using System.Text;
8+
using Docker.Testify;
9+
using Xunit;
10+
using Amazon.DynamoDBv2;
11+
using Amazon.Runtime;
12+
13+
namespace WorkflowCore.Tests.DynamoDB
14+
{
15+
public class DynamoDbDockerSetup : DockerSetup
16+
{
17+
public static string ConnectionString { get; set; }
18+
19+
public static AWSCredentials Credentials => new EnvironmentVariablesAWSCredentials();
20+
21+
public override string ImageName => @"amazon/dynamodb-local";
22+
public override int InternalPort => 8000;
23+
24+
public override void PublishConnectionInfo()
25+
{
26+
ConnectionString = $"http://localhost:{ExternalPort}";
27+
}
28+
29+
public override bool TestReady()
30+
{
31+
try
32+
{
33+
AmazonDynamoDBConfig clientConfig = new AmazonDynamoDBConfig
34+
{
35+
ServiceURL = $"http://localhost:{ExternalPort}"
36+
};
37+
AmazonDynamoDBClient client = new AmazonDynamoDBClient(clientConfig);
38+
var resp = client.ListTablesAsync().Result;
39+
40+
return resp.HttpStatusCode == HttpStatusCode.OK;
41+
}
42+
catch
43+
{
44+
return false;
45+
}
46+
47+
}
48+
}
49+
50+
[CollectionDefinition("DynamoDb collection")]
51+
public class DynamoDbCollection : ICollectionFixture<DynamoDbDockerSetup>
52+
{
53+
}
54+
55+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Amazon.DynamoDBv2;
5+
using Microsoft.Extensions.Logging;
6+
using WorkflowCore.Interface;
7+
using WorkflowCore.Providers.AWS.Services;
8+
using WorkflowCore.UnitTests;
9+
using Xunit;
10+
11+
namespace WorkflowCore.Tests.DynamoDB
12+
{
13+
[Collection("DynamoDb collection")]
14+
public class DynamoPersistenceProviderFixture : BasePersistenceFixture
15+
{
16+
DynamoDbDockerSetup _dockerSetup;
17+
private IPersistenceProvider _subject;
18+
19+
public DynamoPersistenceProviderFixture(DynamoDbDockerSetup dockerSetup)
20+
{
21+
_dockerSetup = dockerSetup;
22+
}
23+
24+
protected override IPersistenceProvider Subject
25+
{
26+
get
27+
{
28+
if (_subject == null)
29+
{
30+
var cfg = new AmazonDynamoDBConfig { ServiceURL = DynamoDbDockerSetup.ConnectionString };
31+
var provisioner = new DynamoDbProvisioner(DynamoDbDockerSetup.Credentials, cfg, "unittests", new LoggerFactory());
32+
var client = new DynamoPersistenceProvider(DynamoDbDockerSetup.Credentials, cfg, provisioner, "unittests", new LoggerFactory());
33+
client.EnsureStoreExists();
34+
_subject = client;
35+
}
36+
return _subject;
37+
}
38+
}
39+
}
40+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Amazon.DynamoDBv2;
5+
using Amazon.Runtime;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using WorkflowCore.IntegrationTests.Scenarios;
8+
using WorkflowCore.Tests.DynamoDB;
9+
using Xunit;
10+
11+
namespace WorkflowCore.Tests.MongoDB.Scenarios
12+
{
13+
[Collection("DynamoDb collection")]
14+
public class DynamoBasicScenario : BasicScenario
15+
{
16+
protected override void ConfigureServices(IServiceCollection services)
17+
{
18+
var cfg = new AmazonDynamoDBConfig {ServiceURL = DynamoDbDockerSetup.ConnectionString};
19+
services.AddWorkflow(x => x.UseAwsDynamoPersistence(DynamoDbDockerSetup.Credentials, cfg, "tests-"));
20+
}
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Amazon.DynamoDBv2;
5+
using Amazon.Runtime;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using WorkflowCore.IntegrationTests.Scenarios;
8+
using WorkflowCore.Tests.DynamoDB;
9+
using Xunit;
10+
11+
namespace WorkflowCore.Tests.MongoDB.Scenarios
12+
{
13+
[Collection("DynamoDb collection")]
14+
public class DynamoCompensationScenario : CompensationScenario
15+
{
16+
protected override void ConfigureServices(IServiceCollection services)
17+
{
18+
var cfg = new AmazonDynamoDBConfig {ServiceURL = DynamoDbDockerSetup.ConnectionString};
19+
services.AddWorkflow(x => x.UseAwsDynamoPersistence(DynamoDbDockerSetup.Credentials, cfg, "tests-"));
20+
}
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Amazon.DynamoDBv2;
5+
using Amazon.Runtime;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using WorkflowCore.IntegrationTests.Scenarios;
8+
using WorkflowCore.Tests.DynamoDB;
9+
using Xunit;
10+
11+
namespace WorkflowCore.Tests.MongoDB.Scenarios
12+
{
13+
[Collection("DynamoDb collection")]
14+
public class DynamoDataScenario : DataIOScenario
15+
{
16+
protected override void ConfigureServices(IServiceCollection services)
17+
{
18+
var cfg = new AmazonDynamoDBConfig {ServiceURL = DynamoDbDockerSetup.ConnectionString};
19+
services.AddWorkflow(x => x.UseAwsDynamoPersistence(DynamoDbDockerSetup.Credentials, cfg, "tests-"));
20+
}
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Amazon.DynamoDBv2;
5+
using Amazon.Runtime;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using WorkflowCore.IntegrationTests.Scenarios;
8+
using WorkflowCore.Tests.DynamoDB;
9+
using Xunit;
10+
11+
namespace WorkflowCore.Tests.MongoDB.Scenarios
12+
{
13+
[Collection("DynamoDb collection")]
14+
public class DynamoDynamicDataScenario : DynamicDataIOScenario
15+
{
16+
protected override void ConfigureServices(IServiceCollection services)
17+
{
18+
var cfg = new AmazonDynamoDBConfig {ServiceURL = DynamoDbDockerSetup.ConnectionString};
19+
services.AddWorkflow(x => x.UseAwsDynamoPersistence(DynamoDbDockerSetup.Credentials, cfg, "tests-"));
20+
}
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Amazon.DynamoDBv2;
5+
using Amazon.Runtime;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using WorkflowCore.IntegrationTests.Scenarios;
8+
using WorkflowCore.Tests.DynamoDB;
9+
using Xunit;
10+
11+
namespace WorkflowCore.Tests.MongoDB.Scenarios
12+
{
13+
[Collection("DynamoDb collection")]
14+
public class DynamoEventScenario : EventScenario
15+
{
16+
protected override void ConfigureServices(IServiceCollection services)
17+
{
18+
var cfg = new AmazonDynamoDBConfig {ServiceURL = DynamoDbDockerSetup.ConnectionString};
19+
services.AddWorkflow(x => x.UseAwsDynamoPersistence(DynamoDbDockerSetup.Credentials, cfg, "tests-"));
20+
}
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Amazon.DynamoDBv2;
5+
using Amazon.Runtime;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using WorkflowCore.IntegrationTests.Scenarios;
8+
using WorkflowCore.Tests.DynamoDB;
9+
using Xunit;
10+
11+
namespace WorkflowCore.Tests.MongoDB.Scenarios
12+
{
13+
[Collection("DynamoDb collection")]
14+
public class DynamoForeachScenario : ForeachScenario
15+
{
16+
protected override void ConfigureServices(IServiceCollection services)
17+
{
18+
var cfg = new AmazonDynamoDBConfig {ServiceURL = DynamoDbDockerSetup.ConnectionString};
19+
services.AddWorkflow(x => x.UseAwsDynamoPersistence(DynamoDbDockerSetup.Credentials, cfg, "tests-"));
20+
}
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Amazon.DynamoDBv2;
5+
using Amazon.Runtime;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using WorkflowCore.IntegrationTests.Scenarios;
8+
using WorkflowCore.Tests.DynamoDB;
9+
using Xunit;
10+
11+
namespace WorkflowCore.Tests.MongoDB.Scenarios
12+
{
13+
[Collection("DynamoDb collection")]
14+
public class DynamoIfScenario : IfScenario
15+
{
16+
protected override void ConfigureServices(IServiceCollection services)
17+
{
18+
var cfg = new AmazonDynamoDBConfig {ServiceURL = DynamoDbDockerSetup.ConnectionString};
19+
services.AddWorkflow(x => x.UseAwsDynamoPersistence(DynamoDbDockerSetup.Credentials, cfg, "tests-"));
20+
}
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Amazon.DynamoDBv2;
5+
using Amazon.Runtime;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using WorkflowCore.IntegrationTests.Scenarios;
8+
using WorkflowCore.Tests.DynamoDB;
9+
using Xunit;
10+
11+
namespace WorkflowCore.Tests.MongoDB.Scenarios
12+
{
13+
[Collection("DynamoDb collection")]
14+
public class DynamoRetrySagaScenario : RetrySagaScenario
15+
{
16+
protected override void ConfigureServices(IServiceCollection services)
17+
{
18+
var cfg = new AmazonDynamoDBConfig {ServiceURL = DynamoDbDockerSetup.ConnectionString};
19+
services.AddWorkflow(x => x.UseAwsDynamoPersistence(DynamoDbDockerSetup.Credentials, cfg, "tests-"));
20+
}
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Amazon.DynamoDBv2;
5+
using Amazon.Runtime;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using WorkflowCore.IntegrationTests.Scenarios;
8+
using WorkflowCore.Tests.DynamoDB;
9+
using Xunit;
10+
11+
namespace WorkflowCore.Tests.MongoDB.Scenarios
12+
{
13+
[Collection("DynamoDb collection")]
14+
public class DynamoSagaScenario : SagaScenario
15+
{
16+
protected override void ConfigureServices(IServiceCollection services)
17+
{
18+
var cfg = new AmazonDynamoDBConfig {ServiceURL = DynamoDbDockerSetup.ConnectionString};
19+
services.AddWorkflow(x => x.UseAwsDynamoPersistence(DynamoDbDockerSetup.Credentials, cfg, "tests-"));
20+
}
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Amazon.DynamoDBv2;
5+
using Amazon.Runtime;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using WorkflowCore.IntegrationTests.Scenarios;
8+
using WorkflowCore.Tests.DynamoDB;
9+
using Xunit;
10+
11+
namespace WorkflowCore.Tests.MongoDB.Scenarios
12+
{
13+
[Collection("DynamoDb collection")]
14+
public class DynamoWhileScenario : WhileScenario
15+
{
16+
protected override void ConfigureServices(IServiceCollection services)
17+
{
18+
var cfg = new AmazonDynamoDBConfig {ServiceURL = DynamoDbDockerSetup.ConnectionString};
19+
services.AddWorkflow(x => x.UseAwsDynamoPersistence(DynamoDbDockerSetup.Credentials, cfg, "tests-"));
20+
}
21+
}
22+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.1</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.3.16" />
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
12+
<PackageReference Include="xunit" Version="2.4.0" />
13+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\src\providers\WorkflowCore.Providers.AWS\WorkflowCore.Providers.AWS.csproj" />
18+
<ProjectReference Include="..\test\Docker.Testify\Docker.Testify.csproj" />
19+
<ProjectReference Include="..\test\WorkflowCore.IntegrationTests\WorkflowCore.IntegrationTests.csproj" />
20+
<ProjectReference Include="..\test\WorkflowCore.UnitTests\WorkflowCore.UnitTests.csproj" />
21+
</ItemGroup>
22+
23+
</Project>

WorkflowCore.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WorkflowCore.Persistence.My
120120
EndProject
121121
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WorkflowCore.Tests.MySQL", "test\WorkflowCore.Tests.MySQL\WorkflowCore.Tests.MySQL.csproj", "{DF7F7ECA-1771-40C9-9CD0-AFEFC44E60DE}"
122122
EndProject
123+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkflowCore.Tests.DynamoDB", "WorkflowCore.Tests.DynamoDB\WorkflowCore.Tests.DynamoDB.csproj", "{0FF3F27E-E909-4ABA-BF82-39D1BA133EA7}"
124+
EndProject
123125
Global
124126
GlobalSection(SolutionConfigurationPlatforms) = preSolution
125127
Debug|Any CPU = Debug|Any CPU
@@ -302,6 +304,10 @@ Global
302304
{DF7F7ECA-1771-40C9-9CD0-AFEFC44E60DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
303305
{DF7F7ECA-1771-40C9-9CD0-AFEFC44E60DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
304306
{DF7F7ECA-1771-40C9-9CD0-AFEFC44E60DE}.Release|Any CPU.Build.0 = Release|Any CPU
307+
{0FF3F27E-E909-4ABA-BF82-39D1BA133EA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
308+
{0FF3F27E-E909-4ABA-BF82-39D1BA133EA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
309+
{0FF3F27E-E909-4ABA-BF82-39D1BA133EA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
310+
{0FF3F27E-E909-4ABA-BF82-39D1BA133EA7}.Release|Any CPU.Build.0 = Release|Any CPU
305311
EndGlobalSection
306312
GlobalSection(SolutionProperties) = preSolution
307313
HideSolutionNode = FALSE
@@ -354,6 +360,7 @@ Global
354360
{5E82A137-0954-46A1-8C46-13C00F0E4842} = {2EEE6ABD-EE9B-473F-AF2D-6DABB85D7BA2}
355361
{453E260D-DBDC-4DDC-BC9C-CA500CED7897} = {2EEE6ABD-EE9B-473F-AF2D-6DABB85D7BA2}
356362
{DF7F7ECA-1771-40C9-9CD0-AFEFC44E60DE} = {E6CEAD8D-F565-471E-A0DC-676F54EAEDEB}
363+
{0FF3F27E-E909-4ABA-BF82-39D1BA133EA7} = {E6CEAD8D-F565-471E-A0DC-676F54EAEDEB}
357364
EndGlobalSection
358365
GlobalSection(ExtensibilityGlobals) = postSolution
359366
SolutionGuid = {DC0FA8D3-6449-4FDA-BB46-ECF58FAD23B4}

WorkflowCore.sln.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
1313
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
1414
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpRenamePlacementToArrangementMigration/@EntryIndexedValue">True</s:Boolean>
15+
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
1516
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
1617
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002ECSharpPlaceAttributeOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
1718
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>

0 commit comments

Comments
 (0)