Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@
using Shouldly;
using Weasel.Postgresql;
using Xunit;
using Xunit.Abstractions;

namespace ContainerScopedProjectionTests;

[Collection("ioc")]
public class projections_with_IoC_services
{
private readonly ITestOutputHelper _output;

public projections_with_IoC_services(ITestOutputHelper output)
{
_output = output;
}

[Fact]
public async Task can_apply_database_changes_at_runtime_with_projection_with_services()
{
Expand Down Expand Up @@ -366,7 +374,7 @@ public async Task get_async_shards_with_custom_name_on_martenStore()
[Fact]
public async Task use_multistream_projection_as_scoped_and_inline_on_martenStore()
{
using var host = await Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder()
using var host = await Host.CreateDefaultBuilder()
.ConfigureServices(services =>
{
services.AddSingleton<IPriceLookup, PriceLookup>();
Expand All @@ -393,7 +401,47 @@ public async Task use_multistream_projection_as_scoped_and_inline_on_martenStore
product.Name.ShouldBe("Ankle Socks");

// Now rebuild
var daemon = await store.BuildProjectionDaemonAsync();
var daemon = await store.BuildProjectionDaemonAsync(logger:new TestOutputMartenLogger(_output));
await daemon.RebuildProjectionAsync<Product>(CancellationToken.None);

// Test again
product = await session.LoadAsync<Product>(streamId);
product.Price.ShouldBeGreaterThan(0);
product.Name.ShouldBe("Ankle Socks");
}


[Fact]
public async Task use_multistream_projection_as_singleton_and_inline_on_martenStore()
{
using var host = await Host.CreateDefaultBuilder()
.ConfigureServices(services =>
{
services.AddSingleton<IPriceLookup, PriceLookup>();

services.AddMartenStore<ICustomStore>(opts =>
{
opts.Connection(ConnectionSource.ConnectionString);
opts.DatabaseSchemaName = "ioc3";
opts.ApplyChangesLockId = opts.ApplyChangesLockId + 9;
}).AddProjectionWithServices<ProductMultiStreamProjection>(ProjectionLifecycle.Inline, ServiceLifetime.Singleton, "MyProjection")
.ApplyAllDatabaseChangesOnStartup();
}).StartAsync();

var store = host.Services.GetRequiredService<ICustomStore>();



await using var session = store.LightweightSession();
var streamId = session.Events.StartStream<Product>(new ProductRegistered("Ankle Socks", "Socks")).Id;
await session.SaveChangesAsync();

var product = await session.LoadAsync<Product>(streamId);
product.Price.ShouldBeGreaterThan(0);
product.Name.ShouldBe("Ankle Socks");

// Now rebuild
var daemon = await store.BuildProjectionDaemonAsync(logger:new TestOutputMartenLogger(_output));
await daemon.RebuildProjectionAsync<Product>(CancellationToken.None);

// Test again
Expand Down
5 changes: 3 additions & 2 deletions src/DaemonTests/Internals/HighWaterAgentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ public async Task will_not_go_in_loop_when_sequence_is_advanced_but_gaps_from_hi
[Fact]
public async Task skips_multiple_gaps_and_keeps_advancing()
{
NumberOfStreams = 10;
NumberOfStreams = 100;
await PublishSingleThreaded();

// Create multiple gaps in the event sequence
var gaps = new[] { NumberOfEvents - 9, NumberOfEvents - 6, NumberOfEvents - 5, NumberOfEvents - 3 };
var gaps = new[] { NumberOfEvents - 50,NumberOfEvents - 9, NumberOfEvents - 6, NumberOfEvents - 5, NumberOfEvents - 3 };
await deleteEvents(gaps);

// Make gap skipping kick in faster
Expand All @@ -127,6 +127,7 @@ public async Task skips_multiple_gaps_and_keeps_advancing()
await agent.Tracker.WaitForHighWaterMark(gaps[1], 2.Seconds());
await agent.Tracker.WaitForHighWaterMark(gaps[2], 2.Seconds());
await agent.Tracker.WaitForHighWaterMark(gaps[3], 2.Seconds());
await agent.Tracker.WaitForHighWaterMark(gaps[4], 2.Seconds());
// And eventually reach the head
await agent.Tracker.WaitForHighWaterMark(NumberOfEvents, 2.Seconds());

Expand Down
12 changes: 3 additions & 9 deletions src/Marten/Marten.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,15 @@

<ItemGroup>
<PackageReference Include="FSharp.Core" Version="9.0.100" />
<!-- <PackageReference Include="JasperFx" Version="1.5.0" />-->
<!-- <PackageReference Include="JasperFx.Events" Version="1.7.1" />-->
<!-- <PackageReference Include="JasperFx.RuntimeCompiler" Version="4.0.0" />-->
<PackageReference Include="JasperFx" Version="1.5.0" />
<PackageReference Include="JasperFx.Events" Version="1.7.3" />
<PackageReference Include="JasperFx.RuntimeCompiler" Version="4.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<!-- This is forced by Npgsql peer dependency -->
<PackageReference Include="Npgsql.Json.NET" Version="9.0.2" />
<PackageReference Include="Polly.Core" Version="8.5.2" />
<PackageReference Include="Weasel.Postgresql" Version="8.1.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\jasperfx\src\JasperFx.Events\JasperFx.Events.csproj" />
<ProjectReference Include="..\..\..\jasperfx\src\JasperFx.RuntimeCompiler\JasperFx.RuntimeCompiler.csproj" />
<ProjectReference Include="..\..\..\jasperfx\src\JasperFx\JasperFx.csproj" />
</ItemGroup>

<Import Project="../../Analysis.Build.props" />
</Project>
Loading