-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow storing extra data on objects before persisting (#17)
* rename GetLatestObjects to QueryLatest * allow multiple object adapters * ensure Simple kernel can be used across multiple tests with different Json configs used by EF * test `BeforeSaveObject ` to store commit id among other data * move BeforeSaveObject up into the snapshot worker so it's always applied to objects, not only when using projected tables * enable benchmarking comments * change BeforePersistObject to BeforeSaveObject
- Loading branch information
Showing
18 changed files
with
193 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,8 @@ on: | |
pull_request: | ||
branches: | ||
- main | ||
|
||
permissions: | ||
pull-requests: write #allow benchmark-action to comment on PRs | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
@@ -19,4 +20,19 @@ jobs: | |
uses: actions/setup-dotnet@v4 | ||
|
||
- name: Build & test | ||
run: dotnet test --configuration Release --logger GitHubActions | ||
run: dotnet test --configuration Release --logger GitHubActions | ||
- name: Download previous benchmark data | ||
uses: actions/cache@v4 | ||
with: | ||
path: ./cache | ||
key: ${{ runner.os }}-benchmark | ||
- name: Continuous Benchmark | ||
uses: benchmark-action/[email protected] | ||
with: | ||
tool: benchmarkdotnet | ||
output-file-path: src/artifacts/bin/SIL.Harmony.Tests/release/BenchmarkDotNet.Artifacts/results/SIL.Harmony.Tests.DataModelPerformanceBenchmarks-report-full-compressed.json | ||
external-data-json-path: ./cache/benchmark-data.json | ||
fail-on-alert: true | ||
comment-on-alert: true | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
using SIL.Harmony.Changes; | ||
using SIL.Harmony.Core; | ||
using SIL.Harmony.Entities; | ||
using SIL.Harmony.Sample; | ||
|
||
namespace SIL.Harmony.Tests; | ||
|
||
public class PersistExtraDataTests | ||
{ | ||
private DataModelTestBase _dataModelTestBase; | ||
|
||
public class CreateExtraDataModelChange(Guid entityId) : CreateChange<ExtraDataModel>(entityId), ISelfNamedType<CreateExtraDataModelChange> | ||
{ | ||
public override ValueTask<ExtraDataModel> NewEntity(Commit commit, ChangeContext context) | ||
{ | ||
return ValueTask.FromResult(new ExtraDataModel() | ||
{ | ||
Id = EntityId, | ||
}); | ||
} | ||
} | ||
|
||
public class ExtraDataModel : IObjectBase<ExtraDataModel> | ||
{ | ||
public Guid Id { get; set; } | ||
public DateTimeOffset? DeletedAt { get; set; } | ||
public Guid CommitId { get; set; } | ||
public DateTimeOffset? DateTime { get; set; } | ||
public long Counter { get; set; } | ||
|
||
public Guid[] GetReferences() | ||
{ | ||
return []; | ||
} | ||
|
||
public void RemoveReference(Guid id, Commit commit) | ||
{ | ||
} | ||
|
||
public IObjectBase Copy() | ||
{ | ||
return new ExtraDataModel() | ||
{ | ||
Id = Id, | ||
DeletedAt = DeletedAt, | ||
CommitId = CommitId, | ||
DateTime = DateTime, | ||
Counter = Counter | ||
}; | ||
} | ||
} | ||
|
||
public PersistExtraDataTests() | ||
{ | ||
_dataModelTestBase = new DataModelTestBase(configure: services => | ||
{ | ||
services.Configure<CrdtConfig>(config => | ||
{ | ||
config.ObjectTypeListBuilder.DefaultAdapter().Add<ExtraDataModel>(); | ||
config.ChangeTypeListBuilder.Add<CreateExtraDataModelChange>(); | ||
config.BeforeSaveObject = (obj, snapshot) => | ||
{ | ||
if (obj is ExtraDataModel extraDataModel) | ||
{ | ||
extraDataModel.CommitId = snapshot.CommitId; | ||
extraDataModel.DateTime = snapshot.Commit.HybridDateTime.DateTime; | ||
extraDataModel.Counter = snapshot.Commit.HybridDateTime.Counter; | ||
} | ||
return ValueTask.CompletedTask; | ||
}; | ||
}); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public async Task CanPersistExtraData() | ||
{ | ||
var entityId = Guid.NewGuid(); | ||
var commit = await _dataModelTestBase.WriteNextChange(new CreateExtraDataModelChange(entityId)); | ||
var extraDataModel = _dataModelTestBase.DataModel.QueryLatest<ExtraDataModel>().Should().ContainSingle().Subject; | ||
extraDataModel.Id.Should().Be(entityId); | ||
extraDataModel.CommitId.Should().Be(commit.Id); | ||
extraDataModel.DateTime.Should().Be(commit.HybridDateTime.DateTime); | ||
extraDataModel.Counter.Should().Be(commit.HybridDateTime.Counter); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.