Skip to content

Commit

Permalink
Rename TransactionBuilder -> Transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
purkhusid committed Oct 14, 2024
1 parent 76b7ee9 commit 026cf02
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
10 changes: 5 additions & 5 deletions src/FSharp.AWS.DynamoDB/TableContext.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2023,7 +2023,7 @@ module TransactWriteItemsRequest =
| _ -> None


type TransactionBuilder(?metricsCollector: (RequestMetrics -> unit)) =
type Transaction(?metricsCollector: (RequestMetrics -> unit)) =
let transactionItems = ResizeArray<TransactWriteItem>()
let mutable (dynamoDbClient: IAmazonDynamoDB) = null

Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -2087,7 +2087,7 @@ type TransactionBuilder(?metricsCollector: (RequestMetrics -> unit)) =
tableContext: TableContext<'TRecord>,
key: TableKey,
precondition: option<ConditionExpression<'TRecord>>
) : TransactionBuilder =
) : Transaction =
setClient tableContext.Client

let req = Delete(TableName = tableContext.TableName, Key = tableContext.Template.ToAttributeValues key)
Expand Down
4 changes: 2 additions & 2 deletions tests/FSharp.AWS.DynamoDB.Tests/MetricsCollectorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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 ->
Expand Down
38 changes: 19 additions & 19 deletions tests/FSharp.AWS.DynamoDB.Tests/SimpleTableOperationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()
Expand All @@ -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 ->
Expand All @@ -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)

Expand All @@ -236,30 +236,30 @@ 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
existsConditionTable1
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
Expand All @@ -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
<@
Expand All @@ -289,16 +289,16 @@ type ``TransactWriteItems tests``(table1: TableFixture, table2: TableFixture) =

[<Fact>]
let ``Empty request list is rejected with AORE`` () =
shouldBeRejectedWithArgumentOutOfRangeException (TransactionBuilder())
shouldBeRejectedWithArgumentOutOfRangeException (Transaction())
|> Async.RunSynchronously
|> ignore

[<Fact>]
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<TableFixture>

0 comments on commit 026cf02

Please sign in to comment.