Skip to content

Commit

Permalink
SqlConnection reuse / MultipleActiveResultSets=true kgrzybek#122
Browse files Browse the repository at this point in the history
  • Loading branch information
kgrzybek committed Nov 14, 2020
1 parent ac359f2 commit 8e8b76e
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 28 deletions.
2 changes: 1 addition & 1 deletion runIntegrationTests.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TIMEOUT 30
docker cp ./src/Database/CompanyName.MyMeetings.Database/Scripts/CreateDatabase_Linux.sql myMeetings-integration-db:/
docker exec -i myMeetings-integration-db sh -c "/opt/mssql-tools/bin/sqlcmd -d master -i /CreateDatabase_Linux.sql -U sa -P 61cD4gE6!"
dotnet build src/ --configuration Release --no-restore
SETX ASPNETCORE_MyMeetings_IntegrationTests_ConnectionString "Server=localhost,1439;Database=MyMeetings;User=sa;Password=61cD4gE6!"
SET ASPNETCORE_MyMeetings_IntegrationTests_ConnectionString=Server=localhost,1439;Database=MyMeetings;User=sa;Password=61cD4gE6!
dotnet "src/Database/DatabaseMigrator/bin/Release/netcoreapp3.1/DatabaseMigrator.dll" %ASPNETCORE_MyMeetings_IntegrationTests_ConnectionString% "src/Database/CompanyName.MyMeetings.Database/Scripts/Migrations"
dotnet test --configuration Release --no-build --verbosity normal src/Modules/Administration/Tests/IntegrationTests/CompanyName.MyMeetings.Modules.Administration.IntegrationTests.csproj
dotnet test --configuration Release --no-build --verbosity normal src/Modules/Payments/Tests/IntegrationTests/CompanyName.MyMeetings.Modules.Payments.IntegrationTests.csproj
Expand Down
5 changes: 3 additions & 2 deletions src/BuildingBlocks/EventBus/InMemoryEventBus.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CompanyName.MyMeetings.BuildingBlocks.Infrastructure.EventBus;

namespace CompanyName.MyMeetings.BuildingBlocks.EventBus
Expand All @@ -25,7 +26,7 @@ public void Subscribe<T>(IIntegrationEventHandler<T> handler)
_handlers.Add(new HandlerSubscription(handler, typeof(T).FullName));
}

public void Publish<T>(T @event)
public async Task Publish<T>(T @event)
where T : IntegrationEvent
{
var eventType = @event.GetType();
Expand All @@ -36,7 +37,7 @@ public void Publish<T>(T @event)
{
if (integrationEventHandler.Handler is IIntegrationEventHandler<T> handler)
{
handler.Handle(@event);
await handler.Handle(@event);
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/BuildingBlocks/EventBus/InMemoryEventBusClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CompanyName.MyMeetings.BuildingBlocks.Infrastructure.EventBus;
using System.Threading.Tasks;
using CompanyName.MyMeetings.BuildingBlocks.Infrastructure.EventBus;
using Serilog;

namespace CompanyName.MyMeetings.BuildingBlocks.EventBus
Expand All @@ -16,11 +17,11 @@ public void Dispose()
{
}

public void Publish<T>(T @event)
public async Task Publish<T>(T @event)
where T : IntegrationEvent
{
_logger.Information("Publishing {Event}", @event.GetType().FullName);
InMemoryEventBus.Instance.Publish(@event);
await InMemoryEventBus.Instance.Publish(@event);
}

public void Subscribe<T>(IIntegrationEventHandler<T> handler)
Expand Down
3 changes: 2 additions & 1 deletion src/BuildingBlocks/Infrastructure/EventBus/IEventsBus.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System.Threading.Tasks;

namespace CompanyName.MyMeetings.BuildingBlocks.Infrastructure.EventBus
{
public interface IEventsBus : IDisposable
{
void Publish<T>(T @event)
Task Publish<T>(T @event)
where T : IntegrationEvent;

void Subscribe<T>(IIntegrationEventHandler<T> handler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ internal NewUserRegisteredIntegrationEventHandler(ICommandsScheduler commandsSch
_commandsScheduler = commandsScheduler;
}

public Task Handle(NewUserRegisteredIntegrationEvent notification, CancellationToken cancellationToken)
public async Task Handle(NewUserRegisteredIntegrationEvent notification, CancellationToken cancellationToken)
{
_commandsScheduler.EnqueueAsync(new
await _commandsScheduler.EnqueueAsync(new
CreateMemberCommand(
Guid.NewGuid(),
notification.UserId,
Expand All @@ -27,8 +27,6 @@ public Task Handle(NewUserRegisteredIntegrationEvent notification, CancellationT
notification.FirstName,
notification.LastName,
notification.Name));

return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public async Task<Unit> Handle(ProcessInboxCommand command, CancellationToken ca
throw;
}

await connection.ExecuteAsync(sqlUpdateProcessedDate, new
await connection.ExecuteScalarAsync(sqlUpdateProcessedDate, new
{
Date = DateTime.UtcNow,
message.Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public NewUserRegisteredIntegrationEventHandler(ICommandsScheduler commandsSched
_commandsScheduler = commandsScheduler;
}

public Task Handle(NewUserRegisteredIntegrationEvent notification, CancellationToken cancellationToken)
public async Task Handle(NewUserRegisteredIntegrationEvent notification, CancellationToken cancellationToken)
{
_commandsScheduler.EnqueueAsync(new
await _commandsScheduler.EnqueueAsync(new
CreateMemberCommand(
Guid.NewGuid(),
notification.UserId,
Expand All @@ -27,8 +27,6 @@ public Task Handle(NewUserRegisteredIntegrationEvent notification, CancellationT
notification.FirstName,
notification.LastName,
notification.Name));

return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Threading;
using System.Threading.Tasks;
using CompanyName.MyMeetings.BuildingBlocks.Application.Data;
using CompanyName.MyMeetings.BuildingBlocks.Infrastructure;
using CompanyName.MyMeetings.Modules.Meetings.Application.Configuration.Commands;
using Dapper;
using MediatR;
Expand Down Expand Up @@ -57,7 +56,7 @@ public async Task<Unit> Handle(ProcessInboxCommand command, CancellationToken ca
throw;
}

await connection.ExecuteAsync(sqlUpdateProcessedDate, new
await connection.ExecuteScalarAsync(sqlUpdateProcessedDate, new
{
Date = DateTime.UtcNow,
message.Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ internal NewUserRegisteredIntegrationEventHandler(ICommandsScheduler commandsSch
_commandsScheduler = commandsScheduler;
}

public Task Handle(NewUserRegisteredIntegrationEvent notification, CancellationToken cancellationToken)
public async Task Handle(NewUserRegisteredIntegrationEvent notification, CancellationToken cancellationToken)
{
_commandsScheduler.EnqueueAsync(new
await _commandsScheduler.EnqueueAsync(new
CreatePayerCommand(
Guid.NewGuid(),
notification.UserId,
Expand All @@ -27,8 +27,6 @@ public Task Handle(NewUserRegisteredIntegrationEvent notification, CancellationT
notification.FirstName,
notification.LastName,
notification.Name));

return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ public async Task<Unit> Handle(ProcessInboxCommand command, CancellationToken ca

try
{
await _mediator.Publish((INotification)request, cancellationToken);
await _mediator.Publish((INotification) request, cancellationToken);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}

await connection.ExecuteAsync(sqlUpdateProcessedDate, new
await connection.ExecuteScalarAsync(sqlUpdateProcessedDate, new
{
Date = DateTime.UtcNow,
message.Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public NewUserRegisteredPublishEventHandler(IEventsBus eventsBus)
_eventsBus = eventsBus;
}

public Task Handle(NewUserRegisteredNotification notification, CancellationToken cancellationToken)
public async Task Handle(NewUserRegisteredNotification notification, CancellationToken cancellationToken)
{
_eventsBus.Publish(new NewUserRegisteredIntegrationEvent(
await _eventsBus.Publish(new NewUserRegisteredIntegrationEvent(
notification.Id,
notification.DomainEvent.OccurredOn,
notification.DomainEvent.UserRegistrationId.Value,
Expand All @@ -26,8 +26,6 @@ public Task Handle(NewUserRegisteredNotification notification, CancellationToken
notification.DomainEvent.FirstName,
notification.DomainEvent.LastName,
notification.DomainEvent.Name));

return Task.CompletedTask;
}
}
}

0 comments on commit 8e8b76e

Please sign in to comment.