Skip to content

Commit

Permalink
Uncommenting tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alzimmermsft committed Jun 28, 2019
1 parent c7bb151 commit 25ed916
Showing 1 changed file with 50 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
package com.azure.storage.blob

import com.azure.core.http.HttpHeaders
import com.azure.core.http.HttpPipelineCallContext
import com.azure.core.http.HttpPipelineNextPolicy
import com.azure.core.http.HttpRequest
import com.azure.core.http.policy.HttpPipelinePolicy
import com.azure.core.http.rest.Response
import com.azure.core.http.rest.VoidResponse
import com.azure.core.implementation.util.ImplUtils
import com.azure.storage.blob.BlobProperties
import com.azure.storage.blob.models.*
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
import spock.lang.Unroll

import java.nio.ByteBuffer
Expand Down Expand Up @@ -76,46 +83,49 @@ class BlobAPITest extends APISpec {
This is to test the appropriate integration of DownloadResponse, including setting the correct range values on
HTTPGetterInfo.
*/
// def "Download with retry range"() {
// /*
// We are going to make a request for some range on a blob. The Flux returned will throw an exception, forcing
// a retry per the ReliableDownloadOptions. The next request should have the same range header, which was generated
// from the count and offset values in HTTPGetterInfo that was constructed on the initial call to download. We
// don't need to check the data here, but we want to ensure that the correct range is set each time. This will
// test the correction of a bug that was found which caused HTTPGetterInfo to have an incorrect offset when it was
// constructed in BlobClient.download().
// */
// setup:
// def mockPolicy = Mock(HttpPipelinePolicy) {
// process(_ as HttpPipelineCallContext, _ as HttpPipelineNextPolicy) >> {
// HttpPipelineCallContext context, HttpPipelineNextPolicy next ->
// HttpRequest request = context.httpRequest()
// if (request.headers().value("x-ms-range") != "bytes=2-6") {
// return Mono.error(new IllegalArgumentException("The range header was not set correctly on retry."))
// }
// else {
// // ETag can be a dummy value. It's not validated, but DownloadResponse requires one
// // return Mono.just(getStubResponseForBlobDownload(206, Flux.error(new IOException()), "etag"))
// }
// }
// }
//
// def pipeline = HttpPipeline.builder().policies(mockPolicy).build()
// bu = bu.pipeline(pipeline)
//
// when:
// def range = new BlobRange(2, 5L)
// def options = new ReliableDownloadOptions().maxretryrequests(3)
// bu.download(null, options, range, null, false, null)
//
// then:
// /*
// Because the dummy Flux always throws an error. This will also validate that an IllegalArgumentException is
// NOT thrown because the types would not match.
// */
// def e = thrown(RuntimeException)
// e.getCause() instanceof IOException
// }
def "Download with retry range"() {
/*
We are going to make a request for some range on a blob. The Flux returned will throw an exception, forcing
a retry per the ReliableDownloadOptions. The next request should have the same range header, which was generated
from the count and offset values in HTTPGetterInfo that was constructed on the initial call to download. We
don't need to check the data here, but we want to ensure that the correct range is set each time. This will
test the correction of a bug that was found which caused HTTPGetterInfo to have an incorrect offset when it was
constructed in BlobClient.download().
*/
setup:
HttpPipelinePolicy mockPolicy = Mock(HttpPipelinePolicy) {
process(_ as HttpPipelineCallContext, _ as HttpPipelineNextPolicy) >> {
HttpPipelineCallContext context, HttpPipelineNextPolicy next ->
HttpRequest request = context.httpRequest()
if (request.headers().value("x-ms-range") != "bytes=2-6") {
return Mono.error(new IllegalArgumentException("The range header was not set correctly on retry."))
}
else {
// ETag can be a dummy value. It's not validated, but DownloadResponse requires one
return Mono.just(getStubResponseForBlobDownload(206, Flux.error(new IOException()), "etag"))
}
}
}

BlobClient bu2 = new BlobClientBuilder()
.endpoint(bu.getBlobUrl().toString())
.credential(primaryCreds)
.addPolicy(mockPolicy)
.buildClient()

when:
def range = new BlobRange(2, 5L)
def options = new ReliableDownloadOptions().maxRetryRequests(3)
bu2.download(new ByteArrayOutputStream(), options, range, null, false, null)

then:
/*
Because the dummy Flux always throws an error. This will also validate that an IllegalArgumentException is
NOT thrown because the types would not match.
*/
def e = thrown(RuntimeException)
e.getCause() instanceof IOException
}

def "Download min"() {
when:
Expand Down

0 comments on commit 25ed916

Please sign in to comment.