From 9ba0e9f1dc392c0ad057f69dedb7b699105d25e9 Mon Sep 17 00:00:00 2001 From: Ruben Bartelink Date: Wed, 10 Oct 2018 03:25:55 +0100 Subject: [PATCH] Tidy projects in an enricosada style --- CallPolly.sln | 2 ++ Directory.Build.props | 14 +++++++++++ build.cmd | 5 +++- global.json | 5 ++++ src/CallPolly/CallPolly.fsproj | 24 +++++-------------- src/CallPolly/Config.fs | 10 ++++---- src/CallPolly/Parser.fs | 11 +++++---- src/CallPolly/Rules.fs | 4 ++++ .../CallPolly.Acceptance.fsproj | 11 ++++----- tests/CallPolly.Acceptance/Orchestration.fs | 4 ++++ tests/CallPolly.Tests/CallPolly.Tests.fsproj | 11 ++++----- tests/CallPolly.Tests/RulesTests.fs | 6 +++++ 12 files changed, 64 insertions(+), 43 deletions(-) create mode 100644 Directory.Build.props create mode 100644 global.json diff --git a/CallPolly.sln b/CallPolly.sln index 2169bd7..12079d4 100644 --- a/CallPolly.sln +++ b/CallPolly.sln @@ -12,6 +12,8 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".project", ".project", "{6047ADD6-C48C-4583-A5C6-58FDF7A0DC10}" ProjectSection(SolutionItems) = preProject build.cmd = build.cmd + Directory.Build.props = Directory.Build.props + global.json = global.json LICENSE = LICENSE README.md = README.md SECURITY.md = SECURITY.md diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..a397163 --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,14 @@ + + + 0.0.2 + @jet @bartelink and contributors + Jet.com + Apply systemwide resilience strategies consistently across subsystems, standing on Polly's shoulders + https://github.com/jet/CallPolly + https://github.com/jet/CallPolly + git + polly bulkhead circuitbreaker timeout fsharp + https://github.com/jet/CallPolly/blob/master/LICENSE + Copyright © 2018 + + \ No newline at end of file diff --git a/build.cmd b/build.cmd index 89df33d..806e875 100644 --- a/build.cmd +++ b/build.cmd @@ -2,4 +2,7 @@ dotnet pack src/CallPolly --configuration Release -o "%CD%\bin" --version-suffix if ERRORLEVEL 1 (echo Error building CallPolly; exit /b 1) dotnet test tests/CallPolly.Tests --configuration Release -if ERRORLEVEL 1 (echo Error testing CallPolly; exit /b 1) \ No newline at end of file +if ERRORLEVEL 1 (echo Error testing CallPolly; exit /b 1) + +dotnet test tests/CallPolly.Acceptance --configuration Release +if ERRORLEVEL 1 (echo Error acceptance testing CallPolly; exit /b 1) \ No newline at end of file diff --git a/global.json b/global.json new file mode 100644 index 0000000..455cd36 --- /dev/null +++ b/global.json @@ -0,0 +1,5 @@ +{ + "sdk": { + "version": "2.1.402" + } +} \ No newline at end of file diff --git a/src/CallPolly/CallPolly.fsproj b/src/CallPolly/CallPolly.fsproj index ccc7673..b886d19 100644 --- a/src/CallPolly/CallPolly.fsproj +++ b/src/CallPolly/CallPolly.fsproj @@ -2,24 +2,10 @@ netstandard2.0;net461 - 0.0.1 - @jet @bartelink and contributors - Jet.com - Apply systemwide resilience strategies consistently across subsystems, standing on Polly's shoulders - https://github.com/jet/CallPolly - https://github.com/jet/CallPolly - git - polly circuitbreaker fsharp - https://github.com/jet/CallPolly/blob/master/LICENSE - Copyright © 2018 - - - - 5 - - - 5 + false + true + true @@ -31,7 +17,9 @@ - + + + diff --git a/src/CallPolly/Config.fs b/src/CallPolly/Config.fs index 704453f..5a04c3c 100644 --- a/src/CallPolly/Config.fs +++ b/src/CallPolly/Config.fs @@ -38,17 +38,17 @@ module Policy = minThroughput = x.minRequests errorRateThreshold = x.failPct/100. retryAfter = TimeSpan.FromSeconds x.breakS - dryRun = x.dryRun |> Option.defaultValue false } + dryRun = defaultArg x.dryRun false } | Input.Value.Limit x -> Rule.Limit { dop = x.maxParallel queue = x.maxQueue - dryRun = x.dryRun |> Option.defaultValue false } + dryRun = defaultArg x.dryRun false } | Input.Value.Cutoff ({ timeoutMs=TimeSpanMs timeout } as x) -> Rule.Cutoff { timeout = timeout sla = x.slaMs |> Option.map (|TimeSpanMs|) - dryRun = x.dryRun |> Option.defaultValue false } + dryRun = defaultArg x.dryRun false } let private fold : Rule seq -> Rules.PolicyConfig = let folder (s : Rules.PolicyConfig) = function @@ -103,8 +103,8 @@ module Http = let private interpret (x: Input.Value): Rule seq = seq { match x with | Input.Value.Uri { ``base``=b; path=p } -> - match Option.toObj b with null -> () | b -> yield Rule.BaseUri(Uri b) - match Option.toObj p with null -> () | p -> yield Rule.RelUri(Uri(p, UriKind.Relative)) + match b with Some null | None -> () | Some b -> yield Rule.BaseUri(Uri b) + match p with Some null | None -> () | Some p -> yield Rule.RelUri(Uri(p, UriKind.Relative)) | Input.Value.Sla { slaMs=TimeSpanMs sla; timeoutMs=TimeSpanMs timeout } -> yield Rule.Sla(sla,timeout) | Input.Value.Log { req=req; res=res } -> yield Rule.Log(toRuleLog req,toRuleLog res) } diff --git a/src/CallPolly/Parser.fs b/src/CallPolly/Parser.fs index 34e03f1..451dc4f 100644 --- a/src/CallPolly/Parser.fs +++ b/src/CallPolly/Parser.fs @@ -6,12 +6,13 @@ open Newtonsoft.Json.Converters.FSharp open System open System.Collections.Generic -/// Wrappers for Newtonsoft.Json +// shims for F# < 4, can be removed if we stop supporting that +module private Option = + let ofObj = function null -> None | x -> Some x + +/// Wrappers for Newtonsoft.Json - OptionConverter is required type Newtonsoft() = - static let settings = - let tmp = Settings.CreateDefault() - tmp.Converters.Add(OptionConverter()) - tmp + static let settings = Settings.CreateCorrect(OptionConverter()) /// Deserializes value of given type from json string. /// Json string to deserialize. diff --git a/src/CallPolly/Rules.fs b/src/CallPolly/Rules.fs index 51f37cf..96e894c 100644 --- a/src/CallPolly/Rules.fs +++ b/src/CallPolly/Rules.fs @@ -8,6 +8,10 @@ open System.Diagnostics open System.Threading open System.Threading.Tasks +// shims for F# < 4, can be removed if we stop supporting that +module private Option = + let toNullable = function Some x -> Nullable x | None -> Nullable () + type BreakerConfig = { window: TimeSpan; minThroughput: int; errorRateThreshold: float; retryAfter: TimeSpan; dryRun: bool } type BulkheadConfig = { dop: int; queue: int; dryRun: bool } type CutoffConfig = { timeout: TimeSpan; sla: TimeSpan option; dryRun: bool } diff --git a/tests/CallPolly.Acceptance/CallPolly.Acceptance.fsproj b/tests/CallPolly.Acceptance/CallPolly.Acceptance.fsproj index 92db1fd..41ff518 100644 --- a/tests/CallPolly.Acceptance/CallPolly.Acceptance.fsproj +++ b/tests/CallPolly.Acceptance/CallPolly.Acceptance.fsproj @@ -3,14 +3,9 @@ netcoreapp2.1;net461 false - - - - 5 - - - 5 + true + true @@ -19,6 +14,8 @@ + + diff --git a/tests/CallPolly.Acceptance/Orchestration.fs b/tests/CallPolly.Acceptance/Orchestration.fs index 685174b..88fd6d1 100644 --- a/tests/CallPolly.Acceptance/Orchestration.fs +++ b/tests/CallPolly.Acceptance/Orchestration.fs @@ -5,6 +5,10 @@ open Swensen.Unquote open System open Xunit +// shims for F# < 4, can be removed if we stop supporting that +module private Seq = + let replicate n x = seq { for i in 1..n do yield x } + [] module Helpers = let ms x = TimeSpan.FromMilliseconds (float x) diff --git a/tests/CallPolly.Tests/CallPolly.Tests.fsproj b/tests/CallPolly.Tests/CallPolly.Tests.fsproj index 36a040e..ad7c77a 100644 --- a/tests/CallPolly.Tests/CallPolly.Tests.fsproj +++ b/tests/CallPolly.Tests/CallPolly.Tests.fsproj @@ -3,14 +3,9 @@ netcoreapp2.1;net461 false - - - - 5 - - - 5 + true + true @@ -20,6 +15,8 @@ + + diff --git a/tests/CallPolly.Tests/RulesTests.fs b/tests/CallPolly.Tests/RulesTests.fs index 4f32a05..05b49a1 100644 --- a/tests/CallPolly.Tests/RulesTests.fs +++ b/tests/CallPolly.Tests/RulesTests.fs @@ -6,6 +6,12 @@ open System open Swensen.Unquote open Xunit +// shims for F# < 4, can be removed if we stop supporting that +module private List = + let contains x = List.exists ((=) x) +module private Seq = + let replicate n x = seq { for i in 1..n do yield x } + [] module Helpers = let ms x = TimeSpan.FromMilliseconds (float x)