Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactoring #32

Merged
merged 45 commits into from
Mar 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
ff6cdd8
refactored as theory with multiple hosts
mizrael Mar 24, 2021
ac8baa7
Merge branch 'develop' into cosmosdb
mizrael Mar 24, 2021
c854149
refactored as theory with multiple hosts
mizrael Mar 24, 2021
94d3a34
refactoring
mizrael Mar 24, 2021
9ea9b63
small fix
mizrael Mar 24, 2021
2e1e4a4
updated cancellation policy
mizrael Mar 25, 2021
d518c1c
test
mizrael Mar 25, 2021
5eec52b
updated test cleanup strategy
mizrael Mar 25, 2021
2acba2e
updated partition key
mizrael Mar 25, 2021
ec040ef
updated cancellation policy
mizrael Mar 25, 2021
78a795c
updated message filtering
mizrael Mar 25, 2021
bedd101
improved logging
mizrael Mar 25, 2021
5207770
we need to track the entity changes
mizrael Mar 25, 2021
f201331
removed retry policy, fail fast
mizrael Mar 25, 2021
eaa42f2
removed unnecessary test
mizrael Mar 25, 2021
e0033bf
updated exception message
mizrael Mar 25, 2021
c5db2fd
removed try/catch
mizrael Mar 25, 2021
91e739e
updated dispose pattern
mizrael Mar 25, 2021
f2e71ed
minor fixes
mizrael Mar 25, 2021
158a332
fixed test
mizrael Mar 25, 2021
385a806
refactored to store messages in a outbox on the state before persisti…
mizrael Mar 25, 2021
61412d3
updated samples
mizrael Mar 25, 2021
44b81e7
excluding E2E tests from sonarscan
mizrael Mar 25, 2021
fa21aed
splitted tests execution
mizrael Mar 25, 2021
3c553d8
improved locking
mizrael Mar 25, 2021
bbd04b7
removed space
mizrael Mar 25, 2021
05d1374
disabled Dispose on DEBUG mode
mizrael Mar 25, 2021
203b761
updated services startup and lifecycle
mizrael Mar 26, 2021
17cc146
removed try catch
mizrael Mar 26, 2021
41c273b
updated test initialization and cleanup
mizrael Mar 26, 2021
90bdd4b
updated tests to use ServiceBus instead of InMemory
mizrael Mar 26, 2021
0b8b19b
added e2e tests project
mizrael Mar 26, 2021
d1e7e35
moved cosmos sql + service bus tests to e2e project
mizrael Mar 26, 2021
683fb3a
moved cosmosMongo tests + servicebus to e2e project
mizrael Mar 26, 2021
e5d9a03
added db cleanup
mizrael Mar 26, 2021
347bc1e
cleanup
mizrael Mar 26, 2021
db568ee
skipping E2E tests for now
mizrael Mar 26, 2021
1d35bec
moved e2e tests
mizrael Mar 26, 2021
01b4ae3
added infrastructure creator
mizrael Mar 27, 2021
81a888b
minor fixes
mizrael Mar 27, 2021
6862030
moved e2e tests
mizrael Mar 27, 2021
6d3ea96
chores
mizrael Mar 27, 2021
df1e171
moved to public to fix unit tests
mizrael Mar 27, 2021
1d7d508
removed unnecessary using statements
mizrael Mar 27, 2021
96146e8
addressed sonarcloud issues
mizrael Mar 27, 2021
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
18 changes: 15 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,22 @@ jobs:
steps:
- checkout
- run:
name: Build and test
name: Build
command: |
dotnet build
dotnet test --no-build
- run:
name: Unit tests
command: |
dotnet test --filter "Category!=E2E&Category!=Integration"
- run:
name: Integration tests
command: |
dotnet test --filter "Category=Integration"

#- run: # skipping E2E tests for now
# name: E2E tests
# command: |
# dotnet test --filter "Category=E2E"

sonarscan:
docker:
Expand Down Expand Up @@ -86,7 +98,7 @@ jobs:
name: Build and test
command: |
dotnet build
dotnet test --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput=coverage.opencover.xml
dotnet test --no-build --filter "Category!=E2E" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput=coverage.opencover.xml

- run:
name: Stop Sonarcloud
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file.

## [2021-03-26](https://github.com/mizrael/OpenSleigh/pull/32)
### Added
- major refactoring
- moved E2E tests to standalone project
### Fixed
- addressed minor consistency issue
- minor bugfixes

## [2021-03-23](https://github.com/mizrael/OpenSleigh/pull/31)
### Added
- added Kafka transport library
Expand Down
10 changes: 8 additions & 2 deletions OpenSleigh.sln
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenSleigh.Persistence.Cosm
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenSleigh.Persistence.Cosmos.SQL.Tests", "tests\OpenSleigh.Persistence.Cosmos.SQL.Tests\OpenSleigh.Persistence.Cosmos.SQL.Tests.csproj", "{08E996DB-3D0C-4A63-8166-BF61732D3B21}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSleigh.Transport.Kafka", "src\OpenSleigh.Transport.Kafka\OpenSleigh.Transport.Kafka.csproj", "{887358C5-9EFF-4498-A04B-E12B199EC259}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenSleigh.Transport.Kafka", "src\OpenSleigh.Transport.Kafka\OpenSleigh.Transport.Kafka.csproj", "{887358C5-9EFF-4498-A04B-E12B199EC259}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSleigh.Transport.Kafka.Tests", "tests\OpenSleigh.Transport.Kafka.Tests\OpenSleigh.Transport.Kafka.Tests.csproj", "{5B363808-664B-42F4-8C38-EEFB9F05C500}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenSleigh.Transport.Kafka.Tests", "tests\OpenSleigh.Transport.Kafka.Tests\OpenSleigh.Transport.Kafka.Tests.csproj", "{5B363808-664B-42F4-8C38-EEFB9F05C500}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSleigh.E2ETests", "tests\OpenSleigh.E2ETests\OpenSleigh.E2ETests.csproj", "{A14A1452-A758-4CF3-83CC-E1C6897D83ED}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -121,6 +123,10 @@ Global
{5B363808-664B-42F4-8C38-EEFB9F05C500}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5B363808-664B-42F4-8C38-EEFB9F05C500}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5B363808-664B-42F4-8C38-EEFB9F05C500}.Release|Any CPU.Build.0 = Release|Any CPU
{A14A1452-A758-4CF3-83CC-E1C6897D83ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A14A1452-A758-4CF3-83CC-E1C6897D83ED}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A14A1452-A758-4CF3-83CC-E1C6897D83ED}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A14A1452-A758-4CF3-83CC-E1C6897D83ED}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public async Task HandleAsync(IMessageContext<StartSaga> context, CancellationTo
_logger.LogInformation($"starting saga '{context.Message.CorrelationId}'...");

var message = new ProcessMySaga(Guid.NewGuid(), context.Message.CorrelationId);
await this.Bus.PublishAsync(message, cancellationToken);
this.Publish(message);
}

public async Task HandleAsync(IMessageContext<ProcessMySaga> context, CancellationToken cancellationToken = default)
{
_logger.LogInformation($"processing saga '{context.Message.CorrelationId}'...");

var message = new MySagaCompleted(Guid.NewGuid(), context.Message.CorrelationId);
await this.Bus.PublishAsync(message, cancellationToken);
this.Publish(message);
}

public Task HandleAsync(IMessageContext<MySagaCompleted> context, CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task HandleAsync(IMessageContext<StartChildSaga> context, Cancellat
await Task.Delay(TimeSpan.FromSeconds(_random.Next(1, 5)), cancellationToken);

var message = new ProcessChildSaga(Guid.NewGuid(), context.Message.CorrelationId);
await this.Bus.PublishAsync(message, cancellationToken);
this.Publish(message);
}

public async Task HandleAsync(IMessageContext<ProcessChildSaga> context, CancellationToken cancellationToken = default)
Expand All @@ -50,7 +50,7 @@ public async Task HandleAsync(IMessageContext<ProcessChildSaga> context, Cancell
_logger.LogInformation($"child saga '{context.Message.CorrelationId}' completed!");

var completedEvent = new ChildSagaCompleted(Guid.NewGuid(), context.Message.CorrelationId);
await this.Bus.PublishAsync(completedEvent, cancellationToken);
this.Publish(completedEvent);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ public async Task HandleAsync(IMessageContext<StartParentSaga> context, Cancella
_logger.LogInformation($"starting parent saga '{context.Message.CorrelationId}'...");

var message = new ProcessParentSaga(Guid.NewGuid(), context.Message.CorrelationId);
await this.Bus.PublishAsync(message, cancellationToken);
this.Publish(message);
}

public async Task HandleAsync(IMessageContext<ProcessParentSaga> context, CancellationToken cancellationToken = default)
{
_logger.LogInformation($"starting child saga from parent saga '{context.Message.CorrelationId}'...");

var message = new StartChildSaga(Guid.NewGuid(), context.Message.CorrelationId);
await this.Bus.PublishAsync(message, cancellationToken);
this.Publish(message);
}

public async Task HandleAsync(IMessageContext<ChildSagaCompleted> context, CancellationToken cancellationToken = default)
Expand All @@ -56,7 +56,7 @@ public async Task HandleAsync(IMessageContext<ChildSagaCompleted> context, Cance
await Task.Delay(TimeSpan.FromSeconds(_random.Next(1, 5)), cancellationToken);

var message = new ParentSagaCompleted(Guid.NewGuid(), context.Message.CorrelationId);
await this.Bus.PublishAsync(message, cancellationToken);
this.Publish(message);
}

public Task HandleAsync(IMessageContext<ParentSagaCompleted> context, CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public async Task HandleAsync(IMessageContext<StartSimpleSaga> context, Cancella
_logger.LogInformation($"starting saga '{context.Message.CorrelationId}'...");

var message = new ProcessSimpleSaga(Guid.NewGuid(), context.Message.CorrelationId);
await this.Bus.PublishAsync(message, cancellationToken);
this.Publish(message);
}

public async Task HandleAsync(IMessageContext<ProcessSimpleSaga> context, CancellationToken cancellationToken = default)
{
_logger.LogInformation($"processing saga '{context.Message.CorrelationId}'...");

var message = new SimpleSagaCompleted(Guid.NewGuid(), context.Message.CorrelationId);
await this.Bus.PublishAsync(message, cancellationToken);
this.Publish(message);
}

public Task HandleAsync(IMessageContext<SimpleSagaCompleted> context, CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,20 @@ public async Task HandleAsync(IMessageContext<StartChildSaga> context, Cancellat
await Task.Delay(TimeSpan.FromSeconds(_random.Next(1, 5)), cancellationToken);

var message = new ProcessChildSaga(Guid.NewGuid(), context.Message.CorrelationId);
await this.Bus.PublishAsync(message, cancellationToken);
this.Publish(message);
}

public async Task HandleAsync(IMessageContext<ProcessChildSaga> context, CancellationToken cancellationToken = default)
public async Task HandleAsync(IMessageContext<ProcessChildSaga> context,
CancellationToken cancellationToken = default)
{
_logger.LogInformation($"processing child saga '{context.Message.CorrelationId}'...");

await Task.Delay(TimeSpan.FromSeconds(_random.Next(1, 5)), cancellationToken);

_logger.LogInformation($"child saga '{context.Message.CorrelationId}' completed!");

var completedEvent = new ChildSagaCompleted(Guid.NewGuid(), context.Message.CorrelationId);
await this.Bus.PublishAsync(completedEvent, cancellationToken);
this.Publish(completedEvent);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ public async Task HandleAsync(IMessageContext<StartParentSaga> context, Cancella
_logger.LogInformation($"starting parent saga '{context.Message.CorrelationId}'...");

var message = new ProcessParentSaga(Guid.NewGuid(), context.Message.CorrelationId);
await this.Bus.PublishAsync(message, cancellationToken);
this.Publish(message);
}

public async Task HandleAsync(IMessageContext<ProcessParentSaga> context, CancellationToken cancellationToken = default)
{
_logger.LogInformation($"starting child saga from parent saga '{context.Message.CorrelationId}'...");

var message = new StartChildSaga(Guid.NewGuid(), context.Message.CorrelationId);
await this.Bus.PublishAsync(message, cancellationToken);
this.Publish(message);
}

public async Task HandleAsync(IMessageContext<ChildSagaCompleted> context, CancellationToken cancellationToken = default)
Expand All @@ -56,7 +56,7 @@ public async Task HandleAsync(IMessageContext<ChildSagaCompleted> context, Cance
await Task.Delay(TimeSpan.FromSeconds(_random.Next(1, 5)), cancellationToken);

var message = new ParentSagaCompleted(Guid.NewGuid(), context.Message.CorrelationId);
await this.Bus.PublishAsync(message, cancellationToken);
this.Publish(message);
}

public Task HandleAsync(IMessageContext<ParentSagaCompleted> context, CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public async Task HandleAsync(IMessageContext<StartSimpleSaga> context, Cancella
_logger.LogInformation($"starting saga '{context.Message.CorrelationId}'...");

var message = new ProcessSimpleSaga(Guid.NewGuid(), context.Message.CorrelationId);
await this.Bus.PublishAsync(message, cancellationToken);
this.Publish(message);
}

public async Task HandleAsync(IMessageContext<ProcessSimpleSaga> context, CancellationToken cancellationToken = default)
{
_logger.LogInformation($"processing saga '{context.Message.CorrelationId}'...");

var message = new SimpleSagaCompleted(Guid.NewGuid(), context.Message.CorrelationId);
await this.Bus.PublishAsync(message, cancellationToken);
this.Publish(message);
}

public Task HandleAsync(IMessageContext<SimpleSagaCompleted> context, CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task HandleAsync(IMessageContext<CheckInventory> context, Cancellat
_logger.LogInformation($"checking inventory for order '{context.Message.OrderId}'...");

var message = InventoryCheckCompleted.New(context.Message.OrderId);
await this.Bus.PublishAsync(message, cancellationToken);
this.Publish(message);

this.State.MarkAsCompleted();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public async Task HandleAsync(IMessageContext<SaveOrder> context, CancellationTo
this.State.OrderId = context.Message.OrderId;

var startCreditCheck = ProcessCreditCheck.New(context.Message.OrderId);
await this.Bus.PublishAsync(startCreditCheck, cancellationToken);
this.Publish(startCreditCheck);

var startInventoryCheck = CheckInventory.New(context.Message.OrderId);
await this.Bus.PublishAsync(startInventoryCheck, cancellationToken);
this.Publish(startInventoryCheck);
}

public async Task HandleAsync(IMessageContext<CrediCheckCompleted> context, CancellationToken cancellationToken = default)
Expand All @@ -66,7 +66,7 @@ public async Task HandleAsync(IMessageContext<ShippingCompleted> context, Cancel
_logger.LogInformation($"shipping for order '{context.Message.OrderId}' completed!");

var message = OrderSagaCompleted.New(this.State.OrderId);
await this.Bus.PublishAsync(message, cancellationToken);
this.Publish(message);

this.State.MarkAsCompleted();
}
Expand All @@ -79,7 +79,7 @@ private async Task CheckStateAsync(CancellationToken cancellationToken = default
return;

var message = ProcessShipping.New(this.State.OrderId);
await this.Bus.PublishAsync(message, cancellationToken);
this.Publish(message);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task HandleAsync(IMessageContext<ProcessCreditCheck> context, Cance
_logger.LogInformation($"processing credit check for order '{context.Message.OrderId}'...");

var message = CrediCheckCompleted.New(context.Message.OrderId);
await this.Bus.PublishAsync(message, cancellationToken);
this.Publish(message);

this.State.MarkAsCompleted();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task HandleAsync(IMessageContext<ProcessShipping> context, Cancella
_logger.LogInformation($"processing shipping for order '{context.Message.OrderId}'...");

var message = ShippingCompleted.New(context.Message.OrderId);
await this.Bus.PublishAsync(message, cancellationToken);
this.Publish(message);

this.State.MarkAsCompleted();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task HandleAsync(IMessageContext<StartSaga> context, CancellationTo
throw new ApplicationException("whoops!");

var message = new MySagaCompleted(Guid.NewGuid(), context.Message.CorrelationId);
await this.Bus.PublishAsync(message, cancellationToken);
this.Publish(message);
}

public Task HandleAsync(IMessageContext<MySagaCompleted> context, CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task HandleAsync(IMessageContext<StartSaga> context, CancellationTo
_logger.LogInformation($"processing saga '{context.Message.CorrelationId}'...");

var message = new MySagaCompleted(Guid.NewGuid(), context.Message.CorrelationId);
await this.Bus.PublishAsync(message, cancellationToken);
this.Publish(message);
}

public Task HandleAsync(IMessageContext<MySagaCompleted> context, CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task HandleAsync(IMessageContext<StartSaga> context, CancellationTo
this.State.CurrentStep = MySagaState.Steps.Successful;

var message = new MySagaCompleted(Guid.NewGuid(), context.Message.CorrelationId);
await this.Bus.PublishAsync(message, cancellationToken);
this.Publish(message);
}

public async Task CompensateAsync(ICompensationContext<StartSaga> context, CancellationToken cancellationToken = default)
Expand All @@ -56,7 +56,7 @@ public async Task CompensateAsync(ICompensationContext<StartSaga> context, Cance
this.State.CurrentStep = MySagaState.Steps.Failed;

var message = new MySagaCompleted(Guid.NewGuid(), context.MessageContext.Message.CorrelationId);
await this.Bus.PublishAsync(message, cancellationToken);
this.Publish(message);
}

public Task HandleAsync(IMessageContext<MySagaCompleted> context, CancellationToken cancellationToken = default)
Expand Down
12 changes: 3 additions & 9 deletions samples/Sample8/Server/Sagas/StepsSaga.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ public async Task HandleAsync(IMessageContext<StartSaga> context, CancellationTo

await SendNotification($"starting saga {context.Message.CorrelationId} with {State.TotalSteps} total steps...");

await this.Bus.PublishAsync(
new ProcessNextStep(Guid.NewGuid(), context.Message.CorrelationId),
cancellationToken);
this.Publish(new ProcessNextStep(Guid.NewGuid(), context.Message.CorrelationId));
}

public async Task HandleAsync(IMessageContext<ProcessNextStep> context,
Expand All @@ -66,19 +64,15 @@ public async Task HandleAsync(IMessageContext<StartSaga> context, CancellationTo

if (State.CurrentStep > State.TotalSteps)
{
await this.Bus.PublishAsync(
new SagaCompleted(Guid.NewGuid(), context.Message.CorrelationId),
cancellationToken);
this.Publish(new SagaCompleted(Guid.NewGuid(), context.Message.CorrelationId));
return;
}

await SendNotification($"processing step {State.CurrentStep}/{State.TotalSteps} on saga {context.Message.CorrelationId} ...");

await Task.Delay(250, cancellationToken);

await this.Bus.PublishAsync(
new ProcessNextStep(Guid.NewGuid(), context.Message.CorrelationId),
cancellationToken);
this.Publish(new ProcessNextStep(Guid.NewGuid(), context.Message.CorrelationId));
}

public async Task HandleAsync(IMessageContext<SagaCompleted> context, CancellationToken cancellationToken = default)
Expand Down
Loading