Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
50ac7d6
Newtonsoft JSON - based event adapter with field update capability.
Sep 30, 2016
f385278
sub-property & collection items upgrade
andreyleskov Oct 1, 2016
3297653
Moved classes to files
andreyleskov Oct 1, 2016
53f8ed1
Simplifying object adapter & code cleanup
andreyleskov Oct 1, 2016
a458aff
test class rename
andreyleskov Oct 1, 2016
7a49a34
Simplified events upgrade chain algorithm
andreyleskov Oct 1, 2016
6b33842
Adding Json event adapter to GridDomain
andreyleskov Oct 1, 2016
f16cf10
saving events in unicode format to allow sql server produce human-rea…
andreyleskov Oct 1, 2016
c826d8e
nunit packages version upgrade, moved test to acceptance project
Oct 3, 2016
6737e6a
Upgrade nunit to 3.4.1
Oct 3, 2016
fe4a12c
reference to nunit upgrade
Oct 3, 2016
5751812
reference to nunit upgrade
Oct 3, 2016
cb79319
Revert "reference to nunit upgrade"
Oct 3, 2016
18abecf
removed schema declaration witch lead to null reference exception fro…
Oct 3, 2016
868e9ce
Fixed packages issues
Oct 4, 2016
f82de4e
sql schema updated to latest akka.persistence.sql
Oct 4, 2016
aed35c8
Merge branch 'master' into #46_smart_event_adapters
Oct 25, 2016
2056856
green tests without message serialization
Oct 25, 2016
064bf33
updating references
Oct 25, 2016
1c5453a
extracted methods for save\load messages directly from journal
Oct 25, 2016
a800468
Green test for domain event serializers adapters
Oct 25, 2016
c33da12
disabled json serializer for a while
Oct 25, 2016
31f53ea
Already persisted domain events by wire 0.0.6 can be automatically co…
Oct 25, 2016
6e90a97
container configuration order change
Oct 26, 2016
95f01d3
Added tests for events upgrade from legacy wire 0.0.6 format
Oct 26, 2016
fb2a294
Adding legacy wire 0.0.6 dll to support already persisted data
Oct 26, 2016
bd1d390
Separated tests for wire persisted events update to json
Oct 26, 2016
f5b66e0
fixing acceptance tests
Oct 26, 2016
0b9821a
Changed ObjectAdapter class, all tests for events upgrade are green
Oct 26, 2016
1089223
Correct sql schema for db creation
Oct 27, 2016
4fb0386
Removed custom serializer property from GridNode, small adjustments f…
Oct 27, 2016
af992fd
New class for registering ObjectAdapters
Oct 27, 2016
f636dcc
actor hocon config changes
Oct 27, 2016
ef8dd12
hocon config for release configuration changes
Oct 27, 2016
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
4 changes: 2 additions & 2 deletions AkkaClusterTests/AkkaClusterTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=3.0.5797.27534, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.0.0\lib\net45\nunit.framework.dll</HintPath>
<Reference Include="nunit.framework, Version=3.4.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.4.1\lib\net45\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
2 changes: 1 addition & 1 deletion AkkaClusterTests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<package id="Google.ProtocolBuffers" version="2.4.1.555" targetFramework="net461" />
<package id="Helios" version="2.1.2" targetFramework="net461" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net461" />
<package id="NUnit" version="3.0.0" targetFramework="net461" />
<package id="NUnit" version="3.4.1" targetFramework="net461" />
<package id="System.Collections" version="4.0.11" targetFramework="net461" />
<package id="System.Collections.Immutable" version="1.1.36" targetFramework="net461" />
<package id="System.Diagnostics.Debug" version="4.0.11" targetFramework="net461" />
Expand Down
6 changes: 6 additions & 0 deletions GridDomain.Common/GridDomain.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,19 @@
<Compile Include="DateTimeStrategyHolder.cs" />
<Compile Include="ExceptionExtensions.cs" />
<Compile Include="IContainerConfiguration.cs" />
<Compile Include="LegacyWireSerializer.cs" />
<Compile Include="MemberNameExtractor.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TasksExtensions.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="LegacyBinaries\LegacyWire_0.0.6.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</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.
Expand Down
Binary file not shown.
67 changes: 67 additions & 0 deletions GridDomain.Common/LegacyWireSerializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;

namespace GridDomain.Common
{
public class LegacyWireSerializer
{
private readonly object _serializer;
private readonly MethodInfo _serializeMethod;
private readonly MethodInfo _deserializeMethod;

public LegacyWireSerializer()
{
var path = Path.Combine(Path.GetDirectoryName(Assembly.GetAssembly(typeof(LegacyWireSerializer)).Location),
@"LegacyBinaries\LegacyWire_0.0.6.dll");

if (!File.Exists(path))
throw new CannotFindLegacyWireLibraryException();

var assembly = Assembly.LoadFile(path);

var options = CreateByConstructor(assembly, "Wire.SerializerOptions", new object[] { true,null,false,null});
_serializer = CreateByConstructor(assembly, "Wire.Serializer", new [] {options});

_serializeMethod = _serializer.GetType().GetMethod("Serialize", new [] {typeof(object), typeof(Stream)});
if(_serializeMethod == null)
throw new MissingMethodException("Cannot find serialize method for legacy wire");

_deserializeMethod = _serializer.GetType().GetMethods().FirstOrDefault(m => m.Name == "Deserialize" & !m.IsGenericMethod);
if (_deserializeMethod == null)
throw new MissingMethodException("Cannot find deserialize method for legacy wire");
}

private static object CreateByConstructor(Assembly assembly, string typeName, object[] parameters)
{
return assembly.CreateInstance(typeName,
true,
BindingFlags.Public | BindingFlags.Instance,
null,
parameters,
CultureInfo.CurrentCulture,
null);
}

public object Deserialize(byte[] payload, Type type)
{
using (var stream = new MemoryStream(payload))
return _deserializeMethod.Invoke(_serializer, new object[] { stream});
}

public byte[] Serialize(object obj)
{
using (var stream = new MemoryStream())
{
_serializeMethod.Invoke(_serializer,new object[] { obj, stream});
return stream.ToArray();
}
}
}

public class CannotFindLegacyWireLibraryException : Exception
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Akka.Actor;
using Akka.DI.Core;
using GridDomain.Node.Actors;
using GridDomain.Tests.Aggregate_Sagas_actor_lifetime.Actors;
using GridDomain.Tests.SampleDomain;
using GridDomain.Tests.SampleDomain.Commands;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using GridDomain.EventSourcing.Sagas;
using GridDomain.EventSourcing.Sagas.InstanceSagas;
using GridDomain.Node.Actors;
using GridDomain.Tests.Aggregate_Sagas_actor_lifetime.Actors;
using GridDomain.Tests.Sagas.InstanceSagas;
using GridDomain.Tests.Sagas.SoftwareProgrammingDomain.Events;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Akka.Actor;
using Akka.DI.Core;
using GridDomain.Node.Actors;
using GridDomain.Tests.Aggregate_Sagas_actor_lifetime.Actors;
using GridDomain.Tests.Sagas.SoftwareProgrammingDomain.Events;
using GridDomain.Tests.Sagas.StateSagas.SampleSaga;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Threading;
using Akka.Actor;
using GridDomain.Tests.Aggregate_Sagas_actor_lifetime.Actors;
using NUnit.Framework;

namespace GridDomain.Tests.Aggregate_Sagas_actor_lifetime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using GridDomain.Node.Actors;
using GridDomain.Node.Configuration.Composition;
using GridDomain.Node.Configuration.Persistence;
using GridDomain.Tests.Aggregate_Sagas_actor_lifetime.Actors;
using GridDomain.Tests.Aggregate_Sagas_actor_lifetime.Infrastructure;
using GridDomain.Tests.Framework.Configuration;
using GridDomain.Tests.Sagas.InstanceSagas;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using GridDomain.Node.Actors;

namespace GridDomain.Tests.Aggregate_Sagas_actor_lifetime.Actors
namespace GridDomain.Tests.Aggregate_Sagas_actor_lifetime
{
internal class TestPersistentChildsRecycleConfiguration : IPersistentChildsRecycleConfiguration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ namespace GridDomain.Tests.CommandsExecution
{
public class SampleDomainCommandExecutionTests : ExtendedNodeCommandTest
{
protected override TimeSpan Timeout => Debugger.IsAttached
? TimeSpan.FromMinutes(10)
: TimeSpan.FromSeconds(5);

protected override TimeSpan Timeout => TimeSpan.FromSeconds(5);
protected override IContainerConfiguration CreateConfiguration()
{
return new SampleDomainContainerConfiguration();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using GridDomain.EventSourcing.DomainEventAdapters;
using GridDomain.EventSourcing.Adapters;
using GridDomain.Tests.EventsUpgrade.Domain.Events;

namespace GridDomain.Tests.EventsUpgrade
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using GridDomain.EventSourcing.DomainEventAdapters;
using GridDomain.EventSourcing.Adapters;
using GridDomain.Tests.EventsUpgrade.Events;

namespace GridDomain.Tests.EventsUpgrade.Chain
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using GridDomain.EventSourcing.DomainEventAdapters;
using GridDomain.EventSourcing.Adapters;
using GridDomain.Tests.EventsUpgrade.Events;

namespace GridDomain.Tests.EventsUpgrade.Chain
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using GridDomain.EventSourcing.DomainEventAdapters;
using GridDomain.EventSourcing.Adapters;
using GridDomain.Tests.EventsUpgrade.Events;

namespace GridDomain.Tests.EventsUpgrade.Chain
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using GridDomain.EventSourcing.DomainEventAdapters;
using GridDomain.EventSourcing.Adapters;
using GridDomain.Tests.EventsUpgrade.Domain;
using GridDomain.Tests.EventsUpgrade.Events;
using NUnit.Framework;
Expand All @@ -17,7 +17,7 @@ public class Given_DomainEventUpgradeChain_When_updating_events_split_Tests
[OneTimeSetUp]
public void When_updating_single_event_Tests()
{
var chain = new EventAdaptersCatalog();
var chain = new EventsAdaptersCatalog();
chain.Register(new DomainEventUpdater3());
var balanceAggregate = new BalanceAggregate(Guid.NewGuid(), 10);
_initialEvent = new TestEvent_V2(balanceAggregate.Id);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Linq;
using GridDomain.EventSourcing.DomainEventAdapters;
using GridDomain.EventSourcing.Adapters;
using GridDomain.Tests.EventsUpgrade.Domain;
using GridDomain.Tests.EventsUpgrade.Events;
using NUnit.Framework;
Expand All @@ -16,7 +16,7 @@ public class Given_DomainEventUpgradeChain_When_updating_single_event_Tests
[OneTimeSetUp]
public void When_updating_single_event_Tests()
{
var chain = new EventAdaptersCatalog();
var chain = new EventsAdaptersCatalog();
chain.Register(new DomainEventUpdater1());
chain.Register(new DomainEventUpdater2());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using System;
using System.Linq;
using GridDomain.EventSourcing.Adapters;
using Newtonsoft.Json;
using NUnit.Framework;

namespace GridDomain.Tests.EventsUpgrade
{
[TestFixture]
class Collection_nested_property_upgrade_by_constructor
{

[Test]
public void All_occurance_should_be_upgraded()
{
var initialEvent = new Event(new []{ new Payload(new ISubObject[]{new SubObject_V1("10", "123")})});

var settings = DomainEventSerialization.GetDefaultSettings();
settings.Converters.Add(new SubObjectConverter());

var serializedValue = JsonConvert.SerializeObject(initialEvent, settings);
Console.WriteLine(serializedValue);

var restoredEvent = JsonConvert.DeserializeObject<Event>(serializedValue, settings);

Assert.IsInstanceOf<SubObject_V2>(restoredEvent.Payload?.FirstOrDefault()?.Property?.FirstOrDefault());
}

[Test]

public void All_occurance_should_be_upgraded_with_implicit_collection_set()
{
//Should get an exception due to different serialized value
var initialEvent = new Event(new[] { new Payload(new [] { new SubObject_V1("10", "123") }) });

var settings = DomainEventSerialization.GetDefaultSettings();
settings.Converters.Add(new SubObjectConverter());

var serializedValue = JsonConvert.SerializeObject(initialEvent, settings);
Console.WriteLine(serializedValue);
Assert.Throws<ArgumentException>(() =>
JsonConvert.DeserializeObject<Event>(serializedValue, settings));

}


[Test]
public void Collections_should_be_deserialized()
{
var initialEvent = new Event(new[] { new Payload(new[] { new SubObject_V1("10", "123") }) });

var settings = DomainEventSerialization.GetDefaultSettings();

var serializedValue = JsonConvert.SerializeObject(initialEvent, settings);
var restoredEvent = JsonConvert.DeserializeObject<Event>(serializedValue, settings);

Assert.IsInstanceOf<SubObject_V1>(restoredEvent.Payload?.FirstOrDefault()?.Property?.FirstOrDefault());
}



class SubObjectConverter : ObjectAdapter<SubObject_V1, SubObject_V2>
{
public override SubObject_V2 Convert(SubObject_V1 value)
{
return new SubObject_V2(int.Parse(value.Name), value.Value);
}
}

private interface ISubObject
{
string Value { get; }
}

class SubObject_V1 : ISubObject
{
public SubObject_V1(string name, string value)
{
Name = name;
Value = value;
}
public string Name { get; }
public string Value { get; }
}

class SubObject_V2 : ISubObject
{

public SubObject_V2(int number, string value)
{
Number = number;
Value = value;
}

public int Number { get; }
public string Value { get; }
}

class Payload
{
public Payload(ISubObject[] property)
{
Property = property;
}
public ISubObject[] Property { get; }
}
class Event
{
public Event(Payload[] payload)
{
Payload = payload;
}
public Payload[] Payload { get; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class Given_aggregate_with_upgraded_event_with_new_field: ExtendedNodeCom
[OneTimeSetUp]
public void When_aggregate_is_recovered_from_persistence()
{
GridNode.EventAdaptersCatalog.Register(new BalanceChangedDomainEventAdapter1());
GridNode.EventsAdaptersCatalog.Register(new BalanceChangedDomainEventAdapter1());
_balanceId = Guid.NewGuid();
var events = new DomainEvent[]
{
Expand Down
Loading