Skip to content

Remove publish steps #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 68 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
b3b0276
Updated README to provide detailed usage scenarios
mikegore1000 Jan 25, 2017
754d3ae
Added support for parameterising the build
asosMikeGore Mar 9, 2017
ac92bb7
Enabled nuget packaging & deploy
asosMikeGore Mar 9, 2017
3a5a17c
Fixed parameter naming issue with the PS bootstrapper
asosMikeGore Mar 9, 2017
1befc9b
Removed redundant guard statement
mikegore1000 May 16, 2017
d8d7998
Improved EventData test coverage
mikegore1000 May 16, 2017
5cf6c14
Added StorageEventTests
mikegore1000 May 16, 2017
638c2e4
Added MIT license
Jun 9, 2017
3c8a872
Amended licence copyright holder to be ASOS
Jun 9, 2017
a47a35f
Merge pull request #1 from DaveAurionix/master
asosMikeGore Jun 9, 2017
541b91c
Fix for issue #7: https://github.com/ASOS/SimpleEventStore/issues/7
Jun 23, 2017
270e9d0
Merge pull request #8 from DaveAurionix/partitionkeyrangefix
asosMikeGore Jun 23, 2017
d36a3dc
Ensured consistency levels are configurable to fix issue #10
mikegore1000 Jun 27, 2017
d773f44
Removed generic T argument
mikegore1000 Jun 27, 2017
2d002c7
Committed initial compile success - need to migrate the build process…
mikegore1000 Jun 27, 2017
1fb2ccd
Current WIP on build script - not complete. Need to move to use dotn…
mikegore1000 Jun 27, 2017
3520894
Migrated build process up to unit test passing and fixed
mikegore1000 Jun 27, 2017
6f37e00
Removed redundant comments from build script.
mikegore1000 Jun 27, 2017
f1d418e
Altered build process to ensure everything apart from nuget package p…
mikegore1000 Jun 27, 2017
6a6513d
Fixed package path issue
mikegore1000 Jun 27, 2017
3ed7506
Added support for .NET 4.6.1 on top of netstandard 1.6
mikegore1000 Jun 28, 2017
e3efded
Corrected documentation issue #11
mikegore1000 Jun 28, 2017
dee9c94
Implemented a builder for the AzureDocumentDbStorageEngine (#3) and a…
mikegore1000 Jun 29, 2017
c93728e
Ensure that when subscription options haven't been specified then an …
mikegore1000 Jun 29, 2017
fa799b2
Updated docs due to changes for issue #3
mikegore1000 Jun 29, 2017
1eac9be
Corrected docs for #12 #3
mikegore1000 Jun 29, 2017
30c6cf4
Corrected doc formatting #12 #3
mikegore1000 Jun 29, 2017
238cb9c
Initial implementation for logging improvement for #5. Only supports…
mikegore1000 Jul 5, 2017
deedbe5
Enabled support for custom type names to be specified for the event b…
mikegore1000 Jul 7, 2017
6be7c8e
Corrected tests so they return a Task rather than void
mikegore1000 Jul 12, 2017
16411f6
Initial commit to support issues #4 & #9. Need to add missing tests …
mikegore1000 Jul 12, 2017
31a8758
Added missing tests to check subscription stop & start work as intended.
mikegore1000 Jul 14, 2017
d6aaa5d
Added missing package references for VS/Rider unit test debugging.
mikegore1000 Jul 15, 2017
6a52b93
Fixed failing tests due to auto-generated proxy types.
mikegore1000 Jul 15, 2017
f4c6fd1
Ensured that subcription tasks don't cancel before they can start. T…
mikegore1000 Jul 15, 2017
076b578
Added support for .NET Framework 4.5.2 upwards
mikegore1000 Aug 11, 2017
3230970
Fixed build script and targeting for tests
mikegore1000 Aug 11, 2017
1de8ba3
Update README.md
britebit Aug 30, 2017
b926be6
Removed support for subscriptions
mikegore1000 Sep 19, 2017
2cafc27
Changed package name to include Asos as a prefix
mikegore1000 Sep 19, 2017
3052314
Removed references to subscriptions in the README
mikegore1000 Sep 19, 2017
061c4b1
Updated build script so nuget settings are passed in as strings
mikegore1000 Sep 19, 2017
65c8a74
Updated csproj to add ASOS as the nuget package author
mikegore1000 Sep 19, 2017
b9d27e0
Merge pull request #16 from britebit/britebit-patch-2
asosMikeGore Sep 21, 2017
dc77f3f
Altered build script to ensure assembly versions match package versio…
mikegore1000 Sep 21, 2017
3548046
Corrected build script issue where PackageVersion was used twice rath…
mikegore1000 Sep 22, 2017
5f6e016
Altered build script to see if it fixes Version override issues on th…
mikegore1000 Sep 22, 2017
c41f987
Altered build scripts and projects so we pass in the PackageVersion a…
mikegore1000 Sep 22, 2017
98205f5
Fix KeyNotFoundException when reading an empty stream
ralphwillgoss Oct 11, 2017
9b6bc72
Simplied code to initalise Cosmos database & collection
mikegore1000 Oct 15, 2017
748997c
Merge branch 'ralphwillgoss-master'
mikegore1000 Oct 15, 2017
58ae1a0
Simplified in-memory storage engine
mikegore1000 Oct 15, 2017
622612d
Updated build script to use explicit versions for addins
mikegore1000 Oct 16, 2017
7aaa4c3
Build uses explicit versions for add-ins
asosMikeGore Oct 16, 2017
3c7d19b
Merge branch 'master' of https://github.com/ASOS/SimpleEventStore
mikegore1000 Oct 21, 2017
a9b3844
Updated XUnit for .NET Core SDK 2 only build agents
mikegore1000 Oct 21, 2017
eb86101
Revert "Updated XUnit for .NET Core SDK 2 only build agents"
mikegore1000 Oct 21, 2017
1db527f
Tests now use NUnit. All packages have been upgraded.
mikegore1000 Oct 22, 2017
6dfea14
Test projects now target .NET Core 2.0
mikegore1000 Oct 22, 2017
36010db
Added VS code launch & tasks files
mikegore1000 Oct 22, 2017
086b11b
Collection level time to live support. Resolves #23
mikegore1000 Nov 9, 2017
41fed8f
Match file case for appendToStream.js
Aug 6, 2018
a58f45e
Merge pull request #29 from searbe/fix-resource-case-sensitivity
asosMikeGore Aug 7, 2018
3b0b7a2
Match case when retrieving appendToStream.js via Resources
Sep 7, 2018
cc5499a
Merge pull request #30 from searbe/fix-resource-case-sensitivity
asosMikeGore Sep 13, 2018
ff59f4f
Ability to log response metrics by action performed so can differenti…
tony-gamble-asos Sep 13, 2018
4f04f76
Update to latest CosmosDB package version
Oct 4, 2018
19db7ef
Removed publishing to nuget task
mikegore1000 Dec 3, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
22 changes: 22 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"command": "powershell",
"options": {
"cwd": "${workspaceRoot}/build"
},
"args": [
"./build.ps1",
"-ConsistencyLevel",
"Session"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
}
]
}
21 changes: 21 additions & 0 deletions License.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 ASOS

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
88 changes: 87 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,87 @@
# SimpleEventStore
# Simple Event Store

Simple Event Store (SES) provides a lightweight event sourcing abstraction.

## Key Features
- Full support for async/await for all persistence engines
- Optimistic concurrency for append operations
- Reading streams forward

## Persistence Engines
SES supports the following
- Azure Cosmos DB
- In Memory

All persistence engines run the same test scenarios to ensure feature parity. At present only the Cosmos DB persistence engine should be considered for production usage.

## Usage

### Creation
```csharp
var storageEngine = new InMemoryStorageEngine();
var eventStore = new EventStore(storageEngine);
```
Do not use storage engines directly, only interact with the event store using the EventStore class. There should only be a single instance of the EventStore per process. Creating transient instances will lead to a decrease in performance.

### Appending Events
```csharp
var expectedRevision = 0;

await eventStore.AppendToStream(streamId, expectedRevision, new EventData(Guid.NewGuid(), new OrderCreated(streamId)));
```
The expected stream revision would either be set to 0 for a new stream, or to the expected event number. If the latest event number in the database differs then a concurrency exception will be thrown.

### Reading Events
```csharp
var events = await eventStore.ReadStreamForwards(streamId, startPosition: 2, numberOfEventsToRead: 1);
// or
var events = await subject.ReadStreamForwards(streamId);
```
You can either read all events in a stream, or a subset of events. Only read all events if you know the maximum size of a stream is going to be low and that you always need to read all events as part of your workload e.g. replaying events to project current state for a DDD aggregate.

## Cosmos DB
```csharp
DocumentClient client; // Set this up as required

// If UseCollection isn't specified, sensible defaults for development are used.
// If UseSubscriptions isn't supplied the subscription feature is disabled.
return await new AzureDocumentDbStorageEngineBuilder(client, databaseName)
.UseCollection(o =>
{
o.ConsistencyLevel = consistencyLevelEnum;
o.CollectionRequestUnits = 400;
})
.UseLogging(o =>
{
o.Success = onSuccessCallback;
})
.UseTypeMap(new ConfigurableSerializationTypeMap()
.RegisterTypes(
typeof(OrderCreated).GetTypeInfo().Assembly,
t => t.Namespace.EndsWith("Events"),
t => t.Name))
.Build()
.Initialise();
```
### CollectionOptions
Allows you to specify
- The consistency level of the database
- The default number of RUs when the collection is created
- The collection name

Only use one of the following consistency levels
- Strong
- Bounded Staleness - use this if you need to geo-replicate the database

### UseLogging
Sets up callbacks per Cosmos DB operation performed. This is useful if you want to record per call data e.g. RU cost of each operation.

### UseTypeMap
Allows you to control the event body/metadata type names. Built in implementations
- DefaultSerializationTypeMap - uses the AssemblyQualifiedName of the type. (default)
- ConfigurableSerializationTypeMap - provides full control.

While the default implementation is simple, this isn't great for versioning as contract assembly version number changes will render events unreadable. Therefore the configurable implementation or your own implementation is recommended.

### Initialise
Calling the operation creates the underlying collection based on the DatabaseOptions. This ensures the required stored procedure is present too. It is safe to call this multiple times.
78 changes: 69 additions & 9 deletions build/build.cake
Original file line number Diff line number Diff line change
@@ -1,41 +1,101 @@
#tool "nuget:?package=xunit.runner.console"
#addin nuget:?package=Cake.Json&version=1.0.2.13
#addin nuget:?package=Newtonsoft.Json&version=9.0.1

//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////

var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var uri = Argument("uri", "https://localhost:8081/");
var authKey = Argument("authKey", "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==");
var consistencyLevel = Argument("consistencyLevel", "BoundedStaleness");
var buildVersion = Argument("buildVersion", "1.0.0");

//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////

// Define directories.
var solutionFile = "../src/SimpleEventStore/SimpleEventStore.sln";
var solutionDir = "../src/SimpleEventStore/";
var solutionFile = solutionDir + "SimpleEventStore.sln";
var testProjs = GetFiles(solutionDir + "**/*.Tests.csproj");
var outputDir = "./nuget";

//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////

Task("Restore-NuGet-Packages")
Task("Restore-Packages")
.Does(() =>
{
NuGetRestore(solutionFile);
DotNetCoreRestore(solutionDir);
});

Task("Clean")
.Does(() =>
{
CleanDirectory(outputDir);
});

Task("Build")
.IsDependentOn("Restore-NuGet-Packages")
.IsDependentOn("Clean")
.IsDependentOn("Restore-Packages")
.Does(() =>
{
DotNetCoreBuild(solutionFile, new DotNetCoreBuildSettings {
Configuration = configuration,
NoIncremental = true,
ArgumentCustomization = args => args.Append("/p:BuildVersion=" + buildVersion)
});
});

Task("Transform-Unit-Test-Config")
.Does(() =>
{
// Use MSBuild
MSBuild(solutionFile, settings => settings.SetConfiguration(configuration));
var documentDbTestConfigFiles = GetFiles(solutionDir + "SimpleEventStore.AzureDocumentDb.Tests/bin/" + configuration + "/**/appsettings.json");

foreach(var documentDbTestConfigFile in documentDbTestConfigFiles)
{
var configJson = ParseJsonFromFile(documentDbTestConfigFile);
configJson["Uri"] = uri;
configJson["AuthKey"] = authKey;
configJson["ConsistencyLevel"] = consistencyLevel;

SerializeJsonToFile(documentDbTestConfigFile, configJson);

Information("Transformed " + documentDbTestConfigFile);
}
});

Task("Run-Unit-Tests")
.IsDependentOn("Build")
.IsDependentOn("Transform-Unit-Test-Config")
.Does(() =>
{
XUnit2("../src/**/bin/" + configuration + "/*.Tests.dll");
foreach(var testPath in testProjs)
{
DotNetCoreTest(testPath.FullPath, new DotNetCoreTestSettings {
Configuration = configuration,
NoBuild = true
});
}
});

Task("Package")
.IsDependentOn("Build")
.IsDependentOn("Run-Unit-Tests")
.Does(() =>
{
var settings = new DotNetCorePackSettings {
Configuration = configuration,
NoBuild = true,
OutputDirectory = outputDir,
ArgumentCustomization = args => args.Append("/p:BuildVersion=" + buildVersion)
};

DotNetCorePack("./../src/SimpleEventStore/SimpleEventStore/", settings);
DotNetCorePack("./../src/SimpleEventStore/SimpleEventStore.AzureDocumentDb/", settings);
});

//////////////////////////////////////////////////////////////////////
Expand All @@ -49,4 +109,4 @@ Task("Default")
// EXECUTION
//////////////////////////////////////////////////////////////////////

RunTarget(target);
RunTarget(target);
11 changes: 9 additions & 2 deletions build/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ Param(
[string]$Target = "Default",
[ValidateSet("Release", "Debug")]
[string]$Configuration = "Release",
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
# TODO: Tidy up and revert back to standard Cake bootstrapper, shouldn't need config in here
[string]$Uri = "https://localhost:8081/",
[string]$AuthKey = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
[string]$ConsistencyLevel = "BoundedStaleness",
[string]$BuildVersion = "1.0.0",
[string]$NugetSource,
[string]$NugetApiKey,
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
[string]$Verbosity = "Verbose",
[switch]$Experimental,
[Alias("DryRun","Noop")]
Expand Down Expand Up @@ -185,5 +192,5 @@ if (!(Test-Path $CAKE_EXE)) {

# Start Cake
Write-Host "Running build script..."
Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs"
Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" -uri=$Uri -authKey=$AuthKey -consistencyLevel=$ConsistencyLevel -buildVersion=`"$BuildVersion`" -nugetSource=`"$NugetSource`" -nugetApiKey=`"$NugetApiKey`" $UseMono $UseDryRun $UseExperimental $ScriptArgs"
exit $LASTEXITCODE
2 changes: 1 addition & 1 deletion build/tools/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Cake" version="0.17.0" />
<package id="Cake" version="0.20.0" />
</packages>
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;
using Microsoft.Azure.Documents.Linq;
using NUnit.Framework;

namespace SimpleEventStore.AzureDocumentDb.Tests
{
[TestFixture]
public class AzureDocumentDBEventStoreInitializing
{
private const string DatabaseName = "InitializeTests";

[OneTimeTearDown]
public async Task TearDownDatabase()
{
var client = DocumentClientFactory.Create(DatabaseName);
await client.DeleteDatabaseAsync(UriFactory.CreateDatabaseUri(DatabaseName));
}

[Test]
public async Task when_initializing_all_expected_resources_are_created()
{
var client = DocumentClientFactory.Create(DatabaseName);
var collectionName = "AllExpectedResourcesAreCreated_" + Guid.NewGuid();
var storageEngine = await StorageEngineFactory.Create(DatabaseName, o => o.CollectionName = collectionName);

await storageEngine.Initialise();

var database = (await client.ReadDatabaseAsync(UriFactory.CreateDatabaseUri(DatabaseName))).Resource;
var collection = (await client.ReadDocumentCollectionAsync(UriFactory.CreateDocumentCollectionUri(DatabaseName, collectionName))).Resource;
var storedProcedure = (await client.ReadStoredProcedureAsync(UriFactory.CreateStoredProcedureUri(DatabaseName, collectionName, TestConstants.AppendStoredProcedureName))).Resource;
var offer = client.CreateOfferQuery()
.Where(r => r.ResourceLink == collection.SelfLink)
.AsEnumerable()
.OfType<OfferV2>()
.Single();

Assert.That(offer.Content.OfferThroughput, Is.EqualTo(TestConstants.RequestUnits));
Assert.That(collection.DefaultTimeToLive, Is.Null);
Assert.That(collection.PartitionKey.Paths.Count, Is.EqualTo(1));
Assert.That(collection.PartitionKey.Paths.Single(), Is.EqualTo("/streamId"));
Assert.That(collection.IndexingPolicy.IncludedPaths.Count, Is.EqualTo(1));
Assert.That(collection.IndexingPolicy.IncludedPaths[0].Path, Is.EqualTo("/*"));
Assert.That(collection.IndexingPolicy.ExcludedPaths.Count, Is.EqualTo(2));
Assert.That(collection.IndexingPolicy.ExcludedPaths[0].Path, Is.EqualTo("/body/*"));
Assert.That(collection.IndexingPolicy.ExcludedPaths[1].Path, Is.EqualTo("/metadata/*"));
}

[Test]
public async Task when_initializing_with_a_time_to_live_it_is_set()
{
var ttl = 60;
var collectionName = "TimeToLiveIsSet_" + Guid.NewGuid();
var client = DocumentClientFactory.Create(DatabaseName);
var storageEngine = await StorageEngineFactory.Create(DatabaseName, o =>
{
o.CollectionName = collectionName;
o.DefaultTimeToLive = ttl;
});

await storageEngine.Initialise();

var collection = (await client.ReadDocumentCollectionAsync(UriFactory.CreateDocumentCollectionUri(DatabaseName, collectionName))).Resource;
Assert.That(collection.DefaultTimeToLive, Is.EqualTo(ttl));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using System.Threading.Tasks;
using NUnit.Framework;
using SimpleEventStore.Tests;

namespace SimpleEventStore.AzureDocumentDb.Tests
{
[TestFixture]
public class AzureDocumentDbEventStoreAppending : EventStoreAppending
{
protected override Task<IStorageEngine> CreateStorageEngine()
{
return StorageEngineFactory.Create("AppendingTests"); ;
return StorageEngineFactory.Create("AppendingTests");
}
}
}
Loading