From c0b0d7377b382657e99c4be8a151b7b058cd43cf Mon Sep 17 00:00:00 2001 From: Ruben Bartelink Date: Fri, 8 Apr 2022 08:56:59 +0100 Subject: [PATCH] Review changes --- src/FSharp.AWS.DynamoDB/TableContext.fs | 7 ++----- .../ConditionalExpressionTests.fs | 2 +- tests/FSharp.AWS.DynamoDB.Tests/MetricsCollectorTests.fs | 8 ++++---- tests/FSharp.AWS.DynamoDB.Tests/PaginationTests.fs | 2 +- .../ProjectionExpressionTests.fs | 2 +- .../SimpleTableOperationTests.fs | 2 +- tests/FSharp.AWS.DynamoDB.Tests/SparseGSITests.fs | 2 +- tests/FSharp.AWS.DynamoDB.Tests/UpdateExpressionTests.fs | 2 +- tests/FSharp.AWS.DynamoDB.Tests/Utils.fs | 2 +- 9 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/FSharp.AWS.DynamoDB/TableContext.fs b/src/FSharp.AWS.DynamoDB/TableContext.fs index 975604e..1e1c265 100644 --- a/src/FSharp.AWS.DynamoDB/TableContext.fs +++ b/src/FSharp.AWS.DynamoDB/TableContext.fs @@ -1133,11 +1133,8 @@ module Scripting = /// DynamoDB client instance. /// Table name to target. /// Optional throughput to configure if the Table does not yet exist. - /// Function to receive request metrics. - static member Initialize<'TRecord> - ( client : IAmazonDynamoDB, tableName : string, ?throughput, - ?metricsCollector : RequestMetrics -> unit) : TableContext<'TRecord> = - let context = TableContext<'TRecord>(client, tableName, ?metricsCollector = metricsCollector) + static member Initialize<'TRecord>(client : IAmazonDynamoDB, tableName : string, ?throughput) : TableContext<'TRecord> = + let context = TableContext<'TRecord>(client, tableName) match throughput with | None -> context.VerifyTableAsync() |> Async.RunSynchronously | Some t -> context.VerifyOrCreateTableAsync(t) |> Async.RunSynchronously diff --git a/tests/FSharp.AWS.DynamoDB.Tests/ConditionalExpressionTests.fs b/tests/FSharp.AWS.DynamoDB.Tests/ConditionalExpressionTests.fs index 621a0f3..13ae79a 100644 --- a/tests/FSharp.AWS.DynamoDB.Tests/ConditionalExpressionTests.fs +++ b/tests/FSharp.AWS.DynamoDB.Tests/ConditionalExpressionTests.fs @@ -86,7 +86,7 @@ type ``Conditional Expression Tests`` (fixture : TableFixture) = Serialized = rand(), guid() } - let table = fixture.CreateContextAndTableIfNotExists() + let table = fixture.CreateEmpty() let [] ``Item exists precondition`` () = let item = mkItem() diff --git a/tests/FSharp.AWS.DynamoDB.Tests/MetricsCollectorTests.fs b/tests/FSharp.AWS.DynamoDB.Tests/MetricsCollectorTests.fs index 100aba7..5bf6ef7 100644 --- a/tests/FSharp.AWS.DynamoDB.Tests/MetricsCollectorTests.fs +++ b/tests/FSharp.AWS.DynamoDB.Tests/MetricsCollectorTests.fs @@ -52,7 +52,7 @@ let (|TotalCu|) : ConsumedCapacity list -> float = Seq.sumBy (fun c -> c.Capacit /// Tests without common setup type Tests(fixture : TableFixture) = - let rawTable = fixture.CreateContextAndTableIfNotExists() + let rawTable = fixture.CreateEmpty() let (|ExpectedTableName|_|) name = if name = fixture.TableName then Some () else None @@ -84,7 +84,7 @@ type Tests(fixture : TableFixture) = /// Tests that look up a specific item. Each test run gets a fresh individual item type ItemTests(fixture : TableFixture) = - let rawTable = fixture.CreateContextAndTableIfNotExists() + let rawTable = fixture.CreateEmpty() let (|ExpectedTableName|_|) name = if name = fixture.TableName then Some () else None let item = mkItem (guid()) (guid()) 0 @@ -131,7 +131,7 @@ type ItemTests(fixture : TableFixture) = /// Heavy tests reliant on establishing (and mutating) multiple items. Separate Test Class so Xunit will run them in parallel with others type BulkMutationTests(fixture : TableFixture) = - let rawTable = fixture.CreateContextAndTableIfNotExists() + let rawTable = fixture.CreateEmpty() let (|ExpectedTableName|_|) name = if name = fixture.TableName then Some () else None // NOTE we mutate the items so they need to be established each time @@ -169,7 +169,7 @@ type ManyReadOnlyItemsFixture() = inherit TableFixture() // TOCONSIDER shift this into IAsyncLifetime.InitializeAsync - let table = base.CreateContextAndTableIfNotExists() + let table = base.CreateEmpty() let hk = guid () do let gsk = guid () diff --git a/tests/FSharp.AWS.DynamoDB.Tests/PaginationTests.fs b/tests/FSharp.AWS.DynamoDB.Tests/PaginationTests.fs index e4cfa49..93d6833 100644 --- a/tests/FSharp.AWS.DynamoDB.Tests/PaginationTests.fs +++ b/tests/FSharp.AWS.DynamoDB.Tests/PaginationTests.fs @@ -43,7 +43,7 @@ type ``Pagination Tests`` (fixture : TableFixture) = LocalAttribute = int (rand () % 2L) } - let table = fixture.CreateContextAndTableIfNotExists() + let table = fixture.CreateEmpty() let [] ``Paginated Query on Primary Key`` () = let hk = guid() diff --git a/tests/FSharp.AWS.DynamoDB.Tests/ProjectionExpressionTests.fs b/tests/FSharp.AWS.DynamoDB.Tests/ProjectionExpressionTests.fs index db5f1e5..5b039cd 100644 --- a/tests/FSharp.AWS.DynamoDB.Tests/ProjectionExpressionTests.fs +++ b/tests/FSharp.AWS.DynamoDB.Tests/ProjectionExpressionTests.fs @@ -97,7 +97,7 @@ type ``Projection Expression Tests`` (fixture : TableFixture) = Serialized = rand(), guid() ; Serialized2 = { NV = guid() ; NE = enum (int (rand()) % 3) } ; } - let table = fixture.CreateContextAndTableIfNotExists() + let table = fixture.CreateEmpty() let [] ``Should fail on invalid projections`` () = let testProj (p : Expr 'T>) = diff --git a/tests/FSharp.AWS.DynamoDB.Tests/SimpleTableOperationTests.fs b/tests/FSharp.AWS.DynamoDB.Tests/SimpleTableOperationTests.fs index 752d307..ec671a9 100644 --- a/tests/FSharp.AWS.DynamoDB.Tests/SimpleTableOperationTests.fs +++ b/tests/FSharp.AWS.DynamoDB.Tests/SimpleTableOperationTests.fs @@ -56,7 +56,7 @@ type ``Simple Table Operation Tests`` (fixture : TableFixture) = Unions = [Choice1Of3 (guid()) ; Choice2Of3(rand()) ; Choice3Of3(Guid.NewGuid().ToByteArray())] } - let table = fixture.CreateContextAndTableIfNotExists() + let table = fixture.CreateEmpty() let [] ``Convert to compatible table`` () = let table' = table.WithRecordType () diff --git a/tests/FSharp.AWS.DynamoDB.Tests/SparseGSITests.fs b/tests/FSharp.AWS.DynamoDB.Tests/SparseGSITests.fs index f553b30..70e9bda 100644 --- a/tests/FSharp.AWS.DynamoDB.Tests/SparseGSITests.fs +++ b/tests/FSharp.AWS.DynamoDB.Tests/SparseGSITests.fs @@ -31,7 +31,7 @@ type ``Sparse GSI Tests`` (fixture : TableFixture) = SecondaryHashKey = if rand() % 2L = 0L then Some (guid()) else None ; } - let table = fixture.CreateContextAndTableIfNotExists() + let table = fixture.CreateEmpty() let [] ``GSI Put Operation`` () = let value = mkItem() diff --git a/tests/FSharp.AWS.DynamoDB.Tests/UpdateExpressionTests.fs b/tests/FSharp.AWS.DynamoDB.Tests/UpdateExpressionTests.fs index ea95d2d..f9d1343 100644 --- a/tests/FSharp.AWS.DynamoDB.Tests/UpdateExpressionTests.fs +++ b/tests/FSharp.AWS.DynamoDB.Tests/UpdateExpressionTests.fs @@ -94,7 +94,7 @@ type ``Update Expression Tests``(fixture : TableFixture) = Serialized = rand(), guid() ; Serialized2 = { NV = guid() ; NE = enum (int (rand()) % 3) } ; } - let table = fixture.CreateContextAndTableIfNotExists() + let table = fixture.CreateEmpty() let [] ``Attempt to update HashKey`` () = let item = mkItem() diff --git a/tests/FSharp.AWS.DynamoDB.Tests/Utils.fs b/tests/FSharp.AWS.DynamoDB.Tests/Utils.fs index 4d93c40..606ed0c 100644 --- a/tests/FSharp.AWS.DynamoDB.Tests/Utils.fs +++ b/tests/FSharp.AWS.DynamoDB.Tests/Utils.fs @@ -46,7 +46,7 @@ module Utils = member _.Client = client member _.TableName = tableName - member _.CreateContextAndTableIfNotExists<'TRecord>() = + member _.CreateEmpty<'TRecord>() = let throughput = ProvisionedThroughput(readCapacityUnits = 10L, writeCapacityUnits = 10L) Scripting.TableContext.Initialize<'TRecord>(client, tableName, Throughput.Provisioned throughput)