public Task MultipleAsyncRequestRepliesWithJokerExceptions_AcidTest_Success() { return(TestServiceExecutor.ExecuteInScope(async scope => { var host = scope.ServiceProvider.GetService <IHostedService>(); var cancellationTokenSource = new CancellationTokenSource(); var hardCancellationTokenSource = new CancellationTokenSource(); var outputQueue = scope.ServiceProvider.GetService <IConfiguration>().GetRabbitMqOutputQueue(); var outboxCleanerHost = TestHostProvider.GetOutboxCleanerHost(); var spammerHost = TestHostProvider.GetSpammerHost(outputQueue); var spammerHostTask = spammerHost.StartAsync(cancellationTokenSource.Token); var outboxCleanerHostTask = outboxCleanerHost.StartAsync(cancellationTokenSource.Token); var timeoutTask = Task.Run(async() => { await Task.Delay(OverrideConfig.DurationOfAcidTest); cancellationTokenSource.Cancel(); await host.StopAsync(hardCancellationTokenSource.Token); await outboxCleanerHost.StopAsync(hardCancellationTokenSource.Token); await spammerHost.StopAsync(hardCancellationTokenSource.Token); }, hardCancellationTokenSource.Token); await host.StartAsync(cancellationTokenSource.Token); await spammerHostTask; await outboxCleanerHostTask; await timeoutTask; })); }
public Task TryInsert_ShouldBeFalse() { return(TestServiceExecutor.ExecuteInScope(async scope => { var repository = scope.ServiceProvider.GetService <IOutboxDuplicationFilterRepository>(); var id = Guid.NewGuid(); (await repository.TryInsertMessageId(id)).Should().BeTrue(); (await repository.TryInsertMessageId(id)).Should().BeFalse(); })); }
public Task InsertAndCheckExists_Success() { return(TestServiceExecutor.ExecuteInScope(async scope => { var repository = scope.ServiceProvider.GetService <IOutboxDuplicationFilterRepository>(); var id = Guid.NewGuid(); await repository.InsertMessageId(id); (await repository.MessageIdExists(id)).Should().BeTrue(); })); }
public Task AsyncRequestReply_Success() { return(TestServiceExecutor.ExecuteInScope(async scope => { var bus = scope.ServiceProvider.GetService <IBus>(); var repository = scope.ServiceProvider.GetService <IResponseRepository>(); var request = new SafeRebusRequest(); await bus.Send(request); await Utilities.Tools.WaitUntilSuccess(async() => { (await repository.SelectResponse(request.Id)).Id.Should().Be(request.Id); }); })); }
public async Task InsertSelectAndDelete_Success() { var outboxMessage = GetOutboxMessage(); await TestServiceExecutor.ExecuteInScope(async scope => { var repository = scope.ServiceProvider.GetService <IOutboxMessageRepository>(); var dbProvider = scope.ServiceProvider.GetService <IDbProvider>(); await repository.InsertOutboxMessage(outboxMessage); dbProvider.GetDbTransaction().Commit(); }); await Task.Delay(TimeSpan.FromMilliseconds(700)); await TestServiceExecutor.ExecuteInScope(async scope => { var repository = scope.ServiceProvider.GetService <IOutboxMessageRepository>(); var dbProvider = scope.ServiceProvider.GetService <IDbProvider>(); await repository.InsertOutboxMessage(GetOutboxMessage()); dbProvider.GetDbTransaction().Commit(); }); await Task.Delay(TimeSpan.FromMilliseconds(500)); await TestServiceExecutor.ExecuteInScope(async scope => { var repository = scope.ServiceProvider.GetService <IOutboxMessageRepository>(); var insertedOutboxMessages = (await repository.SelectOutboxMessagesBeforeThreshold(TimeSpan.FromSeconds(1))).ToArray(); insertedOutboxMessages.Count().Should().Be(1); var insertedOutboxMessage = insertedOutboxMessages.First(); insertedOutboxMessage.Id.Should().Be(outboxMessage.Id); insertedOutboxMessage.Headers.Should().BeEquivalentTo(outboxMessage.Headers); insertedOutboxMessage.Message.Should().BeEquivalentTo(outboxMessage.Message); insertedOutboxMessage.SendFunction.Should().Be(outboxMessage.SendFunction); }); await TestServiceExecutor.ExecuteInScope(async scope => { var repository = scope.ServiceProvider.GetService <IOutboxMessageRepository>(); await repository.DeleteOutboxMessage(outboxMessage.Id); }); await TestServiceExecutor.ExecuteInScope(async scope => { var repository = scope.ServiceProvider.GetService <IOutboxMessageRepository>(); var insertedOutboxMessages = (await repository.SelectOutboxMessagesBeforeThreshold(TimeSpan.FromSeconds(1))).ToArray(); insertedOutboxMessages.Should().BeEmpty(); }); }
public Task BeginTransactionAndCommit_Success() { return(TestServiceExecutor.ExecuteInScope(async scope => { var originalQueue = scope.ServiceProvider.GetService <IConfiguration>().GetRabbitMqInputQueue(); var bus = scope.ServiceProvider.GetService <IOutboxBus>(); var repository = scope.ServiceProvider.GetService <IResponseRepository>(); var request = new SafeRebusRequest(); await bus.BeginTransaction(GetTransportMessage(originalQueue)); await bus.Send(request); await bus.Commit(); await MessageHandler.Utilities.Tools.WaitUntilSuccess(async() => { (await repository.SelectResponse(request.Id)).Id.Should().Be(request.Id); }); })); }
public async Task CleanOld_Success() { var savedIds = new List <Guid>(); var saveIdsShouldNotBeDeleted = new List <Guid>(); await TestServiceExecutor.ExecuteInScope(async scope => { var repository = scope.ServiceProvider.GetService <IOutboxDuplicationFilterRepository>(); var dbProvider = scope.ServiceProvider.GetService <IDbProvider>(); for (var i = 0; i < 10; i++) { var id = Guid.NewGuid(); await repository.InsertMessageId(id); savedIds.Add(id); } dbProvider.GetDbTransaction().Commit(); }); await Task.Delay(TimeSpan.FromSeconds(2)); await TestServiceExecutor.ExecuteInScope(async scope => { var repository = scope.ServiceProvider.GetService <IOutboxDuplicationFilterRepository>(); var dbProvider = scope.ServiceProvider.GetService <IDbProvider>(); for (var i = 0; i < 10; i++) { var id = Guid.NewGuid(); await repository.InsertMessageId(id); saveIdsShouldNotBeDeleted.Add(id); } dbProvider.GetDbTransaction().Commit(); }); await TestServiceExecutor.ExecuteInScope(async scope => { var repository = scope.ServiceProvider.GetService <IOutboxDuplicationFilterRepository>(); await repository.CleanOldMessageIds(TimeSpan.FromSeconds(1.5)); foreach (var savedId in savedIds) { (await repository.MessageIdExists(savedId)).Should().BeFalse(); } foreach (var savedIdShouldExist in saveIdsShouldNotBeDeleted) { (await repository.MessageIdExists(savedIdShouldExist)).Should().BeTrue(); } }); }
public async Task InsertAndCheckExists_Success() { var response = new SafeRebusResponse { Response = "some new random" }; await TestServiceExecutor.ExecuteInScope(async scope => { var repository = scope.ServiceProvider.GetService <IResponseRepository>(); var dbProvider = scope.ServiceProvider.GetService <IDbProvider>(); await repository.InsertResponse(response); dbProvider.GetDbTransaction().Commit(); }); await TestServiceExecutor.ExecuteInScope(async scope => { var repository = scope.ServiceProvider.GetService <IResponseRepository>(); var savedResponse = await repository.SelectResponse(response.Id); savedResponse.Response.Should().Be(response.Response); savedResponse.Id.Should().Be(response.Id); }); }
public async Task BeginTransactionAndNotCommit_ResendWithReplySuccess() { var response = new SafeRebusResponse(); var additionalOverrideConfig = new Dictionary <string, string>(); await TestServiceExecutor.ExecuteInScope(async scope => { var inputQueue = scope.ServiceProvider.GetService <IConfiguration>().GetRabbitMqInputQueue(); var outputQueue = scope.ServiceProvider.GetService <IConfiguration>().GetRabbitMqOutputQueue(); additionalOverrideConfig["rabbitMq:inputQueue"] = inputQueue; additionalOverrideConfig["rabbitMq:outputQueue"] = outputQueue; var bus = scope.ServiceProvider.GetService <IOutboxBus>(); var dbProvider = scope.ServiceProvider.GetService <IDbProvider>(); await bus.BeginTransaction(GetTransportMessage(inputQueue)); await bus.Reply(response); dbProvider.GetDbTransaction().Commit(); }, additionalOverrideConfig); await Task.Delay(TimeSpan.FromSeconds(1)); await TestServiceExecutor.ExecuteInScope(async scope => { var outboxMessageCleaner = scope.ServiceProvider.GetService <IOutboxMessageCleaner>(); await outboxMessageCleaner.CleanMessages(false); await Task.Delay(TimeSpan.FromSeconds(1)); }, additionalOverrideConfig); await TestServiceExecutor.ExecuteInScope(async scope => { var repository = scope.ServiceProvider.GetService <IResponseRepository>(); var outboxMessageRepository = scope.ServiceProvider.GetService <IOutboxMessageRepository>(); await MessageHandler.Utilities.Tools.WaitUntilSuccess(async() => { (await repository.SelectResponse(response.Id)).Id.Should().Be(response.Id); }); var outboxMessages = await outboxMessageRepository.SelectOutboxMessagesBeforeThreshold(TimeSpan.Zero); outboxMessages.Should().BeEmpty(); }, additionalOverrideConfig); }
public async Task MultipleInsertAndCheckExists_Success() { var allResponseIds = new List <Guid>(); await TestServiceExecutor.ExecuteInScope(async scope => { var repository = scope.ServiceProvider.GetService <IResponseRepository>(); var dbProvider = scope.ServiceProvider.GetService <IDbProvider>(); for (var i = 0; i < 10; i++) { var response = new SafeRebusResponse(); await repository.InsertResponse(response); allResponseIds.Add(response.Id); } dbProvider.GetDbTransaction().Commit(); }); await TestServiceExecutor.ExecuteInScope(async scope => { var repository = scope.ServiceProvider.GetService <IResponseRepository>(); var savedResponseIds = (await repository.SelectResponses(allResponseIds)).Select(savedResponse => savedResponse.Id); allResponseIds.Select(responseId => savedResponseIds.Should().Contain(responseId)); }); }