Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmus committed Dec 5, 2015
2 parents e0251c7 + 778838a commit fb6e1e9
Show file tree
Hide file tree
Showing 47 changed files with 1,192 additions and 335 deletions.
22 changes: 21 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
### New in 0.22 (not released yet)
### New in 0.23 (not released yet)

* Breaking: EventFlow no longer ignores columns named `Id` in MSSQL read models.
If you were dependent on this, use the `MsSqlReadModelIgnoreColumn` attribute
* Fixed: Instead of using `MethodInfo.Invoke` to call methods on reflected
types, e.g. when a command is published, EventFlow now compiles an expression
tree instead. This has a slight initial overhead, but provides a significant
performance improvement for subsequent calls
* Fixed: Read model stores are only invoked if there's any read model updates
* Fixed: EventFlow now correctly throws an `ArgumentException` if EventFlow has
been incorrectly configure with known versioned types, e.g. an event
is emitted that hasn't been added during EventFlow initialization. EventFlow
would handle the save operation correctly, but if EventFlow was reinitialized
and the event was loaded _before_ it being emitted again, an exception would
be thrown as EventFlow would know which type to use. Please make sure to
correctly load all event, command and job types before use
* Fixed: `IReadModelFactory<>.CreateAsync(...)` is now correctly used in
read store mangers
* Fixed: Versioned type naming convention now allows numbers

### New in 0.22.1393 (released 2015-11-19)

* New: To customize how a specific read model is initially created, implement
a specific `IReadModelFactory<>` that can bootstrap that read model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public Task<IJobId> ScheduleAsync(IJob job, TimeSpan delay, CancellationToken ca

private Task<IJobId> ScheduleAsync(IJob job, Func<IBackgroundJobClient, JobDefinition, string, string> schedule)
{
var jobDefinition = _jobDefinitionService.GetJobDefinition(job.GetType());
var jobDefinition = _jobDefinitionService.GetDefinition(job.GetType());
var json = _jsonSerializer.Serialize(job);

var id = schedule(_backgroundJobClient, jobDefinition, json);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,68 +21,74 @@
// 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.
//

using System;
using System.ComponentModel.DataAnnotations.Schema;
using EventFlow.MsSql.Tests.IntegrationTests.ReadStores.ReadModels;
using EventFlow.ReadStores;
using EventFlow.ReadStores.MsSql;
using EventFlow.ReadStores.MsSql.Attributes;
using EventFlow.TestHelpers;
using FluentAssertions;
using NUnit.Framework;
#pragma warning disable 618

namespace EventFlow.MsSql.Tests.UnitTests.ReadModels
{
public class ReadModelSqlGeneratorTests : TestsFor<ReadModelSqlGenerator>
{
[Table("FancyTable")]
public class TestTableAttribute : MssqlReadModel { }

[Test]
public void CreateInsertSql_ProducesCorrectSql()
{
// Act
var sql = Sut.CreateInsertSql<MsSqlThingyReadModel>();
var sql = Sut.CreateInsertSql<TestAttributesReadModel>();

// Assert
sql.Should().Be(
"INSERT INTO [ReadModel-ThingyAggregate] " +
"(AggregateId, CreateTime, DomainErrorAfterFirstReceived, LastAggregateSequenceNumber, PingsReceived, UpdatedTime) " +
"VALUES " +
"(@AggregateId, @CreateTime, @DomainErrorAfterFirstReceived, @LastAggregateSequenceNumber, @PingsReceived, @UpdatedTime)");
sql.Should().Be("INSERT INTO [ReadModel-TestAttributes] (Id, UpdatedTime) VALUES (@Id, @UpdatedTime)");
}

[Test]
public void CreateUpdateSql_ProducesCorrectSql()
{
// Act
var sql = Sut.CreateUpdateSql<MsSqlThingyReadModel>();
var sql = Sut.CreateUpdateSql<TestAttributesReadModel>();

// Assert
sql.Should().Be(
"UPDATE [ReadModel-ThingyAggregate] SET " +
"CreateTime = @CreateTime, DomainErrorAfterFirstReceived = @DomainErrorAfterFirstReceived, " +
"LastAggregateSequenceNumber = @LastAggregateSequenceNumber, " +
"PingsReceived = @PingsReceived, UpdatedTime = @UpdatedTime " +
"WHERE AggregateId = @AggregateId");
sql.Should().Be("UPDATE [ReadModel-TestAttributes] SET UpdatedTime = @UpdatedTime WHERE Id = @Id");
}

[Test]
public void CreateSelectSql_ProducesCorrectSql()
{
// Act
var sql = Sut.CreateSelectSql<MsSqlThingyReadModel>();
var sql = Sut.CreateSelectSql<TestAttributesReadModel>();

// Assert
sql.Should().Be("SELECT * FROM [ReadModel-ThingyAggregate] WHERE AggregateId = @EventFlowReadModelId");
sql.Should().Be("SELECT * FROM [ReadModel-TestAttributes] WHERE Id = @EventFlowReadModelId");
}

[Test]
public void GetTableName_UsesTableAttribute()
{
// Act
var tableName = Sut.GetTableName<TestTableAttribute>();
var tableName = Sut.GetTableName<TestTableAttributeReadModel>();

// Assert
tableName.Should().Be("[FancyTable]");
tableName.Should().Be("[Fancy]");
}

public class TestAttributesReadModel : IReadModel
{
[MsSqlReadModelIdentityColumn]
public string Id { get; set; }

public DateTimeOffset UpdatedTime { get; set; }

[MsSqlReadModelIgnoreColumn]
public string Secret { get; set; }
}

[Table("Fancy")]
public class TestTableAttributeReadModel : IReadModel
{
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// The MIT License (MIT)
//
// Copyright (c) 2015 Rasmus Mikkelsen
// Copyright (c) 2015 eBay Software Foundation
// https://github.com/rasmus/EventFlow
//
// 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.
//

using System;

namespace EventFlow.ReadStores.MsSql.Attributes
{
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public class MsSqlReadModelIgnoreColumnAttribute : Attribute
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<Link>Properties\SolutionInfo.cs</Link>
</Compile>
<Compile Include="Attributes\MsSqlReadModelIdentityColumnAttribute.cs" />
<Compile Include="Attributes\MsSqlReadModelIgnoreColumnAttribute.cs" />
<Compile Include="Attributes\MsSqlReadModelVersionColumnAttribute.cs" />
<Compile Include="Extensions\EventFlowOptionsExtensions.cs" />
<Compile Include="IMssqlReadModel.cs" />
Expand Down
2 changes: 1 addition & 1 deletion Source/EventFlow.ReadStores.MsSql/ReadModelSqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ protected IEnumerable<string> GetInsertColumns<TReadModel>()
where TReadModel : IReadModel
{
return GetPropertyInfos(typeof (TReadModel))
.Where(p => p.Name != "Id") // TODO: Maybe use the key attribute to mark this
.Select(p => p.Name);
}

Expand Down Expand Up @@ -165,6 +164,7 @@ protected IReadOnlyCollection<PropertyInfo> GetPropertyInfos(Type readModelType)
{
return t
.GetProperties(BindingFlags.Instance | BindingFlags.Public)
.Where(p => p.GetCustomAttribute<MsSqlReadModelIgnoreColumnAttribute>() == null)
.OrderBy(p => p.Name)
.ToList();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// The MIT License (MIT)
//
// Copyright (c) 2015 Rasmus Mikkelsen
// Copyright (c) 2015 eBay Software Foundation
// https://github.com/rasmus/EventFlow
//
// 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.
//

using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using EventFlow.Commands;
using EventFlow.TestHelpers.Aggregates.Entities;
using EventFlow.TestHelpers.Aggregates.ValueObjects;

namespace EventFlow.TestHelpers.Aggregates.Commands
{
public class ThingyImportCommand : Command<ThingyAggregate, ThingyId>
{
public IReadOnlyCollection<PingId> PingIds { get; }
public IReadOnlyCollection<ThingyMessage> ThingyMessages { get; }

public ThingyImportCommand(
ThingyId aggregateId,
IEnumerable<PingId> pingIds,
IEnumerable<ThingyMessage> thingyMessages)
: base(aggregateId)
{
PingIds = pingIds.ToList();
ThingyMessages = thingyMessages.ToList();
}
}

public class ThingyImportCommandHandler : CommandHandler<ThingyAggregate, ThingyId, ThingyImportCommand>
{
public override Task ExecuteAsync(
ThingyAggregate aggregate,
ThingyImportCommand command,
CancellationToken cancellationToken)
{
foreach (var pingId in command.PingIds)
{
aggregate.Ping(pingId);
}

foreach (var thingyMessage in command.ThingyMessages)
{
aggregate.AddMessage(thingyMessage);
}

return Task.FromResult(0);
}
}
}
1 change: 1 addition & 0 deletions Source/EventFlow.TestHelpers/EventFlow.TestHelpers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Aggregates\Commands\ThingyAddMessageCommand.cs" />
<Compile Include="Aggregates\Commands\ThingyImportCommand.cs" />
<Compile Include="Aggregates\Commands\ThingyNopCommand.cs" />
<Compile Include="Aggregates\Commands\ThingyDomainErrorAfterFirstCommand.cs" />
<Compile Include="Aggregates\Commands\ThingyPingCommand.cs" />
Expand Down
23 changes: 23 additions & 0 deletions Source/EventFlow.TestHelpers/Suites/TestSuiteForReadModelStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using EventFlow.TestHelpers.Aggregates.Commands;
using EventFlow.TestHelpers.Aggregates.Entities;
using EventFlow.TestHelpers.Aggregates.Queries;
using EventFlow.TestHelpers.Aggregates.ValueObjects;
using EventFlow.TestHelpers.Extensions;
using FluentAssertions;
using NUnit.Framework;
Expand Down Expand Up @@ -111,6 +112,28 @@ public async Task CanStoreMultipleMessages()
returnedThingyMessages.ShouldAllBeEquivalentTo(thingyMessages);
}

[Test]
public async Task CanHandleMultipleMessageAtOnce()
{
// Arrange
var thingyId = ThingyId.New;
var pingIds = Many<PingId>(5);
var thingyMessages = Many<ThingyMessage>(7);

// Act
await CommandBus.PublishAsync(new ThingyImportCommand(
thingyId,
pingIds,
thingyMessages))
.ConfigureAwait(false);
var returnedThingyMessages = await QueryProcessor.ProcessAsync(new ThingyGetMessagesQuery(thingyId)).ConfigureAwait(false);
var thingy = await QueryProcessor.ProcessAsync(new ThingyGetQuery(thingyId)).ConfigureAwait(false);

// Assert
thingy.PingsReceived.Should().Be(pingIds.Count);
returnedThingyMessages.ShouldAllBeEquivalentTo(returnedThingyMessages);
}

[Test]
public async Task PurgeRemovesReadModels()
{
Expand Down
8 changes: 7 additions & 1 deletion Source/EventFlow.Tests/EventFlow.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,12 @@
<Compile Include="UnitTests\Configuration\ModuleRegistrationTests.cs" />
<Compile Include="UnitTests\Core\CircularBufferTests.cs" />
<Compile Include="UnitTests\Core\IdentityTests.cs" />
<Compile Include="UnitTests\Core\ReflectionHelperTests.cs" />
<Compile Include="UnitTests\Core\VersionedTypes\VersionedTypeDefinitionServiceTestSuite.cs" />
<Compile Include="UnitTests\Extensions\AggregatesExtensionsTests.cs" />
<Compile Include="UnitTests\Extensions\StringExtensionsTests.cs" />
<Compile Include="UnitTests\Extensions\TypeExtensionsTests.cs" />
<Compile Include="UnitTests\Jobs\JobDefinitionServiceTests.cs" />
<Compile Include="UnitTests\Jobs\JobsFlowTests.cs" />
<Compile Include="UnitTests\Provided\Specifications\AtLeastSpecificationTests.cs" />
<Compile Include="UnitTests\Queries\QueryProcessorTests.cs" />
Expand All @@ -112,7 +115,10 @@
<Compile Include="UnitTests\EventStores\EventUpgradeManagerTests.cs" />
<Compile Include="UnitTests\ReadStores\ReadModelFactoryTests.cs" />
<Compile Include="UnitTests\ReadStores\ReadModelPopulatorTests.cs" />
<Compile Include="UnitTests\ReadStores\ReadStoreManagerTests.cs" />
<Compile Include="UnitTests\ReadStores\ReadStoreManagerTestReadModel.cs" />
<Compile Include="UnitTests\ReadStores\ReadStoreManagerTestSuite.cs" />
<Compile Include="UnitTests\ReadStores\MultipleAggregateReadStoreManagerTests.cs" />
<Compile Include="UnitTests\ReadStores\SingleAggregateReadStoreManagerTests.cs" />
<Compile Include="UnitTests\Specifications\SpecificationTests.cs" />
<Compile Include="UnitTests\Specifications\TestSpecifications.cs" />
<Compile Include="UnitTests\Specifications\TestSpecificationsTests.cs" />
Expand Down
Loading

0 comments on commit fb6e1e9

Please sign in to comment.