Skip to content

Commit

Permalink
Fixing #8
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzoukr committed Jan 20, 2019
1 parent d822308 commit 817481c
Show file tree
Hide file tree
Showing 13 changed files with 2,699 additions and 1,139 deletions.
6 changes: 6 additions & 0 deletions CosmoStore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "CosmoStore", "src\CosmoStor
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "CosmoStore.Tests", "tests\CosmoStore.Tests\CosmoStore.Tests.fsproj", "{7C9EF46C-93C5-4037-8860-2EF29FADC455}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "CosmoStore.PerformanceTests", "tests\CosmoStore.PerformanceTests\CosmoStore.PerformanceTests.fsproj", "{C88CBEE6-EEBD-4A91-BEA3-FDAD3A1BFBDE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,10 @@ Global
{7C9EF46C-93C5-4037-8860-2EF29FADC455}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7C9EF46C-93C5-4037-8860-2EF29FADC455}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7C9EF46C-93C5-4037-8860-2EF29FADC455}.Release|Any CPU.Build.0 = Release|Any CPU
{C88CBEE6-EEBD-4A91-BEA3-FDAD3A1BFBDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C88CBEE6-EEBD-4A91-BEA3-FDAD3A1BFBDE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C88CBEE6-EEBD-4A91-BEA3-FDAD3A1BFBDE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C88CBEE6-EEBD-4A91-BEA3-FDAD3A1BFBDE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 1.5.1 - January 20 2019
* Fixing #8

### 1.5.0 - January 02 2019
* Added GetStream function (mentioned in #7)

Expand Down
38 changes: 26 additions & 12 deletions paket.dependencies
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
source https://api.nuget.org/v3/index.json

nuget FSharp.Core = 4.3.1
nuget TaskBuilder.fs !~> 2 lowest_matching: true
nuget Newtonsoft.Json !~> 11 lowest_matching: true
nuget Microsoft.Azure.DocumentDB.Core !~> 2 lowest_matching: true
nuget WindowsAzure.Storage !~> 9 lowest_matching: true
nuget System.Reactive !~> 4 lowest_matching: true
version 5.193.0
group Library
source https://api.nuget.org/v3/index.json
storage: none
nuget FSharp.Core = 4.3.1
nuget TaskBuilder.fs !~> 2 lowest_matching: true
nuget Newtonsoft.Json !~> 11 lowest_matching: true
nuget Microsoft.Azure.DocumentDB.Core !~> 2 lowest_matching: true
nuget WindowsAzure.Storage !~> 9 lowest_matching: true
nuget System.Reactive !~> 4 lowest_matching: true

nuget NUnit
nuget NUnit3TestAdapter
nuget Microsoft.NET.Test.Sdk
nuget FSharp.Control.Reactive
group Tests
source https://api.nuget.org/v3/index.json
storage: none
nuget FSharp.Core
nuget NUnit
nuget NUnit3TestAdapter
nuget Microsoft.NET.Test.Sdk
nuget FSharp.Control.Reactive
nuget Microsoft.Azure.DocumentDB.Core

group Build
source https://api.nuget.org/v3/index.json
storage: none
nuget FSharp.Core
nuget Fake.DotNet.Cli
nuget Fake.Core.Target
nuget Fake.IO.FileSystem
nuget Fake.DotNet.Testing.NUnit
nuget Fake.Core.ReleaseNotes

group PerformanceTests
source https://api.nuget.org/v3/index.json
storage: none
nuget FSharp.Core
nuget BenchmarkDotNet
3,692 changes: 2,589 additions & 1,103 deletions paket.lock

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions src/CosmoStore/CosmosDb/EventStore.fs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,11 @@ let getEventStore (configuration:Configuration) =
}

AppendEvents = fun stream pos events -> task {
let! events = appendEvents getRequestOptions client appendEventProcUri stream pos events
events |> List.iter eventAppended.Trigger
return events
if events |> List.isEmpty then return []
else
let! events = appendEvents getRequestOptions client appendEventProcUri stream pos events
events |> List.iter eventAppended.Trigger
return events
}

GetEvent = getEvent client eventsCollectionUri
Expand Down
8 changes: 5 additions & 3 deletions src/CosmoStore/TableStorage/EventStore.fs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,11 @@ let getEventStore (configuration:Configuration) =
return events |> List.head
}
AppendEvents = fun stream pos events -> task {
let! events = appendEvents table stream pos events
events |> List.iter eventAppended.Trigger
return events
if events |> List.isEmpty then return []
else
let! events = appendEvents table stream pos events
events |> List.iter eventAppended.Trigger
return events
}
GetEvent = getEvent table
GetEvents = getEvents table
Expand Down
13 changes: 7 additions & 6 deletions src/CosmoStore/paket.references
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FSharp.Core
TaskBuilder.fs
Newtonsoft.Json
Microsoft.Azure.DocumentDB.Core
WindowsAzure.Storage
System.Reactive
group Library
FSharp.Core
TaskBuilder.fs
Newtonsoft.Json
Microsoft.Azure.DocumentDB.Core
WindowsAzure.Storage
System.Reactive
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
<Import Project="..\..\.paket\Paket.Restore.targets" />
</Project>
8 changes: 8 additions & 0 deletions tests/CosmoStore.PerformanceTests/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Learn more about F# at http://fsharp.org

open System

[<EntryPoint>]
let main argv =
printfn "Hello World from F#!"
0 // return an integer exit code
3 changes: 3 additions & 0 deletions tests/CosmoStore.PerformanceTests/paket.references
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
group PerformanceTests
FSharp.Core
BenchmarkDotNet
30 changes: 26 additions & 4 deletions tests/CosmoStore.Tests/BasicTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module CosmosDb =
CosmoStore.CosmosDb.Configuration.CreateDefault
(Uri "https://localhost:8081")
"C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="
|> fun cfg -> { cfg with DatabaseName = "CosmosStoreTests" }

let getCleanEventStore() =
let client = new DocumentClient(config.ServiceEndpoint, config.AuthKey)
Expand All @@ -29,13 +30,13 @@ module CosmosDb =

module TableStorage =
open Microsoft.WindowsAzure.Storage

let private conf = Configuration.CreateDefaultForLocalEmulator()
let private tableName = "CosmosStoreTests"
let private conf = Configuration.CreateDefaultForLocalEmulator() |> fun cfg -> { cfg with TableName = tableName }

let getCleanEventStore() =
let account = CloudStorageAccount.DevelopmentStorageAccount
let client = account.CreateCloudTableClient()
let table = client.GetTableReference("Events")
let table = client.GetTableReference(tableName)
try
table.DeleteIfExistsAsync() |> Async.AwaitTask |> Async.RunSynchronously |> ignore
with _ -> ()
Expand Down Expand Up @@ -301,4 +302,25 @@ let ``Appends events`` ([<Values(StoreType.CosmosDB, StoreType.TableStorage)>] (
|> (fun er ->
er |> List.fold checkCreation DateTime.MinValue |> ignore
er |> List.fold checkPosition 0L |> ignore
)
)

[<Test>]
let ``Appending no events does not affect stream metadata`` ([<Values(StoreType.CosmosDB, StoreType.TableStorage)>] (typ:StoreType)) =
let store = typ |> getEventStore
let streamId = getStreamId()

// append single event
0 |> getEvent |> store.AppendEvent streamId (ExpectedPosition.Exact(1L)) |> Async.AwaitTask |> Async.RunSynchronously |> ignore

let stream = store.GetStream streamId |> Async.AwaitTask |> Async.RunSynchronously

// append empty events
List.empty
|> List.map getEvent
|> store.AppendEvents streamId ExpectedPosition.Any
|> Async.AwaitTask
|> Async.RunSynchronously
|> ignore

let streamAfterAppend = store.GetStream streamId |> Async.AwaitTask |> Async.RunSynchronously
Assert.AreEqual(stream, streamAfterAppend)
3 changes: 2 additions & 1 deletion tests/CosmoStore.Tests/CosmoStore.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<Compile Include="BasicTests.fs" />
Expand Down
15 changes: 8 additions & 7 deletions tests/CosmoStore.Tests/paket.references
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
NUnit
NUnit3TestAdapter
Microsoft.NET.Test.Sdk
FSharp.Core
Newtonsoft.Json
Microsoft.Azure.DocumentDB.Core
FSharp.Control.Reactive
group Tests
FSharp.Core
NUnit
NUnit3TestAdapter
Microsoft.NET.Test.Sdk
Newtonsoft.Json
Microsoft.Azure.DocumentDB.Core
FSharp.Control.Reactive

0 comments on commit 817481c

Please sign in to comment.