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

Add programmatic Setup support #199

Merged
merged 9 commits into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,30 @@ akka.persistence {
}
```

### Programmatic configuration

You can programmatically overrides the connection string setting in the HOCON configuration by adding a `MongoDbPersistenceSetup` to the
`ActorSystemSetup` during `ActorSystem` creation. The `MongoDbPersistenceSetup` takes `MongoClientSettings` instances to be used to configure
MongoDB client connection to the server. The `connection-string` settings in the HOCON configuration will be ignored if any of these `MongoClientSettings`
exists inside the Setup object.

Example:
```
// Set snapshotClientSettings or journalClientSettings to null if you do not use them.
var snapshotClientSettings = new MongoClientSettings();
var journalClientSettings = new MongoClientSettings();

// database names are not needed when its client setting is set to null
var snapshotDatabaseName = "theSnapshotDatabase"
var journalDatabaseName = "theJournalDatabase"

var setup = BootstrapSetup.Create()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need some more examples:

  1. Journal only
  2. Snapshot store only
  3. Both (which you have included here)

Also need to explain that you still need to set the mongodb plugin in akka.persistence.journal and akka.persistence.snapshot-store in HOCON even with these settings passed in.

.WithConfig(myHoconConfig)
.And(new MongoDbPersistenceSetup(snapshotDatabaseName, snapshotClientSettings, journalDatabaseName, journalClientSettings));

var actorSystem = ActorSystem.Create("actorSystem", setup);
```

### Serialization
[Going from v1.4.0 onwards, all events and snapshots are saved as byte arrays using the standard Akka.Persistence format](https://github.com/akkadotnet/Akka.Persistence.MongoDB/issues/72).

Expand Down
11 changes: 11 additions & 0 deletions build-system/azure-pipeline.template.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
parameters:
name: ''
displayName: ''
vmImage: ''
scriptFileName: ''
scriptArgs: 'all'
timeoutInMinutes: 120

jobs:
- job: ${{ parameters.name }}
displayName: ${{ parameters.displayName }}
timeoutInMinutes: ${{ parameters.timeoutInMinutes }}
pool:
vmImage: ${{ parameters.vmImage }}
Expand All @@ -15,6 +17,15 @@ jobs:
clean: false # whether to fetch clean each time
submodules: recursive # set to 'true' for a single level of submodules or 'recursive' to get submodules of submodules
persistCredentials: true
- task: UseDotNet@2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

displayName: 'Use .NET 5 SDK 5.0.101'
inputs:
version: 5.0.101
- task: UseDotNet@2
displayName: 'Use .NET Core Runtime 3.1.10'
inputs:
packageType: runtime
version: 3.1.10
# Linux or macOS
- task: Bash@3
displayName: Linux / OSX Build
Expand Down
21 changes: 15 additions & 6 deletions build-system/linux-pr-validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@ pr:
include: [ dev, master ] # branch names which will trigger a build

jobs:
- template: azure-pipeline.template.yaml
parameters:
name: Ubuntu
vmImage: 'ubuntu-16.04'
scriptFileName: ./build.sh
scriptArgs: all
- template: azure-pipeline.template.yaml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

parameters:
name: 'net_core_tests_linux'
displayName: '.NET Core Unit Tests (Linux)'
vmImage: 'ubuntu-18.04'
scriptFileName: ./build.sh
scriptArgs: runTestsNetCore

- template: azure-pipeline.template.yaml
parameters:
name: 'net_5_tests_linux'
displayName: '.NET 5 Unit Tests (Linux)'
vmImage: 'ubuntu-18.04'
scriptFileName: ./build.sh
scriptArgs: runTestsNet
39 changes: 33 additions & 6 deletions build-system/windows-pr-validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,36 @@ pr:
name: $(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)

jobs:
- template: azure-pipeline.template.yaml
parameters:
name: Windows
vmImage: 'vs2017-win2016'
scriptFileName: build.cmd
scriptArgs: all
- template: azure-pipeline.template.yaml
parameters:
name: 'netfx_tests_windows'
displayName: '.NET Framework Unit Tests (Windows)'
vmImage: 'windows-2019'
scriptFileName: build.cmd
scriptArgs: runTests

- template: azure-pipeline.template.yaml
parameters:
name: 'net_core_tests_windows'
displayName: '.NET Core Unit Tests (Windows)'
vmImage: 'windows-2019'
scriptFileName: build.cmd
scriptArgs: runTestsNetCore

- template: azure-pipeline.template.yaml
parameters:
name: 'net_5_tests_windows'
displayName: '.NET 5 Unit Tests (Windows)'
vmImage: 'windows-2019'
scriptFileName: build.cmd
scriptArgs: runTestsNet

- template: azure-pipeline.template.yaml
parameters:
name: 'nuget_pack'
displayName: 'NuGet Pack'
vmImage: 'windows-2019'
scriptFileName: build.cmd
scriptArgs: CreateNuget nugetprerelease=dev
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

outputDirectory: 'bin/nuget'
artifactName: 'nuget_pack-$(Build.BuildId)'
113 changes: 102 additions & 11 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ let toolsDir = __SOURCE_DIRECTORY__ @@ "tools"
let output = __SOURCE_DIRECTORY__ @@ "bin"
let outputTests = __SOURCE_DIRECTORY__ @@ "TestResults"
let outputPerfTests = __SOURCE_DIRECTORY__ @@ "PerfResults"
let outputBinaries = output @@ "binaries"
let outputNuGet = output @@ "nuget"
let outputBinariesNet45 = outputBinaries @@ "net45"
let outputBinariesNetStandard = outputBinaries @@ "netstandard2.0"
let outputBinariesNet = outputBinaries @@ "net5.0"

// Configuration values for tests
let testNetFrameworkVersion = "net471"
let testNetCoreVersion = "netcoreapp3.1"
let testNetVersion = "net5.0"

Target "Clean" (fun _ ->
ActivateFinalTarget "KillCreatedProcesses"
Expand All @@ -52,7 +61,13 @@ Target "Clean" (fun _ ->
CleanDir outputTests
CleanDir outputPerfTests
CleanDir outputNuGet
CleanDir outputBinariesNet45
CleanDir outputBinariesNetStandard
CleanDir outputBinariesNet
CleanDir "docs/_site"

CleanDirs !! "./**/bin"
CleanDirs !! "./**/obj"
)

Target "AssemblyInfo" (fun _ ->
Expand All @@ -61,17 +76,35 @@ Target "AssemblyInfo" (fun _ ->
)

Target "Build" (fun _ ->
let additionalArgs = if versionSuffix.Length > 0 then [sprintf "/p:VersionSuffix=%s" versionSuffix] else []
DotNetCli.Build
(fun p ->
{ p with
Project = solutionFile
Configuration = configuration }) // "Rebuild"
Configuration = configuration
AdditionalArgs = additionalArgs }) // "Rebuild"
)


//--------------------------------------------------------------------------------
// Tests targets
//--------------------------------------------------------------------------------
type Runtime =
| NetCore
| Net
| NetFramework

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

if Seq.isEmpty assemblyPath then
None
else
Some (assemblyPath |> Seq.head)

module internal ResultHandling =
let (|OK|Failure|) = function
| 0 -> OK
Expand Down Expand Up @@ -99,8 +132,56 @@ Target "RunTests" (fun _ ->
let runSingleProject project =
let arguments =
match (hasTeamCity) with
| true -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --results-directory %s -- -parallel none -teamcity" (outputTests))
| false -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --results-directory %s -- -parallel none" (outputTests))
| true -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s --results-directory %s -- -parallel none -teamcity" testNetFrameworkVersion outputTests)
| false -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s --results-directory %s -- -parallel none" testNetFrameworkVersion outputTests)

let result = ExecProcess(fun info ->
info.FileName <- "dotnet"
info.WorkingDirectory <- (Directory.GetParent project).FullName
info.Arguments <- arguments) (TimeSpan.FromMinutes 30.0)

ResultHandling.failBuildIfXUnitReportedError TestRunnerErrorLevel.Error result

CreateDir outputTests
projects |> Seq.iter (log)
projects |> Seq.iter (runSingleProject)
)

Target "RunTestsNetCore" (fun _ ->
let projects =
match (isWindows) with
| true -> !! "./src/**/*.Tests.csproj"
| _ -> !! "./src/**/*.Tests.csproj" // if you need to filter specs for Linux vs. Windows, do it here

let runSingleProject project =
let arguments =
match (hasTeamCity) with
| true -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s --results-directory %s -- -parallel none -teamcity" testNetCoreVersion outputTests)
| false -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s --results-directory %s -- -parallel none" testNetCoreVersion outputTests)

let result = ExecProcess(fun info ->
info.FileName <- "dotnet"
info.WorkingDirectory <- (Directory.GetParent project).FullName
info.Arguments <- arguments) (TimeSpan.FromMinutes 30.0)

ResultHandling.failBuildIfXUnitReportedError TestRunnerErrorLevel.Error result

CreateDir outputTests
projects |> Seq.iter (log)
projects |> Seq.iter (runSingleProject)
)

Target "RunTestsNet" (fun _ ->
let projects =
match (isWindows) with
| true -> !! "./src/**/*.Tests.csproj"
| _ -> !! "./src/**/*.Tests.csproj" // if you need to filter specs for Linux vs. Windows, do it here

let runSingleProject project =
let arguments =
match (hasTeamCity) with
| true -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s --results-directory %s -- -parallel none -teamcity" testNetVersion outputTests)
| false -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s --results-directory %s -- -parallel none" testNetVersion outputTests)

let result = ExecProcess(fun info ->
info.FileName <- "dotnet"
Expand All @@ -109,6 +190,7 @@ Target "RunTests" (fun _ ->

ResultHandling.failBuildIfXUnitReportedError TestRunnerErrorLevel.Error result

CreateDir outputTests
projects |> Seq.iter (log)
projects |> Seq.iter (runSingleProject)
)
Expand Down Expand Up @@ -275,15 +357,17 @@ Target "Help" <| fun _ ->
"./build.ps1 [target]"
""
" Targets for building:"
" * Build Builds"
" * Nuget Create and optionally publish nugets packages"
" * SignPackages Signs all NuGet packages, provided that the following arguments are passed into the script: SignClientSecret={secret} and SignClientUser={username}"
" * RunTests Runs tests"
" * All Builds, run tests, creates and optionally publish nuget packages"
" * DocFx Creates a DocFx-based website for this solution"
" * Build Builds"
" * Nuget Create and optionally publish nugets packages"
" * SignPackages Signs all NuGet packages, provided that the following arguments are passed into the script: SignClientSecret={secret} and SignClientUser={username}"
" * RunTests Runs Net Framework tests"
" * RunTestsNetCore Runs Net Core tests"
" * RunTestsNet Runs Net 5 tests"
" * All Builds, run tests, creates and optionally publish nuget packages"
" * DocFx Creates a DocFx-based website for this solution"
""
" Other Targets"
" * Help Display this help"
" * Help Display this help"
""]

//--------------------------------------------------------------------------------
Expand All @@ -293,15 +377,20 @@ Target "Help" <| fun _ ->
Target "BuildRelease" DoNothing
Target "All" DoNothing
Target "Nuget" DoNothing
Target "RunTestsFull" DoNothing
Target "RunTestsNetCoreFull" DoNothing

// build dependencies
"Clean" ==> "AssemblyInfo" ==> "Build" ==> "BuildRelease"

// tests dependencies
"Build" ==> "RunTests"
"Build" ==> "RunTestsNetCore"
"Build" ==> "RunTestsNet"
"Build" ==> "NBench"

// nuget dependencies
"Clean" ==> "Build" ==> "CreateNuget"
"Clean" ==> "BuildRelease" ==> "CreateNuget"
"CreateNuget" ==> "SignPackages" ==> "PublishNuget" ==> "Nuget"

// docs
Expand All @@ -310,6 +399,8 @@ Target "Nuget" DoNothing
// all
"BuildRelease" ==> "All"
"RunTests" ==> "All"
"RunTestsNetCore" ==> "All"
"RunTestsNet" ==> "All"
"NBench" ==> "All"
"Nuget" ==> "All"

Expand Down
54 changes: 4 additions & 50 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ Param(
[string[]]$ScriptArgs
)

$FakeVersion = "4.61.2"
$DotNetChannel = "LTS";
$DotNetVersion = "2.1.500";
$DotNetInstallerUri = "https://raw.githubusercontent.com/dotnet/cli/v$DotNetVersion/scripts/obtain/dotnet-install.ps1";
$NugetVersion = "4.1.0";
$FakeVersion = "4.63.0"
$NugetVersion = "5.8.0";
$NugetUrl = "https://dist.nuget.org/win-x86-commandline/v$NugetVersion/nuget.exe"
$ProtobufVersion = "3.4.0"
$DocfxVersion = "2.40.5"
$ProtobufVersion = "3.13.0"
$DocfxVersion = "2.48.1"

# Make sure tools folder exists
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
Expand All @@ -46,49 +43,6 @@ if (!(Test-Path $ToolPath)) {
New-Item -Path $ToolPath -Type directory | out-null
}

###########################################################################
# INSTALL .NET CORE CLI
###########################################################################

Function Remove-PathVariable([string]$VariableToRemove)
{
$path = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($path -ne $null)
{
$newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove }
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "User")
}

$path = [Environment]::GetEnvironmentVariable("PATH", "Process")
if ($path -ne $null)
{
$newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove }
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "Process")
}
}

# Get .NET Core CLI path if installed.
$FoundDotNetCliVersion = $null;
if (Get-Command dotnet -ErrorAction SilentlyContinue) {
$FoundDotNetCliVersion = dotnet --version;
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
$env:DOTNET_CLI_TELEMETRY_OPTOUT=1
}

if($FoundDotNetCliVersion -ne $DotNetVersion) {
$InstallPath = Join-Path $PSScriptRoot ".dotnet"
if (!(Test-Path $InstallPath)) {
mkdir -Force $InstallPath | Out-Null;
}
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, "$InstallPath\dotnet-install.ps1");
& $InstallPath\dotnet-install.ps1 -Channel $DotNetChannel -Version $DotNetVersion -InstallDir $InstallPath -Architecture x64;

Remove-PathVariable "$InstallPath"
$env:PATH = "$InstallPath;$env:PATH"
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
$env:DOTNET_CLI_TELEMETRY_OPTOUT=1
}

###########################################################################
# INSTALL NUGET
###########################################################################
Expand Down
Loading