Skip to content

Commit

Permalink
Add block blob api test
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghaolu committed Jun 11, 2019
1 parent 1bd0424 commit bc8b084
Show file tree
Hide file tree
Showing 15 changed files with 3,069 additions and 2,029 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static BlobServiceClientBuilder builder() {
public ContainerAsyncClient createContainerAsyncClient(String containerName) {
AzureBlobStorageImpl azureBlobStorage = blobServiceAsyncRawClient.azureBlobStorage;
UrlBuilder urlBuilder = UrlBuilder.parse(azureBlobStorage.url());
urlBuilder.withPath(urlBuilder.path() + "/" + containerName);
urlBuilder.withPath("/" + containerName);
return new ContainerAsyncClient(new AzureBlobStorageBuilder()
.url(urlBuilder.toString())
.pipeline(azureBlobStorage.httpPipeline())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static BlobServiceClientBuilder builder() {
public ContainerClient createContainerClient(String containerName) {
AzureBlobStorageImpl azureBlobStorage = blobServiceAsyncClient.blobServiceAsyncRawClient.azureBlobStorage;
UrlBuilder urlBuilder = UrlBuilder.parse(azureBlobStorage.url());
urlBuilder.withPath(urlBuilder.path() + "/" + containerName);
urlBuilder.withPath("/" + containerName);
return new ContainerClient(new AzureBlobStorageBuilder()
.url(urlBuilder.toString())
.pipeline(azureBlobStorage.httpPipeline())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.azure.core.implementation.util.ImplUtils;
import com.azure.storage.blob.implementation.AzureBlobStorageBuilder;
import com.azure.storage.blob.implementation.AzureBlobStorageImpl;
import com.azure.storage.common.credential.SharedKeyCredential;

import java.net.MalformedURLException;
import java.net.URL;
Expand All @@ -36,6 +37,7 @@ public final class BlobServiceClientBuilder {

private URL endpoint;
private ICredentials credentials = new AnonymousCredentials();
private SharedKeyCredential sharedKeyCredential;
private HttpClient httpClient;
private HttpLogDetailLevel logLevel;
private RetryPolicy retryPolicy;
Expand Down Expand Up @@ -107,8 +109,8 @@ public BlobServiceClientBuilder endpoint(String endpoint) {
* @param credentials authorization credentials
* @return the updated BlobServiceClientBuilder object
*/
public BlobServiceClientBuilder credentials(SharedKeyCredentials credentials) {
this.credentials = credentials;
public BlobServiceClientBuilder credentials(SharedKeyCredential credentials) {
this.sharedKeyCredential = sharedKeyCredential;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public final class BlobServiceRawClient {
* [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=service_url "Sample code for ServiceURL constructor")] \n
* For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java)
*/
public BlobServiceRawClient(AzureBlobStorageBuilder azureBlobStorageBuilder) {
this.blobServiceAsyncRawClient = new BlobServiceAsyncRawClient(azureBlobStorageBuilder);
public BlobServiceRawClient(AzureBlobStorageImpl azureBlobStorage) {
this.blobServiceAsyncRawClient = new BlobServiceAsyncRawClient(azureBlobStorage);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import com.azure.storage.blob.implementation.AzureBlobStorageImpl;
import com.azure.storage.blob.models.BlobHTTPHeaders;
import com.azure.storage.blob.models.BlockBlobCommitBlockListHeaders;
import com.azure.storage.blob.models.BlockBlobGetBlockListHeaders;
import com.azure.storage.blob.models.BlockBlobUploadHeaders;
import com.azure.storage.blob.models.BlockItem;
import com.azure.storage.blob.models.BlockListType;
import com.azure.storage.blob.models.LeaseAccessConditions;
import com.azure.storage.blob.models.SourceModifiedAccessConditions;
Expand Down Expand Up @@ -278,8 +278,8 @@ public Mono<Void> stageBlockFromURL(String base64BlockID, URL sourceURL,
* @return
* A reactive response containing the list of blocks.
*/
public Mono<BlockBlobGetBlockListHeaders> getBlockList(BlockListType listType) {
return this.getBlockList(listType, null, null);
public Flux<BlockItem> listBlocks(BlockListType listType) {
return this.listBlocks(listType, null, null);
}

/**
Expand All @@ -303,11 +303,18 @@ public Mono<BlockBlobGetBlockListHeaders> getBlockList(BlockListType listType) {
* @return
* A reactive response containing the list of blocks.
*/
public Mono<BlockBlobGetBlockListHeaders> getBlockList(BlockListType listType,
LeaseAccessConditions leaseAccessConditions, Context context) {
public Flux<BlockItem> listBlocks(BlockListType listType,
LeaseAccessConditions leaseAccessConditions, Context context) {
return blockBlobAsyncRawClient
.getBlockList(listType, leaseAccessConditions, context)
.map(ResponseBase::deserializedHeaders);
.listBlocks(listType, leaseAccessConditions, context)
.map(ResponseBase::value)
.flatMapMany(bl -> {
Flux<BlockItem> committed = Flux.fromIterable(bl.committedBlocks())
.map(block -> new BlockItem(block, true));
Flux<BlockItem> uncommitted = Flux.fromIterable(bl.uncommittedBlocks())
.map(block -> new BlockItem(block, false));
return Flux.concat(committed, uncommitted);
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@

import com.azure.core.http.HttpPipeline;
import com.azure.core.util.Context;
import com.azure.storage.blob.implementation.AzureBlobStorageBuilder;
import com.azure.storage.blob.implementation.AzureBlobStorageImpl;
import com.azure.storage.blob.implementation.BlockBlobsImpl;
import com.azure.storage.blob.models.*;
import io.netty.buffer.ByteBuf;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.List;

import static com.azure.storage.blob.Utility.postProcessResponse;
Expand Down Expand Up @@ -289,11 +285,11 @@ public Mono<BlockBlobsStageBlockFromURLResponse> stageBlockFromURL(String base64
* @return Emits the successful response.
*
* @apiNote ## Sample Code \n
* [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobAsyncRawClient.getBlockList")] \n
* [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobAsyncRawClient.listBlocks")] \n
* For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java)
*/
public Mono<BlockBlobsGetBlockListResponse> getBlockList(BlockListType listType) {
return this.getBlockList(listType, null, null);
public Mono<BlockBlobsGetBlockListResponse> listBlocks(BlockListType listType) {
return this.listBlocks(listType, null, null);
}

/**
Expand All @@ -316,11 +312,11 @@ public Mono<BlockBlobsGetBlockListResponse> getBlockList(BlockListType listType)
* @return Emits the successful response.
*
* @apiNote ## Sample Code \n
* [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobAsyncRawClient.getBlockList")] \n
* [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobAsyncRawClient.listBlocks")] \n
* For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java)
*/
public Mono<BlockBlobsGetBlockListResponse> getBlockList(BlockListType listType,
LeaseAccessConditions leaseAccessConditions, Context context) {
public Mono<BlockBlobsGetBlockListResponse> listBlocks(BlockListType listType,
LeaseAccessConditions leaseAccessConditions, Context context) {
context = context == null ? Context.NONE : context;

return postProcessResponse(this.azureBlobStorage.blockBlobs().getBlockListWithRestResponseAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import com.azure.storage.blob.implementation.AzureBlobStorageImpl;
import com.azure.storage.blob.models.BlobHTTPHeaders;
import com.azure.storage.blob.models.BlockBlobCommitBlockListHeaders;
import com.azure.storage.blob.models.BlockBlobGetBlockListHeaders;
import com.azure.storage.blob.models.BlockBlobUploadHeaders;
import com.azure.storage.blob.models.BlockItem;
import com.azure.storage.blob.models.BlockListType;
import com.azure.storage.blob.models.LeaseAccessConditions;
import com.azure.storage.blob.models.SourceModifiedAccessConditions;
Expand Down Expand Up @@ -269,8 +269,8 @@ public void stageBlockFromURL(String base64BlockID, URL sourceURL,
* @return
* The list of blocks.
*/
public BlockBlobGetBlockListHeaders getBlockList(BlockListType listType) {
return this.getBlockList(listType, null, null, null);
public Iterable<BlockItem> listBlocks(BlockListType listType) {
return this.listBlocks(listType, null, null, null);
}

/**
Expand All @@ -296,13 +296,13 @@ public BlockBlobGetBlockListHeaders getBlockList(BlockListType listType) {
* @return
* The list of blocks.
*/
public BlockBlobGetBlockListHeaders getBlockList(BlockListType listType,
LeaseAccessConditions leaseAccessConditions, Duration timeout, Context context) {
Mono<BlockBlobGetBlockListHeaders> response = blockBlobAsyncClient.getBlockList(listType, leaseAccessConditions, context);
public Iterable<BlockItem> listBlocks(BlockListType listType,
LeaseAccessConditions leaseAccessConditions, Duration timeout, Context context) {
Flux<BlockItem> response = blockBlobAsyncClient.listBlocks(listType, leaseAccessConditions, context);

return timeout == null?
response.block():
response.block(timeout);
response.toIterable():
response.timeout(timeout).toIterable();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@

import com.azure.core.http.HttpPipeline;
import com.azure.core.util.Context;
import com.azure.storage.blob.implementation.AzureBlobStorageBuilder;
import com.azure.storage.blob.implementation.AzureBlobStorageImpl;
import com.azure.storage.blob.models.*;
import io.netty.buffer.ByteBuf;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.net.URL;
import java.nio.ByteBuffer;
import java.time.Duration;
import java.util.List;

Expand Down Expand Up @@ -277,7 +275,7 @@ public BlockBlobsStageBlockFromURLResponse stageBlockFromURL(String base64BlockI
* @return Emits the successful response.
*
* @apiNote ## Sample Code \n
* [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobAsyncRawClient.getBlockList")] \n
* [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobAsyncRawClient.listBlocks")] \n
* For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java)
*/
public BlockBlobsGetBlockListResponse getBlockList(BlockListType listType) {
Expand All @@ -304,12 +302,12 @@ public BlockBlobsGetBlockListResponse getBlockList(BlockListType listType) {
* @return Emits the successful response.
*
* @apiNote ## Sample Code \n
* [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobAsyncRawClient.getBlockList")] \n
* [!code-java[Sample_Code](../azure-storage-java/src/test/java/com/microsoft/azure/storage/Samples.java?name=blocks "Sample code for BlockBlobAsyncRawClient.listBlocks")] \n
* For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java)
*/
public BlockBlobsGetBlockListResponse getBlockList(BlockListType listType,
LeaseAccessConditions leaseAccessConditions, Duration timeout, Context context) {
Mono<BlockBlobsGetBlockListResponse> response = blockBlobAsyncRawClient.getBlockList(listType, leaseAccessConditions, context);
Mono<BlockBlobsGetBlockListResponse> response = blockBlobAsyncRawClient.listBlocks(listType, leaseAccessConditions, context);
return timeout == null?
response.block():
response.block(timeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.azure.core.http.rest.ResponseBase;

/**
* Contains all response data for the getBlockList operation.
* Contains all response data for the listBlocks operation.
*/
public final class BlockBlobsGetBlockListResponse extends ResponseBase<BlockBlobGetBlockListHeaders, BlockList> {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.storage.blob.models;

/**
* Represents a single block in a block blob.
*/
public final class BlockItem {
/* Internal block object. */
private Block block;

private boolean isCommitted;

/**
* Creates an instance of a BlobItem.
* @param block the API blob object
* @param isCommitted if the blob is committed
*/
public BlockItem(Block block, boolean isCommitted) {
this.block = block;
this.isCommitted = isCommitted;
}

/**
* @return the base64 encoded block ID.
*/
public String name() {
return this.block.name();
}

/**
* @return the block size in bytes.
*/
public int size() {
return this.block.size();
}

/**
* @return if the block has been committed.
*/
public boolean isCommitted() {
return isCommitted;
}
}
Loading

0 comments on commit bc8b084

Please sign in to comment.