Skip to content

Commit

Permalink
Merge pull request Azure#37 from jofriedm-msft/share_snapshot
Browse files Browse the repository at this point in the history
Share Snapshot Support
  • Loading branch information
erezvani1529 authored Feb 10, 2017
2 parents c4856ab + ae54acc commit 6c34612
Show file tree
Hide file tree
Showing 24 changed files with 1,191 additions and 151 deletions.
11 changes: 10 additions & 1 deletion BreakingChanges.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
Changes in 6.0.0

FILE
* Exists() calls on Shares and Directories now populates metadata. This was already being done for Files.
* CloudFileShare constructor now takes a snapshotID String which can be null.
* FileRequest get methods now takes a snapshotID String which can be null.
* Changed listShares() ShareListingDetails parameter to be an enum set like what is done for listing blobs.
* In CloudFileShareProperties, setShareQuota() no longer asserts in bounds. This check has been moved to create() and uploadProperties() in CloudFileShare.

Changes in 5.0.0

BLOB
* getQualifiedUri() has been deprecated. Please use getSnapshotQualifiedUri() instead. This new function will return the blob including the snapshot (if present) and no SAS token.
* getQualifiedStorageUri() has been deprecated. Please use getSnapshotQualifiedStorageUri() instead. This new function will return the blob including the snapshot (if present) and no SAS token.
* Fixed a bug where copying from a blob that included a SAS token and a snapshot did not use the SAS token.

FILE
FILE
* Fixed a bug where copying from a blob that included a SAS token and a snapshot did not use the SAS token.

QUEUE
Expand Down
4 changes: 4 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2017.XX.XX Version 6.0.0
* Added support for taking a snapshot of a share.
* Fixed Exists() calls on Shares and Directories to now populate metadata. This was already being done for Files.

2017.01.18 Version 5.0.0
* Prefix support for listing files and directories.
* Added support for setting public access when creating a blob container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.UUID;

import static org.junit.Assert.*;
Expand Down Expand Up @@ -64,8 +66,8 @@ public void testListSharesTest() throws StorageException, URISyntaxException {
ResultContinuation token = null;
do {

ResultSegment<CloudFileShare> segment = fileClient.listSharesSegmented(prefix, ShareListingDetails.ALL,
15, token, null, null);
ResultSegment<CloudFileShare> segment = fileClient.listSharesSegmented(prefix,
EnumSet.allOf(ShareListingDetails.class), 15, token, null, null);

for (final CloudFileShare share : segment.getResults()) {
share.downloadAttributes();
Expand Down Expand Up @@ -102,7 +104,7 @@ public void testListSharesMaxResultsValidationTest() throws StorageException, UR
for (int i = 0; i >= -2; i--) {
try{
fileClient.listSharesSegmented(
prefix, ShareListingDetails.ALL, i, null, null, null);
prefix, EnumSet.allOf(ShareListingDetails.class), i, null, null, null);
fail();
}
catch (IllegalArgumentException e) {
Expand All @@ -112,4 +114,47 @@ public void testListSharesMaxResultsValidationTest() throws StorageException, UR
}
assertNotNull(fileClient.listSharesSegmented("thereshouldntbeanyshareswiththisprefix"));
}

@Test
public void testListSharesWithSnapshot() throws StorageException, URISyntaxException {
CloudFileClient fileClient = FileTestHelper.createCloudFileClient();
CloudFileShare share = fileClient.getShareReference(UUID.randomUUID().toString());
share.create();

HashMap<String, String> shareMeta = new HashMap<String, String>();
shareMeta.put("key1", "value1");
share.setMetadata(shareMeta);
share.uploadMetadata();

CloudFileShare snapshot = share.createSnapshot();
HashMap<String, String> meta2 = new HashMap<String, String>();
meta2.put("key2", "value2");
share.setMetadata(meta2);
share.uploadMetadata();

CloudFileClient client = FileTestHelper.createCloudFileClient();
Iterable<CloudFileShare> listResult = client.listShares(share.name, EnumSet.allOf(ShareListingDetails.class), null, null);

int count = 0;
boolean originalFound = false;
boolean snapshotFound = false;
for (CloudFileShare listShareItem : listResult) {
if (listShareItem.getName().equals(share.getName()) && !listShareItem.isSnapshot() && !originalFound)
{
count++;
originalFound = true;
assertEquals(share.getMetadata(), listShareItem.getMetadata());
assertEquals(share.getStorageUri(), listShareItem.getStorageUri());
}
else if (listShareItem.getName().equals(share.getName()) &&
listShareItem.isSnapshot() && !snapshotFound) {
count++;
snapshotFound = true;
assertEquals(snapshot.getMetadata(), listShareItem.getMetadata());
assertEquals(snapshot.getStorageUri(), listShareItem.getStorageUri());
}
}

assertEquals(2, count);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
import com.microsoft.azure.storage.TestRunners.DevStoreTests;
import com.microsoft.azure.storage.core.PathUtility;
import com.microsoft.azure.storage.core.SR;
import com.microsoft.azure.storage.core.UriQueryBuilder;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;

import org.junit.After;
import org.junit.Assert;
Expand Down Expand Up @@ -460,7 +462,7 @@ public void testCloudFileDirectoryInvalidMetadata() throws StorageException, URI
testMetadataFailures(directory, "key1", "\n \t", false);
}

private static void testMetadataFailures(CloudFileDirectory directory, String key, String value, boolean badKey) {
private static void testMetadataFailures(CloudFileDirectory directory, String key, String value, boolean badKey) throws URISyntaxException {
directory.getMetadata().put(key, value);
try {
directory.uploadMetadata();
Expand All @@ -478,6 +480,71 @@ private static void testMetadataFailures(CloudFileDirectory directory, String ke
directory.getMetadata().remove(key);
}

@Test
public void testUnsupportedDirectoryApisWithinShareSnapshot() throws StorageException, URISyntaxException {
CloudFileShare snapshot = this.share.createSnapshot();
CloudFileDirectory rootDir = snapshot.getRootDirectoryReference();
try {
rootDir.create();
fail("Shouldn't get here");
}
catch (IllegalArgumentException e) {
assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage());
}
try {
rootDir.delete();
fail("Shouldn't get here");
}
catch (IllegalArgumentException e) {
assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage());
}
try {
rootDir.uploadMetadata();
fail("Shouldn't get here");
}
catch (IllegalArgumentException e) {
assertEquals(SR.INVALID_OPERATION_FOR_A_SHARE_SNAPSHOT, e.getMessage());
}

snapshot.delete();
}

@Test
public void testSupportedDirectoryApisInShareSnapshot() throws StorageException, URISyntaxException {
CloudFileDirectory dir = this.share.getRootDirectoryReference().getDirectoryReference("dir1");
dir.deleteIfExists();
dir.create();
HashMap<String, String> meta = new HashMap<String, String>();
meta.put("key1", "value1");
dir.setMetadata(meta);
dir.uploadMetadata();
CloudFileShare snapshot = this.share.createSnapshot();
CloudFileDirectory snapshotDir = snapshot.getRootDirectoryReference().getDirectoryReference("dir1");

HashMap<String, String> meta2 = new HashMap<String, String>();
meta2.put("key2", "value2");
dir.setMetadata(meta2);
dir.uploadMetadata();
snapshotDir.downloadAttributes();

assertTrue(snapshotDir.getMetadata().size() == 1 && snapshotDir.getMetadata().get("key1").equals("value1"));
assertNotNull(snapshotDir.getProperties().getEtag());

dir.downloadAttributes();
assertTrue(dir.getMetadata().size() == 1 && dir.getMetadata().get("key2").equals("value2"));
assertNotNull(dir.getProperties().getEtag());
assertNotEquals(dir.getProperties().getEtag(), snapshotDir.getProperties().getEtag());

final UriQueryBuilder uriBuilder = new UriQueryBuilder();
uriBuilder.add("sharesnapshot", snapshot.snapshotID);
uriBuilder.add("restype", "directory");
CloudFileDirectory snapshotDir2 = new CloudFileDirectory(uriBuilder.addToURI(dir.getUri()), this.share.getServiceClient().getCredentials());
assertEquals(snapshot.snapshotID, snapshotDir2.getShare().snapshotID);
assertTrue(snapshotDir2.exists());

snapshot.delete();
}

/*
[TestMethod]
[Description("CloudFileDirectory deleting a directory using conditional access")]
Expand Down Expand Up @@ -807,6 +874,8 @@ public void eventOccurred(SendingRequestEvent eventArg) {
}
catch (StorageException e) {
fail("Delete should succeed.");
} catch (URISyntaxException e) {
fail("Delete should succeed.");
}
}
}
Expand Down
Loading

0 comments on commit 6c34612

Please sign in to comment.