From 6e46353f441251ffc6ebbf6ae2245128a454c2a8 Mon Sep 17 00:00:00 2001 From: Romeo Dumitrescu Date: Sat, 5 Oct 2024 17:45:51 +0300 Subject: [PATCH] feat(ES.FX.OneOf): add Failure types - Introduced a new record struct, `Failure`. - Added a generic version of the `Failure` struct, `Failure`, to hold any type of value. --- Directory.Packages.props | 2 +- .../HostedServices/TestHostedService.cs | 5 +- .../Migrations/V1.cs | 198 ++++++++---------- .../Messaging/MessageTypeAttribute.cs | 2 +- src/ES.FX.OneOf/Types/Failure.cs | 5 + .../OutboxDeliveryService.cs | 1 - .../ProgramEntrySerilogExtensionsTests.cs | 1 - .../DatabaseExtensionTests.cs | 2 +- 8 files changed, 101 insertions(+), 115 deletions(-) create mode 100644 src/ES.FX.OneOf/Types/Failure.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index a10711e..edac429 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -37,7 +37,7 @@ - + diff --git a/playground/Playground.Microservice.Api.Host/HostedServices/TestHostedService.cs b/playground/Playground.Microservice.Api.Host/HostedServices/TestHostedService.cs index d3e0343..06f8713 100644 --- a/playground/Playground.Microservice.Api.Host/HostedServices/TestHostedService.cs +++ b/playground/Playground.Microservice.Api.Host/HostedServices/TestHostedService.cs @@ -1,14 +1,11 @@ #pragma warning disable CS9113 // Parameter is unread. -using ES.FX.StackExchange.Redis; using ES.FX.TransactionalOutbox.EntityFrameworkCore; using ES.FX.TransactionalOutbox.EntityFrameworkCore.Messages; using Microsoft.EntityFrameworkCore; using Playground.Microservice.Api.Host.Testing; using Playground.Shared.Data.Simple.EntityFrameworkCore; using Playground.Shared.Data.Simple.EntityFrameworkCore.Entities; -using StackExchange.Redis; -using StackExchange.Redis.KeyspaceIsolation; namespace Playground.Microservice.Api.Host.HostedServices; @@ -32,7 +29,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) DelayBetweenAttempts = 5, DelayBetweenAttemptsIsExponential = true }); - dbContext.SimpleUsers.Add(new SimpleUser { Id = Guid.NewGuid(), Username = Guid.NewGuid().ToString()}); + dbContext.SimpleUsers.Add(new SimpleUser { Id = Guid.NewGuid(), Username = Guid.NewGuid().ToString() }); } await dbContext.SaveChangesAsync(stoppingToken).ConfigureAwait(false); diff --git a/playground/Playground.Shared.Data.Simple.EntityFrameworkCore.SqlServer/Migrations/V1.cs b/playground/Playground.Shared.Data.Simple.EntityFrameworkCore.SqlServer/Migrations/V1.cs index e0baaaf..0b738d4 100644 --- a/playground/Playground.Shared.Data.Simple.EntityFrameworkCore.SqlServer/Migrations/V1.cs +++ b/playground/Playground.Shared.Data.Simple.EntityFrameworkCore.SqlServer/Migrations/V1.cs @@ -1,123 +1,109 @@ -using System; +#nullable disable + using Microsoft.EntityFrameworkCore.Migrations; -#nullable disable +namespace Playground.Shared.Data.Simple.EntityFrameworkCore.SqlServer.Migrations; -namespace Playground.Shared.Data.Simple.EntityFrameworkCore.SqlServer.Migrations +/// +public partial class V1 : Migration { /// - public partial class V1 : Migration + protected override void Up(MigrationBuilder migrationBuilder) { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "__Outboxes", - columns: table => new - { - Id = table.Column(type: "uniqueidentifier", nullable: false), - AddedAt = table.Column(type: "datetimeoffset", nullable: false), - Lock = table.Column(type: "uniqueidentifier", nullable: true), - DeliveryDelayedUntil = table.Column(type: "datetimeoffset", nullable: true), - RowVersion = table.Column(type: "rowversion", rowVersion: true, nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK___Outboxes", x => x.Id); - }); + migrationBuilder.CreateTable( + "__Outboxes", + table => new + { + Id = table.Column("uniqueidentifier", nullable: false), + AddedAt = table.Column("datetimeoffset", nullable: false), + Lock = table.Column("uniqueidentifier", nullable: true), + DeliveryDelayedUntil = table.Column("datetimeoffset", nullable: true), + RowVersion = table.Column("rowversion", rowVersion: true, nullable: true) + }, + constraints: table => { table.PrimaryKey("PK___Outboxes", x => x.Id); }); - migrationBuilder.CreateTable( - name: "__OutboxMessageFaults", - columns: table => new - { - Id = table.Column(type: "bigint", nullable: false), - OutboxId = table.Column(type: "uniqueidentifier", nullable: false), - AddedAt = table.Column(type: "datetimeoffset", nullable: false), - Headers = table.Column(type: "nvarchar(max)", nullable: false), - PayloadType = table.Column(type: "nvarchar(max)", nullable: false), - Payload = table.Column(type: "nvarchar(max)", nullable: false), - DeliveryAttempts = table.Column(type: "int", nullable: false), - DeliveryFirstAttemptedAt = table.Column(type: "datetimeoffset", nullable: true), - DeliveryLastAttemptedAt = table.Column(type: "datetimeoffset", nullable: true), - DeliveryLastAttemptError = table.Column(type: "nvarchar(4000)", maxLength: 4000, nullable: true), - DeliveryNotBefore = table.Column(type: "datetimeoffset", nullable: true), - DeliveryNotAfter = table.Column(type: "datetimeoffset", nullable: true), - FaultedAt = table.Column(type: "datetimeoffset", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK___OutboxMessageFaults", x => x.Id); - }); + migrationBuilder.CreateTable( + "__OutboxMessageFaults", + table => new + { + Id = table.Column("bigint", nullable: false), + OutboxId = table.Column("uniqueidentifier", nullable: false), + AddedAt = table.Column("datetimeoffset", nullable: false), + Headers = table.Column("nvarchar(max)", nullable: false), + PayloadType = table.Column("nvarchar(max)", nullable: false), + Payload = table.Column("nvarchar(max)", nullable: false), + DeliveryAttempts = table.Column("int", nullable: false), + DeliveryFirstAttemptedAt = table.Column("datetimeoffset", nullable: true), + DeliveryLastAttemptedAt = table.Column("datetimeoffset", nullable: true), + DeliveryLastAttemptError = table.Column("nvarchar(4000)", maxLength: 4000, nullable: true), + DeliveryNotBefore = table.Column("datetimeoffset", nullable: true), + DeliveryNotAfter = table.Column("datetimeoffset", nullable: true), + FaultedAt = table.Column("datetimeoffset", nullable: false) + }, + constraints: table => { table.PrimaryKey("PK___OutboxMessageFaults", x => x.Id); }); - migrationBuilder.CreateTable( - name: "__OutboxMessages", - columns: table => new - { - Id = table.Column(type: "bigint", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - OutboxId = table.Column(type: "uniqueidentifier", nullable: false), - AddedAt = table.Column(type: "datetimeoffset", nullable: false), - Headers = table.Column(type: "nvarchar(max)", nullable: false), - PayloadType = table.Column(type: "nvarchar(max)", nullable: false), - Payload = table.Column(type: "nvarchar(max)", nullable: false), - DeliveryAttempts = table.Column(type: "int", nullable: false), - DeliveryMaxAttempts = table.Column(type: "int", nullable: true), - DeliveryFirstAttemptedAt = table.Column(type: "datetimeoffset", nullable: true), - DeliveryLastAttemptedAt = table.Column(type: "datetimeoffset", nullable: true), - DeliveryLastAttemptError = table.Column(type: "nvarchar(4000)", maxLength: 4000, nullable: true), - DeliveryNotBefore = table.Column(type: "datetimeoffset", nullable: true), - DeliveryNotAfter = table.Column(type: "datetimeoffset", nullable: true), - DeliveryAttemptDelay = table.Column(type: "int", nullable: false), - DeliveryAttemptDelayIsExponential = table.Column(type: "bit", nullable: false), - RowVersion = table.Column(type: "rowversion", rowVersion: true, nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK___OutboxMessages", x => x.Id); - }); + migrationBuilder.CreateTable( + "__OutboxMessages", + table => new + { + Id = table.Column("bigint", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + OutboxId = table.Column("uniqueidentifier", nullable: false), + AddedAt = table.Column("datetimeoffset", nullable: false), + Headers = table.Column("nvarchar(max)", nullable: false), + PayloadType = table.Column("nvarchar(max)", nullable: false), + Payload = table.Column("nvarchar(max)", nullable: false), + DeliveryAttempts = table.Column("int", nullable: false), + DeliveryMaxAttempts = table.Column("int", nullable: true), + DeliveryFirstAttemptedAt = table.Column("datetimeoffset", nullable: true), + DeliveryLastAttemptedAt = table.Column("datetimeoffset", nullable: true), + DeliveryLastAttemptError = table.Column("nvarchar(4000)", maxLength: 4000, nullable: true), + DeliveryNotBefore = table.Column("datetimeoffset", nullable: true), + DeliveryNotAfter = table.Column("datetimeoffset", nullable: true), + DeliveryAttemptDelay = table.Column("int", nullable: false), + DeliveryAttemptDelayIsExponential = table.Column("bit", nullable: false), + RowVersion = table.Column("rowversion", rowVersion: true, nullable: true) + }, + constraints: table => { table.PrimaryKey("PK___OutboxMessages", x => x.Id); }); - migrationBuilder.CreateTable( - name: "SimpleUsers", - columns: table => new - { - Id = table.Column(type: "uniqueidentifier", nullable: false), - Username = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_SimpleUsers", x => x.Id); - }); + migrationBuilder.CreateTable( + "SimpleUsers", + table => new + { + Id = table.Column("uniqueidentifier", nullable: false), + Username = table.Column("nvarchar(128)", maxLength: 128, nullable: false) + }, + constraints: table => { table.PrimaryKey("PK_SimpleUsers", x => x.Id); }); - migrationBuilder.CreateIndex( - name: "IX___Outboxes_AddedAt", - table: "__Outboxes", - column: "AddedAt"); + migrationBuilder.CreateIndex( + "IX___Outboxes_AddedAt", + "__Outboxes", + "AddedAt"); - migrationBuilder.CreateIndex( - name: "IX___Outboxes_DeliveryDelayedUntil", - table: "__Outboxes", - column: "DeliveryDelayedUntil"); + migrationBuilder.CreateIndex( + "IX___Outboxes_DeliveryDelayedUntil", + "__Outboxes", + "DeliveryDelayedUntil"); - migrationBuilder.CreateIndex( - name: "IX___Outboxes_Lock", - table: "__Outboxes", - column: "Lock"); - } + migrationBuilder.CreateIndex( + "IX___Outboxes_Lock", + "__Outboxes", + "Lock"); + } - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "__Outboxes"); + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + "__Outboxes"); - migrationBuilder.DropTable( - name: "__OutboxMessageFaults"); + migrationBuilder.DropTable( + "__OutboxMessageFaults"); - migrationBuilder.DropTable( - name: "__OutboxMessages"); + migrationBuilder.DropTable( + "__OutboxMessages"); - migrationBuilder.DropTable( - name: "SimpleUsers"); - } + migrationBuilder.DropTable( + "SimpleUsers"); } -} +} \ No newline at end of file diff --git a/src/ES.FX.Contracts/Messaging/MessageTypeAttribute.cs b/src/ES.FX.Contracts/Messaging/MessageTypeAttribute.cs index 25023b0..3694afd 100644 --- a/src/ES.FX.Contracts/Messaging/MessageTypeAttribute.cs +++ b/src/ES.FX.Contracts/Messaging/MessageTypeAttribute.cs @@ -27,6 +27,6 @@ public class MessageTypeAttribute(string messageType) : Attribute return attribute?.MessageType; } - public static string? MessageTypeFor() => + public static string? MessageTypeFor() => MessageTypeFor(typeof(T)); } \ No newline at end of file diff --git a/src/ES.FX.OneOf/Types/Failure.cs b/src/ES.FX.OneOf/Types/Failure.cs new file mode 100644 index 0000000..f5de277 --- /dev/null +++ b/src/ES.FX.OneOf/Types/Failure.cs @@ -0,0 +1,5 @@ +namespace ES.FX.OneOf.Types; + +public record struct Failure; + +public record struct Failure(T Value); \ No newline at end of file diff --git a/src/ES.FX.TransactionalOutbox.EntityFrameworkCore/OutboxDeliveryService.cs b/src/ES.FX.TransactionalOutbox.EntityFrameworkCore/OutboxDeliveryService.cs index 5a698ba..d58bb1d 100644 --- a/src/ES.FX.TransactionalOutbox.EntityFrameworkCore/OutboxDeliveryService.cs +++ b/src/ES.FX.TransactionalOutbox.EntityFrameworkCore/OutboxDeliveryService.cs @@ -250,7 +250,6 @@ await dbContext.Database.CreateExecutionStrategy().ExecuteAsync(async () => } finally { - deliverOutboxActivity?.Stop(); deliverOutboxActivity?.Dispose(); diff --git a/tests/ES.FX.Serilog.Tests/Lifetime/ProgramEntrySerilogExtensionsTests.cs b/tests/ES.FX.Serilog.Tests/Lifetime/ProgramEntrySerilogExtensionsTests.cs index c0a63e3..a85812e 100644 --- a/tests/ES.FX.Serilog.Tests/Lifetime/ProgramEntrySerilogExtensionsTests.cs +++ b/tests/ES.FX.Serilog.Tests/Lifetime/ProgramEntrySerilogExtensionsTests.cs @@ -18,6 +18,5 @@ await ProgramEntry.CreateBuilder([]).UseSerilog(LogEventLevel.Verbose, Assert.NotEmpty(InMemorySink.Instance.LogEvents); return Task.FromResult(1); }); - } } \ No newline at end of file diff --git a/tests/ES.FX.StackExchange.Redis.Tests/DatabaseExtensionTests.cs b/tests/ES.FX.StackExchange.Redis.Tests/DatabaseExtensionTests.cs index ec42e03..884270a 100644 --- a/tests/ES.FX.StackExchange.Redis.Tests/DatabaseExtensionTests.cs +++ b/tests/ES.FX.StackExchange.Redis.Tests/DatabaseExtensionTests.cs @@ -19,7 +19,7 @@ public void KeysDelete_Input_Output_check(string pattern, int batchSize) batchSize); database.Verify(database => database.ScriptEvaluate(It.IsAny(), - It.Is(x=>x.Contains(pattern)), + It.Is(x => x.Contains(pattern)), It.Is(x => x.Contains(batchSize)), It.IsAny()), Times.Once); }