Skip to content

Commit

Permalink
reinitialized sql server journal
Browse files Browse the repository at this point in the history
sqlexpress based test database

working SqlServerJournal, intializes SqlServerSnapshotStore

initial impl of SqlServer snapshot store

fixed rest of broken sql server snapshot store specs

Akka.Persistence.SqlServer comments for public API

final notest and docs for Akka.Persistence.SqlServer

safe escape of SQL string formats + mdf based tests

fixed sln file
  • Loading branch information
Horusiath committed Apr 13, 2015
1 parent ff8f5c3 commit 911b0d3
Show file tree
Hide file tree
Showing 32 changed files with 1,743 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ UpgradeLog*.htm
*.mdf
*.ldf

# make exception for Akka.Persistence.SqlServer database file
!AkkaPersistenceSqlServerSpecDb.mdf

# Business Intelligence projects
*.rdl.data
*.bim.layout
Expand Down
25 changes: 25 additions & 0 deletions src/Akka.sln
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicUnityUses", "contrib\d
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.DI.Unity", "contrib\dependencyInjection\Akka.DI.Unity\Akka.DI.Unity.csproj", "{2065C3A2-8C15-4912-BCF5-AE89E3DDA079}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Persistence", "Persistence", "{22EF93A8-761B-48E0-AC38-1416886FD5BA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.Persistence.SqlServer", "contrib\persistence\Akka.Persistence.SqlServer\Akka.Persistence.SqlServer.csproj", "{BAC85686-AFC4-413E-98DC-5ED8F468BC63}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.Persistence.SqlServer.Tests", "contrib\persistence\Akka.Persistence.SqlServer.Tests\Akka.Persistence.SqlServer.Tests.csproj", "{5A3C24D7-0D1C-4974-BBB4-22AC792666DE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug Mono|Any CPU = Debug Mono|Any CPU
Expand Down Expand Up @@ -661,6 +667,22 @@ Global
{2065C3A2-8C15-4912-BCF5-AE89E3DDA079}.Release Mono|Any CPU.Build.0 = Release|Any CPU
{2065C3A2-8C15-4912-BCF5-AE89E3DDA079}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2065C3A2-8C15-4912-BCF5-AE89E3DDA079}.Release|Any CPU.Build.0 = Release|Any CPU
{BAC85686-AFC4-413E-98DC-5ED8F468BC63}.Debug Mono|Any CPU.ActiveCfg = Debug|Any CPU
{BAC85686-AFC4-413E-98DC-5ED8F468BC63}.Debug Mono|Any CPU.Build.0 = Debug|Any CPU
{BAC85686-AFC4-413E-98DC-5ED8F468BC63}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BAC85686-AFC4-413E-98DC-5ED8F468BC63}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BAC85686-AFC4-413E-98DC-5ED8F468BC63}.Release Mono|Any CPU.ActiveCfg = Release|Any CPU
{BAC85686-AFC4-413E-98DC-5ED8F468BC63}.Release Mono|Any CPU.Build.0 = Release|Any CPU
{BAC85686-AFC4-413E-98DC-5ED8F468BC63}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BAC85686-AFC4-413E-98DC-5ED8F468BC63}.Release|Any CPU.Build.0 = Release|Any CPU
{5A3C24D7-0D1C-4974-BBB4-22AC792666DE}.Debug Mono|Any CPU.ActiveCfg = Debug|Any CPU
{5A3C24D7-0D1C-4974-BBB4-22AC792666DE}.Debug Mono|Any CPU.Build.0 = Debug|Any CPU
{5A3C24D7-0D1C-4974-BBB4-22AC792666DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5A3C24D7-0D1C-4974-BBB4-22AC792666DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5A3C24D7-0D1C-4974-BBB4-22AC792666DE}.Release Mono|Any CPU.ActiveCfg = Release|Any CPU
{5A3C24D7-0D1C-4974-BBB4-22AC792666DE}.Release Mono|Any CPU.Build.0 = Release|Any CPU
{5A3C24D7-0D1C-4974-BBB4-22AC792666DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5A3C24D7-0D1C-4974-BBB4-22AC792666DE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -742,5 +764,8 @@ Global
{D1CCD86E-0EF8-473A-979B-25E1235FEA2D} = {B1D10183-8FAE-4506-B935-403FCED89BDB}
{32EABA12-DDAA-4F2A-B254-85239267D869} = {D1CCD86E-0EF8-473A-979B-25E1235FEA2D}
{2065C3A2-8C15-4912-BCF5-AE89E3DDA079} = {B1D10183-8FAE-4506-B935-403FCED89BDB}
{22EF93A8-761B-48E0-AC38-1416886FD5BA} = {588C1513-FAB6-42C3-B6FC-3485F13620CF}
{BAC85686-AFC4-413E-98DC-5ED8F468BC63} = {22EF93A8-761B-48E0-AC38-1416886FD5BA}
{5A3C24D7-0D1C-4974-BBB4-22AC792666DE} = {22EF93A8-761B-48E0-AC38-1416886FD5BA}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{5A3C24D7-0D1C-4974-BBB4-22AC792666DE}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Akka.Persistence.SqlServer.Tests</RootNamespace>
<AssemblyName>Akka.Persistence.SqlServer.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DbCleanup.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
<Compile Include="SqlServerJournalSpec.cs" />
<Compile Include="SqlServerSnapshotStoreSpec.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\core\Akka.Persistence.TestKit\Akka.Persistence.TestKit.csproj">
<Project>{ad9418b6-c452-4169-94fb-d43de0bfa966}</Project>
<Name>Akka.Persistence.TestKit</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\core\Akka.Persistence\Akka.Persistence.csproj">
<Project>{fca84dea-c118-424b-9eb8-34375dfef18a}</Project>
<Name>Akka.Persistence</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\core\Akka.TestKit\Akka.TestKit.csproj">
<Project>{0d3cbad0-bbdb-43e5-afc4-ed1d3ecdc224}</Project>
<Name>Akka.TestKit</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\core\Akka\Akka.csproj">
<Project>{5deddf90-37f0-48d3-a0b0-a5cbd8a7e377}</Project>
<Name>Akka</Name>
</ProjectReference>
<ProjectReference Include="..\..\testkits\Akka.TestKit.Xunit\Akka.TestKit.Xunit.csproj">
<Project>{11f4d4b8-7e07-4457-abf2-609b3e7b2649}</Project>
<Name>Akka.TestKit.Xunit</Name>
</ProjectReference>
<ProjectReference Include="..\Akka.Persistence.SqlServer\Akka.Persistence.SqlServer.csproj">
<Project>{bac85686-afc4-413e-98dc-5ed8f468bc63}</Project>
<Name>Akka.Persistence.SqlServer</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Content Include="Resources\AkkaPersistenceSqlServerSpecDb.mdf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Resources\AkkaPersistenceSqlServerSpecDb_log.ldf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<DependentUpon>AkkaPersistenceSqlServerSpecDb.mdf</DependentUpon>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Data.SqlClient;

namespace Akka.Persistence.SqlServer.Tests
{
public static class DbCleanup
{
private static readonly string ConnectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Resources\AkkaPersistenceSqlServerSpecDb.mdf;Integrated Security=True";

static DbCleanup()
{
AppDomain.CurrentDomain.SetData("DataDirectory", AppDomain.CurrentDomain.BaseDirectory);
}

public static void Clean()
{
using (var conn = new SqlConnection(ConnectionString))
using (var cmd = new SqlCommand())
{
conn.Open();
cmd.CommandText = @"
IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND TABLE_NAME = 'EventJournal') BEGIN DELETE FROM dbo.EventJournal END;
IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND TABLE_NAME = 'SnapshotStore') BEGIN DELETE FROM dbo.SnapshotStore END";
cmd.Connection = conn;
cmd.ExecuteNonQuery();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Akka.Persistence.SqlServer.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Akka.Persistence.SqlServer.Tests")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("343a20b5-0aa8-4c22-baea-de78162b1c94")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="Akka.Persistence.SqlServer.Tests.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="SqlServerJournalSpecDbConnectionString" Type="(Connection string)" Scope="Application">
<DesignTimeValue Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;ConnectionString&gt;Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\SqlServerJournalSpecDb.mdf;Integrated Security=True;Connect Timeout=30&lt;/ConnectionString&gt;
&lt;ProviderName&gt;System.Data.SqlClient&lt;/ProviderName&gt;
&lt;/SerializableConnectionString&gt;</DesignTimeValue>
<Value Profile="(Default)">Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\SqlServerJournalSpecDb.mdf;Integrated Security=True;Connect Timeout=30</Value>
</Setting>
</Settings>
</SettingsFile>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Akka.Configuration;
using Akka.Persistence.TestKit.Journal;

namespace Akka.Persistence.SqlServer.Tests
{
public class SqlServerJournalSpec : JournalSpec
{
private static readonly Config SpecConfig = ConfigurationFactory.ParseString(@"
akka.persistence {
publish-plugin-commands = on
journal {
plugin = ""akka.persistence.journal.sql-server""
sql-server {
class = ""Akka.Persistence.SqlServer.Journal.SqlServerJournal, Akka.Persistence.SqlServer""
plugin-dispatcher = ""akka.actor.default-dispatcher""
table-name = EventJournal
schema-name = dbo
auto-initialize = on
connection-string = ""Data Source=(LocalDB)\\v11.0;AttachDbFilename=|DataDirectory|\\Resources\\AkkaPersistenceSqlServerSpecDb.mdf;Integrated Security=True""
}
}
}");

public SqlServerJournalSpec()
: base(SpecConfig, "SqlServerJournalSpec")
{
DbCleanup.Clean();
Initialize();
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
DbCleanup.Clean();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Akka.Configuration;
using Akka.Persistence.TestKit.Snapshot;

namespace Akka.Persistence.SqlServer.Tests
{
public class SqlServerSnapshotStoreSpec : SnapshotStoreSpec
{
private static readonly Config SpecConfig = ConfigurationFactory.ParseString(@"
akka.persistence {
publish-plugin-commands = on
snapshot-store {
plugin = ""akka.persistence.snapshot-store.sql-server""
sql-server {
class = ""Akka.Persistence.SqlServer.Snapshot.SqlServerSnapshotStore, Akka.Persistence.SqlServer""
plugin-dispatcher = ""akka.actor.default-dispatcher""
table-name = SnapshotStore
schema-name = dbo
auto-initialize = on
connection-string = ""Data Source=(LocalDB)\\v11.0;AttachDbFilename=|DataDirectory|\\Resources\\AkkaPersistenceSqlServerSpecDb.mdf;Integrated Security=True""
}
}
}");

public SqlServerSnapshotStoreSpec()
: base(SpecConfig, "SqlServerSnapshotStoreSpec")
{
DbCleanup.Clean();
Initialize();
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
DbCleanup.Clean();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
</configuration>
Loading

0 comments on commit 911b0d3

Please sign in to comment.