From 026cf023fa77a6c3561d7aa04f45f6afeb43d101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=C3=ADel=20P=2E=20Purkh=C3=BAs?= Date: Mon, 14 Oct 2024 10:37:00 +0000 Subject: [PATCH] Rename TransactionBuilder -> Transaction --- src/FSharp.AWS.DynamoDB/TableContext.fs | 10 ++--- .../MetricsCollectorTests.fs | 4 +- .../SimpleTableOperationTests.fs | 38 +++++++++---------- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/FSharp.AWS.DynamoDB/TableContext.fs b/src/FSharp.AWS.DynamoDB/TableContext.fs index 7bbb783..7668c05 100644 --- a/src/FSharp.AWS.DynamoDB/TableContext.fs +++ b/src/FSharp.AWS.DynamoDB/TableContext.fs @@ -2023,7 +2023,7 @@ module TransactWriteItemsRequest = | _ -> None -type TransactionBuilder(?metricsCollector: (RequestMetrics -> unit)) = +type Transaction(?metricsCollector: (RequestMetrics -> unit)) = let transactionItems = ResizeArray() let mutable (dynamoDbClient: IAmazonDynamoDB) = null @@ -2049,7 +2049,7 @@ type TransactionBuilder(?metricsCollector: (RequestMetrics -> unit)) = tableContext: TableContext<'TRecord>, item: 'TRecord, ?precondition: ConditionExpression<'TRecord> - ) : TransactionBuilder = + ) : Transaction = setClient tableContext.Client let req = Put(TableName = tableContext.TableName, Item = tableContext.Template.ToAttributeValues item) precondition @@ -2058,7 +2058,7 @@ type TransactionBuilder(?metricsCollector: (RequestMetrics -> unit)) = req.ConditionExpression <- cond.Conditional.Write writer) transactionItems.Add(TransactWriteItem(Put = req)) this - member this.Check(tableContext: TableContext<'TRecord>, key: TableKey, condition: ConditionExpression<'TRecord>) : TransactionBuilder = + member this.Check(tableContext: TableContext<'TRecord>, key: TableKey, condition: ConditionExpression<'TRecord>) : Transaction = setClient tableContext.Client let req = ConditionCheck(TableName = tableContext.TableName, Key = tableContext.Template.ToAttributeValues key) @@ -2073,7 +2073,7 @@ type TransactionBuilder(?metricsCollector: (RequestMetrics -> unit)) = updater: UpdateExpression<'TRecord>, ?precondition: ConditionExpression<'TRecord> - ) : TransactionBuilder = + ) : Transaction = setClient tableContext.Client let req = Update(TableName = tableContext.TableName, Key = tableContext.Template.ToAttributeValues key) @@ -2087,7 +2087,7 @@ type TransactionBuilder(?metricsCollector: (RequestMetrics -> unit)) = tableContext: TableContext<'TRecord>, key: TableKey, precondition: option> - ) : TransactionBuilder = + ) : Transaction = setClient tableContext.Client let req = Delete(TableName = tableContext.TableName, Key = tableContext.Template.ToAttributeValues key) diff --git a/tests/FSharp.AWS.DynamoDB.Tests/MetricsCollectorTests.fs b/tests/FSharp.AWS.DynamoDB.Tests/MetricsCollectorTests.fs index aedb110..dddcb83 100644 --- a/tests/FSharp.AWS.DynamoDB.Tests/MetricsCollectorTests.fs +++ b/tests/FSharp.AWS.DynamoDB.Tests/MetricsCollectorTests.fs @@ -107,7 +107,7 @@ type Tests(fixture: TableFixture) = let item = mkItem (guid ()) (guid ()) 0 do! - TransactionBuilder(collector.Collect) + Transaction(collector.Collect) .Put(sut, item, compile <@ fun t -> NOT_EXISTS t.RangeKey @>) .TransactWriteItems() @@ -135,7 +135,7 @@ type Tests(fixture: TableFixture) = try do! // The check will fail, which triggers a throw from the underlying AWS SDK; there's no way to extract the consumption info in that case - TransactionBuilder() + Transaction() .Put(sut, item, compile <@ fun t -> EXISTS t.RangeKey @>) .TransactWriteItems() with TransactWriteItemsRequest.TransactionCanceledConditionalCheckFailed -> diff --git a/tests/FSharp.AWS.DynamoDB.Tests/SimpleTableOperationTests.fs b/tests/FSharp.AWS.DynamoDB.Tests/SimpleTableOperationTests.fs index 152c0ba..683390e 100644 --- a/tests/FSharp.AWS.DynamoDB.Tests/SimpleTableOperationTests.fs +++ b/tests/FSharp.AWS.DynamoDB.Tests/SimpleTableOperationTests.fs @@ -162,7 +162,7 @@ type ``TransactWriteItems tests``(table1: TableFixture, table2: TableFixture) = let ``Minimal happy path`` () = async { let item = mkItem () do! - TransactionBuilder() + Transaction() .Put(table1, item, doesntExistConditionTable1) .TransactWriteItems() @@ -176,7 +176,7 @@ type ``TransactWriteItems tests``(table1: TableFixture, table2: TableFixture) = let compatibleItem = mkCompatibleItem () do! - TransactionBuilder() + Transaction() .Put(table1, item, doesntExistConditionTable1) .Put(table2, compatibleItem, doesntExistConditionTable2) .TransactWriteItems() @@ -195,7 +195,7 @@ type ``TransactWriteItems tests``(table1: TableFixture, table2: TableFixture) = let mutable failed = false try do! - TransactionBuilder() + Transaction() .Put(table1, item, existsConditionTable1) .TransactWriteItems() with TransactWriteItemsRequest.TransactionCanceledConditionalCheckFailed -> @@ -214,9 +214,9 @@ type ``TransactWriteItems tests``(table1: TableFixture, table2: TableFixture) = let transaction = if shouldFail then - TransactionBuilder().Check(table1, key, doesntExistConditionTable1) + Transaction().Check(table1, key, doesntExistConditionTable1) else - TransactionBuilder() + Transaction() .Check(table1, key, existsConditionTable1) .Put(table1, item2) @@ -236,15 +236,15 @@ type ``TransactWriteItems tests``(table1: TableFixture, table2: TableFixture) = let ``All paths`` shouldFail = async { let item, item2, item3, item4, item5, item6, item7 = mkItem (), mkItem (), mkItem (), mkItem (), mkItem (), mkItem (), mkItem () let! key = table1.PutItemAsync item - let transactionBuilder = TransactionBuilder() + let Transaction = Transaction() let requests = - [ transactionBuilder.Update(table1, key, compileUpdateTable1 <@ fun t -> { t with Value = 42 } @>, existsConditionTable1) - transactionBuilder.Put(table1, item2) - transactionBuilder.Put(table1, item3, doesntExistConditionTable1) - transactionBuilder.Delete(table1, table1.Template.ExtractKey item4, Some doesntExistConditionTable1) - transactionBuilder.Delete(table1, table1.Template.ExtractKey item5, None) - transactionBuilder.Check( + [ Transaction.Update(table1, key, compileUpdateTable1 <@ fun t -> { t with Value = 42 } @>, existsConditionTable1) + Transaction.Put(table1, item2) + Transaction.Put(table1, item3, doesntExistConditionTable1) + Transaction.Delete(table1, table1.Template.ExtractKey item4, Some doesntExistConditionTable1) + Transaction.Delete(table1, table1.Template.ExtractKey item5, None) + Transaction.Check( table1, table1.Template.ExtractKey item6, (if shouldFail then @@ -252,14 +252,14 @@ type ``TransactWriteItems tests``(table1: TableFixture, table2: TableFixture) = else doesntExistConditionTable1) ) - transactionBuilder.Update( + Transaction.Update( table1, TableKey.Combined(item7.HashKey, item7.RangeKey), compileUpdateTable1 <@ fun t -> { t with Tuple = (42, 42) } @> ) ] let mutable failed = false try - do! transactionBuilder.TransactWriteItems() + do! Transaction.TransactWriteItems() with TransactWriteItemsRequest.TransactionCanceledConditionalCheckFailed -> failed <- true failed =! shouldFail @@ -277,7 +277,7 @@ type ``TransactWriteItems tests``(table1: TableFixture, table2: TableFixture) = test <@ shouldFail <> (maybeItem7 |> Option.map (fun x -> x.Tuple) |> Option.contains (42, 42)) @> } - let shouldBeRejectedWithArgumentOutOfRangeException (builder: TransactionBuilder) = async { + let shouldBeRejectedWithArgumentOutOfRangeException (builder: Transaction) = async { let! e = Async.Catch(builder.TransactWriteItems()) test <@ @@ -289,16 +289,16 @@ type ``TransactWriteItems tests``(table1: TableFixture, table2: TableFixture) = [] let ``Empty request list is rejected with AORE`` () = - shouldBeRejectedWithArgumentOutOfRangeException (TransactionBuilder()) + shouldBeRejectedWithArgumentOutOfRangeException (Transaction()) |> Async.RunSynchronously |> ignore [] let ``Over 100 writes are rejected with AORE`` () = - let transactionBuilder = TransactionBuilder() + let Transaction = Transaction() for _x in 1..101 do - transactionBuilder.Put(table1, mkItem ()) |> ignore + Transaction.Put(table1, mkItem ()) |> ignore - shouldBeRejectedWithArgumentOutOfRangeException transactionBuilder + shouldBeRejectedWithArgumentOutOfRangeException Transaction interface IClassFixture