Skip to content

Commit

Permalink
Merge pull request Azure#121 from asorrin-msft/dev
Browse files Browse the repository at this point in the history
Fixing bug in getShareQuota and removing unnecessary code.
  • Loading branch information
pemari-msft authored Sep 8, 2016
2 parents 39c5b4e + 0a1e903 commit 3261b62
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,25 +288,40 @@ public void testCloudFileSharePermissionsToString() {
*/
@Test
public void testCloudFileShareUploadMetadata() throws StorageException, URISyntaxException {
this.share.getMetadata().put("key1", "value1");
this.share.create();
Assert.assertEquals(1, this.share.getMetadata().size());
Assert.assertEquals("value1", this.share.getMetadata().get("key1"));

CloudFileShare share2 = this.share.getServiceClient().getShareReference(this.share.getName());
share2.downloadAttributes();
Assert.assertEquals(0, share2.getMetadata().size());
Assert.assertEquals(1, share2.getMetadata().size());
Assert.assertEquals("value1", share2.getMetadata().get("key1"));

this.share.getMetadata().put("key1", "value1");
this.share.getMetadata().put("key2", "value2");

Assert.assertEquals(2, this.share.getMetadata().size());
Assert.assertEquals("value1", this.share.getMetadata().get("key1"));
Assert.assertEquals("value2", this.share.getMetadata().get("key2"));
this.share.uploadMetadata();

Assert.assertEquals(2, this.share.getMetadata().size());
Assert.assertEquals("value1", this.share.getMetadata().get("key1"));
Assert.assertEquals("value2", this.share.getMetadata().get("key2"));

share2.downloadAttributes();
Assert.assertEquals(1, share2.getMetadata().size());
Assert.assertEquals("value1", share2.getMetadata().get("key1"));

Assert.assertEquals(2, this.share.getMetadata().size());
Assert.assertEquals("value1", this.share.getMetadata().get("key1"));
Assert.assertEquals("value2", this.share.getMetadata().get("key2"));

Iterable<CloudFileShare> shares = this.share.getServiceClient().listShares(this.share.getName(),
ShareListingDetails.METADATA, null, null);

for (CloudFileShare share3 : shares) {
Assert.assertEquals(1, share3.getMetadata().size());
Assert.assertEquals(2, share3.getMetadata().size());
Assert.assertEquals("value1", share3.getMetadata().get("key1"));
Assert.assertEquals("value2", this.share.getMetadata().get("key2"));
}

this.share.getMetadata().clear();
Expand Down Expand Up @@ -402,6 +417,8 @@ public void testCloudFileShareQuota() throws StorageException, URISyntaxExceptio
this.share = FileTestHelper.getRandomShareReference();
this.share.getProperties().setShareQuota(shareQuota);
this.share.create();
assertNotNull(this.share.getProperties().getShareQuota());
assertEquals(shareQuota, this.share.getProperties().getShareQuota().intValue());
this.share.downloadAttributes();
assertNotNull(this.share.getProperties().getShareQuota());
assertEquals(shareQuota, this.share.getProperties().getShareQuota().intValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,12 @@ public Void preProcessResponse(CloudFileShare share, CloudFileClient client, Ope
// Set attributes
final FileShareAttributes attributes = FileResponse.getFileShareAttributes(this.getConnection(),
client.isUsePathStyleUris());

// The response from the service does not include the share quota.
// Instead, we keep the existing value.
Integer oldShareQuota = share.properties.getShareQuota();
share.properties = attributes.getProperties();
share.name = attributes.getName();
share.properties.setShareQuota(oldShareQuota);
return null;
}
};
Expand Down Expand Up @@ -519,7 +523,6 @@ public Void preProcessResponse(CloudFileShare share, CloudFileClient client, Ope
client.isUsePathStyleUris());
share.metadata = attributes.getMetadata();
share.properties = attributes.getProperties();
share.name = attributes.getName();
return null;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,6 @@ public static CopyState getCopyState(final HttpURLConnection request) throws URI
public static FileShareAttributes getFileShareAttributes(final HttpURLConnection request,
final boolean usePathStyleUris) throws StorageException {
final FileShareAttributes shareAttributes = new FileShareAttributes();
URI tempURI;
try {
tempURI = PathUtility.stripSingleURIQueryAndFragment(request.getURL().toURI());
}
catch (final URISyntaxException e) {
final StorageException wrappedUnexpectedException = Utility.generateNewUnexpectedStorageException(e);
throw wrappedUnexpectedException;
}

shareAttributes.setName(PathUtility.getShareNameFromUri(tempURI, usePathStyleUris));

final FileShareProperties shareProperties = shareAttributes.getProperties();
shareProperties.setEtag(BaseResponse.getEtag(request));
shareProperties.setShareQuota(parseShareQuota(request));
Expand Down

0 comments on commit 3261b62

Please sign in to comment.