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
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>
<Version>8.0.0-beta-2</Version>
<Version>8.0.0-rc-1</Version>
<LangVersion>12.0</LangVersion>
<Authors>Jeremy D. Miller;Babu Annamalai;Oskar Dudycz;Joona-Pekka Kokko</Authors>
<PackageIconUrl>https://martendb.io/logo.png</PackageIconUrl>
Expand Down
16 changes: 0 additions & 16 deletions docs/events/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,3 @@ var store = DocumentStore.For(opts =>
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/Marten.Testing/Examples/ConfiguringDocumentStore.cs#L235-L245' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_making_the_events_multi_tenanted' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

By default, if you try to define projection with a single tenancy, Marten will throw an exception at runtime informing you about the mismatch.

You can enable global projections for conjoined tenancy.

<!-- snippet: sample_enabling_global_projections_for_conjoined_tenancy -->
<a id='snippet-sample_enabling_global_projections_for_conjoined_tenancy'></a>
```cs
opts.Events.EnableGlobalProjectionsForConjoinedTenancy = true;
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/EventSourcingTests/Aggregation/aggregation_projection_validation_rules.cs#L90-L94' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_enabling_global_projections_for_conjoined_tenancy' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

::: warning
If you enable global projections for conjoined tenancy, Marten won't validate potential tenancy mismatch and won't throw an exception for that case.
:::
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Npgsql;
using Shouldly;
using Weasel.Core.Migrations;
using Weasel.Core.MultiTenancy;
using Xunit;

namespace CoreTests;
Expand Down Expand Up @@ -523,5 +524,8 @@ private static void ShouldHaveAllTheExpectedRegistrations(Container container,
container.GetInstance<IDatabaseSource>().ShouldBeSameAs(store.As<DocumentStore>().Tenancy);

container.Model.For<IOptions<JasperFxOptions>>().Default.ShouldNotBeNull();

container.GetInstance<IMasterTableMultiTenancy>()
.ShouldBeSameAs(store);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using JasperFx.Core.Reflection;
using JasperFx.Descriptors;
using Marten.Storage;
using Marten.Testing.Harness;
Expand All @@ -19,7 +20,7 @@ public describing_database_usage_from_DefaultTenancy(DefaultStoreFixture fixture
public async Task create_usage()
{
theStore.Options.Tenancy.ShouldBeOfType<DefaultTenancy>();
theStore.Options.Tenancy.Cardinality.ShouldBe(DatabaseCardinality.Single);
theStore.Options.Tenancy.As<IDatabaseUser>().Cardinality.ShouldBe(DatabaseCardinality.Single);
var description = await theStore.Options.Tenancy.DescribeDatabasesAsync(CancellationToken.None);

description.Cardinality.ShouldBe(DatabaseCardinality.Single);
Expand Down
2 changes: 1 addition & 1 deletion src/DaemonTests/DaemonTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Confluent.Kafka" Version="2.3.0" />
<PackageReference Include="Lamar.Microsoft.DependencyInjection" Version="15.0.0-alpha-4" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Neovolve.Logging.Xunit" Version="6.3.0" />
Expand All @@ -14,6 +13,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="Lamar.Microsoft.DependencyInjection" Version="15.0.0-alpha-4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EventSourcingTests\EventSourcingTests.csproj"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq;
using System.Threading.Tasks;
using JasperFx.Events;
using JasperFx.Events.Daemon;
using JasperFx.Events.Projections;
using Marten.Events.Daemon.Progress;
using Marten.Exceptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using JasperFx.CodeGeneration;
using JasperFx.Core.Reflection;
using JasperFx.Events;
using JasperFx.Events.Grouping;
using JasperFx.Events.Internals;
using JasperFx.Events.Projections;
using Marten;
Expand Down Expand Up @@ -80,23 +81,6 @@ public void if_events_are_multi_tenanted_and_global_projections_are_disabled_so_
$"Tenancy storage style mismatch between the events (Conjoined) and the aggregate type {typeof(GuidIdentifiedAggregate).FullNameInCode()} (Single)");
}

[Fact]
public void if_events_are_multi_tenanted_and_global_projections_are_enabled()
{
shouldNotThrow(opts =>
{
opts.Events.TenancyStyle = TenancyStyle.Conjoined;

#region sample_enabling_global_projections_for_conjoined_tenancy

opts.Events.EnableGlobalProjectionsForConjoinedTenancy = true;

#endregion

opts.Projections.Snapshot<GuidIdentifiedAggregate>(SnapshotLifecycle.Async);
});
}

[Fact]
public void if_the_aggregate_is_multi_tenanted_but_the_events_are_not()
{
Expand Down Expand Up @@ -131,6 +115,15 @@ public void Apply(AEvent a)
}
}

public class GuidIdentifiedAggregateProjection: MultiStreamProjection<GuidIdentifiedAggregate, Guid>
{
public GuidIdentifiedAggregateProjection()
{
TenancyGrouping = TenancyGrouping.AcrossTenants;
Identity<IEvent>(x => x.StreamId);
}
}

public class StringIdentifiedAggregate
{
public string Id { get; set; }
Expand Down
38 changes: 38 additions & 0 deletions src/EventSourcingTests/Aggregation/when_doing_live_aggregations.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using EventSourcingTests.FetchForWriting;
using JasperFx.Events;
using Marten;
using Marten.Events;
Expand Down Expand Up @@ -45,6 +46,43 @@ public async Task sync_apply_and_default_create()
aggregate.DCount.ShouldBe(1);
}

[Fact]
public async Task when_requesting_an_aggregate_for_an_invalid_version()
{
var streamId = Guid.NewGuid();

theSession.Events.StartStream<SimpleAggregate>(streamId, new AEvent(), new BEvent(), new CEvent(),
new DEvent());
await theSession.SaveChangesAsync();

var aggregate1 = await theSession.Events.AggregateStreamAsync<SimpleAggregate>(streamId);
var aggregateAt4 = await theSession.Events.AggregateStreamAsync<SimpleAggregate>(streamId, version:4);
var aggregateAt5 = await theSession.Events.AggregateStreamAsync<SimpleAggregate>(streamId, version: 5);

aggregateAt4.ShouldBe(aggregate1);

aggregateAt5.ShouldBeNull();
}

[Fact]
public async Task when_requesting_an_aggregate_for_an_invalid_version_with_string_identifiers()
{
UseStreamIdentity(StreamIdentity.AsString);
var streamId = Guid.NewGuid().ToString();

theSession.Events.StartStream<SimpleAggregateAsString>(streamId, new AEvent(), new BEvent(), new CEvent(),
new DEvent());
await theSession.SaveChangesAsync();

var aggregate1 = await theSession.Events.AggregateStreamAsync<SimpleAggregateAsString>(streamId);
var aggregateAt4 = await theSession.Events.AggregateStreamAsync<SimpleAggregateAsString>(streamId, version:4);
var aggregateAt5 = await theSession.Events.AggregateStreamAsync<SimpleAggregateAsString>(streamId, version: 5);

aggregateAt4.ShouldBe(aggregate1);

aggregateAt5.ShouldBeNull();
}

[Fact]
public async Task sync_apply_and_specific_create()
{
Expand Down
Loading
Loading