Skip to content

Commit

Permalink
Extract Foldunk.InMemoryStore
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Sep 6, 2017
1 parent 59cfd67 commit 2e371b1
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 20 deletions.
6 changes: 6 additions & 0 deletions Foldunk.sln
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Integration", "Samples\Stor
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{A7C685D7-1E7B-4E86-922B-25B2EA9FC5D6}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Foldunk.InMemoryStore", "src\Foldunk.InMemoryStore\Foldunk.InMemoryStore.fsproj", "{A7441FF0-94E6-45E4-B02D-F14ED248516D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -68,6 +70,10 @@ Global
{0B2D5815-D6A5-4AAC-9B75-D57B165E2A92}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0B2D5815-D6A5-4AAC-9B75-D57B165E2A92}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0B2D5815-D6A5-4AAC-9B75-D57B165E2A92}.Release|Any CPU.Build.0 = Release|Any CPU
{A7441FF0-94E6-45E4-B02D-F14ED248516D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A7441FF0-94E6-45E4-B02D-F14ED248516D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A7441FF0-94E6-45E4-B02D-F14ED248516D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A7441FF0-94E6-45E4-B02D-F14ED248516D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
9 changes: 4 additions & 5 deletions Samples/Store/Integration/CartIntegration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

open Backend.Carts
open Domain
open EventStore.ClientAPI
open Foldunk
open Swensen.Unquote
open System
Expand All @@ -11,10 +10,10 @@ type Tests(testOutputHelper) =
let testOutput = TestOutputAdapter testOutputHelper
let createLog () = createLogger (testOutput.Subscribe >> ignore)

(* ======== Tests against In-memory Store *)
(* ======== Tests against InMemoryStore *)

let createServiceWithInMemoryStore () =
let store : Handler.IEventStream<_,_> = Stores.MemoryStreamStore() :> _
let store : Handler.IEventStream<_,_> = Stores.InMemoryStore.MemoryStreamStore() :> _
CartService(store)

[<AutoData>]
Expand Down Expand Up @@ -81,9 +80,9 @@ type Tests(testOutputHelper) =
return conn }

let createServiceWithEventStoreEx conn batchSize =
let store = Foldunk.EventStore.GesStreamStore(conn, batchSize)
let store = Foldunk.Stores.EventStore.GesStreamStore(conn, batchSize)
let encoder = Foldunk.EventSum.generateJsonUtf8SumEncoder<_>
CartService(Foldunk.EventStore.GesEventStreamAdapter(store, encoder))
CartService(Foldunk.Stores.EventStore.GesEventStreamAdapter(store, encoder))
let createServiceWithEventStoreBatchingOnly conn batchSize = createServiceWithEventStoreEx conn batchSize

let createLoggerWithCapture () =
Expand Down
5 changes: 5 additions & 0 deletions Samples/Store/Integration/Integration.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@
<Project>{92b4acc9-7f30-4727-a4b6-0b6903d0aa08}</Project>
<Private>True</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\src\Foldunk.InMemoryStore\Foldunk.InMemoryStore.fsproj">
<Name>Foldunk.InMemoryStore</Name>
<Project>{a7441ff0-94e6-45e4-b02d-f14ed248516d}</Project>
<Private>True</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\src\Foldunk\Foldunk.fsproj">
<Name>Foldunk</Name>
<Project>{54cd058f-5b0a-4564-b732-1f6301e120ac}</Project>
Expand Down
3 changes: 1 addition & 2 deletions src/Foldunk.EventStore/EventStore.fs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module Foldunk.EventStore
module Foldunk.Stores.EventStore

open EventStore.ClientAPI
open Foldunk
open Foldunk.Stores
open FSharp.Control
open Serilog // NB must shadow EventStore.ClientAPI.ILogger
open System
Expand Down
92 changes: 92 additions & 0 deletions src/Foldunk.InMemoryStore/Foldunk.InMemoryStore.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.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>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>a7441ff0-94e6-45e4-b02d-f14ed248516d</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>Foldunk.InMemoryStore</RootNamespace>
<AssemblyName>Foldunk.InMemoryStore</AssemblyName>
<UseStandardResourceNames>true</UseStandardResourceNames>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFSharpCoreVersion>4.4.1.0</TargetFSharpCoreVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Name>Foldunk.InMemoryStore</Name>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<Tailcalls>false</Tailcalls>
<OutputPath>bin\$(Configuration)\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>bin\$(Configuration)\$(AssemblyName).XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<Tailcalls>true</Tailcalls>
<OutputPath>bin\$(Configuration)\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>bin\$(Configuration)\$(AssemblyName).XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '11.0'">
<PropertyGroup Condition=" '$(FSharpTargetsPath)' == '' AND Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets') ">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup Condition=" '$(FSharpTargetsPath)' == '' AND Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets') ">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</Otherwise>
</Choose>
<Import Project="$(FSharpTargetsPath)" />
<ItemGroup>
<None Include="paket.references" />
<Compile Include="MemoryStreamStore.fs" />
</ItemGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="FSharp.Core">
<Name>FSharp.Core</Name>
<AssemblyName>FSharp.Core.dll</AssemblyName>
<HintPath>$(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\$(TargetFSharpCoreVersion)\FSharp.Core.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Foldunk\Foldunk.fsproj">
<Name>Foldunk</Name>
<Project>{54cd058f-5b0a-4564-b732-1f6301e120ac}</Project>
<Private>True</Private>
</ProjectReference>
</ItemGroup>
<!-- 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>
-->
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v4.5.2'">
<ItemGroup>
<Reference Include="Serilog">
<HintPath>..\..\packages\Serilog\lib\net45\Serilog.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
</Project>
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
namespace Foldunk.Stores
namespace Foldunk.Stores.InMemoryStore

open Serilog
open Foldunk

/// Helpers for derivation of a StreamState - shared between EventStore and MemoryStreamStore
module StreamState =
/// Represent a [possibly compacted] array of events with a known token from a store.
let ofTokenAndEvents (token : StreamToken) (events: 'event seq) = token, None, List.ofSeq events
/// Represent a state known to have been persisted to the store
let ofTokenAndKnownState token state = token, Some state, []
/// Represent a state to be composed from a snapshot together with the successor events
let ofTokenSnapshotAndEvents token stateSnapshot (successorEvents : 'event list) =
token, Some stateSnapshot, successorEvents
open Serilog

exception private WrongVersionException of streamName: string * expected: int * value: obj

Expand Down
1 change: 1 addition & 0 deletions src/Foldunk.InMemoryStore/paket.references
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nuget Serilog
10 changes: 10 additions & 0 deletions src/Foldunk/Foldunk.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ type StreamToken = { value : obj }
/// Foldunk-internal representation of a current known state of the stream, including the concurrency token (e.g. Stream Version number)
type StreamState<'state,'event> = StreamToken * 'state option * 'event list

/// Helpers for derivation of a StreamState - shared between EventStore and InMemoryStore
module StreamState =
/// Represent a [possibly compacted] array of events with a known token from a store.
let ofTokenAndEvents (token : StreamToken) (events: 'event seq) = token, None, List.ofSeq events
/// Represent a state known to have been persisted to the store
let ofTokenAndKnownState token state = token, Some state, []
/// Represent a state to be composed from a snapshot together with the successor events
let ofTokenSnapshotAndEvents token stateSnapshot (successorEvents : 'event list) =
token, Some stateSnapshot, successorEvents

/// Maintains state associated with a Command Handling flow
type DecisionState<'event, 'state>(fold, originState : 'state) =
let accumulated = ResizeArray<'event>()
Expand Down
1 change: 0 additions & 1 deletion src/Foldunk/Foldunk.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<Compile Include="Serialization.fs" />
<Compile Include="EventSum.fs" />
<Compile Include="Foldunk.fs" />
<Compile Include="MemoryStreamStore.fs" />
</ItemGroup>
<ItemGroup>
<Reference Include="mscorlib" />
Expand Down

0 comments on commit 2e371b1

Please sign in to comment.