public void close() { assertNull(this.error); assertEquals(this.initialLocation, this.operationContext.getRequestResults().get(0).getTargetLocation()); assertEquals(this.retryInfoList.size() + 1, this.operationContext.getRequestResults().size()); for (int i = 0; i < this.retryInfoList.size(); i++) { assertEquals(this.retryInfoList.get(i).getTargetLocation(), this.operationContext.getRequestResults().get(i + 1).getTargetLocation()); int retryInterval = (int) (this.operationContext.getRequestResults().get(i + 1).getStartDate().getTime() - this.operationContext .getRequestResults().get(i).getStopDate().getTime()); assertTrue(this.retryInfoList.get(i).getRetryInterval() <= retryInterval); } } }
private void appendBlock(ByteArrayInputStream blockData, long offset, long writeLength) { final CloudAppendBlob blobRef = (CloudAppendBlob) this.parentBlobRef; this.accessCondition.setIfAppendPositionEqual(offset); int previousResultsCount = this.opContext.getRequestResults().size(); try { blobRef.appendBlock(blockData, writeLength, this.accessCondition, this.options, this.opContext); } catch (final IOException e) { this.lastError = e; } catch (final StorageException e) { if (this.options.getAbsorbConditionalErrorsOnRetry() && e.getHttpStatusCode() == HttpURLConnection.HTTP_PRECON_FAILED && e.getExtendedErrorInformation() != null && e.getErrorCode() != null && (e.getErrorCode() .equals(StorageErrorCodeStrings.INVALID_APPEND_POSITION) || e.getErrorCode().equals(StorageErrorCodeStrings.INVALID_MAX_BLOB_SIZE_CONDITION)) && (this.opContext.getRequestResults().size() - previousResultsCount > 1)) { // Pre-condition failure on a retry should be ignored in a single writer scenario since // the request succeeded in the first attempt. Logger.info(this.opContext, SR.PRECONDITION_FAILURE_IGNORED); } else { this.lastError = Utility.initIOException(e); } } }
&& operationContext.getRequestResults().size() > 1 && operationContext.getRequestResults().get(0).getException() != null) { LOG.debug("Swallowing delete exception on retry: {}", e.getMessage()); return;
private void appendBlock(ByteArrayInputStream blockData, long offset, long writeLength) { final CloudAppendBlob blobRef = (CloudAppendBlob) this.parentBlobRef; this.accessCondition.setIfAppendPositionEqual(offset); int previousResultsCount = this.opContext.getRequestResults().size(); try { blobRef.appendBlock(blockData, writeLength, this.accessCondition, this.options, this.opContext); } catch (final IOException e) { this.lastError = e; } catch (final StorageException e) { if (this.options.getAbsorbConditionalErrorsOnRetry() && e.getHttpStatusCode() == HttpURLConnection.HTTP_PRECON_FAILED && e.getExtendedErrorInformation() != null && e.getExtendedErrorInformation().getErrorCode() != null && (e.getExtendedErrorInformation().getErrorCode() .equals(StorageErrorCodeStrings.INVALID_APPEND_POSITION) || e.getExtendedErrorInformation() .getErrorCode().equals(StorageErrorCodeStrings.INVALID_MAX_BLOB_SIZE_CONDITION)) && (this.opContext.getRequestResults().size() - previousResultsCount > 1)) { // Pre-condition failure on a retry should be ignored in a single writer scenario since // the request succeeded in the first attempt. Logger.info(this.opContext, SR.PRECONDITION_FAILURE_IGNORED); } else { this.lastError = Utility.initIOException(e); } } }
options.setLocationMode(LocationMode.PRIMARY_ONLY); queue.createIfNotExists(options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); options.setLocationMode(LocationMode.PRIMARY_ONLY); queue.deleteIfExists(options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation());
options.setLocationMode(LocationMode.PRIMARY_ONLY); table.createIfNotExists(options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); options.setLocationMode(LocationMode.PRIMARY_ONLY); table.deleteIfExists(options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation());
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testBlobUploadFromStreamRequestOptionsTest() throws URISyntaxException, StorageException, IOException { final String blockBlobName1 = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob"); final CloudBlockBlob blockBlobRef1 = this.container.getBlockBlobReference(blockBlobName1); final String blockBlobName2 = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob"); final CloudBlockBlob blockBlobRef2 = this.container.getBlockBlobReference(blockBlobName2); final int length = 2 * com.microsoft.azure.storage.Constants.MB; ByteArrayInputStream srcStream = BlobTestHelper.getRandomDataStream(length); BlobRequestOptions options = new BlobRequestOptions(); options.setSingleBlobPutThresholdInBytes(length / 2); options.setRetryPolicyFactory(RetryNoRetry.getInstance()); OperationContext context = new OperationContext(); blockBlobRef1.upload(srcStream, length, null /* accessCondition */, options, context); assertTrue(context.getRequestResults().size() >= 2); srcStream.reset(); options.setSingleBlobPutThresholdInBytes(length); context = new OperationContext(); blockBlobRef2.upload(srcStream, length, null /* accessCondition */, options, context); assertTrue(context.getRequestResults().size() <= 2); }
options.setLocationMode(LocationMode.PRIMARY_ONLY); container.createIfNotExists(options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); options.setLocationMode(LocationMode.PRIMARY_ONLY); container.deleteIfExists(null, options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); options.setLocationMode(LocationMode.PRIMARY_ONLY); blockBlob.deleteIfExists(DeleteSnapshotsOption.NONE, null, options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); options.setLocationMode(LocationMode.PRIMARY_ONLY); pageBlob.deleteIfExists(DeleteSnapshotsOption.NONE, null, options, context); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation()); assertEquals(StorageLocation.PRIMARY, context.getRequestResults().get(0).getTargetLocation());