Skip to content

Commit

Permalink
Clarified ctor and Creation/Verification APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Mar 28, 2022
1 parent e073081 commit dc283ee
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 91 deletions.
8 changes: 7 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
* Moved Sync-over-Async versions of `TableContext` operations into `namespace FSharp.AWS.DynamoDB.Scripting`
* Added `?collector` parameter to each operation on `TableContext` to enable separated collection for concurrent requests
* Ensured metrics are reported even for failed requests
* Added `TableContext.CreateUnverified` (`TableContext.CreateAsync` without the optional store round-trips)
* Clarified Creation/Verification APIs:
* Obsoleted `TableContext.Create` (replace with `TableContext.Scripting.Initialize` and/or `TableContext.InitializeTableAsync`)
* Added `TableContext` constructor (replaces `TableContext.Create(verifyTable = false)`)
* Added `TableContext.Scripting.Initialize` (replaces `TableContext.Create()`)
* Added `TableContext.VerifyTableAsync` overload that only performs verification but never creates a Table
* Added `TableContext.InitializeTableAsync` (replaces `TableContext.VerifyTableAsync(createIfNotExists = true)`)
* Removed `TableContext.CreateAsync` (replace with `TableContext.VerifyTableAsync` or `TableContext.InitializeTableAsync`)

### 0.9.3-beta
* Added `RequestMetrics` record type
Expand Down
192 changes: 114 additions & 78 deletions src/FSharp.AWS.DynamoDB/TableContext.fs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ type ``Conditional Expression Tests`` (fixture : TableFixture) =
Serialized = rand(), guid()
}

let table = TableContext.Create<CondExprRecord>(fixture.Client, fixture.TableName, createIfNotExists = true)
let table = fixture.CreateContextAndTableIfNotExists<CondExprRecord>()

member this.``Item exists precondition`` () =
let item = mkItem()
Expand Down
2 changes: 1 addition & 1 deletion tests/FSharp.AWS.DynamoDB.Tests/PaginationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type ``Pagination Tests`` (fixture : TableFixture) =
LocalAttribute = int (rand () % 2L)
}

let table = TableContext.Create<PaginationRecord>(fixture.Client, fixture.TableName, createIfNotExists = true)
let table = fixture.CreateContextAndTableIfNotExists<PaginationRecord>()

member __.``Paginated Query on Primary Key`` () =
let hk = guid()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ type ``Projection Expression Tests`` (fixture : TableFixture) =
Serialized = rand(), guid() ; Serialized2 = { NV = guid() ; NE = enum<Enum> (int (rand()) % 3) } ;
}

let table = TableContext.Create<ProjectionExprRecord>(fixture.Client, fixture.TableName, createIfNotExists = true)
let table = fixture.CreateContextAndTableIfNotExists<ProjectionExprRecord>()

member this.``Should fail on invalid projections`` () =
let testProj (p : Expr<R -> 'T>) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type ``Simple Table Operation Tests`` (fixture : TableFixture) =
Unions = [Choice1Of3 (guid()) ; Choice2Of3(rand()) ; Choice3Of3(Guid.NewGuid().ToByteArray())]
}

let table = TableContext.Create<SimpleRecord>(fixture.Client, fixture.TableName, createIfNotExists = true)
let table = fixture.CreateContextAndTableIfNotExists<SimpleRecord>()

member this.``Convert to compatible table`` () =
let table' = table.WithRecordType<CompatibleRecord> ()
Expand Down
2 changes: 1 addition & 1 deletion tests/FSharp.AWS.DynamoDB.Tests/SparseGSITests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type ``Sparse GSI Tests`` (fixture : TableFixture) =
SecondaryHashKey = if rand() % 2L = 0L then Some (guid()) else None ;
}

let table = TableContext.Create<GsiRecord>(fixture.Client, fixture.TableName, createIfNotExists = true)
let table = fixture.CreateContextAndTableIfNotExists<GsiRecord>()

member this.``GSI Put Operation`` () =
let value = mkItem()
Expand Down
2 changes: 1 addition & 1 deletion tests/FSharp.AWS.DynamoDB.Tests/UpdateExpressionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ type ``Update Expression Tests`` (fixture : TableFixture) =
Serialized = rand(), guid() ; Serialized2 = { NV = guid() ; NE = enum<Enum> (int (rand()) % 3) } ;
}

let table = TableContext.Create<UpdateExprRecord>(fixture.Client, fixture.TableName, createIfNotExists = true)
let table = fixture.CreateContextAndTableIfNotExists<UpdateExprRecord>()

member this.``Attempt to update HashKey`` () =
let item = mkItem()
Expand Down
14 changes: 8 additions & 6 deletions tests/FSharp.AWS.DynamoDB.Tests/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ open System.IO
open Expecto
open FsCheck

open Amazon
open Amazon.Util
open Amazon.DynamoDBv2
open Amazon.Runtime

Expand All @@ -17,12 +15,12 @@ open FSharp.AWS.DynamoDB
module Utils =

let getRandomTableName() =
sprintf "fsdynamodb-%s" <| System.Guid.NewGuid().ToString("N")
sprintf "fsdynamodb-%s" <| Guid.NewGuid().ToString("N")

let guid() = Guid.NewGuid().ToString("N")

let shouldFailwith<'T, 'Exn when 'Exn :> exn>(f : unit -> 'T) =
ignore <| Expect.throws (f >> ignore) typeof<'Exn>.Name
Expect.throws (f >> ignore) typeof<'Exn>.Name

let getDynamoDBAccount () =
let credentials = new BasicAWSCredentials("Fake", "Fake")
Expand All @@ -32,7 +30,7 @@ module Utils =


type FsCheckGenerators =
static member MemoryStream =
static member MemoryStream =
Arb.generate<byte[] option>
|> Gen.map (function None -> null | Some bs -> new MemoryStream(bs))
|> Arb.fromGen
Expand All @@ -44,6 +42,10 @@ module Utils =
member __.Client = client
member __.TableName = tableName

member __.CreateContextAndTableIfNotExists<'TRecord>() =
let autoCreate = InitializationMode.CreateIfNotExists (ProvisionedThroughput(10, 10))
Scripting.TableContext.Initialize<'TRecord>(__.Client, __.TableName, mode = autoCreate)

interface IDisposable with
member __.Dispose() =
client.DeleteTableAsync(tableName) |> Async.AwaitTask |> Async.RunSynchronously |> ignore
client.DeleteTableAsync(tableName) |> Async.AwaitTask |> Async.RunSynchronously |> ignore

0 comments on commit dc283ee

Please sign in to comment.