From f908a67ec6a86a840b7a684e6e0f6407d74fe999 Mon Sep 17 00:00:00 2001 From: Gauri Prasad Date: Wed, 21 Oct 2020 14:51:14 -0700 Subject: [PATCH 1/2] Fixed bug where NPE was returned on null visibilityTimeout --- .../azure/storage/queue/QueueAsyncClient.java | 5 +- .../com/azure/storage/queue/QueueClient.java | 4 +- .../azure/storage/queue/QueueAPITests.groovy | 17 +++ ...ueueAPITestsUpdateMessageNullDuration.json | 110 ++++++++++++++++++ 4 files changed, 132 insertions(+), 4 deletions(-) create mode 100644 sdk/storage/azure-storage-queue/src/test/resources/session-records/QueueAPITestsUpdateMessageNullDuration.json diff --git a/sdk/storage/azure-storage-queue/src/main/java/com/azure/storage/queue/QueueAsyncClient.java b/sdk/storage/azure-storage-queue/src/main/java/com/azure/storage/queue/QueueAsyncClient.java index 319002e9eff6..8cd342a49554 100644 --- a/sdk/storage/azure-storage-queue/src/main/java/com/azure/storage/queue/QueueAsyncClient.java +++ b/sdk/storage/azure-storage-queue/src/main/java/com/azure/storage/queue/QueueAsyncClient.java @@ -779,7 +779,7 @@ PagedFlux peekMessagesWithOptionalTimeout(Integer maxMessages * @param popReceipt Unique identifier that must match for the message to be updated * @param messageText Updated value for the message * @param visibilityTimeout The timeout period for how long the message is invisible in the queue in seconds. The - * timeout period must be between 1 second and 7 days. + * timeout period must be between 1 second and 7 days. The default value is Duration.ZERO. * @return A {@link UpdateMessageResult} that contains the new * {@link UpdateMessageResult#getPopReceipt() popReceipt} to interact with the message, * additionally contains the updated metadata about the message. @@ -812,7 +812,7 @@ public Mono updateMessage(String messageId, String popRecei * @param popReceipt Unique identifier that must match for the message to be updated * @param messageText Updated value for the message * @param visibilityTimeout The timeout period for how long the message is invisible in the queue in seconds. The - * timeout period must be between 1 second and 7 days. + * timeout period must be between 1 second and 7 days. The default value is Duration.ZERO. * @return A {@link UpdateMessageResult} that contains the new * {@link UpdateMessageResult#getPopReceipt() popReceipt} to interact with the message, * additionally contains the updated metadata about the message. @@ -833,6 +833,7 @@ Mono> updateMessageWithResponse(String messageId, String messageText, Duration visibilityTimeout, Context context) { QueueMessage message = messageText == null ? null : new QueueMessage().setMessageText(messageText); context = context == null ? Context.NONE : context; + visibilityTimeout = visibilityTimeout == null ? Duration.ZERO : visibilityTimeout; return client.messageIds().updateWithRestResponseAsync(queueName, messageId, popReceipt, (int) visibilityTimeout.getSeconds(), message, null, null, context.addData(AZ_TRACING_NAMESPACE_KEY, STORAGE_TRACING_NAMESPACE_VALUE)) diff --git a/sdk/storage/azure-storage-queue/src/main/java/com/azure/storage/queue/QueueClient.java b/sdk/storage/azure-storage-queue/src/main/java/com/azure/storage/queue/QueueClient.java index fc98c2fb8386..148e1f34ddc2 100644 --- a/sdk/storage/azure-storage-queue/src/main/java/com/azure/storage/queue/QueueClient.java +++ b/sdk/storage/azure-storage-queue/src/main/java/com/azure/storage/queue/QueueClient.java @@ -583,7 +583,7 @@ public PagedIterable peekMessages(Integer maxMessages, Durati * @param popReceipt Unique identifier that must match for the message to be updated * @param messageText Updated value for the message * @param visibilityTimeout The timeout period for how long the message is invisible in the queue in seconds. The - * timeout period must be between 1 second and 7 days. + * timeout period must be between 1 second and 7 days. The default value is Duration.ZERO. * @return A {@link UpdateMessageResult} that contains the new * {@link UpdateMessageResult#getPopReceipt() popReceipt} to interact with the message, * additionally contains the updated metadata about the message. @@ -612,7 +612,7 @@ public UpdateMessageResult updateMessage(String messageId, String popReceipt, St * @param popReceipt Unique identifier that must match for the message to be updated * @param messageText Updated value for the message * @param visibilityTimeout The timeout period for how long the message is invisible in the queue in seconds. The - * timeout period must be between 1 second and 7 days. + * timeout period must be between 1 second and 7 days. The default value is Duration.ZERO. * @param timeout An optional timeout applied to the operation. If a response is not returned before the timeout * concludes a {@link RuntimeException} will be thrown. * @param context Additional context that is passed through the Http pipeline during the service call. diff --git a/sdk/storage/azure-storage-queue/src/test/java/com/azure/storage/queue/QueueAPITests.groovy b/sdk/storage/azure-storage-queue/src/test/java/com/azure/storage/queue/QueueAPITests.groovy index 6602dce479e2..99b7c0613cf6 100644 --- a/sdk/storage/azure-storage-queue/src/test/java/com/azure/storage/queue/QueueAPITests.groovy +++ b/sdk/storage/azure-storage-queue/src/test/java/com/azure/storage/queue/QueueAPITests.groovy @@ -458,6 +458,23 @@ class QueueAPITests extends APISpec { messageText == peekMsgIter.getMessageText() } + def "Update message null duration"() { + given: + def messageText = "test message before update" + queueClient.create() + queueClient.sendMessage(messageText) + + def dequeueMsg = queueClient.receiveMessage() + when: + def updateMsgResponse = queueClient.updateMessageWithResponse(dequeueMsg.getMessageId(), + dequeueMsg.getPopReceipt(), null, null, null, null) + sleepIfLive(2000) + def peekMsgIter = queueClient.peekMessage() + then: + QueueTestHelper.assertResponseStatusCode(updateMsgResponse, 204) + messageText == peekMsgIter.getMessageText() + } + @Unroll def "Update message invalid args"() { given: diff --git a/sdk/storage/azure-storage-queue/src/test/resources/session-records/QueueAPITestsUpdateMessageNullDuration.json b/sdk/storage/azure-storage-queue/src/test/resources/session-records/QueueAPITestsUpdateMessageNullDuration.json new file mode 100644 index 000000000000..84314dc38e40 --- /dev/null +++ b/sdk/storage/azure-storage-queue/src/test/resources/session-records/QueueAPITestsUpdateMessageNullDuration.json @@ -0,0 +1,110 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://REDACTED.queue.core.windows.net/queueapitestsupdatemessagenullduration842819d7fed86", + "Headers" : { + "x-ms-version" : "2020-02-10", + "User-Agent" : "azsdk-java-azure-storage-queue/12.7.0-beta.2 (11.0.7; Windows 10; 10.0)", + "x-ms-client-request-id" : "f9843273-eb84-46fd-b7f4-cd6f3285bf82" + }, + "Response" : { + "x-ms-version" : "2020-02-10", + "Server" : "Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0", + "retry-after" : "0", + "Content-Length" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "3bf16729-a003-0028-49f4-a74401000000", + "Date" : "Wed, 21 Oct 2020 21:49:25 GMT", + "x-ms-client-request-id" : "f9843273-eb84-46fd-b7f4-cd6f3285bf82" + }, + "Exception" : null + }, { + "Method" : "POST", + "Uri" : "https://REDACTED.queue.core.windows.net/queueapitestsupdatemessagenullduration842819d7fed86/messages", + "Headers" : { + "x-ms-version" : "2020-02-10", + "User-Agent" : "azsdk-java-azure-storage-queue/12.7.0-beta.2 (11.0.7; Windows 10; 10.0)", + "x-ms-client-request-id" : "ea0d98d0-caba-4aa1-9e0a-ae8283e82051", + "Content-Type" : "application/xml; charset=utf-8" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-02-10", + "Server" : "Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "3bf16759-a003-0028-72f4-a74401000000", + "Body" : "f28a8611-c393-4825-92fa-e48e661b59c8Wed, 21 Oct 2020 21:49:27 GMTWed, 28 Oct 2020 21:49:27 GMTAgAAAAMAAAAAAAAAqrNhDPSn1gE=Wed, 21 Oct 2020 21:49:27 GMT", + "Date" : "Wed, 21 Oct 2020 21:49:26 GMT", + "x-ms-client-request-id" : "ea0d98d0-caba-4aa1-9e0a-ae8283e82051", + "Content-Type" : "application/xml" + }, + "Exception" : null + }, { + "Method" : "GET", + "Uri" : "https://REDACTED.queue.core.windows.net/queueapitestsupdatemessagenullduration842819d7fed86/messages?numofmessages=1", + "Headers" : { + "x-ms-version" : "2020-02-10", + "User-Agent" : "azsdk-java-azure-storage-queue/12.7.0-beta.2 (11.0.7; Windows 10; 10.0)", + "x-ms-client-request-id" : "b00cfa4e-e113-439e-b457-b3e44193dd5b" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-02-10", + "Server" : "Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0", + "Cache-Control" : "no-cache", + "retry-after" : "0", + "StatusCode" : "200", + "x-ms-request-id" : "3bf1676c-a003-0028-04f4-a74401000000", + "Body" : "f28a8611-c393-4825-92fa-e48e661b59c8Wed, 21 Oct 2020 21:49:27 GMTWed, 28 Oct 2020 21:49:27 GMTAgAAAAMAAAAAAAAACf1qHvSn1gE=Wed, 21 Oct 2020 21:49:57 GMT1test message before update", + "Date" : "Wed, 21 Oct 2020 21:49:26 GMT", + "x-ms-client-request-id" : "b00cfa4e-e113-439e-b457-b3e44193dd5b", + "Content-Type" : "application/xml" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.queue.core.windows.net/queueapitestsupdatemessagenullduration842819d7fed86/messages/f28a8611-c393-4825-92fa-e48e661b59c8?popreceipt=AgAAAAMAAAAAAAAACf1qHvSn1gE%3D&visibilitytimeout=0", + "Headers" : { + "x-ms-version" : "2020-02-10", + "User-Agent" : "azsdk-java-azure-storage-queue/12.7.0-beta.2 (11.0.7; Windows 10; 10.0)", + "x-ms-client-request-id" : "e961f723-85ca-4369-99b0-34b4aebf9a6c" + }, + "Response" : { + "x-ms-version" : "2020-02-10", + "Server" : "Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-time-next-visible" : "Wed, 21 Oct 2020 21:49:28 GMT", + "retry-after" : "0", + "Content-Length" : "0", + "StatusCode" : "204", + "x-ms-request-id" : "3bf16782-a003-0028-18f4-a74401000000", + "x-ms-popreceipt" : "AwAAAAMAAAAAAAAA+IunDPSn1gEBAAAA", + "Date" : "Wed, 21 Oct 2020 21:49:27 GMT", + "x-ms-client-request-id" : "e961f723-85ca-4369-99b0-34b4aebf9a6c" + }, + "Exception" : null + }, { + "Method" : "GET", + "Uri" : "https://REDACTED.queue.core.windows.net/queueapitestsupdatemessagenullduration842819d7fed86/messages?peekonly=true", + "Headers" : { + "x-ms-version" : "2020-02-10", + "User-Agent" : "azsdk-java-azure-storage-queue/12.7.0-beta.2 (11.0.7; Windows 10; 10.0)", + "x-ms-client-request-id" : "7abaf01c-93d1-4d12-93ed-61932a1ed0de" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-02-10", + "Server" : "Windows-Azure-Queue/1.0 Microsoft-HTTPAPI/2.0", + "Cache-Control" : "no-cache", + "retry-after" : "0", + "StatusCode" : "200", + "x-ms-request-id" : "3bf167d5-a003-0028-66f4-a74401000000", + "Body" : "f28a8611-c393-4825-92fa-e48e661b59c8Wed, 21 Oct 2020 21:49:27 GMTWed, 28 Oct 2020 21:49:27 GMT1test message before update", + "Date" : "Wed, 21 Oct 2020 21:49:29 GMT", + "x-ms-client-request-id" : "7abaf01c-93d1-4d12-93ed-61932a1ed0de", + "Content-Type" : "application/xml" + }, + "Exception" : null + } ], + "variables" : [ "queueapitestsupdatemessagenullduration842819d7fed86" ] +} \ No newline at end of file From 09e21645685aa8d5b8d43679950515053864c4d7 Mon Sep 17 00:00:00 2001 From: Gauri Prasad Date: Wed, 21 Oct 2020 14:51:57 -0700 Subject: [PATCH 2/2] Changelog --- sdk/storage/azure-storage-queue/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/storage/azure-storage-queue/CHANGELOG.md b/sdk/storage/azure-storage-queue/CHANGELOG.md index ad27ffb0df23..bf94d2a64374 100644 --- a/sdk/storage/azure-storage-queue/CHANGELOG.md +++ b/sdk/storage/azure-storage-queue/CHANGELOG.md @@ -2,6 +2,7 @@ ## 12.7.0-beta.2 (Unreleased) - Added support to specify whether or not a pipeline policy should be added per call or per retry. +- Fixed a bug that would cause a NPE when visibilityTimeout was set to null in QueueClient.updateMessage ## 12.7.0-beta.1 (2020-10-01) - Added support for the 2020-02-10 service version.