Skip to content

Commit

Permalink
Updated file progress receiver tests to handle potentially empty buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
alzimmermsft committed Feb 4, 2020
1 parent bbbe9af commit ae21b49
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1209,8 +1209,14 @@ class EncyptedBlockBlobAPITest extends APISpec {
new DownloadRetryOptions().setMaxRetryRequests(3), null, false, null, null)

then:
// We should receive exactly one notification of the completed progress.
1 * mockReceiver.reportProgress(fileSize)
/*
* Should receive at least one notification indicating completed progress, multiple notifications may be
* received if there are empty buffers in the stream.
*/
(1.._) * mockReceiver.reportProgress(fileSize)

// There should be NO notification with a larger than expected size.
0 * mockReceiver.reportProgress({ it > fileSize })

/*
We should receive at least one notification reporting an intermediary value per block, but possibly more
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package com.azure.storage.blob

import com.azure.core.exception.UnexpectedLengthException

import com.azure.core.http.RequestConditions
import com.azure.core.util.CoreUtils
import com.azure.core.util.polling.LongRunningOperationStatus
Expand Down Expand Up @@ -32,7 +32,6 @@ import com.azure.storage.blob.sas.BlobServiceSasSignatureValues
import com.azure.storage.blob.specialized.BlobClientBase
import com.azure.storage.blob.specialized.SpecializedBlobClientBuilder
import com.azure.storage.common.implementation.Constants
import com.ctc.wstx.shaded.msv_core.verifier.jarv.Const
import reactor.core.Exceptions
import reactor.core.publisher.Hooks
import reactor.test.StepVerifier
Expand Down Expand Up @@ -693,16 +692,22 @@ class BlobAPITest extends APISpec {
new DownloadRetryOptions().setMaxRetryRequests(3), null, false, null, null)

then:
// We should receive exactly one notification of the completed progress.
1 * mockReceiver.reportProgress(fileSize)
/*
* Should receive at least one notification indicating completed progress, multiple notifications may be
* received if there are empty buffers in the stream.
*/
(1.._) * mockReceiver.reportProgress(fileSize)

// There should be NO notification with a larger than expected size.
0 * mockReceiver.reportProgress({ it > fileSize })

/*
We should receive at least one notification reporting an intermediary value per block, but possibly more
notifications will be received depending on the implementation. We specify numBlocks - 1 because the last block
will be the total size as above. Finally, we assert that the number reported monotonically increases.
*/
(numBlocks - 1.._) * mockReceiver.reportProgress(!file.size()) >> { long bytesTransferred ->
if (!(bytesTransferred > prevCount)) {
if (!(bytesTransferred >= prevCount)) {
throw new IllegalArgumentException("Reported progress should monotonically increase")
} else {
prevCount = bytesTransferred
Expand Down

0 comments on commit ae21b49

Please sign in to comment.