Skip to content

Commit

Permalink
Ensured that the memory event store doesn't shallow projection except…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
dennisdoomen committed Feb 8, 2018
1 parent f817965 commit f366df5
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,5 @@ Build/**
Tools/**

# Visual Studio
.vs/
**/.vs/**
.vs/**
2 changes: 1 addition & 1 deletion Src/LiquidProjections.Testing/MemoryEventSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace LiquidProjections.Testing
/// <summary>
/// An event source which stores all the transactions in memory and has methods which are convenient for testing.
/// </summary>
public partial class MemoryEventSource
public class MemoryEventSource
{
private readonly int batchSize;
private readonly List<MemorySubscription> subscriptions = new List<MemorySubscription>();
Expand Down
24 changes: 22 additions & 2 deletions Src/LiquidProjections.Testing/MemorySubscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public class MemorySubscription : IDisposable
private CancellationTokenSource cancellationTokenSource;
private readonly object syncRoot = new object();
private Task task;

// Returns the last exception that caused the subscription to abort or <c>null</c>.
private Exception exception;
private TaskCompletionSource<long> progressCompletionSource = new TaskCompletionSource<long>();

private readonly TaskCompletionSource<bool> waitForCheckingWhetherItIsAheadCompletionSource =
Expand Down Expand Up @@ -63,8 +66,13 @@ public void Start()
{
await RunAsync(info).ConfigureAwait(false);
}
catch (Exception)
catch (OperationCanceledException)
{
Dispose();
}
catch (Exception exc)
{
exception = exc;
Dispose();
}
},
Expand Down Expand Up @@ -208,7 +216,19 @@ public async Task WaitUntilCheckpoint(long checkpoint)
}
}

await progressTask.ConfigureAwait(false);
try
{
await progressTask.ConfigureAwait(false);
}
catch (OperationCanceledException)
{
break;
}
}

if (exception != null)
{
throw new AggregateException(exception);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/LiquidProjections.Specs/DispatcherSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public When_a_projector_throws_an_exception()
{
Given(() =>
{
LogProvider.SetCurrentLogProvider(UseThe(new FakeLogProvider()));
UseThe(new MemoryEventSource());
WithSubject(_ => new Dispatcher(The<MemoryEventSource>().Subscribe));
LogProvider.SetCurrentLogProvider(UseThe(new FakeLogProvider()));
UseThe(new ProjectionException("Some message."));
Subject.Subscribe(null, (transaction, info) =>
Expand Down
5 changes: 3 additions & 2 deletions Tests/LiquidProjections.Specs/LiquidProjections.Specs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>6</LangVersion>
<LangVersion>7</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
Expand All @@ -31,7 +31,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>6</LangVersion>
<LangVersion>7</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
Expand Down Expand Up @@ -83,6 +83,7 @@
<ItemGroup>
<Compile Include="DispatcherSpecs.cs" />
<Compile Include="EventMapSpecs.cs" />
<Compile Include="MemoryEventSourceSpecs.cs" />
<Compile Include="ProjectionExceptionSpecs.cs" />
<Compile Include="ProjectionStatsSpecs.cs" />
<Compile Include="ProjectorSpecs.cs" />
Expand Down
47 changes: 47 additions & 0 deletions Tests/LiquidProjections.Specs/MemoryEventSourceSpecs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using Chill;
using FluentAssertions;
using LiquidProjections.Testing;
using Xunit;

namespace LiquidProjections.Specs
{
namespace MemoryEventSourceSpecs
{
public class When_a_subscriber_throws_an_exception_that_the_dispatcher_rethrows : GivenSubject<Dispatcher>
{
public When_a_subscriber_throws_an_exception_that_the_dispatcher_rethrows()
{
Given(() =>
{
UseThe(new MemoryEventSource());
WithSubject(_ => new Dispatcher(The<MemoryEventSource>().Subscribe)
{
ExceptionHandler = (exception, attempts, info) => throw exception
});
Subject.Subscribe(null, (transaction, info) =>
{
throw new ArgumentException();
});
});

WhenLater(() =>
{
return The<MemoryEventSource>().Write(new List<Transaction>
{
new Transaction()
});
});
}

[Fact]
public void Then_the_exception_should_bubble_up_through_the_memory_event_source()
{
WhenAction.Should().Throw<ArgumentException>();
}
}

}
}

0 comments on commit f366df5

Please sign in to comment.