From 02fe311ecbf75cc77a2261c486812c10b2e09590 Mon Sep 17 00:00:00 2001 From: Ruben Bartelink Date: Sat, 7 Dec 2019 12:19:54 +0000 Subject: [PATCH] Formatting consistency --- equinox-fc/Domain.Tests/AllocationTests.fs | 2 +- equinox-fc/Domain.Tests/Infrastructure.fs | 2 +- equinox-fc/Domain.Tests/LocationEpochTests.fs | 12 ++++++------ equinox-fc/Domain.Tests/LocationSeriesTests.fs | 2 +- equinox-fc/Domain.Tests/LocationTests.fs | 14 +++++++------- equinox-fc/Domain/Allocation.fs | 6 +++--- equinox-fc/Domain/ListAllocation.fs | 8 ++++---- equinox-fc/Domain/Location.fs | 8 ++++---- equinox-fc/Domain/LocationEpoch.fs | 8 ++++---- equinox-fc/Domain/LocationSeries.fs | 8 ++++---- equinox-fc/Domain/TicketList.fs | 4 ++-- 11 files changed, 37 insertions(+), 37 deletions(-) diff --git a/equinox-fc/Domain.Tests/AllocationTests.fs b/equinox-fc/Domain.Tests/AllocationTests.fs index f6c92ff1c..a8f7fd3d4 100644 --- a/equinox-fc/Domain.Tests/AllocationTests.fs +++ b/equinox-fc/Domain.Tests/AllocationTests.fs @@ -5,6 +5,6 @@ open FsCheck.Xunit open Swensen.Unquote let [] ``codec can roundtrip`` event = - let ee = Events.codec.Encode(None,event) + let ee = Events.codec.Encode(None, event) let ie = FsCodec.Core.TimelineEvent.Create(0L, ee.EventType, ee.Data) test <@ Some event = Events.codec.TryDecode ie @> \ No newline at end of file diff --git a/equinox-fc/Domain.Tests/Infrastructure.fs b/equinox-fc/Domain.Tests/Infrastructure.fs index 66dd13d73..8cee0f304 100644 --- a/equinox-fc/Domain.Tests/Infrastructure.fs +++ b/equinox-fc/Domain.Tests/Infrastructure.fs @@ -26,7 +26,7 @@ module Cosmos = let context = Context(connection, d, c) let cache = Equinox.Cache (appName, 10) context, cache - | s,d,c -> + | s, d, c -> failwithf "Connection, Database and Container EQUINOX_COSMOS_* Environment variables are required (%b,%b,%b)" (Option.isSome s) (Option.isSome d) (Option.isSome c) diff --git a/equinox-fc/Domain.Tests/LocationEpochTests.fs b/equinox-fc/Domain.Tests/LocationEpochTests.fs index 6901aa746..238083ab9 100644 --- a/equinox-fc/Domain.Tests/LocationEpochTests.fs +++ b/equinox-fc/Domain.Tests/LocationEpochTests.fs @@ -6,8 +6,8 @@ open Swensen.Unquote let interpret delta _balance = match delta with - | 0 -> (),[] - | delta -> (),[Events.Delta { value = delta }] + | 0 -> (), [] + | delta -> (), [Events.Delta { value = delta }] let validateAndInterpret expectedBalance delta balance = test <@ expectedBalance = balance @> @@ -15,14 +15,14 @@ let validateAndInterpret expectedBalance delta balance = let verifyDeltaEvent delta events = let dEvents = events |> List.filter (function Events.Delta _ -> true | _ -> false) - test <@ interpret delta (Unchecked.defaultof<_>) = ((),dEvents) @> + test <@ interpret delta (Unchecked.defaultof<_>) = ((), dEvents) @> let [] properties carriedForward delta1 closeImmediately delta2 close = (* Starting with an empty stream, we'll need to supply the balance carried forward, optionally we apply a delta and potentially close *) let initialShouldClose _state = closeImmediately - let res,events = sync (Some carriedForward) (validateAndInterpret carriedForward delta1) initialShouldClose Fold.initial + let res, events = sync (Some carriedForward) (validateAndInterpret carriedForward delta1) initialShouldClose Fold.initial let cfEvents events = events |> List.filter (function Events.CarriedForward _ -> true | _ -> false) let closeEvents events = events |> List.filter (function Events.Closed -> true | _ -> false) let state1 = Fold.fold Fold.initial events @@ -38,7 +38,7 @@ let [] properties carriedForward delta1 closeImmediately delta2 close (* After initializing, validate we don't need to supply a carriedForward, and don't produce a CarriedForward event *) let shouldClose _state = close - let { isOpen = isOpen; result = worked; balance = bal },events = sync None (validateAndInterpret expectedBalance delta2) shouldClose state1 + let { isOpen = isOpen; result = worked; balance = bal }, events = sync None (validateAndInterpret expectedBalance delta2) shouldClose state1 let expectedBalance = if expectImmediateClose then expectedBalance else expectedBalance + delta2 test <@ [] = cfEvents events && (expectImmediateClose || not close || 1 = Seq.length (closeEvents events)) @> @@ -49,6 +49,6 @@ let [] properties carriedForward delta1 closeImmediately delta2 close verifyDeltaEvent delta2 events let [] ``codec can roundtrip`` event = - let ee = Events.codec.Encode(None,event) + let ee = Events.codec.Encode(None, event) let ie = FsCodec.Core.TimelineEvent.Create(0L, ee.EventType, ee.Data) test <@ Some event = Events.codec.TryDecode ie @> \ No newline at end of file diff --git a/equinox-fc/Domain.Tests/LocationSeriesTests.fs b/equinox-fc/Domain.Tests/LocationSeriesTests.fs index b0ec09dd7..ab0bee57e 100644 --- a/equinox-fc/Domain.Tests/LocationSeriesTests.fs +++ b/equinox-fc/Domain.Tests/LocationSeriesTests.fs @@ -39,6 +39,6 @@ let [] properties c1 c2 = test <@ List.isEmpty l @> let [] ``codec can roundtrip`` event = - let ee = Events.codec.Encode(None,event) + let ee = Events.codec.Encode(None, event) let ie = FsCodec.Core.TimelineEvent.Create(0L, ee.EventType, ee.Data) test <@ Some event = Events.codec.TryDecode ie @> \ No newline at end of file diff --git a/equinox-fc/Domain.Tests/LocationTests.fs b/equinox-fc/Domain.Tests/LocationTests.fs index 169834991..c9311e7f5 100644 --- a/equinox-fc/Domain.Tests/LocationTests.fs +++ b/equinox-fc/Domain.Tests/LocationTests.fs @@ -21,7 +21,7 @@ module Location = let resolve store = Resolver(store, Epoch.Events.codec, Epoch.Fold.fold, Epoch.Fold.initial).Resolve - let createService (zeroBalance, shouldClose) store = + let create (zeroBalance, shouldClose) store = let maxAttempts = Int32.MaxValue let series = Series.create (Series.resolve store) maxAttempts let epochs = Epoch.create (Epoch.resolve store) maxAttempts @@ -39,12 +39,12 @@ let run (service : LocationService) (IdsAtLeastOne locations, deltas : _[]) = As let value = max -bal delta if value = 0 then 0, [] else value, [Location.Epoch.Events.Delta { value = value }] - let! appliedDeltas = seq { for loc,x in updates -> async { let! _,eff = service.Execute(loc, adjust x) in return loc,eff } } |> Async.Parallel - let expectedBalances = Seq.append (seq { for l in locations -> l, 0}) appliedDeltas |> Seq.groupBy fst |> Seq.map (fun (l,xs) -> l, xs |> Seq.sumBy snd) |> Set.ofSeq + let! appliedDeltas = seq { for loc, x in updates -> async { let! _, eff = service.Execute(loc, adjust x) in return loc, eff } } |> Async.Parallel + let expectedBalances = Seq.append (seq { for l in locations -> l, 0}) appliedDeltas |> Seq.groupBy fst |> Seq.map (fun (l, xs) -> l, xs |> Seq.sumBy snd) |> Set.ofSeq (* Verify loading yields identical state *) - let! balances = seq { for loc in locations -> async { let! bal,() = service.Execute(loc,(fun _ -> (),[])) in return loc,bal } } |> Async.Parallel + let! balances = seq { for loc in locations -> async { let! bal, () = service.Execute(loc, (fun _ -> (), [])) in return loc, bal } } |> Async.Parallel test <@ expectedBalances = Set.ofSeq balances @> } let [] ``MemoryStore properties`` maxEvents args = @@ -52,12 +52,12 @@ let [] ``MemoryStore properties`` maxEvents args = let zeroBalance = 0 let maxEvents = max 1 maxEvents let shouldClose (state : Epoch.Fold.OpenState) = state.count > maxEvents - let service = Location.MemoryStore.createService (zeroBalance, shouldClose) store + let service = Location.MemoryStore.create (zeroBalance, shouldClose) store run service args type Cosmos(testOutput) = - let context,cache = Cosmos.connect () + let context, cache = Cosmos.connect () let log = testOutput |> TestOutputAdapter |> createLogger do Serilog.Log.Logger <- log @@ -66,5 +66,5 @@ type Cosmos(testOutput) = let zeroBalance = 0 let maxEvents = max 1 maxEvents let shouldClose (state : Epoch.Fold.OpenState) = state.count > maxEvents - let service = Location.Cosmos.createService (zeroBalance, shouldClose) (context,cache,Int32.MaxValue) + let service = Location.Cosmos.create (zeroBalance, shouldClose) (context, cache, Int32.MaxValue) run service args \ No newline at end of file diff --git a/equinox-fc/Domain/Allocation.fs b/equinox-fc/Domain/Allocation.fs index 9ce07e7d5..502a06d91 100644 --- a/equinox-fc/Domain/Allocation.fs +++ b/equinox-fc/Domain/Allocation.fs @@ -32,7 +32,7 @@ module Events = interface TypeShape.UnionContract.IUnionContract let codec = FsCodec.NewtonsoftJson.Codec.Create() let [] categoryId = "Allocation" - let (|AggregateId|) id = Equinox.AggregateId(categoryId, AllocationId.toString id) + let (|For|) id = Equinox.AggregateId(categoryId, AllocationId.toString id) module Fold = @@ -216,9 +216,9 @@ let sync (updates : Update seq, command : Command) (state : Fold.State) : (bool* (* Yield outstanding processing requirements (if any), together with events accumulated based on the `updates` *) (accepted, ProcessState.FromFoldState state), acc.Accumulated -type Service internal (log, resolve, ?maxAttempts) = +type Service internal (log, resolve, maxAttempts) = - let resolve (Events.AggregateId id) = Equinox.Stream(log, resolve id, maxAttempts = defaultArg maxAttempts 3) + let resolve (Events.For id) = Equinox.Stream(log, resolve id, maxAttempts) member __.Sync(allocationId, updates, command) : Async = let stream = resolve allocationId diff --git a/equinox-fc/Domain/ListAllocation.fs b/equinox-fc/Domain/ListAllocation.fs index 51662d008..0485d9077 100644 --- a/equinox-fc/Domain/ListAllocation.fs +++ b/equinox-fc/Domain/ListAllocation.fs @@ -8,15 +8,15 @@ type Service(maxListLen, allocators : Allocator.Service, allocations : Allocatio let cutoff = let now = DateTimeOffset.UtcNow in now.Add transactionTimeout let! state = allocators.Commence(allocatorId, allocationId, cutoff) // TODO cancel timed out conflicting work - let! (_,state) = allocations.Sync(allocationId, Seq.empty, Allocation.Commence tickets) + let! _, state = allocations.Sync(allocationId, Seq.empty, Allocation.Commence tickets) return state } member __.Read(allocationId) : Async<_> = async { - let! (_,state) = allocations.Sync(allocationId, Seq.empty, Allocation.Command.Apply ([],[])) + let! _, state = allocations.Sync(allocationId, Seq.empty, Allocation.Command.Apply ([], [])) // TODO incorporate allocator state return state } - member __.Cancel(allocatorId,allocationId) : Async<_> = async { - let! (_,state) = allocations.Sync(allocationId, Seq.empty, Allocation.Command.Cancel) + member __.Cancel(allocatorId, allocationId) : Async<_> = async { + let! _, state = allocations.Sync(allocationId, Seq.empty, Allocation.Command.Cancel) // TODO propagate to allocator with reason return state } diff --git a/equinox-fc/Domain/Location.fs b/equinox-fc/Domain/Location.fs index 7e4468f58..5cdba4c5e 100644 --- a/equinox-fc/Domain/Location.fs +++ b/equinox-fc/Domain/Location.fs @@ -10,7 +10,7 @@ type LocationService internal (zeroBalance, shouldClose, series : Series.Service let rec execute locationId originEpochId = let rec aux epochId balanceToCarryForward wip = async { - let decide state = match wip with Complete r -> r,[] | Pending decide -> decide state + let decide state = match wip with Complete r -> r, [] | Pending decide -> decide state match! epochs.Sync(locationId, epochId, balanceToCarryForward, decide, shouldClose) with | { balance = bal; result = Some res; isOpen = true } -> if originEpochId <> epochId then @@ -40,7 +40,7 @@ module Helpers = module Cosmos = - let createService (zeroBalance, shouldClose) (context, cache, maxAttempts) = - let series = Series.Cosmos.createService (context, cache, maxAttempts) - let epochs = Epoch.Cosmos.createService (context, cache, maxAttempts) + let create (zeroBalance, shouldClose) (context, cache, maxAttempts) = + let series = Series.Cosmos.create (context, cache, maxAttempts) + let epochs = Epoch.Cosmos.create (context, cache, maxAttempts) create (zeroBalance, shouldClose) (series, epochs) \ No newline at end of file diff --git a/equinox-fc/Domain/LocationEpoch.fs b/equinox-fc/Domain/LocationEpoch.fs index e2f41d27f..03b69b988 100644 --- a/equinox-fc/Domain/LocationEpoch.fs +++ b/equinox-fc/Domain/LocationEpoch.fs @@ -57,7 +57,7 @@ let sync (balanceCarriedForward : Fold.Balance option) (decide : (Fold.Balance - acc.Ingest state <| match state with | Fold.Initial -> failwith "We've just guaranteed not Initial" - | Fold.Open { value = bal } -> let r,es = decide bal in Some r,es + | Fold.Open { value = bal } -> let r, es = decide bal in Some r, es | Fold.Closed _ -> None, [] // Finally (iff we're `Open`, have run a `decide` and `shouldClose`), we generate a Closed event let (balance, isOpen), _ = @@ -82,8 +82,8 @@ let create resolve maxAttempts = Service(Serilog.Log.ForContext(), reso module Cosmos = open Equinox.Cosmos - let resolve (context,cache) = + let resolve (context, cache) = let cacheStrategy = CachingStrategy.SlidingWindow (cache, System.TimeSpan.FromMinutes 20.) Resolver(context, Events.codec, Fold.fold, Fold.initial, cacheStrategy, AccessStrategy.Unoptimized).Resolve - let createService (context,cache,maxAttempts) = - create (resolve (context,cache)) maxAttempts \ No newline at end of file + let create (context, cache, maxAttempts) = + create (resolve (context, cache)) maxAttempts \ No newline at end of file diff --git a/equinox-fc/Domain/LocationSeries.fs b/equinox-fc/Domain/LocationSeries.fs index 7c7d1e6c8..e33916993 100644 --- a/equinox-fc/Domain/LocationSeries.fs +++ b/equinox-fc/Domain/LocationSeries.fs @@ -43,9 +43,9 @@ let create resolve maxAttempts = Service(Serilog.Log.ForContext(), reso module Cosmos = open Equinox.Cosmos - let resolve (context,cache) = + let resolve (context, cache) = let cacheStrategy = CachingStrategy.SlidingWindow (cache, System.TimeSpan.FromMinutes 20.) let opt = Equinox.ResolveOption.AllowStale - fun id -> Resolver(context, Events.codec, Fold.fold, Fold.initial, cacheStrategy, AccessStrategy.LatestKnownEvent).Resolve(id,opt) - let createService (context, cache, maxAttempts) = - create (resolve (context,cache)) maxAttempts \ No newline at end of file + fun id -> Resolver(context, Events.codec, Fold.fold, Fold.initial, cacheStrategy, AccessStrategy.LatestKnownEvent).Resolve(id, opt) + let create (context, cache, maxAttempts) = + create (resolve (context, cache)) maxAttempts \ No newline at end of file diff --git a/equinox-fc/Domain/TicketList.fs b/equinox-fc/Domain/TicketList.fs index a21e8265e..fa5205e6a 100644 --- a/equinox-fc/Domain/TicketList.fs +++ b/equinox-fc/Domain/TicketList.fs @@ -11,7 +11,7 @@ module Events = interface TypeShape.UnionContract.IUnionContract let codec = FsCodec.NewtonsoftJson.Codec.Create() let [] categoryId = "TicketList" - let (|AggregateId|) id = Equinox.AggregateId(categoryId, TicketListId.toString id) + let (|For|) id = Equinox.AggregateId(categoryId, TicketListId.toString id) module Fold = @@ -31,7 +31,7 @@ let interpret (allocatorId : AllocatorId, allocated : TicketId list) (state : Fo type Service internal (log, resolve, maxAttempts) = - let resolve (Events.AggregateId id) = Equinox.Stream(log, resolve id, maxAttempts) + let resolve (Events.For id) = Equinox.Stream(log, resolve id, maxAttempts) member __.Sync(pickListId, allocatorId, assignedTickets) : Async = let stream = resolve pickListId