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

Commit bfb24a4

Browse files
author
Josh Friedman
committed
Fixing share listing for snapshots
1 parent 5a4cd4b commit bfb24a4

File tree

5 files changed

+81
-81
lines changed

5 files changed

+81
-81
lines changed

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

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void testListSharesTest() throws StorageException, URISyntaxException {
6767
do {
6868

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

7272
for (final CloudFileShare share : segment.getResults()) {
7373
share.downloadAttributes();
@@ -104,7 +104,7 @@ public void testListSharesMaxResultsValidationTest() throws StorageException, UR
104104
for (int i = 0; i >= -2; i--) {
105105
try{
106106
fileClient.listSharesSegmented(
107-
prefix, ShareListingDetails.ALL, i, null, null, null);
107+
prefix, EnumSet.allOf(ShareListingDetails.class), i, null, null, null);
108108
fail();
109109
}
110110
catch (IllegalArgumentException e) {
@@ -119,42 +119,46 @@ public void testListSharesMaxResultsValidationTest() throws StorageException, UR
119119
public void testListSharesWithSnapshot() throws StorageException, URISyntaxException {
120120
CloudFileClient fileClient = FileTestHelper.createCloudFileClient();
121121
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());
122+
try {
123+
share.create();
124+
125+
HashMap<String, String> shareMeta = new HashMap<String, String>();
126+
shareMeta.put("key1", "value1");
127+
share.setMetadata(shareMeta);
128+
share.uploadMetadata();
129+
130+
CloudFileShare snapshot = share.createSnapshot();
131+
HashMap<String, String> meta2 = new HashMap<String, String>();
132+
meta2.put("key2", "value2");
133+
share.setMetadata(meta2);
134+
share.uploadMetadata();
135+
136+
CloudFileClient client = FileTestHelper.createCloudFileClient();
137+
Iterable<CloudFileShare> listResult = client.listShares(share.name, EnumSet.allOf(ShareListingDetails.class), null, null);
138+
139+
int count = 0;
140+
boolean originalFound = false;
141+
boolean snapshotFound = false;
142+
for (CloudFileShare listShareItem : listResult) {
143+
if (listShareItem.getName().equals(share.getName()) && !listShareItem.isSnapshot() && !originalFound) {
144+
count++;
145+
originalFound = true;
146+
assertEquals(share.getMetadata(), listShareItem.getMetadata());
147+
assertEquals(share.getStorageUri(), listShareItem.getStorageUri());
148+
} else if (listShareItem.getName().equals(share.getName()) &&
149+
listShareItem.isSnapshot() && !snapshotFound) {
150+
count++;
151+
snapshotFound = true;
152+
assertEquals(snapshot.getMetadata(), listShareItem.getMetadata());
153+
assertEquals(snapshot.getStorageUri(), listShareItem.getStorageUri());
154+
}
155155
}
156-
}
157156

158-
assertEquals(2, count);
157+
assertEquals(2, count);
158+
}
159+
finally
160+
{
161+
share.deleteIfExists(DeleteShareSnapshotsOption.INCLUDE_SNAPSHOTS, null, null, null);
162+
}
159163
}
160164
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public void testCloudFileShareUploadMetadata() throws StorageException, URISynta
318318
Assert.assertEquals("value2", this.share.getMetadata().get("key2"));
319319

320320
Iterable<CloudFileShare> shares = this.share.getServiceClient().listShares(this.share.getName(),
321-
ShareListingDetails.METADATA, null, null);
321+
EnumSet.of(ShareListingDetails.METADATA), null, null);
322322

323323
for (CloudFileShare share3 : shares) {
324324
Assert.assertEquals(2, share3.getMetadata().size());

microsoft-azure-storage/src/com/microsoft/azure/storage/file/CloudFileClient.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public CloudFileShare getShareReference(final String shareName, String snapshotI
134134
*/
135135
@DoesServiceRequest
136136
public Iterable<CloudFileShare> listShares() {
137-
return this.listSharesWithPrefix(null, ShareListingDetails.NONE, null /* options */, null /* opContext */);
137+
return this.listSharesWithPrefix(null, EnumSet.noneOf(ShareListingDetails.class), null /* options */, null /* opContext */);
138138
}
139139

140140
/**
@@ -149,7 +149,7 @@ public Iterable<CloudFileShare> listShares() {
149149
*/
150150
@DoesServiceRequest
151151
public Iterable<CloudFileShare> listShares(final String prefix) {
152-
return this.listSharesWithPrefix(prefix, ShareListingDetails.NONE, null /* options */, null /* opContext */);
152+
return this.listSharesWithPrefix(prefix, EnumSet.noneOf(ShareListingDetails.class), null /* options */, null /* opContext */);
153153
}
154154

155155
/**
@@ -159,7 +159,8 @@ public Iterable<CloudFileShare> listShares(final String prefix) {
159159
* @param prefix
160160
* A <code>String</code> that represents the share name prefix.
161161
* @param detailsIncluded
162-
* A {@link ShareListingDetails} value that indicates whether share metadata will be returned.
162+
* A <code>java.util.EnumSet</code> object that contains {@link ShareListingDetails} values that indicate
163+
* whether share snapshots and/or metadata will be returned.
163164
* @param options
164165
* A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying
165166
* <code>null</code> will use the default request options from the associated service client (
@@ -173,7 +174,7 @@ public Iterable<CloudFileShare> listShares(final String prefix) {
173174
* shares for this client.
174175
*/
175176
@DoesServiceRequest
176-
public Iterable<CloudFileShare> listShares(final String prefix, final ShareListingDetails detailsIncluded,
177+
public Iterable<CloudFileShare> listShares(final String prefix, final EnumSet<ShareListingDetails> detailsIncluded,
177178
final FileRequestOptions options, final OperationContext opContext) {
178179
return this.listSharesWithPrefix(prefix, detailsIncluded, options, opContext);
179180
}
@@ -189,7 +190,7 @@ public Iterable<CloudFileShare> listShares(final String prefix, final ShareListi
189190
*/
190191
@DoesServiceRequest
191192
public ResultSegment<CloudFileShare> listSharesSegmented() throws StorageException {
192-
return this.listSharesSegmented(null, ShareListingDetails.NONE, null, null /* continuationToken */,
193+
return this.listSharesSegmented(null, EnumSet.noneOf(ShareListingDetails.class), null, null /* continuationToken */,
193194
null /* options */, null /* opContext */);
194195
}
195196

@@ -209,7 +210,7 @@ public ResultSegment<CloudFileShare> listSharesSegmented() throws StorageExcepti
209210
*/
210211
@DoesServiceRequest
211212
public ResultSegment<CloudFileShare> listSharesSegmented(final String prefix) throws StorageException {
212-
return this.listSharesWithPrefixSegmented(prefix, ShareListingDetails.NONE, null, null /* continuationToken */,
213+
return this.listSharesWithPrefixSegmented(prefix, EnumSet.noneOf(ShareListingDetails.class), null, null /* continuationToken */,
213214
null /* options */, null /* opContext */);
214215
}
215216

@@ -220,7 +221,8 @@ public ResultSegment<CloudFileShare> listSharesSegmented(final String prefix) th
220221
* @param prefix
221222
* A <code>String</code> that represents the prefix of the share name.
222223
* @param detailsIncluded
223-
* A {@link ShareListingDetails} value that indicates whether share metadata will be returned.
224+
* A <code>java.util.EnumSet</code> object that contains {@link ShareListingDetails} values that indicate
225+
* whether share snapshots and/or metadata will be returned.
224226
* @param maxResults
225227
* The maximum number of results to retrieve. If <code>null</code> or greater
226228
* than 5000, the server will return up to 5,000 items. Must be at least 1.
@@ -244,7 +246,7 @@ public ResultSegment<CloudFileShare> listSharesSegmented(final String prefix) th
244246
*/
245247
@DoesServiceRequest
246248
public ResultSegment<CloudFileShare> listSharesSegmented(final String prefix,
247-
final ShareListingDetails detailsIncluded, final Integer maxResults,
249+
final EnumSet<ShareListingDetails> detailsIncluded, final Integer maxResults,
248250
final ResultContinuation continuationToken, final FileRequestOptions options,
249251
final OperationContext opContext) throws StorageException {
250252
return this.listSharesWithPrefixSegmented(prefix, detailsIncluded, maxResults, continuationToken, options,
@@ -258,7 +260,8 @@ public ResultSegment<CloudFileShare> listSharesSegmented(final String prefix,
258260
* @param prefix
259261
* A <code>String</code> that represents the prefix of the share name.
260262
* @param detailsIncluded
261-
* A {@link ShareListingDetails} value that indicates whether share metadata will be returned.
263+
* A <code>java.util.EnumSet</code> object that contains {@link ShareListingDetails} values that indicate
264+
* whether share snapshots and/or metadata will be returned.
262265
* @param options
263266
* A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying
264267
* <code>null</code> will use the default request options from the associated service client (
@@ -272,7 +275,7 @@ public ResultSegment<CloudFileShare> listSharesSegmented(final String prefix,
272275
* shares whose names begin with the specified prefix.
273276
*/
274277
private Iterable<CloudFileShare> listSharesWithPrefix(final String prefix,
275-
final ShareListingDetails detailsIncluded, FileRequestOptions options, OperationContext opContext) {
278+
final EnumSet<ShareListingDetails> detailsIncluded, FileRequestOptions options, OperationContext opContext) {
276279
if (opContext == null) {
277280
opContext = new OperationContext();
278281
}
@@ -294,7 +297,8 @@ private Iterable<CloudFileShare> listSharesWithPrefix(final String prefix,
294297
* @param prefix
295298
* A <code>String</code> that represents the prefix of the share name.
296299
* @param detailsIncluded
297-
* A {@link ShareListingDetails} value that indicates whether share metadata will be returned.
300+
* A <code>java.util.EnumSet</code> object that contains {@link ShareListingDetails} values that indicate
301+
* whether share snapshots and/or metadata will be returned.
298302
* @param maxResults
299303
* The maximum number of results to retrieve. If <code>null</code> or greater
300304
* than 5000, the server will return up to 5,000 items. Must be at least 1.
@@ -317,7 +321,7 @@ private Iterable<CloudFileShare> listSharesWithPrefix(final String prefix,
317321
* If a storage service error occurred.
318322
*/
319323
private ResultSegment<CloudFileShare> listSharesWithPrefixSegmented(final String prefix,
320-
final ShareListingDetails detailsIncluded, final Integer maxResults,
324+
final EnumSet<ShareListingDetails> detailsIncluded, final Integer maxResults,
321325
final ResultContinuation continuationToken, FileRequestOptions options, OperationContext opContext)
322326
throws StorageException {
323327
if (opContext == null) {
@@ -338,7 +342,7 @@ private ResultSegment<CloudFileShare> listSharesWithPrefixSegmented(final String
338342
}
339343

340344
private StorageRequest<CloudFileClient, Void, ResultSegment<CloudFileShare>> listSharesWithPrefixSegmentedImpl(
341-
final String prefix, final ShareListingDetails detailsIncluded, final Integer maxResults,
345+
final String prefix, final EnumSet<ShareListingDetails> detailsIncluded, final Integer maxResults,
342346
final FileRequestOptions options, final SegmentedStorageRequest segmentedRequest) {
343347

344348
Utility.assertContinuationType(segmentedRequest.getToken(), ResultContinuationType.SHARE);

microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileRequest.java

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,8 @@ private static HttpURLConnection getProperties(final URI uri, final FileRequestO
640640
* @param listingContext
641641
* A set of parameters for the listing operation.
642642
* @param detailsIncluded
643-
* Additional details to return with the listing.
643+
* A <code>java.util.EnumSet</code> object that contains {@link ShareListingDetails} values that indicate
644+
* whether share snapshots and/or metadata will be returned.
644645
* @return a HttpURLConnection configured for the operation.
645646
* @throws IOException
646647
* @throws URISyntaxException
@@ -649,32 +650,28 @@ private static HttpURLConnection getProperties(final URI uri, final FileRequestO
649650
*/
650651
public static HttpURLConnection listShares(final URI uri, final FileRequestOptions fileOptions,
651652
final OperationContext opContext, final ListingContext listingContext,
652-
final ShareListingDetails detailsIncluded) throws URISyntaxException, IOException, StorageException {
653+
final EnumSet<ShareListingDetails> detailsIncluded) throws URISyntaxException, IOException, StorageException {
653654
final UriQueryBuilder builder = BaseRequest.getListUriQueryBuilder(listingContext);
654655

655-
// if (detailsIncluded != null && detailsIncluded.size() > 0) {
656-
// final StringBuilder sb = new StringBuilder();
657-
// boolean started = false;
656+
if (detailsIncluded != null && detailsIncluded.size() > 0) {
657+
final StringBuilder sb = new StringBuilder();
658+
boolean started = false;
658659

659-
// if (detailsIncluded.contains(ShareListingDetails.SNAPSHOTS)) {
660-
// started = true;
661-
// sb.append(SNAPSHOTS_QUERY_ELEMENT_NAME);
662-
// }
660+
if (detailsIncluded.contains(ShareListingDetails.SNAPSHOTS)) {
661+
started = true;
662+
sb.append(SNAPSHOTS_QUERY_ELEMENT_NAME);
663+
}
663664

664-
// if (detailsIncluded.contains(ShareListingDetails.METADATA)) {
665-
// if (started)
666-
// {
667-
// sb.append(",");
668-
// }
669-
//
670-
// sb.append(Constants.QueryConstants.METADATA);
671-
// }
672-
673-
// builder.add(Constants.QueryConstants.INCLUDE, sb.toString());
674-
// }
675-
676-
if (detailsIncluded == ShareListingDetails.ALL || detailsIncluded == ShareListingDetails.METADATA) {
677-
builder.add(Constants.QueryConstants.INCLUDE, Constants.QueryConstants.METADATA);
665+
if (detailsIncluded.contains(ShareListingDetails.METADATA)) {
666+
if (started)
667+
{
668+
sb.append(",");
669+
}
670+
671+
sb.append(Constants.QueryConstants.METADATA);
672+
}
673+
674+
builder.add(Constants.QueryConstants.INCLUDE, sb.toString());
678675
}
679676

680677
final HttpURLConnection request = BaseRequest.createURLConnection(uri, fileOptions, builder, opContext);

microsoft-azure-storage/src/com/microsoft/azure/storage/file/ShareListingDetails.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,15 @@ public enum ShareListingDetails {
2424
*/
2525
NONE(0),
2626

27-
/**
28-
* Specifies including all available details.
29-
*/
30-
ALL(1),
31-
3227
/**
3328
* Specifies including share metadata.
3429
*/
35-
METADATA(1);
30+
METADATA(1),
3631

3732
/**
3833
* Specifies listing share snapshots.
3934
*/
40-
//SNAPSHOTS(2);
35+
SNAPSHOTS(2);
4136

4237
/**
4338
* Returns the value of this enum.

0 commit comments

Comments
 (0)