Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Commit e3ec15c

Browse files
author
Josh Friedman
committed
Share snapshot support
1 parent ef71e25 commit e3ec15c

File tree

12 files changed

+801
-722
lines changed

12 files changed

+801
-722
lines changed

BreakingChanges.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
Changes in 5.1.1
1+
Changes in 6.0.0
2+
3+
FILE
4+
* CloudFileShare constructor now takes a snapshotID String which can be null.
5+
6+
* FileRequest get methods now takes a snapshotID String which can be null.
7+
8+
* Changed listShares() ShareListingDetails parameter to be an enum set like what is done for listing blobs.
9+
10+
Changes in 5.1.1
211
OTHER
312
* Reverted the code from 5.1.0 because it contained a regression and an accidental change.
413

ChangeLog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2017.XX.XX Version 6.0.0
2+
* Added support for taking a snapshot of a share.
3+
14
2017.08.28 Version 5.5.0
25
* Fixed a bug when using a SAS token where the token was being omitted from calls to delete a directory in the file service.
36
* For Standard Storage Accounts only, added the ability to set the tier of individual block blobs. The tier can currently only be set through uploadTier()

microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileClientTests.java

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -115,46 +115,46 @@ public void testListSharesMaxResultsValidationTest() throws StorageException, UR
115115
assertNotNull(fileClient.listSharesSegmented("thereshouldntbeanyshareswiththisprefix"));
116116
}
117117

118-
// @Test
119-
// public void testListSharesWithSnapshot() throws StorageException, URISyntaxException {
120-
// CloudFileClient fileClient = FileTestHelper.createCloudFileClient();
121-
// CloudFileShare share = fileClient.getShareReference(UUID.randomUUID().toString());
122-
// share.create();
123-
//
124-
// HashMap<String, String> shareMeta = new HashMap<String, String>();
125-
// shareMeta.put("key1", "value1");
126-
// share.setMetadata(shareMeta);
127-
// share.uploadMetadata();
128-
//
129-
// CloudFileShare snapshot = share.createSnapshot();
130-
// HashMap<String, String> meta2 = new HashMap<String, String>();
131-
// meta2.put("key2", "value2");
132-
// share.setMetadata(meta2);
133-
// share.uploadMetadata();
134-
//
135-
// CloudFileClient client = FileTestHelper.createCloudFileClient();
136-
// Iterable<CloudFileShare> listResult = client.listShares(share.name, ShareListingDetails.ALL, null, null);
137-
//
138-
// int count = 0;
139-
// boolean originalFound = false;
140-
// boolean snapshotFound = false;
141-
// for (CloudFileShare listShareItem : listResult) {
142-
// if (listShareItem.getName().equals(share.getName()) && !listShareItem.isSnapshot() && !originalFound)
143-
// {
144-
// count++;
145-
// originalFound = true;
146-
// assertEquals(share.getMetadata(), listShareItem.getMetadata());
147-
// assertEquals(share.getStorageUri(), listShareItem.getStorageUri());
148-
// }
149-
// else if (listShareItem.getName().equals(share.getName()) &&
150-
// listShareItem.isSnapshot() && !snapshotFound) {
151-
// count++;
152-
// snapshotFound = true;
153-
// assertEquals(snapshot.getMetadata(), listShareItem.getMetadata());
154-
// assertEquals(snapshot.getStorageUri(), listShareItem.getStorageUri());
155-
// }
156-
// }
157-
//
158-
// assertEquals(2, count);
159-
// }
118+
//@Test
119+
public void testListSharesWithSnapshot() throws StorageException, URISyntaxException {
120+
CloudFileClient fileClient = FileTestHelper.createCloudFileClient();
121+
CloudFileShare share = fileClient.getShareReference(UUID.randomUUID().toString());
122+
share.create();
123+
124+
HashMap<String, String> shareMeta = new HashMap<String, String>();
125+
shareMeta.put("key1", "value1");
126+
share.setMetadata(shareMeta);
127+
share.uploadMetadata();
128+
129+
CloudFileShare snapshot = share.createSnapshot();
130+
HashMap<String, String> meta2 = new HashMap<String, String>();
131+
meta2.put("key2", "value2");
132+
share.setMetadata(meta2);
133+
share.uploadMetadata();
134+
135+
CloudFileClient client = FileTestHelper.createCloudFileClient();
136+
Iterable<CloudFileShare> listResult = client.listShares(share.name, ShareListingDetails.ALL, null, null);
137+
138+
int count = 0;
139+
boolean originalFound = false;
140+
boolean snapshotFound = false;
141+
for (CloudFileShare listShareItem : listResult) {
142+
if (listShareItem.getName().equals(share.getName()) && !listShareItem.isSnapshot() && !originalFound)
143+
{
144+
count++;
145+
originalFound = true;
146+
assertEquals(share.getMetadata(), listShareItem.getMetadata());
147+
assertEquals(share.getStorageUri(), listShareItem.getStorageUri());
148+
}
149+
else if (listShareItem.getName().equals(share.getName()) &&
150+
listShareItem.isSnapshot() && !snapshotFound) {
151+
count++;
152+
snapshotFound = true;
153+
assertEquals(snapshot.getMetadata(), listShareItem.getMetadata());
154+
assertEquals(snapshot.getStorageUri(), listShareItem.getStorageUri());
155+
}
156+
}
157+
158+
assertEquals(2, count);
159+
}
160160
}

microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileDirectoryTests.java

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -480,70 +480,70 @@ private static void testMetadataFailures(CloudFileDirectory directory, String ke
480480
directory.getMetadata().remove(key);
481481
}
482482

483-
// @Test
484-
// public void testUnsupportedDirectoryApisWithinShareSnapshot() throws StorageException, URISyntaxException {
485-
// CloudFileShare snapshot = this.share.createSnapshot();
486-
// CloudFileDirectory rootDir = snapshot.getRootDirectoryReference();
487-
// try {
488-
// rootDir.create();
489-
// fail("Shouldn't get here");
490-
// }
491-
// catch (IllegalArgumentException e) {
492-
// assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage());
493-
// }
494-
// try {
495-
// rootDir.delete();
496-
// fail("Shouldn't get here");
497-
// }
498-
// catch (IllegalArgumentException e) {
499-
// assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage());
500-
// }
501-
// try {
502-
// rootDir.uploadMetadata();
503-
// fail("Shouldn't get here");
504-
// }
505-
// catch (IllegalArgumentException e) {
506-
// assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage());
507-
// }
508-
//
509-
// snapshot.delete();
510-
// }
511-
512-
// @Test
513-
// public void testSupportedDirectoryApisInShareSnapshot() throws StorageException, URISyntaxException {
514-
// CloudFileDirectory dir = this.share.getRootDirectoryReference().getDirectoryReference("dir1");
515-
// dir.deleteIfExists();
516-
// dir.create();
517-
// HashMap<String, String> meta = new HashMap<String, String>();
518-
// meta.put("key1", "value1");
519-
// dir.setMetadata(meta);
520-
// dir.uploadMetadata();
521-
// CloudFileShare snapshot = this.share.createSnapshot();
522-
// CloudFileDirectory snapshotDir = snapshot.getRootDirectoryReference().getDirectoryReference("dir1");
523-
//
524-
// HashMap<String, String> meta2 = new HashMap<String, String>();
525-
// meta2.put("key2", "value2");
526-
// dir.setMetadata(meta2);
527-
// dir.uploadMetadata();
528-
// snapshotDir.downloadAttributes();
529-
//
530-
// assertTrue(snapshotDir.getMetadata().size() == 1 && snapshotDir.getMetadata().get("key1").equals("value1"));
531-
// assertNotNull(snapshotDir.getProperties().getEtag());
532-
//
533-
// dir.downloadAttributes();
534-
// assertTrue(dir.getMetadata().size() == 1 && dir.getMetadata().get("key2").equals("value2"));
535-
// assertNotNull(dir.getProperties().getEtag());
536-
// assertNotEquals(dir.getProperties().getEtag(), snapshotDir.getProperties().getEtag());
537-
//
538-
// final UriQueryBuilder uriBuilder = new UriQueryBuilder();
539-
// uriBuilder.add("sharesnapshot", snapshot.snapshotID);
540-
// uriBuilder.add("restype", "directory");
541-
// CloudFileDirectory snapshotDir2 = new CloudFileDirectory(uriBuilder.addToURI(dir.getUri()), this.share.getServiceClient().getCredentials());
542-
// assertEquals(snapshot.snapshotID, snapshotDir2.getShare().snapshotID);
543-
// assertTrue(snapshotDir2.exists());
544-
//
545-
// snapshot.delete();
546-
// }
483+
//@Test
484+
public void testUnsupportedDirectoryApisWithinShareSnapshot() throws StorageException, URISyntaxException {
485+
CloudFileShare snapshot = this.share.createSnapshot();
486+
CloudFileDirectory rootDir = snapshot.getRootDirectoryReference();
487+
try {
488+
rootDir.create();
489+
fail("Shouldn't get here");
490+
}
491+
catch (IllegalArgumentException e) {
492+
assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage());
493+
}
494+
try {
495+
rootDir.delete();
496+
fail("Shouldn't get here");
497+
}
498+
catch (IllegalArgumentException e) {
499+
assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage());
500+
}
501+
try {
502+
rootDir.uploadMetadata();
503+
fail("Shouldn't get here");
504+
}
505+
catch (IllegalArgumentException e) {
506+
assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage());
507+
}
508+
509+
snapshot.delete();
510+
}
511+
512+
//@Test
513+
public void testSupportedDirectoryApisInShareSnapshot() throws StorageException, URISyntaxException {
514+
CloudFileDirectory dir = this.share.getRootDirectoryReference().getDirectoryReference("dir1");
515+
dir.deleteIfExists();
516+
dir.create();
517+
HashMap<String, String> meta = new HashMap<String, String>();
518+
meta.put("key1", "value1");
519+
dir.setMetadata(meta);
520+
dir.uploadMetadata();
521+
CloudFileShare snapshot = this.share.createSnapshot();
522+
CloudFileDirectory snapshotDir = snapshot.getRootDirectoryReference().getDirectoryReference("dir1");
523+
524+
HashMap<String, String> meta2 = new HashMap<String, String>();
525+
meta2.put("key2", "value2");
526+
dir.setMetadata(meta2);
527+
dir.uploadMetadata();
528+
snapshotDir.downloadAttributes();
529+
530+
assertTrue(snapshotDir.getMetadata().size() == 1 && snapshotDir.getMetadata().get("key1").equals("value1"));
531+
assertNotNull(snapshotDir.getProperties().getEtag());
532+
533+
dir.downloadAttributes();
534+
assertTrue(dir.getMetadata().size() == 1 && dir.getMetadata().get("key2").equals("value2"));
535+
assertNotNull(dir.getProperties().getEtag());
536+
assertNotEquals(dir.getProperties().getEtag(), snapshotDir.getProperties().getEtag());
537+
538+
final UriQueryBuilder uriBuilder = new UriQueryBuilder();
539+
uriBuilder.add("sharesnapshot", snapshot.snapshotID);
540+
uriBuilder.add("restype", "directory");
541+
CloudFileDirectory snapshotDir2 = new CloudFileDirectory(uriBuilder.addToURI(dir.getUri()), this.share.getServiceClient().getCredentials());
542+
assertEquals(snapshot.snapshotID, snapshotDir2.getShare().snapshotID);
543+
assertTrue(snapshotDir2.exists());
544+
545+
snapshot.delete();
546+
}
547547

548548
/*
549549
[TestMethod]
@@ -872,7 +872,7 @@ public void eventOccurred(SendingRequestEvent eventArg) {
872872
directory.delete();
873873
assertFalse(directory.exists());
874874
}
875-
catch (StorageException e) {
875+
catch (Exception e) {
876876
fail("Delete should succeed.");
877877
}
878878
}

0 commit comments

Comments
 (0)