From c9a79c490aa7e3ca49bc56c812f7fdef50c690f8 Mon Sep 17 00:00:00 2001 From: "Jeremy D. Miller" Date: Fri, 25 Oct 2024 10:27:23 -0500 Subject: [PATCH] new test to verify behavior of 3504. Closes GH-3504 --- .../marten_managed_tenant_id_partitioning.cs | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/src/MultiTenancyTests/marten_managed_tenant_id_partitioning.cs b/src/MultiTenancyTests/marten_managed_tenant_id_partitioning.cs index 0cb040429b..06e74e1e92 100644 --- a/src/MultiTenancyTests/marten_managed_tenant_id_partitioning.cs +++ b/src/MultiTenancyTests/marten_managed_tenant_id_partitioning.cs @@ -4,6 +4,7 @@ using System.Threading; using System.Threading.Tasks; using Marten; +using Marten.Metadata; using Marten.Schema; using Marten.Storage; using Marten.Testing.Documents; @@ -74,6 +75,43 @@ await theStore } + + + [Fact] + public async Task should_not_build_storage_for_live_aggregations() + { + StoreOptions(opts => + { + opts.Policies.AllDocumentsAreMultiTenanted(); + opts.Policies.PartitionMultiTenantedDocumentsUsingMartenManagement("tenants"); + + opts.Events.TenancyStyle = TenancyStyle.Conjoined; + + opts.Schema.For(); + opts.Schema.For(); + + opts.Projections.LiveStreamAggregation(); + }, true); + + var streamId = theSession.Events.StartStream(new AEvent(), new BEvent()).Id; + await theSession.SaveChangesAsync(); + + var aggregate = theSession.Events.AggregateStreamAsync(streamId); + aggregate.ShouldNotBeNull(); + + await theStore + .Advanced + // This is ensuring that there are tenant id partitions for all multi-tenanted documents + // with the named tenant ids + .AddMartenManagedTenantsAsync(CancellationToken.None, "a1", "a2", "a3"); + + await theStore.Storage.ApplyAllConfiguredChangesToDatabaseAsync(); + + // Seeing if the table for SimpleAggregate exists, and it should *not* + var table = await theStore.Storage.Database.ExistingTableFor(typeof(SimpleAggregate)); + table.ShouldBeNull(); + } + [Fact] public async Task can_build_storage_with_dynamic_tenants_by_variable_tenant_and_suffix_mappings() { @@ -234,3 +272,48 @@ public class DocThatShouldBeExempted2 public Guid Id { get; set; } } +public class SimpleAggregate : IRevisioned +{ + // This will be the aggregate version + public int Version { get; set; } + + public Guid Id { get; set; } + + public int ACount { get; set; } + public int BCount { get; set; } + public int CCount { get; set; } + public int DCount { get; set; } + public int ECount { get; set; } + + public void Apply(AEvent _) + { + ACount++; + } + + public void Apply(BEvent _) + { + BCount++; + } + + public void Apply(CEvent _) + { + CCount++; + } + + public void Apply(DEvent _) + { + DCount++; + } + + public void Apply(EEvent _) + { + ECount++; + } +} + +public class BEvent{} +public class CEvent{} +public class DEvent{} +public class EEvent{} + +