Skip to content

Commit 20f3574

Browse files
authored
Bump MongoDb.Driver to 3.0.0 (#395)
* Bump MongoDb.Driver to 3.0.0 * Cleanup FullTypeNameObjectSerializer * Fix build system * Fix build script * Fix AzDo Pipeline
1 parent e6237c7 commit 20f3574

16 files changed

+84
-93
lines changed

build-system/azure-pipeline.template.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ jobs:
1818
submodules: recursive # set to 'true' for a single level of submodules or 'recursive' to get submodules of submodules
1919
persistCredentials: true
2020
- task: UseDotNet@2
21-
displayName: 'Use .NET 7 SDK 7'
21+
displayName: 'Use .NET SDK 8'
2222
inputs:
23-
version: 7.x
23+
version: 8.x
2424
- task: UseDotNet@2
25-
displayName: 'Use .NET Core Runtime 3'
25+
displayName: 'Use .NET SDK 7'
2626
inputs:
2727
packageType: runtime
28-
version: 3.x
28+
version: 7.x
2929
# Linux or macOS
3030
- task: Bash@3
3131
displayName: Linux / OSX Build

build-system/linux-pr-validation.yaml

-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ pr:
1414
include: [ dev, master ] # branch names which will trigger a build
1515

1616
jobs:
17-
- template: azure-pipeline.template.yaml
18-
parameters:
19-
name: 'net_core_tests_linux'
20-
displayName: '.NET Core Unit Tests (Linux)'
21-
vmImage: 'ubuntu-latest'
22-
scriptFileName: ./build.sh
23-
scriptArgs: runTestsNetCore
24-
2517
- template: azure-pipeline.template.yaml
2618
parameters:
2719
name: 'net_7_tests_linux'

build-system/windows-pr-validation.yaml

-8
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@ jobs:
2222
scriptFileName: build.cmd
2323
scriptArgs: runTests
2424

25-
- template: azure-pipeline.template.yaml
26-
parameters:
27-
name: 'net_core_tests_windows'
28-
displayName: '.NET Core Unit Tests (Windows)'
29-
vmImage: 'windows-latest'
30-
scriptFileName: build.cmd
31-
scriptArgs: runTestsNetCore
32-
3325
- template: azure-pipeline.template.yaml
3426
parameters:
3527
name: 'net_7_tests_windows'

build.fsx

+48-37
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ let outputTests = __SOURCE_DIRECTORY__ @@ "TestResults"
4545
let outputPerfTests = __SOURCE_DIRECTORY__ @@ "PerfResults"
4646
let outputBinaries = output @@ "binaries"
4747
let outputNuGet = output @@ "nuget"
48-
let outputBinariesNet45 = outputBinaries @@ "net45"
49-
let outputBinariesNetStandard = outputBinaries @@ "netstandard2.0"
50-
let outputBinariesNet = outputBinaries @@ "net5.0"
48+
49+
// Configuration values for builds
50+
let buildNetFrameworkVersion = "net472"
51+
let buildNetVersion = "netstandard2.1"
5152

5253
// Configuration values for tests
53-
let testNetFrameworkVersion = "net471"
54-
let testNetCoreVersion = "netcoreapp3.1"
54+
let testNetFrameworkVersion = "net472"
5555
let testNetVersion = "net7.0"
5656

5757
Target "Clean" (fun _ ->
@@ -61,9 +61,6 @@ Target "Clean" (fun _ ->
6161
CleanDir outputTests
6262
CleanDir outputPerfTests
6363
CleanDir outputNuGet
64-
CleanDir outputBinariesNet45
65-
CleanDir outputBinariesNetStandard
66-
CleanDir outputBinariesNet
6764
CleanDir "docs/_site"
6865

6966
CleanDirs !! "./**/bin"
@@ -85,6 +82,48 @@ Target "Build" (fun _ ->
8582
AdditionalArgs = additionalArgs }) // "Rebuild"
8683
)
8784

85+
// Build target that only builds netstandard2.1 library and net7.0 test projects
86+
// Intended for build platforms that does not support .NET Framework (eg. Linux/MAC)
87+
Target "BuildNet" (fun _ ->
88+
let additionalArgs = if versionSuffix.Length > 0 then [sprintf "/p:VersionSuffix=%s" versionSuffix] else []
89+
90+
let projects =
91+
match (isWindows) with
92+
| true -> !! "./src/**/*.csproj"
93+
-- "./src/**/*.Tests.csproj"
94+
-- "./src/examples/**/*.csproj"
95+
| _ -> !! "./src/**/*.csproj" // if you need to filter specs for Linux vs. Windows, do it here
96+
-- "./src/**/*.Tests.csproj"
97+
-- "./src/examples/**/*.csproj"
98+
99+
let tests =
100+
match (isWindows) with
101+
| true -> !! "./src/**/*.Tests.csproj"
102+
| _ -> !! "./src/**/*.Tests.csproj" // if you need to filter specs for Linux vs. Windows, do it here
103+
104+
let compileSingleProject project =
105+
DotNetCli.Build
106+
(fun p ->
107+
{ p with
108+
Project = project
109+
Configuration = configuration
110+
Framework = buildNetVersion
111+
AdditionalArgs = additionalArgs }) // "Rebuild"
112+
113+
let compileSingleTest project =
114+
DotNetCli.Build
115+
(fun p ->
116+
{ p with
117+
Project = project
118+
Configuration = configuration
119+
Framework = testNetVersion
120+
AdditionalArgs = additionalArgs }) // "Rebuild"
121+
122+
projects |> Seq.iter (log)
123+
projects |> Seq.iter (compileSingleProject)
124+
tests |> Seq.iter (log)
125+
tests |> Seq.iter (compileSingleTest)
126+
)
88127

89128
//--------------------------------------------------------------------------------
90129
// Tests targets
@@ -96,7 +135,6 @@ type Runtime =
96135

97136
let getTestAssembly runtime project =
98137
let assemblyPath = match runtime with
99-
| NetCore -> !! ("src" @@ "**" @@ "bin" @@ "Release" @@ testNetCoreVersion @@ fileNameWithoutExt project + ".dll")
100138
| NetFramework -> !! ("src" @@ "**" @@ "bin" @@ "Release" @@ testNetFrameworkVersion @@ fileNameWithoutExt project + ".dll")
101139
| Net -> !! ("src" @@ "**" @@ "bin" @@ "Release" @@ testNetVersion @@ fileNameWithoutExt project + ".dll")
102140

@@ -147,30 +185,6 @@ Target "RunTests" (fun _ ->
147185
projects |> Seq.iter (runSingleProject)
148186
)
149187

150-
Target "RunTestsNetCore" (fun _ ->
151-
let projects =
152-
match (isWindows) with
153-
| true -> !! "./src/**/*.Tests.csproj"
154-
| _ -> !! "./src/**/*.Tests.csproj" // if you need to filter specs for Linux vs. Windows, do it here
155-
156-
let runSingleProject project =
157-
let arguments =
158-
match (hasTeamCity) with
159-
| true -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s --results-directory %s -- -parallel none -teamcity" testNetCoreVersion outputTests)
160-
| false -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s --results-directory %s -- -parallel none" testNetCoreVersion outputTests)
161-
162-
let result = ExecProcess(fun info ->
163-
info.FileName <- "dotnet"
164-
info.WorkingDirectory <- (Directory.GetParent project).FullName
165-
info.Arguments <- arguments) (TimeSpan.FromMinutes 30.0)
166-
167-
ResultHandling.failBuildIfXUnitReportedError TestRunnerErrorLevel.Error result
168-
169-
CreateDir outputTests
170-
projects |> Seq.iter (log)
171-
projects |> Seq.iter (runSingleProject)
172-
)
173-
174188
Target "RunTestsNet" (fun _ ->
175189
let projects =
176190
match (isWindows) with
@@ -380,15 +394,13 @@ Target "BuildRelease" DoNothing
380394
Target "All" DoNothing
381395
Target "Nuget" DoNothing
382396
Target "RunTestsFull" DoNothing
383-
Target "RunTestsNetCoreFull" DoNothing
384397

385398
// build dependencies
386399
"Clean" ==> "AssemblyInfo" ==> "Build" ==> "BuildRelease"
387400

388401
// tests dependencies
389402
"Build" ==> "RunTests"
390-
"Build" ==> "RunTestsNetCore"
391-
"Build" ==> "RunTestsNet"
403+
"AssemblyInfo" ==> "BuildNet" ==> "RunTestsNet"
392404
"Build" ==> "NBench"
393405

394406
// nuget dependencies
@@ -401,7 +413,6 @@ Target "RunTestsNetCoreFull" DoNothing
401413
// all
402414
"BuildRelease" ==> "All"
403415
"RunTests" ==> "All"
404-
"RunTestsNetCore" ==> "All"
405416
"RunTestsNet" ==> "All"
406417
"NBench" ==> "All"
407418
"Nuget" ==> "All"

src/Akka.Persistence.MongoDb.Hosting/Akka.Persistence.MongoDb.Hosting.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>$(NetStandardLibVersion)</TargetFrameworks>
3+
<TargetFrameworks>$(NetStandardLibVersion);$(NetFrameworkLibVersion)</TargetFrameworks>
44
</PropertyGroup>
55

66
<ItemGroup>

src/Akka.Persistence.MongoDb.Tests/Akka.Persistence.MongoDb.Tests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>$(NetFrameworkTestVersion);$(NetTestVersion);$(NetCoreTestVersion)</TargetFrameworks>
3+
<TargetFrameworks>$(NetFrameworkTestVersion);$(NetTestVersion)</TargetFrameworks>
44
</PropertyGroup>
55

66
<PropertyGroup>

src/Akka.Persistence.MongoDb.Tests/MongoDbJournalSetupSpec.cs

-2
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ public MongoDbJournalSetupSpec(
3131

3232
private static ActorSystemSetup CreateBootstrapSetup(DatabaseFixture fixture)
3333
{
34-
//Default LinqProvider has been changed to LINQ3.LinqProvider can be changed back to LINQ2 in the following way:
3534
var connectionString = new MongoUrl(fixture.ConnectionString);
3635
var clientSettings = MongoClientSettings.FromUrl(connectionString);
37-
clientSettings.LinqProvider = LinqProvider.V2;
3836
var client = new MongoClient(clientSettings);
3937
var databaseName = connectionString.DatabaseName;
4038
var settings = client.Settings;

src/Akka.Persistence.MongoDb.Tests/MongoDbSnapshotStoreSetupSpec.cs

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
using Akka.Actor;
22
using Akka.Actor.Setup;
33
using Akka.Configuration;
4-
using Akka.Persistence.TCK.Journal;
54
using Akka.Persistence.TCK.Snapshot;
65
using MongoDB.Driver;
7-
using MongoDB.Driver.Linq;
86
using Xunit;
97
using Xunit.Abstractions;
108

@@ -25,10 +23,8 @@ public MongoDbSnapshotStoreSetupSpec(
2523

2624
private static ActorSystemSetup CreateBootstrapSetup(DatabaseFixture fixture)
2725
{
28-
//Default LinqProvider has been changed to LINQ3.LinqProvider can be changed back to LINQ2 in the following way:
2926
var connectionString = new MongoUrl(fixture.ConnectionString);
3027
var clientSettings = MongoClientSettings.FromUrl(connectionString);
31-
clientSettings.LinqProvider = LinqProvider.V2;
3228
var client = new MongoClient(clientSettings);
3329
var databaseName = connectionString.DatabaseName;
3430
var settings = client.Settings;
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>$(NetStandardLibVersion)</TargetFrameworks>
3+
<TargetFrameworks>$(NetStandardLibVersion);$(NetFrameworkLibVersion)</TargetFrameworks>
44
</PropertyGroup>
55

66
<ItemGroup>
@@ -10,6 +10,5 @@
1010
<PackageReference Include="Akka.Persistence.Query" />
1111
<PackageReference Include="Akka.Streams" />
1212
<PackageReference Include="MongoDB.Driver" />
13-
<PackageReference Include="MongoDB.Driver.GridFS" />
1413
</ItemGroup>
1514
</Project>

src/Akka.Persistence.MongoDb/FullTypeNameObjectSerializer.cs

+12-7
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,20 @@ namespace Akka.Persistence.MongoDb
1717
/// <summary>
1818
/// Represents a serializer for objects.
1919
/// </summary>
20-
class FullTypeNameObjectSerializer : ObjectSerializer
20+
internal class FullTypeNameObjectSerializer : ClassSerializerBase<object>, IHasDiscriminatorConvention
2121
{
22-
protected readonly IDiscriminatorConvention DiscriminatorConvention = FullTypeNameDiscriminatorConvention.Instance;
23-
22+
private readonly ObjectSerializer _serializer;
23+
2424
/// <summary>
2525
/// Initializes a new instance of the <see cref="FullTypeNameObjectSerializer"/> class.
2626
/// </summary>
27-
public FullTypeNameObjectSerializer() : base(FullTypeNameDiscriminatorConvention.Instance, AllAllowedTypes) { }
27+
public FullTypeNameObjectSerializer()
28+
{
29+
_serializer = new ObjectSerializer(DiscriminatorConvention, ObjectSerializer.AllAllowedTypes);
30+
}
2831

32+
public IDiscriminatorConvention DiscriminatorConvention => FullTypeNameDiscriminatorConvention.Instance;
33+
2934
/// <summary>
3035
/// Deserializes a value.
3136
/// </summary>
@@ -38,7 +43,7 @@ public override object Deserialize(BsonDeserializationContext context, BsonDeser
3843
RegisterNewTypesToDiscriminator(DiscriminatorConvention.GetActualType(bsonReader, typeof(object)));
3944
}
4045

41-
return base.Deserialize(context, args);
46+
return _serializer.Deserialize(context, args);
4247
}
4348

4449
/// <summary>
@@ -52,14 +57,14 @@ public override void Serialize(BsonSerializationContext context, BsonSerializati
5257
RegisterNewTypesToDiscriminator(value.GetType());
5358
}
5459

55-
base.Serialize(context, args, value);
60+
_serializer.Serialize(context, args, value);
5661
}
5762

5863
/// <summary>
5964
/// If the type is not registered, attach it to our discriminator
6065
/// </summary>
6166
/// <param name="actualType">the type to examine</param>
62-
protected void RegisterNewTypesToDiscriminator(Type actualType)
67+
private void RegisterNewTypesToDiscriminator(Type actualType)
6368
{
6469
// we've detected a new concrete type that isn't registered in MongoDB's serializer
6570
if (actualType != typeof(object) && !actualType.GetTypeInfo().IsInterface && !BsonSerializer.IsTypeDiscriminated(actualType))

src/Akka.Persistence.MongoDb/Journal/MongoDbJournal.cs

-3
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,8 @@ private IMongoDatabase GetMongoDb()
7474
return _mongoDatabase_DoNotUseDirectly;
7575
}
7676

77-
//Default LinqProvider has been changed to LINQ3.LinqProvider can be changed back to LINQ2 in the following way:
7877
var connectionString = new MongoUrl(_settings.ConnectionString);
7978
var clientSettings = MongoClientSettings.FromUrl(connectionString);
80-
clientSettings.LinqProvider = LinqProvider.V2;
81-
8279
client = new MongoClient(clientSettings);
8380
_mongoDatabase_DoNotUseDirectly = client.GetDatabase(connectionString.DatabaseName);
8481
return _mongoDatabase_DoNotUseDirectly;

src/Akka.Persistence.MongoDb/Journal/MongoDbJournalQueries.cs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
using System;
88
using System.Collections.Generic;
9+
using System.Linq;
910
using System.Threading;
1011
using System.Threading.Tasks;
1112
using MongoDB.Bson;

src/Akka.Persistence.MongoDb/Snapshot/MongoDbGridFSSnapshotStore.cs

-2
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,8 @@ private IMongoDatabase GetMongoDb()
7878
var setupOption = Context.System.Settings.Setup.Get<MongoDbPersistenceSetup>();
7979
if (!setupOption.HasValue || setupOption.Value.SnapshotConnectionSettings == null)
8080
{
81-
//Default LinqProvider has been changed to LINQ3.LinqProvider can be changed back to LINQ2 in the following way:
8281
var connectionString = new MongoUrl(_settings.ConnectionString);
8382
var clientSettings = MongoClientSettings.FromUrl(connectionString);
84-
clientSettings.LinqProvider = LinqProvider.V2;
8583
client = new MongoClient(clientSettings);
8684
_mongoDatabase_DoNotUseDirectly = client.GetDatabase(connectionString.DatabaseName);
8785
return _mongoDatabase_DoNotUseDirectly;

src/Akka.Persistence.MongoDb/Snapshot/MongoDbSnapshotStore.cs

+9-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
using Akka.Persistence.Snapshot;
1313
using Akka.Util;
1414
using MongoDB.Driver;
15-
using MongoDB.Driver.Linq;
1615

1716
#nullable enable
1817
namespace Akka.Persistence.MongoDb.Snapshot
@@ -94,10 +93,8 @@ private IMongoDatabase GetMongoDb()
9493
var setupOption = Context.System.Settings.Setup.Get<MongoDbPersistenceSetup>();
9594
if (!setupOption.HasValue || setupOption.Value.SnapshotConnectionSettings == null)
9695
{
97-
//Default LinqProvider has been changed to LINQ3.LinqProvider can be changed back to LINQ2 in the following way:
9896
var connectionString = new MongoUrl(_settings.ConnectionString);
9997
var clientSettings = MongoClientSettings.FromUrl(connectionString);
100-
clientSettings.LinqProvider = LinqProvider.V2;
10198
client = new MongoClient(clientSettings);
10299
_mongoDatabase_DoNotUseDirectly = client.GetDatabase(connectionString.DatabaseName);
103100
return _mongoDatabase_DoNotUseDirectly;
@@ -135,19 +132,20 @@ protected override void PostStop()
135132
base.PostStop();
136133
}
137134

138-
protected override async Task<SelectedSnapshot> LoadAsync(string persistenceId, SnapshotSelectionCriteria criteria)
135+
protected override async Task<SelectedSnapshot?> LoadAsync(string persistenceId, SnapshotSelectionCriteria criteria)
139136
{
140137
using var unitedCts = CreatePerCallCts();
141138
var snapshotCollection = await GetSnapshotCollection(unitedCts.Token);
142139

143140
return await MaybeWithTransaction(async (session, token) =>
144141
{
145142
var filter = CreateRangeFilter(persistenceId, criteria);
146-
return await (session is not null ? snapshotCollection.Find(session, filter) : snapshotCollection.Find(filter))
143+
var entry = await (session is not null ? snapshotCollection.Find(session, filter) : snapshotCollection.Find(filter))
147144
.SortByDescending(x => x.SequenceNr)
148145
.Limit(1)
149-
.Project(x => ToSelectedSnapshot(x))
150146
.FirstOrDefaultAsync(token);
147+
148+
return ToSelectedSnapshot(entry);
151149
}, unitedCts.Token);
152150
}
153151

@@ -272,12 +270,15 @@ private SnapshotEntry ToSnapshotEntry(SnapshotMetadata metadata, object snapshot
272270
Snapshot = binary,
273271
Timestamp = metadata.Timestamp.Ticks,
274272
Manifest = binaryManifest,
275-
SerializerId = serializer?.Identifier
273+
SerializerId = serializer.Identifier
276274
};
277275
}
278276

279-
private SelectedSnapshot ToSelectedSnapshot(SnapshotEntry entry)
277+
private SelectedSnapshot? ToSelectedSnapshot(SnapshotEntry? entry)
280278
{
279+
if (entry is null)
280+
return null;
281+
281282
if (_settings.LegacySerialization)
282283
{
283284
return new SelectedSnapshot(

0 commit comments

Comments
 (0)