private AzureBlobLease createLeaseIfNotExistsInternal(String partitionId, BlobRequestOptions options) throws URISyntaxException, IOException, StorageException { AzureBlobLease returnLease = null; try { CloudBlockBlob leaseBlob = this.consumerGroupDirectory.getBlockBlobReference(partitionId); // getBlockBlobReference does not take options returnLease = new AzureBlobLease(partitionId, leaseBlob, this.leaseOperationOptions); uploadLease(returnLease, leaseBlob, AccessCondition.generateIfNoneMatchCondition("*"), UploadActivity.Create, options); // Do not set metadata on creation. No metadata/no owner value indicates that the lease is unowned. TRACE_LOGGER.info(this.hostContext.withHostAndPartition(partitionId, "CreateLeaseIfNotExist OK - leaseContainerName: " + this.storageContainerName + " consumerGroupName: " + this.hostContext.getConsumerGroupName() + " storageBlobPrefix: " + this.storageBlobPrefix)); } catch (StorageException se) { StorageExtendedErrorInformation extendedErrorInfo = se.getExtendedErrorInformation(); if ((extendedErrorInfo != null) && ((extendedErrorInfo.getErrorCode().compareTo(StorageErrorCodeStrings.BLOB_ALREADY_EXISTS) == 0) || (extendedErrorInfo.getErrorCode().compareTo(StorageErrorCodeStrings.LEASE_ID_MISSING) == 0))) // occurs when somebody else already has leased the blob { // The blob already exists. TRACE_LOGGER.info(this.hostContext.withHostAndPartition(partitionId, "Lease already exists")); returnLease = getLeaseInternal(partitionId, options); } else { throw se; } } return returnLease; }
blob.uploadMetadata(AccessCondition.generateIfNoneMatchCondition(newETag), null, null); fail("If none match on conditional test should throw"); blob.uploadMetadata(AccessCondition.generateIfNoneMatchCondition(invalidETag), null, null);
@Test public void testRetryOn304() throws StorageException, IOException, URISyntaxException { OperationContext operationContext = new OperationContext(); operationContext.getRetryingEventHandler().addListener(new StorageEvent<RetryingEvent>() { @Override public void eventOccurred(RetryingEvent eventArg) { fail("Request should not be retried."); } }); CloudBlobContainer container = BlobTestHelper.getRandomContainerReference(); try { container.create(); CloudBlockBlob blockBlobRef = (CloudBlockBlob) BlobTestHelper.uploadNewBlob(container, BlobType.BLOCK_BLOB, "originalBlob", 1024, null); AccessCondition accessCondition = AccessCondition.generateIfNoneMatchCondition(blockBlobRef.getProperties().getEtag()); blockBlobRef.download(new ByteArrayOutputStream(), accessCondition, null, operationContext); fail("Download should fail with a 304."); } catch (StorageException ex) { assertEquals("The condition specified using HTTP conditional header(s) is not met.", ex.getMessage()); } finally { container.deleteIfExists(); } }
IOException { CloudPageBlob blob1 = this.container.getPageBlobReference("blob1"); AccessCondition accessCondition = AccessCondition.generateIfNoneMatchCondition("\"*\""); final int length = 6 * 512; ByteArrayInputStream srcStream = BlobTestHelper.getRandomDataStream(length); accessCondition = AccessCondition.generateIfNoneMatchCondition(blob1.getProperties().getEtag()); try { blob1.upload(srcStream, length, accessCondition, null, null); accessCondition = AccessCondition.generateIfNoneMatchCondition(blob2.getProperties().getEtag()); blob1.upload(srcStream, length, accessCondition, null, null);
IOException { CloudBlockBlob blob1 = this.container.getBlockBlobReference("blob1"); AccessCondition accessCondition = AccessCondition.generateIfNoneMatchCondition("\"*\""); accessCondition = AccessCondition.generateIfNoneMatchCondition(blob1.getProperties().getEtag()); try { blob1.upload(srcStream, length, accessCondition, null, null); accessCondition = AccessCondition.generateIfNoneMatchCondition(blob2.getProperties().getEtag()); blob1.upload(srcStream, length, accessCondition, null, null);
CloudAppendBlob blob1 = this.container.getAppendBlobReference("blob1"); AccessCondition accessCondition = AccessCondition .generateIfNoneMatchCondition("\"*\""); final int length = 6 * 512; ByteArrayInputStream srcStream = BlobTestHelper accessCondition = AccessCondition.generateIfNoneMatchCondition(blob1 .getProperties().getEtag()); try { accessCondition = AccessCondition.generateIfNoneMatchCondition(blob2 .getProperties().getEtag()); blob1.upload(srcStream, length, accessCondition, null, null);