Skip to content

Commit

Permalink
Merge branch 'JasperFx:master' into tenant-slice-group-check-null-ide…
Browse files Browse the repository at this point in the history
…ntifier
  • Loading branch information
micahosborne authored Jul 7, 2023
2 parents 136394f + 999d371 commit 41989cf
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<VersionPrefix>6.0.3</VersionPrefix>
<VersionPrefix>6.0.4</VersionPrefix>
<LangVersion>11.0</LangVersion>
<Authors>Jeremy D. Miller;Babu Annamalai;Oskar Dudycz;Joona-Pekka Kokko</Authors>
<PackageIconUrl>https://martendb.io/logo.png</PackageIconUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/Marten.AspNetCore/Marten.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<Description>Helpers for Marten-backed AspNetCore applications</Description>
<VersionPrefix>6.0.3</VersionPrefix>
<VersionPrefix>6.0.4</VersionPrefix>
<GenerateAssemblyTitleAttribute>true</GenerateAssemblyTitleAttribute>
<GenerateAssemblyDescriptionAttribute>true</GenerateAssemblyDescriptionAttribute>
<GenerateAssemblyProductAttribute>true</GenerateAssemblyProductAttribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ namespace Marten.AsyncDaemon.Testing.DocumentTrackingByIdentity;

public class CustomProjection_follow_up_operations: DaemonContext
{
public CustomProjection_follow_up_operations(ITestOutputHelper output): base(output)
{
}

[Fact]
public async Task rebuild_with_follow_up_operations_should_work()
{
Expand Down Expand Up @@ -96,4 +92,8 @@ public async Task ApplyAsync(IDocumentOperations operations, IReadOnlyList<Strea
}
}
}

public CustomProjection_follow_up_operations(ITestOutputHelper output): base(output)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Marten.AsyncDaemon.Testing.TestingSupport;
using Marten.Events.Daemon;
using Marten.Events.Projections;
using Shouldly;
using Xunit;
using Xunit.Abstractions;

namespace Marten.AsyncDaemon.Testing.DocumentTrackingByIdentity;

public class EventProjectionWithCreate_follow_up_operations: DaemonContext
{
[Fact]
public async Task rebuild_with_follow_up_operations_should_work()
{
StoreOptions(x => x.Projections.Add<EntityProjection>(ProjectionLifecycle.Inline,
asyncOptions => asyncOptions.EnableDocumentTrackingByIdentity = true));

var entityId = Guid.NewGuid();

await using var session = theStore.IdentitySession();

session.Events.StartStream(entityId, new EntityCreated(entityId, "Some name"));
await session.SaveChangesAsync();
session.Events.Append(entityId, new EntityNameUpdated(entityId, "New name"));
await session.SaveChangesAsync();

var agent = await StartDaemon();

await agent.RebuildProjection(nameof(EntityProjection), CancellationToken.None);

var shoppingCartRebuilt = await session.LoadAsync<Entity>(entityId);

shoppingCartRebuilt!.Id.ShouldBe(entityId);
shoppingCartRebuilt.Name.ShouldBe("New name");
}


[Fact]
public async Task regular_usage_follow_up_operations_should_work()
{
StoreOptions(x => x.Projections.Add<EntityProjection>(ProjectionLifecycle.Async,
asyncOptions => asyncOptions.EnableDocumentTrackingByIdentity = true));

var entityId = Guid.NewGuid();

await using var session = theStore.IdentitySession();

session.Events.StartStream(entityId, new EntityCreated(entityId, "Some name"));
await session.SaveChangesAsync();
session.Events.Append(entityId, new EntityNameUpdated(entityId, "New name"));
await session.SaveChangesAsync();

var daemon = await StartDaemon();

await daemon.StartDaemon();

await daemon.Tracker.WaitForShardState($"{nameof(EntityProjection)}:All", 2);

var entity = await session.LoadAsync<Entity>(entityId);

entity.ShouldNotBeNull();

entity.Id.ShouldBe(entityId);
entity.Name.ShouldBe("New name");
}

public record Entity(Guid Id, string Name);

public record EntityCreated(Guid Id, string Name);

public record EntityNameUpdated(Guid Id, string Name);

public class EntityProjection: EventProjection
{
public EntityProjection()
{
ProjectionName = nameof(EntityProjection);
}

public Entity Create(EntityCreated @event)
=> new(@event.Id, @event.Name);

public async Task Project(EntityNameUpdated @event, IDocumentOperations operations,
CancellationToken cancellationToken)
{
var stock = await operations.LoadAsync<Entity>(@event.Id, cancellationToken).ConfigureAwait(false);
if (stock is null)
{
throw new ArgumentNullException(nameof(stock), "Stock does not exist!");
}

stock = stock with { Name = @event.Name };

operations.Store(stock);
}
}

public EventProjectionWithCreate_follow_up_operations(ITestOutputHelper output): base(output)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ namespace Marten.AsyncDaemon.Testing.DocumentTrackingByIdentity;

public class EventProjection_follow_up_operations: DaemonContext
{
public EventProjection_follow_up_operations(ITestOutputHelper output): base(output)
{
}

[Fact]
public async Task rebuild_with_follow_up_operations_should_work()
{
Expand Down Expand Up @@ -72,4 +68,8 @@ public NestedEntityEventProjection()
});
}
}

public EventProjection_follow_up_operations(ITestOutputHelper output): base(output)
{
}
}
2 changes: 1 addition & 1 deletion src/Marten.NodaTime/Marten.NodaTime.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>NodaTime extension for Marten</Description>
<VersionPrefix>6.0.3</VersionPrefix>
<VersionPrefix>6.0.4</VersionPrefix>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<GenerateAssemblyTitleAttribute>true</GenerateAssemblyTitleAttribute>
<GenerateAssemblyDescriptionAttribute>true</GenerateAssemblyDescriptionAttribute>
Expand Down
2 changes: 1 addition & 1 deletion src/Marten.PLv8/Marten.PLv8.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Description>Document transforms and patching extension for Marten</Description>
<VersionPrefix>6.0.3</VersionPrefix>
<VersionPrefix>6.0.4</VersionPrefix>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<GenerateAssemblyTitleAttribute>true</GenerateAssemblyTitleAttribute>
<GenerateAssemblyDescriptionAttribute>true</GenerateAssemblyDescriptionAttribute>
Expand Down
16 changes: 9 additions & 7 deletions src/Marten/Events/Daemon/ProjectionDocumentSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ namespace Marten.Events.Daemon;
/// </summary>
internal class ProjectionDocumentSession: DocumentSessionBase
{
public ProjectionDocumentSession(DocumentStore store, ISessionWorkTracker workTracker,
SessionOptions sessionOptions): base(
store, sessionOptions, new MartenControlledConnectionTransaction(sessionOptions), workTracker)
public ProjectionDocumentSession(
DocumentStore store,
ISessionWorkTracker workTracker,
SessionOptions sessionOptions
): base(store, sessionOptions, new MartenControlledConnectionTransaction(sessionOptions), workTracker)
{
}

protected internal override IDocumentStorage<T> selectStorage<T>(DocumentProvider<T> provider)
{
return provider.Lightweight;
}
internal override DocumentTracking TrackingMode => SessionOptions.Tracking;

protected internal override IDocumentStorage<T> selectStorage<T>(DocumentProvider<T> provider) =>
TrackingMode == DocumentTracking.IdentityOnly ? provider.IdentityMap : provider.Lightweight;

protected internal override void ejectById<T>(long id)
{
Expand Down
16 changes: 12 additions & 4 deletions src/Marten/Internal/Sessions/DocumentSessionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,23 @@ public abstract partial class DocumentSessionBase: QuerySession, IDocumentSessio

private Dictionary<string, NestedTenantSession>? _byTenant;

internal DocumentSessionBase(DocumentStore store, SessionOptions sessionOptions, IConnectionLifetime connection):
base(store, sessionOptions, connection)
internal DocumentSessionBase(
DocumentStore store,
SessionOptions sessionOptions,
IConnectionLifetime connection
): base(store, sessionOptions, connection)
{
Concurrency = sessionOptions.ConcurrencyChecks;
_workTracker = new UnitOfWork(this);
}

internal DocumentSessionBase(DocumentStore store, SessionOptions sessionOptions, IConnectionLifetime connection,
ISessionWorkTracker workTracker, Tenant? tenant = default): base(store, sessionOptions, connection, tenant)
internal DocumentSessionBase(
DocumentStore store,
SessionOptions sessionOptions,
IConnectionLifetime connection,
ISessionWorkTracker workTracker,
Tenant? tenant = default
): base(store, sessionOptions, connection, tenant)
{
Concurrency = sessionOptions.ConcurrencyChecks;
_workTracker = workTracker;
Expand Down
6 changes: 4 additions & 2 deletions src/Marten/Internal/Sessions/QuerySession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ protected virtual IQueryEventStore CreateEventStore(DocumentStore store, Tenant
public string TenantId { get; protected set; }
#nullable enable

internal QuerySession(DocumentStore store,
internal QuerySession(
DocumentStore store,
SessionOptions sessionOptions,
IConnectionLifetime connection,
Tenant? tenant = default)
Tenant? tenant = default
)
{
_store = store;
TenantId = tenant?.TenantId ?? sessionOptions.Tenant?.TenantId ?? sessionOptions.TenantId;
Expand Down

0 comments on commit 41989cf

Please sign in to comment.