Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #78. #82

Merged
merged 4 commits into from
Jul 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/FSharp.Azure.StorageTypeProvider/Queue/ProvidedQueueTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type PopReceipt = | PopReceipt of string
type ProvidedMessageId = | ProvidedMessageId of MessageId : MessageId * PopReceipt : PopReceipt

/// Represents a single message that has been dequeued.
type ProvidedQueueMessage =
type ProvidedQueueMessage =
{ /// The composite key of this message, containing both the message id and the pop receipt.
Id : ProvidedMessageId
/// The number of times this message has been dequeued.
Expand All @@ -26,9 +26,9 @@ type ProvidedQueueMessage =
/// The time that this message will next become visible.
NextVisibleTime : DateTimeOffset option
/// Gets the contents of the message as a byte array.
AsBytes : byte array
AsBytes : Lazy<byte array>
/// Gets the contest of the message as a string.
AsString : string }
AsString : Lazy<string> }

module internal Factory =
let unpackId messageId =
Expand All @@ -41,8 +41,8 @@ module internal Factory =
InsertionTime = message.InsertionTime |> Option.ofNullable
ExpirationTime = message.ExpirationTime |> Option.ofNullable
NextVisibleTime = message.NextVisibleTime |> Option.ofNullable
AsBytes = message.AsBytes
AsString = message.AsString }
AsBytes = Lazy.Create(fun _ -> message.AsBytes)
AsString = Lazy.Create(fun _ -> message.AsString) }

let toAzureQueueMessage providedMessageId =
let messageId, popReceipt = providedMessageId |> unpackId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,9 @@ type AzureTable internal (defaultConnection, tableName) =
/// Asynchronously deletes an entire partition from the table
member __.DeletePartitionAsync(partitionKey, ?connectionString) = async {
let table = getTableForConnection (defaultArg connectionString defaultConnection)
let connStringToUse =
match connectionString with
| Some c -> c
| None -> defaultConnection
let connectionString = defaultArg connectionString defaultConnection
let filter = Table.TableQuery.GenerateFilterCondition ("PartitionKey", Table.QueryComparisons.Equal, partitionKey)
let! response = executeGenericQueryAsync connStringToUse table.Name Int32.MaxValue filter (fun e -> (Partition(e.PartitionKey), Row(e.RowKey)))
let! response = executeGenericQueryAsync connectionString table.Name Int32.MaxValue filter (fun e -> (Partition(e.PartitionKey), Row(e.RowKey)))
return!
response
|> __.DeleteAsync
Expand Down
30 changes: 19 additions & 11 deletions tests/IntegrationTests/QueueUnitTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ type Local = AzureTypeProvider<"DevStorageAccount", "">

type ResetQueueDataAttribute() =
inherit BeforeAfterTestAttribute()
override x.Before(methodUnderTest) = QueueHelpers.resetData()
override x.After(methodUnderTest) = QueueHelpers.resetData()
override __.Before _ = QueueHelpers.resetData()
override __.After _ = QueueHelpers.resetData()

[<Fact>]
let ``Correctly identifies queues``() =
// compiles!
Local.Queues.``sample-queue`` |> ignore
Local.Queues.``second-sample`` |> ignore
Local.Queues.``third-sample``
Local.Queues.``third-sample`` |> ignore

let queue = Local.Queues.``sample-queue``

[<Fact>]
[<ResetQueueData>]
let ``Enqueues a message``() =
queue.Enqueue("Foo") |> Async.RunSynchronously
queue.Enqueue "Foo" |> Async.RunSynchronously
test <@ queue.GetCurrentLength() = 1 @>

[<Fact>]
Expand All @@ -36,22 +36,30 @@ let ``Dequeues a message``() =
let message = async { do! queue.Enqueue "Foo"
return! queue.Dequeue() }
|> Async.RunSynchronously
test <@ message.Value.AsString = "Foo" @>
test <@ message.Value.AsString.Value = "Foo" @>

[<Fact>]
[<ResetQueueData>]
let ``Dequeues a message of bytes``() =
let message = async { do! queue.Enqueue [| 0uy; 1uy; 2uy; |]
return! queue.Dequeue() }
|> Async.RunSynchronously
test <@ message.Value.AsBytes = [| 0uy; 1uy; 2uy; |] @>
test <@ message.Value.AsBytes.Value = [| 0uy; 1uy; 2uy; |] @>

[<Fact(Skip = "Waiting for reproducable test case")>]
[<ResetQueueData>]
let ``Safely supports lazy evaluation of "bad data"``() =
let message = async { do! queue.Enqueue [| 0uy; 1uy; 2uy; |]
return! queue.Dequeue() }
|> Async.RunSynchronously
test <@ message.Value.AsString.Value <> null @>

[<Fact>]
[<ResetQueueData>]
let ``Deletes a message``() =
async { do! queue.Enqueue "Foo"
let! message = queue.Dequeue()
do! queue.DeleteMessage(message.Value.Id) }
do! queue.DeleteMessage message.Value.Id }
|> Async.RunSynchronously
test <@ queue.GetCurrentLength() = 0 @>

Expand All @@ -69,7 +77,7 @@ let ``Update Message affects the text message body``() =
return! queue.Dequeue() }
|> Async.RunSynchronously

test <@ message.Value.AsString = "Bar" @>
test <@ message.Value.AsString.Value = "Bar" @>

[<Fact>]
[<ResetQueueData>]
Expand All @@ -80,17 +88,17 @@ let ``Update Message affects the bytes message body``() =
return! queue.Dequeue() }
|> Async.RunSynchronously

test <@ message.Value.AsBytes = [| 2uy; 1uy; 0uy |] @>
test <@ message.Value.AsBytes.Value = [| 2uy; 1uy; 0uy |] @>

[<Fact>]
[<ResetQueueData>]
let ``Dequeue Count is correctly emitted``() =
let message = async {
do! queue.Enqueue("Foo")
let! message = queue.Dequeue()
do! queue.UpdateMessage(message.Value.Id, TimeSpan.FromSeconds(0.))
do! queue.UpdateMessage(message.Value.Id, TimeSpan.FromSeconds 0.)
let! message = queue.Dequeue()
do! queue.UpdateMessage(message.Value.Id, TimeSpan.FromSeconds(0.))
do! queue.UpdateMessage(message.Value.Id, TimeSpan.FromSeconds 0.)
return! queue.Dequeue() } |> Async.RunSynchronously
test <@ message.Value.DequeueCount = 3 @>

Expand Down