Skip to content
Closed
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
@@ -0,0 +1,35 @@
using System;
using System.Threading.Tasks;
using Marten.Exceptions;
using Marten.Testing.Harness;
using Shouldly;
using Xunit;

namespace EventSourcingTests.Bugs;

public class start_stream_should_enforce_that_it_is_a_new_stream_when_UseArchivedStreamPartitioning_is_enabled: OneOffConfigurationsContext
{
[Fact]
public async Task throw_exception_if_start_stream_is_called_on_existing_stream_when_UseArchivedStreamPartitioning()
{
StoreOptions(_ => _.Events.UseArchivedStreamPartitioning = true);

var stream = Guid.NewGuid();

using (var session = theStore.LightweightSession())
{
session.Events.StartStream(stream, new MembersJoined());
await session.SaveChangesAsync();
}

using (var session = theStore.LightweightSession())
{
session.Events.StartStream(stream, new MembersJoined());

await Should.ThrowAsync<ExistingStreamIdCollisionException>(async () =>
{
await session.SaveChangesAsync();
});
}
}
}
7 changes: 6 additions & 1 deletion src/Marten/Events/Operations/InsertStreamBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,16 @@ public override string ToString()
}

private static bool matches(Exception e)
{
{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: undo the whitespace change

Suggested change
{
{

return e is PostgresException
{
SqlState: PostgresErrorCodes.UniqueViolation,
TableName: StreamsTable.TableName
}
|| e is PostgresException
{
SqlState: PostgresErrorCodes.UniqueViolation,
TableName: StreamsTable.DefaultPartionedTableName
};
}

Expand Down
1 change: 1 addition & 0 deletions src/Marten/Events/Schema/StreamsTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace Marten.Events.Schema;
internal class StreamsTable: Table
{
public const string TableName = "mt_streams";
public const string DefaultPartionedTableName = $"{TableName}_default";

public StreamsTable(EventGraph events): base(new PostgresqlObjectName(events.DatabaseSchemaName, TableName))
{
Expand Down
Loading