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

Commit aff397f

Browse files
rickle-msftmirobers
authored andcommitted
Merge pull request 103 from rickle-msft/jul17
Add queue message TTL and error code header changes for Jul17.
1 parent 9a16e35 commit aff397f

File tree

14 files changed

+121
-106
lines changed

14 files changed

+121
-106
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The Azure Storage development team uses Intellij. However, any preferred IDE or
2020

2121
### Configuration
2222
The only step to configure testing is to setup a configuration file or connection string via environment variables. To use the connection string route, create an environment variable named "storageConnection". To use the configuration file route, create an environment variable named "storageTestConfiguration" with the path to a TestConfigurations.xml file with this [template](https://github.com/Azure/azure-storage-java/blob/master/microsoft-azure-storage-test/res/TestConfigurations.xml).
23+
Alternatively, you can fill in microsoft-azure-storage-test/res/TestConfigurations.xml with the appropriate information.
2324

2425
### Running
2526
To actually run tests, right click on the test class in the Package Explorer or the individual test in the Outline and select Run As->JUnitTest. All tests or tests grouped by service can be run using the test runners in the com.microsoft.azure.storage package TestRunners file. Running all tests from the top of the package explorer will result in each test being run multiple times as the package explorer will also run every test runner.

ChangeLog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
XXXX.XX.xx Version X.X.X
2+
* Support for 2017-07-29 REST version. Please see our REST api documentation and blogs for information about the related added features.
3+
14
2017.11.01 Version 6.1.0
25
* Added support for the last time the tier was modified.
36

microsoft-azure-storage-test/src/com/microsoft/azure/storage/EventFiringTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ public void eventOccurred(RetryingEvent eventArg) {
338338
catch (StorageException e) {
339339
assertEquals(HttpURLConnection.HTTP_NOT_FOUND, e.getHttpStatusCode());
340340
assertEquals("The specified container does not exist.", e.getMessage());
341-
assertEquals(StorageErrorCode.RESOURCE_NOT_FOUND.toString(), e.getErrorCode());
341+
assertEquals(StorageErrorCodeStrings.CONTAINER_NOT_FOUND, e.getErrorCode());
342342
}
343343
assertEquals(1, callList.size());
344344
assertEquals(1, globalCallList.size());
@@ -351,7 +351,7 @@ public void eventOccurred(RetryingEvent eventArg) {
351351
catch (StorageException e) {
352352
assertEquals(HttpURLConnection.HTTP_NOT_FOUND, e.getHttpStatusCode());
353353
assertEquals("The specified container does not exist.", e.getMessage());
354-
assertEquals(StorageErrorCode.RESOURCE_NOT_FOUND.toString(), e.getErrorCode());
354+
assertEquals(StorageErrorCodeStrings.CONTAINER_NOT_FOUND, e.getErrorCode());
355355
}
356356
assertEquals(1, callList.size());
357357
assertEquals(2, globalCallList.size());
@@ -368,7 +368,7 @@ public void eventOccurred(RetryingEvent eventArg) {
368368
catch (StorageException e) {
369369
assertEquals(HttpURLConnection.HTTP_NOT_FOUND, e.getHttpStatusCode());
370370
assertEquals("The specified container does not exist.", e.getMessage());
371-
assertEquals(StorageErrorCode.RESOURCE_NOT_FOUND.toString(), e.getErrorCode());
371+
assertEquals(StorageErrorCodeStrings.CONTAINER_NOT_FOUND, e.getErrorCode());
372372
}
373373
assertEquals(1, callList.size());
374374
assertEquals(2, globalCallList.size());
@@ -422,7 +422,7 @@ public void eventOccurred(RequestCompletedEvent eventArg) {
422422
catch (StorageException e) {
423423
assertEquals(HttpURLConnection.HTTP_NOT_FOUND, e.getHttpStatusCode());
424424
assertEquals("The specified container does not exist.", e.getMessage());
425-
assertEquals(StorageErrorCode.RESOURCE_NOT_FOUND.toString(), e.getErrorCode());
425+
assertEquals(StorageErrorCodeStrings.CONTAINER_NOT_FOUND, e.getErrorCode());
426426
}
427427

428428
assertEquals(2, sendingCallList.size());

microsoft-azure-storage-test/src/com/microsoft/azure/storage/GenericTests.java

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,8 @@
1414
*/
1515
package com.microsoft.azure.storage;
1616

17-
import com.microsoft.azure.storage.blob.BlobOutputStream;
18-
import com.microsoft.azure.storage.blob.BlobRequestOptions;
19-
import com.microsoft.azure.storage.blob.BlobTestHelper;
20-
import com.microsoft.azure.storage.blob.CloudBlobClient;
21-
import com.microsoft.azure.storage.blob.CloudBlobContainer;
22-
import com.microsoft.azure.storage.blob.CloudBlockBlob;
17+
import com.microsoft.azure.storage.blob.*;
18+
import com.microsoft.azure.storage.core.BaseRequest;
2319
import com.microsoft.azure.storage.core.SR;
2420
import com.microsoft.azure.storage.core.Utility;
2521
import com.microsoft.azure.storage.queue.CloudQueue;
@@ -476,4 +472,48 @@ private static String generateRandomContainerName() {
476472
String containerName = "container" + UUID.randomUUID().toString();
477473
return containerName.replace("-", "");
478474
}
475+
476+
@Test
477+
public void testErrorCodeFromHeader() throws URISyntaxException, StorageException, IOException {
478+
byte[] buffer = BlobTestHelper.getRandomBuffer(1 * 1024 * 1024);
479+
480+
CloudBlobClient blobClient = TestHelper.createCloudBlobClient();
481+
CloudBlobContainer container = blobClient.getContainerReference(generateRandomContainerName());
482+
483+
String blobName = "testBlob";
484+
CloudAppendBlob appendBlob = container.getAppendBlobReference("testAppend");
485+
486+
try {
487+
container.createIfNotExists();
488+
OperationContext ctx = new OperationContext();
489+
appendBlob.createOrReplace();
490+
491+
// Verify that the error code is set on a non HEAD request
492+
try {
493+
appendBlob.delete(DeleteSnapshotsOption.NONE, AccessCondition.generateIfMatchCondition("garbage"),
494+
null, ctx);
495+
}
496+
catch (Exception e) {
497+
// Validate that the error code is set on the exception and the result
498+
assertEquals(((StorageException)e).getErrorCode(), StorageErrorCodeStrings.CONDITION_NOT_MET);
499+
assertEquals(ctx.getLastResult().getErrorCode(), StorageErrorCodeStrings.CONDITION_NOT_MET);
500+
}
501+
502+
// Verify that the error code is set on a HEAD request
503+
try {
504+
appendBlob.downloadAttributes(AccessCondition.generateIfMatchCondition("garbage"), null, ctx);
505+
}
506+
catch (Exception e) {
507+
assertEquals(((StorageException)e).getErrorCode(), StorageErrorCodeStrings.CONDITION_NOT_MET);
508+
assertEquals(ctx.getLastResult().getErrorCode(), StorageErrorCodeStrings.CONDITION_NOT_MET);
509+
}
510+
511+
// Verify that the ErrorCode is not set on a successful request
512+
appendBlob.delete(DeleteSnapshotsOption.NONE, null, null, ctx);
513+
assertEquals(ctx.getLastResult().getErrorCode(), null);
514+
}
515+
finally {
516+
container.deleteIfExists();
517+
}
518+
}
479519
}

microsoft-azure-storage-test/src/com/microsoft/azure/storage/queue/CloudQueueTests.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,9 @@ public void testAddMessageSpecialVisibilityTimeout() throws StorageException {
911911
this.queue.addMessage(message, 1, 0, null, null);
912912
this.queue.addMessage(message, 7 * 24 * 60 * 60, 0, null, null);
913913
this.queue.addMessage(message, 7 * 24 * 60 * 60, 7 * 24 * 60 * 60 - 1, null, null);
914+
this.queue.addMessage(message, 7 * 24 * 60 * 60 * 1024, 0, null, null);
915+
this.queue.addMessage(message, -1, 0, null, null);
916+
this.queue.addMessage(message, 0, 1, null, null);
914917

915918
try {
916919
this.queue.addMessage(message, 0, -1, null, null);
@@ -927,14 +930,14 @@ public void testAddMessageSpecialVisibilityTimeout() throws StorageException {
927930
}
928931

929932
try {
930-
this.queue.addMessage(message, 7 * 24 * 60 * 60 + 1, 0, null, null);
933+
this.queue.addMessage(message, 0, 7 * 24 * 60 * 60 + 1, null, null);
931934
fail();
932935
}
933936
catch (final IllegalArgumentException e) {
934937
}
935938

936939
try {
937-
this.queue.addMessage(message, 0, 7 * 24 * 60 * 60 + 1, null, null);
940+
this.queue.addMessage(message, -2, 0, null, null);
938941
fail();
939942
}
940943
catch (final IllegalArgumentException e) {

microsoft-azure-storage/src/com/microsoft/azure/storage/Constants.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,11 @@ public static class HeaderConstants {
450450
*/
451451
public static final String ETAG = "ETag";
452452

453+
/**
454+
* The ErrorCode header.
455+
*/
456+
public static final String ERROR_CODE = "x-ms-error-code";
457+
453458
/**
454459
* An unused HTTP code used internally to indicate a non-http related failure when constructing
455460
* {@link StorageException} objects
@@ -641,7 +646,7 @@ public static class HeaderConstants {
641646
/**
642647
* The current storage version header value.
643648
*/
644-
public static final String TARGET_STORAGE_VERSION = "2017-04-17";
649+
public static final String TARGET_STORAGE_VERSION = "2017-07-29";
645650

646651
/**
647652
* The header that specifies the next visible time for a queue message.

microsoft-azure-storage/src/com/microsoft/azure/storage/RequestResult.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ public final class RequestResult {
6767
*/
6868
private String statusMessage;
6969

70+
/**
71+
* Represents the service ErrorCode for the request.
72+
*/
73+
private String errorCode;
74+
7075
/**
7176
* Represents the stop date of the operation.
7277
*/
@@ -167,6 +172,12 @@ public String getStatusMessage() {
167172
return this.statusMessage;
168173
}
169174

175+
/**
176+
* Gets the service ErrorCode for the request.
177+
*
178+
* @return A <code>String</code> which contains the service ErrorCode.
179+
*/
180+
public String getErrorCode() { return this.errorCode; }
170181
/**
171182
* Gets the stop date for the request.
172183
*
@@ -273,6 +284,14 @@ public void setStatusMessage(final String statusMessage) {
273284
this.statusMessage = statusMessage;
274285
}
275286

287+
/**
288+
* Sets the service ErrorCode for the request.
289+
*
290+
* @param errorCode
291+
* A <code>String</code> which contains the service ErrorCode to set.
292+
*/
293+
public void setErrorCode(final String errorCode) { this.errorCode = errorCode; }
294+
276295
/**
277296
* Sets the stop date for the request.
278297
*

microsoft-azure-storage/src/com/microsoft/azure/storage/StorageException.java

Lines changed: 2 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,8 @@ public static StorageException translateException(final StorageRequest<?, ?, ?>
8484
}
8585

8686
StorageExtendedErrorInformation extendedError = request.parseErrorDetails();
87-
if (extendedError != null) {
88-
// 1. If extended information is available use it
89-
translatedException = new StorageException(extendedError.getErrorCode(), responseMessage, responseCode,
90-
extendedError, cause);
91-
} else {
92-
// 2. If extended information is unavailable, translate exception based
93-
// on status code
94-
translatedException = translateFromHttpStatus(responseCode, responseMessage, cause);
95-
}
87+
translatedException = new StorageException(request.getResult().getErrorCode(), responseMessage,
88+
responseCode, extendedError, cause);
9689

9790
if (translatedException != null) {
9891
Utility.logHttpError(translatedException, opContext);
@@ -104,78 +97,6 @@ public static StorageException translateException(final StorageRequest<?, ?, ?>
10497
}
10598
}
10699

107-
/**
108-
* Translates the specified HTTP status code into a storage exception.
109-
*
110-
* @param statusCode
111-
* The HTTP status code returned by the operation.
112-
* @param statusDescription
113-
* A <code>String</code> that represents the status description.
114-
* @param inner
115-
* An <code>Exception</code> object that represents a reference to the initial exception, if one exists.
116-
*
117-
* @return A <code>StorageException</code> object that represents translated exception.
118-
**/
119-
protected static StorageException translateFromHttpStatus(final int statusCode, final String statusDescription,
120-
final Exception inner) {
121-
String errorCode;
122-
switch (statusCode) {
123-
case HttpURLConnection.HTTP_FORBIDDEN:
124-
errorCode = StorageErrorCode.ACCESS_DENIED.toString();
125-
break;
126-
case HttpURLConnection.HTTP_GONE:
127-
case HttpURLConnection.HTTP_NOT_FOUND:
128-
errorCode = StorageErrorCode.RESOURCE_NOT_FOUND.toString();
129-
break;
130-
case 416:
131-
case HttpURLConnection.HTTP_BAD_REQUEST:
132-
// 416: RequestedRangeNotSatisfiable - No corresponding enum in HttpURLConnection
133-
errorCode = StorageErrorCode.BAD_REQUEST.toString();
134-
break;
135-
136-
case HttpURLConnection.HTTP_PRECON_FAILED:
137-
case HttpURLConnection.HTTP_NOT_MODIFIED:
138-
errorCode = StorageErrorCode.CONDITION_FAILED.toString();
139-
break;
140-
141-
case HttpURLConnection.HTTP_CONFLICT:
142-
errorCode = StorageErrorCode.RESOURCE_ALREADY_EXISTS.toString();
143-
break;
144-
145-
case HttpURLConnection.HTTP_UNAVAILABLE:
146-
errorCode = StorageErrorCode.SERVER_BUSY.toString();
147-
break;
148-
149-
case HttpURLConnection.HTTP_GATEWAY_TIMEOUT:
150-
errorCode = StorageErrorCode.SERVICE_TIMEOUT.toString();
151-
break;
152-
153-
case HttpURLConnection.HTTP_INTERNAL_ERROR:
154-
errorCode = StorageErrorCode.SERVICE_INTERNAL_ERROR.toString();
155-
break;
156-
157-
case HttpURLConnection.HTTP_NOT_IMPLEMENTED:
158-
errorCode = StorageErrorCode.NOT_IMPLEMENTED.toString();
159-
break;
160-
161-
case HttpURLConnection.HTTP_BAD_GATEWAY:
162-
errorCode = StorageErrorCode.BAD_GATEWAY.toString();
163-
break;
164-
165-
case HttpURLConnection.HTTP_VERSION:
166-
errorCode = StorageErrorCode.HTTP_VERSION_NOT_SUPPORTED.toString();
167-
break;
168-
default:
169-
errorCode = null;
170-
}
171-
172-
if (errorCode == null) {
173-
return null;
174-
} else {
175-
return new StorageException(errorCode, statusDescription, statusCode, null, inner);
176-
}
177-
}
178-
179100
/**
180101
* Represents the error code returned by the operation.
181102
*/

microsoft-azure-storage/src/com/microsoft/azure/storage/StorageExtendedErrorInformation.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public HashMap<String, String[]> getAdditionalDetails() {
6161
* Gets the storage service error code.
6262
*
6363
* @return A <code>String</code> which contains the error code.
64+
*
65+
* @deprecated use the property on {@link RequestResult} instead.
6466
*/
6567
public String getErrorCode() {
6668
return this.errorCode;

microsoft-azure-storage/src/com/microsoft/azure/storage/core/BaseResponse.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,21 @@ public static String getEtag(final HttpURLConnection request) {
6161
}
6262

6363
/**
64-
* Gets the metadata from the request The response from server.
64+
* Gets the ErrorCode
65+
*
66+
* @param request
67+
* The response from server.
68+
* @return The ErrorCode.
69+
*/
70+
public static String getErrorCode(final HttpURLConnection request) {
71+
return request.getHeaderField(Constants.HeaderConstants.ERROR_CODE);
72+
}
73+
74+
/**
75+
* Gets the metadata from the request.
76+
*
77+
* @param request
78+
* The response from server.
6579
*
6680
* @return the metadata from the request
6781
*/

0 commit comments

Comments
 (0)