From 41fdbd202117172a79c0e1edc247274ebde429b3 Mon Sep 17 00:00:00 2001 From: Sun Zhongfeng Date: Thu, 30 Nov 2023 18:07:21 +0800 Subject: [PATCH] update net8 --- Directory.Build.props | 4 +- Directory.Packages.props | 51 +++++++++--------- global.json | 2 +- src/Fabron.Core/Diagnostics/Telemetry.cs | 5 +- .../Dispatching/SimpleFireRouterOptions.cs | 2 +- src/Fabron.Core/Schedulers/CronScheduler.cs | 2 +- .../Schedulers/GenericScheduler.cs | 2 +- .../Schedulers/PeriodicScheduler.cs | 2 +- src/Fabron.Core/Stores/InMemoryStateStore.cs | 2 +- src/FabronService/FabronService.csproj | 1 - .../Hosting/SecurityConfigureExtensions.cs | 54 ------------------- src/FabronService/Program.cs | 6 +-- .../CronSchedulerTests/CronTimerTestBase.cs | 2 +- .../CronTimerTickingTests.cs | 2 +- .../SchedulerTests/FakeReminderRegistry.cs | 2 +- .../SchedulerTests/FakeSystemClock.cs | 2 +- .../SchedulerTests/FakeTimerRegistry.cs | 2 +- .../GenericTimerTickingTests.cs | 12 ++--- .../PeriodicTimerTickingTests.cs | 6 +-- .../PeriodicTimerTests/PeriodicStopTests.cs | 3 +- .../TestSiloConfigurator.cs | 2 +- .../TestAuthHandler.cs | 26 --------- .../WAFExtensions.cs | 11 ---- 23 files changed, 53 insertions(+), 150 deletions(-) delete mode 100644 src/FabronService/Hosting/SecurityConfigureExtensions.cs delete mode 100644 test/FabronService.FunctionalTests/TestAuthHandler.cs diff --git a/Directory.Build.props b/Directory.Build.props index 946879e..31dea31 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -5,9 +5,9 @@ - net7.0 + net8.0 enable - 0.1.0 + 1.0.0 https://github.com/DCArea/Fabron diff --git a/Directory.Packages.props b/Directory.Packages.props index 56c2b87..cb9570b 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -3,31 +3,30 @@ true - 7.2.1 - 7.0.0 + 7.2.3 + 8.0.0 0.0.1-alpha4.1 + 1.7.0-rc.1 + 1.6.0-beta.3 - - - - + + - - - - - - - - - - - - + + + + + + + + + + + - + @@ -41,19 +40,19 @@ - + - - + + - - + + - - + + \ No newline at end of file diff --git a/global.json b/global.json index 06ce1b4..5ce8495 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { "sdk": { - "version": "7.0.400" + "version": "8.0.100" } } diff --git a/src/Fabron.Core/Diagnostics/Telemetry.cs b/src/Fabron.Core/Diagnostics/Telemetry.cs index 8bdd99d..df8c813 100644 --- a/src/Fabron.Core/Diagnostics/Telemetry.cs +++ b/src/Fabron.Core/Diagnostics/Telemetry.cs @@ -7,7 +7,6 @@ namespace Fabron.Diagnostics; -#pragma warning disable IDE0052 // Remove unread private members internal sealed class Telemetry { public const string TelemetryName = "Fabron"; @@ -19,7 +18,7 @@ internal sealed class Telemetry public static HistogramAggregator TimerDispatchTardiness = new( new(), - new(Buckets: new[] { 0L, 1L, 5L, 50L, 1_000L, 5_000L, 60_000L })); + new(Buckets: [0L, 1L, 5L, 50L, 1_000L, 5_000L, 60_000L])); private static readonly ObservableCounter timerDispatchTardinessCount = s_meter.CreateObservableCounter("fabron-timer-dispatch-tardiness-count", TimerDispatchTardiness.CollectCount); private static readonly ObservableCounter timerDispatchTardinessSum @@ -33,7 +32,7 @@ private static readonly ObservableCounter timerDispatchTardinessBuckets public static HistogramAggregator FabronTimerDispatchDuration = new( new(), - new(Buckets: new[] { 0L, 1L, 5L, 50L, 1_000L, 5_000L, 10_000L })); + new(Buckets: [0L, 1L, 5L, 50L, 1_000L, 5_000L, 10_000L])); private static readonly ObservableCounter timerDispatchDurationCount = s_meter.CreateObservableCounter("fabron-timer-dispatch-duration-count", FabronTimerDispatchDuration.CollectCount); private static readonly ObservableCounter timerDispatchDurationSum diff --git a/src/Fabron.Core/Dispatching/SimpleFireRouterOptions.cs b/src/Fabron.Core/Dispatching/SimpleFireRouterOptions.cs index 7a555f7..c03e439 100644 --- a/src/Fabron.Core/Dispatching/SimpleFireRouterOptions.cs +++ b/src/Fabron.Core/Dispatching/SimpleFireRouterOptions.cs @@ -2,5 +2,5 @@ public class SimpleFireRouterOptions { - public List Routes { get; init; } = new(); + public List Routes { get; init; } = []; } diff --git a/src/Fabron.Core/Schedulers/CronScheduler.cs b/src/Fabron.Core/Schedulers/CronScheduler.cs index 88c8876..c4b7a05 100644 --- a/src/Fabron.Core/Schedulers/CronScheduler.cs +++ b/src/Fabron.Core/Schedulers/CronScheduler.cs @@ -51,7 +51,7 @@ public async Task Schedule( CreationTimestamp: utcNow, DeletionTimestamp: null, Owner: owner, - Extensions: extensions ?? new()), + Extensions: extensions ?? []), Data: data, Spec: spec ); diff --git a/src/Fabron.Core/Schedulers/GenericScheduler.cs b/src/Fabron.Core/Schedulers/GenericScheduler.cs index 8366323..066dae5 100644 --- a/src/Fabron.Core/Schedulers/GenericScheduler.cs +++ b/src/Fabron.Core/Schedulers/GenericScheduler.cs @@ -53,7 +53,7 @@ public async Task Schedule( CreationTimestamp: utcNow, DeletionTimestamp: null, Owner: owner, - Extensions: extensions ?? new()), + Extensions: extensions ?? []), Data: data, Spec: spec ); diff --git a/src/Fabron.Core/Schedulers/PeriodicScheduler.cs b/src/Fabron.Core/Schedulers/PeriodicScheduler.cs index f18e4ba..c40a9dd 100644 --- a/src/Fabron.Core/Schedulers/PeriodicScheduler.cs +++ b/src/Fabron.Core/Schedulers/PeriodicScheduler.cs @@ -50,7 +50,7 @@ public async Task Schedule( CreationTimestamp: utcNow, DeletionTimestamp: null, Owner: owner, - Extensions: extensions ?? new()), + Extensions: extensions ?? []), Data: data, Spec: spec ); diff --git a/src/Fabron.Core/Stores/InMemoryStateStore.cs b/src/Fabron.Core/Stores/InMemoryStateStore.cs index 3cff883..6cdf6fb 100644 --- a/src/Fabron.Core/Stores/InMemoryStateStore.cs +++ b/src/Fabron.Core/Stores/InMemoryStateStore.cs @@ -14,7 +14,7 @@ public class InMemoryPeriodicTimerStore : InMemoryStateStore, IPe public abstract class InMemoryStateStore : IStateStore where TState : IDistributedTimer { - private readonly Dictionary> _states = new(); + private readonly Dictionary> _states = []; public Task?> GetAsync(string key) { diff --git a/src/FabronService/FabronService.csproj b/src/FabronService/FabronService.csproj index bef3627..d32ec35 100644 --- a/src/FabronService/FabronService.csproj +++ b/src/FabronService/FabronService.csproj @@ -6,7 +6,6 @@ - diff --git a/src/FabronService/Hosting/SecurityConfigureExtensions.cs b/src/FabronService/Hosting/SecurityConfigureExtensions.cs deleted file mode 100644 index 6c8f48e..0000000 --- a/src/FabronService/Hosting/SecurityConfigureExtensions.cs +++ /dev/null @@ -1,54 +0,0 @@ -using AspNetCore.Authentication.ApiKey; -using Microsoft.AspNetCore.Authorization; - -namespace FabronService.Hosting; - -public static class SecurityConfigureExtensions -{ - public static WebApplicationBuilder ConfigureSecurity(this WebApplicationBuilder builder) - { - builder.Services - .AddApiKeyAuth(builder.Configuration["ApiKey"]!) - .AddAuthorization(options => - { - options.FallbackPolicy = new AuthorizationPolicyBuilder() - .RequireAuthenticatedUser() - .Build(); - }); - return builder; - } - - public static WebApplication UseSecurity(this WebApplication app) - { - app.UseAuthentication() - .UseAuthorization(); - return app; - } - - private static IServiceCollection AddApiKeyAuth(this IServiceCollection services, string validApiKey) - { - services.AddAuthentication(ApiKeyDefaults.AuthenticationScheme) - .AddApiKeyInAuthorizationHeader(options => - { - options.Realm = "FabronService API"; - options.KeyName = "token"; - options.IgnoreAuthenticationIfAllowAnonymous = true; - options.Events = new ApiKeyEvents - { - OnValidateKey = ctx => - { - if (ctx.ApiKey == validApiKey) - { - ctx.ValidationSucceeded("debug"); - } - else - { - ctx.ValidationFailed(); - } - return Task.CompletedTask; - } - }; - }); - return services; - } -} diff --git a/src/FabronService/Program.cs b/src/FabronService/Program.cs index 2d32e1c..b9a2b77 100644 --- a/src/FabronService/Program.cs +++ b/src/FabronService/Program.cs @@ -1,8 +1,7 @@ -using FabronService.Hosting; +using FabronService.Hosting; var builder = WebApplication.CreateBuilder(args); builder.ConfigureFabron(); -builder.ConfigureSecurity(); builder.ConfigureOpenTelemetry(); builder.ConfigureSwagger(); builder.Services.AddHealthChecks(); @@ -11,9 +10,8 @@ app.MapHealthChecks("/health").AllowAnonymous(); app.UseOpenTelemetry(); app.UseConfiguredSwagger(); -app.UseSecurity(); app.MapRoutes(); app.Run(); -public partial class Program { } \ No newline at end of file +public partial class Program { } diff --git a/test/Fabron.Core.Test/SchedulerTests/CronSchedulerTests/CronTimerTestBase.cs b/test/Fabron.Core.Test/SchedulerTests/CronSchedulerTests/CronTimerTestBase.cs index 28eec4f..4e3db1e 100644 --- a/test/Fabron.Core.Test/SchedulerTests/CronSchedulerTests/CronTimerTestBase.cs +++ b/test/Fabron.Core.Test/SchedulerTests/CronSchedulerTests/CronTimerTestBase.cs @@ -38,7 +38,7 @@ internal CronFakes PrepareGrain(string? schedule = null, [CallerMemberName] stri CreationTimestamp: DateTimeOffset.UtcNow, DeletionTimestamp: null, Owner: null, - Extensions: new() + Extensions: [] ), Data: JsonSerializer.Serialize(new { data = new { foo = "bar" } }), Spec: new CronTimerSpec diff --git a/test/Fabron.Core.Test/SchedulerTests/CronSchedulerTests/CronTimerTickingTests.cs b/test/Fabron.Core.Test/SchedulerTests/CronSchedulerTests/CronTimerTickingTests.cs index 256e882..e8255a6 100644 --- a/test/Fabron.Core.Test/SchedulerTests/CronSchedulerTests/CronTimerTickingTests.cs +++ b/test/Fabron.Core.Test/SchedulerTests/CronSchedulerTests/CronTimerTickingTests.cs @@ -62,7 +62,7 @@ await scheduler.Schedule( JsonSerializer.Serialize(new { data = new { foo = "bar" } }), new CronTimerSpec("0 0 0 1 6 *"), null, - new()); + []); var reminder = reminderRegistry.Reminders.Single().Value; reminder.DueTime.Should().Be(TimeSpan.FromDays(49)); diff --git a/test/Fabron.Core.Test/SchedulerTests/FakeReminderRegistry.cs b/test/Fabron.Core.Test/SchedulerTests/FakeReminderRegistry.cs index 8e4c26a..f25d920 100644 --- a/test/Fabron.Core.Test/SchedulerTests/FakeReminderRegistry.cs +++ b/test/Fabron.Core.Test/SchedulerTests/FakeReminderRegistry.cs @@ -5,7 +5,7 @@ namespace Fabron.Core.Test.SchedulerTests { public class FakeReminderRegistry : IReminderRegistry { - public Dictionary Reminders { get; } = new(); + public Dictionary Reminders { get; } = []; public static Task Fire(IRemindable remindable, string reminderName, TickStatus tickerStatus) => remindable.ReceiveReminder(reminderName, tickerStatus); diff --git a/test/Fabron.Core.Test/SchedulerTests/FakeSystemClock.cs b/test/Fabron.Core.Test/SchedulerTests/FakeSystemClock.cs index 26f47a5..6b9c596 100644 --- a/test/Fabron.Core.Test/SchedulerTests/FakeSystemClock.cs +++ b/test/Fabron.Core.Test/SchedulerTests/FakeSystemClock.cs @@ -10,7 +10,7 @@ public class FakeSystemClock : ISystemClock public class FakeFireDispatcher : IFireDispatcher { - public List Envelops { get; } = new List(); + public List Envelops { get; } = []; public Task DispatchAsync(FireEnvelop envelop) { Envelops.Add(envelop); diff --git a/test/Fabron.Core.Test/SchedulerTests/FakeTimerRegistry.cs b/test/Fabron.Core.Test/SchedulerTests/FakeTimerRegistry.cs index 06c09a0..a40200d 100644 --- a/test/Fabron.Core.Test/SchedulerTests/FakeTimerRegistry.cs +++ b/test/Fabron.Core.Test/SchedulerTests/FakeTimerRegistry.cs @@ -5,7 +5,7 @@ namespace Fabron.Core.Test.SchedulerTests { public class FakeTimerRegistry : ITimerRegistry { - public List Timers { get; } = new(); + public List Timers { get; } = []; public IDisposable RegisterTimer(IGrainContext grainContext, Func asyncCallback, object state, TimeSpan dueTime, TimeSpan period) { var timer = new FakeTimer(asyncCallback, state, dueTime, period); diff --git a/test/Fabron.Core.Test/SchedulerTests/GenericTimerTests/GenericTimerTickingTests.cs b/test/Fabron.Core.Test/SchedulerTests/GenericTimerTests/GenericTimerTickingTests.cs index 96930ea..5a67e11 100644 --- a/test/Fabron.Core.Test/SchedulerTests/GenericTimerTests/GenericTimerTickingTests.cs +++ b/test/Fabron.Core.Test/SchedulerTests/GenericTimerTests/GenericTimerTickingTests.cs @@ -38,7 +38,7 @@ private GenericFakes PrepareGrain(DateTimeOffset? schedule = null, [CallerMember CreationTimestamp: DateTimeOffset.UtcNow, DeletionTimestamp: null, Owner: null, - Extensions: new() + Extensions: [] ), Data: JsonSerializer.Serialize(new { data = new { foo = "bar" } }), Spec: new GenericTimerSpec @@ -72,7 +72,7 @@ await scheduler.Schedule( JsonSerializer.Serialize(new { data = new { foo = "bar" } }), new GenericTimerSpec(tickTime), null, - new()); + []); var reminder = reminderRegistry.Reminders.Single().Value; reminder.DueTime.Should().Be(tickTime - clock.UtcNow); @@ -92,7 +92,7 @@ await scheduler.Schedule( JsonSerializer.Serialize(new { data = new { foo = "bar" } }), new GenericTimerSpec(tickTime), null, - new()); + []); reminderRegistry.Reminders.Single().Value.DueTime.Should().Be(tickTime - clock.UtcNow); var state = await scheduler.GetState(); @@ -111,7 +111,7 @@ await scheduler.Schedule( JsonSerializer.Serialize(new { data = new { foo = "bar" } }), new GenericTimerSpec(tickTime), null, - new()); + []); var reminder = reminderRegistry.Reminders.Single().Value; reminder.DueTime.Should().Be(TimeSpan.FromDays(49)); @@ -130,7 +130,7 @@ await scheduler.Schedule( JsonSerializer.Serialize(new { data = new { foo = "bar" } }), new GenericTimerSpec(tickTime), null, - new()); + []); var reminderDueTime = clock.UtcNow.Add(reminderRegistry.Reminders.Single().Value.DueTime); clock.UtcNow = reminderDueTime.AddMilliseconds(100); @@ -152,7 +152,7 @@ await scheduler.Schedule( JsonSerializer.Serialize(new { data = new { foo = "bar" } }), new GenericTimerSpec(tickTime), null, - new()); + []); var reminderDueTime = clock.UtcNow.Add(reminderRegistry.Reminders.Single().Value.DueTime); clock.UtcNow = reminderDueTime.AddMilliseconds(100); await FakeReminderRegistry.Fire(scheduler, Names.TickerReminder, new TickStatus(reminderDueTime.UtcDateTime, Timeout.InfiniteTimeSpan, clock.UtcNow.UtcDateTime)); diff --git a/test/Fabron.Core.Test/SchedulerTests/PeriodicTimerTests/PeriodicTimerTickingTests.cs b/test/Fabron.Core.Test/SchedulerTests/PeriodicTimerTests/PeriodicTimerTickingTests.cs index ba80d60..0bc48ce 100644 --- a/test/Fabron.Core.Test/SchedulerTests/PeriodicTimerTests/PeriodicTimerTickingTests.cs +++ b/test/Fabron.Core.Test/SchedulerTests/PeriodicTimerTests/PeriodicTimerTickingTests.cs @@ -38,7 +38,7 @@ private PeriodicFakes PrepareGrain(TimeSpan? schedule = null, [CallerMemberName] CreationTimestamp: DateTimeOffset.UtcNow, DeletionTimestamp: null, Owner: null, - Extensions: new() + Extensions: [] ), Data: JsonSerializer.Serialize(new { data = new { foo = "bar" } }), Spec: new PeriodicTimerSpec @@ -72,7 +72,7 @@ await scheduler.Schedule( JsonSerializer.Serialize(new { data = new { foo = "bar" } }), new(TimeSpan.FromSeconds(10)), null, - new()); + []); timerRegistry.Timers.Count.Should().Be(6); timerRegistry.Timers[0].DueTime.Should().Be(TimeSpan.Zero); @@ -101,7 +101,7 @@ await scheduler.Schedule( JsonSerializer.Serialize(new { data = new { foo = "bar" } }), new(TimeSpan.FromMinutes(1)), null, - new()); + []); timerRegistry.Timers.Count.Should().Be(1); timerRegistry.Timers[0].DueTime.Should().Be(TimeSpan.Zero); diff --git a/test/Fabron.FunctionalTests/PeriodicTimerTests/PeriodicStopTests.cs b/test/Fabron.FunctionalTests/PeriodicTimerTests/PeriodicStopTests.cs index 6aaf49a..ed32a2e 100644 --- a/test/Fabron.FunctionalTests/PeriodicTimerTests/PeriodicStopTests.cs +++ b/test/Fabron.FunctionalTests/PeriodicTimerTests/PeriodicStopTests.cs @@ -1,12 +1,11 @@ using Fabron.Schedulers; using FluentAssertions; -using Microsoft.Extensions.DependencyInjection; -using Orleans.Timers; using Xunit; using Xunit.Abstractions; namespace Fabron.FunctionalTests.PeriodicTimerTests; +#pragma warning disable xUnit1031 // Do not use blocking task operations in test method public class PeriodicStopTests(DefaultClusterFixture fixture, ITestOutputHelper output) : TestBase(fixture, output) { [Fact] diff --git a/test/Fabron.FunctionalTests/TestSiloConfigurator.cs b/test/Fabron.FunctionalTests/TestSiloConfigurator.cs index 15412df..2d33260 100644 --- a/test/Fabron.FunctionalTests/TestSiloConfigurator.cs +++ b/test/Fabron.FunctionalTests/TestSiloConfigurator.cs @@ -41,7 +41,7 @@ public void Configure(ISiloBuilder siloBuilder) public class TestFireDispatcher : IFireDispatcher { - public ConcurrentBag Fires { get; } = new(); + public ConcurrentBag Fires { get; } = []; public Task DispatchAsync(FireEnvelop envelop) { Fires.Add(envelop); diff --git a/test/FabronService.FunctionalTests/TestAuthHandler.cs b/test/FabronService.FunctionalTests/TestAuthHandler.cs deleted file mode 100644 index 43448a8..0000000 --- a/test/FabronService.FunctionalTests/TestAuthHandler.cs +++ /dev/null @@ -1,26 +0,0 @@ - -using System.Security.Claims; -using System.Text.Encodings.Web; - -using Microsoft.AspNetCore.Authentication; -using Microsoft.Extensions.Options; - -namespace FabronService.FunctionalTests -{ - public class TestAuthHandler(IOptionsMonitor options, - ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) : AuthenticationHandler(options, logger, encoder, clock) - { - protected override Task HandleAuthenticateAsync() - { - var claims = new[] { new Claim(ClaimTypes.Name, "Test user") }; - ClaimsIdentity? identity = new(claims, "Test"); - ClaimsPrincipal? principal = new(identity); - AuthenticationTicket? ticket = new(principal, "Test"); - - var result = AuthenticateResult.Success(ticket); - - return Task.FromResult(result); - } - } - -} diff --git a/test/FabronService.FunctionalTests/WAFExtensions.cs b/test/FabronService.FunctionalTests/WAFExtensions.cs index 8b8e2c4..0e943e7 100644 --- a/test/FabronService.FunctionalTests/WAFExtensions.cs +++ b/test/FabronService.FunctionalTests/WAFExtensions.cs @@ -8,17 +8,6 @@ namespace FabronService.FunctionalTests { public static class WAFExtensions { - public static WebApplicationFactory WithTestUser(this WebApplicationFactory waf) - => waf.WithWebHostBuilder(builder => - { - builder.ConfigureTestServices(services => - { - services.AddAuthentication("Test") - .AddScheme( - "Test", options => { }); - }); - }); - public static TestCluster GetSiloCluster(this WebApplicationFactory waf) => waf.Services.GetRequiredService();