Skip to content

Commit

Permalink
Replace magic string with boolean options
Browse files Browse the repository at this point in the history
Issue Azure#43
  • Loading branch information
Renaud Paquay committed Nov 19, 2011
1 parent 323b733 commit d736a73
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,15 @@ public ListBlobBlocksResult listBlobBlocks(String container, String blob, ListBl
throws ServiceException {
WebResource webResource = getResource(options).path(container).path(blob).queryParam("comp", "blocklist");
webResource = addOptionalQueryParam(webResource, "snapshot", options.getSnapshot());
webResource = addOptionalQueryParam(webResource, "blocklisttype", options.getListType());
if (options.isCommittedList() && options.isUncommittedList()) {
webResource = addOptionalQueryParam(webResource, "blocklisttype", "all");
}
else if (options.isCommittedList()) {
webResource = addOptionalQueryParam(webResource, "blocklisttype", "committed");
}
else if (options.isUncommittedList()) {
webResource = addOptionalQueryParam(webResource, "blocklisttype", "uncommitted");
}

Builder builder = webResource.header("x-ms-version", API_VERSION);
builder = addOptionalHeader(builder, "x-ms-lease-id", options.getLeaseId());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.microsoft.windowsazure.services.blob.models;


public class ListBlobBlocksOptions extends BlobServiceOptions {
private String leaseId;
private String snapshot;
private String listType; // "committed", "uncommitted", "all"
private boolean committedList;
private boolean uncommittedList;

public String getLeaseId() {
return leaseId;
Expand All @@ -24,12 +24,21 @@ public ListBlobBlocksOptions setSnapshot(String snapshot) {
return this;
}

public String getListType() {
return listType;
public boolean isCommittedList() {
return committedList;
}

public ListBlobBlocksOptions setCommittedList(boolean committedList) {
this.committedList = committedList;
return this;
}

public boolean isUncommittedList() {
return uncommittedList;
}

public ListBlobBlocksOptions setListType(String listType) {
this.listType = listType;
public ListBlobBlocksOptions setUncommittedList(boolean uncommittedList) {
this.uncommittedList = uncommittedList;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,8 @@ public void listBlobBlocksWorks() throws Exception {
service.createBlobBlock(container, blob, "124", new ByteArrayInputStream(new byte[512]));
service.createBlobBlock(container, blob, "125", new ByteArrayInputStream(new byte[195]));

ListBlobBlocksResult result = service.listBlobBlocks(container, blob,
new ListBlobBlocksOptions().setListType("all"));
ListBlobBlocksResult result = service.listBlobBlocks(container, blob, new ListBlobBlocksOptions()
.setCommittedList(true).setUncommittedList(true));

// Assert
assertNotNull(result);
Expand All @@ -758,6 +758,43 @@ public void listBlobBlocksWorks() throws Exception {
assertEquals(195, result.getUncommittedBlocks().get(2).getBlockLength());
}

@Test
public void listBlobBlocksWithOptionsWorks() throws Exception {
// Arrange
Configuration config = createConfiguration();
BlobContract service = config.create(BlobContract.class);

// Act
String container = TEST_CONTAINER_FOR_BLOBS;
String blob = "test14";
service.createBlockBlob(container, blob, null);
service.createBlobBlock(container, blob, "123", new ByteArrayInputStream(new byte[256]));

BlockList blockList = new BlockList();
blockList.addUncommittedEntry("123");
service.commitBlobBlocks(container, blob, blockList);

service.createBlobBlock(container, blob, "124", new ByteArrayInputStream(new byte[512]));
service.createBlobBlock(container, blob, "125", new ByteArrayInputStream(new byte[195]));

ListBlobBlocksResult result1 = service.listBlobBlocks(container, blob, new ListBlobBlocksOptions()
.setCommittedList(true).setUncommittedList(true));
ListBlobBlocksResult result2 = service.listBlobBlocks(container, blob,
new ListBlobBlocksOptions().setCommittedList(true));
ListBlobBlocksResult result3 = service.listBlobBlocks(container, blob,
new ListBlobBlocksOptions().setUncommittedList(true));

// Assert
assertEquals(1, result1.getCommittedBlocks().size());
assertEquals(2, result1.getUncommittedBlocks().size());

assertEquals(1, result2.getCommittedBlocks().size());
assertEquals(0, result2.getUncommittedBlocks().size());

assertEquals(0, result3.getCommittedBlocks().size());
assertEquals(2, result3.getUncommittedBlocks().size());
}

@Test
public void commitBlobBlocksWorks() throws Exception {
// Arrange
Expand All @@ -779,8 +816,8 @@ public void commitBlobBlocksWorks() throws Exception {
blockList.addUncommittedEntry(blockId1).addLatestEntry(blockId3);
service.commitBlobBlocks(container, blob, blockList);

ListBlobBlocksResult result = service.listBlobBlocks(container, blob,
new ListBlobBlocksOptions().setListType("all"));
ListBlobBlocksResult result = service.listBlobBlocks(container, blob, new ListBlobBlocksOptions()
.setCommittedList(true).setUncommittedList(true));

// Assert
assertNotNull(result);
Expand Down

0 comments on commit d736a73

Please sign in to comment.