Skip to content
Draft
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
2 changes: 1 addition & 1 deletion sdk/storage/azure-storage-blob/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/storage/azure-storage-blob",
"Tag": "java/storage/azure-storage-blob_018b1a065c"
"Tag": "java/storage/azure-storage-blob_e4e816b0d8"
}
Original file line number Diff line number Diff line change
Expand Up @@ -1122,33 +1122,17 @@ PagedFlux<BlobItem> listBlobsFlatWithOptionalTimeout(ListBlobsOptions options, S
Duration timeout) {
ModelHelper.validateListBlobsOptions(options);
BiFunction<String, Integer, Mono<PagedResponse<BlobItem>>> func = (marker, pageSize) -> {
ListBlobsOptions finalOptions;
ListBlobsOptions finalOptions = ModelHelper.copyListBlobsOptions(options);
ModelHelper.applyDefaultsToListBlobsOptions(finalOptions);
/*
If pageSize was not set in a .byPage(int) method, the page size from options will be preserved.
Otherwise, prefer the new value.
*/
*/
if (pageSize != null) {
if (options == null) {
finalOptions = new ListBlobsOptions().setMaxResultsPerPage(pageSize);
} else {
// Note that this prefers the value passed to .byPage(int) over the value on the options
finalOptions = new ListBlobsOptions().setMaxResultsPerPage(pageSize)
.setPrefix(options.getPrefix())
.setDetails(options.getDetails())
.setStartFrom(options.getStartFrom());
if (ModelHelper.resolveSerializationFormat(options.getStorageResponseSerializationFormat())
== StorageResponseSerializationFormat.ARROW) {
finalOptions.setStorageResponseSerializationFormat(StorageResponseSerializationFormat.ARROW)
.setEndBefore(options.getEndBefore());
}
}
} else {
finalOptions = options;
finalOptions.setMaxResultsPerPage(pageSize);
}

if (finalOptions != null
&& ModelHelper.resolveSerializationFormat(finalOptions.getStorageResponseSerializationFormat())
== StorageResponseSerializationFormat.ARROW) {
if (finalOptions.getStorageResponseSerializationFormat() == StorageResponseSerializationFormat.ARROW) {
return listBlobsFlatSegmentArrow(marker, finalOptions, timeout);
}

Expand Down Expand Up @@ -1366,33 +1350,17 @@ PagedFlux<BlobItem> listBlobsHierarchyWithOptionalTimeout(String delimiter, List
Duration timeout) {
ModelHelper.validateListBlobsOptions(options);
BiFunction<String, Integer, Mono<PagedResponse<BlobItem>>> func = (marker, pageSize) -> {
ListBlobsOptions finalOptions;
ListBlobsOptions finalOptions = ModelHelper.copyListBlobsOptions(options);
ModelHelper.applyDefaultsToListBlobsOptions(finalOptions);
/*
If pageSize was not set in a .byPage(int) method, the page size from options will be preserved.
Otherwise, prefer the new value.
*/
*/
if (pageSize != null) {
if (options == null) {
finalOptions = new ListBlobsOptions().setMaxResultsPerPage(pageSize);
} else {
// Note that this prefers the value passed to .byPage(int) over the value on the options
finalOptions = new ListBlobsOptions().setMaxResultsPerPage(pageSize)
.setPrefix(options.getPrefix())
.setDetails(options.getDetails())
.setStartFrom(options.getStartFrom());
if (ModelHelper.resolveSerializationFormat(options.getStorageResponseSerializationFormat())
== StorageResponseSerializationFormat.ARROW) {
finalOptions.setStorageResponseSerializationFormat(StorageResponseSerializationFormat.ARROW)
.setEndBefore(options.getEndBefore());
}
}
} else {
finalOptions = options;
finalOptions.setMaxResultsPerPage(pageSize);
}

if (finalOptions != null
&& ModelHelper.resolveSerializationFormat(finalOptions.getStorageResponseSerializationFormat())
== StorageResponseSerializationFormat.ARROW) {
if (finalOptions.getStorageResponseSerializationFormat() == StorageResponseSerializationFormat.ARROW) {
return listBlobsHierarchySegmentArrow(marker, delimiter, finalOptions, timeout);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,19 +1035,8 @@ public PagedIterable<BlobItem> listBlobs(ListBlobsOptions options, Duration time
public PagedIterable<BlobItem> listBlobs(ListBlobsOptions options, String continuationToken, Duration timeout) {
ModelHelper.validateListBlobsOptions(options);
BiFunction<String, Integer, PagedResponse<BlobItem>> retriever = (nextMarker, pageSize) -> {
ListBlobsOptions finalOptions = new ListBlobsOptions();
if (options != null) {
finalOptions.setMaxResultsPerPage(options.getMaxResultsPerPage())
.setPrefix(options.getPrefix())
.setStartFrom(options.getStartFrom())
.setDetails(options.getDetails());

if (options.getStorageResponseSerializationFormat() == StorageResponseSerializationFormat.ARROW) {
finalOptions.setStorageResponseSerializationFormat(StorageResponseSerializationFormat.ARROW)
.setEndBefore(options.getEndBefore());
}

}
ListBlobsOptions finalOptions = ModelHelper.copyListBlobsOptions(options);
ModelHelper.applyDefaultsToListBlobsOptions(finalOptions);
/*
If pageSize was not set in a .byPage(int) method, the page size from options will be preserved.
Otherwise, prefer the new value.
Expand Down Expand Up @@ -1230,18 +1219,8 @@ public PagedIterable<BlobItem> listBlobsByHierarchy(String directory) {
public PagedIterable<BlobItem> listBlobsByHierarchy(String delimiter, ListBlobsOptions options, Duration timeout) {
ModelHelper.validateListBlobsOptions(options);
BiFunction<String, Integer, PagedResponse<BlobItem>> func = (marker, pageSize) -> {
ListBlobsOptions finalOptions = new ListBlobsOptions();
if (options != null) {
finalOptions.setMaxResultsPerPage(options.getMaxResultsPerPage())
.setPrefix(options.getPrefix())
.setDetails(options.getDetails())
.setStartFrom(options.getStartFrom());
if (ModelHelper.resolveSerializationFormat(options.getStorageResponseSerializationFormat())
== StorageResponseSerializationFormat.ARROW) {
finalOptions.setStorageResponseSerializationFormat(StorageResponseSerializationFormat.ARROW)
.setEndBefore(options.getEndBefore());
}
}
ListBlobsOptions finalOptions = ModelHelper.copyListBlobsOptions(options);
ModelHelper.applyDefaultsToListBlobsOptions(finalOptions);
/*
If pageSize was not set in a .byPage(int) method, the page size from options will be preserved.
Otherwise, prefer the new value.
Expand All @@ -1263,8 +1242,7 @@ private PagedResponse<BlobItem> listBlobsHierarchySegment(String marker, String
ArrayList<ListBlobsIncludeItem> include
= options.getDetails().toList().isEmpty() ? null : options.getDetails().toList();

if (ModelHelper.resolveSerializationFormat(options.getStorageResponseSerializationFormat())
== StorageResponseSerializationFormat.ARROW) {
if (options.getStorageResponseSerializationFormat() == StorageResponseSerializationFormat.ARROW) {
Callable<ResponseBase<ContainersListBlobHierarchySegmentApacheArrowHeaders, InputStream>> operation
= () -> azureBlobStorage.getContainers()
.listBlobHierarchySegmentApacheArrowWithResponse(containerName, delimiter, options.getPrefix(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public final class ModelHelper {
* but it is not a public API change.
*/
private static final StorageResponseSerializationFormat DEFAULT_SERIALIZATION_FORMAT
= StorageResponseSerializationFormat.XML;
= StorageResponseSerializationFormat.ARROW;

/**
* Determines whether the passed authority is IP style, that is, it is of the format {@code <host>:<port>}.
Expand Down Expand Up @@ -689,6 +689,34 @@ public static BlobStorageException mapToBlobStorageException(BlobStorageExceptio
return format;
}

/**
* Copies list blobs options.
*
* @param options the listing options to copy, or {@code null}.
* @return the copied options.
*/
public static ListBlobsOptions copyListBlobsOptions(ListBlobsOptions options) {
if (options == null) {
return new ListBlobsOptions();
}
return new ListBlobsOptions().setMaxResultsPerPage(options.getMaxResultsPerPage())
.setPrefix(options.getPrefix())
.setStartFrom(options.getStartFrom())
.setEndBefore(options.getEndBefore())
.setDetails(options.getDetails())
.setStorageResponseSerializationFormat(options.getStorageResponseSerializationFormat());
}

/**
* Replaces the requested serialization format with the concrete wire format.
*
* @param options the listing options to update.
*/
public static void applyDefaultsToListBlobsOptions(ListBlobsOptions options) {
options.setStorageResponseSerializationFormat(
resolveSerializationFormat(options.getStorageResponseSerializationFormat()));
}

/**
* Validates that {@code endBefore}, when specified, is used with the Apache Arrow response format.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.storage.blob;

import com.azure.core.http.HttpHeaderName;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.HttpPipelineBuilder;
import com.azure.core.test.http.MockHttpResponse;
import com.azure.core.test.utils.MockTokenCredential;
import com.azure.storage.blob.models.BlobStorageException;
import com.azure.storage.blob.models.ListBlobsOptions;
import com.azure.storage.blob.models.StorageResponseSerializationFormat;
import com.azure.storage.common.implementation.Constants;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import reactor.core.publisher.Mono;

import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class BlobContainerAsyncClientTests {
private AtomicReference<String> acceptHeader;
private BlobContainerAsyncClient client;

@BeforeEach
public void setup() {
acceptHeader = new AtomicReference<>();
HttpPipeline pipeline = new HttpPipelineBuilder().httpClient(request -> {
acceptHeader.set(request.getHeaders().getValue(HttpHeaderName.ACCEPT));
// Fail after capturing the request so the test doesn't need a format-specific response body.
return Mono.just(new MockHttpResponse(request, 500));
}).build();
client = new BlobContainerClientBuilder().endpoint("https://account.blob.core.windows.net/container")
.credential(new MockTokenCredential())
.pipeline(pipeline)
.buildAsyncClient();
}

@ParameterizedTest
@MethodSource("serializationFormatSupplier")
public void listBlobsUsesResolvedSerializationFormat(ListBlobsOptions options, String expectedAcceptHeader) {
sendRequest(() -> client.listBlobs(options).byPage(1).blockFirst());
assertEquals(expectedAcceptHeader, acceptHeader.get());
}

@ParameterizedTest
@MethodSource("serializationFormatSupplier")
public void listBlobsByHierarchyUsesResolvedSerializationFormat(ListBlobsOptions options,
String expectedAcceptHeader) {
sendRequest(() -> client.listBlobsByHierarchy("/", options).byPage(1).blockFirst());
assertEquals(expectedAcceptHeader, acceptHeader.get());
}

private static void sendRequest(Supplier<?> request) {
try {
request.get();
} catch (BlobStorageException exception) {
if (exception.getStatusCode() != 500) {
throw exception;
}
}
}

private static Stream<Arguments> serializationFormatSupplier() {
String arrowAcceptHeader
= Constants.ContentTypeConstants.APPLICATION_VND_APACHE_ARROW_STREAM + ",application/xml";
return Stream.of(Arguments.of(null, arrowAcceptHeader), Arguments.of(new ListBlobsOptions(), arrowAcceptHeader),
Arguments.of(
new ListBlobsOptions().setStorageResponseSerializationFormat(StorageResponseSerializationFormat.AUTO),
arrowAcceptHeader),
Arguments.of(
new ListBlobsOptions().setStorageResponseSerializationFormat(StorageResponseSerializationFormat.ARROW),
arrowAcceptHeader),
Arguments.of(
new ListBlobsOptions().setStorageResponseSerializationFormat(StorageResponseSerializationFormat.XML),
"application/xml"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.storage.blob;

import com.azure.core.http.HttpHeaderName;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.HttpPipelineBuilder;
import com.azure.core.test.http.MockHttpResponse;
import com.azure.core.test.utils.MockTokenCredential;
import com.azure.storage.blob.models.BlobStorageException;
import com.azure.storage.blob.models.ListBlobsOptions;
import com.azure.storage.blob.models.StorageResponseSerializationFormat;
import com.azure.storage.common.implementation.Constants;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import reactor.core.publisher.Mono;

import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class BlobContainerClientTests {
private AtomicReference<String> acceptHeader;
private BlobContainerClient client;

@BeforeEach
public void setup() {
acceptHeader = new AtomicReference<>();
HttpPipeline pipeline = new HttpPipelineBuilder().httpClient(request -> {
acceptHeader.set(request.getHeaders().getValue(HttpHeaderName.ACCEPT));
// Fail after capturing the request so the test doesn't need a format-specific response body.
return Mono.just(new MockHttpResponse(request, 500));
}).build();
client = new BlobContainerClientBuilder().endpoint("https://account.blob.core.windows.net/container")
.credential(new MockTokenCredential())
.pipeline(pipeline)
.buildClient();
}

@ParameterizedTest
@MethodSource("serializationFormatSupplier")
public void listBlobsUsesResolvedSerializationFormat(ListBlobsOptions options, String expectedAcceptHeader) {
sendRequest(() -> client.listBlobs(options, null).iterableByPage(1).iterator().hasNext());
assertEquals(expectedAcceptHeader, acceptHeader.get());
}

@ParameterizedTest
@MethodSource("serializationFormatSupplier")
public void listBlobsByHierarchyUsesResolvedSerializationFormat(ListBlobsOptions options,
String expectedAcceptHeader) {
sendRequest(() -> client.listBlobsByHierarchy("/", options, null).iterableByPage(1).iterator().hasNext());
assertEquals(expectedAcceptHeader, acceptHeader.get());
}

private static void sendRequest(Supplier<?> request) {
try {
request.get();
} catch (BlobStorageException exception) {
if (exception.getStatusCode() != 500) {
throw exception;
}
}
}

private static Stream<Arguments> serializationFormatSupplier() {
String arrowAcceptHeader
= Constants.ContentTypeConstants.APPLICATION_VND_APACHE_ARROW_STREAM + ",application/xml";
return Stream.of(Arguments.of(null, arrowAcceptHeader), Arguments.of(new ListBlobsOptions(), arrowAcceptHeader),
Arguments.of(
new ListBlobsOptions().setStorageResponseSerializationFormat(StorageResponseSerializationFormat.AUTO),
arrowAcceptHeader),
Arguments.of(
new ListBlobsOptions().setStorageResponseSerializationFormat(StorageResponseSerializationFormat.ARROW),
arrowAcceptHeader),
Arguments.of(
new ListBlobsOptions().setStorageResponseSerializationFormat(StorageResponseSerializationFormat.XML),
"application/xml"));
}
}

This file was deleted.

Loading
Loading