Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
updated JSON.NET + added root caching mechanism in DefaultViewContext…
Browse files Browse the repository at this point in the history
… + some other stuff
  • Loading branch information
mookid8000 committed Dec 17, 2015
1 parent a4fb86e commit 7c0d5ac
Show file tree
Hide file tree
Showing 44 changed files with 52,583 additions and 58,592 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -735,10 +735,11 @@

* Making InMemoryEventStore and InMemoryUnitOfWork testing tools public to ease implementing custom event dispatchers

## 0.63.16
## 0.64.0

* Fixed `Kind` of `DateTime` retrieved by `MsSqlViewManager` to be UTC because that's what it is. The really short version of the description of this problem is: Use `DateTimeOffset`s instead. They are explicit about the fact that they are just a UTC timestamp.
* Added Sunshine Scenario Aggregate Root Load Caching mechanism in `DefaultViewContext` which can provide a nice acceleration in Sunshine Scenarios.
* Updated internal Newtonsoft JSON serializer to 7.0.1

[asgerhallas]: https://github.com/asgerhallas
[kimbirkelund]: https://github.com/kimbirkelund
Expand Down
14 changes: 2 additions & 12 deletions build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<NuSpecFolder>$(Root)\nuspec</NuSpecFolder>
<ToolsFolder>$(Root)\tools</ToolsFolder>
<NuGetFolder>$(ToolsFolder)\NuGet</NuGetFolder>
<DefaultNuSpecVersion>$version$</DefaultNuSpecVersion>
<ReleaseMaster>$(ToolsFolder)\ReleaseMaster\ReleaseMaster.exe</ReleaseMaster>
<IlMerge>$(ToolsFolder)\IlMerge\ilmerge.exe</IlMerge>
</PropertyGroup>
Expand All @@ -27,18 +26,9 @@
</Target>

<Target Name="release_packages" DependsOnTargets="validate_version_is_present">
<Error Condition="'$(NuggieRepoPath)' == ''"
Text="Cannot publish packages because the NuggieRepoPath environment variable has not been set."/>

<!--<Message Text="Updating NuSpec version..."/>
<XmlPoke XmlInputPath="%(NuSpecFiles.FullPath)" Query="//version" Value="$(Version)" />
<XmlPoke XmlInputPath="%(DependantNuSpecFiles.FullPath)" Query="//dependency[starts-with(@id, 'd60.Cirqus')]/@version" Value="$(Version)" />-->
<Error Condition="'$(NuggieRepoPath)' == ''" Text="Cannot publish packages because the NuggieRepoPath environment variable has not been set."/>

<CallTarget Targets="publish_packages"/>

<!--<XmlPoke XmlInputPath="%(NuSpecFiles.FullPath)" Query="//version" Value="$(DefaultNuSpecVersion)" />
<XmlPoke XmlInputPath="%(DependantNuSpecFiles.FullPath)" Query="//dependency[starts-with(@id, 'd60.Cirqus')]/@version" Value="$(DefaultNuSpecVersion)" />-->
</Target>

<Target Name="build" DependsOnTargets="clean_output_folder; build_solution" />
Expand Down Expand Up @@ -117,4 +107,4 @@
<Error Condition="'$(NuggieRepoPath)' == ''"
Text="In order to publish NuGet packages you need to define an environment variable NuggieRepoPath to point to our NuGet repository in Dropbox"/>
</Target>
</Project>
</Project>
6 changes: 3 additions & 3 deletions d60.Cirqus.AzureServiceBus/d60.Cirqus.AzureServiceBus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
<Reference Include="Microsoft.WindowsAzure.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.WindowsAzure.ConfigurationManager.2.0.3\lib\net40\Microsoft.WindowsAzure.Configuration.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.6.0.5\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
2 changes: 1 addition & 1 deletion d60.Cirqus.AzureServiceBus/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.3" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.5" targetFramework="net45" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
<package id="WindowsAzure.ServiceBus" version="2.4.2.0" targetFramework="net45" />
</packages>
131 changes: 83 additions & 48 deletions d60.Cirqus.MongoDb/Events/MongoDbEventStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,90 @@ public MongoDbEventStore(MongoDatabase database, string eventCollectionName, boo

public IEnumerable<EventData> Stream(long globalSequenceNumber = 0)
{
var criteria = Query.GTE(GlobalSeqNoDocPath, globalSequenceNumber);
var lowerGlobalSequenceNumber = globalSequenceNumber;

return _eventBatches.Find(criteria)
.SelectMany(b => b.Events)
.OrderBy(e => e.GlobalSequenceNumber)
.Where(e => e.GlobalSequenceNumber >= globalSequenceNumber)
.Select(MongoEventToEvent);
while (true)
{
var criteria = Query.GTE(GlobalSeqNoDocPath, lowerGlobalSequenceNumber);

var eventBatch = _eventBatches.Find(criteria)
.SetSortOrder(SortBy.Ascending(GlobalSeqNoDocPath))
.SetLimit(1000)
.SelectMany(b => b.Events.OrderBy(e => e.GlobalSequenceNumber))
.Where(e => e.GlobalSequenceNumber >= lowerGlobalSequenceNumber)
.Select(MongoEventToEvent)
.ToList();

foreach (var e in eventBatch)
{
yield return e;
}

if (!eventBatch.Any()) break;

lowerGlobalSequenceNumber = eventBatch.Max(e => e.GetGlobalSequenceNumber()) + 1;
}
}

public IEnumerable<EventData> Load(string aggregateRootId, long firstSeq = 0)
{
// aggregation framework is extremely slow - don't use it (for this)
//var args = new AggregateArgs
//{
// Pipeline = new[]
// {
// new BsonDocument {{"$unwind", "$Events"}},
// new BsonDocument
// {
// {
// "$match", new BsonDocument
// {
// {"Events.AggregateRootId", aggregateRootId},
// {"Events.SequenceNumber", new BsonDocument {{"$gte", firstSeq}}},
// }
// }
// },
// new BsonDocument {{"$sort", new BsonDocument {{"Events.SequenceNumber", 1}}}}
// }
//};

//return _eventBatches.Aggregate(args)
// .Select(result =>
// {
// var bsonValue = result["Events"];
// var asBsonDocument = bsonValue.AsBsonDocument;
// return BsonSerializer.Deserialize<MongoEvent>(asBsonDocument);
// })
// .Select(MongoEventToEvent);

var lowerSequenceNumber = firstSeq;

while (true)
{
var eventCriteria = Query.And(Query.EQ("AggregateRootId", aggregateRootId),
Query.GTE("SequenceNumber", lowerSequenceNumber));

var criteria = Query.ElemMatch("Events", eventCriteria);

var eventBatch = _eventBatches.Find(criteria)
.SetSortOrder(SortBy.Ascending(GlobalSeqNoDocPath))
.SetLimit(1000)
.SelectMany(b => b.Events
.Where(e => e.AggregateRootId == aggregateRootId)
.OrderBy(e => e.SequenceNumber))
.Where(e => e.SequenceNumber >= lowerSequenceNumber)
.Select(MongoEventToEvent)
.ToList();

foreach (var e in eventBatch)
{
yield return e;
}

if (!eventBatch.Any()) break;

lowerSequenceNumber = eventBatch.Max(e => e.GetSequenceNumber()) + 1;
}
}

public long GetNextGlobalSequenceNumber()
Expand Down Expand Up @@ -169,48 +246,6 @@ Metadata GetDictionaryAsMetadata(Dictionary<string, string> dictionary)
return metadata;
}

public IEnumerable<EventData> Load(string aggregateRootId, long firstSeq = 0)
{
// aggregation framework is extremely slow - don't use it (for this)
//var args = new AggregateArgs
//{
// Pipeline = new[]
// {
// new BsonDocument {{"$unwind", "$Events"}},
// new BsonDocument
// {
// {
// "$match", new BsonDocument
// {
// {"Events.AggregateRootId", aggregateRootId},
// {"Events.SequenceNumber", new BsonDocument {{"$gte", firstSeq}}},
// }
// }
// },
// new BsonDocument {{"$sort", new BsonDocument {{"Events.SequenceNumber", 1}}}}
// }
//};

//return _eventBatches.Aggregate(args)
// .Select(result =>
// {
// var bsonValue = result["Events"];
// var asBsonDocument = bsonValue.AsBsonDocument;
// return BsonSerializer.Deserialize<MongoEvent>(asBsonDocument);
// })
// .Select(MongoEventToEvent);

var criteria = Query.And(
Query.EQ(AggregateRootIdDocPath, aggregateRootId),
Query.GTE(SeqNoDocPath, firstSeq));

return _eventBatches.Find(criteria)
.SelectMany(b => b.Events)
.OrderBy(e => e.GlobalSequenceNumber)
.Where(e => e.SequenceNumber >= firstSeq && e.AggregateRootId == aggregateRootId)
.Select(MongoEventToEvent);
}

EventData MongoEventToEvent(MongoEvent e)
{
var meta = GetDictionaryAsMetadata(e.Meta);
Expand Down
6 changes: 3 additions & 3 deletions d60.Cirqus.MongoDb/d60.Cirqus.MongoDb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\mongocsharpdriver.1.10.0\lib\net35\MongoDB.Driver.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.6.0.5\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
Expand Down
2 changes: 1 addition & 1 deletion d60.Cirqus.MongoDb/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="mongocsharpdriver" version="1.10.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.5" targetFramework="net45" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
</packages>
6 changes: 3 additions & 3 deletions d60.Cirqus.Testing/d60.Cirqus.Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.6.0.5\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
2 changes: 1 addition & 1 deletion d60.Cirqus.Testing/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="Newtonsoft.Json" version="6.0.5" targetFramework="net45" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
</packages>
4 changes: 2 additions & 2 deletions d60.Cirqus.Tests/Contracts/EventStore/EventStoreTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,10 @@ public void CanLoadEventsByAggregateRootId()
var allEventsForAgg2 = _eventStore.Load("agg2").ToList();

// assert
Assert.That(allEventsForAgg1.Count, Is.EqualTo(4));
Assert.That(allEventsForAgg1.Count, Is.EqualTo(4), "Expected to get events 0, 1, 3, 4, but got only {0}", string.Join(", ", allEventsForAgg1.Select(e => e.GetGlobalSequenceNumber())));
Assert.That(allEventsForAgg1.GetSeq(), Is.EqualTo(new[] { 0, 1, 3, 4 }));

Assert.That(allEventsForAgg2.Count, Is.EqualTo(2));
Assert.That(allEventsForAgg2.Count, Is.EqualTo(2), "Expected to get events 2, 5 but got only {0}", string.Join(", ", allEventsForAgg2.Select(e => e.GetGlobalSequenceNumber())));
Assert.That(allEventsForAgg2.GetSeq(), Is.EqualTo(new[] { 2, 5 }));
}

Expand Down
6 changes: 3 additions & 3 deletions d60.Cirqus.Tests/d60.Cirqus.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@
<HintPath>..\packages\Moq.4.2.1507.0118\lib\net40\Moq.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.6.0.5\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Npgsql, Version=2.1.3.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down
2 changes: 1 addition & 1 deletion d60.Cirqus.Tests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<package id="HybridDb" version="0.7.1" targetFramework="net45" />
<package id="mongocsharpdriver" version="1.10.0" targetFramework="net45" />
<package id="Moq" version="4.2.1507.0118" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.5" targetFramework="net45" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
<package id="Npgsql" version="2.1.3" targetFramework="net45" />
<package id="NUnit" version="2.6.3" targetFramework="net45" />
<package id="Serilog" version="1.4.1" targetFramework="net45" />
Expand Down
5 changes: 3 additions & 2 deletions d60.Cirqus.TsClient/d60.Cirqus.TsClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.6.0.5\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
2 changes: 1 addition & 1 deletion d60.Cirqus.TsClient/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="d60.Cirqus" version="0.24.1" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.5" targetFramework="net45" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
</packages>
8 changes: 8 additions & 0 deletions d60.Cirqus/Extensions/DictionaryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ namespace d60.Cirqus.Extensions
/// </summary>
public static class DictionaryExtensions
{
public static void InsertInto<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, IDictionary<TKey, TValue> otherDictionary)
{
foreach (var kvp in dictionary)
{
otherDictionary[kvp.Key] = kvp.Value;
}
}

/// <summary>
/// Gets the value from
/// </summary>
Expand Down
10 changes: 3 additions & 7 deletions d60.Cirqus/Views/DependentViewManagerEventDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,14 @@ void DispatchBatchToViewManagers(IEnumerable<IViewManager> viewManagers, IEnumer
.Select(e => _domainEventSerializer.Deserialize(e))
.ToList();

var context = new DefaultViewContext(_aggregateRootRepository, _domainTypeNameMapper, eventList);

foreach (var kvp in _viewContextItems)
{
context.Items[kvp.Key] = kvp.Value;
}

foreach (var viewManager in viewManagers)
{
var thisParticularPosition = positions[viewManager].Position;
if (thisParticularPosition >= eventList.Max(e => e.GetGlobalSequenceNumber())) continue;

var context = new DefaultViewContext(_aggregateRootRepository, _domainTypeNameMapper, eventList);
_viewContextItems.InsertInto(context.Items);

_logger.Debug("Dispatching batch of {0} events to {1}", eventList.Count, viewManager);

viewManager.Dispatch(context, eventList, _viewManagerProfiler);
Expand Down
10 changes: 3 additions & 7 deletions d60.Cirqus/Views/ViewManagerEventDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,18 +350,14 @@ void DispatchBatchToViewManagers(IEnumerable<IViewManager> viewManagers, IEnumer
.Select(e => _domainEventSerializer.Deserialize(e))
.ToList();

var context = new DefaultViewContext(_aggregateRootRepository, _domainTypeNameMapper, eventList);

foreach (var kvp in _viewContextItems)
{
context.Items[kvp.Key] = kvp.Value;
}

foreach (var viewManager in viewManagers)
{
var thisParticularPosition = positions[viewManager].Position;
if (thisParticularPosition >= eventList.Max(e => e.GetGlobalSequenceNumber())) continue;

var context = new DefaultViewContext(_aggregateRootRepository, _domainTypeNameMapper, eventList);
_viewContextItems.InsertInto(context.Items);

_logger.Debug("Dispatching batch of {0} events to {1}", eventList.Count, viewManager);

viewManager.Dispatch(context, eventList, _viewManagerProfiler);
Expand Down
Loading

0 comments on commit 7c0d5ac

Please sign in to comment.